akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X,K,D;
  cin >> X >> K >> D;
  long long M = abs(X/D);
  
  if (M % 2 == 0){
    if (K % 2 == 0){
      if (K <= M){
        cout << abs(abs(X) - K*D) << endl;
        return 0;
      }
      else {
        cout << abs(abs(X) - M*D) << endl;
        return 0;
      }
    }
    else {
      if (M+1 <= K){
        cout << abs(abs(X) - (M+1)*D) << endl;
        return 0;
      }
      else if (M-1 <= K){
        cout << abs(abs(X) - (M-1)*D) << endl;
        return 0;
      }
      else {
        cout << abs(abs(X) - K*D) << endl;
        return 0;
      }
    }
  }
  else {
    if (K % 2 != 0){
      if (K <= M){
        cout << abs(abs(X) - K*D) << endl;
        return 0;
      }
      else {
        cout << abs(abs(X) - M*D) << endl;
        return 0;
      }
    }
    else {
      if (M+1 <= K){
        cout << abs(abs(X) - (M+1)*D) << endl;
        return 0;
      }
      else if (M-1 <= K){
        cout << abs(abs(X) - (M-1)*D) << endl;
        return 0;
      }
      else {
        cout << abs(abs(X) - K*D) << endl;
        return 0;
      }
    }
  }
}




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

