akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
using namespace std;
int main() {
  int N;
  std::cin >> N;
  map<string, int> S;
  std::string a;
  for (size_t i = 0; i < N; i++) {
    std::cin >> a;
      if (!S.count(a)) {
        S[a] = 1;
      }
  }
  std::cout << S.size() << '\n';
}


Measured memory_bytes: 19224
import heapq

n, m = [int(i) for i in input().split()]
inf = 10**10
path = [[0] * n for _ in range(n)]
Q = [[inf] * n for _ in range(n)]
ans = 0
pathnum = []

for i in range(m):
    a, b, c = map(lambda x: int(x)-1 ,input().split())    
    path[a][b] = path[b][a] = c+1
    pathnum.append((a,b))

for i in range(n):
    decided = [False for _ in range(n)]
    H = []
    ctr = 0
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    while ctr != n:
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                ctr += 1
                break
        for j in range(n):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

for i in pathnum:
    if Q[i[0]][i[1]] == inf:
        continue
    elif Q[i[0]][i[1]] != path[i[0]][i[1]]:
        ans += 1
print(ans)
    

Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int n, pos;
vector<int> pre, in;
int flg;
void rec(int l, int r) { //reconstruct
    if (l >= r) return;
    int c = pre[pos++];
    int m = (int)distance(in.begin(), find(in.begin(), in.end(), c));
    rec(l, m);
    rec(m + 1, r);
    if (flg) cout << " ";
    flg = 1;
    cout << c;
    
}
int main() {
    cin >> n;
    rep(i, n) {int v; cin >> v; pre.push_back(v);}
    rep(i, n) {int v; cin >> v; in.push_back(v);}
    rec(0, (int)pre.size());
    cout << endl;
}



Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

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

using namespace std;

typedef unsigned int uint;
typedef long long ll;

struct inc{
  void operator() (char &c){
    if(isalpha(c)){
      if(islower(c))
	c = (((c - 'a') + 1) % ('z'-'a'+1)) + 'a';
      else
	c = (((c - 'A') + 1) % ('Z'-'A'+1)) + 'A';
    }
  }
};

