akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

ll idx_color = 0;

void dfs(vector<vll> &G, vll &checked, ll u){
    checked[u] = idx_color;
    for(auto v: G[u]){
        if(checked[v] == -1)
            dfs(G, checked, v);
    }
}


void dfs_driver(vector<vll> &G, vll &checked){
    ll N = G.size();
    fill(ALL(checked), -1);
    REP(i, N){
        if(checked[i]== -1){
            dfs(G, checked, i);
            idx_color++;
        }
        
    }
}

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<vll> G(N);
    REP(i, M){
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    //* dfs
    vll color(N, -1);
    dfs_driver(G, color);
    ll ans = 0;
    map<ll, ll> R;
    REP(i, N){
        R[color[i]]++;
    }
    for ( auto x: R){
        chmax(ans, x.second);
    }
    cout<<ans<<endl;

}
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        A[i]--; B[i]--;
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 27804
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 27 21:30:42 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
N, X = map(int,input().split())
#A = list(map(int,input().split()))

n = N
eat = X

def dfs(x):
    x

ans = 0
#print(ans,eat,n)
while eat > 0 and n >= 0:
    if eat == (pow(2,n+2) - 3 + 1) //2:
        ans += pow(2,n) - 1 + 1
        eat = 0
        n -= 1
    elif eat > (pow(2,n+2) - 3 + 1) //2:
        ans += pow(2,n) - 1 + 1
        eat -= (pow(2,n+2) - 2) //2
        n -= 1
    else:
        eat -= 1
        n -= 1
#    print(ans,eat,n)

print(ans)
    


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

class UnionFind {
  public:
  // 親の番号を格納。ルートだった場合は-(その集合のサイズ)
  vector<ll> parents;

  UnionFind(ll N) {
    parents = vector<ll>(N, -1);
  }

  // iがどのグループに属しているか
  ll root(ll i) {
    if (parents[i] < 0) {
      return i;
    } else {
      return parents[i] = root(parents[i]);
    }
  }

  // iが属しているグループの大きさ
  ll size(ll i) {
    return -parents[root(i)];
  }

  // root(a)とroot(b)を接続する
  bool connect(ll a, ll b) {
    ll rootA = root(a);
    ll rootB = root(b);
    if (rootA == rootB) {
        return false;
    } else {
      // 大きいほう(a)に小さいほう(b)をくっつける
      // 大小が逆の場合はスワップ
      if (size(rootA) < size(rootB)) {
        swap(rootA, rootB);
      }

      // aグループのサイズを増やす
      parents[rootA] += parents[rootB];
      // bの親をaのルートに変更する
      parents[rootB] = rootA;

      return true;
    }
  }

};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);
  for (ll i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<ll> ans(M);
  // 橋が全部崩落した
  ans[M-1] = N*(N-1)/2;

  UnionFind Uni(N);
  for (ll i = M - 1; i >= 1; i--) {
    // A[i]とB[i]がつなげる
    if (Uni.root(A[i]) != Uni.root(B[i])) {
      ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      Uni.connect(A[i], B[i]);
    } else {
      ans[i-1] = ans[i];
    }
  }
  for (ll i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4480
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		Main main = new Main();
		main.solv();
	}
	private void solv() {
		int n = in.nextInt();
		int k = in.nextInt();
		int[] w = new int[n];

		long total = 0;
		long max = 0;
		for (int i = 0; i < n; i++) {
			w[i] = in.nextInt();
			total += w[i];
			max = Math.max(max, w[i]);
		}

		while(max < total) {
			long m = (max + total) / 2;
			long sum = 0;
			int kId = 0;

			for(int i = 0; i < n && kId != k; i++) {
				if (sum + w[i] > m) {
					sum = w[i];
					kId++;
				} else {
					sum += w[i];
				}
			}
			if (kId != k) {
				total = m;
			} else {
				max = m + 1;
			}
		}
		out.println(max);
	}
}

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

