akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define M 1000000007
int N;
int flag;
void check(int T[N], int A[N])
{
    int i,max_T,max_A;
    flag = 1;
    max_T=T[0];
    max_A=A[0];
    for(i=1;i<N;i++){
        if(T[i]<T[i-1] || A[i]>A[i-1]){
            flag = 0;
            return;
        }
        if(T[i]>max_T){
            max_T = T[i];
        }
        if(A[i]>max_A){
            max_A = A[i];
        }
    }
    if(max_T != max_A){
        flag = 0;
    }
    return;
}
void justify_T(int T[N], int jus_T[N][2])
{
    jus_T[0][0] = T[0];
    jus_T[0][1] = 0;
    int i;
    for(i=1;i<N;i++){
        if(T[i]>T[i-1]){
            jus_T[i][0] = T[i];
            jus_T[i][1] = 0;
        }else{
            jus_T[i][0] = 0;
            jus_T[i][1] = T[i];
        }
    }
    return;
}

void justify_A(int A[N], int jus_A[N][2])
{
    jus_A[N-1][0] = A[N-1];
    jus_A[N-1][1] = 0;
    int i;
    for(i=N-2;i>=0;i--){
        if(A[i]>A[i+1]){
            jus_A[i][0] = A[i];
            jus_A[i][1] = 0;
        }else{
            jus_A[i][0] = 0;
            jus_A[i][1] = A[i];
        }
    }
    return;
}

void compare(int combine[N], int jus_T[N][2], int jus_A[N][2])
{
    int i;
    flag = 1;
    for(i=0;i<N;i++){
        if(jus_A[i][0]!=0 & jus_T[i][0]!=0 & jus_A[i][0]!= jus_T[i][0]){
            flag = 0;
            return;
        }else if(jus_A[i][0]!=0 & jus_T[i][0]==0 & jus_A[i][0]>jus_T[i][1]){
            flag = 0;
            return;
        }else if(jus_T[i][0]!=0 & jus_A[i][0]==0 & jus_T[i][0]>jus_A[i][1]){
            flag = 0;
            return;
        }else if(jus_A[i][0] ==0 & jus_T[i][0] ==0){
            combine[i] = jus_A[i][1]<jus_T[i][1] ? jus_A[i][1] : jus_T[i][1];
        }else{
            combine[i] = 1;
        }
    }
    return;
}