int main(){
    int N;
    cin>>N;
    
    int a[N];
    for(int i=0;i<N;i++) cin>>a[i];
    
    int count=0;
    for(int i=0;i<N-1;i++){
        if(a[i+1]==a[i]){count++;i++;}
    }

    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long int a,b,c,d;
long long int max(long long int x,long long int y){
	if(x>y)return x;
	return y;
}
int main(){
	cin>>a>>b>>c>>d;
	cout<<max(a*c,max(a*d,max(b*c,b*d)))<<endl;
	return 0;
}

Measured memory_bytes: 3196
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int H,W,h,w; cin >> H >> W >> h >> w;
    
    cout << H*W - (h*W+w*H-h*w) << ln;
    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<pair<pair<string, int>, int>> rs(n);
    for (int i = 0; i < n; ++i) {
        cin >> rs[i].first.first >> rs[i].first.second;
        rs[i].first.second *= -1;
        rs[i].second = i + 1;
    }

    sort(rs.begin(), rs.end());

    for (const auto &r : rs)
        cout << r.second << '\n';

    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> t(n+1, 0), x(n+1, 0), y(n+1, 0);
    rep(i,n){
        cin >> t.at(i+1) >> x.at(i+1) >> y.at(i+1);
    }

    
    rep(i, n){
        int tx = x.at(i);
        int ty = y.at(i);
        int tt = t.at(i+1)-t.at(i);

        int sum = abs(tx - x.at(i+1)) + abs(ty - y.at(i+1));
        dump(tx);
        if(sum>tt){
            cout << "No" << endl;
            return 0;
        }
        else{
            if((tt-sum)%2!=0){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


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

using namespace std;
using ll=long long;
using db=double;

typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<bool> vbl;

int inf=(1LL<<31)-1;
int MOD=1000000007;

#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=a;i<=b;i++)
#define f_j(a,b) for(int j=a;j<=b;j++)
#define vvii(c,a,b) vector<vector<ii>> c(a,vector<ii>(b,0))
#define vvll(c,a,b) vector<vector<ll>> c(a,vector<ll>(b,0))
#define vvstr(c,a,b) vector<vectorM<string> c(a,vector<string>(b,0))

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    while(true)
    {
        int ans=0;
        int count=0;
        int n,x;
        cin >> n >> x;
        if(n==0&&x==0)
        {
            return(0);
        }
        f_i(1,n)
        {
            f_j(1,i)
            {
                if(j==i)
                {
                    continue;
                }
                for(int o=1;o<=j;o++)
                {
                    if(o==i||o==j)
                    {
                        continue;
                    }
                    ans=i+j+o;
                    if(ans==x)
                    {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3220
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int s = in.ni(), w = in.ni();
    out.println(s > w ? "safe" : "unsafe");
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

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

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

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

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 32772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  vector<pair<int,bool>> nums(101000);
  nums[0].second = nums[1].second = false;
  for(int i=2;i<(int)nums.size();i++){
    nums[i] = make_pair(i,true);
  }
  vector<int> prime;
  for(int i=2;i<=sqrt(101000);i++){
    if(nums[i].second == false) continue;
    for(int j=i;j<(int)nums.size();j+=i){
      if(i!=j)nums[j].second = false;
    }
  }
  for(int i=2;i<(int)nums.size();i++){
    if(nums[i].second) prime.pb(nums[i].first);
  }
  vector<int> like2017(101000,0);
  like2017[0] = 0;
  int tmp = 0;
  for(int i=1;i<=100010;i+=2){
    if(binary_search(all(prime),i) && binary_search(all(prime),(i+1)/2)){
      tmp++;
    }
    like2017[i] = tmp;
  }

  int Q;
  cin >> Q;
  int l,r;
  rep(i,Q){
    cin >> l >> r;
    cout << like2017[r] - like2017[max(0,l-2)] << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	alpha := "abcdefghijklmnopqrstuvwxyz"
	C := sc.next()
	numStrArray := strings.Split(alpha, "")

	var index int
	for i, v := range numStrArray {
		if v == C {
			index = i
		}
	}
	fmt.Println(numStrArray[index+1])
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}

func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}

func (s *scanner) resetCur() {
	s.cur = 0
}

func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}

func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}

func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur], 64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i], 64)
	}
	s.resetCur()
	return res
}

func digits(x int) int {
	return len(strconv.Itoa(x))
}

func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

string s[111];
int dp[111][111];
int h, w;

signed main() {

    cin >> h >> w;
    for(int i = 0; i < h; i++)
        cin >> s[i];

    dp[1][1] = (s[0][0] == '#');

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(!(i+j)) continue;
            dp[i+1][j+1] = INF;
            if(i)
                dp[i+1][j+1] = dp[i][j+1] + (s[i][j] == '#' and s[i-1][j] == '.');
            if(j)
                chmin(dp[i+1][j+1], dp[i+1][j] + (s[i][j] == '#' and s[i][j-1] == '.'));
        }
    }

    cout << dp[h][w] << endl;
    
    return 0;
}



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

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int const MAX = 100010;

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N), vec(MAX, 0);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        vec[a] += 1;
        vec[b + 1] -= 1;
    }

    int ans = 0, sum = 1;
    REP(i, MAX) {
        sum += vec[i];
        if (i <= sum) ans = i;
    }

    cout << ans - 1 << endl;
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll ans = 0;
    ll pre = 0;
    REP(i, n){
        if(i == 0){
            pre = a[0];
        }else {
            if(pre - a[i] > 0){
                ans += pre - a[i];
            } else {
                pre = a[i];
            }
            
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 4900
N, Q = map(int, input().split())

S = input()
items = []
for i in range(Q):
    t, d = input().split()
    items.append((t, d))

left_ok = -1
left_ng = N

while left_ng - left_ok > 1:
    mid = (left_ok + left_ng) // 2
    flag = False
    tmp = mid
    for t, d in items:
        if t == S[tmp]:
            if d == "L":
                if tmp - 1 == -1:
                    flag = True
                    break
                tmp -= 1
            else:
                if tmp + 1 >= N:
                    break
                tmp += 1

    if flag:
        left_ok = mid
    else:
        left_ng = mid


right_ok = N
right_ng = -1

while right_ok - right_ng > 1:
    mid = (right_ok + right_ng) // 2
    flag = False
    tmp = mid
    for t, d in items:
        if t == S[tmp]:
            if d == "R":
                if tmp + 1 == N:
                    flag = True
                    break
                tmp += 1
            else:
                if tmp - 1 == -1:
                    break
                tmp -= 1

    if flag:
        right_ok = mid
    else:
        right_ng = mid
ans = N
if left_ok != -1:
    ans -= left_ok + 1

if right_ok != N:
    ans -= N - right_ok

if left_ok >= right_ok:
    ans = 0

print(ans)


Measured memory_bytes: 91596
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;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; }

const long long INF = 1000000000000000;
//const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
//ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

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

int main() {
	int a, b,res;
	res = 0;
	cin >> a >> b;
	if (a >= 13)res = b;
	else if (a >= 6 && a <= 12) res = b / 2;
	else if (a <= 5) res = 0;
	cout << res << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;

const ll mod = 1e9 + 7;
const int MM = 1e4 + 5, KM = 105;

inline int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}

inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}

