akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main(){
    int h,w,i,j,k,x,y,nx,ny;
    long long int ans=0,wh,bl;
    cin >> h >> w;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    vector<string> S(h);
    for(i=0;i<h;i++){
        cin >> S.at(i);
    }
    int visited[h][w];
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            visited[i][j]=0;
        }
    }
    queue<pair<int,int> > Q;
    pair<int,int> now;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(visited[i][j]==0){
                wh=0; bl=0;
                visited[i][j]=1;
                Q.push(make_pair(i,j));
                while(!Q.empty()){
                    now = Q.front();
                    Q.pop();
                    y=now.first;
                    x=now.second;
                    if(S[y][x]=='.')wh++;
                    else bl++;
                    for(k=0;k<4;k++){
                        nx = x + dx[k];
                        ny = y + dy[k];
                        if(nx<0 || nx>=w || ny<0 || ny>=h || S[ny][nx]==S[y][x] || visited[ny][nx]==1) continue;
                        visited[ny][nx]=1;
                        Q.push(make_pair(ny,nx));
                    }
                }
                ans += bl*wh;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(n),t(m);
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i];
  vector<vector<LL>> dp(n+1,vector<LL>(m+1,0));
  rep(i,n+1) dp[i][0]=1;
  rep(i,m+1) dp[0][i]=1;
  LL ans=1;
  rep(i,n){
    rep(j,m){
      dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+MOD)%MOD;
      if(s[i]==t[j]){
        dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%MOD;
        ans=(ans+dp[i][j])%MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  Ml calc1;
  Ml calc2;

  rep(i, n) {
    calc1[a[i]-(i+1)]++;
    calc2[a[i]+(i+1)]++;
  }
  ll ans = 0;

  for(auto itr = calc1.begin(); itr != calc1.end(); ++itr) {
    ans += calc1[itr->first] * calc2[(-1) * itr->first];
    // cout << itr->first << " " << calc1[itr->first] <<" ";
    // cout << calc2[(-1) * itr->first] << endl;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 39000
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100001;
int main() {
	int N;
	int A[MAX];
	int S[MAX] = { 0 };

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

		if (i != 0)sum += abs(A[i] - A[i - 1]);
		else sum += abs(A[i]);

		S[i] = sum;
	}
	A[N] = 0;
	S[N] = sum + abs(A[N - 1]);

	for (int i = 0; i < N; i++) {
		int ans = S[N] - S[i + 1];
		if (i != 0)ans += S[i - 1];
		if (i != 0)ans += abs(A[i + 1] - A[i - 1]);
		else ans += abs(A[i + 1]);

		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m,k=mii()

for i in range(n+1):
    for j in range(m+1):
        if k==i*(m-j)+j*(n-i):
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 63852
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define pb push_back
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rii(x,y) ri(x), ri(y)
#define rll(x,y) rl(x), rl(y)

#define fst first
#define snd second
#define dprintf debug && printf
#define debug false

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

const int MAXN = 60;

int N, P, a[MAXN], cnt[2];
ll dp[MAXN][2];
ll f(int i, int m){
	ll &ret = dp[i][m];
	if(ret!=-1) return ret;
	if(i==N){
		return ret = m==P;
	}
	ret = f(i+1, m) + f(i+1, (m+a[i])%2);
	return ret;
}

int main(){
	rii(N,P);
	FOR(i,0,N){
		ri(a[i]);
	}
	ms(dp,-1);
	printf("%lld\n",f(0,0));
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d%d%d%d", $w, $h, $x, $y);
//   if(($w/2) == $x || ($h/2) == $y){
      echo ($w*$h)/2;
      if(($w/2) == $x && ($h/2) == $y){
          echo " 1";
      }else{
          echo " 0";
      }
      exit;
//   }
  

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

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

    cout << (A-1)*(B-1) << endl;
}

Measured memory_bytes: 256
import heapq
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class Graph:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.edges = [[] for _ in range(n_nodes)]

    def add_edge(self, s, t, d=None, undirected=False):
        if d is not None:
            self.edges[s].append((t, d))
        else:
            self.edges[s].append(t)
        if undirected:
            self.add_edge(t, s, d)

    def add_edges(self, edges, undirected=False):
        for edge in edges:
            self.add_edge(*edge, undirected=undirected)


class Dijkstra:
    def __init__(self, graph):
        self.graph = graph

    def compute(self, s, t):
        distances = [float('inf') for _ in range(self.graph.n_nodes)]
        visited = [False for _ in range(self.graph.n_nodes)]
        prev_nodes = [None for _ in range(self.graph.n_nodes)]
        distances[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        while q:
            dist_x, x = heapq.heappop(q)
            if x == t:
                return distances, prev_nodes

            if visited[x]:
                continue
            visited[x] = True

            for y, d_xy in self.graph.edges[x]:
                if visited[y]:
                    continue
                dist_y = dist_x + d_xy
                if dist_y < distances[y]:
                    distances[y] = dist_y
                    prev_nodes[y] = x
                    heapq.heappush(q, (dist_y, y))
        return distances, prev_nodes

    def compute_all(self, s):
        distances = [float('inf') for _ in range(self.graph.n_nodes)]
        visited = [False for _ in range(self.graph.n_nodes)]
        prev_nodes = [None for _ in range(self.graph.n_nodes)]
        distances[s] = 0
        q = []
        for t in range(self.graph.n_nodes):
            heapq.heappush(q, (distances[t], t))
        while q:
            dist_x, x = heapq.heappop(q)
            if visited[x]:
                continue
            visited[x] = True

            for y, d_xy in self.graph.edges[x]:
                if visited[y]:
                    continue
                dist_y = dist_x + d_xy
                if dist_y < distances[y]:
                    distances[y] = dist_y
                    prev_nodes[y] = x
                    heapq.heappush(q, (dist_y, y))
        return distances, prev_nodes


n, m = ril()
graph = Graph(n)
for i in range(1, n):
    graph.add_edge(i, i - 1, 0)
for _ in range(m):
    a, b, c = ril()
    graph.add_edge(a - 1, b - 1, c)
dijkstra = Dijkstra(graph)
distances, _ = dijkstra.compute(0, n - 1)
d = distances[-1]
if d == float('inf'):
    print(-1)
else:
    print(d)

Measured memory_bytes: 45768
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;

#define MAX_N 200000

int N;
vector<int> tree[MAX_N];

int diameter()
{
    int root = 0;
    int max_depth = 0;

    queue<tuple<int, int, int>> q;
    q.push( make_tuple( root, -1, 0 ) );

    while ( !q.empty() )
    {
        auto e = q.front();
        q.pop();

        int vert = get<0>( e );
        int prev = get<1>( e );
        int dept = get<2>( e );

        for ( auto t : tree[vert] )
        {
            if ( t == prev ) continue;

            q.push( make_tuple( t, vert, dept + 1 ) );
        }

        root = vert;
    }

    q.push( make_tuple( root, -1, 0 ) );

    while ( !q.empty() )
    {
        auto e = q.front();
        q.pop();

        int vert = get<0>( e );
        int prev = get<1>( e );
        int dept = get<2>( e );

        for ( auto t : tree[vert] )
        {
            if ( t == prev ) continue;

            q.push( make_tuple( t, vert, dept + 1 ) );
        }

        max_depth = max( max_depth, dept );
    }

    return max_depth;
}

int main( int argc, char **argv )
{
    cin >> N;

    for ( int n = 0; n < N - 1; n++ )
    {
        int a, b;
        cin >> a >> b;

        tree[a - 1].push_back( b - 1 );
        tree[b - 1].push_back( a - 1 );
    }

    int L = diameter();

    if ( L % 3 == 1 )
        cout << "Second" << endl;
    else
        cout << "First" << endl;

    return 0;
}


Measured memory_bytes: 14452
#xの約数の数を数える関数
def divNum(x):
    tmp = set()
    i = 1
    while i < x**0.5:
        if x%i == 0:
            tmp.add(i)
            tmp.add(x//i) 
        i+=1
    return len(tmp)

def main():
    n = int(input())
    cnt = 0
    for i in range(1, n+1):
        if i%2 == 0:
            continue
        if divNum(i) == 8:
            cnt += 1
    print(cnt)
main()

Measured memory_bytes: 3060
w = str(input())
n = 1
if len(w) == 2*n + 1:
  print ('No')
l=[]
for i in w:
  l.append(i)

sort=sorted(l)

import collections
c = collections.Counter(sort)
v_list = list(c.values())

ans='Yes'
for i in v_list:
  if i % 2 != 0:
    ans='No'
    break
    
print(ans)
    
   
  


Measured memory_bytes: 3316
N = int(input())
t = []
x = []
y = []
t.append(0)
x.append(0)
y.append(0)

for i in range(0,N):
	I = list(map(int,input().split()))
	t.append(I[0])
	x.append(I[1])
	y.append(I[2])

frag = 1
for i in range(0,N):
	if ((t[i + 1] - t[i]) % 2) != (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])) % 2:
		frag = 0
	if abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) > t[i + 1] - t[i]:
		frag = 0

if frag == 1:
	print("Yes")
else:
	print("No")

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

typedef long long ll;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()
const ll mod = 998244353;
const ll n_max = 10e5;
int main()
{
    int n;
    cin >> n;
    v<int> dp(n + 1, n_max);
    v<int> num;
    dp[0] = 0;

    num.push_back(1);

    int six = 6, nine = 9;
    while (true)
    {
        num.push_back(six);
        six *= 6;
        if (six > n)
            break;
    }

    while (true)
    {
        num.push_back(nine);
        nine *= 9;
        if (nine > n)
            break;
    }
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < num.size(); j++)
        {
            if (i + 1 - num[j] >= 0)
            {
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - num[j]] + 1);
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int N, K;
    string S;

    cin >> N;
    cin >> S;
    cin >> K;

    char Si = S.at(K-1);

    for(int i=0; i<N; i++){
        if(S[i] != Si){
            S[i] = '*';
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	public static void main(String[] args) {
		int N=stdIn.nextInt();
		int a[]=new int[N];
		long lsum=0,rsum=0,min=Long.MAX_VALUE;
		for(int i=0;i<N;i++){
			a[i]=stdIn.nextInt();
			lsum+=a[i];
		}
		for(int i=0;i<N-1;i++){
			rsum+=a[i];
			lsum-=a[i];
			if(Math.abs(rsum-lsum)<min)
				min=Math.abs(rsum-lsum);
		}
		System.out.println(min);
	}
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n;
    vector<pair<int, int>> v;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int ta, tb;
        cin >> ta >> tb;
        v.push_back(make_pair(tb, ta));
    }
    sort(all(v));

    int sum = 0;
    bool f = true;
    for (int i = 0; i < n; i++)
    {
        sum += v[i].second;
        if (sum > v[i].first)
        {
            f = false;
        }
    }
    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 6256
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n; 

int main(){

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

	// int T;
 //    cin >> T;
 
 //    while (T--) {
        
 //    }

	cin>>n;
	map<string, int> m;
	string x;
	for(int i = 0; i < n; i++) {
		cin>>x;
		m[x] += 1;
	}

	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;

	return 0;
}

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

using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int low, high;
    for (int i = x; ; i--) {
        auto it = std::find(p.begin(), p.end(), i);
        if (it == p.end()) {
            low = i;
            break;
        }
    }
    for (int i = x; ; i++) {
        auto it = std::find(p.begin(), p.end(), i);
        if (it == p.end()) {
            high = i;
            break;
        }
    }
    int ans;
    if (x - low <= high - x) {
        ans = low;
    } else {
        ans = high;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay){
    int left = 0;
    int right = SZ(v);
    int mid;
    while(left < right){
        mid = (left + right)/2;
        if (v[mid] == kay) return true;
        else if (kay < v[mid]) right = mid;
        else left = mid+1; 
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> v;
    int t;
    REP(_, n){cin >> t; v.PB(t);}

    cin >> n;
    int count = 0;
    REP(_, n){
        cin >> t;
        if (binary_search(v, t)) count++;
    }

    cout << count << endl;
}


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

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)

int r;

int main(){
	read(r);
	printf("%f\n", acos(-1) * 2 * r);
	return 0;
}

Measured memory_bytes: 3720
from collections import deque
N , M = map(int,input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    a,b = [int(x) for x in input().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
branch_list = [0 for i in range(N)]
def bfs(u):
    queue = deque([u])
    d = [None] *N
    d[u] = 0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] +1
                queue.append(i)
                branch_list[i] = v +1
    return d
d = bfs(0)
for i in range(1,len(branch_list)):
    if branch_list[i] == 0:
        print("No")
        break
    if i == 1:
        print("Yes")
    print(branch_list[i])

Measured memory_bytes: 37756
a, b, c, d = map(int, input().split())

time = [0] * 101

for i in range(a, b + 1):
    time[i] += 1

for i in range(c, d + 1):
    time[i] += 1

ans = 0
for i in time:
    if i == 2:
        ans += 1

print(max(0, ans - 1))

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

const int INF = 0x3f3f3f3f;

template <typename T>
void mini(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

int32_t main() {
  int x, n;
  scanf("%d%d", &x, &n);

  std::map<int, bool> forbidden;

  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    forbidden[p] = true;
  }

  std::pair<int, int> ans = {INF, INF};

  for (int i = 0; i <= 101; i++) {
    if (!forbidden[i]) {
      mini(ans, {std::abs(x-i), i});
    }
  }

  printf("%d\n", ans.second);

  return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(i%2==0)continue;
    int cnt=0;
    for(int j=1;j<=sqrt(i);j++){
      if(i%j==0)cnt++;
    }
    if(cnt==4)ans++;
    
  }
  cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

int main(){
    int i, N;
    ll ans = 1e18, R = 0, L = 0;
    cin >> N;
    vector<ll> a(N);
    for(i=0; i<N; i++) {
        cin >> a[i];
        R += a[i];
    }

    for(i=0; i<N-1; i++) {
        L += a[i];
        R -= a[i];
        ans = min(ans, abs(R - L));
    }

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

Measured memory_bytes: 1792
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

import heapq

N = ri()
A = rl()

A.sort()

heap = []
a = A.pop()
heapq.heappush(heap, (-a, a, a))

ans = 0
while A:
	a = A.pop()
	b, l, r = heapq.heappop(heap)
	b = -b
	ans += b
	heapq.heappush(heap, (-min(a, l), l, a))
	heapq.heappush(heap, (-min(a, r), a, r))
print(ans)


Measured memory_bytes: 138360
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 2;


int h, w, n;
void fall(vector<string> &s){

	rep(y, h - 1)rep(x, w){
		if (s[y][x] != '.' && s[y + 1][x] == '.'){
			swap(s[y][x], s[y + 1][x]);
			for (int ty = y - 1; ty >= 0; ty--){
				if (s[ty][x] != '.'){
					swap(s[ty][x], s[ty + 1][x]);
				}
				else{
					break;
				}
			}
		}
	}
}
bool ok(vector<string> s){
	fall(s);
	bool f[31][31];
	clr(f);
	rep(y, h){
		int cnt = 1;
		rep(x, w){
			if (x < w-1 && s[y][x] != '.' && s[y][x] == s[y][x + 1]){
				cnt++;
			}
			else{
				if (cnt >= n){
					for (int tx = x; tx > x - cnt; tx--){
						f[y][tx] = true;
					}
				}
				cnt = 1;
			}
		}
	}
	rep(x, w){
		int cnt = 1;
		rep(y, h){
			if (y < h-1 && s[y][x] != '.' && s[y][x] == s[y + 1][x]){
				cnt++;
			}
			else{
				if (cnt >= n){
					for (int ty = y; ty > y - cnt; ty--){
						f[ty][x] = true;
					}
				}
				cnt = 1;
			}
		}
	}
	bool ef = true;
	rep(y, h)rep(x, w){
		if (f[y][x]){
			s[y][x] = '.';
			ef = false;
		}
	}
	if (ef == false){
		return ok(s);
	}
	rep(y, h)rep(x, w){
		if (s[y][x] != '.')return false;
	}
	return true;
}

int main(){
	cin >> h >> w >> n;
	vector<string> s(h);
	rep(y, h){
		cin >> s[y];
	}
	if (ok(s)){
		cout << "YES" << endl;
		return 0;
	}
	rep(y, h)rep(x, w-1){
		if (s[y][x] != s[y][x+1]){
			swap(s[y][x], s[y][x+1]);
			if (ok(s)){
				cout << "YES" << endl;
				return 0;
			}
			swap(s[y][x], s[y][x+1]);
		}
	}
	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 1312
if __name__ == "__main__":
	N = int(input())
	S = input()
	left = []
	right = []
	for i,p in enumerate(S):
		if p == '(':
			left.append(i)
		else:
			if (len(left) > 0):
				left.pop(0)
			else:
				right.append(i)
	for x in range(len(right)):
		S = '(' + S
	for x in range(len(left)):
		S = S + ')'
	print (S)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());
	cout << v[0] <<" "<< v[1] <<" "<< v[2]<<endl;
	
	return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin >> N;
    string S, T;
    cin >> S >> T;
    string ans;
    rep(i, 0, N)
    {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int checker = 0;
    for (int i=0;i<N;i++){
      int a = sc.nextInt();
      checker ^= a;
    }
    if (checker == 0){
    System.out.println("Yes");
    }else{
    System.out.println("No");
    }
  }
}

Measured memory_bytes: 49148
import java.util.*;

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

        int x = sc.nextInt();

        while (!isPrime(x)){
            x += 1;
        }
        System.out.println(x);


    }
    public static boolean isPrime(int x){
        int i=2;
        while (i*i<=x){
            if (x%i==0){
                return false;
            }
            i++;
        }
        return true;
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
// ABC098-A-
/*
int main(){
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}
 */

// ABC099-A-
/*
int main(){
    int a;
    bool okey = true;
    cin >> a ;
    if (a > 999) {
        okey = false;
        a -= 1000;
    }
    
    if (okey) {
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
}
*/

//ABC100-A-

int main(){
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) {
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    
}
 
//ABC101-A-
/*
int main(){
    int ans = 0;
    for (int i = 0; i < 4; i++) {
        char s;
        cin >> s;
        if(s == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}
*/
//ABC102-A-
/*
int main(){
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    }else{
        cout << n * 2 << endl;
    }
}
*/
//ABC102-A-
/*
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int>task;
    task = {a, b, c};
    sort(task.begin(), task.end());
    cout << task.at(2) - task.at(0) << endl;
}
*/




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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int ceil(int a, int b){
	if(a == 0) return 0;
	return a % b == 0 ? a / b: a / b + 1;
}

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

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

	cout << ceil(n-1,k-1) << endl;
}

Measured memory_bytes: 256
using System;

namespace abc93_a
{
    class Program
    {
        static void Main(string[] args)
        {
            char ch;
            int index = 0;
            string word = Console.ReadLine();
            for(int i = 0; i < 3; i++)
            {
                ch = word[i];
                if (ch == 'a')
                {
                    index = index + 1;
                }else if (ch == 'b')
                {
                    index = index + 2;
                }else if (ch == 'c')
                {
                    index = index + 3;
                }
            }
            if (index == 6)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
import sys
import math
import itertools

n,k=list(map(int,input().split()))
count=0
num=[i for i in range(1,k+1,1)]
for j in range(n):
	a=list(map(int,input().split()))
	del a[0]
	num=list(set(a)&set(num))
print(len(num))

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int A,B,K;
    cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<' '<<B<<endl;
    }
    else{
        cout<<0<<' '<<max((long long int)0,B-(K-A))<<endl;
    }
    return 0;
}


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

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

  ll cnt = 0;
  ll ans = 0;
  const ll mod = 1000000007;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] > a[j]) cnt++;
    }
  }
  ans = (cnt * k) % mod;

  ll nC2 = k * (k - 1) / 2 % mod;
  for (int i = 0; i < n; i++) {
    ll cnt2 = 0;
    for (int j = 0; j < n; j++) {
      if (a[i] > a[j]) cnt2++;
    }
    ll tmp = cnt2 * nC2 % mod;
    ans = (ans + tmp) % mod;
  }

  cout << ans << endl;
}

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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

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