int main(void)
{
    scanf("%d",&N);
    int i,j,T[N],A[N];
    for(i=0;i<N;i++){
        scanf("%d",&T[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    check(T,A);
    if(flag == 0){
        printf("0");
        return 0;
    }

    int jus_T[N][2];
    int jus_A[N][2];

    justify_T(T,jus_T);
    justify_A(A,jus_A);

    /*for(i=0;i<N;i++){
        for(j=0;j<2;j++){
            printf("%d ",jus_T[i][j]);
        }
        printf("\n");
    }
    printf("\n");
    for(i=0;i<N;i++){
        for(j=0;j<2;j++){
            printf("%d ",jus_A[i][j]);
        }
        printf("\n");
    }*/

    int combine[N];
    unsigned long long  result;
    compare(combine,jus_T,jus_A);

    if(flag==0){
        printf("0");
        return 0;
    }else{
        result = 1;
        //printf("M:%d\n",M);
        for(i=0;i<N;i++){
            //printf("combine:%d\n",combine[i]);
            result = result*combine[i]%M;
            //printf("result:%d\n",result);
        }
        printf("%ld",result);
        return 0;
    }

}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
using namespace std;
typedef long long ll;
 
void create_set(int k){
    int out[k+1][k];
 
    int cnt = 1;
 
    REP(i, k){
        REP(j, k){
            if (j >= i){
                out[i][j] = cnt;
                cnt++;
            }
 
        }
    }
 
    cnt = 1;
 
    REP(j, k){
        RREP(i, 1, k+1){
            if (i >= j+1){
                out[i][j] = cnt;
                cnt++;
            }
        }
    }
 
    REP(i, k+1){
        cout << k << " ";
        REP(j, k){
            cout << out[i][j] << " ";
        }
        cout << endl;
    }
}
 
int main(){
    int N;
    cin >> N;
    int k = 1;
    bool good_number = false;
    while(k * (k+1) <= 2 * N){
        if (k * (k+1) == 2 * N) {
            good_number = true;
            break;
        }
        k++;
    }
    if(!good_number) {
        cout << "No" << endl;
        return 0;
    }
 
    cout << "Yes" << endl;
    cout << k+1 << endl;
    create_set(k);
 
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,A[10007],B[10007],plu=0,minu=0;
  cin >> N;
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
  }
  rep(i,N){
    if(A[i]<=B[i]){
      if((B[i]-A[i])%2==1){
        A[i]+=2;
        B[i]+=1;
      }
      plu+=B[i]-A[i];
    }
    else{
      minu+=A[i]-B[i];
    }
  }
  if(minu*2>plu){
    cNo;
  }
  else{
    cYes;
  }
}

Measured memory_bytes: 384
import sys
import itertools

s = sys.stdin.readline().rstrip()
n = len(s)


ans = 0
for i in range(n):
    combs = list(map(list, itertools.combinations(range(1, n), i)))
    res2 = 0
    for c in combs:
        c.insert(0, 0); c.append(n)
        res1 = 0
        for j in range(i+1):
            res1 += int(s[c[j]:c[j+1]])
        res2 += res1
    ans += res2

print(ans)

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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<std::pair<int64_t, int64_t>> v(n);
  std::cin >> v;
  std::sort(v.begin(), v.end());

  int64_t num = 0;
  for (const auto &i : v) {
    if (k <= num + i.second) {
      std::cout << i.first << std::endl;
      return 0;
    }
    num += i.second;
  }
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<stack>

using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
  stack<int> S;
  S.push(r);
  color[r]=c;
  while(!S.empty() ){
    int u=S.top(); S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==NIL){
        color[v]=c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for(int i =0; i<n;i++) color[i] = NIL;
  for(int u =0; u<n;u++){
    if(color[u] == NIL) dfs(u,id++);
  }
}

int main(){
  int s, t, m, q;

  cin >> n >> m;

  for(int i = 0; i<m; i++){
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for(int i=0;i<q;i++){
    cin >> s >> t;
    if(color[s]==color[t]){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }

  return 0;
}
   


Measured memory_bytes: 8884
#include<stdio.h>

int n;
int a[20];
int flg[10000000];

void dfs(int x,int sum){
  if(x==n){
    flg[sum]=1;
    return;
  }
  dfs(x+1,sum);
  dfs(x+1,sum+a[x]);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  dfs(0,0);
  int q,key;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if( flg[key]==1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2040
using System;
using System.Collections.Generic;
namespace 令和{
    class ABC{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            //bool[] isEven = new bool[n-1];
            List<int[]>[] tonari = new List<int[]>[n+1];
            int[] ans = new int[n+1];
            for(int i=0;i<n+1;i++){
                tonari[i] = new List<int[]>();
                ans[i] = -1;
            }
            int u,v,w;
            for(int i=1;i<n;i++){
var rrrr =  Console.ReadLine();
                string[] uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
uvw = rrrr.Split();
                u = int.Parse(uvw[0]);
                v = int.Parse(uvw[1]);
                w = int.Parse(uvw[2]);
                tonari[u].Add(new int[2]{v,w});
                tonari[v].Add(new int[2]{u,w});
            }
            Queue<int> q = new Queue<int>();
            q.Enqueue(1);
            ans[1] = 0;
            while(q.Count!=0){
                int p = q.Dequeue();
                foreach(int[] tnr in tonari[p]){
                    if(ans[tnr[0]]==-1){
                        ans[tnr[0]] = (tnr[1]+ans[p])%2;
                        q.Enqueue(tnr[0]);
                    }
                }
            }
            for(int i=0;i<n;i++){
                Console.WriteLine(ans[i+1]);
            }
 
 
        }
    }
}

Measured memory_bytes: 39000
# 文字列を受け取る
inpstr = input()

# 命令の数を受け取る
q = int(input())

# 命令を受け取って処理実行
for i in range(q):
    order = input()
    order_list = [j for j in order.split(" ")]
    order_txt = order_list[0]
    if order_txt == "replace":
        rplc1 = int(order_list[1])
        rplc2 = int(order_list[2])
        rplcstr = order_list[3]
        inpstr = inpstr[:rplc1] + rplcstr + inpstr[rplc2 + 1:]
    elif order_txt == "reverse":
        rvrs1 = int(order_list[1])
        rvrs2 = int(order_list[2])
        tmp_str = inpstr[rvrs1:rvrs2 + 1]
        rvrs_str = "".join(reversed(tmp_str))
        inpstr = inpstr[:rvrs1] + rvrs_str + inpstr[rvrs2 + 1:]
    else:
        prt1 = int(order_list[1])
        prt2 = int(order_list[2])
        print(inpstr[prt1:prt2 + 1])



Measured memory_bytes: 5620
n = int(input())
a = list(map(int, input().split()))
s = 0
a.insert(0, 0)
a.insert(n + 1, 0)
for i in range(1, n + 2):
    s += abs(a[i - 1] - a[i])
for i in range(1, n + 1):
    print(s - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]))

Measured memory_bytes: 14048
void main() {
  auto n = ri;
  n %= 10;
  switch(n) {
    case 2, 4, 5, 7, 9:
      writeln("hon");
      break;
    case 0, 1, 6, 8:
      writeln("pon");
      break;
    case 3:
      writeln("bon");
      break;
    default: assert(0);
  }
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
  return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
  return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    res[i] = readAs!(T[]);
  }
  return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    auto s = rs;
    foreach(j; 0..width) res[i][j] = s[j].to!T;
  }
  return res;
}

int ri() {
  return readAs!int;
}

long rl() {
  return readAs!long;
}

double rd() {
  return readAs!double;
}

string rs() {
  return readln.chomp;
}

Measured memory_bytes: 2724
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> v;
  if(s[0] == '1') v.push_back(0);
  for(int i = 0; i < s.size();) {
    int j = i+1;
    while(j < s.size() && s[i] == s[j]) j++;
    v.push_back(j-i);
    i = j;
  }
  v.push_back(0);
  vector<int> prefs;
  prefs.push_back(0);
  for(int out: v) {
    prefs.push_back(prefs.back() + out);
  }
  int ret = 0;
  // evens are the ones being flipped
  for(int i = 0; i < v.size(); i+=2) {
    int largestEven = i + 2 * (k-1);
    int rhs = min(largestEven+1, (int)v.size()-1);
    int lhs = max(i-1, 0);
    ret = max(ret, prefs[rhs+1] - prefs[lhs]);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vec a(3),b(3);
    rep(i,3) cin>>a[i];
    rep(i,3) cin>>b[i];
    vector<bool> aisl(3);
    rep(i,3) aisl[i] = a[i]>=b[i];
    vec v(3);
    rep(i,3) v[i] = abs(a[i]-b[i]);
    bool bre = false;
    ll temp;
    ll ans = 0;
    ll N_i,N_ij;
    rep(i,N+1){
        if(i == 1 && aisl[0])break;
        N_i = N-i;
        rep(j,N_i+1){
            if(j == 1 && aisl[1])break;
            N_ij = N_i - j;
            temp = 0;
            if(!aisl[0])temp += (i/a[0])*v[0];
            if(!aisl[1])temp += (j/a[1])*v[1];
            if(!aisl[2])temp += (N_ij/a[2])*v[2];
            ans = max(ans,temp);
            if(aisl[2]){
                bre = true;
                break;
            }            
        }
        if(bre){
            temp = 0;
            if(!aisl[0])temp += (i/a[0])*v[0];
            if(!aisl[1])temp += (N_i/a[1])*v[1];
            if(!aisl[2])temp += (N_ij/a[2])*v[2];
            ans = max(ans,temp);              
        }
    }
    N += ans;
    ans = 0;
    /*cout<<N<<endl;
    rep(i,3) cout<<aisl[i]<<endl;*/
    bre = false;
    rep(i,3) aisl[i] = a[i]<=b[i];
    rep(i,N+1){
        if(i == 1 && aisl[0])break;
        N_i = N-i;
        rep(j,N_i+1){
            if(j == 1 && aisl[1])break;
            N_ij = N_i - j;
            temp = 0;
            if(!aisl[0])temp += (i/b[0])*v[0];
            if(!aisl[1])temp += (j/b[1])*v[1];
            if(!aisl[2])temp += (N_ij/b[2])*v[2];
            ans = max(ans,temp);
            if(aisl[2]){
                bre = true;
                break;
            }            
        }
        if(bre){
            temp = 0;
            if(!aisl[0])temp += (i/b[0])*v[0];
            if(!aisl[1])temp += (N_i/b[1])*v[1];
            if(!aisl[2])temp += (N_ij/b[2])*v[2];
            ans = max(ans,temp);              
        }
    }
    cout<<N+ans<<endl;
}

Measured memory_bytes: 384
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n;
int h[N];
int cache[N];

int dp(int idx){
    if(idx>=n) return 0;
    int &ans=cache[idx];
    if(ans!=-1) return ans;
    ans=inf;
    if(idx<=n-1) ans=min(ans,dp(idx+1)+abs(h[idx+1]-h[idx]));
    if(idx<=n-2) ans=min(ans,dp(idx+2)+abs(h[idx+2]-h[idx]));
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,1,n+1) cin >> h[i];
    mst(cache,-1);
    int res=dp(1);
    cout << res;
    return 0;
}