int main(){
  string str;
  while(getline(cin, str)){
    bool f = true;
    while(f){
      for_each(str.begin(), str.end(), inc());
      stringstream ss(str);
      string tmp;
      while(ss>>tmp)
	if(tmp == "the" || tmp == "this" || tmp == "that" ||
	   tmp == "THE" || tmp == "THIS" || tmp == "THAT"){
	  cout << str << endl;
	  f = false;
	  break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(void){
  char s[101],t[101];
  scanf("%s %s",s,t);
  printf("%s%s\n",t,s);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
ret = 0
def count(nega):
  ret = 0
  s = 0
  for e in A:
    nega = not nega
    #print(e,ret,s,s+e)
    if nega and 0 <= s + e:
      ret += abs(s + e) + 1
      s = -1
    elif not nega and s + e <= 0:
      ret += abs(s + e) + 1
      s = 1
    else:
      s += e
  return ret
print(min(count(True),count(False)))


Measured memory_bytes: 14332
#include <stdio.h>

int main() {
  int n, a, min = 1000000, max = -1000000;
  long long sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a < min) min = a;
    if (a > max) max = a;
    sum += a;
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

struct data{
public:
    int pos;
    int a;
    int b;
    int c;
    bool operator<(const data &another) const
    {
        return c > another.c;//年齢を比較
    };
};

static int compare(const void*a,const void*b){
    int anum = *(int*)a;
    int bnum = *(int*)b;
    return anum - bnum;
}
void swap(int *x, int *y){
  int temp;
  temp = *x;
  *x = *y;
  *y  = temp;
}

int main(){
    long ans=0;
    int n;
    cin >> n;
    data d[n];
    //int a[n][3];//,b[n],c[n];
    for(int i=0;i<n;i++){
        cin >> d[i].a >> d[i].b;
        d[i].c=d[i].a+d[i].b; 
        
    }
    /*for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i][2]<a[j][2]){
                swap(a[i][0],a[j][0]);
                swap(a[i][1],a[j][1]);
                swap(a[i][2],a[j][2]);
            }
        }
    }*/
    sort(d,&d[n]);

    for(int i=0;i<n;i++){
        //cout << d[i].a;
        if(i%2==0)ans+=d[i].a;
        else ans -= d[i].b;
        //cout << ans;
    }
    //cout << endl;

    cout << ans << endl;


}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
int main(){
  char c;
  cin>>c;
  switch(c){
    case 'A':
      cout<<'T'<<endl;
      break;
    case 'T':
      cout<<'A'<<endl;
      break;
    case 'G':
      cout<<'C'<<endl;
      break;
    case 'C':
      cout<<'G'<<endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  string S;
  cin >> S;
  REP(i, S.size()) { cout << (char)((S[i] - 'A' + N) % 26 + 'A'); }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n, tmp = 0;
    cin >> n;
    vi a(n);
    rep(i, n){
        cin >> a[i];
        if(a[i]==tmp + 1){
            tmp++;
        }
    }
    if(tmp == 0)cout<< -1 <<endl;
    else cout << n - tmp <<endl;
}

Measured memory_bytes: 1024
def main():
    from collections import deque
    N = int(input())
    A = [int(i) for i in input().split()]
    B = deque()
    if N & 1:
        for i, a in enumerate(A):
            if i & 1:
                B.append(a)
            else:
                B.appendleft(a)
    else:
        for i, a in enumerate(A):
            if i & 1:
                B.appendleft(a)
            else:
                B.append(a)
    print(*B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99000
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)

	if n == 0 {
		fmt.Print(s)
		return
	}

	alf := []string{
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
	}

	ss := strings.Split(s, "")

	for _, s := range ss {
		index := 0
		for i, a := range alf {
			if s == a {
				if i+n <= 25 {
					index += i + n
					break
				} else {
					fowerd := 25 - i
					rem := n - fowerd
					index += rem - 1
					break
				}
			}
		}
		fmt.Print(alf[index])
	}

}


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

#define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 1000000> A;;
  // string S;
  // string T;

  array<string, 100> W;
  bool flag = true;

  cin >> N;

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

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

    if (i > 0) {
      if (W[i-1][W[i-1].length() - 1] != W[i][0]) {
        flag = false;
        break;
      }
    }

    for (int j = 0; j < i; ++j) {
      if (W[j] == W[i]) {
        flag = false;
        break;
      }
    }
  }

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 2501;
const int MAX_E = 5001;

struct edge {
  int from, to, cost;
};

// 辺
edge es[MAX_E];
// 最短距離
int d[MAX_V];
int V, E;
int P;

vector<int> to[2501];
vector<int> rto[2501];
bool ok[2501];
bool rok[2501];

void dfs(int s) {
  if (ok[s]) {
    return;
  }
  ok[s] = true;
  for (int i = 0; i < to[s].size(); i++) {
    dfs(to[s][i]);
  }
}

void rdfs(int s) {
  if (rok[s]) {
    return;
  }
  rok[s] = true;
  for (int i = 0; i < rto[s].size(); i++) {
    rdfs(rto[s][i]);
  }
}

bool bellman_ford(int s) {
  fill(d, d + V, INF);
  d[s] = 0;

  for (int i = 0; i < V - 1; i++) {
    for (int j = 0; j < E; j++) {
      edge e = es[j];
      if (d[e.from] == INF) {
        continue;
      }
      // if (ok[e.from] && rok[e.from]) {
      d[e.to] = min(d[e.to], d[e.from] + e.cost);
      //}
    }
  }

  for (int j = 0; j < E; j++) {
    edge e = es[j];
    if (d[e.from] == INF) {
      continue;
    }
    if (d[e.from] + e.cost < d[e.to]) {
      if (ok[e.from] && rok[e.from]) {
        return false;
      }
    }
  }

  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E >> P;
  for (int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    es[i] = edge{a, b, P - c};
    to[a].push_back(b);
    rto[b].push_back(a);
  }

  // 0からの経路があるか
  dfs(0);
  // V-1への経路があるか
  rdfs(V - 1);

  bool flag = bellman_ford(0);
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }

  int ans = max(-d[V - 1], 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
/******************************************
 	AUTHOR : PRATIK 
 INSTITUTION : BITS PILANI HYDERABAD CAMPUS 
******************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef multiset<int> ms;
typedef set<int> s;
typedef vector<double> vid;
typedef multiset<double> msd;
typedef set<double> sd;
#define sp setprecision 
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void fastscan(ll &number)
{
    //variable to indicate sign of input number
    bool negative = false;
    register int c;
 
    number = 0;
 
    // extract current character from buffer
    c = getchar();
    if (c=='-')
    {
        // number is negative
        negative = true;
 
        // extract the next character from the buffer
        c = getchar();
    }
 
    // Keep on extracting characters if they are integers
    // i.e ASCII Value lies from '0'(48) to '9' (57)
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
 
    // if scanned input has a negative sign, negate the
    // value of the input number
    if (negative)
        number *= -1;
}
 
// Function Call

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
   ll t;
   cin>>t;

   ll y=t;
   ll A[t];
   ll i=1;
   cin>>A[0];
   ll min=A[0];
   ll max=A[0];
   y--;
   while(y--)
{
       cin>>A[i++];
       if(min>=A[i-1])  min=A[i-1];
       if(max<=A[i-1])  max=A[i-1];
   }
   cout<<max-min;
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long int h,n,s=0;
  cin >> h >> n;
  for(int i=0;i<n;i++){
       int x; cin >> x;
       s += x;
  }
  if(s>=h) puts("Yes");
  else puts("No");
}


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

int main() {
  int n, m;
  cin>>n>>m;
  int a[n];
  for (int i=0; i<n; i++) {
    cin>>a[i];
    a[i] %= m;
  }
  long long acc[n];
  acc[0] = a[0];
  for (int i=1; i<n; i++) {
    acc[i] = acc[i-1] + a[i];
  }
  map<long long, int> mods;

  long long ans = 0;
  mods[0] = 1;
  for (int i=0; i<n; i++) {
    long long mod = acc[i] % m;
    if (mods.find(mod) != mods.end()) {
      ans += mods[mod];
    }
    ++mods[mod];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
    int ans[100000]={0};
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                ans[((i+j)*(i+j)+(i+k)*(i+k)+(j+k)*(j+k))/2]++;
            }
        }
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4004
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  string N;
  int K;
  while (cin >> N >> K) {
    int sz = N.size();
    vec<ll, 3> dp = make_v(sz + 1, 2, K + 2, 0ll);
    dp[0][0][0] = 1;
    for (int i = 0; i < sz; i++) {
      int cur = N[i] - '0';
      for (int less = 0; less < 2; less++) {
        for (int k = 0; k <= K; k++) {
          for (int d = 0; d < 10; d++) {
            if (d <= cur || less) {
              dp[i + 1][(d < cur) | less][k + (d != 0)] += dp[i][less][k];
            }
          }
        }
      }
    }
    cout << (dp[sz][0][K] + dp[sz][1][K]) << endl;
  }
  return 0;
}


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

struct Edge {
  int to;
  Edge(int to) : to(to) {}
};

using Graph = vector< vector<Edge> >;

vector<bool> used;

void init(int n) {
  used.assign(n,false);
}

int dfs(Graph& G, int v, int p) {
  int res = 1;
  used[v] = true;
  for (auto e : G[v]) {
    if (used[e.to] || e.to == p) continue;
    res += dfs(G,e.to,v);
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph G(n);
  rep(i,m) {
    int a, b; cin >> a >> b; a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  init(n);
  int ans = 0;
  rep(i,n) if (!used[i]) ans = max(ans,dfs(G,i,-1));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 29920
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<ctime>
#include<map>
#include<queue>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<stack>

using namespace std;


	long long dp[262144*2+5990];
	#define beg 262144
	long long hig[200900];
	long long val[200090];
	
	long long sumsum(int l , int r){
		
		long long sss = 0;
		
		while( l <= r ){
			
			if(l % 2 != 0){
				sss = max(sss,dp[l]);
				l++;
			}
			if(r % 2 == 0){
				sss = max(sss,dp[r]);
				r--;
			} l/=2; r/=2;
			
		}
		
		return sss;
		
	}

int main(){
	
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> hig[i];
	for(int i = 0; i < n; i++) cin >> val[i];
	
	long long sol = 0;
	for(int i = 0; i < n; i++){
		
		dp[hig[i] + beg] = max(dp[hig[i] + beg], sumsum(beg,beg + hig[i] - 1) + val[i]); 
		
		int node = hig[i] + beg; node/=2;
		while(node > 0){
			dp[node] = max(dp[node*2],dp[node*2+1]);
			node/=2;
		}
		
		sol = max(sol,dp[hig[i] + beg]);	
	}
	
	cout << sol;


return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
/*
alias g='g++ -std=c++17 -O2 pra.cpp'
alias a='./a.out'
cd programming
cd cpp
cd practice

*/
/*
clock_t start = clock();
処理
cout<<"cpu時間: "<<(double)(end-start)/CLOCKS_PER_SEC<<"秒"<< endl;
clock_t end = clock();
*/
#define rep(i, n) for(int i=0; i<(n); i++)
//if (i) cout << " "; で最初のみ空白文字を出力することができる
#define Sort(v) sort((v).begin(), (v).end())
#define pb push_back
using veci = vector<int>;
veci pre, in, ans;
int pos=0;
void reconstruction(int l, int r, int n){
    if (r <= l) return;
    int root = pre[pos];
    pos++;
    int d=distance(in.begin(), find(in.begin(), in.end(), root));//inの中からrootと同じ値を見つけて、そのイテレータを返す
    reconstruction(l, d, n);//まず左側から分割していく
    reconstruction(d+1, r, n);
    ans.pb(root);//根までいくのは分割した部分が全てリターンされたとき
}
int main(){
    int n; cin >> n;
    int m;
    rep(i, n){
        cin >> m;
        pre.pb(m);
    }
    rep(i, n){
        cin >> m;
        in.pb(m);
    }
    reconstruction(0, n, n);
    rep(i, n){
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll a, b, c; cin >> a >> b >> c;
  ll lhs = 4 * a * b;
  ll rhs = (c - a - b) * (c - a - b);

  if (c - a - b <= 0) {
    cout << "No" << endl;
    return 0;
  } 

  if (lhs < rhs) cout << "Yes" << endl; 
  else cout << "No" << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>

using lli = long long int;
lli inf = 1000000007;
using namespace std;

void solve()
{
	string s;
	cin >> s;
	if (s.length() == 2) {
		if (s[0] == s[1]) { cout << "1 2" << endl; }
		else { cout << "-1 -1" << endl; }
		return;
	}
	for (int i = 0; i < s.length() - 2; i++) {
		if (s[i] == s[i + 1] ||
			s[i] == s[i + 2] ||
			s[i + 1] == s[i + 2]) {
			cout << (i + 1) << " " << (i + 3) << endl;
			return;
		}
	}
	cout << -1 << " " << -1 << endl;
}

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

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

using namespace std;

int main()
{
    long long int n, k;
    cin >> n >> k;

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

    if (k < n + 1)
    {
        int nresult = 1;
        for (int i = 0; i < k; i++)
        {
            nresult = a[nresult - 1];
        }
        cout << nresult << endl;
        return 0;
    }
    int nresult = 1;
    for (int i = 0; i < n + 1; i++)
    {
        nresult = a[nresult - 1];
    }
    int temp = 1;
    int firstnresult;
    for (int i = 0; i < n + 1; i++)
    {
        if (temp == nresult)
        {
            firstnresult = i;
            break;
        }
        temp = a[temp - 1];
    }
    int amari = (k - firstnresult) % (n + 1 - firstnresult);
    int res = nresult;
    for (int i = 0; i < amari; i++)
    {
        res = a[res - 1];
    }
    cout << res << endl;
    return 0;
}

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

#define MOD 1000000007

long long mul_mod(long long x, long long y, long long mod)
{
    return (x * y) % mod;
}

long long factorial_mod(long long a, long long mod)
{
    long long ans = 1;
    for (int i = 2; i <= a; i++)
    {
        ans = mul_mod(ans, i, mod);
    }
    return ans;
}

int main()
{
    long long N, M;
    cin >> N >> M;
    if (N > M)
    {
        swap(N, M);
    }

    if (M - N > 1)
    {
        cout << 0 << endl;
        return 0;
    }

    long long ans = factorial_mod(N, MOD);
    ans = mul_mod(ans, factorial_mod(M, MOD), MOD);
    if (N == M)
    {
        ans = mul_mod(ans, 2, MOD);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a % b)


@mt
def slv(A, B):
    ad = [v for v in divisor(A)]
    bd = [v for v in divisor(B)]
    cd = list(set(ad) & set(bd))
    cd.sort()
    ans = [1]
    for i in range(1, len(cd)):
        for j in range(1, i):
            if cd[i] % cd[j] == 0:
                break
        else:
            ans.append(cd[i])
    
    return len(ans)




def main():
    A, B = read_int_n()
    print(slv(A, B))

    # A = random.randint(10**11, 10**12)
    # B = random.randint(10**11, 10**12)
    # print(A, B)
    # print(slv(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7628
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
struct UnionFind
{
    V<int> par;
    V<int> siz;
    UnionFind(int n) : par(n), siz(n, 1)
    {
        rep(i, n) par[i] = i;
    }
    int root(int x)
    {
        while (par[x] != x) x = par[x] = par[par[x]];
        return x;
    }
    bool unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) false;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return true;
    }
    int same(int x, int y)
    {
        return root(x) == root(y);
    }
};

#pragma endregion RegionDefs

void solve()
{
    IN(a, b);
    cout << max(0, a - 2*b) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  int cnt = 0;
  int ans;
  for (int i = A; i >= 1; i--) {
    if (A % i == 0 && B % i == 0) cnt++;
    if (cnt == K) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
//-----by LY02------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//------------------------------------------------


int a[100010],b[100010],c[100010];
int dp[100010][3];
//------------------------------------------------
int main() {
//------------------------------------------------
//	freopen("In.txt","r",stdin);
//	freopen("Out.txt","w",stdout);
//------------------------------------------------
	ios::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------
int n;
cin>>n;
for(int i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
	
dp[0][0]=a[0];
dp[0][1]=b[0];
dp[0][2]=c[0];
for(int i=1;i<n;i++)
{
	dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
	dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
	dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
}

cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;


//------------------------------------------------
	return 0;
}





//-----by LY02------------------------------------


Measured memory_bytes: 2560
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    p=[list(map(int,input().split())) for i in range(m)]
    for i in range(1,m):
        for j in range(n):
            p[i][j]+=p[i-1][j]
    print(max(p[m-1]))


Measured memory_bytes: 7672
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from functools import lru_cache

N,M = II()
A = III()
num = [0]*10
num[1],num[2],num[3],num[4],num[5] = 2,5,5,4,5
num[6],num[7],num[8],num[9] = 6,3,7,6

@lru_cache(maxsize=10**5)
def rec(n):
    val = []
    for i in range(M):
        if n-num[A[i]] < 0:
            continue
        elif n-num[A[i]] == 0:
            val.append(A[i])
        else:
            if rec(n-num[A[i]])>0:
                val.append(10*rec(n-num[A[i]])+A[i])
    if val:
        return max(val)
    else:
        return -1

print(rec(N))

Measured memory_bytes: 121432
import math
N = int(input())
sorted_map = {}

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
    inserted_flag = True
    input_sorted = ''.join(sorted(input()))
    if input_sorted in sorted_map.keys():
        sorted_map[input_sorted] += 1
        inserted_flag = False
    if inserted_flag:
        sorted_map[input_sorted] = 1

count = 0
for count_num in sorted_map.values():
    if count_num == 1:
        continue
    count += combinations_count(count_num, 2)
print(count)

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

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

    int count=0; int height=h[0];
    int max_count=0;
    for(int i=1; i<n; i++){
        if(height>=h[i]){
            count++; height = h[i];
        }else{
            if(count>max_count)
                max_count = count;
            count =0 ;
            height = h[i];
        }
    }
    if(count > max_count)
        max_count = count;
    cout << max_count << endl;

    return 0;
}

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

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int n, m;
    int[] a, b, c;
    int x;
    long ans;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        m = int.Parse(input[1]);
        a = new int[n];
        b = new int[m];
        c = new int[m];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++) a[i] = int.Parse(input[i]);

        for (int i = 0; i < m; i++)
        {
            input = Console.ReadLine().Split(' ');
            b[i] = int.Parse(input[0]);
            c[i] = int.Parse(input[1]);
        }

        Array.Sort(a);
        Array.Sort(c, b);
        x = 0;
        ans = 0;
        for(int i = m - 1; i > -1; i--)
        {
            for(int j=0; j<b[i]; j++)
            {
                if(x >= n)
                {
                    i = -1;
                    break;
                }
                if(c[i] > a[x])
                {
                    a[x] = c[i];
                    x++;
                }
                else
                {
                    i = -1;
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            ans += a[i];
            DebugWL(a[i]);
        }

        Console.WriteLine(ans);
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 30388
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    string s;
    cin>>s;
    if(s=="RRR")
    cout<<3;
    else if(s=="RRS" || s=="SRR")
    cout<<2;
    else if(s=="RSS" || s=="SSR" || s=="RSR" || s=="SRS")
    cout<<1;
    else
    cout<<0;

}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, d;
    cin>>n>>d;
    int cnt=0;
    int x, y;
    for(int i=0; i<n; i++){
        cin>> x >> y;
        if(sqrt(pow(x, 2) + pow(y, 2)) <= d){
            cnt++;
        }
    }
    cout<< cnt << endl;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    int64_t ans = 0;
    if (x % y == 0) ans = -1;
    else ans = x;
    cout << ans << endl;
}

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

int main(){
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	ll an = 0, d = abs(a - b);
	if (d & 1)an = min(min(a - 1, n - a), min(b - 1, n - b));
	an += d + 1 >> 1;
	printf("%lld\n", an);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int cost,num,sum=0,avg=0,i=0;

	while(scanf("%d,%d",&cost,&num)!=EOF){
		sum+=cost*num;
		avg+=num;
		i++;
	}
	printf("%d\n%d\n",sum,(int)((double)avg/(double)i+0.5));

	return 0;
}

Measured memory_bytes: 588
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007// prime modulo value 
#define C 1000000001
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<double> arr(n, 0.0);
	f(i, 0, n)
		cin >> arr[i];
	double deno = 0;
	double lcm = arr[0];
	f(i, 1, n)
	{
		lcm = (lcm * arr[i]) / gcd(lcm, arr[i]);
	}
	f(i, 0, n)
	{
		deno += (lcm / arr[i]);
	}
	double ans = lcm / deno;
	cout << ans;
	return 0;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    int n;
    cin >> n;
    ll sum = 0;
    map<ll, ll> cnt;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        sum += x;
        cnt[x]++;
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        sum -= cnt[a] * a;
        sum += cnt[a] * b;
        cout << sum << '\n';
        cnt[b] += cnt[a];
        cnt[a] = 0;
    }
    return 0;
}
// Write Here


Measured memory_bytes: 9432
n=list(input())
l=[]
for i in n:
    for j in range(68,91):
        if i == chr(j):
            m = chr(j-3)
            l.append(m)
    if i == 'A':
        m = 'X'
        l.append(m)
    elif i == 'B':
        m = 'Y'
        l.append(m)
    elif i == 'C':
        m = 'Z'
        l.append(m)
print(''.join(l))
    



Measured memory_bytes: 5568
N,M = map(int, input().split())
H = [int(i) for i in input().split()]
edge = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans = 0
for v in range(N):
    flag = False
    for w in edge[v]:
        if H[v] <= H[w]:
            flag = True
            break
    if flag: continue
    ans += 1

print(ans)

Measured memory_bytes: 92756
n,a,b=map(int,input().split())
M=10**9+7
def c(k):
  s=t=1
  for i in range(k): s=s*(n-i)%M; t=t*(i+1)%M
  return s*pow(t,M-2,M)%M
print((pow(2,n,M)-c(a)-c(b)-1)%M)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))

minabs = 10 ** 9
numneg = 0

for i in range(N):
    if A[i] < 0:
        numneg += 1
        A[i] *= -1

    minabs = min(minabs, A[i])

print(sum(A) if numneg % 2 == 0 else sum(A) - 2 * minabs)


Measured memory_bytes: 14224
N, T = map(int,input().split())
A = list(map(int,input().split()))
m = [0]*N
M = [0]*N
m[0] = A[0]
for k in range(1,N):
    m[k] = min(A[k],m[k-1])

M[-1] = A[-1]
for k in range(N-2,-1,-1):
    M[k] = max(A[k],M[k+1])

D = [M[k]-m[k] for k in range(N)]
P = max(D)

ans = 0
for k in range(N):
    if A[k]-m[k] == P:
        ans += 1
print(ans)


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

using namespace std;

typedef long long ll;


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    ll ret = 0;
    for(ll i = 1 ; i <= N ; ++i){
        ret += i * (N+1-i);
    }
    for(ll i = 0; i < N-1 ; ++i){
        ll u, v;
        cin >> u >> v;
        ret -= (min(u, v) * (N+1 - max(u, v)));
    }
    cout << ret << endl;

    return 0;


}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define MAX 100010
using namespace std;
int P[MAX];
int main() {
  int N; cin >> N;
  REP(i,1,N+1)
    cin >> P[i];
  int ans = 0;
  REP(i,1,N+1) {
    if (i != P[i]) {
      continue;
    } else {
      int tmp1 = P[i];
      int tmp2 = P[i+1];
      P[i]   = tmp2;
      P[i+1] = tmp1;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;
    while(cin>>n,n){
        ll a[5010];
        ll dp[5010];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll ans=-LINF;
        for(int j=0;j<n;j++){
            if(dp[j]<0){
                dp[j+1]=a[j];
            }else{
                dp[j+1]=dp[j]+a[j];
            }
            ans=max(dp[j+1],ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}




Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Double[] list = Arrays.stream(sc.nextLine().split(" ")).map(Double::parseDouble).toArray(Double[]::new);
            System.out.println((float)((list[2]-list[0])*(list[6]-list[4]))+(float)((list[3]-list[1])*(list[7]-list[5]))==0.0?"YES":"NO");
        }
    }
}



Measured memory_bytes: 32376
h, w, k = (int(i) for i in input().split())

slist=[]
for i in range(h):
    alist = input()
    slist.append(alist)
#print(slist[2])

right=0
for i in range(w):
    swit=0
    for j in range(h):
        if slist[j][i]=='#':
            swit=1
    if swit==1:
        right=i

#print(right)

ans=[]

for i in range(h):
    ans.append([0]*w)
#print(ans)

bef=-1
now=0
eswit=0

for i in range(w):
    swit=0
    
    for j in range(h):
        if slist[j][i]=='#':
            swit+=1
    if swit>=1:
        if i==right:
            eswit=1
        now+=1
        switt=0
        nlist=[]
        for j in range(h):
            if slist[j][i]=='#':
                if switt==1:
                    now+=1
                else:
                    switt=1
            #ans[j][i]=now
            #print(i, bef)
            if bef==-1:
                hani=i-bef
            else:
                hani=i-bef
            if eswit==0:
                for k in range(hani):
                    #print(j, i-k, now)
                    ans[j][i-k]=now
            else:
                for k in range(hani+w-right-1):
                    #print(j, i-k, now)
                    ans[j][i-k+w-right-1]=now
        bef=i

#print(ans)

for i in range(h):
    for j in range(w):
        if j!=w-1:
            print(ans[i][j], end=" ")
        else:
            print(ans[i][j])

Measured memory_bytes: 54104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
int main(){
  int n;
  cin >> n;
  int tmp = (n + 999) / 1000;
  cout << tmp * 1000 - n << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>

int solve(int , int);

int n, str1[200],str2[200];

int main(){
  
  int i, j, k, m;

  scanf("%d",&n);

  for( i = 0; i < n; i++) scanf("%d", &str1[i]);

  scanf("%d",&m);

  for( i = 0; i < m; i++){

    scanf("%d", &str2[i]);

  }    
  for( i = 0; i < m; i++){

     if( solve( 0, str2[i]) == 1) printf("yes\n");

    else if( solve( 0, str2[i]) == 0) printf("no\n");
  
}
  return 0;
}

     
int solve( int i, int m){

  int res;

  if( m == 0) return 1;

  if( i >= n) return 0;

  res = solve( i + 1, m) || solve( i + 1, m - str1[i]);

  return res;
}

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

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;

	int count = 0;
	string t = "";
	string u = "";


	for (int i = 0; i < q; i++) {
		int f;
		cin >> f;

		if (f == 1) {
			count++;
		}

		else {
			int a;
			string b;
			cin >> a >> b;

			if (a == 1) {
				if (count %2==0) {
					t += b;
				}
				else {
					u += b;
				}
			}
			else {
				if (count % 2 == 0) {
					u += b;
				}
				else {
					t += b;
				}
			}
		}

	}


	reverse(t.begin(),t.end());
	string k = t + s + u;

	if (count % 2 == 1) {
		reverse(k.begin(), k.end());
	}

	cout << k << endl;
	return 0;
}


Measured memory_bytes: 4324
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
/*メンチン待ちクイズ*/
void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool ck = true;
    if(n % 2 != 0){
        cout << "No" << endl;
    }
    else{
        for(int i = 0; i < n / 2; i++){
            if(s.at(i) != s.at(i + n / 2)){
                ck = false;
                break;
            }
        }
        if(ck){
            cout << "Yes" << endl;
        }
        else 
        cout << "No" << endl;
    }

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


Measured memory_bytes: 256
s = input("")
if s[0] == s[1] and s[1] != s[2] and s[2] == s[3]:
  print("Yes")
elif s[0] == s[2] and s[2] != s[1] and s[1] == s[3]:
  print("Yes")
elif s[0] == s[3] and s[3] != s[1] and s[1] == s[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8992
import java.util.Scanner;
class Main {
	public static void main(String args[]) {
		char[] Alphabet = new char[26];
		Scanner sc = new Scanner(System.in);
		String buf = sc.nextLine();
		sc.close();
		char moji = buf.charAt(0);
		Alphabet[0] = 'a';
		Alphabet[1] = 'b';
		Alphabet[2] = 'c';
		Alphabet[3] = 'd';
		Alphabet[4] = 'e';
		Alphabet[5] = 'f';
		Alphabet[6] = 'g';
		Alphabet[7] = 'h';
		Alphabet[8] = 'i';
		Alphabet[9] = 'j';
		Alphabet[10] = 'k';
		Alphabet[11] = 'l';
		Alphabet[12] = 'm';
		Alphabet[13] = 'n';
		Alphabet[14] = 'o';
		Alphabet[15] = 'p';
		Alphabet[16] = 'q';
		Alphabet[17] = 'r';
		Alphabet[18] = 's';
		Alphabet[19] = 't';
		Alphabet[20] = 'u';
		Alphabet[21] = 'v';
		Alphabet[22] = 'w';
		Alphabet[23] = 'x';
		Alphabet[24] = 'y';
		Alphabet[25] = 'z';
		int i = 0;
		while(Alphabet[i] != moji) {
			i++;
		}
		System.out.print(Alphabet[i+1]);
	}
}

Measured memory_bytes: 23124