akhauriyash/Code-Regression huggingface dataset:
n, d = [int(i) for i in input().split()]
x =[[int(i) for i in input().split()] for j in range(n)]
squares = set([i * i for i in range(1000)])
count = 0
for i in range(n):
	for j in range(i):
		dist = sum([(x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)])
		if dist in squares:
			count += 1
print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	static long mod = 1000000000 + 7;
	static long fact(long n) {
		long ans = 1;
		for(int i = 1; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		if(Math.abs(N - M) > 1) System.out.println(0);
		else if(Math.abs(N - M) == 1) System.out.println((fact(N) * fact(M)) % mod);
		else System.out.println((fact(N) * fact(M) * 2) % mod);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> tri;

int n,m;
vector<tri> g[10100];
int dis[10100], cost[10100];

int main(){
  while(scanf("%d%d",&n,&m), n){
    rep(i,n)g[i].clear();
    rep(i,m){
      int u,v,d,c;
      scanf("%d%d%d%d",&u,&v,&d,&c);
      u--; v--;
      g[u].push_back(tri(pii(d,c),v));
      g[v].push_back(tri(pii(d,c),u));
    }

    fill(dis,dis+n,1e9);
    dis[0] = cost[0] = 0;
    priority_queue<pii, vector<pii>, greater<pii> > q;
    q.push(pii(0,0));

    while(q.size()){
      pii p = q.top(); q.pop();
      if(dis[p.sc]<p.fs)continue;      
      for(tri nxt : g[p.sc]){
	int nd = p.fs + nxt.fs.fs, nc = nxt.fs.sc, u = nxt.sc;
	if(dis[u] > nd){
	  dis[u] = nd; cost[u] = nc;
	  q.push(pii(nd,u));
	}else if(dis[u] == nd && cost[u] > nc)cost[u] = nc;
      }
    }
    cout << accumulate(cost,cost+n,0) << endl;
  }
}

Measured memory_bytes: 3304
#include<iostream>
using namespace std;
int main()
{
    int a,b,i,n,t=0,r;
    cin>>a;
    n=a;
    while(n!=0)
    {
        r=n%10;
        t=r+t;
        n=n/10;
    }
   
    if(a%t==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
const int N=200;
typedef long long ll;
ll f[N][N];
int n,a,b,r[N],s[N],c[N];
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i){
		cin>>r[i]>>s[i];
		c[i]=c[i-1]+s[i];
	}
	memset(f,63,sizeof f);
	for(int i=n;i;--i){
		int d=c[n]-c[i-1];
		for(int j=0;j<=d;++j)
			f[i][j]=min(-f[i+1][d-j+1]+1-r[i],max(r[i]+1+f[i+1][j],1ll));
	}
	for(int i=c[n];;--i)
		if(f[1][i]<=a-b){
			cout<<i<<" "<<c[n]-i<<endl;
			return 0;
		}
}

Measured memory_bytes: 3408
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] && s[0] == s[2] && s[1] == s[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;
    cin>>n;
    vi a(n),b(n),c(n-1);
    rep(i,n){cin>>a[i];a[i]--;}rep(i,n)cin>>b[i];rep(i,n-1)cin>>c[i];
    int cnt=0;
    rep(i,n){
        cnt+=b[a[i]];
        if(a[i]!=n-1&&i!=n-1&&a[i]+1==a[i+1])cnt+=c[a[i]];
    }
    cout<<cnt;
}

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

#define f(a, b) for(auto i = a;i < b;i++)
typedef long long int ll;

void solve()
{
	// return ;
}

int main()
{
	ll x, y , A, B, C, sum = 0;

	cin >> x >> y >> A >> B >> C;

	vector < ll > v1, v2, v3;

	f(0, A)
	{
		ll a;
		cin >> a;
		v1.push_back(a);
	}

	f(0, B)
	{
		ll a;
		cin >> a;
		v2.push_back(a);
	}

	f(0, C)
	{
		ll a;
		cin >> a;
		v3.push_back(a);
	}

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	sort(v3.begin(), v3.end());

	vector < ll > ans;
	f(0, x)
	{
		ans.push_back(v1[v1.size() - 1 - i]);
		sum += ans[i];
	}
	f(0, y)
	{
		ans.push_back(v2[v2.size() - 1 - i]);
		sum += ans[x + i];
	}
	sort(ans.begin(), ans.end());

	ll sum1 = 0, sum2 = 0,maxi = sum;
	f(0, C)
	{
		if(i >= x + y)
			break;
		sum1 += v3[v3.size() - 1 - i];
		sum2 += ans[i];

		if(sum1 > sum2)
			maxi = max(sum + sum1 - sum2, maxi);
	}
	cout << maxi << "\n";


	

}

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

using namespace std;

vector<int> fib_iter(int n) {

  vector<int> fib;

  int a = 1;
  int b = 1;
  int temp;

  for(int i = 0;i < n;i++) {

    temp = a;
    a += b;
    b = temp;

    a %= 1001;

    fib.push_back(a);

  }

  return fib;

}

int main() {

  vector<int> fib, fibset;
  int v, d;

  fib = fib_iter(1001);

  

  while(cin >> v >> d) {

    int count = 1;
    vector<int> fibsubset;

    for(int i = 0;i < v;i++) {
      
      fibsubset.push_back(fib[i]);

    }

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

    for(int i = 0;i < v;i++) {

      //cout << fibsubset[i] << " ";

      if(i != v-1 && abs(fibsubset[i] - fibsubset[i+1]) >= d) {

	//cout << " | "; 
	count++;

      }

    }

    cout << count << endl;

  }

  return 0;

}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9 + 7;
const ll INF = 5e15;
int main(){
    ll N;
    ll Q;
    cin >> N >> Q;
    vector<ll> A(N);
    for(ll &a : A) cin >> a;
    auto AR = A;
    reverse(AR.begin(), AR.end());
    for(ll &a : AR) a *= -1;
    vector<ll> sum(N + 1), osum(N + 1), esum(N + 1);
    for(ll i = 0; i < N; i++){
        sum[i + 1] = sum[i] + A[i];
        osum[i + 1] = osum[i];
        esum[i + 1] = esum[i];
        (i % 2 ? osum : esum)[i + 1] += A[i];
    }
    if(N == 2){
        for(ll i = 0; i < Q; i++) cout << A[1] << '\n';
        return 0;
    }
    for(ll QQ = 0; QQ < Q; QQ++){
        ll X;
        cin >> X;
        ll ok = 0, ng = 1e10;
        if(abs(X - A[N - 2]) > abs(X - A[N - 1])){
            cout << (N & 1 ? esum[N] : osum[N]) << '\n';
            continue;
        }
        while(abs(ok - ng) > 1){
            ll mid = (ok + ng) / 2;
            auto ite1 = upper_bound(A.begin(), A.end(), X + mid);
            auto ite2 = upper_bound(AR.begin(), AR.end(), -(X - mid));
            ll right = ite1 - A.begin() - 1;
            ll left = AR.end() - ite2;
            if(left == N){  // <=> right == -1  ????
                ng = mid;
                continue;
            }
            ll cnt = right - left + 1;
            ll senkou = N - cnt;
            if(right < senkou || (right == senkou && A[right] == X + mid && A[left] == X - mid)) ok = mid;
            else ng = mid;
        }
        auto ite1 = upper_bound(A.begin(), A.end(), X + ok);
        auto ite2 = upper_bound(AR.begin(), AR.end(), -(X - ok));
        ll idx1 = ite1 - A.begin() - 1;
        ll idx2 = AR.end() - ite2;
        ll cnt = (idx1 - idx2 + 1);
        ll snum = cnt, knum = cnt;
        if(idx1 == N - snum){
            idx1--;
            cnt--;
        }
        ll senkou = sum[N] - sum[idx1 + 1];
        ll koukou = sum[idx1 + 1] - sum[idx2];
        if(N & 1){
            if((knum + snum) % 2 == 0){
                senkou += esum[idx2];
                koukou += osum[idx2];
            }else{
                senkou += osum[idx2];
                koukou += esum[idx2];
            }
        }else{
            if((knum + snum) % 2 == 0){
                senkou += osum[idx2];
                koukou += esum[idx2];
            }else{
                senkou += esum[idx2];
                koukou += osum[idx2];
            }
        }
        cout << senkou << '\n';
    }
    return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>

int main(void)
{
  int X;
  int s_500,a_500,s_5,uresii;
  
  scanf("%d",&X);
  
  s_500 = X/500;
  a_500 = X%500;
  s_5 = a_500/5;
  
  uresii = s_500*1000 + s_5*5;
  printf("%d\n",uresii);
  return 0;
}

Measured memory_bytes: 128
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
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 <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename 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 <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 FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n, m;
    cin >> n >> m;
    if(n - 2 >= 0 and m - 2 >= 0) cout << (n - 2) * (m - 2) << endl;
    else {
    	if(n - 2 < 0) n = 1;
    	else n -= 2;
    	if(m - 2 < 0) m = 1;
    	else m -= 2;
    	cout << n * m << endl;
    }
}
  
int32_t main() {
 
    FAST;

    
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 3624
import java.util.*;

public 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(a+b == c || b + c == a|| c + a == b){
        System.out.println("Yes");
    }else{
        System.out.println("No");        
    }
       
      
       
   }
}
        
        
        

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

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

    int ans;
    if(n%2==0) ans = n/2;
    else       ans = n/2+1;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  s[5]=s[13]=' ';
  cout << s << endl;
  return 0;
}

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

