akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(ll factor[],ll n){
    ll a = 2;
    bool flag = false;
    for(int p = 2;p*p <= n;p++){
        while(n%p == 0){
            n/=p;
            factor[p]++;
        }
    }
    if(n!=1)  factor[n]++; //prime num
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
   int n; cin >> n;
   int a[n];
   rep(0,n) cin >> a[i];
   sort(a,a+n);
   int e = 0,b = 0;
   rrep(n-1,0){
       if((n-1 - i)%2 == 0) e+=a[i];
       else b += a[i]; 
   }
   cout << abs(e-b) << endl;

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

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int main(){
    int long long n,h,w;
    cin>>n>>h>>w;
    int long long ans=0;
    for(int i=0;i<n;i++){
        int long long a,b;
        cin>>a>>b;
        if(a>=h&&b>=w){
            ans++;
        }
    }
    cout<<ans<<endl;
    

return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[]
while n>0:
    s,y=map(str,input().split())
    if y=='JPY':
        k=int(s)
        l.append(k)
        n-=1
    else:
        j=float(s)*380000
        l.append(j)
        n-=1
print(sum(l))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		while(h!=0 && w != 0){
			for(int j=0;j<w;j++) {
					System.out.print("#");
			}
			System.out.println();
			
			for(int i=0; i<h-2 ;i++) {
				System.out.print("#");
				for(int k = 0;k < w-2;k++) {
					System.out.print(".");
				}
				System.out.print("#");
				System.out.println();
			}
			
			for(int j=0;j<w;j++) {
				System.out.print("#");
			}
			System.out.println();
			h = sc.nextInt();
			w = sc.nextInt();
			System.out.println();
		}
		sc.close();
	}
}



Measured memory_bytes: 34152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll res1 = 0, res2 = 0, sum = 0;
  rep(i, n) {
    sum += a[i];
    if(i % 2 == 0) {
      res1 += max(0LL, 1 - sum);
      sum = max(sum, 1LL);
    } else {
      res1 += -1 * min(0LL, -1 - sum);
      sum = min(sum, -1LL);
    }
  }
  sum = 0;
  rep(i, n) {
    sum += a[i];
    if(i % 2 == 1) {
      res2 += max(0LL, 1 - sum);
      sum = max(sum, 1LL);
    } else {
      res2 += -1 * min(0LL, -1 - sum);
      sum = min(sum, -1LL);
    }
  }
  cout << min(res1, res2) << endl;
}

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

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        while((str = br.readLine()) != null){
            if(str.equals("-")){
                break;
            }

           StringBuilder aabc =new StringBuilder(str);
           int L = aabc.length();//4
           str = br.readLine();
           int m = Integer.parseInt(str);//3
           for(int i=0;i<m;i++){
            str = br.readLine();
            int h = Integer.parseInt(str);//1,2,1
            String temp = aabc.substring(0,h);//substring doesn't include index No of h
            aabc.append(temp);
            aabc.delete(0,h);
           }

           System.out.println(aabc.toString());
        }
    }
}

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

struct info {
    string cn;
    int score, sn;
    
    bool operator< (const info& rhs) {
        if(cn != rhs.cn) return cn < rhs.cn;
        return score > rhs.score;
    }
} cities[103];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> cities[i].cn >> cities[i].score;
        cities[i].sn = i;
    }
    sort(cities, cities + n + 1);
    for(int i = 1; i <= n; i++) {
        cout << cities[i].sn << "\n";
    }
}


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


// 1000000007 で割ったあまりを扱う構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;


mint solve(const string &L) {
    long long num = 0;
    mint res = 0;
    for (int i = 0; i < L.size(); ++i) {
        int len = (int)L.size() - i - 1;
        if (L[i] == '1') {
            res += modpow(mint(2), num) * modpow(mint(3), len);
            ++num;
        }
    }
    res += modpow(mint(2), num);
    return res;
}

int main() {
    string L; cin >> L;
    cout << solve(L) << endl;
}

Measured memory_bytes: 512
import heapq
import sys

sys.setrecursionlimit(10**5)

