akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

// z[i] = len of lcp of s, s[i..]; lcp(longest common prefix)
vector<int> z_fn(const string& s) {
    int n = s.size();
    vector<int> z(n, 0);
    for (int i = 1, l = 0, r = 0; i < n; i++) {
        if (i <= r)
            z[i] = min(r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            z[i]++;
        }
        if (i+z[i]-1 > r) {
            l = i; r = i+z[i]-1;
        }
    }
    return z;
}

const char L = 'a'-1;
const char H = 'z'+1; 
const int N = 2001; 
const int LEN = 10001; 
bool dp[N][LEN];

void solve() {
    int n, T;
    cin >> n >> T;
    vector<string> s(n);
    for (auto& x: s) {
        cin >> x;
    }

    // prep dp
    dp[n][0] = true;
    for (int i = n-1; i >= 0; i--) {
        int len = s[i].size();
        memcpy(dp[i], dp[i+1], sizeof dp[i]);
        for (int j = 0; j <= T; j++) {
            if (j - len >= 0)
                dp[i][j] |= dp[i+1][j-len];
        }
    }

    // sustitute
    vector<bool> cat(T+1, false);
    cat[0] = true;
    string mi(T, H);
    for (int i = 0; i < n; i++) {
        string tmp = s[i] + L + mi;
        auto z = z_fn(tmp);
        int len = s[i].size();
        int id = -1;
        int min_len = T<<1;
        for (int j = T-len; j >= 0; j--) {
            if (!cat[j] || !dp[i+1][T - (j+len)]) continue;
            int lcp = z[len+1+j];
            if (j + lcp >= T) continue;
            if (lcp == len) {
                cat[j+lcp] = true;
            }
            if (lcp >= len) continue;
            if (s[i][lcp] >= mi[j+lcp]) continue;
            if (j+lcp < min_len) {
                id = j;
                min_len = j+lcp;
            }
        }
        if (id == -1) continue;
        for (int j = 0; j < len; j++) {
            mi[id+j] = s[i][j];
        }
        for (int j = id+len; j < T; j++) {
            mi[j] = H;
        }
        for (int j = id+z[len+1+id]+1; j < T; j++) {
            cat[j] = false;
        }
        cat[id+len] = true;
    }
    
    cout << mi;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100005],a[100005],n;