V <V <ll>> dp(MM, V <ll> (KM, 0));
int K;
void pre() {
	dp[0][0] = 1;
	for(int dig = 1; dig < MM; dig++) {
		for(int cd = 0; cd <= 9; cd++) {
			for(int rem = 0; rem < K; rem++) {
				dp[dig][rem] = add(dp[dig][rem], dp[dig - 1][(rem - cd + 10 * K) % K]);
			}
		}
	}
}
ll ansFor(V <int> &N, int ind, ll rem) {
	if(ind == -1) {
		return rem == 0;
	}
	ll cnt0 = 0;
	for(int d = 0; d < N[ind]; d++) {
		cnt0 = add(cnt0, dp[ind][(-rem - d + 10 * K) % K]);
	}
	ll cnt1 = ansFor(N, ind - 1, (rem + N[ind]) % K);
	return add(cnt0, cnt1);
}

int main() {fio;
	string N;
	cin >> N >> K;
	pre();
	V <int> num(N.size());
	for(int i = 0; i < N.size(); i++) {
		num[N.size() - i - 1] = N[i] - '0';
	}
	cout << sub(ansFor(num, N.size() - 1, 0), 1) % mod;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    int n,m;
    cin >> n >> m;
    bool same = true;
    vector<string> A(n);
    rep(i,n) {
        cin >> A[i];
    }
    vector<string> B(m);
    rep(i,m) {
        cin >> B[i];
    }
    // 列方向
    rep(i,n-m+1) {
        int j = 0;
        while(j<n-m+1) {
            int k = 0;
            vector<bool> o(m,false);
            while (k<m) {
                if (A[j+k].substr(i,m) == B[k]) {
                    o[k] = true;
                }
                k++;
            }
            int cnt = count(all(o), true);
            if (cnt == m) {
                cout << "Yes" << "\n";
                return 0;
            }
            j++;
        }
    }
    cout << "No" << "\n";
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<bool> used(26, false);
    bool flag = false;
    for(auto c: s){
        if(used[c]){
            flag = true;
            break;
        }
        else{
            used[c] = true;
        }
    }
    cout << (flag?"no":"yes") << endl;
       

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

long long f(long long b, long long n)
{
	if (b > n) return n;

	return f(b, n / b) + n % b;
}

long long CheckForB(long long n, long long s)
{
	long long max_sroot = 316228;

	if (n < s)
	{
		return -1;
	}

	if (n == s)
	{
		return n + 1;
	}

	long long b = 1;

	if (s < 2 * max_sroot) // it could be possible that there are 3 or more b-digits
	{
		while (++b < max_sroot)
		{
			if (f(b, n) == s)
			{
				return b;
			}
		}

	}

	// now we left with at most 2 digits
	// and the first is at most max_sroot
	long long firstDigit = std::min(s, max_sroot) + 1, secondDigit = s - firstDigit;

	while ((++secondDigit, --firstDigit) > 0)
	{
		b = (n - secondDigit) / firstDigit;
		if (b > 1 && f(b, n) == s)
		{
			return b;
		}
	}

	return -1;
}

int main(int, char**)
{
		long long n, s;

		std::cin >> n >> s;

		std::cout << CheckForB(n, s) << std::endl;

	return 0;
}

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

int main() {
  double N; cin >> N;
  double even=0;
  double odd=0;
  
  rep(i,N){
    if(i%2 == 0){
      odd++;
    }
    else{
      even++;
    }
  }
  cout << odd / N << endl;
}


Measured memory_bytes: 256
s = list(input())
flg = True

if s[0] != "A":
    flg = False

count = 0
for i in s[2:-1]:
    if i == "C":
        count += 1
if count != 1:
    flg = False

n = 0
for i in s:
    if i.isupper():
        n += 1
if n != 2:
    flg = False

if flg:
    print("AC")
else:
    print("WA")

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



int main() {
  ll N,x = 0;
  cin >> N;
  rep (i,N)
  {
    ll l,r;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, enD) for (int var = (begin); var <= (enD); var++)
#define RFOR(var, begin, enD) for (int var = (begin); var >= (enD); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
using pll = pair<ll, ll>;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll N, A, B, C, D;
unordered_map<ll, ll> mp;

ll dfs(ll n) {
  if (mp.count(n)) return mp[n];
  if (n == 0) return 0;
  if (n > LINF / D) {
    mp[n] = LINF;
  } else {
    mp[n] = D * n;
  }
  mp[n] = min(mp[n], dfs(n / 2) + A + n % 2 * D);
  mp[n] = min(mp[n], dfs((n + 1) / 2) + A + (2 - n % 2) % 2 * D);
  mp[n] = min(mp[n], dfs(n / 3) + B + n % 3 * D);
  mp[n] = min(mp[n], dfs((n + 2) / 3) + B + (3 - n % 3) % 3 * D);
  mp[n] = min(mp[n], dfs(n / 5) + C + n % 5 * D);
  mp[n] = min(mp[n], dfs((n + 4) / 5) + C + (5 - n % 5) % 5 * D);
  return mp[n];
}

void solve(istream& cin, ostream& cout) {
  int t;
  cin >> t;
  REP(i, t) {
    cin >> N >> A >> B >> C >> D;
    mp.clear();
    dfs(N);
    cout << mp[N] << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

using namespace std;

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e5 + 7;
const ld pi = 3.14159265359;
const int INF = 1e20 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

int n, m, a[N], mn = INF;

map < int, int > cnt;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n >> m;

  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }

  for(int i = 1; i <= n; i++){
    mn = min(mn, a[i]);
    cnt[a[i] - mn]++;
  }

  cout << cnt.rbegin() -> second;
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

ll cl[3][33];



int main(){
    ll n,c;cin>>n>>c;
    ll d[33][33];
    rep(i,0,c)rep(j,0,c)cin>>d[i][j];
    rep(i,0,n){
        rep(j,0,n){
            ll C;cin>>C;
            if((i+j)%3==0)cl[0][C-1]++;
            else if((i+j)%3==1)cl[1][C-1]++;
            else if((i+j)%3==2)cl[2][C-1]++;
        }
    }
    ll MN=1e9,an;
    rep(i,0,c){
        rep(j,0,c){
            if(i==j)continue;
            rep(k,0,c){
                if(i==k||j==k)continue;
                an=0;
                rep(J,0,c)an+=d[J][i]*cl[0][J];
                rep(J,0,c)an+=d[J][j]*cl[1][J];
                rep(J,0,c)an+=d[J][k]*cl[2][J];
                MN=min(MN,an);
            }
        }
    }
    cout<<MN<<endl;
}
    









Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        int t,n;cin>>t;if(!t)return 0;
        cin>>n;
        for(int i=0;i<n;++i){
            int s,e;
            cin>>s>>e;
            t-=e-s;
        }
        if(t>0)cout<<t<<endl;
        else cout<<"OK"<<endl;
    }
    return 0;
}

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

void printBinary(ll n,string chosen,vector<string> &v2) {
	if(n==0) {
		v2.push_back(chosen);
	} else {
		printBinary(n-1,chosen+"0",v2);
		printBinary(n-1,chosen+"1",v2);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code here;
	ll n,i,j,k,a,x,y,max=0,count=0;
	cin>>n;
	vector<vector<pair<ll,ll> > > v;
	for(i=0;i<n;i++) {
		cin>>a;
		vector<pair<ll,ll> > v1;
		for(j=0;j<a;j++) {
			cin>>x>>y;
			v1.push_back(make_pair(x,y));
		}
		v.push_back(v1);
	}
	/*for(i=0;i<v.size();i++) {
		for(j=0;j<v[i].size();j++) {
			cout<<v[i][j].first<<" "<<v[i][j].second<<endl;
		}
	}*/
	vector<string> v2;
	string chosen="";
	printBinary(n,chosen,v2);
	for(i=0;i<v2.size();i++) {
		for(j=0;j<v2[i].size();j++) {
			//cout<<"@"<<v2[i][j]<<endl;
			if(v2[i][j]=='1') {
				count++;
				//cout<<"#"<<count<<endl;
				//for(k=0;k<v[j].size();k++) cout<<v[j][k].first<<" "<<v[j][k].second<<endl;
				for(k=0;k<v[j].size();k++) {
					//cout<<v2[i][(v[j][k].first-1)]-'0'<<"%%"<<v[j][k].second<<endl;
					if(v2[i][(v[j][k].first-1)]-'0'!=v[j][k].second) break;
				}
				//cout<<k<<"^^"<<v[j].size()<<endl;
				if(k!=v[j].size()) break;
			}
		}
		//cout<<"$"<<count<<endl;
		//cout<<j<<"&&"<<v2[i].size()<<endl;
		if(j==v2[i].size() && count>max) max=count;
		count=0;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b && b<c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
        using namespace std;
        using ll = long long;
        using ull = unsigned long long;
        using pii = pair<int, int>;
        using pll = pair<ll, ll>;

        const int MAXN = 1e5 + 5;
        const int MOD = 1e9 + 7;
        const int INF = 0x3f3f3f3f;
        const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
        const double EPS = 1e-9;
        #define NMAX 100005

        ll occurence[NMAX];
        int main(){
            ll n;
            cin>>n;
            ll num;
            ll sum=0;
            for (int i = 0; i < n; ++i)
            {
                cin>>num;
                occurence[num]++;
                sum +=num;
            }
            ll operation ; 
            cin>>operation;
            for (int i = 0; i < operation; ++i)
            {
                ll a,b;
                cin>>a>>b;
                sum -= a * occurence[a];
                occurence[b] +=occurence[a];
                sum += b * occurence[a];
                occurence[a] = 0;
                cout<<sum<<endl;
            }


            return 0;

        }


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

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


Measured memory_bytes: 3112
n, a, b = map(int,input().split())

if a >= b:
    if a+b > n:
        print(b,a+b-n)
    else:
        print(b,0)
elif b >= a:
    if a+b > n:
        print(a,a+b-n)
    else:
        print(a,0)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n, k;
    cin >> n >> k;
    VL p(n);
    rep(i, 0, n) cin >> p[i];
    sort(ALL(p));
    ll ans = 0;
    rep(i, 0, k) ans += p[i];
    cout << ans << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, r;
	cin >> n >> r;
	if(n >= 10) {
		cout << r;
	} else {
		cout << r + (100 * (10 - n));
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    cout<<n*n;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"


signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n;
    string a;
    cin>>a;
    vector<int> vectr,vectg,vectb;
    map<int,int> mpr,mpg,mpb;
    
    for(i=0;i<n;i++)
    {
        if(a[i]=='R')
        {
            vectr.push_back(i);
            mpr[i]=1;
        }
        
        else if(a[i]=='G')
        {
            vectg.push_back(i);
            mpg[i]=1;
        }
        
        else
        {
            vectb.push_back(i);
            mpb[i]=1;
        }
    }
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            temp = j-i;
            if(a[i]!=a[j])
            {
                if((a[i]=='R' || a[i]=='G') && (a[j]=='R' || a[j]=='G')) // black case
                {
                    auto it = lower_bound(vectb.begin() , vectb.end() , j) - vectb.begin();
                    ans += (vectb.size()-it);
                    if(mpb.find(j+temp)!=mpb.end())
                    {
                        ans--;
                    }
                    
                }
                
                else if((a[i]=='R' || a[i]=='B') && (a[j]=='R' || a[j]=='B')) // green case
                {
                     auto it = lower_bound(vectg.begin() , vectg.end() , j) - vectg.begin();
                    ans += (vectg.size()-it);
                    if(mpg.find(j+temp)!=mpg.end())
                    {
                        ans--;
                    }
                }
                
                else // red case
                {
                     auto it = lower_bound(vectr.begin() , vectr.end() , j) - vectr.begin();
                    ans += (vectr.size()-it);
                    if(mpr.find(j+temp)!=mpr.end())
                    {
                        ans--;
                    }
                }
                
            }
            
        }
    }
    
    cout<<ans<<endl;
    
    
    
    
    
    
    
        
    
}

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

int h,w,k;
int sx,sy,ex,ey;
vector<string> g;
vector<vector<int>> dis[4];
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};

int main(){

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

    cin>>h>>w>>k;
    cin>>sx>>sy>>ex>>ey;
    sx--;
    sy--;
    ex--;
    ey--;
    g.resize(h);
    for(int d=0;d<4;d++)dis[d].resize(h);
    for(int i=0;i<h;i++){
        cin>>g[i];
        for(int d=0;d<4;d++){
            dis[d][i].resize(w);
            fill(dis[d][i].begin(),dis[d][i].end(),1e9);
        }
    }
    for(int d=0;d<4;d++)dis[d][sx][sy]=0;
    queue<pair<int,int>> q;
    q.push(make_pair(sx,sy));
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        int cd=min(min(dis[0][x][y],dis[1][x][y]),min(dis[2][x][y],dis[3][x][y]));
        //cerr<<x<<' '<<y<<' '<<rd<<endl;
        for(int d=0;d<4;d++){
            for(int nx=x+dx[d],ny=y+dy[d],cnt=1;
            nx>=0&&ny>=0&&nx<h&&ny<w
            &&dis[d][nx][ny]>cd+1
            &&g[nx][ny]!='@'
            &&cnt<=k;
            nx+=dx[d],ny+=dy[d],cnt++){
                dis[d][nx][ny]=cd+1;
                for(int nd=0;nd<4;nd++)if(nd!=d){
                    dis[nd][nx][ny]=min(dis[nd][nx][ny],cd+2);
                }
                q.push(make_pair(nx,ny));
            }
        }
    }
    int ans=min(min(dis[0][ex][ey],dis[1][ex][ey]),min(dis[2][ex][ey],dis[3][ex][ey]));
    cout<<(ans==1e9?-1:ans)<<endl;

    return 0;
}


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