def add(i,pj,T):
    if T[i]!=i:
        add(T[i],pj,T)
    T[i]=pj
    
def parent(i,T):
    if T[i]!=i:
        T[i]= parent(T[i],T)
        return T[i]
    else:
        return i

N=int(input())
town=[]
for i in range(N):
    x,y=list(map(int,input().split()))
    town.append([i,x,y])
townX=sorted(town,key=lambda x:x[1])
townY=sorted(town,key=lambda x:x[2])
road=[]
for i in range(1,N):
    heapq.heappush(road,[townX[i][1]-townX[i-1][1],townX[i-1][0],townX[i][0]])
for i in range(1,N):
    heapq.heappush(road,[townY[i][2]-townY[i-1][2],townY[i-1][0],townY[i][0]])

vi=0
ans=0
tree=[i for i in range(N)]
rank=[0 for i in range(N)]
while vi<N-1:
    d,u,v = heapq.heappop(road)
    pu=parent(u,tree)
    pv=parent(v,tree)
    ru=rank[pu]
    rv=rank[pv]
    if pu == pv:
        continue
    elif ru<rv:
        add(u,pv,tree)
    elif ru==rv:
        add(u,pv,tree)
        rank[pu]+=1
    else:
        add(v,pu,tree)
    vi+=1
    ans+=d
print(ans)

