akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a,b,c;
        a = input.nextInt();
        b = input.nextInt();
        c = input.nextInt();
        int array[] = {a,b,c};
        boolean flag = false;
        int tmp;
        while(true) {
            if(flag){
                break;
            }
            flag = true;
            for (int i = 1; i < array.length; i++){
                if (array[i-1] > array[i]){
                    flag = false;
                    tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                }
            }
        }
        for (int i = 0; i < array.length; i++){
            if (i == array.length - 1){
                System.out.printf("%d\n",array[i]);
            } else {
                System.out.printf("%d ",array[i]);
            }
        }
    }
}


Measured memory_bytes: 26356
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int w[105];
int p[105];
int main()
{
    int n,i,t;
    cin>>n;
    for(i=1; i<=n; i++)
        cin>>w[i];
    for(t=1; t<n; t++)
    {
        int s1=0,s2=0;
        for(i=1; i<=t; i++)
            s1+=w[i];
        for(i=n; i>t; i--)
            s2+=w[i];
        p[t]=abs(s1-s2);
    }
    int Min=p[1];
    for(t=2;t<n;t++)
        Min=min(Min,p[t]);
    cout<<Min<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N, Q;
string S;
int l[MAX], r[MAX];
int dp1[MAX], dp2[MAX];

void solve() {
    REPR (i, N-1) {
        dp1[i] = dp1[i+1];
        if (S[i] == 'A' && S[i+1] == 'C') {
            dp1[i]++;
            dp2[i+1]++;
        }
        dp2[i] = dp2[i+1];
    }
    REP (q, Q) {
        cout << dp1[l[q]-1] - dp2[r[q]] << endl;
    }
}

int main() {
    cin >> N >> Q >> S;
    REP (i, Q) cin >> l[i] >> r[i];
    solve();
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()

{
    long long int k;
    string s;
    cin >> s;
    cin >> k;
    long long int ans = 1;
    long long int max = 5000000000000000;
    for (long long int i = 0; i < s.size(); i++)
    {
        if (s[i] != '1')
        {
            if (i <= k - 1)
            {
                cout << s[i];
            }
            return 0;
        }
        else
        {
            if (i == k - 1)
            {
                cout << '1';
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const double INF = 1e9;

struct Dat{
  int vw, pf, vf, th;
  Dat(){}
  Dat(int a, int b, int c, int d):
	vw(a),pf(b),vf(c),th(d){}
  double f() const{
	return (vw==0? -INF: th*1./vw);
  }
  bool operator<(const Dat& dat) const{
	return f() < dat.f();
  }
};

double f(double w, double pw, vector<Dat>& vd){
  double ans = w*pw;
  REP(i,SZ(vd))
	ans += max(vd[i].pf*1./vd[i].vf*(vd[i].th-w*vd[i].vw), 0.);
  return ans;
}

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

  int N;
  while(cin>>N,N){
	int pw; cin >> pw;

	vector<Dat> var;
	VI vw(N), pf(N), vf(N), th(N);
	REP(i,N){
	  cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
	  var.emplace_back(vw[i],pf[i],vf[i],th[i]);
	}

	double lb = 0., ub = 1000.;
	double ans = INF;
	REP(i,100){
	  double lx = (lb*2+ub)/3.;
	  double rx = (lb+ub*2)/3.;
	  double ly = f(lx, pw, var);
	  double ry = f(rx, pw, var);
	  if(ly < ry)
		ans = min(ans, ly), ub = rx;
	  else
		ans = min(ans, ry), lb = lx;
	}
	  
	cout << fixed << setprecision(9) << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 6416
#include<stdio.h>
int main(void)
{
    int N,i,a,b=0,c=0;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&a);
        b+=a;
        if(c<a)c=a;
    }
    if(b<=(2*c))printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 1732
public class Hello{
    public static void Main(){
        // Your code here!
        var N = System.Console.ReadLine();
        var sum = 0;
        var c = N.ToCharArray();
        for (var i = 0; i < c.Length; i++)
        {
            sum += int.Parse(c[i].ToString());
        }
        if (sum % 9 == 0)
        {
            System.Console.WriteLine("Yes");
        }
        else
        {
            System.Console.WriteLine("No");
        }
    }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2==0)cout<<s[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007

bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[900005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;
    // cout << node << "\n";
    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}

int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
void process2(int A[], int N)
{
    int i, j;

    //initialize M for the intervals with length 1
    for (i = 0; i < N; i++)
        M[i][0] = i;
    //compute values from smaller to bigger intervals
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (A[M[i][j - 1]] < A[M[i + (1 << (j - 1))][j - 1]])
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
//int parent[200005];
vector<int> vec1;
//bool vis[200005];
//int hei[200005];
int lev[200005];
int dis[200005];
bool cmp(pair<int, int> &a,
         pair<int, int> &b)
{
    return a.second < b.second;
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    //  int t;
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2)
        cout << "Odd"
             << "\n";
    else
    {
        cout << "Even"
             << "\n";
    }

    return 0;
}


Measured memory_bytes: 50492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define rep2(i, a, b) for(int i=a; i<=(int)(b); ++i)
#define all(v) v.begin(),v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> g(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  rep(from, n) {
    bool ok = true;
    for   (int to : g[from]) {
      if (h[to] >= h[from]) {
        ok = false;
        break;
      }
    }
    if (ok) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8752
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[tuple(map(int,input().split())) for i in range(M)]
A=sorted(A)
BC=sorted(BC,key=lambda x:x[1])
lim=min(M,N)
i=0
j=0
while i<M and j<N:
  if A[j]<BC[M-1-i][1]:
    for b in range(BC[M-1-i][0]):
      if A[j]<BC[M-1-i][1]:
        A[j]=BC[M-1-i][1]
        j+=1
        if j>N-1:
          break
      else:
        i=lim
        break
    i+=1
  else:
    break
print(sum(A))

Measured memory_bytes: 22884
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)

ll M = 1e9 + 7;
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 1e5 + 5;
vector <int> adj[N];
bool vis[N];
int h[N];
int ans;

void dfs(int u)
{
    vis[u] = 1; bool ok=1;
    for(auto it:adj[u])
    {
        if( h[u] <= h[it] )
        {
            ok=0; break;
        }
    }
    if(ok) ans++;
    for(auto it:adj[u])
    {
        if(vis[it]) continue;
        dfs(it);
    }
}


int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	int a[n+1];
	//vector <ll> v1,v2; 
	map <int,int> m1,m2;
	for(int i=1;i<=n;i++)
	{
	    ll h; cin>>h; a[i] = h;
	    //v1.pb(i-h); v2.pb(i+h);
	    m1[i-h]++; m2[i+h]++;
	}
// 	sort(v1.begin(),v1.end());
// 	sort(v2.begin(),v2.end());
	ll ans = 0;
	//int id = 0;
// 	for(auto it:v1) cout<<it<<' '; cout<<endl;
// 	for(auto it:v2) cout<<it<<' '; cout<<endl;
// 	for(int i=0;i<n;i++)
// 	{
// 	    int g = v1[i];
// 	    if(v2[id]>g) continue;
// 	    ll tmp = 0;
// 	    while(id<n && v2[id]<g) id++;
// 	    if(id==n) break;
// 	    int t1 = id;
// 	    while(id<n && v2[id]==g){ tmp++; id++; }
// 	    id=t1;
// 	    ans += tmp;
// 	    if(id==n) break;
// 	}

    for(int i=1;i<=n;i++)
    {
        ans += m2[i-a[i]];
        ans += m1[i+a[i]];
    }
	cout<<ans/2;
	return 0;
}


Measured memory_bytes: 40864
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            a,b,c = Co.most_common()[0][0],Co.most_common()[1][0],Co.most_common()[2][0]
            if a^b==c and b^c==a and c^a==b:
                ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        a, b = Co.most_common()[0][0], Co.most_common()[1][0]
        if a^b==a and a^a==b:
            ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 0 :
        ans = "Yes"
print(ans)

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int ans=0;
    cin >> n;
    vector<int> d(n);
    //int d[n];
    for(int i=0;i<n;i++) cin >> d[i];
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a,b,c = I()
if b-a == c-b:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 10064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll l,r,x;
  cin >> l >> r >> x;
  set<ll> s;
  rep(i,x) {
    ll y=l+i;
    if(y<=r) s.in(y);
    y=r-i;
    if(l<=y) s.in(y);
  }
  tr(it,s) pr(*it);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

bool on[11][11];

bool contain(int mask, int pos){
  return (mask & (1 << pos)) != 0; 
}

int main(){
  int N, M, _s, ans = 0;
  cin >> N >> M;
  vector<int> k(M);
  
  for(int i = 0; i < M; i++) {
    cin >> k[i];
    for(int j = 0; j < k[i]; j++) {
      cin >> _s;_s--;
      on[i][_s] = true; // on[電球iは][スイッチ_s...]
    }
  }
  vector<int> p(M);
  for(int i = 0; i < M; i++) cin >> p[i];

  
  for(int mask = 0; mask < (1 << N); mask++){
    // //cerr << "debug: " << mask << endl;
    vector<int> lamp(M, 0);
    for(int i = 0; i < N; i++) { // スイッチを押したか
      if(contain(mask, i)) {
	for(int j = 0; j < M; j++) { // そのスイッチを押したら...?
	  if(on[j][i]) lamp[j]++;
	}
      }
    }
    //  for(int i = 0; i < M; i++) //cerr << lamp[i] << " " ;cerr << endl;
    int cnt = 0;
    for(int i = 0; i < M; i++) if(lamp[i] % 2 == p[i])cnt++;
    if(cnt == M) ans++;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int a[50], b[50], c[50], d[50], y[10];
int n, m, q;
int sol;

void dfs(int x, int p)
{
    if (x == n)
    {
        int sum = 0;
        for (int i = 0; i < q; ++i)
            if (y[b[i]] - y[a[i]] == c[i])
                sum += d[i];
        sol = max(sol, sum);
        return;
    }
    for (int i = p; i <= m; ++i)
    {
        y[x] = i;
        dfs(x + 1, i);
    }
}

int main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    dfs(0, 1);
    cout << sol;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}
typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> B(M);
    Graph G(N);
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        G[A[i]-1].push_back(B[i]-1);
        G[B[i]-1].push_back(A[i]-1);
    }
    queue<int> que;
    vector<int> dist(N+1, -1);
    dist[0] = 0;
    que.push(0);
    vector<int> kiroku(N,-1);
    while (!que.empty())
    {
        int v = que.front();
        que.pop();
        for (int i : G[v])
        {
            if(dist[i] != -1){
                continue;
            }
            else{
                dist[i] = dist[v] + 1;
                kiroku[i] = v;
                que.push(i);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {
        cout << kiroku[i]+1 << endl;
    }
}


Measured memory_bytes: 12180
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	q := nextInt()
	v := make(map[int][]int)
	s := make([]int, n)

	for i := 0; i < n-1; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		v[a] = append(v[a], b)
		v[b] = append(v[b], a)
	}

	for i := 0; i < q; i++ {
		p := nextInt() - 1
		x := nextInt()

		s[p] += x
	}

	visited := make(map[int]struct{})
	traverse(0, 0, s, v, visited)

	x := make([]string, n)
	for i := 0; i < n; i++ {
		x[i] = fmt.Sprintf("%d", s[i])
	}

	fmt.Println(strings.Join(x, " "))
}

func traverse(node int, parentScore int, s []int, v map[int][]int, visited map[int]struct{}) {
	visited[node] = struct{}{}
	s[node] += parentScore

	for _, nextNode := range v[node] {
		_, ok := visited[nextNode]
		if ok {
			continue
		}

		traverse(nextNode, s[node], s, v, visited)
	}
}


Measured memory_bytes: 85808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
signed main(){
  int N,top=0,small=MOD;
  cin>>N;
  vi A(N);
  rep(i,0,N){
    cin>>A[i];
    top=max(top,A[i]);
    small=min(small,A[i]);
    }
  sort(ALL(A));
  int ans=0;
  REP(X,small,top){
    int count=distance(A.begin(),upper_bound(ALL(A),X+1))-distance(A.begin(),lower_bound(ALL(A),X-1));
    ans=max(count,ans);
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化

  int N;
  IN(N);
  vector<pair<int,int>> pairs(N);
  
  REP(i,N){
    int a, b;
    cin >> a >> b;
    pairs[i] = make_pair(b, a);
  }
  sort(pairs.begin(), pairs.end());
  
  //REP(i,N) OUT(pairs[i].first <<"," << pairs[i].second);

  string ans="Yes";
  int time=0;
  REP(i,N){
    time += pairs[i].second;
    if(time > pairs[i].first){
      ans = "No";
      break;
    }
  }
  OUT(ans);
}

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

int main(){
  int N;
  cin >> N;
  
  int h[N+2];
  for(int i=1;i<N+1;i++){cin >> h[i];}
  h[0]=0;
  h[N+1]=0;
  
  int x=0;
  int s=1;
  
  while(s!=0){
    for(int i=1;i<N+1;i++){
      if(h[i]>h[i+1] && h[i]>h[i-1]){
        if(h[i+1]>=h[i-1]){x+=h[i]-h[i+1]; h[i]=h[i+1];}
        else{x+=h[i]-h[i-1]; h[i]=h[i-1];}
      }
      else if(h[i]==h[i+1]){
        h[i]=h[i-1];
      }
      else{x+=0;}
    }
    s=0;
    for(int i=1;i<N+1;i++){s+=h[i];}
  }
  
  cout << x << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


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


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

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    ll all = 0;
    rep(i, N) all = all ^ a[i];

    cout << (all ^ a[0]);
    rep(i, N - 1) cout << " " << (all ^ a[i + 1]);
    cout << endl;

    return 0;
}


Measured memory_bytes: 4840
n,m,x=map(int,input().split())
c=[0]*n
a=[0]*n
ans=10**10
for i in range(n):
  d,*b=map(int,input().split())
  c[i]=d
  a[i]=b
import numpy as np
a=np.array(a)
from itertools import product
r=list(product([0,1],repeat=n))
for i in r:
  tmp=np.array([0]*m)
  cost=0
  for j,k in enumerate(i):
    tmp+=k*a[j]
    cost+=k*c[j]
  if all(tmp>=x):
    ans=min(ans,cost)
if ans>10**9:
  ans=-1
print(ans)

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

int main(){
	ll n,a,b; cin >> n >> a >> b;
	vector<ll> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	ll l=1; ll r=1e9;
	while(l<r){
		ll mid=(r+l)/2;
		ll cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>mid*b){
				cnt+=((h[i]-mid*b+(a-b-1))/(a-b));
			}
		}
		if(cnt<=mid){
			r=mid;
		}
		else{
			l=mid+1;
		}
	}
	cout << r << endl;
}


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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

//long long hornest_search(long long bit, vector<vector<pair<long long, long long>>>)
bool honest_search(long long bit, vector<vector<pair<long long, long long>>> x_y, long long N)
{
    //i番目の人の発言を基にhonestを探す。
    for (long long i = 0; i < N; i++)
    {
        //bit & (1 << i) を使うことで、半自動的に全部の通りを割り当てている。
        // 11010101 ~ 0番目の人:正直,1の人:不親切,2の人:正直,3:不親切....
        //search対象がhonestではない場合
        if (!(bit & (1 << i)))
            continue;

        //i番目の人の証言確認
        for (pair<long long, long long> xy : x_y[i])
        {
            int x = xy.first;  //x番目の人が
            int y = xy.second; //0 or 1

            //iの話では不親切(y=1)だが,<bitset>(8)では正直者扱い
            if (y == 1 && !(bit & (1 << x)))
                return false;

            //iの話では正直(y=0)だが,bitでは不親切扱い
            if (y == 0 && (bit & (1 << x)))
                return false;

            //完全に一致するデータは一つだけ?
            //bitは2^N通りであり,その分だけ繰り返しているだけ,
        }
    }
    //正直者と嘘つきの分け方は,全ての証言+bitの照らし合わせで決まる。
    //なので,return trueはfor抜けた後、
    return true;
}

int main()
{
    long long N;
    cin >> N;

    vector<vector<pair<long long, long long>>> x_y(N);
    for (int i = 0; i < N; i++)
    {
        long long A;
        cin >> A;
        x_y[i].resize(A);
        for (int j = 0; j < A; j++)
        {
            //long long x, y;
            //cin >> x >> y;
            //x_y[i].push_back({x, y}); //x_y[i][j].first >> x_y[i][j].secondでもok
            cin >> x_y[i][j].first >> x_y[i][j].second;
            --x_y[i][j].first; // 0-indexed に
        }
    }

    //bit < 2^N

    long long max_h = 0;
    for (long long bit = 0; bit < (1 << N); bit++)
    {
        if (honest_search(bit, x_y, N))
        {
            long long count = 0;
            for (int i = 0; i < N; i++)
            {
                if (bit & (1 << i))
                {
                    count++;
                }
            }
            max_h = max(max_h, count);
        }
    }
    cout << max_h << endl;
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 201001;
ll P[NM];
ll MOD = 1000000007;

void solve() {
    ll A,B;
    cin >> A >> B;
	ll cnt = 0;
	ll sum = 1;
  
	REP(i,20){
      	if(B<=sum){
        	break;
        }
        sum-=1;
    	sum+=A;
      	cnt++;
    }
  
	cout << cnt;
    return;
}


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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    a, b, k = list(map(int, input().split()))

    if (b - a + 1) <= 2 * k:
        for i in range(a, b + 1):
            print(i)
    else:
        for j in range(a, a + k):
            print(j)
        for j in range(b - k + 1, b + 1):
            print(j)



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

using namespace std;

int main() {
	string s;
	cin >> s;
	int c = s.back() - '0';

	if(c == 3) {
		cout << "bon" << '\n';
	} else if(c == 0 || c == 1 || c == 6 || c == 8) {
		cout << "pon" << '\n';
	} else {
		cout << "hon" << '\n';
	}

	return 0;
}


Measured memory_bytes: 3624
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

x = INT()
ans = x // 11 * 2
if 0 < x % 11 <= 6:
    ans += 1
elif x % 11 > 6:
    ans += 2
print(ans)


Measured memory_bytes: 5388
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true; 
    for(int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int isSimilarTo2017(int n) {
    return isPrime(n) && isPrime((n + 1) / 2);
}

int main() {
    vector<int> acc(100001, 0);
    for(int i = 1; i <= 100000; i++) {
        acc[i] = acc[i - 1] + (isSimilarTo2017(i) == true ? 1 : 0);
    }
    int Q;
    cin >> Q;
    for(int q = 0; q < Q; q++) {
        int l, r;
        cin >> l >> r;
        cout << acc[r] - acc[l - 1] << endl;
    }
    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int dat[125];
int root(int x){return dat[x]<0?x:dat[x]=root(dat[x]);}
void unite(int a,int b){
  a=root(a);b=root(b);
  if(a==b)return;
  dat[a]+=dat[b];dat[b]=a;
}

int main(){
  int n;
  cin>>n;
  vector<vi> g(n,vi(n));
  REP(i,n)REP(j,n)cin>>g[i][j];
  auto g2 = g;
  REP(k,n)REP(i,n)REP(j,n)CHMIN(g[i][j], g[i][k] + g[k][j]);
  if(g != g2){
    puts("-1");
    return 0;
  }
  vector<vector<bool>> f(n,vector<bool>(n,true));
  REP(k,n)REP(i,n)REP(j,n)if(i!=k && k!=j && g[i][j]==g[i][k]+g[k][j])f[i][j]=false;
  ll ans = 0;
  REP(i,n)REP(j,i)if(f[i][j])ans+=g[i][j];
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int D = B / A;
	if (D > C) cout << C << endl;
	else cout << D << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define vec vector
#define mst(a,b) memset(a,b,sizeof(a))
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define all(v) v.begin(),v.end()
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define nnf LLONG_MIN
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=((res%mod)*(x%mod))%mod;
        }
        x=((x%mod)*(x%mod))%mod;
        y=y/2;
    }
    return res;
}
 
 struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(pair<uint64_t,uint64_t> x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);
  }
};

void get_time(auto start,auto end){
    double time_taken =  
      chrono::duration_cast<chrono::nanoseconds>(end - start).count(); 
  
    time_taken *= 1e-9;
    cout<<"\n";
    cout<<"Time taken : "<<fixed<<time_taken<<setprecision(6);
}

  
  ll n,dp[3000][3000],a[3000];

  ll fn(ll i,ll j,ll s){
    if(i==j)return a[i];

    if(dp[i][j]!=0)return dp[i][j];

    return dp[i][j]=max(s-fn(i+1,j,s-a[i]),s-fn(i,j-1,s-a[j]));

  }

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

  auto start = chrono::high_resolution_clock::now();

  
 

/* #ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/

    cin>>n;



    ll s=0;

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

    ll x=fn(0,n-1,s);

    cout<<2*x-s;


   



  auto end = chrono::high_resolution_clock::now();

  /*#ifndef ONLINE_JUDGE

   get_time(start,end); 

  #endif*/

    return 0;
 }

Measured memory_bytes: 49840
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

#define ll long long
#define ull unsigned long long

using namespace std;
int main(void) {

	ll A[100001] = { 0 };
	ll N = 0, X = 0;
	ll ans = 0;

	scanf("%lld%lld", &N,&X);

	for (ll i = 0; i < N; i++)
		scanf("%lld", &A[i]);

	if (A[0] > X) {
		ans += A[0] - X;
		A[0] -= A[0] - X;
	}


	for (ll i = 1; i < N; i++) {
		if (A[i - 1] + A[i] > X) {
			ans += (A[i - 1] + A[i]) - X;
			A[i] -= (A[i - 1] + A[i]) - X;
		}
	}

	printf("%lld\n", ans);

	return 0;
}



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

int main() {
  int n;
  cin >> n;
  rep(i,0,n){
    int a;
    cin >> a;
    if(a%2 == 1){
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll K,A,B;
  cin >> K >> A >> B;
  ll KK = K;
  if(A + 2 <= B) {
    K -= A - 1; // A
    K--; // 1yen
    K--; // B
    if (K < 0) {
      cout << KK + 1 << endl;
      exit(0);
    }
    ll ans = B;
    ans += (K / 2) * (B - A) + K % 2;
    cout << ans << endl;
  } else {
    cout << K + 1 << endl;
  }
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define PI acos(-1)
#define eps 1e-10
#define mem(x) memset(x,0,sizeof(x))
#define _for(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define __for(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD)
{ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}
const int inf=-0x3f3f3f3f;
const int MAX=10000005;
const int MOD=1e9+7;
int a[1000009],b[1000009];
int main(){
    ll n,m;
cin>>n>>m;
if(n%m==0)
{
    cout<<-1<<endl;
    return 0;
}
for(int i=n+n;i<=1000000000000000000;i+=n)
{
    if(i%n==0&&i%m!=0)
        {cout<<i<<endl;return 0;}
}
return 0;
}



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

using namespace std;

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

#define rep(i,n) for (int i = 0; i < (int)n; ++i)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ALL(x) x.begin(),x.end()

string s,t;

int main() {
	cin >> s >> t;
	int n = s.size();
	rep(i, n) {
		string r;
		rep(tt, n) {
			r.pb(s[(i+tt)%n]);
		}
		if (r == t) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
string S;
int main() {
	cin >> S;
	for (int i = 0; i < 26; i++) {
		bool OK = false;
		for (int j = 0; j < S.size(); j++) {
			if (S[j] == ('a' + i))OK = true;
		}
		if (OK == false) { cout << (char)('a' + i) << endl; return 0; }
	}
	cout << "None" << endl;
	return 0;
}

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

int main(void)
{
    char s[9999],t[9999];
    int a,i;
    
    scanf("%s",s);

    a = strlen(s);

    for(i = 0;i < a;i++)
    {
        t[i] = 'x';
    }

    printf("%s",t);

    return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n,a[3<<17];
long sa[1<<17],sb[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<3*n;i++)cin>>a[i];
	priority_queue<int>P,Q;
	long suma=0,sumb=0;
	for(int i=0;i<n;i++)
	{
		P.push(-a[i]);
		suma+=a[i];
	}
	for(int i=0;i<n;i++)
	{
		Q.push(a[2*n+i]);
		sumb+=a[2*n+i];
	}
	sa[0]=suma;
	sb[n]=sumb;
	for(int i=0;i<n;i++)
	{
		P.push(-a[n+i]);
		suma+=a[n+i];
		suma+=P.top();
		P.pop();
		sa[i+1]=suma;
		Q.push(a[2*n-1-i]);
		sumb+=a[2*n-1-i];
		sumb-=Q.top();
		Q.pop();
		sb[n-1-i]=sumb;
	}
	long ans=sa[0]-sb[0];
	for(int i=1;i<=n;i++)ans=max(ans,sa[i]-sb[i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 3960
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    string s;
    cin>>s;
    int N=s.size();
    bool ok=false;
    rep(0,(N-1)/2){
        if(s.at(i)!=s.at((N-1)/2-1-i)){
            cout<<"No"<<endl;
            return 0;
        }

        if(s.at(i+(N+3)/2-1)!=s.at(N-1-i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(0,N){
        if(s.at(i)!=s.at(N-1-i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> S(n);
	for (auto& x : S) {
		cin >> x;
		sort(x.begin(), x.end());
	}
	string ans = S[0];
	for (int i = 1; i < n; ++i) {
		string tmp;
		set_intersection(ans.begin(), ans.end(), S[i].begin(), S[i].end(), back_inserter(tmp));
		ans = tmp;
	}
	cout << ans << endl;
}


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

int main(){
  int K;
  cin >> K;
  vector<int> A(K);
  A.at(0)=7%K;
  for(int i=0;i<K-1;i++){
    A.at(i+1)=(10*A.at(i)+7)%K;
  }
  for(int i=0;i<K;i++){
    if(A.at(i)==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
} 

Measured memory_bytes: 7224
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int ans=0;
    for ( int i=0; i<s.size(); i++ ) {
        if ( s[i]!=t[i] ) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3884
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    string s;
    cin >> s;
    int n = s.length();
  /*  if (n == 1) {
        cout << "1\n";
        return;
    }*/
    vector<int> dp(n);
    dp[0] = 1;
    for (int i = 1; i < n; ++i) {
        dp[i] = dp[i - 1] + (s[i] != s[i - 1]);
        if (i >= 2 && dp[i - 2] + 1 >= dp[i]) {
            s[i] = '#';
            dp[i] = dp[i - 2] + 1;
        }
    }
    cout << dp[n - 1];
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}


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

int main()
{
  int a, b, c, d; cin >> a >> b >> c >>d;
  if(a + b == c + d){
    puts("Balanced");
  }else if( a + b < c + d){
    puts("Right");
  }else{
    puts("Left");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define ull unsigned long long
#define nn 100002
int dfs(vector<int> list[],int n,int s,vector<int> &dp)
{
    if(dp[s]!=-1)return dp[s];
	int maxx=0;

    for(int j=0;j<list[s].size();j++)
    {
    	int i=list[s][j];
           
               maxx=max(maxx,1+dfs(list,n,i,dp));//cout<<maxx<<" "<<"for= "<<i+1<<endl;

            
    }
    dp[s]=maxx;
    return maxx;
 }
int main()
{int n,e;
cin>>n>>e;

vector<int>list[n];

for(int i=1;i<=e;i++)
{
    int a,b;cin>>a>>b;
   list[a-1].push_back(b-1);
}

//int dp[n];
//for(int i=1;i<=n;i++)dp[i]=-1;
//int max=0;


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

//d=dfs(list,n,4,visited);cout<<d<<endl;
//if(d>max)max=d;
//}
//cout<<max<<endl;
int ans = INT_MIN;
vector<int>dp(n,-1);
for(int i=0;i<n;i++)
{
    
//	cout<<i<<" "<<dfs(list,n,i)<<"\n";
	ans = max(ans,dfs(list,n,i,dp));
}
//for(int i=0;i<n;i++)cout<<dp[i]<<" ";cout<<endl;
cout<<ans<<"\n";	
}


Measured memory_bytes: 9472
x, y = gets.chomp.split(" ").map(&:to_i)
if x <= y
    if 0 <= x || y <= 0
        puts y - x
    elsif y.abs < x.abs
        puts (- y) - x + 1
    else
        puts y + x + 1
    end
else
    if 0 < y || x < 0
        puts (- y) + x + 2
    elsif y.abs < x.abs
        puts y + x + 1
    else
        puts (- y) - x + 1
    end
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdbool.h>

#define MAXSIZE 36


struct card{
    char suit[1]; //A, H, C, D
    int value; //1,2, ..., 9
};

void trace(struct card A[], int N){
    int i;
    for(i = 0; i < N; i++){
        if(i > 0) printf(" ");
        printf("%c%d", *A[i].suit, A[i].value);
    }
    printf("\n");
}

void BubbleSort(struct card A[], int N){
    int i,j,t1;
    char t2[1];
    for(i = 0; i < N; i++){
        for(j = N-1; j > i; j--){
            if( A[j].value < A[j-1].value){
                t1 = A[j].value;
                *t2 = *A[j].suit;
                A[j].value = A[j-1].value;
                *A[j].suit = *A[j-1].suit;
                A[j-1].value = t1;
                *A[j-1].suit = *t2;
            } 
            
        }

    }
}

void SelectionSort (struct card B[], int N ){
    int i,j,t1,min;
    char t2[1];
    for( i = 0; i < N; i++ ){
        
        min = i;
        
        for( j = i; j < N; j++ ){
            if( B[j].value < B[min].value) min = j;
        }

        t1 = B[min].value;
        *t2 = *B[min].suit;
        B[min].value = B[i].value;
        *B[min].suit = *B[i].suit;
        B[i].value = t1; 
        *B[i].suit = *t2; 

    }

}

bool isStable( struct card A[], struct card B[], int N ){
    for( int i = 0; i < N; i++){
        if( *A[i].suit != *B[i].suit ) return (false);
    }
    return (true);
}

int main(){

    struct card A[MAXSIZE], B[MAXSIZE];
    int N;
    int i;

    scanf("%d", &N);
    getchar();
    for( i = 0; i < N; i++ ){
        scanf("%c%d", A[i].suit, &A[i].value);
        getchar();
    }
    for( i = 0; i < N; i++ ){
        *B[i].suit = *A[i].suit;
        B[i].value = A[i].value;
    }

    BubbleSort(A, N);
    trace(A, N);
    printf("Stable\n");

    SelectionSort(B, N);
    trace(B, N);
    if(isStable(A, B, N)){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    return 0;
}


Measured memory_bytes: 1984
#define $ for(i=0;i<n;i++)for(j=0;j<n;j++)
#define _(a,x)$ for(b x=l=0;l<n;)b x=(b x+a[i][l]*p[l++][j])%m;$ a x=b x;
long m=1e9+7,p[50][50],a[50][50],b[50][50],k,s;i,j,l;main(n){scanf("%d%ld",&n,&k);$ a[i][i]=1;$ scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a,[i][j])}_(p,[i][j])}$ s+=a[i][j];printf("%d",s%m);}

Measured memory_bytes: 256
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())

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

lst=[[A[0],0,1]]
count=0

for i in range(1,N):
    m=1
    while lst and lst[-1][0]>A[i]:
        a,b,c=lst.pop()
        count+=a*(i-b)*c
        m+=c
    lst.append([A[i],i,m])
while lst:
    a,b,c=lst.pop()
    count+=a*(N-b)*c

print(count)


Measured memory_bytes: 40900