int64_t cnt = 0;
vector<int> G;

void insertionsort(vector<int> &A,int n,int g){
  for(int i = g; i < n; i++){
    int v = A.at(i);
    int j = i - g;
    while(j >= 0 && A.at(j) > v){
      A.at(j+g) = A.at(j);
      j -= g;
      cnt++;
    }
    A.at(j+g) = v;
  }
}

void shellsort(vector<int> &A,int n){
  int m = G.size();
  rep(i,m) insertionsort(A,n,G.at(m-1-i));
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  int h = 1;
  while(h <= N){
    G.push_back(h);
    h = (3 * h) + 1;
  }
  int m  = G.size();
  cout << m << endl;

  shellsort(A,N);
  for(int i = m - 1; i >= 0; i--){
    cout << G.at(i);
    if(i) cout << " ";
  }
  cout << "\n" << cnt << endl;
  rep(i,N) cout << A.at(i) << endl;
}



Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll r[200001]={0},d[200001]={0},n,k;
ll ans,mod=1e9+7;
set<int> A[200001];
int search(int x){
  r[x]=1;
  int a=0;
  for(auto i:A[x]) if(!r[i]) a++;
  if(d[x]==0) rep(i,a) ans=ans*(k-1-i)%mod;
  else rep(i,a) ans=ans*(k-2-i)%mod;
  for(auto i:A[x]) if(!r[i]) d[i]=d[x]+1;
  for(auto i:A[x]) if(!r[i]) search(i);
}
int main(){
  cin>>n>>k;
  int a,b;
  rep(i,n) cin>>a>>b,A[a].insert(b),A[b].insert(a);
  ans=k;
  search(1);
  cout<<ans;
}