Measured memory_bytes: 77724
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 1005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
string get_lcp(string& a, string& b) {
	int len = min(a.size(), b.size());
	int k = 0;
	for (; k < len; k++) {
		if (a[k] != b[k]) break;
	}
	return a.substr(0, k);
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int A, B;
	scanf("%d %d", &A, &B);
	int res = max(A, B);
	if (A > B) A--;
	else B--;
	res += max(A, B);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
using namespace std;
typedef long long LL;
#define ms(a,b) memset(a,b,sizeof(a))
#define eps 1e-8
const int maxn=1e5+100;

LL a[maxn],w[maxn];
int main()
{
    //freopen("c:\\in.txt","r",stdin);
    char s[10],ss[10];
    scanf("%s%s",s,ss);
    printf("%s\n",s[0]>ss[0]?">":(s[0]==ss[0]?"=":"<"));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <unordered_map>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    string s;
    cin >> s;
    
    ll ans = 0;
    ll r[200001];
    unordered_map<ll,ll> mp;
    
    r[s.length()] = 0;
    mp[0] = 1;
    ll d = 1;
    for(ll i = s.length()-1; i >= 0; i--){
        r[i] = (r[i+1] + (s[i]-'0')*d) %2019;
        if(mp.find(r[i]) == mp.end()){
            mp[r[i]] = 1;
        } else {
            mp[r[i]] += 1;
        }
        d = d * 10 % 2019;
    }

    for(auto it = mp.begin(); it != mp.end(); it++){
        ans += (*it).second*((*it).second-1)/2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5292
#include<stdio.h>
int pushBack(int A[],int x,int tail)
{
  A[tail]=x;
  tail++;
  return tail;
}
void randomAccess(int A[],int p)
{
  printf("%d\n",A[p]);
}
int popBack(int tail)
{
  return tail-1;
}
int main(void)
{
  int p,q,i,ord,x,A[200000],tail=0;
  scanf("%d",&q);
  for(i=0;i<q;i++)
  {
    scanf("%d",&ord);
    if(ord==0)
    {
      scanf("%d",&x);
      tail=pushBack(A,x,tail);
    }
    else if(ord==1)
    {
      scanf("%d",&p);
      randomAccess(A,p);
    }
    else if(ord==2)
    {
      tail=popBack(tail);
    }
  }
  return 0;
}



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

using namespace std;


struct Pos {
    int r, c;
    int color;
    Pos() {}
    Pos(int r, int c, int color): r(r), c(c), color(color) {}
    bool operator < (const Pos& o) const {
        return make_tuple(r, c, color) < make_tuple(o.r, o.c, o.color);
    }
    Pos invert() {
        return Pos(r, c, 1 - color);
    }
    Pos down() {
        return Pos(r+1, c, color);
    }
    Pos right() {
        return Pos(r, c+1, color);
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> colors(h, vector<int>(w));
    for (auto& color_row : colors) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            color_row[j] = s[j] == '#';
        }
    }
    priority_queue<pair<int, Pos>> pq;
    map<Pos, int> dists;
    pq.push(make_pair(-colors[0][0], Pos(0, 0, colors[0][0])));
    auto add_if_valid = [&](int dist, Pos new_pos) {
        if (new_pos.r < h && new_pos.c < w && colors[new_pos.r][new_pos.c] == new_pos.color) {
            pq.push(make_pair(-dist, new_pos));
        }
    };
    while (!pq.empty()) {
        auto p = pq.top();
        int dist = -p.first;
        Pos pos = p.second;
        pq.pop();
        if (dists.find(pos) != dists.end()) {
            continue;
        }
        dists[pos] = dist;
        pq.push(make_pair(-(dist+1), pos.invert()));
        add_if_valid(dist, pos.down());
        add_if_valid(dist, pos.right());
    }
    int answer = (dists[Pos(h-1, w-1, 0)] + 1) / 2;
    cout << answer << endl;
    return 0;
}


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

const ll INF = 10010001010;

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

typedef tuple<string, int, int> TUP;

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

int main(){
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> data(m);
  rep(i, m) cin >> data.at(i);

  int sum = 0;

  rep(i,m){
    sum += data.at(i);
  }

  if(n-sum >= 0){
    cout << n - sum << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3640
//C - Tsundoku
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  long long int n,m,k,i,j,inin,num,jmax,ans,aa,bb,a[200010]={},b[200010]={};
  scanf("%lld %lld %lld", &n, &m, &k);
  for(i = 1; i <= n; i++) {
    scanf("%lld", &aa);
    a[i]=a[i-1]+aa;
  }
  for(j = 1; j <= m; j++) {
    scanf("%lld", &bb);
    b[j]=b[j-1]+bb;
  }

  ans=0;
  inin=0;
  jmax=m;
  //long long int x[200010]={};
  for(i = 0; i <= n; i++) {
    for(j = jmax; j >= 0; j--) {
      if(a[i]+b[j]<=k){
        ans=max(ans,i+j);
        jmax=j;
        break;
      }
    }
  }
/*
  ans=x[1];
  for(i = 1; i <= inin; i++) {
    //printf("%lld\n", x[i]);
    ans=max(ans,x[i]);
  }
*/
  printf("%lld\n", ans);

  return 0;
}




/*
int main()
{
  int n,m,k,i,j,aa,num,ans;
  scanf("%d %d %d", &n, &m, &k);
  long long int a[200010],b[200010];
  a[0] = b[0] = 0;
  for(i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for(j = 1; j <= m; j++) {
    scanf("%lld", &b[j]);
  }
  aa=n+m;
  i=1;
  j=1;
  ans=0;
  while(1){
    if(a[i]<=b[j] && i<=n && j<=m){
      num+=a[i];
      if(num>k){
        break;
      }
      else{
        i++;
        ans++;
      }
    }
    else if(a[i]>=b[j] && i<=n && j<=m){
      num+=b[j];
      if(num>k){
        break;
      }
      else{
        j++;
        ans++;
      }
    }
    else if(i==n+1 && j<=m){
      num+=b[j];
      if(num>k){
        break;
      }
      else{
        j++;
        ans++;
      }
    }
    else if(i<=n && j==m+1){
      num+=a[i];
      if(num>k){
        break;
      }
      else{
        i++;
        ans++;
      }
    }
    else if(i==n+1 && j==m+1){
      break;
    }
    else{
      break;
    }


  }


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

  return 0;
}
*/


Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
  
using namespace std;
  
bool isPrime ( int n )
{
  if (n == 2) { return true; }
  if ((n & 1) == 0) { return false; }
  
  for (int i = 3; (i*i) <= n; i += 2)
  {
    if ((n % i) == 0) { return false; }
  }
  
  return (n != 1);
}
  
int main ( void )
{
  int n, count = 0;
  
  cin >> n;
  
  for (int i = 0; i < n; ++i)
  {
    int p;
  
    cin >> p;
  
    if (isPrime(p)) { ++count; }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define st string
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define gcd __gcd
using namespace std;
signed main() {
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int sum=0;
  int d=abs(x-y);
  sum+=min(x,y)*min(a+b,2*c);
  if(x>y) sum+=min(a*d,d*2*c);
  else sum+=min(b*d,d*2*c);
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]){
        print("Yes");
    }else{
        print("No");
    }
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=1e3+10;
bool flag[128];
char s[maxn];

int main(){
	scanf("%s",s);
	for(int i=0;s[i];++i)
		flag[s[i]]=true;
	if(flag['E']!=flag['W']||flag['N']!=flag['S'])
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 256
line = [*0..9] + [5, 4, 3, 2, 1]
line += line

$<.gets.to_i.times do
  start, goal = $<.gets.split.map(&:to_i)
  str = if 1 <= start and start <= 5 and start > goal
    [*goal..start].reverse.join(" ")
  else
    a = line.index(start)
    b = line[a + 1..-1].index(goal)
    line[a..a + 1 + b].join(" ")
  end
  puts str
end


Measured memory_bytes: 6844
#include<iostream>

int main(void){
    int n, h;
    std::cin >> n;
    std::cin >> h;
    int b = h;
    for(int i = 1; i < n; i++){
        std::cin >> h;
        if(b > h){
            std::cout << "No" << std::endl;
            return 0;
        }else if(b <= h - 1){
            h--;
        }
        b = h;
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 3676
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}
func main() {
	var S, T string
	fmt.Scanf("%s\n%s\n", &S, &T)
	cnt := 0
	for i := 0; i < 3; i++ {
		if S[i] == T[i] {
			cnt++
		}
	}
	fmt.Println(cnt)

}


Measured memory_bytes: 512
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nums = inputs(0).split(" ").map(_.toInt)
  val a = nums(0)
  val b = nums(1)
  val c = nums(2)
  val k = nums(3)

  println(solve(a, b, c, k))

  def solve(a: Int, b: Int, c: Int, k: Int): Int = {
    var ans = 0

    if(k < a) {
      ans = k
    } else if (k <= a + b) {
      ans = a
    } else {
      val tmpK = k - (a + b)
      ans = a + (tmpK * -1)
    }
    return ans
  }
}

Measured memory_bytes: 54896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define _overload1(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload1(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _overload2(_1, _2, _3, name, ...) name
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (ll i = (ll)(a - 1); i >= (ll)(b); --i)
#define rrep(...) _overload2(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-15, PI = acos(-1);
const ll INF = 1'010'000'000'000'000'017LL;

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

ll const maxn = 1e6 + 5;
ll dp[maxn][2];

void Main() {
  string s;
  cin >> s;
  reverse(all(s));
  memset(dp, INF, sizeof(dp));
  dp[0][0] = s[0] - '0';
  dp[0][1] = 10 - dp[0][0];
  rep(i, 1, s.size()) {
    ll c = s[i] - '0';
    dp[i][0] = min(dp[i - 1][0] + c, dp[i - 1][1] + c + 1);
    dp[i][1] = min(dp[i - 1][0] + 10 - c, dp[i - 1][1] + 10 - c - 1);
  }
  ll ans = min(dp[(ll)s.size() - 1][0], dp[(ll)s.size() - 1][1] + 1);
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)
#define sz(v) ((int)v.size())
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

struct line {
  ll m, b;
  ll eval(ll x) { return m * x + b; }
  ld inter(line &l) { return (ld) (b - l.b) / (l.m - m); }
};

struct cht {
  vector<line> lines;
  vector<ld> inter;
  int n;
  inline bool ok(line &a, line &b, line &c) {
    return a.inter(c) > a.inter(b);
  }
  void add(line &l) { /// m1 < m2 < m3 ...
    n = sz(lines);
    if(n && lines.back().m == l.m && lines.back().b >= l.b) return;
    if(n == 1 && lines.back().m == l.m && lines.back().b < l.b) lines.pop_back(), n--;
    while(n >= 2 && !ok(lines[n-2], lines[n-1], l)) {
      --n;
      lines.pop_back(); inter.pop_back();
    }
    lines.pb(l); n++;
    if(n >= 2) inter.pb(lines[n-2].inter(lines[n-1]));
  }
  ll get_max(ld x) {
    if(sz(lines) == 0) return LLONG_MIN;
    if(sz(lines) == 1) return lines[0].eval(x);
    int pos = lower_bound(all(inter), x) - inter.begin();
    return lines[pos].eval(x);
  }
};


const ll inf = 1e18;
const int nax = 2e5+200;
ll C;
ll h[nax];
ll dp[nax];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout<< setprecision(20)<< fixed;
  int n;
  cin>> n>> C;
  for1(i,n){
    cin>> h[i];
  }
  cht ch;
  for(int i = 1; i<= n; ++i){
    ll tmp = -C;
    if(i>1){
      tmp += -h[i]*h[i] + ch.get_max(h[i]);
    }
    dp[i] = (i==1 ? 0 : tmp);
    line l = {2*h[i], dp[i] - h[i]*h[i]};
    ch.add(l);
  }
  cout<< -dp[n]<<el;
  return 0;
}


Measured memory_bytes: 13204
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

int rotation(int x, int y, int i, int n)
{
	int cos_r[4] = {1, 0, -1, 0};
	int sin_r[4] = {0, 1, 0, -1};
	if(n == 0) return x * cos_r[i] - y * sin_r[i];
	else return x * sin_r[i] + y * cos_r[i];
}

bool issame(int temple_x[], int temple_y[], int comp_x[], int comp_y[], int m)
{
	int dx[2] = {1, -1};
	int dy[2] = {1, -1};
	int cnt = 0;
	int tmpvec_x[10], tmpvec_y[10], compvec_x[10], compvec_y[10];
	for(int i = 0; i < m - 1; i++){
		tmpvec_x[i] = temple_x[i + 1] - temple_x[i];
		tmpvec_y[i] = temple_y[i + 1] - temple_y[i];
		compvec_x[i] = comp_x[i + 1] - comp_x[i];
		compvec_y[i] = comp_y[i + 1] - comp_y[i];
	}
	for(int i = 0; i < 2; i++){
		cnt = 0;
		while(cnt < m - 1){
			if(tmpvec_x[cnt] * dx[i] == compvec_x[cnt] && tmpvec_y[cnt] * dy[i] == compvec_y[cnt]) cnt++;
			else break;
		}
		if(cnt == m - 1) return true;
		cnt = 0;
		while(cnt < m - 1){
			if(tmpvec_x[m - 2 - cnt] * dx[i] == compvec_x[cnt] && tmpvec_y[m - 2 - cnt] * dy[i] == compvec_y[cnt]) cnt++;
			else break;
		}
		if(cnt == m - 1) return true;
	}
	
	return false;
}

int main()
{
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int vertice_x[51][10], vertice_y[51][10];
		int m[51];
		for(int i = 0; i < n + 1; i++){
			cin >> m[i];
			for(int j = 0; j < m[i]; j++){
				cin >> vertice_x[i][j] >> vertice_y[i][j];
			}
		}
		int rotatedtmp_x[4][10], rotatedtmp_y[4][10];
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < m[0]; j++){
				rotatedtmp_x[i][j] = rotation(vertice_x[0][j], vertice_y[0][j], i, 0);
				rotatedtmp_y[i][j] = rotation(vertice_x[0][j], vertice_y[0][j], i, 1);
			}
		}
		for(int i = 1; i < n + 1; i++){
			for(int j = 0; j < 4; j++){
				if(m[i] != m[0]) break;
				if(issame(rotatedtmp_x[j], rotatedtmp_y[j], vertice_x[i], vertice_y[i], m[i])){
					cout << i << endl;
					break;
				}
			}
		}
		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(){
  int n,min,max,a,i,s;
  while(scanf("%d",&n),n){
    max=0;
    min=1e9;
    while(n--){
      for(i=s=0;i<5;i++){
	scanf("%d",&a);
	s+=a;
      }
      if(max<s)max=s;
      if(min>s)min=s;
    }
    printf("%d %d\n",max,min);
  }
  return 0;
}
  

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long k = sc.NextLong();
        long t = sc.NextLong();
        long[] aa = sc.LongArray();

        long sum = aa.Sum();
        long max = aa.Max();

        if (sum / 2 >= max)
        {
            Console.WriteLine(0);
            return;
        }

        long answer = max * 2 - sum - 1;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

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

  int n = 5;
  int a;
  int s = 0;
  int d = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    int tmp = (a + 9) / 10 * 10;
    d = max(d, tmp - a); 
    s += tmp;
  }
  cout << s - d << '\n';
  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a<9&&b<9)cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


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

int main(){

  int n;
  cin>>n;
  int ans = 0;
  REP(i,n){
    int l,r;
    cin>>l>>r;
    ans += r-l+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

function binarySearch($A, $key) {
    $left = 0;
    $right = count($A);
    while ($left < $right) {
        $mid = floor(($left + $right) / 2);
        if ($key === $A[$mid]) {
            return true;
        } else if ($key > $A[$mid]) {
            $left = $mid + 1;
        } else if ($key < $A[$mid]) {
            $right = $mid;
        }
    }
    return false;
}

input();
$A = array_map(function($numeric_string) {
    return (int)$numeric_string;
}, input_array());

input();

echo array_sum(array_map(function($key) use ($A) {
    return (int)binarySearch($A, (int)$key);
}, input_array())) . "\n";


Measured memory_bytes: 40908
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;


void solve()
{

    lli k;
    string s;
    cin>>k>>s;
    if(s.size() <= k) {
        cout<<s;
    }
    else {
        string ans = "";
        for(int i = 0; i < k; i ++) {
            ans += s[i];
        }
        ans += "...";
        cout<<ans;
    }
    cout<<"\n";
    return ;
}

/*

*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;

bool dp[110][10100] = {false};

int main(void){
	string s;cin >> s;
	bool ok = true;
	if(s.length()%2==1)ok = false;
	for(int i=0;i<s.length();i++){
		if(i%2==0) if(s[i]!='h') ok = false; 
		if(i%2==1) if(s[i]!='i') ok = false; 
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def swap(a,b):
	tmp=a
	a=b
	b=tmp
	return a,b

n=int(input())
A=input_array()
MAX=10**18
A=sorted(A)
ans=A[0]
for i in range(1,len(A)):
	ans*=A[i]
	if ans==0:
		break
	elif ans>MAX:
		ans=-1
		break
	else:
		pass

print(ans)


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

int main()
{

        int r, g, b;

        cin >> r >> g >> b;

        string S = "123";
        string R = to_string(r);
        string G = to_string(g);
        string B = to_string(b);
        S[0] = R[0];
        S[1] = G[0];
        S[2] = B[0];
        int ans = stoi(S);
        if (ans % 4 == 0) {
                cout << "YES" << endl;
        }
        else {
                cout << "NO" << endl;
        }


}


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

ll c[30010][3010];

void init_triangle()
{
    c[0][0] = 1;
    rep(i, 3000)
        rep(j, 3000)
        {
            if (j > i) break;
            

            c[i+1][j] = (c[i+1][j] + c[i][j]) % MOD;
            c[i+1][j+1] = (c[i+1][j+1] + c[i][j]) % MOD;
        }
}


ll f(int n, int m)
{
    if (n < m) return 0;
    if (n == 0 and m ==0 ) return 1;
    return c[n - 1][m - 1];
}

int main()
{
    init_triangle();

    int n, k;
    cin >> n >> k;

    int num_blue = k;
    int num_red = n - k;
    rep(i, k+1)
    {
        if (i == 0) continue;
        ll blue = f(num_blue, i);
        int res = 0;
        res = (res + blue * f(num_red, i - 1 + 0)) % MOD;
        res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
        res = (res + blue * f(num_red, i - 1 + 1)) % MOD;
        res = (res + blue * f(num_red, i - 1 + 2)) % MOD;

        cout << res << endl;
    }
}

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

int main() 
{
    int n;
    cin >> n;
    set<char> s;
    for (int i=0; i<n; i++)
    {
        char c;
        cin >> c;
        s.insert(c);
    }
    cout << (s.size()==3?"Three":"Four");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
const int MAX=1e3+5;
const int INF=1e9+5;
const double M=4e18;
using namespace std;
const int MOD=1e9+7;
typedef pair<int,int> pii;
const double eps=0.000000001;
int a,b,c;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if(c>=a&&c<=b)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int dp[3001][3001];
string s, t;

void print(int i, int j) {
  if (i==0 || j==0) return;
  if (s[i-1] == t[j-1]) {
    print(i-1, j-1);
    cout << s[i-1];
  } else {
    if (dp[i-1][j] >= dp[i][j-1]) {
      print(i-1, j);
    } else {
      print(i, j-1);
    }
  }
}

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

  cin >> s >> t;

  int ssize = s.size();
  int tsize = t.size();

  rep(i, 3001) {
    rep(j, 3001) {
      dp[i][j] = 0;
    }
  }
  
  rep(i, ssize) {
    rep(j, tsize) {
      if (s[i] == t[j]) {
        dp[i+1][j+1] = dp[i][j]+1;
      } else {
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }
  /*
  rep(i, 15) {
    rep(j, 15) {
      cerr << dp[i][j] << ' ';
    }
    cerr << endl;
  }*/

  print(ssize, tsize);
  cout << endl;
}

Measured memory_bytes: 35968
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>



using namespace std;
int main(void){

  int x;
  int keta;
  int hyaku;//100の数
  int simo2;//下二桁
  cin >> x;


  hyaku=(x/100);//hyakuのくらい
  simo2=x-(x/100)*100;//下二桁
  if(simo2<=hyaku*5){
    cout << 1;
  }

  else {
    cout << 0;
  }


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;


namespace AtCoder_Beginner_Contest_132
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var N=Sarray()[0];
            var Ai = Sarray();

            //答え以上なら　偶数個目-、奇数個目＋
            var mid = Ai[0] / 2;
            var min = 0L;
            var max = Ai[0];
            while (true)
            {
                var pre = mid;
                StringBuilder str = new StringBuilder($"{pre*2}");
                for (var i = 0; i < N - 1; ++i)
                {
                    pre = Ai[i] - pre;
                    str.Append(new StringBuilder($" {pre*2}"));
                }
                if (Ai[N - 1] == pre + mid)
                {
                    WriteLine(str);
                    return;
                }
                if (Ai[N - 1] < pre + mid)//startを↓に
                {
                    max = mid - 1;
                }
                else//startを↑に
                {
                    min = mid + 1;
                }
                mid = min + (max - min) / 2;
            }
        }
    }
}

Measured memory_bytes: 37712
def main
  n = STDIN.gets.chomp.to_i
  ns = STDIN.gets.chomp.split(' ').map(&:to_i)

  cnt = 0

  for i in (0...n - 2) do
    center = ns[i+1]
    sorted_set = [ns[i], center, ns[i+2]].sort
    cnt += 1 if center == sorted_set[1] && center < n
  end

  puts cnt
end

main

Measured memory_bytes: 1788
import java.util.Scanner;

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

        while((N = scan.nextInt()) != 0){
            int count = 0;
            int sum = 0;
            for(int i=1; i*2<N; i++){
                for(int j=i; sum<N; j++){
                    sum += j;

                    if(sum == N){
                        count++;
                    }
                }
                sum = 0;
            }

            System.out.println(count);
        }
    }
}