Measured memory_bytes: 4992
from sys import stdin


def dfs(str, mx):
    if len(str) == N:
        print(str)
        return

    for i in range(ord("a"), mx+2):
        # print(i,mx+2)
        if i > mx:
            mx = i
        t = str
        t = t+chr(i)
        # print(str)
        dfs(t, mx)
    # print(str)


# S = stdin.readline().rstrip().split()
N = [int(x) for x in stdin.readline().rstrip().split()][0]


dfs("", ord("a")-1)


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

int main()
{
    string arr;
    cin>>arr;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]>='a'&&arr[i]<='z')arr[i]='x';
    }
    cout<<arr<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
int main()
{
  int sum;
  int data;
  while(cin >> sum,sum){
    Rep(i,9) {
      cin >> data;
      sum -= data;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define f first
#define ss second

const int mod = 1e9+7;
void solve_case()
{
    int n,i,j,t,k,m;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++) cin >> a[i];
    sort(a,a+n, greater<int>());
    int ans = 0;
    multiset<pair<int, pair<int, int>>> st;
    j = a[0];
    st.insert(mp(j, mp(j,j)));
    for(i=1; i<n; i++)
    {
        int x = a[i];
        auto it = *st.rbegin();
        ans += it.f;
        //cout << i << " " << x << " " << it.f << "\n";
        int l = it.ss.f, r = it.ss.ss;
        st.erase(st.find(it));
        st.insert(mp(min(x,l), mp(l,x)));
        st.insert(mp(min(x,r), mp(x,r)));
    }
    cout << ans << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int Testcases = 1;
    //cin >> Testcases;
    while(Testcases--)
    {
        solve_case();
    }
    return 0;
}


Measured memory_bytes: 17716
import sys
input = sys.stdin.readline

n = int(input())
t = 0
x = 0
y = 0
judge = True

for i in range(n):
    t1, x1, y1 = map(int, input().split())
    if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
        judge = False
    x = x1
    y = y1
    t = t1

if judge == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

N = int(input())
S = str(input())


cnt = S.count(".")

l = [cnt] #all black
for i in range(N):
    if S[i]==".":
        cnt -= 1
        l.append(cnt)
    else:
        cnt += 1
        l.append(cnt)

# print(l)
print(min(l))


Measured memory_bytes: 13052
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc166
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc166B();
			Console.Out.Flush();

        }

        public static void solve_abc166B()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];
            int[] cnt = new int[n];
            while (k-- > 0)
            {
                int d = Convert.ToInt32(Console.ReadLine());
                int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                for (int i = 0; i < d; i++)
                {
                    cnt[a[i] - 1]++; 
                }
            }
            int sum = 0;
            for (int i = 0; i < cnt.Length; i++)
            {
                if (cnt[i] == 0)
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc166A()
        {
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 28820
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
      
      

T = True
while T:
  n = int(input())
  if n == 0:
    quit()
    
  data = UnionFind(n + 1)
  x = [0] * n
  for i in range(n):
    x[i] = list(map(float, input().split()))
  p = int(n * (n - 1) / 2)
  kumi = [0] * p
  q = 0
  for i in range(n):
    one = x[i]
    for j in range(i + 1, n):
      two = x[j]
      L1 = (one[0] - two[0]) ** 2 + (one[1] - two[1]) ** 2 + (one[2] - two[2]) ** 2
      L2 = L1 ** (1 / 2) - (one[3] + two[3])
      L2 = max(L2, 0)
      kumi[q] = [i, j, L2]
      q += 1
  kumi = sorted(kumi, key = lambda x:x[2])
  ans = 0
  for i in range(p):
    x, y, z = kumi[i][0], kumi[i][1], kumi[i][2]
    if not data.same_check(x, y):
      data.union(x, y)
      ans += z
  print('{:.3f}'.format(ans))
    
    
    







Measured memory_bytes: 6468
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int circumference = sc.nextInt(); //円周
		int numOfHouses = sc.nextInt();
		int[] distance = new int[numOfHouses];
		for (int i = 0; i < numOfHouses; i++) {
			distance[i] = sc.nextInt();
		}
		
		int longestDistance = 0;
		for (int i = 2; i < numOfHouses; i++) {
			int tmp = distance[i] - distance[i - 1];
			if (tmp > longestDistance) {
				longestDistance = tmp;
			}
		}
		
		System.out.println(Math.min(distance[numOfHouses - 1] - distance[0], circumference - longestDistance));
	}
}

