akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define my_max(a, b) ((a) > (b) ? (a) : (b))
#define my_min(a, b) ((a) < (b) ? (a) : (b))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i, s, t) for(int i = (int)(s); i <= (int)(t); i++)
#define rev(i, t, s) for(int i = (int)(t); i >= (int)(s); i--)
#define lson rt << 1
#define rson rt << 1 | 1
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double lb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> VI;
typedef std::vector<ll> VL;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbtree;
ll gcd(ll x, ll y){ return y % x == 0 ? x : gcd(y % x, x); }
template<class T>T my_abs(T a){ if(a < 0) a = -a; return a; }
inline ll read(){
    ll ret = 0, sign = 1;
    char c = getchar();
    while(c < '0' || c > '9'){ if(c == '-') sign = -1; c = getchar();}
    while(c >= '0' && c <= '9'){ ret = ret * 10 + c - '0'; c = getchar(); }
    return ret * sign;
}
inline void write(ll x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

//void expand_stack_space(){
//    int size = 256 << 20; // 256MB
//    char *p = (char*)malloc(size) + size;
//    __asm__("movl %0, %%esp\n" :: "r"(p));
//}

int main(){
#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if(s == t) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1e9+7
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (int)x.size()
#define INF 1000000000
bool debug = 0;
queue<pi> Q,R;
int H,W,K,a,b;
int G[1000][1000],P[1000][1000];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
string S;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if(debug)freopen("input.txt","r",stdin);
  cin>>H>>W>>K;
  for (int i=0;i<H;++i){
    cin>>S;
    // cout << S << '\n';
    for(int j=0;j<W;++j){
      if(S[j] == 'S'){
        Q.push(mp(i,j));
        R.push(mp(i,j));
        continue;
      }
      if (S[j]=='#')G[i][j] = P[i][j] = -2;
      else G[i][j] = P[i][j] = -1;
    }
  }
  // First we DFS to the K nearest neighbours
  while(Q.size()){
    pi cur = Q.front();
    if (P[cur.f][cur.s] == K)break;
    Q.pop();
    for (int k=0;k<4;++k){
      int cx = cur.f+dx[k];
      int cy = cur.s+dy[k];
      if (cx < 0 || cy < 0 || cx > H || cy > W){
        cout << 1;
        return 0;
      }
      if (P[cx][cy] != -1)continue;
      P[cx][cy] = P[cur.f][cur.s] + 1;
      G[cx][cy] = 0;
      Q.push(mp(cx,cy));
      R.push(mp(cx,cy));
      // cout << cx << ' ' << cy << '\n';
    }
  }
  while(R.size()){
    // cout << R.front().f << ' ' << R.front().s << '\n';
    pi cur = R.front();
    R.pop();
    for (int k=0;k<4;++k){
      int cx = cur.f+dx[k];
      int cy = cur.s+dy[k];
      if (cx < 0 || cy < 0 || cx >=H || cy >=W){
        // cout << cx << ' ' << cy << '\n';
        if(debug)cout << G[cur.f][cur.s] << '\n';
        cout << (G[cur.f][cur.s] + K - 1)/K + 1;
        return 0;
      }
      if (G[cx][cy] != -1 && G[cx][cy] != -2)continue;
      if (P[cx][cy] >= 0)continue;
      G[cx][cy] = G[cur.f][cur.s] + 1;
      R.push(mp(cx,cy));
    }
  }
  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j)cout<<G[i][j] << ' ';cout<<'\n';
  }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

class UnionFind {
private:
    std::vector<int> par;
    std::vector<int> sz;

public:
    UnionFind(int N) : par(N), sz(N, 1) {
        for (int i = 0; i < N; ++i) par[i] = i;
    }
    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) std::swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }
    int size(int x) {
        return sz[root(x)];
    }
    void reset(int N) {
        par.resize(N);
        for (int i = 0; i < N; ++i) par[i] = i;
        sz.assign(N, 1);
    }
};