Measured memory_bytes: 19812
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.length();
  if(n==3){
    char c = s[2];
    s[2] = s[0];
    s[0] = c;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

int dp[3030][3030];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int n=s.size(); int m=t.size();
    int cnt=dp[n][m];
    string res="";
    int i=n;
    int j=m;
    while(cnt){
        while(i&&dp[i][j]==dp[i-1][j]){
            i--;
        }
        while(j&&dp[i][j]==dp[i][j-1]){
            j--;
        }
        res+=s[i-1];
        cnt--;
        i--;
        j--;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}


Measured memory_bytes: 39084
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A1, A2, A3; cin >> A1 >> A2 >> A3;
  int ans = max({A1, A2, A3}) -min({A1, A2, A3});
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n,k,i,j,u,al[26],l[200010];
  bool ans=true;
  string s,t;
  cin >> s >> t;
  n=s.size();
  while (k<2){
    for (i=0;i<26;i++) al[i]=-1;
    for (i=0;i<n;i++){
      if (al[s[i]-'a']==-1) al[s[i]-'a']=l[i]=i;
      else l[i]=al[s[i]-'a'];
    }
    for (i=0;i<n;i++){
      if (t[i]!=t[l[i]]) break;
    }
    if (i!=n){
      ans=false;
      break;
    }
    swap(s,t);
    k++;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    string S; cin >> S;
    ll SUM = 0;
    for(auto ch : S){ SUM += ch - 48; }
    if(SUM % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

struct StGoods
{
  StGoods() : m_nPrice(0), m_nNum(0) { }

  int m_nPrice;
  int m_nNum;

  bool operator<(const StGoods& rhs) const
  {
    return m_nPrice < rhs.m_nPrice;
  }
};

void input(int& rnTrgNum, vector<StGoods>& rvoGoods)
{
  int nGoodsSiz;
  cin >> nGoodsSiz >> rnTrgNum;
  rvoGoods.resize(nGoodsSiz);

  for (StGoods& roGoods : rvoGoods)
    cin >> roGoods.m_nPrice >> roGoods.m_nNum;
}

llong calcMinCost(int nTrgNum, vector<StGoods>& rvoGoods)
{
  sort(begin(rvoGoods), end(rvoGoods));

  llong nCost = 0;

  for (StGoods oGoods : rvoGoods)
  {
    int nUsedNum = min(nTrgNum, oGoods.m_nNum);
    nCost += (llong)oGoods.m_nPrice * nUsedNum;
    nTrgNum -= nUsedNum;

    if ( !nTrgNum ) break;
  }
  return nCost;
}
 
int main()
{
  int nTrgNum;
  vector<StGoods> voGoods;

  input(nTrgNum, voGoods);
  cout << calcMinCost(nTrgNum, voGoods) << endl;

  return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    bool ok = true;
    for (int i = n-1; i >= 0; i--) {
        if (a[i] > a[i+1]) a[i]--;
    }
    rep(i,n-1) if (a[i] > a[i+1]) ok = false;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















int main() {
	ll n;
	cin >> n;
	vector<string> s(n);
	vector<ll> t(n);
	REP(i, n) {
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;
	ll ans = 0;
	bool f = false;
	REP(i, n) {
		if (f) ans += t[i];
		if (s[i] == x) f = true;
	}
	cout << ans << endl;
}

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

int main()
{
    string s;
    cin >> s;
    bool ok = true;
    rep(i, s.size() - 1) if (s[i] == s[i + 1]) ok = false;
    if (ok)
        cout << "Good" << endl;
    else
        cout << "Bad" << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			long n = long.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long ans = 0;
			if (n % 2 == 0) {
#if false
				long x = 1;
				for (long i = 2; i <= n; i += 2) {
					long tmp1 = ans, tmp2 = x;
					long j = i;
					while (j % 10 == 0) {
						j /= 10;
						ans++;
					}
					x *= j;
					while (x % 10 == 0) {
						x /= 10;
						ans++;
					}
					x %= 1000;
					if (ans != tmp1) {
						System.Diagnostics.Debug.WriteLine($"{tmp2,3} * {i,3} = {x,3} * 10^{ans} {(i / 10 + i / 50 + i / 250 + i / 1250 + i / 6250 + i / 31250 == ans ? "o" : "x")}");
					}
				}
				System.Diagnostics.Debug.WriteLine("");
#else
				long x = 10;
				while (x <= n) {
					ans += n / x;
					x *= 5;
				}
#endif
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13140