Measured memory_bytes: 25472
N,K = map(int, input().split())
S = str(input())

if(S[K-1]=='A'):
  for i in range(N):
    if(i==K-1):
      print('a',end='')
    else:
      print(S[i], end='')
elif(S[K-1]=='B'):
  for i in range(N):
    if(i==K-1):
      print('b',end='')
    else:
      print(S[i],end='')
else:
  for i in range(N):
    if(i==K-1):
      print('c',end='')
    else:
      print(S[i],end='')

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let m = if n % 2 == 0 { 1 } else { 2 };
    const INF: i64 = 1 << 50;
    let mut dp = vec![vec![-INF; m + 1]; n + 2];
    dp[0][0] = 0;
    for i in 2..n + 2 {
        // j + 1 <= i
        for j in 1..min(m + 2, i) {
            for k in j - 1..m + 1 {
                let val = dp[i - j - 1][k - (j - 1)] + a[i - 2];
                dp[i][k] = max(dp[i][k], val);
            }
        }
    }
    let mut ma = -INF;
    for i in 0..m + 1 {
        let dif = m - i;
        ma = max(ma, dp[n + 1 - dif][i]);
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)

using namespace std;

constexpr double eps = 1e-12;

int64_t mod(int64_t x, int64_t mod) {
  if (x >= 0) return x%mod;
  else return mod + x%mod;
}