main () {
	cin>>n;
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		if (i>1) dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if (i>2) dp[i]=min(dp[i],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        System.out.println(3*a*a);
    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25344
import Data.List
main = interact $ unlines . map show . dropping_ink . map (map read . splitOn ',') . lines

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)

dropping_ink inks = [whites,depth]
 where
  whites = 100 - length (nub canvas)
  depth = maximum $ map length $ group $ sort $ canvas
  canvas = filter (\(x,y) -> elem x [0..9] && elem y [0..9]) (concatMap sink inks)
  sink [x,y,s] = case s of
   1 -> [(x,y),(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
   2 -> [(x,y),(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x+1,y-1),(x-1,y+1),(x-1,y-1)]
   3 -> [(x,y),(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x+1,y-1),(x-1,y+1),(x-1,y-1),(x+2,y),(x-2,y),(x,y+2),(x,y-2)]

Measured memory_bytes: 4132
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[999999999999999]*n
d[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:
            break 
        d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]))
print(d[n-1])

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

void main_()
{
    ll N;
    cin >> N;
    vector<ll> bit_count(60);
    for (ll i = 0; i < N; ++i) {
        ll A;
        cin >> A;
        for (ll j = 0; j < 60; j++) {
            if ((A & (1LL << j)) != 0) {
                bit_count[j]++;
            }
        }
    }
    const ll MOD = 1e9 + 7;

    ll ans = 0;
    for (ll i = 0; i < 60; i++) {
        ll plus = bit_count[i] * (N - bit_count[i]) % MOD;
        plus = plus * ((1LL << i) % MOD) % MOD;
        ans += plus;
        ans %= MOD;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,m,a[50],b[50],ans[50];
	cin>>n>>m;
	for(int i=0;i<50;i++){
	ans[i]=0;
	}
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		for(int i2=0;i2<n;i2++){
			if(a[i]==i2+1){
				ans[i2]=ans[i2]+1;
			}
			if(b[i]==i2+1){
				ans[i2]=ans[i2]+1;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int R, G, B, N;
  cin>>R>>G>>B>>N;
  int ans = 0;
  for(int r=0;r<=3000;++r) {
    for(int g=0;g<=3000;++g) {
      if(R*r+G*g>N) continue;
      if((N-R*r-G*g)%B==0) ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3612
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 文字列の入力
		String[] s = sc.next().split("");
        Arrays.sort(s, Comparator.naturalOrder());
        String sortedS;
        String sortedT;
        StringBuilder builder = new StringBuilder();
        for(String value : s) {
          builder.append(value);
        }
        sortedS = builder.toString();
        builder.setLength(0);
        String[] t = sc.next().split("");
        Arrays.sort(t, Comparator.reverseOrder());
        for(String value : t) {
          builder.append(value);
        }
        sortedT = builder.toString();

        String[] list = {sortedS, sortedT};
        Arrays.sort(list, Comparator.naturalOrder());
    
		// 出力
		System.out.println(!sortedS.equals(sortedT) && list[0].equals(sortedS) ? "Yes" : "No");
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int n, a, b, c, d;
string s;

int main() {
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	s = "#"+s;
	bool ok = true;
	for (int i = a+1; i <= c-1; i++) {
		if (s[i] == '#' && s[i+1] == '#') ok = false;
	}
	for (int i = b+1; i <= d-1; i++) {
		if (s[i] == '#' && s[i+1] == '#') ok = false;
	}
	if (c > d && ok) {
		ok = false;
		for (int i = b; i <= d; i++) {
			if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
				ok = true;
			}
		}
	}
	if (ok) cout << "Yes\n";
	else cout << "No\n";
}


Measured memory_bytes: 772
n = int(input())
p = list(map(int, input().split()))
a = 0
for i in range(1,n):
    if p[i-1] > p[i]:
        a = a + p[i-1] - p[i]
        p[i] = p[i-1]
    else:
        p[i] = p[i]
        a = a
print(a)

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

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

#define pb push_back

using namespace std;

typedef pair<double, string> P;

bool solve(){
	int n;
	cin>>n;
	
	if(n==0)return false;
	
	vector<P> dat;
	rep(i,n){
		string l;
		int p,a,b,c,d,e,f,s,m;
		cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
		
		double price = s*f*m -p;
		double time = a+b+c+(d+e)*m;
		
		
		dat.push_back(P(-price/time, l));
	}
	
	sort(dat.begin(),dat.end());
	
	rep(i,dat.size()){
		cout<<dat[i].second<<endl;
	}
	cout<<"#"<<endl;
	return true;
}

int main(){
	while(solve());
}

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

int main()
{
   int n;
   char s[1000010];
   
   cin >> n;
   scanf("%s",s);
   
   int l,r,mid,jj,oo,ii,isum;
   l = 0;
   r = n-1;
  while(l < r){
       jj = 0;
       oo = 0;
       ii = 0;
       isum = 0;
       mid = (l+r+1)/2;
       for(int i=n-1;i>=0;i--){
           if(s[i] == 'I' && isum < mid){
               ii++;
               isum++;
           }
           else if(ii > 0 && s[i] == 'O'){
               oo++;
               ii--;
           }
           else if(oo > 0 && s[i] != 'O'){
               jj++;
               oo--;
           }
       }
       
       if(jj >= mid) l = mid;
       else r = mid-1;
       
   }
    
    cout << l << endl;
    
    return 0;
}



Measured memory_bytes: 4200
# include <iostream>
# include <string>
# include <vector>
using namespace std;
int main(void)
{
	string s;
	bool f = false,flag;
	double cnt;
	int high = 0,sum = 0,*d,left;
	vector<int> ans;
	cin>>s;
	int len = s.length();
	d = new int [len+1];
	d[0] = 0;
	for(int i = 1;i <= len;i++)
	{
		if(s[i-1] == '_') d[i] = d[i-1];
		else if(s[i-1] == '/') d[i] = d[i-1]+1;
		else if(s[i-1] == '\\')d[i] = d[i-1]-1;
	}
	high = 0;
	for(int i = 0;i < len;i++)
	{
		if(f == false) 
		{
			if(s[i] == '_') continue;
			else if(s[i] == '/')
			{
				high++;
				continue;
			}
			else
			{
				flag = false;
				for(int j = i+1;j <= len;j++)
				{
					if(d[j] == high) 
					{
						flag = true;
						break;
					}
				}
				if(flag)
				{
					left = high; f = true;
					cnt = 0.5;
				}
				high--;
			}
		}
		else
		{
			if(s[i] == '\\')
			{
				high--;
				cnt += (left-high-0.5);
			}
			else if(s[i] == '_') cnt += left-high;
			else 
			{
				cnt += (left-high-0.5);
				high++;
				if(high == left)
				{
					f = false;
					ans.push_back(int(cnt));
					sum += int(cnt);
				}
			}
		}
	}
	printf("%d\n%d",sum,ans.size());
	for(int i = 0;i < ans.size();i++) printf(" %d",ans[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3388
n = int(input())
a = 0
b = 0
c = 0
d = 0
for x in range (n):
  word = input()
  if word == 'AC':
    a +=1
    continue
  if word == 'WA':
    b+= 1
  if word == 'TLE':
    c+= 1
  if word == 'RE':
    d+= 1
print('AC x',a)
print('WA x',b)
print('TLE x',c)
print('RE x',d)

Measured memory_bytes: 9208
import Data.Functor

default (Integer, Double)

main :: IO ()
main = do
    point_list <- map (\x  -> read x::Double) <$> words <$> getLine
    print (distance point_list)

distance::[Double] -> Double
distance ps =
        sqrt ((ps!!0 - ps!!2)^2 + (ps!!1 - ps!!3)^2)

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

int main(){
    
    int N,K,x,Km;
    
    int sum = 0;
    
    cin >> N >> K;
    
    for(int i = 0; i < N; i++){
        
        cin >> x;
        
       Km = K - x;
        
        if(Km < 0){
            Km *= -1;
        }
        
        if(x < Km ){
            sum += 2 * x;   
        }else{
            sum += 2 * Km;
        }
        
    }
    
    cout << sum << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


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

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

#define MAX_N 20
i64 N;
i64 A[MAX_N];


int main() {
  cin >> N;
  REP(i, N) cin >> A[i];

  i64 cnt = 0;
  for (i64 i = 1; i <= N - 2; i++) {
    if (A[i-1] >= A[i] && A[i] >= A[i+1]) {
      cnt++;
    } else if (A[i-1] <= A[i] && A[i] <= A[i+1]) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
// Problem : D - String Formation
// Contest : AtCoder - AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359;
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	string S;
	cin>>S;
	int Q;
	cin>>Q;
	vector<char> start,end;
	start.reserve(Q);
	start.reserve(Q);
	bool flip=false;
	F0R(x,Q)
	{
		int choice;
		cin>>choice;
		if(choice==1)
		{
			flip=!flip;
			continue;
		}
		int pt;
		char ch;
		cin>>pt>>ch;
		if(pt==1)
		{
			if(flip)
			{
				end.pb(ch);
			}
			else
			{
				start.pb(ch);
			}
		}
		else
		{
			if(flip)
			{
				start.pb(ch);
			}
			else
			{
				end.pb(ch);
			}
		}
	}
	string ans="";
	F0Rd(x,sz(start))
	{
		ans=ans+start[x];
	}
	ans=ans+S;
	F0R(x,sz(end))
	{
		ans=ans+end[x];
	}
	if(flip)
	{
		F0Rd(x,sz(ans))
		{
			cout<<ans[x];
		}
	}
	else
		cout<<ans<<endl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
 



Measured memory_bytes: 2180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,k,ans=0,a[11]={};
    scanf("%d%d",&n,&k);
    for (int i=0; i<11; i++){
        for (int j=1; j<6; j++){
            a[(((i*7)+j)*9+72)%11]++;
        }
    }
    ans+=(n-2)/11*a[k];
    for (long long i=(n-2)/11*11; i<n-2; i++){
        for (long long j=1; j<=5; j++)
        if ((((i*7)+j)*9+72)%11==k){
            ans++;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
struct edge {
  int u, v, w;
};
struct node {
  int index, w;
};
VEC<list<int>> G;

int main() {
  int N;
  cin >> N;
  G = VEC<list<int>>(N);
  VEC<int> D(N);
  REP(i, 0, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(i, 0, N) { cin >> D[i]; }
  sort(ALL(D));
  LL sum = 0;
  REP(i, 0, N - 1) { sum += D[i]; }
  cout << sum << endl;

  reverse(ALL(D));
  queue<int> q;
  VEC<int> ans(N, 0);
  q.push(0);
  int index = 0;
  VEC<bool> used(N, 0);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    used[node]=true;
    ans[node] = D[index];
    index++;
    for (auto v : G[node]) {
      if (used[v]) continue;
      q.push(v);
    }
  }
  REP(i,0,N){
    cout<<ans[i]<<" ";
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n;
    vector<P> p;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        p.push_back(P(a, i+1));
    }
    sort(p.begin(), p.end());
    for(int i=0;i<n;i++){
        cout << p[i].second << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1780
N,M,A,B=map(int,input().split())

def solve(n,m,a,b):
#そもそも絶対的にスペースが足りない場合
  if a*2+b*2>n*m:
    return False
  else:
    ans=[['.' for x in range(m)] for y in range(n)]
#各タイルの残りをカウント
    remainA=a
    remainB=b
#原点を起点として2枚を正方形にして敷き詰めていく
    nx=0
    ny=0
#縦横の限界値をカウント
    gx=n
    gy=m
#縦が奇数ならばnxを+1して、最初の行にAを並べる
    if n%2:
      nx=1
      cnt=0
      while True:
        if cnt > m-2 or remainA==0:
          break
        ans[0][cnt]='<'
        ans[0][cnt+1]='>'
        remainA-=1
        cnt+=2
#横が奇数ならば限界値を-1して、最後の列にBを並べる
    if m%2:
      gy-=1
      cnt=0
      while True:
        if cnt > n-2 or remainB==0:
          break
        ans[cnt][m-1]='^'
        ans[cnt+1][m-1]='v'
        remainB-=1
        cnt+=2
#以上で縦横どちらかが1列行の場合の処理終わり。ABが残っていたらFalse
    if (n==1 or m==1) and (remainA>0 or remainB>0):
      return False
#残り枚数を2枚ずつ消化するので、for文のために残数を変数にセット。
    cna=remainA
    cnb=remainB
#まずはBを敷き詰める。
    for i in range(cnb//2):
      ans[nx][ny]='^'
      ans[nx+1][ny]='v'
      ans[nx][ny+1]='^'
      ans[nx+1][ny+1]='v'
      remainB-=2
#横軸方向に+2、出来なければ、縦軸方向に+2して横軸位置を0に。
      if ny+2 < gy-1:
        ny+=2
      elif nx+2 < gx-1:
        nx+=2
        ny=0
#移動できなければ、そこで終了。ABが残っていればFalse。残っていなければ正解タイル。
      else:
        if remainA>0 or remainB>0:
          return False
        else:
          return ans
#次にAを敷き詰める。
    for i in range(cna//2):
      ans[nx][ny]='<'
      ans[nx][ny+1]='>'
      ans[nx+1][ny]='<'
      ans[nx+1][ny+1]='>'
      remainA-=2
#横軸方向に+2、出来なければ、縦軸方向に+2して横軸位置を0に。
      if ny+2 < gy-1:
        ny+=2
      elif nx+2 < gx-1:
        nx+=2
        ny=0
#移動できなければ、そこで終了。ABが残っていればFalse。残っていなければ正解タイル。
      else:
        if remainA>0 or remainB>0:
          return False
        else:
          return ans
#x2で敷き詰め終えたので、残数と状況を調査。残っている各タイルは最大1つ
    if remainA%2==0 and remainB%2==0:
      return ans
#両方1つずつ残っている場合、2x2が2つ必要。条件からgx/gyは偶数なので。
    elif remainA%2==1 and remainB%2==1:
      ans[nx][ny]='^'
      ans[nx+1][ny]='v'
      if ny+2 < gy-1:
        ny+=2
      elif nx+2 < gx-1:
        nx+=2
        ny=0
#移動できなくてかつ隅が空いてなければAを置くことができない。
      else:
        if ans[n-1][m-1]=='.'  and ans[n-1][m-2]=='.':
          ans[n-1][m-1]='>'
          ans[n-1][m-2]='<'
          return ans
        return False
#移動できたのでAを置いてreturn
      ans[nx][ny]='<'
      ans[nx][ny+1]='>'
      return ans
#Aだけが残っている場合はAを置いてreturn
    elif remainA%2==1:
      ans[nx][ny]='<'
      ans[nx][ny+1]='>'
      return ans
#Bだけが残っている場合はBを置いてreturn
    else:
      ans[nx][ny]='^'
      ans[nx+1][ny]='v'
      return ans

Ans=solve(N,M,A,B)
if Ans:
  print("YES")
  for i in range(N):
    res="".join(Ans[i])
    print(res)
else:
  print("NO")

Measured memory_bytes: 13044
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long i64;
const int MOD = 998244353, MAX_N = 1000005;

i64 fac[MAX_N], ifac[MAX_N], inv[MAX_N];
int N, M;

i64 binom(int n, int m) {
  if (n < m) return 0;
  return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}

i64 res[MAX_N], temp[MAX_N];

int main() {
  scanf("%d%d", &N, &M);
  
  if (N > M) swap(N, M);
  
  fac[0] = ifac[0] = inv[1] = 1;
  for (int i = 1; i <= N + M; ++i) fac[i] = fac[i - 1] * i % MOD;
  for (int i = 2; i <= N + M; ++i) inv[i] = (-(MOD / i) * inv[MOD % i] % MOD + MOD) % MOD;
  for (int i = 1; i <= N + M; ++i) ifac[i] = ifac[i - 1] * inv[i] % MOD;
  
  i64 horizon = binom(N + M - 1, N), vertical = binom(N + M - 1, N - 1);
  
  for (int i = 1; i <= N + M; ++i) {
    res[i] = (res[i - 1] + horizon + vertical) % MOD;

    if (i <= N * 2) {
      if (!(i & 1)) {
	horizon = (horizon + binom(N + M - 1 - i, M - i / 2 - 1) * binom(i - 1, i / 2) % MOD) % MOD;
	vertical = (vertical + binom(N + M - 1 - i, N - i / 2 - 1) * binom(i - 1, i / 2)) % MOD;
      } else {
	horizon = (horizon - binom(N + M - 1 - i, M - i / 2 - 1) * binom(i - 1, i / 2) % MOD) % MOD;
	vertical = (vertical - binom(N + M - 1 - i, N - i / 2 - 1) * binom(i - 1, i / 2) % MOD) % MOD;
      }
    }
    if (i >= N * 2) vertical = 0;
    // if (i >= M && M > 1) horizon = (horizon - binom((i - M) + M - 1, M - 1)) % MOD;
    // if (i >= N && i < N * 2 && N > 1) vertical = (vertical - binom((i - N) + N - 1, N - 1)) % MOD;
  }

  i64 result = 0;
  for (int i = 1; i <= N + M; ++i)
    result = (result + res[i] * inv[i] % MOD) % MOD;
  result = result * fac[N] % MOD * fac[M] % MOD * ifac[N + M] % MOD;
  printf("%lld\n", (result + MOD) % MOD);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int N; cin >> N;
  vi32 a(N); cin >> a;
  i64 sum = 0;
  rep(i, N) if (i % 2 == 0) sum += a[i]; else sum -= a[i];
  vi32 ans(N);
  ans[0] = sum;
  rep(i, N - 1) {
    ans[i + 1] = a[i] * 2 - ans[i];
  }
  cout << ans << '\n';
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	string s,t;
	cin>>s>>t;
	string s1="";
	for(int i=0;i<t.length()-1;i++)s1+=t[i];
	if(s1==s)cout<<"Yes";
	else cout<<"No";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3656
N = int(input())
a = list(map(int, input().split()))

ans = 1
can = 1
zero = 0

if 0 in a:
    zero = 1
    ans = 0

if(zero==0):
    for i in range(N):
        ans = ans * a[i]
        if(ans>1000000000000000000):
            can = 0
            break

if(can==1):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 21560
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

    int n, k;
    string s;
    cin >> n >> k >> s;
    int i = 0, j = 0;
    int ans = 0;

    while(j < n) {
        while(j < n && s[j] == '1') j++;
        chmax(ans, j - i);
        while(j < n && s[j] == '0') j++;
        k--;
        if(k < 0) {
            while(i < n && s[i] == '1') i++;
            while(i < n && s[i] == '0') i++;
        }
        chmax(ans, j - i);
    }

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

Measured memory_bytes: 512
while True:
    n,x = map(int,input().split())

    if  n == 0 and x==0:
        break
    else:
        sum = 0
        for i in range(1,n-1):
          for j in range(i+1,n):
            for k in range(j+1,n+1):
              if i+j+k == x:
                sum+= 1
    print(sum)


Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int main()
{
    int n,a,i,cnt=0,k=1;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        if(a==k) k++;
        else cnt++;
    }
    if(k==1) cout << "-1";
    else cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K;
  cin >> N >> K;

  string s;
  cin >> s;

  REP(i, N){
    if(i == K-1) s[i] = s[i]-'A'+'a';
    cout << s[i];
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 3620
N = int(input())
A = list(map(int, input().split()))


joutai = 0
kabusu = 0
money = 1000
for i in range(N):
    if i == N-1:
        if joutai == 1 and A[i] >= A[i-1]:
            money = money + A[i] * kabusu
            joutai = 0
            kabusu = 0
    else:
        if A[i] < A[i+1]:
            if joutai == 0:
                kabusu = money // A[i]
                joutai = 1
                money = money - A[i] * kabusu
        elif A[i] > A[i+1]:
            if joutai == 1:
                money = money + A[i] * kabusu
                joutai = 0
                kabusu = 0
                
print(money)

Measured memory_bytes: 9216
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3
dwango 2
sixth 5
prelims 25
dwango
---+/
/+---test
15
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;
  auto S = new string[](N);
  auto T = new long[](N);

  foreach (i; 0..N) {
    readf(" %s %d ", &S[i], &T[i]);
  }
  const X = readln.chomp;

  const t = S.countUntil!(x => x == X);
  T[t+1..$].sum.writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

//abc103
//最小公倍数 -1のMODでよさそう
//最小公倍数を求めずとも、 すべて掛けたあと-1 すればよい
//かける必要もなく、結果だけ出力すればよい
int main() {

    ll N;
    cin >> N;

    ll tmp;
    ll res = 0;

    REP(i,N)
    {
        cin >> tmp;

        res += tmp-1;
    }
    cout << res << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
#include <unordered_map>

using namespace std;

const int pot[]={1, 10, 100, 1000, 10000, 100000};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int x=n;
	int br=0;
	while(x>0){
		br++;
		x/=10;
	}
	int sol=0;
	n++;
	while(br--){
		if((br+1)%2){
			sol+=n-pot[br];
		}
		n=pot[br];
	}
	cout << sol << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main{
	static final double EPS = 0.00000000001;
	static final int COUNTER_CLOCKWISE = 1;
	static final int CLOCKWISE = -1;
	static final int ONLINE_BACK = 2;
	static final int ONLINE_FRONT = -2;
	static final int ON_SEGMENT = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if(n == 0) break;
			List<Point> s = new ArrayList<Point>();
			for(int i = 0; i < n; i++) {
				String[] t = sc.next().split(",");
				double x = Double.parseDouble(t[0]);
				double y = Double.parseDouble(t[1]);
				s.add(new Point(x, y));
			}
			List<Point> l = andrewScan(s);
			System.out.println(n - l.size());
		}
		sc.close();
	}
	static List<Point> andrewScan(List<Point> s){
		List<Point> u = new ArrayList<Point>();
		List<Point> l = new ArrayList<Point>();
		if(s.size() < 3) return s;
		Collections.sort(s, new MyComp(1));
//		for(int i = 0; i < s.size(); i++) {
//			System.out.printf("%d %d %d\n", i, s.get(i).x, s.get(i).y);
//		}
		// x が小さいものから2つ u に追加
		u.add(s.get(0));
		u.add(s.get(1));
		// x が大きいものから2つ l に追加
		l.add(s.get(s.size() - 1));
		l.add(s.get(s.size() - 2));

		// 凸包の上部を生成
		for(int i = 2; i < s.size(); i++) {
			for(int n = u.size(); n >= 2 && ccw(u.get(n - 2), u.get(n - 1), s.get(i)) != CLOCKWISE; n--) {
				u.remove(u.size() - 1);
			}
			u.add(s.get(i));
		}

		// 凸包の下部を生成
		for(int i = s.size() - 3; i >= 0; i--) {
			for(int n = l.size(); n >= 2 && ccw(l.get(n - 2), l.get(n - 1) , s.get(i)) != CLOCKWISE; n--) {
				l.remove(l.size() - 1);
			}
			l.add(s.get(i));
		}

		// 時計回りになるように凸包の点を列に生成
		Collections.reverse(l);
		for(int i = u.size() - 2; i >= 1; i--) {
			l.add(u.get(i));
		}
		return l;
	}
	static class Point{
		double x, y;
		Point(double x, double y){
			this.x = x;
			this.y = y;
		}
	}
	static class MyComp implements Comparator<Point>{
		int sign;
		MyComp(int sign) {
			this.sign = sign;
		}
		public int compare(Point p1, Point p2) {
			if(p1.y < p2.y) {
				return -1 * sign;
			}else if(p1.y == p2.y) {
				if(p1.x < p2.x) {
					return -1 * sign;
				}else if(p1.x == p2.x) {
					return 0;
				}else {
					return 1 * sign;
				}
			}else {
				return 1 * sign;
			}
		}
	}

	static int ccw(Point p0, Point p1, Point p2) {
		Point a = vec(p0, p1);
		Point b = vec(p0, p2);
		if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
		if(cross(a, b) < EPS) return CLOCKWISE;
		if(dot(a, b) < EPS) return ONLINE_BACK;
		if(norm(a) < norm(b)) return ONLINE_FRONT;
		return ON_SEGMENT;
	}
	static double norm(Point p) {
		return p.x * p.x + p.y * p.y;
	}
	static Point vec(Point p1, Point p2) {
		return new Point(p2.x - p1.x, p2.y - p1.y);
	}
	static double dot(Point u, Point v) {
		return u.x * v.x + u.y * v.y;
	}
	static double cross(Point u, Point v) {
		return u.x * v.y - u.y * v.x;
	}
}


Measured memory_bytes: 26412
n = int(input())

mins = []
maxs = []

for i in range(n):
  a, b = map(int, input().split())
  mins.append(a)
  maxs.append(b)
  
mins.sort()
maxs.sort()

if n % 2 == 1:
  mid = n // 2
  print(maxs[mid] - mins[mid] + 1)
else:
  mid1 = n//2
  mid2 = mid1 - 1
  smallest = mins[mid1] + mins[mid2]
  largest = maxs[mid1] + maxs[mid2]
  print(largest - smallest + 1)

Measured memory_bytes: 25480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    if(N%2 == 0){
        for(int i=N-1; i>=1; i-=2){
            if(i != N-1) cout << " ";
            cout << a[i];
        }
        for(int i=0; i<=N-2; i+=2){
            cout << " ";
            cout << a[i];
        }
        cout << endl;
    } else {
        for(int i=N-1; i>=0; i-=2){
            if(i != N-1) cout << " ";
            cout << a[i];
        }
        for(int i=1; i<=N-2; i+=2){
            cout << " ";
            cout << a[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 2944
/* #                          */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <deque>
#include <map>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;

constexpr int               inf = 0x3f3f3f3f;
constexpr long long 		INF = 9123456789123456789;
constexpr long long         MOD = 1000000007LL;
/*************************************************/
int N, H;
vi A;
void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin.tie(nullptr);
    cin >> H >> N;
    int sum(0);
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum < H) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}




Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val area1 = area(scanner.nextInt(),scanner.nextInt())
    val area2 = area(scanner.nextInt(),scanner.nextInt())
    
    when{
        area1 > area2 ->{
            print(area1)}
        
        area1 < area2 ->{
            print(area2)
        }
        
        else -> {
            print(area1)}
    }
}

fun area(a:Int,b:Int):Int = a*b


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	map<int, int> m;
	REP(i, n){
		int a;
		cin >> a;
		m[a]++;
	}
	int ans = 0;
	for(const auto &i : m){
		if(i.X <= i.Y) ans += i.Y - i.X;
		else ans += i.Y;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 4736
def main():
	N = int(input())
	z = []
	for i in range(N):
		d1, d2 = [int(d) for d in input().split(" ")]
		if d1 == d2:
			z.append(1)
		else:
			z.append(0)
	zc = []
	now = 2
	c = 0
	for i in range(len(z)):
		if i == 0:
			now = z[i]
			c += 1
		elif now == z[i]:
			c += 1
		elif now == 1 and z[i] == 0:
			zc.append(c)
			c = 1
			now = z[i]
		elif now == 0 and z[i] == 1:
			c = 1
			now = z[i]
	else:
		if now == 1:
			zc.append(c)

	print("Yes") if len(zc) > 0 and max(zc) >= 3 else print("No")

main()

Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 2e9
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
      ll  n,m;
      cin>>n>>m;
      
      ll ans =0;
  
      
       ans= (n*(n-1))/2 + (m*(m-1))/2;
       cout<<ans<<endl;
       
      
	  
	  
	    
     
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  if (N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}

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;
int INF = 1000000009;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int x;
    rep(i, n)
    {
        cin >> a[i];
        x = a[i] == 1 ? i: x;
    }
    int cnt = 0;
    int tmp = 0;
    int left = x, right = n - 1 - x;
    k--;
    while (right > 0)
    {
        if(right >= k){
            right -= k;
            cnt++;
        }else{
            tmp = k;
            tmp -= right;
            right = 0;
            cnt++;
        }
    }
    left -= tmp;
    while (left > 0)
    {
        left -= k;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var k = Number(lines[1]);
 var x = lines[2].split(' ');
 x = x.map(function(str) { return Number(str)});
 var ans = 0;
 
 for(i=0; i<n; i++){
   var a = x[i] * 2;
   var b = (k - x[i]) * 2;
   if(a < b){
     ans += a;
   }else if(a >= b){
     ans += b;
   }
     
   }
 

 console.log(ans);
});

Measured memory_bytes: 9676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<vector<ll>> c(19, vector<ll>(19));
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        double b;
        cin >> b;
        b *= 1e9;
        a[i] = round(b);
        int x = 0, y = 0;
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            x++;
        }
        while (a[i] % 5 == 0) {
            a[i] /= 5;
            y++;
        }
        x = min(x, 18);
        y = min(y, 18);
        c[x][y]++;
        debug(x, y);
    }
    debug(ans);
    for (int i = 0; i < 19; i++) {
        for (int j = 0; j < 19; j++) {
            for (int k = i; k < 19; k++) {
                for (int l = 0; l < 19; l++) {
                    if ((l < j && k == i)) {
                        continue;
                    }
                    if (i + k >= 18 && j + l >= 18) {
                        if (i == k && j == l) {
                            ans += c[i][j] * (c[i][j] - 1) / 2;
                            continue;
                        }
                        ans += c[i][j] * c[k][l];
                    }
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4680