Measured memory_bytes: 82316
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR(i, beg, end) for (int i = beg; i < end; i++)

using namespace std;

int64_t kRem = 1000000007;

int64_t make_diff(vector<int64_t>& left_w, vector<int64_t>& right_w, vector<bool>& select, int p, int w)
{
	if (p == w) {
		FOR(i, 1, w) {
			if (select[i] && select[i + 1]) return 0;
		}

		FOR(i, 1, w) {
			if (select[i]) {
				left_w[i]++;
				right_w[i + 1]++;
			}
		}
		return 1;
	}

	select[p] = true;
	int ret = make_diff(left_w, right_w, select, p + 1, w);
	select[p] = false;
	ret += make_diff(left_w, right_w, select, p + 1, w);
	return ret;
}

int main()
{
	int64_t h, w, k; cin >> h >> w >> k;

	if (w == 1) {
		cout << 1 << endl;
		return 0;
	}

	vector<int64_t> left_w(w + 1);
	vector<int64_t> right_w(w + 1);
	vector<int64_t> no_w(w + 1);

	vector<bool> select(w + 1);
	int all_cases = make_diff(left_w, right_w, select, 1, w);
	FOR(i, 1, w + 1) {
		no_w[i] = all_cases - left_w[i] - right_w[i];
	}

	vector<int64_t> cases(w + 1); // 0 origin
	vector<int64_t> new_cases(w + 1);
	cases[1] = 1;

	FOR(i, 0, h) {
		new_cases[1] = (cases[1] * no_w[1] + cases[2] * right_w[2]) % kRem;
		FOR(j, 2, w) {
			new_cases[j] = (cases[j - 1] * left_w[j -1] + cases[j] * no_w[j] + cases[j + 1] * right_w[j + 1]) % kRem;
		}
		new_cases[w] = (cases[w - 1] * left_w[w - 1] + cases[w] * no_w[w]) % kRem;

		copy(new_cases.begin(), new_cases.end(), cases.begin());
	}

	cout << cases[k] << endl;

	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	vector<int> prm(1);
	for (ll i=2; i*i<=n; i++) {
		if (n%i == 0) {
			while (n%i == 0) {
				prm.back()++;
				n /= i;
			}
			prm.push_back(0);
		}
	}
	if (n > 1ll) prm.back()++;
	ll cnt = 0;
	for (int x : prm) {
		int prev = 0;
		for (int i=1; i<=x; i++) {
			if (i*(i+1)/2 <= x) prev = i;
			else break;
		}
		cnt += prev;
	}
	cout << cnt;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
    ll n,a,b;cin >> n >> a >> b;
    if((a-b)%2==0)cout << abs(a-b)/2 << endl;
    else{
        if(a>b)swap(a,b);
        b-=a;//1でaが1回勝ってからorNでbが一回負けてから頑張る
        ll ans1=a+((b-1)/2);
        b+=a;
        a+=n-b+1;
        ll ans2=n-b+1+((n-a)/2);
        cout << min(ans1,ans2) << endl;
    }
}

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