int main(){
  int D, G;  cin >> D >> G;
  vector<int> p(D), c(D);
  rep(i,D) cin >> p[i] >> c[i];
  int ans = 1e5;
  rep(x,1<<D){
    int s=0, num=0,  mn=0;
    rep(i,D){
      if(x>>i&1){
        s += 100*(i+1)*p[i]+c[i];
        num += p[i];
      }else
        mn = i;
    }
    if(s<G){
      rep(i,p[mn]){
        s+=100*(mn+1);
        num++;
        if(s>=G) break;
      }
    }
    if(s<G) continue;
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}

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

map<int,int>mp,used;

int w,h,n;
void add(int x,int y,int i){
  if(x == 0) mp[y] = i;
  else if(y == h) mp[h+x] = i;
  else if(x == w) mp[h+w+h-y] = i;
  else if(y == 0) mp[2*h + w + w - x] = i;
}

typedef pair<int,int> P;

bool check(){
  stack <int> S;
  
  for(P a:mp) {
    int num = a.second;
    if(used[num] == 1 && S.top() != num) return 0;
    if(used[num] == 1) S.pop(),used[num] = 0;
    else S.push(num),used[num] = 1;
  }
  
  for(P a:mp) {
    int num = a.second;
    if(used[num] == 1 && S.top() != num) return 0;
    if(used[num] == 1) S.pop(),used[num] = 0;
    else S.push(num),used[num] = 1;
  }
  return 1;
}

int main(){
  cin>>w>>h>>n;
  for(int i=0;i<n;i++){
    int x1,y1,x2,y2;

    cin>>x1>>y1>>x2>>y2;
    if(!((x1 == 0 || y1 == 0 ||x1 == w || y1 == h) &&
         (x2 == 0 || y2 == 0 ||x2 == w || y2 == h)))continue;
    add(x1,y1,i);
    add(x2,y2,i);
  }
  
  cout<<(check()? "YES":"NO")<<endl; 
    
  return 0;
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
     
    using namespace std;
      
      int main(){
    int n;
      set<string> se;
      string g[1100];
      cin>>n;
      for(int i=0;i<n;i++)cin>>g[i];
      for(int i=0;i<n-1;i++){
      if(g[i].back()!=g[i+1][0]){
      cout<<"No"<<endl;
        return 0;
      }
      }
      se.insert(g[0]);
      for(int i=1;i<n;i++){
      	if(se.find(g[i])!=se.end()){
        cout<<"No"<<endl;
          return 0;
        }
        se.insert(g[i]);
      }
      cout<<"Yes"<<endl;
      return 0;
    }

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, k := nextInt(), nextInt()

	ans := 0
	for b := 1; b <= n; b++ {
		p, r := n/b, n%b
		x := p*max(0, b-k) + max(0, r-k+1)
		ans += x
	}
	if k == 0 {
		ans -= n
	}

	puts(ans)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long sum =0;
        ArrayList<Integer> H = new ArrayList<>();
        for(int i=0;i<N;i++) H.add(sc.nextInt());
        Collections.sort(H,Comparator.reverseOrder());
        for(int i=K;i<H.size();i++) sum+=H.get(i);
        System.out.println(sum);
    }
}