int64_t solve(int64_t range, int64_t x, int64_t y, int64_t modx, int64_t mody) {
  int64_t sum = 0;
  for (int64_t i = -range; i <= range; ++i) {
    if (mod(i, mody) != mod(y, mody)) continue;
     int64_t d = sqrt(range*range - i*i + eps);
     sum += floor((d-x)/double(modx)+eps) - ceil((-d-x)/double(modx)-eps) + 1;
  }
  return sum;
}

int main() {
  int64_t w,h,v,t,x,y,p,q;
  cin>>w>>h>>v>>t>>x>>y>>p>>q;
  int64_t vt = v*t;
  int64_t modx = 2*w;
  int64_t mody = 2*h;
  int64_t res = solve(vt, p-x, q-y, modx, mody)
      + solve(vt, modx-p-x, q-y, modx, mody)
      + solve(vt, p-x, mody-q-y, modx, mody)
      + solve(vt, modx-p-x, mody-q-y, modx, mody);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3112
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,na,nb,nab,ans=0;
string s[10010];

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>s[i];
		for(int j=0;j+1<s[i].size();j++) if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
		if(s[i][s[i].size()-1]=='A'&&s[i][0]=='B') nab++;else
		if(s[i][s[i].size()-1]=='A') na++;else
		if(s[i][0]=='B') nb++; 
	}
	ans+=max(0,nab-1);
	if(na>0&&nab>0) na--,ans++;
	if(nb>0&&nab>0) nb--,ans++;
	ans+=max(0,min(na,nb));
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 768
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BAtCoDeerPaintingBallsWithAtCoDeer {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n, k;
	    in >> n >> k;
	    ll res = k;
	    int cnt = n-1;
	    while(cnt > 0){
	        res *= (k-1);
	        cnt--;
	    }
	    out << res << endl;
	}
};


int main() {
	BAtCoDeerPaintingBallsWithAtCoDeer solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long f[112345];
int n,pp,s,t,d[112345];
int main(){
	scanf("%d%d%d",&n,&s,&t);
	for (int i = 1; i <= n; i++)
		scanf("%d",&d[i]);
	pp = 1;
	long long mi = (1 << 31) - 1;
	f[0] = 0;
	for (int i = 1; i <= n; i++){
		while (pp <= n && 2 * (d[i] - d[pp]) > t){
			mi = min(mi,f[pp - 1] - d[pp] * 2);
			pp++;
		}
		f[i] = min(f[pp - 1] + t,mi + d[i] * 2);
	}
	printf("%lld\n",s + f[n]);
}

Measured memory_bytes: 1536