using namespace std;



int main() {
    int w,h,x,y,r;
    cin >>w>>h>>x>>y>>r;
   
   if(x>0 && y>0 && x>=r && y>=r && w -x >=r && h-y >=r){
      cout << "Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
   
}


Measured memory_bytes: 3108
s = input()
ans = []
for i in range(len(s)):
  if s[i] == "0":
    ans.append("0")
  elif s[i] == "1":
    ans.append("1")
  elif s[i] == "B":
    if len(ans) > 0:
      ans.pop(-1)

print("".join(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

#define rep(s, n) for (ll i = s; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    ll N, L;
    input(N, L);

    ll sum = 0;
    rep(1, N + 1)
    {
        sum += L + i - 1;
    }

    ll res, m = 1000000;
    rep(1, N + 1)
    {
        if (m > abs(L + i - 1))
        {
            res = i;
            m = abs(L + i - 1);
        }
    }

    cout << (sum - (L + res - 1)) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

@lru_cache(None)
def recur(temp, index=0, cost=0):
    if index == n:
        for j in range(m):
            if temp[j] < x:
                return inf
        return cost
    answer = inf
    answer = min(answer, recur(temp, index+1, cost))
    temp = list(temp)
    for j in range(m):
        temp[j] += mat[index][j+1]
    cost += mat[index][0]
    answer = min(answer, recur(tuple(temp), index+1, cost))
    return answer


n, m, x = sp()
mat = []
for i in range(n):
    mat.append(l())
res = recur(tuple([0]*m))
if res == inf:
    out(-1)
    exit()
out(res)


Measured memory_bytes: 83384
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<P> v;
    for (auto &c : s) {
        if (v.empty() || v.back().first != c - '0') {
            v.emplace_back(c - '0', 1);
        } else {
            v.back().second++;
        }
    }

    int ans = 0, len = 0, sum = 0, r = 0;
    int m = (int) v.size();
    for (int l = 0; l < m; ++l) {
        while (r < m && sum + (v[r].first == 0) <= k) {
            sum += (v[r].first == 0);
            len += v[r].second;
            ++r;
        }
        ans = max(ans, len);

        sum -= (v[l].first == 0);
        len -= v[l].second;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1528
#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< int, int >;

int main() {
    string s;
    cin >> s;
    int n = s.length();

    if ((s[0] == s[n-1] and n%2 == 0) or (s[0] != s[n-1] and n%2)) cout << "First" << endl;
    else cout << "Second" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
char zf1[1000010],zf2[1000010];
struct SZt
{
	int l,r,h;
	SZt(){}
	SZt(int L,int R,int H)
	{
		l=L;
		r=R;
		h=H;
	}
};
SZt dl[1000010];
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("game.out","w",stdout);
	int n,jg=0,he=0,ta=0,py=0;
	scanf("%d%s%s",&n,zf1,zf2);
	bool bt=false;
	for(int i=0;i<n;i++)
	{
		if(zf1[i]!=zf2[i])
		{
			bt=true;
			break;
		}
	}
	if(!bt)
	{
		printf("0\n");
		return 0;
	}
	for(int i=n-1;i>=0;i--)
	{
		while(he<ta&&dl[he].l-py>i)
			he+=1;
		if(he<ta)
		{
			if(dl[he].h+py+1>jg)
				jg=dl[he].h+py+1;
			if(i>0&&zf2[i]==zf2[i-1])
				continue;
			py+=1;
			dl[he].r=i-1+py;
			int la=dl[ta-1].l-py;
			while(la>=0&&zf1[la]!=zf2[i])
				la-=1;
			if(la==-1)
			{
				printf("-1");
				return 0;
			}
			dl[ta]=SZt(la+py,dl[ta-1].r-1,1-py);
			ta+=1;
		}
		else
		{
			py=0;
			if(jg<1)jg=1;
			if(i>0&&zf2[i]==zf2[i-1])
				continue;
			int la=i;
			while(la>=0&&zf1[la]!=zf2[i])
				la-=1;
			if(la==i)continue;
			if(la==-1)
			{
				printf("-1");
				return 0;
			}
			dl[ta++]=SZt(la,i-1,1);
		}
	}
	printf("%d",jg);
	return 0;
}

Measured memory_bytes: 13824
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = 3;
		boolean canDo = true;
		int[][] array = new int[n+1][d];
		for(int i=0; i < d;i++){
			array[0][i] = 0;
		}

		for(int i = 1; i < n+1; i++){
			int turn = Math.abs(array[i-1][0] - sc.nextInt());
			int dist = Math.abs(array[i-1][1] - sc.nextInt()) + Math.abs(array[i-1][2] - sc.nextInt());
			int x = turn -dist;
			if(x < 0 || x % 2 != 0){
				canDo = false;
				break;
			}
		}
		System.out.println(canDo ? "Yes" : "No");
	}
}

Measured memory_bytes: 93948
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> vs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vs[i].first;
        vs[i].first = -vs[i].first;
        vs[i].second = i;
    }
    sort(vs.begin(), vs.end());

    for (int i = 0; i < n; i++)
    {
        const int index = (vs[0].second == i ? 1 : 0);
        cout << -vs[index].first << endl;
    }
}