int main () {
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    dp[0] = LINF;
    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]),
                    dp[i-2] + abs(a[i] - a[i-2]));
    }
    printf("%lld\n", dp[n]);
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

int n,k,cnt,a[200010],sum[200010],bit[200010];
map<int,int> mp,pm;

inline int sm(int p)
{
	int s=0ll;
	while(p>0){
		s+=bit[p];
		p-=p&(-p);
	}
	return s;
}

inline void add(int p)
{
	while(p<=cnt){
		bit[p]++;
		p+=p&(-p);
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];a[i]-=k;
	}
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	for(int i=0;i<=n;i++) mp[sum[i]]=1;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		cnt++;
		pm[it->first]=cnt;
	}
	for(int i=0;i<=n;i++) sum[i]=pm[sum[i]];
	int ans=0ll;
	for(int i=0;i<=n;i++){
		ans+=sm(sum[i]);
		add(sum[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int k,s;
	cin >> k >> s;
	int a;
	a=0;
	for(int i=0;i<k+1;i++){
		if((s-i>=0)&&(s-i<=k)){
			a=a+s+1-i;
		}
		else if((2*k-s+i+1>0)&&(s-i>=0)){
			a=a+2*k-s+1+i;
		}
		
	}
		cout << a << endl;
		
	
	
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b%a, a);
}

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

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

	ll h,w,m , i ,j;

	cin >> h >> w >> m;

	ll r[h+1] , c[w+1];

	memset(r,0,sizeof(r));
	memset(c,0,sizeof(c));

	vector <pair<ll,ll>> v;

	for(i=0;i<m;i++)
	{
		ll x,y;

		cin >> x >> y;
		r[x]++;
		c[y]++;

		v.push_back(mp(x,y));
	}

	ll rmx= 0 , cmx = 0;

	for(i=1;i<h+1;i++)
		rmx = max(rmx , r[i]);

	for(i=1;i<w+1;i++)
		cmx = max(cmx , c[i]);

	map <ll,ll> rm , cm;

	for(i=1;i<h+1;i++)
	{
		if(r[i] == rmx)
			rm.insert(mp(i,1));
	}

	for(i=0;i<w+1;i++)
	{
		if(c[i] == cmx)
			cm.insert(mp(i,1));
	}

	ll tot = rm.size() * cm.size();

	ll cnt = 0;

	for(i=0;i<m;i++)
	{
		if(rm.find(v[i].first) != rm.end() && cm.find(v[i].second) != cm.end())
			cnt++;
	}

	if(cnt < tot)
		cout << rmx + cmx << endl;
	else
		cout << rmx + cmx - 1 << endl;


}

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