int main() {
  int N;
  string S;
  bool r=false;
  cin >> S >> N;
  for (int i = 0; i < N; i++){
    int t,f;
    cin >> t;
    if(t==1){r = !r;}
    if(t==2){
      string c;
      cin >> f >> c;
      if(f==1&&r==false){S.insert(0,c);}
      if(f==2&&r==false){S.insert(S.size(),c);}
      if(f==2&&r==true){S.insert(0,c);}
      if(f==1&&r==true){S.insert(S.size(),c);}
    }
  }
  if(r==true){reverse(S.begin(), S.end());}
  cout << S << endl;
}


Measured memory_bytes: 900
module.exports=function(t){var r={};function n(i){if(r[i])return r[i].exports;var e=r[i]={i:i,l:!1,exports:{}};return t[i].call(e.exports,e,e.exports,n),e.l=!0,e.exports}return n.m=t,n.c=r,n.d=function(t,r,i){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var e in t)n.d(i,e,function(r){return t[r]}.bind(null,e));return i},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="",n(n.s=0)}([function(t,r,n){"use strict";var i=n(1);n(2)(i.readFileSync("/dev/stdin","utf8"))},function(t,r){t.exports=require("fs")},function(t,r,n){"use strict";var i=n(3),e=n(5);t.exports=function(t){var r=new i(t);e(r)}},function(t,r,n){"use strict";var i=n(4);t.exports=class{constructor(t){var r=t.trim().split(/\s+/g);this.inp=new i(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,r,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,r,n){"use strict";var i=n(6);t.exports=function(t){for(var r=t.in(),n=t.in(),e=new Array(n),s=0;s<n;s++){var o=t.in(),u=t.in(),a=t.in();e.push({s:o,t:u,c:a}),e.push({s:u,t:o,c:a})}for(var c=i(r,e),f=0,h=c.length,p=0;p<h;p++)f+=c[p].c;console.log(f)}},function(t,r,n){"use strict";var i=n(7);t.exports=function(t,r){var n=new i(t),e=[],s=r.concat();s.sort(function(t,r){return t.c-r.c});for(var o=0;e.length<t-1;){var u=s[o++];n.isSameGroup(u.s,u.t)||(e.push(u),n.unite(u.s,u.t))}return e}},function(t,r,n){"use strict";t.exports=class{constructor(t){this.N=t,this.par=new Array(this.N),this.rank=new Array(this.N);for(var r=0;r<this.N;r++)this.par[r]=r,this.rank[r]=0}find(t){return this.par[t]==t?t:this.par[t]=this.find(this.par[t])}unite(t,r){var n=this.find(t),i=this.find(r);n!=i&&(this.rank[n]<this.rank[i]?this.par[n]=i:(this.par[i]=n,this.rank[n]==this.rank[i]&&this.rank[n]++))}isSameGroup(t,r){return this.find(t)==this.find(r)}}}]);


Measured memory_bytes: 66264
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long q,h,s,d,n;
    cin>>q>>h>>s>>d;
    cin>>n;
    long long a[3],b[4];
    a[0]=4*q;
    a[1]=2*h;
    a[2]=s;
    b[0]=2*a[0];
    b[1]=2*a[1];
    b[2]=2*a[2];
    b[3]=d;
    sort(a,a+3);
    sort(b,b+4);
    cout<<(n/2)*b[0]+(n%2)*a[0]<<endl;
    return 0;
}


Measured memory_bytes: 3640
def chmin(min, cur):
	if min > cur:
		min = cur
	return min

n = int(input())
h = list(map(int,input().split()))

dp = [float('inf') for i in range(n+2)]

dp[0] = 0
dp[1] = chmin(dp[1], dp[0]+abs(h[1]-h[0]))

for i in range(2, n):
	dp[i] = chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]))
	dp[i] = chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
	
print(dp[n-1])

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


void solve(long long N){
 N = N+1;
 cout << int(N / 2) << endl;
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let k = get_line().parse::<usize>().unwrap();
    let s = get_line().chars().collect::<Vec<char>>();

    if s.len() <= k {
        println!("{}", s.into_iter().collect::<String>());
        return;
    }

    println!("{}...", &s[..k].into_iter().collect::<String>());
}