Measured memory_bytes: 3200
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  vector<string> vs(4); REP(i, 4) vs[i] = s[i];
  vector<int> abcd(4); REP(i, 4) abcd[i] = stoi(vs[i]);
  for (int bit = 0; bit < (1 << 3); ++bit) {
    int sum = abcd[0];
    REP(i, 3) {
      if (bit & (1 << i)) {
        sum += abcd[i+1];
      } else {
        sum -= abcd[i+1];
      }
    }
    if (sum == 7) {
      cout << abcd[0];
      REP(i, 3) {
        if (bit & (1 << i)) {
          cout << "+" << abcd[i+1];
        } else {
          cout << "-" << abcd[i+1];
        }
      }
      cout << "=7\n";
      return 0;
    }
  }
}


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

int main() {
	long long n,t,i,j,k,l,m;
	cin >> n >> t;
	vector<pair<long long, long long>> a(n);
	vector<long long> x(n),y(n);
	for(i=0; i<n; i++){
		cin >> a[i].first >> a[i].second;
		x[i]=a[i].first; y[i]=a[i].second;
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	
	long long ans=4000000000000000000,cur;
	for(i=0; i<n-1; i++){
		for(j=i+1; j<n; j++){
			for(k=0; k<n-1; k++){
				for(l=k+1; l<n; l++){
					cur=0;
					for(m=0; m<n; m++){
						if(a[m].first>=x[i] && a[m].first<=x[j] && a[m].second>=y[k] && a[m].second<=y[l]){
							cur++;
						}
					}
					if(cur>=t){
						ans=min(ans,(x[j]-x[i])*(y[l]-y[k]));
					}
				}
			}
			
		}
	}
	cout << ans;
	
}

Measured memory_bytes: 256
def prod(array):
    res = 1
    for a, _ in array:
        res *= a
        res %= MOD
    return res

MOD = 10**9 + 7
N, K = map(int, input().split())
if N==K:
    res = 1
    for a in map(int, input().split()):
        res *= a
        res %= MOD
    print(res)
    exit()
A = []
allsgn = 0
for a in map(int, input().split()):
    A.append((abs(a), a < 0))
    allsgn += a<0
A.sort(reverse=True)
sgn = 0
s0 = -1
lastA = -1
for i, p in enumerate(A[:K]):
    a, s = p
    sgn += s
    if s != s0:
        lastA = i-1
    s0 = s
lasts = s0
if allsgn==N:
    if K%2==1:
        print((-prod(A[-K:]))%MOD)
        exit()
    else:
        print(prod(A[:K])%MOD)
        exit()
if sgn%2==0:
    print(prod(A[:K])%MOD)
    exit()
if lasts != A[K][1]:
    res = prod(A[:K-1])*A[K][0]
else:
    firstA = None
    for i, p in enumerate(A[K:],start=K):
        a, s = p
        if s != lasts:
            firstA = i
            break
    if lastA == -1 or (firstA is not None and A[K][0]/A[lastA][0] < A[firstA][0]/A[K-1][0]):
        res = prod(A[:K - 1]) * A[firstA][0]
    else:
        res = prod(A[:lastA]) * prod(A[lastA + 1:K + 1])
print(res%MOD)
"""
6 3
5 -3 -3 -3 -3 -2

10 7
-10 -10 -10 -10 10 10 10 10 10 10
"""

Measured memory_bytes: 105460
#from collections import defaultdict


def main():
    ans=0
    tmp=0
    x=input()
    for i in x:
        if tmp==0 and i=="T":
            ans+=1
        elif i=="T":
            tmp-=1
        else:
            tmp+=1
    print(ans*2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41180
def gcd(x, y):
  while y:
    x, y = y, x % y
  return x

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
M = [0] * N
L[0] = 0
for i in range(N - 1):
  L[i + 1] = gcd(L[i], A[i])
R[N-1] = 0
for j in range(N - 1):
  R[N - j - 2] = gcd(R[N - j - 1], A[N - j - 1])
for i in range(N):
  M[i] = gcd(L[i], R[i])
print(max(M))

Measured memory_bytes: 14436
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if(n == 0 && x == 0)break;
        int cnt = 0;

        for(int i = 1; i <= x; i++){
            int l = x - i;
            for(int j = i+1 ; j <= l; j++){
                int m = x - i - j;
                if(j < m && m <= n)cnt++;
            }
        }

        cout << cnt << endl;

    }


}


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