void solve() {
    ll N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    while (Q--) {
        int query;
        cin >> query;
        if (query == 0) {
            int a, b;
            cin >> a >> b;
            uf.unite(a, b);
        }
        else {
            int a, b;
            cin >> a >> b;
            bool t = uf.same(a, b);
            prints()(t);
        }
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll ans = A[0];
    int idx = 1;
    for (int i = 2; i < N; i++) {
        ans += A[idx];
        if (i % 2 == 1) idx++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4828
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[305111];
int l[305011];
int j[305551];

long long x,y,z,mod=1000000007;
string r;
//char r[111];

P u[1];
queue<int> q;

stack<int> s;
map<int,int> p;
vector<int> v;

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;j[n]++,t++)
    scanf("%d",&n);
  for(int t=1;t<=a;t++)
    l[j[t]]++,o[j[t]]+=j[t];
  for(int t=1;t<=a;t++)
    o[t]+=o[t-1],l[a-t+1]+=l[a-t+2];
  for(int t=1;t<=a;t++)
  {
    n=0,m=a;
    for(;n<m;)
    {
      int h=(n+m)/2+1;
      if(o[h]+l[h+1]*h>=(long long)h*t) n=h;
      else m=h-1;
    }
    //printf("%d ",o[t]);
    printf("%d\n",n);
  }
}





Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    string s;
    cin >> s;
    REP(i,0,s.size()-8) cout << s[i];
    cout << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdbool.h>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<set>
#include<string>
#include<stdlib.h>
typedef long long ll;
using namespace std;

int main() {
	string s,a,b;
	cin >> s;
	a = s[0];
	b = s[s.size() - 1];
	s.erase(s.begin());
	s.erase(s.end() - 1);
	s = (string)to_string(s.size());
	cout << a + s + b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int N, p;
  std::cin >> N;
  int num_misplaced = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> p;
    if (p != i + 1) {
      num_misplaced++;
    }
  }
  if (num_misplaced == 0 || num_misplaced == 2) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

long long bezout_pair(long long a, long long b, long long &x, long long &y) {
    /* extended Euclidean algorithm */
    // get the gcd and a pair of Bezout coefficients
    long long gcd=a;
    if (b) {
        gcd = bezout_pair(b, a%b, y, x);
        y -= (a/b) * x;
    } else {
        x=1; y=0;
    }

    return gcd;
}

int main() {
    long long a, b;
    scanf("%lld %lld", &a, &b);

    long long x, y;
    bezout_pair(a, b, x, y);

    printf("%lld %lld\n", x, y);
    return 0;
}

Measured memory_bytes: 2752
def triple_dot():
    k = int(input())
    s = input()
    len_s =len(s)
    result_s = []
    
    if len_s > k:
        for i in range(k):
            result_s.append(s[i])
        print("".join(result_s) + "...")
    else:
        print("".join(s))
triple_dot()

Measured memory_bytes: 9092
def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)
  
  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1
    
def Same(x, y, par):
  return Find(x, par) == Find(y, par)
 
def Size(x, par):
  return -par[Find(x)]

n, k, l = map(int, input().split())
rpar = [-1]* n
tpar = [-1]* n
rrank = [0]*n
trank = [0]*n

for i in range(k):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, rpar, rrank) 

for i_ in range(l):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, tpar, trank)

d = {}
IDs = [0]*n
for j in range(n):
  ID = Find(j, rpar)+(Find(j, tpar)+1)*10**8
  IDs[j] = ID
  if ID in d:
    d[ID] += 1
  else:
    d[ID] = 1

for j_ in range(n):
  print(d[IDs[j_]])

    



  
  
    
    