Measured memory_bytes: 2072
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  int max1=0;
  int max2=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    //b[i]=a[i];
    if(a[i]>max1){
      max1=a[i];
    }else{
      if(a[i]>max2){
        max2=a[i];
      }
    }
  }
  for(int i=0;i<n;i++){
    if(a[i]==max1){
      printf("%d\n",max2);
    }else{
      printf("%d\n",max1);
    }
  }
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(int key,int value){
  return value >= key;
}

int binary_search(vector<int> a,int key){
  int ok = a.size();
  int ng = -1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n,m,a;cin>>n>>m>>a;
  int black = 0;
  rep(i,n+1){
    rep(j,m+1){
      
      black = i * j + (n - i) * (m - j);
      if(black == a){
        print("Yes");
        return 0;
      }
    }
  }
  print("No");
  return 0;
} 


Measured memory_bytes: 256
def p_e():
    n, t = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ma = ab[-1][0]
    dp = [0] * (t + ma)
    for w, v in ab:
        next = [0] * (t + ma)
        for j in range(1, t + ma):
            if 0 <= j - w < t:
                next[j] = max(dp[j - w] + v, dp[j])
            else:
                next[j] = dp[j]
        dp = next
    print(max(dp))
    
p_e()

Measured memory_bytes: 46424
#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np
import math
import sys
from collections import defaultdict
input = sys.stdin.readline
A = np.array((list(map(int,input().split()))))
B = np.array((list(map(int,input().split()))))
C = np.array((list(map(int,input().split()))))
def kc(i ,a,b,c):
    if a[i] - a[i-1] == b[i] - b[i-1] ==c[i] - c[i-1] :
        return True
    else:
        return False

def kcc(a,b,c):
    if (a-b)[0] ==(a-b)[1] == (a-b)[2] and(b-c)[0]== (b-c)[1]==(b-c)[2] and  (c-a)[0]==(c-a)[1]==(c-a)[2]:
        return True
    else:
        return False