int main()
{
  	int a,b;
  	cin>>a>>b;
  	string str;
  	cin>>str;
  	if(str[a]!='-')
    {
    	cout<<"No"<<endl;
        return 0;
    }
  	for(int i=0 ; i<a ; ++i)
    {
      	if(str[i]=='-')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
  	for(int i=a+1; i<str.length() ; ++i)
    {
    	if(str[i]=='-')
        {
          cout<<"No"<<endl;
          return 0;
        }
    }
	cout<<"Yes"<<endl;
	return 0;
}

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

using namespace std;

int main() {
    long n;
    cin >> n;
    vector<long> h(n);
    for (long i=0; i<n; ++i) {
        cin >> h[i];
    }
    bool can = true;
    --h[0];
    for (long i=0; i<n-1; ++i) {
        if (h[i] > h[i+1]) {
            can = false;
            break;
        } else if (h[i] < h[i+1]) {
            --h[i+1];
        }
    }
    if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please



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

	
	int N, K;
	cin >> N >> K;
	int x[100];
	rep(i, N) cin >> x[i];

	int kotae = 0;
	rep(i, N) {
		kotae += 2 * min(x[i], abs(x[i] - K));
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	c=a+b;
	if(c%2==1)
	{
		cout<<(c+1)/2<<endl;
	}
	if(c%2==0)
	{
		cout<<c/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Not Found

#include <iostream>
#include <string>

using namespace std;

int main(){
	string S;
	cin >> S;

	int alpha[26] = {};

	for (size_t i = 0; i < S.length(); ++i)
		alpha[S[i]-'a']++;

	for (int i = 0; i < 26; ++i){
		if (alpha[i] == 0){
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}

	cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		Dice d = new Dice(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(),
				scan.nextInt());

		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int upp = scan.nextInt();
			int sou = scan.nextInt();
			d.rotate(upp, sou);
			System.out.println(d.getEst());
		}

		scan.close();
		System.exit(0);
	}

}

class Dice {
	int Upp, Sou, Est, Wst, Nor, Bot;

	public Dice(int upp, int sou, int est, int wst, int nor, int bot) {
		Upp = upp;
		Sou = sou;
		Est = est;
		Wst = wst;
		Nor = nor;
		Bot = bot;
	}

	public void rotate(int upp, int sou) {
		if (sou == Wst || sou == Est)
			operate('E');
		for (int i = 0; i < 4; i++) {
			if (sou == Sou)
				break;
			operate('N');
		}
		for (int i = 0; i < 4; i++) {
			if (upp == Upp)
				break;
			operate('E');
		}
	}

	public int getEst() {
		return Est;
	}

	public void operate(char op) {
		int tmp;
		switch (op) {
		case 'S':
			tmp = Upp;
			Upp = Nor;
			Nor = Bot;
			Bot = Sou;
			Sou = tmp;
			break;
		case 'E':
			tmp = Upp;
			Upp = Wst;
			Wst = Bot;
			Bot = Est;
			Est = tmp;
			break;
		case 'W':
			tmp = Upp;
			Upp = Est;
			Est = Bot;
			Bot = Wst;
			Wst = tmp;
			break;
		case 'N':
			tmp = Upp;
			Upp = Sou;
			Sou = Bot;
			Bot = Nor;
			Nor = tmp;
			break;
		}
	}

	public int getUpp() {
		return Upp;
	}

}

Measured memory_bytes: 26296
use std::cmp::{max, min};
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let (h, w): (i64, i64) = parse!(it, 2);
    let diff = |x: i64, y: i64, z: i64| {
        let r = max(x, max(y, z));
        let l = min(x, min(y, z));
        r - l
    };
    let mut ret = std::i64::MAX;

    // w / 3 or h / 3
    let mut parallel = |w, h| {
        let w0 = w / 3;
        let w1 = (w - w0) / 2;
        let w2 = w - w0 - w1;
        diff(h * w0, h * w1, h * w2)
    };
    ret = min(parallel(h, w), ret);
    ret = min(parallel(w, h), ret);
    // w/3, h/2
    let mut block = |w, h| {
        let h0 = h / 2;
        let h1 = h - h0;
        let mut ret = std::i64::MAX;
        for &d in &[-2, -1, 0, 1, 2] {
            let w0 = w / 3 + d;
            let w1 = w - w0;
            if w0 < 1 || w1 < 1 {
                continue;
            }
            ret = min(diff(w0 * h, h0 * w1, h1 * w1), ret);
        }
        ret
    };
    ret = min(block(w, h), ret);
    ret = min(block(h, w), ret);
    println!("{}", ret);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    long long  K ,A, B;
    int check = 1;
    long long count =0;
    long long pre_K ;
    cin >> K >> A >>B ;
    pre_K = K;
    int i;
    if(K == 1 || K <= A){
        cout << K+1 << endl;
    }
    else if(A  >=B-1)
    {
        cout << K+1 <<endl;
    }
    else
    {
       while(K >1)
       {
           if(check == 1 && A !=1 )
           {
               
               K = K - A + 1;
               check = 0;
               pre_K = A;
           }
           if(check == 1)
           {
               pre_K = A;
               check = 0;
           }
           
           if(pre_K >= A )
           {
               pre_K = pre_K-A+B ;
               K = K - 2 ;
               //count ++;
               //pre_K = pre_K -2;
               
           }
           
       }
       cout << K+pre_K << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[51];
signed main() {
    int n; string s;
    for (int h = 0; h < 20; h++) {
        cin >> s; int a = 0, b = 0;
        if (s == "0") { return 0; }
        for (int h = 1; h < s.size(); h++) {
            if (s[h] == 'A') { a++; }
            if (s[h] == 'B') { b++; }
        }
        if (a > b) { cout << a + 1 << ' ' << b << endl; }
        else {
            cout << a << ' ' << b + 1 << endl;
        }
    }
}


Measured memory_bytes: 3056