int main(){
  int m,s,y,n,k,d;
  double r;

  cin >> m;
  for(int i=0;i<m;i++){
    cin >> s >> y >> n;
    int ans = 0;
    for(int j=0;j<n;j++){
      cin >> k >> r >> d;
      int tmp = s;
      if(k==0){
	int tmp2 = 0;
	for(int x=0;x<y;x++){
	  tmp2 += (int)(tmp*r);
	  tmp -= d;
	}
	tmp += tmp2;
      }else{
	for(int x=0;x<y;x++){
	  tmp += (int)(tmp*r) - d;
	}
      }
      ans = max(ans,tmp);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1232
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;


int main() {
    int n;
    cin >> n;
    cout << n*(n + 1) / 2 << endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<pair<ll,ll>> xl(n);
    rep(i,n){
        ll x,l; cin >> x >> l;
        xl.at(i).second = x-l;
        xl.at(i).first = x+l;
    }
    sort(xl.begin(),xl.end());
    int count = 1;
    ll position = xl.at(0).first;
    for(int i=1;i<n;i++){
        if(position>xl.at(i).second) continue;
        position = xl.at(i).first; count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 1792
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    return arr

n = int(input())
l = factorization(n)
ans = 0
for c in l:
    lim = c[1]
    num = 0
    while lim > num:
        num += 1
        lim -= num
    ans += num

print(ans)

Measured memory_bytes: 9476
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n,m;
vector<int> vs[100005];

int col[100005]={};

lli cs[2],s;
bool dfs(int no,int c){
	col[no]=c;
	cs[c-1]++;
	s++;
	bool res = true;
	rep(i,vs[no].size()){
		int to=vs[no][i];
		if(col[to]){
			if(col[to]==c)res=false;
		}
		else res &= dfs(to,3-c);
	}
	return res;
}

int main(void){
	scanf("%d%d",&n,&m);
	rep(i,m){
		int a,b;
		scanf("%d%d",&a,&b); a--; b--;
		vs[a].push_back(b);
		vs[b].push_back(a);
	}
	
	lli ans=0;
	rep(i,n){
		if(col[i]==0){
			cs[0]=cs[1]=s=0;
			if(dfs(i,1))ans += cs[0]*cs[1];
			else ans += s*(s-1)/2;
		}
	}
	printf("%lld\n",ans-m);
	return 0;
}






Measured memory_bytes: 7680
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<=5){
		cout<<0<<endl;
	}
	else if(a<=12){
		cout<<b/2<<endl;
	}
	else{
		cout<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int c1 = 0,c2=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'){
			c1++;
		}
		else
			c2++;
		
	}
	if(c1==3 || c2==3){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 38512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define ARRAY_MAX 100005


int main(){

    ll n,a,b,ans = 0;
    cin >> n >> a >> b;
    if(a > b || (n == 1 && a != b)){
        ans = 0;
    }else{
        ans = (b*(n-1)+a) - (a*(n-1)+b) + 1;
    }
    cout << ans << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[12345];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  long long ans = 0;
  for (int t = 0; t < (1 << (len - 1)); t++) {
    long long num = s[0] - '0';
    for (int i = 0; i < len - 1; i++) {
      if (t & (1 << i)) {
        ans += num;
        num = 0;
      }
      num = num * 10 + s[i + 1] - '0';
    }
    ans += num;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#reverse一回だけなら大丈夫かな？
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans_arr = []
arr.each.with_index do |num,i|
  if i % 2 == 0
    ans_arr.unshift(num)
  else
    ans_arr.push(num)
  end
end
if n % 2 == 0
  ans_arr.reverse!
end
puts ans_arr.join(' ')

Measured memory_bytes: 39324
#include <stdio.h>
int main(void){
	
	int w,h,x,y,r;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	
	if(x+r<=w && y+r<=h && x-r>=0 && y-r>=0)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}


Measured memory_bytes: 2140
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        if (Math.abs(a - e) <= k) {
            System.out.println("Yay!");
            return;
        }
        System.out.println(":(");
    }

}


Measured memory_bytes: 22740
N,X,Y = map(int,input().split())
def kyori(i,j):
    return min(abs(i-j), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))

ans = [0]*(N)
for i in range(1,N):
    for j in range(i+1,N+1):
        ans[kyori(i,j)] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(a*n,b)<<endl;

}


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

using namespace std;

int r,c;
int ans=0;
int se[100001][10];
int flag[10];
int se2[10001][10];

int count(int fl[]){
	int res=0;
	for(int i=0;i<c;i++){
		int r2=0;
		for(int j=0;j<r;j++){
			se2[i][j]=(se[i][j]+fl[j])%2;
			if(se2[i][j]==1)r2++;
		}
		if(r2>=(r+1)/2)res+=r2;
		else res+=r-r2;
	}
	return res;
}

void check(int dy){
	if(dy==r){
		int res;
		res=count(flag);
		ans=max(res,ans);
	}
	else{
		flag[dy]=0;
		check(dy+1);
		flag[dy]=1;
		check(dy+1);
	}
}

int main(void){
	while(1){
		ans=0;
		scanf("%d%d",&r,&c);
		if(r==0 && c==0)break;
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				scanf("%d",&se[j][i]);
			}
		}
		check(0);
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1668
#include <stdio.h>

int n, m, a;

int main() {
    while (1) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if ((i + j) % 2 == 0) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
template < class BidirectionalIterator >
bool next_combination ( BidirectionalIterator first1 ,
  BidirectionalIterator last1 ,
  BidirectionalIterator first2 ,
  BidirectionalIterator last2 )
{
  if (( first1 == last1 ) || ( first2 == last2 )) {
    return false ;
  }
  BidirectionalIterator m1 = last1 ;
  BidirectionalIterator m2 = last2 ; --m2;
  while (--m1 != first1 && !(* m1 < *m2 )){
  }
  bool result = (m1 == first1 ) && !(* first1 < *m2 );
  if (! result ) {
    while ( first2 != m2 && !(* m1 < * first2 )) {
      ++ first2 ;
    }
    first1 = m1;
    iter_swap (first1 , first2 );
    ++ first1 ;
    ++ first2 ;
  }
  if (( first1 != last1 ) && ( first2 != last2 )) {
    m1 = last1 ; m2 = first2 ;
    while (( m1 != first1 ) && (m2 != last2 )) {
      iter_swap (--m1 , m2 );
      ++ m2;
    }
    reverse (first1 , m1 );
    reverse (first1 , last1 );
    reverse (m2 , last2 );
    reverse (first2 , last2 );
  }
  return ! result ;
}
template < class BidirectionalIterator >
bool next_combination ( BidirectionalIterator first ,
  BidirectionalIterator middle ,
  BidirectionalIterator last )
{
  return next_combination (first , middle , middle , last );
}

long long getll(vector<int>& digits, const string& s) {
  long long ret = 0;
  for(int i=0;i<s.size();i++){
    ret *= 10;
    ret += digits[s[i] - '0'];
  }
  return ret;
}

bool solve(){
  int N;
  cin >> N;
  if(N == 0)return false;
  vector<string> s(N);
  set<char> st;
  for(int i=0;i<N;i++){
    cin >> s[i];
    for(int j=0;j<s[i].size();j++)
      st.insert(s[i][j]);
  }

  map<char,int> idx;
  int id = 0;
  for(auto ch : st){
    idx[ch] = id++;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<s[i].size();j++){
      s[i][j] = idx[s[i][j]] + '0';
    }
  }

  int K = st.size();
  vector<int> digits;
  for(int i=0;i<10;i++)
    digits.push_back(i);

  int cnt = 0;
  do{
    vector<int> digs(digits.begin(),digits.begin()+K);
    sort(digs.begin(),digs.end());
    do{
      bool ok = true;
      for(int i=0;i<N;i++){
        if (digs[s[i][0] - '0'] == 0 && s[i].size() != 1){
          ok = false;
          break;
        }
      }
      if(!ok)continue;

      long long sum = 0;
      for(int i=0;i<N-1;i++){
        sum += getll(digs,s[i]);
      }
      if (sum != getll(digs,s[N-1])) ok = false;

      if(!ok)continue;
      cnt++;
    }while(next_permutation(digs.begin(),digs.end()));
  }while(next_combination(digits.begin(),digits.begin()+K,digits.end()));

  cout << cnt << endl;
  return true;
}

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

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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll h,n,cnt=0,max=-1;
    cin>>h>>n;
    ll arr[n];
   	for(ll i=0;i<n;i++)
   	{
   			cin>>arr[i];
   			cnt+=arr[i];
   			if(arr[i]>max)
   				max=arr[i];
	}
	if(cnt>=h)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
   		
}

Measured memory_bytes: 1024
N = int(input())
seq = list(map(int, input().split()))

d = {}
for i in range(0,N):
    e = seq[i]
    if e not in d.keys():
        d[e] = 1
    else:
        d[e] += 1

r = 0
for k in d.keys():
    v = d[k]
    if (v < k):
        r += v
    else:
        r += v-k

print(r)


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int a,b,c;

  cin >> a >> b >> c;

  cout << (b-a == c-b ? "YES" : "NO") << endl;

}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
//vector<int> g[200020];
vector<ll> g[200020];
ll s[200020];
bool used[200020];
int atai[200020];

void dfs(ll x){
	used[x]=1;
	for(auto y:g[x]){
		if(used[y]) continue;
		atai[y]+=atai[x];
		dfs(y);
	}
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    vector<ll> A(N-1),B(N-1),ans(N-1,-1);
    for(ll i=0;i<N-1;i++){
        ll a,b,c;cin>>a>>b;
        a--;b--;
        
        g[a].push_back(b);
        g[b].push_back(a);
    }
	for(ll i=0;i<Q;i++){
        ll a,b,c;cin>>a>>b;
        a--;
        atai[a]+=b;
    }
	dfs(0);
	for(ll i=0; i<N; i++){
		
		cout<<atai[i]<<" " << '\n';
	}
	return 0;
}


Measured memory_bytes: 25984