if kcc(A,B,C) and kc(0 ,A,B,C) and kc(1 ,A,B,C) and kc(2 ,A,B,C):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 12468
#include<stdio.h>
int main()
{
   
   int a,b,c,d;
   scanf("%d %d %d %d",&a,&b,&c,&d);
  while(1){
      c-=b;
      if(c<=0){
          printf("Yes");
          return 0;
      }else{
          a-=d;
          if(a<=0){
              printf("No");
              return 0;
          }
      }
  }
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  int n;
  cin >> s >> n;

  int len = s.length();
  for(int i = 0; i < len; i += n){
    cout << s[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)


int main()
{	
	string a;
	cin>>a;
	int p=0;
	int i=0;
	while(a[i]!='\0'){
		if(a[i]=='p'){
			p++;
		}
	 i++;
	}
	int b = a.size()/2;
	cout<<b-p<<endl;

}


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

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

int main() {
    int n, m;
    cin >> n >> m;
    ll x[n], y[m];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }
    
    const ll MOD = 1e9 + 7;
    sort(x, x + n);
    reverse(x, x + n);
    sort(y, y + m);
    reverse(y, y + m);
    ll sumX = 0;
    ll sumY = 0;
    for (int i = 0; i < n; i++) {
        sumX += x[i] * (n - 2 * i - 1);
        sumX %= MOD;
    }
    for (int i = 0; i < m; i++) {
        sumY += y[i] * (m - 2 * i - 1);
        sumY %= MOD;
    }
    
    cout << (sumX * sumY) % MOD << endl;
    
    
    return 0;
}

Measured memory_bytes: 1920
import numpy as np


def read():
    n = int(input().strip())
    capacities = np.empty((5, ), dtype=np.int64)
    for i in range(5):
        capacities[i] = int(input().strip())
    return n, capacities


def solve(n, capacities):
    n_groups = (n - 1) // np.min(capacities)
    return 5 + n_groups


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 12440
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n,z,w;
    cin >> n >> z >> w;
    vector<int>a(n);
    REP(i,n) cin >> a[i];
    if(n==1){
        cout<<abs(a[0]-w)<<endl;
        return 0;
    }
    //yが最後を引く時
    int ans1=abs(a[n-1]-w);
    int ans2=INF;
    bool flag=true;
    for (int i = 0; i < n-1; i++)
    {
        int tmp = abs(a[i]-a[n-1]);
        flag=true;
        for (int j = i+1; j < n-1; j++)
        {
            if(abs(a[i]-a[n-1]) <=tmp){
                flag = false;
                break;
            }
        }
        if(flag){
            chmin(ans2,tmp);
        }
    }
    flag=true;
    for (int i = -1; i < n-1; i++)
    {
        int tmp = i==-1 ? ans1 : abs(a[i]-a[n-1]);
      //  cerr<<tmp<<endl;
        flag=true;
        for (int j = i+1; j < n-1; j++)
        {
            if(abs(a[i]-a[n-1]) >= tmp){
                flag=false;
                break;
            }
        }
        //cerr<<"flag"<<flag<<endl;
        //cerr<<"tmp"<<tmp<<endl;
        if(flag){
            chmax(ans1,tmp);
        }
        //cerr<<"ans1"<<ans1<<endl;
    }
    //cerr<<ans1<<ans2<<endl;    
    cout<<max(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#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 pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#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;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    double a, b, n;
    cin >> a >> b >> n;

    
    if(n > b-2) cout << floor(a*(b-1)/b) << endl;
    else cout << floor(a*n/b) << endl;
    
    return 0;
}

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




int main(){

	int k,n;
	cin>>k>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int maxa = -1;
	for(int i=1;i<n;i++){
		maxa = max(maxa,arr[i]-arr[i-1]);
	}
	maxa = max(maxa , k - arr[n-1] + arr[0]);
	cout<<k - maxa<<endl;
	
	
	
	
	return 0;
  
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll n i=0; i<n; ++i)
#define rep1(i,n) for(ll n i=1; i<=n; ++i)
#define revrep(i,n) for(ll n i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll ans=0, D, T, S;
    cin >> D >> T >> S;
    if (D <= S * T)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1000100;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, ans;
char a[maxn], b[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> a >> b;
	std::deque<int> q = {n + 1};
	for(int i = n - 1, j = n, d = 0;i >= 0;--i) {
		int ok = 0;
		for(;j >= 0 && (j > i || a[j] != b[i]);ok = 1) -- j;
		if(j < 0) return cout << -1 << '\n', 0;
		if(ok) {
			++ d;
			if(i != j) ans = std::max<int>(ans, q.size()), q.push_front(j + d);
		} else { 
			for(;q.size() && q.back() - d >= i;) q.pop_back();
			q.push_back(i + d);
		} 
	}
	cout << ans << '\n';
}


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

int main(){
    int a,b;
    char s[100];
    scanf("%d %d",&a,&b);
    // cin >> a >> b;
    scanf("%s",&s);

    bool judge=true;
    int i=0;
    /*for(;i<a;i++)
    {
        if(s[i]=='-'){
            judge=false;
        }
    }
    if(s[i]!='-'){
            judge=false;
        }
    for(;i<a+b+1;i++){
        if(s[i]=='-'){
            judge=false;
        }
    }
    */
    for(i=0;i<a;i++)
    {
        if(s[i]=='-'){
            judge=false;
        }
    }
    
    if(s[a]!='-'){
        judge=false;
    }
    for(i=a+1;i<a+b+1;i++){
        if(s[i]=='-'){
            judge=false;
        }
    }
    if(s[i]!='\0') judge=false;
    if(judge) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9


int main()
{
    fastio;
    int n;
    cin >> n;
    lli sum=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        sum+=x;
        m[x]+=1;
    }
    int q;
    cin >> q;
    for(int w=0;w<q;w++)
    {
        int b,c;
        cin >> b >> c;
        if(m.find(b)!=m.end())
        {
            lli t=m[b]*1LL*b,t1=m[b]*1LL*c;
            sum-=t;
            sum+=t1;
            m[c]+=m[b];
            m.erase(m.find(b));
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 6584
#include<stdio.h>
int main()
{
    int x,y;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        if(x==0 && y==0)
            return 0;
        else
        {
            if(x>y)
                printf("%d %d\n",y,x);
            else
                printf("%d %d\n",x,y);
        }
    }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
bool pcom(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 main(){
  ll N,H,ans=0;
  cin>>N>>H;
  vector<pair<ll,ll>> p(N);
  for(ll i=0;i<N;i++) cin>>p[i].first>>p[i].second;
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  ll a=p[0].first,b=p[0].second;
  p[0].first=0;
  p[0].second=0;
  sort(p.begin(),p.end(),pcom);
  for(ll i=0;i<N;i++){
    if(H<=b){
      ans++;
      break;
    }
    if(p[i].second>a){
      H-=p[i].second;
      ans++;
      if(H<=0) break;
    }else{
      H-=b;
      ans++;
      if(H<=0) break;
      if(H%a==0) ans+=H/a;
      else ans+=H/a+1;
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
N = int(input())  # N日間
A = list(map(int, input().split()))  # i日目の株の値段
money = 1000
stocks = 0
for i in range(N-1):
    # print("本日の値段 : ", A[i])
    # print("現在の現金 : ", money)
    # print("現在の株数 : ", stocks)
    # 次の日に上がるなら有り金全部株と交換する
    if A[i+1] > A[i] and money >= A[i]:
        # i日目に株を買う
        stocks = money // A[i]
        money -= (money // A[i])*A[i]
    # 次の日に下がる&今株を持っているのであれば，全部お金にする
    if A[i+1] < A[i] and stocks > 0:
        money += stocks*A[i]
        stocks = 0
print(money + stocks*A[-1])


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 998244353;
const int N = 1e6+5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,s;
    cin>>n>>s;
    int dp[n+1][s+1];
    int arr[n];
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }

    dp[0][0]=1;
    memset(dp, 0, sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<n;i++) {
        for(int j=0;j<=s;j++) {
            dp[i+1][j]+=2*dp[i][j];
            dp[i+1][j]%=MOD;
            if(j+arr[i]<=s) {
                dp[i+1][j+arr[i]]+=dp[i][j];
                dp[i+1][j+arr[i]]%=MOD;
            }
        }
    }
    cout<<dp[n][s];

    return 0;
}

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

int main() {
	int n;
	long long k;
	int a[200005];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int x[200005];
	int flag[200005] = {0};
	x[0] = 0;
	flag[0] = 1;
	int i = 1;
	for (; i < n; i++) {
		x[i] = a[x[i-1]] - 1;
		if (flag[x[i]] == 0) flag[x[i]] = 1;
		else break;
	}
	if (i == n) {cout << x[k%n]+1 << endl; return 0;}
	int j = 0;
	for (; j < n; j++) {
		if (x[j] == x[i]) break;
	}
	if (k < i) cout << x[k]+1 << endl;
	else cout << x[j + (k - i) % (i - j)]+1 << endl;
	return 0;
}

Measured memory_bytes: 5792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int a,b;
int main(){
	a=read(),b=read();
	if(b==1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=b+100;i++){
		if(i*(a-1)+1>=b){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ld a, b;
    cin >> a >> b;
    b *= 100;
    //cout << a << " " << b << endl;
    cout << (ll)floor(a / 100.0 * b) << endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int b[n];
    rep(i,n)cin >> b[i];
    int c[n-1];
    rep(i,n-1)cin >> c[i];

    int ans = 0;

    rep(i,n){
        ans += b[a[i]];
        if(i!=n-1){
            if(a[i] + 1 == a[i+1]){
                ans += c[a[i]];
            }
        }
    }

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


Measured memory_bytes: 256
import heapq as h

N,Q=map(int,input().split())
a=[0 for i in range(0,N-1)]
b=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    a[i],b[i]=map(int,input().split())
p=[0 for i in range(0,Q)]
x=[0 for i in range(0,Q)]
for i in range(0,Q):
    p[i],x[i]=map(int,input().split())
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[a[i]].append(b[i])
    hen[b[i]].append(a[i])
subscore=[0 for i in range(0,N+1)]
for i in range(0,Q):
    subscore[p[i]]+=x[i]

ans=[0 for i in range(0,N+1)]
flag=[0 for i in range(0,N+1)]
q=[]
q.append(1)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        ans[x]+=subscore[x]
        flag[x]=1
        for p in hen[x]:
            if flag[p]==0:
                h.heappush(sub,p)
                ans[p]=ans[x]
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break
ans[0]=-1
ans.remove(-1)
print(*ans)


Measured memory_bytes: 111308
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;

int main() {

    ll D, G;
    cin >> D >> G;

    vector<int> p(D), c(D);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < (1 << D); mask++) {
        
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < D; i++) {
            
            if (mask >> i & 1) {
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            } else {
                rest_max = i;
            }
        }
        if (s < G) {
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if (need >= p[rest_max]) {
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 100005
#define endl "\n"

ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}

int n,k,h[MAXN],dp[MAXN];

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    rep(i,1,n+1) cin>>h[i];
    rep(i,1,n+1) dp[i]=INT_MAX;
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
            dp[i+j]=min(dp[i+j],abs(h[i+j]-h[i])+dp[i]);
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: [u64;3]
    }

    let mut sm = s;
    sm.sort();
    println!("{}", sm[2] * 10 + sm[1] + sm[0]);
}

Measured memory_bytes: 4352
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int count=0;
		for(int i=0;i<s.length();++i) {
			if (s.charAt(i)=='1')++count;
		}
		System.out.println(Math.min(s.length()-count, count)*2);

	}
	
}


Measured memory_bytes: 25172
def main():
    from sys import stdin
    input = stdin.readline

    n, m, r = map(int, input().split())
    l = list(map(int, input().split()))
    for i in range(r):
        l[i] -= 1
    d = [[10**8] * n for _ in range(n)]
    for _ in range(m):
        i, j, k = map(int, input().split())
        d[i-1][j-1] = k
        d[j-1][i-1] = k

    # Warshall-Floyd algorithm
    for k in range(n):
        for i in range(n-1):
            for j in range(i+1, n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    d[j][i] = d[i][j]

    # full search
    # 8! = 40320
    from itertools import permutations

    answer = 10**8
    for i in permutations(l):
        ans = 0
        for j in range(r-1):
            ans += d[i[j]][i[j+1]]
        if ans < answer:
            answer = ans

    print(answer)

main()


Measured memory_bytes: 74516
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec));
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int,int>
using namespace std;
int n,m;
P p[54];
int tab[54][54];
int d[54][54];
signed main() {
	cin>>n>>m;
	int ans=0;
	rep(i,n) {
		rep(j,n) {
			d[i][j]=inf;
			tab[i][j]=inf;
			if(i==j) {
				d[i][j]=0;
				tab[i][j]=0;
			}
		}
	}
	rep(i,m) {
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		p[i].first=a;
		p[i].second=b;
		tab[a][b]=1;
		tab[b][a]=1;
		d[a][b]=1;
		d[b][a]=1;
	}
	rep(o,m) {
		d[p[o].first][p[o].second]=inf;
		d[p[o].second][p[o].first]=inf;
		rep(k,n) {
			rep(i,n) {
				rep(j,n) {
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		bool can=false;
		rep(i,n-1) {
			if(d[0][i+1]==inf) can=true;
		}
		if(can) ans++;
		rep(i,n) {
			rep(j,n) {
				d[i][j]=tab[i][j];
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
MOD=10**9+7

def facinv(N):
    fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
    fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
    for i in range(2,N+1):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

def dfs(v,p):
    connect[v]=len(G[v])
    dp[v]=[1]*connect[v]
    sizdp[v]=[0]*connect[v]
    for i in range(connect[v]):
        nv=G[v][i]
        if nv==p:
            p_i[v]=i
            continue
        R,siz=dfs(nv,v)
        dp[v][i]=R
        size[v]+=siz
        sizdp[v][i]=siz
    res=fac[size[v]-1]
    for i in range(connect[v]):
        if G[v][i]==p:
            continue
        res=res*dp[v][i]%MOD*finv[sizdp[v][i]]%MOD
    return res,size[v]
    
def reroot(v,res_p,p):
    if p!=-1:
        dp[v][p_i[v]]=res_p
        sizdp[v][p_i[v]]=N-size[v]
    ans[v]=fac[N-1]
    for i in range(connect[v]):
        ans[v]=ans[v]*dp[v][i]%MOD*finv[sizdp[v][i]]%MOD
    dp_L=[1]*(connect[v]+1)
    dp_R=[1]*(connect[v]+1)
    for i in range(connect[v]):
        dp_L[i+1]=dp_L[i]*dp[v][i]%MOD*finv[sizdp[v][i]]%MOD
    for i in reversed(range(connect[v])):
        dp_R[i]=dp_R[i+1]*dp[v][i]%MOD*finv[sizdp[v][i]]%MOD
        
    for i in range(connect[v]):
        nv=G[v][i]
        if nv==p:
            continue

        reroot(nv,fac[N-size[nv]-1]*dp_L[i]*dp_R[i+1]%MOD,v)


N=int(input())
fac,finv,inv=facinv(N)
G=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
dp=[[] for i in range(N)]
sizdp=[[] for i in range(N)]
connect=[-1]*N
size=[1]*N
p_i=[-1]*N
dp_L=[[] for i in range(N)]
dp_R=[[] for i in range(N)]
ans=[1]*N
dfs(0,-1)
reroot(0,1,-1)
print(*ans,sep='\n')

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

int main()
{
	int n, d, x, a;
	cin >> n >> d >> x;
	int ans = x;
	for(int i = 1;i <= n;i++){
		cin >> a;
		ans += (d-1)/a+1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
arr = list(map(int,stdin.readline().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
i=j=n-1
for i in range(n-1,-1,-1):
    for j in range(1,n+1):
        if i>j-1:
            continue
        if ((j-i)%2)^(n%2):
            dp[i][j] = min(-arr[i]+dp[i+1][j],-arr[j-1]+dp[i][j-1])
        else:
            dp[i][j] = max(arr[i]+dp[i+1][j],arr[j-1]+dp[i][j-1])
print(dp[0][n])

Measured memory_bytes: 144904
#include <iostream>
using namespace std;
int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r < 0 || y - r < 0 || x + r > W || y + r > H)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}




Measured memory_bytes: 3100
using static System.Math;
using System.Collections.Generic;
using System;

public class UnionFind
{
    private int[] data;

    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }

    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);

        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    public bool IsSameGroup(int x, int y)
    {
        return Root(x) == Root(y);
    }

    public int Root(int x)
    {
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var k = int.Parse(line[2]);
        var ans = getAns(n, m, k);
        Console.WriteLine(ans);
    }
    public static int getAns (int n , int m , int k)
    {
        var f = new UnionFind(n);
        var d = new Dictionary<int, int>();
        for (int i = 0; i < k; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[1]) - 1;
            var b = int.Parse(line[2]) - 1;
            if (line[0] == "1")
            {
                 var ac = d.ContainsKey(f.Root(a)) ? d[f.Root(a)] : -1;
                var bc = d.ContainsKey(f.Root(b)) ? d[f.Root(b)] : -1;
                if (ac > -1 && bc > -1 && ac != bc )return i + 1;
                f.Unite(a, b);
                d[f.Root(a)] = Max(ac, bc);
            }
            else
            {
                var ac = d.ContainsKey(f.Root(a)) ? d[f.Root(a)] : -1;
                if (ac > -1 && ac != b) return i + 1;
                d[f.Root(a)] = b;
            }
        }
        return 0;
    }
}


Measured memory_bytes: 27140
import java.util.ArrayList;
import java.util.*;
  public class Main
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in); 
		String s=sc.next();
		String s2=sc.next();
		s2=s2.substring(0,s2.length()-1);
		if(s2.contains(s))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 35692
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, C, D;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;

  cout << min(A, B) + min (C, D) << "\n";

  return 0;
}


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

int main() {
 int n;
    cin >> n;
    vector<string> c(n);
    
  rep(i,n) {
   cin >> c[i];
  }
   
    
   vector<string> d(n);
    rep(i,n) {
     d[i] = c[i];
    }
    
   
    
    for(int i = 0; i< n; i++) {
      for(int j =  n-1; j > i ; j--){
          if((int)c[j].at(1) < (int)c[j-1].at(1)) {
           swap(c[j],c[j-1]);
          }
      }
    }
       
    rep(i,n-1) {
         cout << c[i] << ' ';
    }
    cout << c[n-1] << endl;
    cout << "Stable" << endl;
    
    
    
    for(int i = 0; i<n; i++) {
     int minj = i;
    for(int j = i; j < n; j++){
     if((int)d[j].at(1) < (int)d[minj].at(1)) {
      minj = j;
     }
    }
        
    swap(d[i],d[minj]);
    }
          
    bool stable = true;
    rep(i,n) {
     if(c[i] != d[i]){
      stable = false;
     }
    }
    rep(i,n-1) {
         cout << d[i] << ' ';
    }
    cout << d[n-1] << endl;
    if(stable) {
     cout << "Stable" << endl;
    } else {
     cout << "Not stable" << endl;
    }
       
}


Measured memory_bytes: 3188
//Program.cpp
//Problem Statement - 

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

//Author: Varun Goyal (@govarun)

#define f(i, n) for(int i=0;i<(n);++i)
#define fa(i, a, n) for(int i=(a);i<=(n);++i)
#define fd(i, a, n) for(int i=(a);i>=(n);--i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define debug if(GOVARUN) cerr
#define d0(x) debug <<#x<<" = "<<x<<' '
#define d1(x) debug <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
#define endl '\n'
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pair<int, int> > vpii;
inline bool EQ(double a, double b) { 
return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

void pre(){

    
}


void solve();

int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    #ifdef GOVARUN
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else 
    #define GOVARUN 0
    #endif
    int TC = 1;
    // cin >> TC;
    while(TC--){    
        solve();
    }

    return 0;
}

void solve(){
    int n, W; cin >> n >> W;
    int w[n + 1], v[n + 1];
    f (i, n) {
        cin >> w[i +1] >> v[i +     1];
    }
    ll val[n + 1][W + 1];
    fill( val);
    fa (i, 0, n) {
        fa (j, 0, W) {
            if (i == 0 || j == 0) val[i][j] = 0;
            else if (j >= w[i]) {
                val[i][j] = max(val[i - 1][j], val[i - 1][j - w[i]] + v[i]);
            }
            else val[i][j] = val[i - 1][j];
        }
    }
    cout << val[n][W];

}

Measured memory_bytes: 79104
X,N = map(int,input().split())
P = set(list(map(int,input().split())))
if X not in P:
    print(X)
    exit()
i = 1
while 1:
    if X-i not in P:
        print(X-i)
        exit()
    if X+i not in P:
        print(X+i)
        exit()
    i += 1

Measured memory_bytes: 9180
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
const int maxn = 100005;
int A[maxn];
int occur[maxn];
using pii = std::pair<int, int>;
int main() {
  int n; scanf("%d", &n);
  for(int i = 1; i <= n; i ++) {
    scanf("%d", &A[i]);
  }
  for(int i = 1; i <= n; i += 2) {
    occur[A[i]] ++;
  }
  pii o1(0, 0), o2(0, 0);
  for(int i = 1; i <= 100000; i ++) {
    if(occur[i] == 0) continue;
    pii nv(occur[i], i);
    if(nv > o1) {
      o2 = o1; o1 = nv;
    } else if(nv > o2) {
      o2 = nv;
    }
  }
  memset(occur, 0, sizeof(occur));
  for(int i = 2; i <= n; i += 2) {
    occur[A[i]] ++;
  }
  pii e1(0, 0), e2(0, 0);
  for(int i = 1; i <= 100000; i ++) {
    if(!occur[i]) continue;
    pii nv(occur[i], i);
    if(nv > e1) {
      e2 = e1; e1 = nv;
    } else if(nv > e2) {
      e2 = nv;
    }
  }
  int ans = 0;
#ifdef LOCAL
  printf("odd : (%d, %d) (%d, %d)\n", o1.first, o1.second, o2.first, o2.second);
#endif
  if(e1.second != o1.second) {
    ans = e1.first + o1.first;
  } else {
    ans = std::max(e1.first + o2.first, e2.first + o1.first);
  }
  ans = n - ans;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 896