Measured memory_bytes: 36204
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  int N;
  cin >> N;
  int dp[N+1];
  int cash[12];
  cash[0] = 1;
  for(int i = 1; i <= 6; i++){
    cash[i] = pow(6,i);
    if(i < 6) cash[i+6] = pow(9, i);
  }
  fill(dp, dp+N+1, INF);
  dp[0] = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < 12; j++){
      if(cash[j] <= i){
        dp[i] = min(dp[i], dp[i-cash[j]] + 1);
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <list>
using namespace std;

int main(){
    int n, a;
    cin >> n;
    unordered_set<int> x;
    for(int i = 0; i < n; i++){
        cin >> a;
        x.insert(a);
    }
    cout << (x.size() == n ? "YES" : "NO") << '\n';
}


Measured memory_bytes: 8520
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int n, k, x = 1;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		x = min(x * 2, x + k);
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int h[100005];
vector<int> adj[100005];
bool ok(int u){
	for(auto v:adj[u]) if(h[v]>=h[u]) return 0;
	return 1;
}
main(){
	int n,m;
	while(~getII(n,m)){
		FE(i,0,n) adj[i].clear();
		F(i,0,n) getI(h[i]);
		F(i,0,m){
			VgetII(u,v);
			u--,v--;
			adj[u].pb(v);
			adj[v].pb(u);
		}
		int ans=0;
		F(i,0,n){
			bool res=ok(i);
			//debug(res);
			if(res) ans++;
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 10388
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

k.times do
    break if a.all?(n)

    c = Array.new(n+1, 0)
    a.each_with_index do |e, i|
        c[ i - e < 0 ? 0 : i - e ] += 1
        c[ i + e + 1 > n ? n : i + e + 1 ] -= 1
    end
    a[0] = c[0]
    (n-1).times {|i| a[i+1] = a[i] + c[i+1]}
end

puts a.join(" ")

Measured memory_bytes: 80556
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char> > v(h , vector<char>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> v.at(i).at(j);
      }
    }

    for (int j = 0; j < w+2; j++) cout << "#";
    cout << endl;

    for (int i = 0; i < h; i++) {
      cout << "#";
      for (int j = 0; j < w; j++) {
        cout << v.at(i).at(j);
      }
      cout << "#" << endl;
    }

    for (int j = 0; j < w+2; j++) cout << "#";
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 string s;
 cin>>s;
 ll n = s.size();
 vector<ll> g( 2019 , 0 );
 g[ s[0]-'0' ]++;

 ll res = 0;
 for(ll i=1;i<n;i++){
  vector<ll> tmp(2019,0);
  for(ll j=0;j<2019;j++){
   tmp[ ( j*10 +(s[i]-'0') )%2019 ] += g[j];
  }
  tmp[ s[i]-'0' ]++;
  
  res += tmp[0];
  g = tmp;
 }
 cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ll long long
#define test(t) int t ; cin>>t ; while(t--)
ll mulmod(ll a, ll b, ll mod){ll res = 0;a = a % mod;while (b > 0){if (b % 2 == 1)res = (res + a) % mod;a = (a * 2) % mod;b /= 2;}return res % mod;}
int n;
int main(){
	BOOST;
	// cin >> n;
	string s , t;
	cin >> s >> t;
	s += s;
	if(s.find(t) == string::npos){
		cout << "No";
	}else{
		cout << "Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000007;

long long power(int a, int b)
{
    long long ret = 1;
    long long tmp = a;
    while(b > 0){
        if(b & 1){
            ret *= tmp;
            ret %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
        b >>= 1;
    }
    return ret;
}

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

    vector<long long> dp(c+1, 0);
    dp[0] = 1;
    for(int i=0; i<n; ++i){
        vector<long long> v(c+1, 0);
        for(int x=a[i]; x<=b[i]; ++x){
            long long y = 1;
            for(int j=0; j<=c; ++j){
                v[j] += y;
                v[j] %= MOD;
                y *= x;
                y %= MOD;
            }
        }

        vector<long long> nextDp(c+1, 0);
        for(int j=0; j<=c; ++j){
            for(int k=0; j+k<=c; ++k){
                nextDp[j+k] += dp[j] * v[k];
                nextDp[j+k] %= MOD;
            }
        }
        dp.swap(nextDp);
    }
    cout << dp[c] << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
acgt = ['A','C','G','T' ]
count = 0

while s.length > 0
  if acgt.include?(s[0])
    i = 0
    while acgt.include?(s[i])
      count = [i+1, count].max
      i += 1
    end
  end
  s.slice!(0)
end

puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
set<int>s;
int a[100010];
int main()
{
	int n;
	scanf("%d",&n);
	int x;
	while(n--)
	{
		scanf("%d",&x);
		if(s.find(x)!=s.end())
		{
			s.erase(x);
		}
		else
		{
			s.insert(x);
		}	
	}
	
	printf("%d",s.size());
	return 0;
 } 

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
struct SegmentTree {
    int n;
    vector<T> node;
    T calc(T a, T b) {
        return a + b;
        // return min(a, b);
        // return max(a, b);
    }
    T e = 0;
    SegmentTree(vector<T> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, e);
        for (int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    SegmentTree(T sz) {
        n = 1;
        while (n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, e);
    }
    void update(int x, T val) {
        x = n + x - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = calc(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    void add(int x, T val) {
        x = n + x - 1;
        node[x] += val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = calc(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return e;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return calc(vl, vr);
    }
    T at(int x) {
        return node[n + x - 1];
    }
};
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    SegmentTree<ll> segt(a);
    ll ans = LINF;
    for (int i = 1; i < n; i++) {
        chmin(ans, abs(segt.query(0, i) - segt.query(i, n)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7424
N = int(input())
a = list(map(int, input().split()))
b = [0] * N
for i in range(N):
    b[i] = a[i] - (i + 1)
b.sort()
if N % 2 == 0:
    m = (b[N // 2 - 1] + b[N // 2]) // 2
else:
    m = b[N // 2]
ans = 0
for i in range(N):
    ans += abs(b[i] - m)
print(ans)

Measured memory_bytes: 25196
#include<stdio.h>

int main(void)
{
	int i,j,n;
	int ind[7];
	double h;
	
	for(i=0;i<6;i++) ind[i]=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lf",&h);
		if(h<165)
		ind[0]++;
		else if(h<170)
		ind[1]++;
		else if(h<175)
		ind[2]++;
		else if(h<180)
		ind[3]++;
		else if(h<185)
		ind[4]++;
		else
		ind[5]++;
	}
	for(i=0;i<6;i++)
	{
		printf("%d:",i+1);
		if(ind[i]>0)
		for(j=0;j<ind[i];j++) printf("*");
		printf("\n");
	}
	return 0;
}

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

int main(){
    int N,x=0;
    cin>>N;
    int p[N];
    for(int i=0;i<N;i++){
        cin>>p[i];
        if(p[i]!=i+1)x++;
    }
    
    if(x==0||x==2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 256
//{{{
#[allow(unused_macros)]
macro_rules! getl {
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right();
            let mut ws = s.split_whitespace();
            ($(ws.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! getl_vec {
    ( $t:ty ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right();
        s.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<$t>>()
    }};
}
//}}}

const INF: u64 = (1 << 31) - 1;

fn main() {
    const UPDATE: u64 = 0;
    const FIND: u64 = 1;

    let (n, q) = getl!(usize, usize);
    let mut queries = vec![];
    for _ in 0..q {
        queries.push(getl!(u64, u64, u64));
    }

    let mut segtree = SegmentTree::new(&vec![INF; n], std::cmp::min, INF);
    for (ty, a, b) in queries {
        if ty == UPDATE {
            segtree.update(a as usize, b);
        } else {
            let ans = segtree.query(a as usize, b as usize + 1);
            println!("{}", ans);
        }
    }
}

struct SegmentTree<T, F>
where
    F: Fn(T, T) -> T + Copy,
    T: Clone + Copy,
{
    len: usize,
    data: Vec<T>,
    operator: F,
    unit: T,
}

impl<T, F> SegmentTree<T, F>
where
    F: Fn(T, T) -> T + Copy,
    T: Clone + Copy,
{
    // const INF: u64 = std::u64::MAX >> 2;

    fn new(v: &Vec<T>, operator: F, unit: T) -> SegmentTree<T, F> {
        let n = v.len();
        let mut len = 1;
        while len < n {
            len *= 2;
        }

        let mut segtree = SegmentTree {
            len: len,
            data: vec![unit; 2 * len - 1],
            operator: operator,
            unit: unit,
        };

        for i in 0..n {
            segtree.data[i + segtree.len - 1] = v[i];
        }
        for i in (0..(segtree.len - 1)).rev() {
            segtree.data[i] = operator(segtree.data[2 * i + 1], segtree.data[2 * i + 2]);
        }

        segtree
    }

    fn update(&mut self, k: usize, a: T) {
        let data = &mut self.data;
        let mut k = k + self.len - 1;
        data[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            data[k] = (self.operator)(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    fn query(&self, a: usize, b: usize) -> T {
        self.process_query(a, b, 0, 0, self.len)
    }

    fn process_query(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return self.unit;
        }

        if a <= l && r <= b {
            self.data[k]
        } else {
            let vl = self.process_query(a, b, k * 2 + 1, l, (l + r) / 2);
            let vr = self.process_query(a, b, k * 2 + 2, (l + r) / 2, r);
            (self.operator)(vl, vr)
        }
    }
}



Measured memory_bytes: 12088
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,x;
    while(cin>>n>>x){
        int l,cnt=1,s=0;
        for(int i=0;i<n;i++){
            cin>>l;
            s+=l;
            cnt+=(s<=x);
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

int main()
{
    char N[5];
    cin >> N;
    
    if (N[0] == N[1] && N[1] == N[2]) cout << "Yes";
    else if (N[1] == N[2] && N[2] == N[3])  cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	int n, m;
	cin >> n >> m;

	int mat[100][100], vec[100];

	for (int i = 0;i < n;i++)
		for (int j = 0;j < m;j++)
			cin >> mat[i][j];

	for (int i = 0;i < m;i++)
		cin >> vec[i];

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

		for (int j = 0; j < m; j++)
		{
			sum += mat[i][j] * vec[j];
		}

		cout << sum << endl;
	}

	return 0;
}



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

long long N,K;
long long A[60];
long long dp[60][5010] = {0};

int main()
{
    scanf("%lld%lld",&N,&K);
    for(int i = 0; i < N; i++)
    {
        scanf("%lld",&A[i]);
        A[i] -= K;
    }
    dp[0][2500] = 1;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 5000; j++)
        {
            if(dp[i][j] == 0)
            {
                continue;
            }
            dp[i + 1][A[i] + j] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    }
    printf("%lld\n",dp[N][2500] - 1);
}


Measured memory_bytes: 896
def insert_string_to_base(target_string, insert_point, insert_string):
    return target_string[:insert_point] + insert_string + target_string[insert_point:]

def main():
    N = str(input())
    l = len(N)-1

    result = 0
    for i in range(2 ** l):
        count = 1
        st = N
        for j in range(l):
            if ((i >> j) & 1):
                st = insert_string_to_base(st, j+count, "+")
                count+=1

        for v in st.split("+"):
            if(v != ''):
                result += int(v)
    print(result)


if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
#include <stdio.h>

int D[101];
int co[101];
int F[101];
int A[101][101];
int time;
void tp(int,int);
void dfs(int);
int main(){
  int i,n,j,c,r,temp;
    //値の入力
  scanf("%d",&n);
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){   
	A[i][j]=0;
      }
    }
    for(j=1;j<=n;j++){  
      scanf("%d%d",&c,&r);

      for(i=1;i<=r;i++){
	scanf("%d",&temp);
	A[c][temp]=1;
      }
    }

    dfs(n);
    
    for(i=1;i<=n;i++){
      printf("%d %d %d\n",i,D[i],F[i]);
    }

    return 0;

}

void tp(int i,int n){
  int j;
  co[i]=1;
  D[i]=++time;
  for(j=1;j<=n;j++){

    if(A[i][j]==1 && co[j]==0)tp(j,n);
  
  }
  co[i]=2;
  F[i]=++time;

}
void dfs(int n){
  int i;
  for(i=1;i<=n;i++){
    co[i]=0;
  }
  time=0;
  for(i=1;i<=n;i++){
    if(co[i]==0) tp(i,n);
  }
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e5+200;
ll a[maxn];
int main(){
	ll n,k;
	cin>>n>>k;
	n%=k;
	cout<<min(n,abs(n-k));
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();
		String t = sc.next();
		String s = sc.next();
		System.out.println(s + t);
		
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
//	public void run() throws Exception
//	{
//		System.out.println("Hi");
//	}
	public static void main (String[] args) throws Exception {
		new Main().run();
	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a, b;
    cin >> a >> b;
    if(a.size()>b.size()){
        cout << "GREATER" << endl;
    }else if(a.size()<b.size()){
        cout << "LESS" << endl;
    }else{
        for(int i=0; i<a.size(); i++){
            if(a[i]>b[i]){
                cout << "GREATER" << endl;
                break;
            }else if(a[i]<b[i]){
                cout << "LESS" << endl;
                break;
            }
            if(i==a.size()-1){
                cout << "EQUAL" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
S = list(map(int, list(input())))
MOD = 2019

acc_mod = [0]
for i, s in enumerate(S[::-1]):
    acc_mod.append((acc_mod[-1] + s * pow(10, i, MOD)) % MOD)

ans = 0
for v in Counter(acc_mod).values():
    ans += v * (v - 1) // 2
print(ans)


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  string s;
  cin >> s;
  if(s == "KIHBR") cout << "YES" << endl;
  else if(s == "KIHBRA") cout << "YES" << endl;
  else if(s == "KIHBAR") cout << "YES" << endl;
  else if(s == "KIHBARA") cout << "YES" << endl;
  else if(s == "KIHABR") cout << "YES" << endl;
  else if(s == "KIHABRA") cout << "YES" << endl;
  else if(s == "KIHABAR") cout << "YES" << endl;
  else if(s == "KIHABARA") cout << "YES" << endl;
  else if(s == "AKIHBR") cout << "YES" << endl;
  else if(s == "AKIHBRA") cout << "YES" << endl;
  else if(s == "AKIHBAR") cout << "YES" << endl;
  else if(s == "AKIHBARA") cout << "YES" << endl;
  else if(s == "AKIHABR") cout << "YES" << endl;
  else if(s == "AKIHABRA") cout << "YES" << endl;
  else if(s == "AKIHABAR") cout << "YES" << endl;
  else if(s == "AKIHABARA") cout << "YES" << endl;
  else cout << "NO" << endl;
}   

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

int n;
int h[MAXN];
int DP[MAXN];

int rek(int pos) {
	if (pos == n - 1) return 0;
	int &ret = DP[pos];
	if (ret != -1) return ret;
	ret = INF;
	if (pos + 1 < n) ret = min(ret, abs(h[pos + 1] - h[pos]) + rek(pos + 1));
	if (pos + 2 < n) ret = min(ret, abs(h[pos + 2] - h[pos]) + rek(pos + 2));
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	memset(DP, -1, sizeof DP);
	cin >> n;
	REP(i, n) cin >> h[i];
	cout << rek(0) << '\n';
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define MIN(a,b) ((a) < (b) ? (a) : (b))

int main() {
    int N, M, L, Q;
    scanf("%d %d %d\n",&N,&M,&L);

    int **roads, **costs;
    int i,j,k;
    roads = (int **)malloc(sizeof(int*)*N);
    costs = (int **)malloc(sizeof(int*)*N);
    for (i=0; i<N; i++) {
        roads[i] = (int *)malloc(sizeof(int)*N);
        costs[i] = (int *)malloc(sizeof(int)*N);
        for (j=0; j<N; j++)  roads[i][j] = costs[i][j] = INT_MAX/2;
        roads[i][i] = costs[i][i] = 0;
    }

    int A, B, C;
    for (i=0; i<M; i++) {
        scanf("%d %d %d\n", &A, &B, &C);
        roads[A-1][B-1] = roads[B-1][A-1] = C;
    }

    for (k=0; k<N; k++)
        for (i=0; i<N; i++)
            for (j=0; j<N; j++)
                roads[i][j] = MIN(roads[i][j], roads[i][k]+roads[k][j]);

    for (i=0; i<N; i++)
        for (j=0; j<N; j++) {
            if (i == j)  continue;
            costs[i][j] = roads[i][j] <= L ? 1 : INT_MAX/2;
        }

    for (k=0; k<N; k++)
        for (i=0; i<N; i++)
            for (j=0; j<N; j++)
                costs[i][j] = MIN(costs[i][j], costs[i][k]+costs[k][j]);

    scanf("%d\n",&Q);
    while (Q--) {
        scanf("%d %d",&A,&B);
        printf("%d\n", costs[A-1][B-1] > 1000 ? -1 : costs[A-1][B-1]-1);
    }

    for (i=0; i<N; i++) {
        free(roads[i]);
        free(costs[i]);
    }
    free(roads);
    free(costs);
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main()
{
  
  int N;
  string S;
  cin >> N >> S;
  N = S.length();
  int ans = 0;
  
  for(int i=0; i<N-2; i++){

    if (S[i]=='A' and S[i+1]=='B' and S[i+2]=='C'){
     ans += 1;
    }
  }
  
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def solve2():
    L = input()[:-1]
    int_L = int(L, 2)
    ans = 1  # (0,0)のぶん
    for l in range(1, int_L+1):  # 10**6
        bit_cnt = bin(l).count("1")  # 遅そうO(len(bin(l)))
        ans += pow(2, bit_cnt, MOD)
        ans %= MOD
    print(ans)


def solve3():
    L = input()[:-1]
    # dp[smaller?][上からi桁目まで見た] = 何通りあるか?
    dp = [[0]*2 for _ in range(len(L)+1)]
    dp[0][0] = 1  # 0

    for i, c in enumerate(L):
        dp[i+1][0] = dp[i][0]*(int(c)+1)
        dp[i+1][1] = dp[i][1]*3+dp[i][0]*int(c)

        dp[i+1][0] %= MOD
        dp[i+1][1] %= MOD
    print(sum(dp[-1]) % MOD)


solve3()


Measured memory_bytes: 19700
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let ab=readInts()
let a=ab[0]
let b=ab[1]
var mouth=a
var ans=1

print(Int(ceil(Double(b-1)/Double(a-1))))

Measured memory_bytes: 13656
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

-- 
--
--

main = do
    inp <- getLine
    putStrLn $ keyboard inp
    where
        keyboard a = reverse $ k a []
            where
                k [] str = str
                k ('0':a) str = k a ('0':str)
                k ('1':a) str = k a ('1':str)
                k ('B':a) [] = k a []
                k ('B':a) str = k a (tail str)


Measured memory_bytes: 380
import math


def f(base, n):
    # 10進数 n を, base 進数に変換して各桁を足し合わせる
    total = 0
    while n > 0:
        # print('除', n // base, 'あまり', n % base)
        total += n % base
        n = n // base
    return total


def solve():
    N, S = int(input()), int(input())
    # print(N, S)

    if N == S:
        return N + 1

    for b in range(2, int(math.sqrt(N)) + 1):
        if f(b, N) == S:
            return b

    largest = N**2
    lowest = largest
    for p in range(1, int(math.sqrt(N)) + 1):
        b = int((N - S) / p + 1)
        if b > 1 and f(b, N) == S:
            lowest = min(lowest, b)

    if not lowest == largest:
        return lowest

    return -1


if __name__ == '__main__':
    res = solve()
    print(res)


Measured memory_bytes: 40668
N = int(input())
a = list(map(int,input().split()))
maxa  = max(a)
mina  = min(a)

print(2*N-1)
r = False
if abs(maxa) >= abs(mina):
    d = maxa
else:
    r = True
    d = mina
ind = a.index(d) + 1

for i in range(N):
    print(ind, i+1)

if r:
    for i in range(N - 1)[::-1]:
        print(i+2, i+1)
else:
    for i in range(N-1):
        print(i+1, i+2)

Measured memory_bytes: 3064
import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    cumA = np.cumsum(A)
    total = cumA[-1]
    ans = 10 ** 10000
    for a in cumA[:-1]:
        ans = min(ans, abs(a - (total - a)))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49348
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

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

Measured memory_bytes: 256
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;

int main() 
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a%2||b%2||c%2)
	{
		printf("0\n");
		return 0;
	}
	if(a==b&&b==c)
	{
		printf("-1\n");
		return 0;
	}
	int an=32;
	int x=a+b;
	int cnt=0;
	while(x%2==0)
	{
		cnt++;
		x/=2;
	}
	an=min(an,cnt);
	x=b+c;
	cnt=0;
	while(x%2==0)
	{
		cnt++;
		x/=2;
	}
	an=min(an,cnt);
	x=a+c;
	cnt=0;
	while(x%2==0)
	{
		cnt++;
		x/=2;
	}
	an=min(an,cnt);
	printf("%d\n",an);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 1) {
            System.out.println(1);
            return;
        }
        int max = 1;
        for (int i = 2; i <= x; i++) {
            for (int j = 2; (int)Math.pow(i, j) <= x; j++) {
                max = Math.max(max, (int)Math.pow(i, j));
            }
        }
        System.out.println(max);
    }
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    string s;
    LL x=0;
    cin>>s;
    for(int i=0;i<s.size();i++)
        x+=s[i]-'0';
    if(x%9)
        cout<<"No";
    else
        cout<<"Yes";

}


Measured memory_bytes: 3760
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

int main() {
    int n; scanf("%d", &n);
    vector<ll> a(n); repeat (i, n) scanf("%lld", &a[i]);
    ll x = a[0];
    ll y = whole(accumulate, a, 0ll) - a[0];
    ll result = abs(x - y);
    repeat_from (i, 1, n - 1) {
        x += a[i];
        y -= a[i];
        setmin(result, abs(x - y));
    }
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

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

  for (int i = 0; i < 3; i++){
    if (s[0][i] != s[1][2 - i]){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N], b[N], c[N];
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < n; i++) {
    cin >> c[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += b[a[i]];
    if (i > 1 && a[i] - a[i-1] == 1) ans += c[a[i] - 1];
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,c;
  char s[100];
  scanf("%d",&n);
  (void) getchar();
  scanf("%s",s);
  for (int i = 0; i < n; i++) {
    if ( s[i] == 'R' ) c++;
    else c--;
  }
  if( c > 0 ) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
import java.io.*;

class Main{

    public static void main(String[] args)throws IOException{

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	while(true){
	    String input = br.readLine();
	    String[] div = input.split(" ");
	    int height = Integer.parseInt(div[0]);
	    int width = Integer.parseInt(div[1]);

	    if(height == 0 && width == 0){
		break;
	    }

	    for(int i = 0; i < height; i++){
		
		if(i == 0 || i == height - 1){
		    
		    for(int j = 0; j < width; j++){
			System.out.printf("#");
		    }
		    System.out.printf("\n");
		    
		}else{
		    
		    System.out.printf("#");
		    for(int j = 0; j < width - 2; j++){
			System.out.printf(".");
		    }
		    System.out.printf("#\n");
		}
		
	    }
	    System.out.printf("\n");
	    
	}

    }

}

Measured memory_bytes: 43700