Measured memory_bytes: 91344
n, a = map(int, input().split())
x = list(map(int, input().split()))
X = max(max(x),a)
y = []
for i in x:
    y.append(i-a)
dp = [[0]*(2*n*X+1) for _ in range(n+1)]

for i in range(n+1):
    for j in range(len(dp[i])):
        if i == 0 and j == n * X:
            dp[i][j] = 1
        elif i > 0 and (j - y[i-1] < 0 or j - y[i-1] > 2 * n * X):
            dp[i][j] = dp[i-1][j]
        elif i > 0 and 0 <= j - y[i-1] <= 2 * n * X:
            dp[i][j] = dp[i-1][j] + dp[i-1][j-y[i-1]]
        else:
            dp[i][j] = 0

print(dp[n][n*X]-1)

Measured memory_bytes: 5612
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "YES"
#define __FALSE "NO"
#define MAX 100001
using namespace std;

int main() {
  string s;
  string a[]={"dream","dreamer","erase","eraser"};
  cin >> s;
  bool flag=true;
  int i=0;
  while(i<s.size()) {
    string tmp=s.substr(i,5);
    if(tmp==a[0]) {
      i+=5;
      if(s[i]=='e'&&s[i+1]=='r'&&s[i+2]!='a') {
        i+=2;
      }
    }else if(tmp==a[2]){
      i+=5;
      if(s[i]=='r') {
        i+=1;
      }
    }else {
      flag=false;
      break;
    }
  }
  if(flag) cout << __TRUE << endl;
  else cout << __FALSE << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
 
int main(){
    int y[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int m, d, d_all, dotw, i;
    char w[7][20] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

    while(scanf("%d %d", &m, &d) != EOF){
        if (m == 0 && d == 0) break;

        d_all = 0;
        dotw = 0;
        for(i = 0; i < (m-1); i++){
            d_all += y[i];
        }
        d_all += d;
        dotw = d_all % 7;
        printf("%s\n", w[dotw]);
    }
    return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String[] s = sc.next().split(",");
			double x1 = Double.parseDouble(s[0]);
			double y1 = Double.parseDouble(s[1]);
			double x2 = Double.parseDouble(s[2]);
			double y2 = Double.parseDouble(s[3]);
			double xq = Double.parseDouble(s[4]);
			double yq = Double.parseDouble(s[5]);
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point q = new Point(xq, yq);
			double k = dot(vec(p1, p2), vec(p1, q)) / dot(vec(p1, p2), vec(p1, p2));
			double x = 2 * (p1.x + k * vec(p1, p2).x) - xq;
			double y = 2 * (p1.y + k * vec(p1, p2).y) - yq;
			System.out.printf("%f %f\n", x, y);
		}
		sc.close();
	}
	static class Point{
		double x, y;
		Point(double x, double y){
			this.x = x;
			this.y = y;
		}
	}
	static Point vec(Point p1, Point p2) {
		return new Point(p2.x - p1.x, p2.y - p1.y);
	}
	static double dot(Point p1, Point p2) {
		return p1.x * p2.x + p1.y * p2.y;
	}
	static double norm(Point p1) {
		return Math.sqrt(p1.x * p1.x + p1.y * p1.y);
	}
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a, b, c; cin >> a >> b >> c;
    int d = min(c, a + b + 1);
    cout << b + d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

template <typename T>
void printV(vector<T>& v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

signed main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

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

    vector<int> b(n);
    b[0] = a[0];
    for(int i = 1; i < n; i++) b[i] = a[i] + b[i - 1];

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());

    int ans = 1;
    for(int i = 0; i < n - 1; i++) {
        if(a[i] <= b[i + 1] * 2) ans++;
        else break;
    }

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;


const int p1 = 999901571;
const int p2 = 999900301;
const int m1 = 1000000097;
const int m2 = 1000000663;

vl f(string s) {
  vp d(1);
  rep(i,sz(s)) {
    int c = s[i];
    vp pre; swap(pre,d);
    for (P p : pre) {
      d.pb(P(((ll)p.fi*p1+c)%m1,p.se));
      d.pb(P(p.fi, ((ll)p.se*p2+c)%m2));
    }
  }
  vl res;
  for (P p : d) {
    res.pb((ll)p.fi<<32|p.se);
  }
  return res;
}

int main() {
  int n;
  scanf("%d",&n);
  string s;
  cin>>s;
  string t = s.substr(n);
  reverse(rng(t));
  s = s.substr(0,n);
  vl x = f(s);
  unordered_map<ll,int> mp;
  for (ll v : x) mp[v]++;
  x = f(t);
  ll ans = 0;
  for (ll v : x) ans += mp[v];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 30808
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int n,a,ans=0,b,c,d;
    cin>>n>>b>>c;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(a<b||a>=c)
        ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
// #define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
string s;
bool HaveCharBefore(int tail, char c) {
  --tail;
  for(int i = tail; i >= 0; --i) {
    if(s[i]==c) return true;
  }
  return false;
}

signed main() {
  cin >> s;
  map<char, bool> have_seen;
  if(s.length() == 26) {
    char tailChar = s[25];
    int ascTailIndex = 0;
    bool impossible = true;
    for(int i = 25; i > 0; --i) {
      if(s[i-1] < s[i]) {
        ascTailIndex = i-1;
        impossible = false;
        break;
      }
    }
    if(impossible) {
      cout << -1 << endl;
      return 0;
    }
    char smallest_char = 'z';
    for(int i = ascTailIndex+1; i < 26; ++i) {
      if(s[i] > s[ascTailIndex]) {
        if(smallest_char > s[i]) smallest_char = s[i];
      }
    }
    // char next_char = s[ascTailIndex] + 1;
    s = s.substr(0,ascTailIndex);
    cout << s + smallest_char << endl;
    return 0;
  }
  REP(i,s.length()) {
    have_seen[s[i]] = true;
  }
  for(char c = 'a'; c <= 'z'; ++c) {
    if(!have_seen[c]) {
      cout << s + c << endl;
      return 0;
    }
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int mod = 1000000007;



int main(){
    string s; cin >> s;
    vector<ll> dp(13);
    dp[0] = 1;

    int mul = 1;
    for(int i = s.size()-1; i >= 0; i--){
        vector<ll> nextdp(13);
        char c = s[i];
        if(c == '?'){
            for(int k = 0; k <= 9; k++){
                //c=0~9
                for(int j = 0; j <= 12; j++){
                    nextdp[(k * mul + j) % 13] += dp[j];
                    nextdp[(k * mul + j) % 13] %= mod;
                }
            }
        } else {
            int k = (int)(s[i] - '0');
            for(int j = 0; j <= 12; j++){
                nextdp[(k * mul + j) % 13] += dp[j];
                nextdp[(k * mul + j) % 13] %= mod;
            }
        }
        mul *= 10;
        mul %= 13;
        swap(dp, nextdp);
    }
    cout << dp[5] << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int c=0;
    for(size_t i=0; i<s.length(); i++) {
        if(s[i]=='o')
            c++;
    }
    cout << ( ( (15 - (s.length() - c)) > (15-8)) ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	int n=read()-1,k=read()-1;
	if(n%k)cout<<n/k+1;
	else cout<<n/k;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

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

int main() {
  int N; cin >> N;
  int A, B, xM = 1e9 + 1, yM = 1e9 + 1, xm = -1, ym = -1;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    if (A < xM) {
      xM = A; yM = B;
    }
    if (A > xm) {
      xm = A; ym = B;
    }
  }
  //cout << xm << " " << ym << endl;                                              
  ll ans = xm + ym;
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
n, m, q = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(q)]
result = [0]
p = deque([[i] for i in range(1, m+1)])
while p:
    i = p.popleft()
    if len(i) == n:
        r = 0
        for a, b, c, d in x:
            if i[b-1]-i[a-1]==c:
                r += d
        result.append(r)
    else:
        for j in range(i[-1], m+1):
            p.append(i+[j])
print(max(result))

Measured memory_bytes: 23404
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    string s;
    cin>>s;
    for(ll i=0;i<s.length()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2;
            return 0;
        }
    }
    for(ll i=0;i<int(s.length())-2;i++)
    {
        if(s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3;
            return 0;
        }
    }
    cout<<"-1 -1";
    
}


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

const int INF = 1 << 30;

bool solve(){
	int N, M;
	cin >> N >> M;
	if (N == 0) return false;

	vector<int> S(N), D(M);
	for(auto& s : S) cin >> s;
	for(auto& d : D) cin >> d;

	vector<int> dp(1 << N, INF);
	dp[0] = accumulate(D.begin(), D.end(), 0);

	for(int b = 0; b < (1 << N); ++b) {
		for(int i = 0; i < N; ++i) {
			if ((b >> i) & 1) continue;

			int sum = 0;
			for(int j = 0; j < N; ++j) {
				if ((b >> j) & 1) sum += S[j];
			}

			// add i
			int score = dp[b];
			for(int j = 0; j < M; ++j) {
				if (abs(D[j] - sum) > abs(D[j] - (sum + S[i]))) {
					score -= abs(D[j] - sum);
					score += abs(D[j] - (sum + S[i]));
				}
			}

			dp[b | (1 << i)] = min(dp[b | (1 << i)], score);
		}
	} 

	cout << dp[(1 << N) - 1] << endl;
	return true;
}


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



Measured memory_bytes: 3196
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    int n;
    int x[100];
    int y[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    double answer[4];
    
    for(int i=0;i<4;i++) answer[i]=0.0;
    for(int p=1;p<=3;p++){
        for(int i=0;i<n;i++){
            answer[p]+=pow(fabs(x[i]-y[i]),p);
    }
     answer[p]=pow(answer[p],1.0/p);   
    }
    for(int i=0;i<n;i++){
        answer[0]=(answer[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):answer[0]);
    }
        
    printf("%1f\n",answer[1]);
    printf("%1f\n",answer[2]);
    printf("%1f\n",answer[3]);
    printf("%1f\n",answer[0]);
    
    return 0;
}


Measured memory_bytes: 3312
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int K;

//無限ループしないように、1度見たところは2度は見ない
vector<vector<bool>> went;




//サブ関数
//入力
void input()
{
	cin >> K;
	went = vector<vector<bool>>(50, vector<bool>(K, false));
}


//計算
void calc()
{
	// first:dist, second:remainder(mod K)
	priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pq.push(make_pair(1, 1));
	while (!pq.empty())
	{
		//距離最短の数値を一つ取り出す
		auto now = pq.top(); pq.pop();

		//移動済みなら無視
		if (now.first >= 50)continue;
		if (went[now.first][now.second])continue;
		went[now.first][now.second] = true;

		//数字を昇順に、そして一意に変化させるとすると、以下の二通りの操作に帰着できる
		//① 1を足す
		//このとき、数字の総和は1増え、mod K は1増える
		auto next = make_pair(now.first + 1, (now.second + 1) % K);
		pq.push(next);
		//②10倍する
		//このとき、数字の総和は増えず、modKは10倍になる
		auto next2 = make_pair(now.first, (now.second * 10) % K);
		pq.push(next2);
	}
}


//出力
void output()
{
	REP(i, 50) {
		if (went[i][0]) {
			cout << i << endl;
			return;
		}
	}
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 2040
N, M = map(int, input().split())
shops = []
for _ in range(N):
    a, b = map(int, input().split())
    shops.append((a, b))
shops = sorted(shops, key=lambda s: s[0])
m = 0
total = 0
for a, b in shops:
    if m + b >= M:
        total += (M - m) * a
        break
    else:
        total += a * b
        m += b
print(total)


Measured memory_bytes: 24356
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

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

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


int main()
{
    int N, M;
    int H[100000];
    int A[100000];
    int B[100000];
    int C[100000] = { 0 };

    scanf("%d%d", &N, &M);

    for (int i = 0; i < N; i++)
        scanf("%d", &H[i]);

    for (int i = 0; i < M; i++)
    {
        scanf("%d%d", &A[i], &B[i]);
        if (H[A[i]-1] > H[B[i]-1])
        {
            C[A[i]-1]++;
            C[B[i]-1] = -INF;
        }
        else if(H[A[i] - 1] < H[B[i] - 1])
        {
            C[B[i]-1]++;
            C[A[i]-1] = -INF;
        }
        else
        {
            C[B[i] - 1] = -INF;
            C[A[i] - 1] = -INF;
        }
    }

    int ans = 0;

    for (int i = 0; i < N; i++)
    {
        if (C[i] >= 0)
        {
            ans++;
            //printf("%d %d\n", i,C[i]);
        }
    }
    printf("%d", ans);
}



Measured memory_bytes: 5388
// Program.cpp

#include <bits/stdc++.h>
using namespace std;

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

#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n)           for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

void solve(int TEST_CASE){
    int n;
    cin >> n;
    ll dp[n+1][n];
    ll cost[n+1][n];
    //dp[i][j] -> minimum possible sum of size i and starting index j
    fr(i,n){
    	dp[0][i] = 0;
    	cin >> dp[1][i];
    	cost[1][i] = 0;
    	cost[0][i] = 0;
    }

    for(int i=2;i<=n;++i){
    	for(int j=0;j<=n-i;++j){
    		ll p = 1e18;
    		ll q;
    		for(int k=1;k<=i-1;++k){
    			q = dp[k][j] + dp[i-k][j+k];
    			if(q<p)
    				p = q;
    		}
    		dp[i][j] = p;
    	}
    }
    for(int i=2;i<=n;++i){
    	for(int j=0;j<=n-i;++j){
    		ll p = 1e18;
    		ll q;
    		for(int k=1;k<=i-1;++k){
    			q = cost[k][j] + dp[k][j] + cost[i-k][j+k] + dp[i-k][j+k];
    			if(q<p)
    				p = q;
    		}
    		cost[i][j] = p;
    	}
    }
    cout << cost[n][0] << endl;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

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

namespace ConsoleApp15
{
    class Class3
    {
        static void Main()
        {
            var PQR = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int sum = PQR.Sum()-PQR.Max();
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int c=0;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            c++;
        }
    }
    cout<<c<<endl;









    return 0;
}


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

int two(int);

int main(){
    int N, count=0, max=0;
    int icount=0;
    cin >> N;
    for(int i=1; i<=N; i++){
        icount = two(i);
        if(icount > count){ 
            count = icount; 
            max = i;
        }
        //cout << "i=" << i << " max=" << max << " count=" << count << endl;
    }
    cout << max << endl;
}

int two(int num){
    int i=1;
    while(num%2 == 0){
        i++;
        num = num/2;
    }
    return i;
}

Measured memory_bytes: 256
import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10):
    Open = np.array([int(x) for x in format(i, '010b')])
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print(-Profit[0])
        

Measured memory_bytes: 27040
#!/usr/bin/env python
# coding: utf-8

import sys
input = sys.stdin.readline

inf = float('inf')

def main():
    A, B, Q = list(map(int, input().split()))
    ls = [-inf] + [int(input()) for _ in range(A)] + [inf]
    lt = [-inf] + [int(input()) for _ in range(B)] + [inf]
    lx = [(int(input()), i) for i in range(Q)]
    ls.sort()
    lt.sort()
    lx.sort()
    ans = {}
    s = 1
    t = 1
    for i in range(Q):
        dist = -1
        x = lx[i][0]
        while s <= A and ls[s] < x:
            s += 1
        while t <= B and lt[t] < x:
            t += 1
        s_min = ls[s-1]
        s_max = ls[s]
        t_min = lt[t-1]
        t_max = lt[t]
        d = min(max(s_max-x, t_max-x),
                (s_max-x)*2 + (x-t_min),
                (t_max-x)*2 + (x-s_min),
                (s_max-x) + (x-t_min)*2,
                (t_max-x) + (x-s_min)*2,
                max(x-s_min,x-t_min))
        ans[lx[i][1]] = str(d)
    print("\n".join(ans[i] for i in range(Q)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40976
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
   int N;
   cin >> N;
   int num = N, sum = 0;
   while(num > 0){
     sum += num%10;
     num /= 10; 
   }
  if(N%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int N, K; cin >> N >> K;

    if (N%K == 0) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 10000000021LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int n;
string s;
long long gogo[20000];
int solve(int len) {
	long long dying = 1;
	int itr = 0;
	long long now = 0;
	for (int q = 0; q < s.length(); ++q) {
		now *= 26LL;
		now += s[q] - 'a';
		now %= MAX_MOD;
		if (q >= len) {
			now += (MAX_MOD - ((dying * (s[q - len] - 'a') % MAX_MOD))) % MAX_MOD;
			now %= MAX_MOD;
		}
		else {
			dying *= 26LL;
			dying %= MAX_MOD;
		}
		if (q >= len - 1) {
			gogo[itr] = now;
			itr++;
		}
	}
	set<long long> nya;
	for (int i = itr - len - 1; i >= 0; --i) {
		nya.insert(gogo[i + len]);
		if (nya.find(gogo[i]) != nya.end()) return true;
	}
	return false;
}
int main() {
	cin >> n >> s;
	int bot = 0;
	int top = s.length();
	while (top - bot > 1) {
		int mid = (top + bot) / 2;
		if (solve(mid) == true) {
			bot = mid;
		}
		else top = mid;
	}
	cout << bot << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 507;
int c[maxn],s[maxn],f[maxn];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    }
    int t=0;
    for(int i=1;i<=n;i++)
    {
        t=0;
        for(int j=i;j<=n-1;j++)
        {
            if(t<s[j])t=s[j];
            else if(t%f[j]==0);
            else t=t-t%f[j]+f[j];
            t+=c[j];
        }
        cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 3708
import bisect

six_list = [6 ** i for i in range(7)]
nine_list = [9 ** i for i in range(6)]


def six_nine(n):
    if n < 6:
        return n
    else:
        six = six_list[bisect.bisect_right(six_list, n) - 1]
        nine = nine_list[bisect.bisect_right(nine_list, n) - 1]
        return min(n // six + six_nine(n % six), 1 + six_nine(n - nine))


if __name__ == '__main__':
    x = int(input())
    print(six_nine(x))

Measured memory_bytes: 42200
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n;
char s[100100];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n-1)
	{
		if (s[i]==s[i+1]) 
		{
			printf("%d %d",i,i+1);
			return 0;
		}
	}
	rep(i,1,n-2)
	{
		if (s[i]==s[i+2])
		{
			printf("%d %d",i,i+2);
			return 0;
		}
	}
	puts("-1 -1");
	return 0;
}


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

using namespace std;

int main() {
  int n;
  long long a, b;
  scanf("%d %lld %lld", &n, &a, &b);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    long long big = max(a / u + (a % u? 1 : 0), b / v + (b % v? 1 : 0));
    a = u * big;
    b = v * big;
  }
  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 256
t[7][7]={{},
{0,0,3,5,2,4,0},
{0,4,0,1,6,0,3},
{0,2,6,0,0,1,5},
{0,5,1,0,0,6,2},
{0,3,0,6,1,0,4},
{0,0,4,2,5,3,0}
},i,N[7],n,a,b;
h(p){for(i=0;p!=N[++i];);return i;}
main(){
for(i=1;i<7;scanf("%d",&N[i++]));
for(scanf("%d",&n);scanf("%d%d",&a,&b),n--;printf("%d\n",N[t[h(a)][h(b)]]));
}

Measured memory_bytes: 1796
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = a[i]
	}

	sort.Ints(b)
	// fmt.Println(b)
	// fmt.Println(a)
	for i := 0; i < n; i++ {
		if a[i] == b[n-1] {
			fmt.Println(b[n-2])
		} else {
			fmt.Println(b[n-1])
			// ans := upperBound(tmp, a[i])
		}
		// fmt.Println(tmp[ans-1])
	}

}

func upperBound(t []int, k int) int {
	lb := -1
	ub := len(t)
	for ub-lb > 1 {
		mid := (lb + ub) / 2

		if t[mid] <= k {
			lb = mid
		} else {
			ub = mid
		}
	}
	// if t[lb] <= k {
	// 	return ub
	// }
	return ub
}


Measured memory_bytes: 9048