akhauriyash/Code-Regression huggingface dataset:
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  max := 0
  count := 0
  for i := 0; i < n; i++ {
    sc.Scan()
    v, _ := strconv.Atoi(sc.Text())
    if v >= max {
      count++
      max = v
    }
  }
  fmt.Println(count)

}


Measured memory_bytes: 640
def partition(A, p, r):
    x = A[r]
    i = p - 1
    
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    
    A[i + 1], A[r] = A[r], A[i + 1]
    
    return i + 1
_ = input()
A = [int(num) for num in input().split()]
p = 0
r = len(A)-1
q = partition(A, p, r)
A_str = [str(a) for a in A]
A_str[q] = "[" + A_str[q] + "]"
print(" ".join(A_str))


Measured memory_bytes: 16588
H, W = map(int, input().split())
c = [[int(j) for j in input().split()] for i in range(10)]
for i in range(10):
	for j in range(10):
		if i == j:
			continue
		for k in range(10):
			if j == k:
				continue
			if c[i][k] + c[j][i] < c[j][k]:
				c[j][k] = c[i][k] + c[j][i]
ans = 0
for i in range(H):
	A = [int(j) for j in input().split()]
	for j in A:
		if j == -1:
			continue
		ans += c[j][1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> vs(n);
    for (int &v : vs)
    {
        cin >> v;
    }

    vector<int> index_of(n + 1);
    for (int i = 0; i < n; i++)
    {
        index_of[vs[i]] = i;
    }
    vector<bool> visited(n + 1, false);

    int max_count = -1;
    for (int i = 0; i < n; i++)
    {
        const int val = vs[i];

        if (!visited[val])
        {
            visited[val] = true;
            int n_val = val;
            int count = 1;

            while (n_val < n && index_of[n_val] < index_of[n_val + 1])
            {
                count++;
                n_val++;
                visited[n_val] = true;
            }
            max_count = max(max_count, count);            
        }
    }
    cout << (n - max_count) << endl;
} 

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

int main(){
    int w,h,x,y,r;

    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && x+r <= w){
        if(y-r >= 0 && y+r <= h){
            cout << "Yes" << endl;
        }   else{
            cout << "No" << endl;
        }
    }   else{
         cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 3096
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i;
  int a[9][9],n,x,y,vx,vy;
  for(h=1;cin>>n&&n;h++){
    x=y=0;
    vx=1;
    vy=-1;
    for(i=1;i<n*n+1;i++){
      a[x][y]=i;
      if(0){
      }else if(y+vy==n){
	x++;
	vx=1;
	vy=-1;
      }else if(x+vx==-1){
	y++;
	vx=1;
	vy=-1;
      }else if(x+vx==n){
	y++;
	vx=-1;
	vy=1;
      }else if(y+vy==-1){
	x++;
	vx=-1;
	vy=1;
      }else{
	x+=vx;
	y+=vy;
      }
    }
    printf("Case %d:\n",h);
    for(y=0;y<n;y++){
      for(x=0;x<n;x++)
	printf("%3d",a[x][y]);
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;

    int ans = 1;
    for(int i = 0; i < N - 1; i++){
        if(s[i] != s[i + 1]) ans++;
    }

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


Measured memory_bytes: 512
from collections import deque

N = int(input())
S = input()

ans = deque([])
emp = deque([])
for s in S[::-1]:
    if s == ")":
        ans.append('(')
    else:
        if ans:
            ans.pop()
        else:
            emp.append(')')
ans = list(ans)
emp = list(emp)
print("".join(ans)+S+"".join(emp))

Measured memory_bytes: 84240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MOD = 1000003;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

ll modpow(ll a, ll n, ll m)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n % 2 == 1) ret = ret * a % m;
    a = a * a % m;
    n /= 2;
  }
  return ret;
}

ll modinv(ll a, ll m)
{
  ll b = m, x = 1, y = 0;
  while (b > 0)
  {
    ll q = a / b, r = a - q * b, s = x - q * y;
    a = b, b = r;
    x = y, y = s;
  }
  return mod(x, m);
}

class combination
{
public:
  vector<ll> fac, finv, inv;

  combination(ll M)
  {
    fac = vector<ll>(M, 1);
    finv = vector<ll>(M, 1);
    inv = vector<ll>(M, 1);

    for (ll i = 2; i < M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i % MOD;
      inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
      finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
    }
  }

  ll P(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(N - K) % MOD;
  }

  ll C(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
  }

  ll H(ll N, ll K)
  {
    return C(N + K - 1, K);
  }
};

int main()
{
  combination com(MOD + 10);

  ll Q;
  cin >> Q;
  for (ll q = 0; q < Q; q++)
  {
    ll x, d, n;
    cin >> x >> d >> n;

    ll ans;

    if (d == 0)
      ans = modpow(x, n, MOD);
    else
    {
      ll X = x * modinv(d, MOD) % MOD;

      if (X + n - 1 >= MOD)
        ans = 0;
      else
        ans = modpow(d, n, MOD) * (com.fac.at(X + n - 1) * com.finv.at(X - 1) % MOD) % MOD;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 24320
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String s = sc.next();
		int b = sc.nextInt();
		if(s.equals("+")){
			System.out.println(a+b);
		}else{
		System.out.println(a-b);
		}
		sc.close();
	}

}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  vector<ll> L(87);
  for(int i = 0; i < 87; i++){
    L[i] = 0;
  }

  L[0] = 2;
  L[1] = 1;

  for(int i = 2; i < 87; i++){
    L[i] = L[i-1] + L[i-2];
  }

  cout << L[N] << endl;


  return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int W, H, N; cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N); REP(i, N) cin >> x[i] >> y[i] >> a[i];
  vector<int> x_vec(W), y_vec(H);
  REP(i, W) x_vec[i] = 0;
  REP(i, H) y_vec[i] = 0;
   
  for(int i = 0; i < N; ++i) {
    if(a[i] == 1) {
      for(int k = 0; k < x[i]; ++k) {
        x_vec[k] = 1;
      }
    }

    if(a[i] == 2) {
      for(int k = x[i]; k < W; ++k) {
        x_vec[k] = 1;
      }
    }

    if(a[i] == 3) {
      for(int k = 0; k < y[i]; ++k) {
        y_vec[k] = 1;
      }
    }

    if(a[i] == 4) {
      for(int k = y[i]; k < H; ++k) {
        y_vec[k] = 1;
      }
    }
  }

  int res_x = 0, res_y = 0;
  for(int i = 0; i < W; ++i) {
    if(x_vec[i] == 0) res_x++;
  }
  for(int i = 0; i < H; ++i) {
    if(y_vec[i] == 0) res_y++;
  }
  cout << res_x * res_y << endl;
}


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

template<typename T>
class BIT {
    public:
    int n;
    vector<T> bit; // i: [1,n]
    BIT(int size) {
        n = size + 1;
        bit = vector<T>(n+1,0);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    T range(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

ll n;
vector<int> a;

bool check(int x) {
    vector<int> b(n);
    rep(i,n){
        b[i] = (a[i] >= x ? +1 : -1);
    }
    vector<ll> s(n+1);
    rep(i,n){
        s[i+1] = s[i] + b[i];
    }
    vector<pair<ll, int>> vp(n+1);
    rep(i,n+1) {
        vp[i] = {s[i],i};
    }
    sort(all(vp));

    // 小さい順に1..n+1の連番を振る
    vector<ll> c(n+1);
    rep(i,n+1){
        c[vp[i].second] = i+1;
    }

    // i < j, c[i] <= c[j] の個数を数える
    ll result = 0;
    BIT<int> bit(n+1);
    rep(i,n+1){
        result += bit.sum(c[i]);
        bit.add(c[i], 1);
    }

    return (n*(n+1)/2 + 1)/2 <= result;
}

int main(void) {
    cin >> n;
    a.resize(n);
    vector<int> meds(n);

    rep(i,n){
        cin >> a[i];
        meds[i] = a[i];
    }
    sort(all(meds));
    int l = 0, r = n;
    while (l + 1 < r) {
        int mid = (l+r)/2;
        if (check(meds[mid])) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << meds[l] << endl;
    return 0;
}


Measured memory_bytes: 4992
n=int(input())
a=list(map(int,input().split()))
b=[2]*n
for i in range(n,0,-1):
    if n//i==1:b[i-1]=a[i-1]
    else: b[i-1]=(sum(b[2*i-1::i])%2)^a[i-1]
print(sum(b))
for i in range(n):
    if b[i]==1:print(i+1,end=' ')

Measured memory_bytes: 8784
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n,k;cin >> n >> k;
	int a[n];rep(i,n)cin >> a[i];
	vector<int> s(n+1);
	rep(i,n)s[i+1] = s[i]+a[i];
	//s[j] - s[i] %k == j-i
	//s[i]-i == s[j] - j && j-i < k
	map<int,int> mp;
	int ret = 0;
	rep(i,n+1){
		//trace(i,(s[i] - i)%k);
		int mae = i - k;
		if(mae >= 0){
			int tmp = (s[mae] - mae)%k;
			mp[(tmp+k)%k]--;
		}
		ret += mp[(s[i]-i)%k];
		
		mp[(s[i]-i)%k]++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 18832
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 21;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e9) return 10;
  if (x >= (long long)1e8) return 9;
  if (x >= (long long)1e7) return 8;
  if (x >= (long long)1e6) return 7;
  if (x >= (long long)1e5) return 6;
  if (x >= (long long)1e4) return 5;
  if (x >= (long long)1e3) return 4;
  if (x >= (long long)1e2) return 3;
  if (x >= (long long)1e1) return 2;
  return 1;
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  if (pt_out > buf_size - 32) flush();
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

int main() {
  int N;
  scan(N);
  int mn1 = INF, mx1 = -INF, mn2 = INF, mx2 = -INF;
  REP(i, N) {
    int x, y;
    scan(x);
    scan(y);
    int a = x + y, b = x - y;
    mn1 = min(mn1, a);
    mx1 = max(mx1, a);
    mn2 = min(mn2, b);
    mx2 = max(mx2, b);
  }
  println(max(mx1 - mn1, mx2 - mn2));
  return 0;
}

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

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A),b(B);
    int x,y,c;
    int i;
    int pa=100000,pb=100000;
    int price;

    for(i=0; i<A; i++){
        cin >> a.at(i);
        if(pa>a.at(i)) pa=a.at(i);
    }
    for(i=0; i<B; i++){
        cin >> b.at(i);
        if(pb>b.at(i)) pb=b.at(i);
    }
    price=pa+pb;

    for(i=0; i<M; i++){
        cin >> x >> y >> c;
        if(price>a.at(x-1)+b.at(y-1)-c) price=a.at(x-1)+b.at(y-1)-c;
    }

    cout << price << endl;
}

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

int main(){
    string s;
    cin >> s;
    int a = s[0]-'0', b = s[1]-'0', c = s[2]-'0', d = s[3]-'0';
    if(a+b+c+d==7) cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    else if(a-b+c+d==7) cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    else if(a+b-c+d==7) cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    else if(a+b+c-d==7) cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    else if(a-b-c+d==7) cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    else if(a+b-c-d==7) cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    else if(a-b-c-d==7) cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
    else if(a-b+c-d==7) cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> x(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int64_t sum = 0;
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      sum += A[i];
    }
    else{
      sum -= A[i];
    }
  }
  x[0] = sum;
  for (int i = 1; i < N; i++){
    x[i] = A[i - 1] * 2 - x[i - 1];
  }
  for (int i = 0; i < N - 1; i++){
    cout << x[i] << " ";
  }
  cout << x[N - 1] << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    ll N,M;
    cin >> N >> M;
    vector<ll> A(M);

    ll num = 0;
    rep(i,M){
        cin >> A[i];
        num += A[i];
    }

    ll ans;
    ans = N - num;
    if(ans < 0) ans = -1;

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3708
//created by pyoxiao on 2020/04/12
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
const int N  = 2e5 + 7;
int n;
LL res[N], a[N];
LL odd_sum[N], even_sum[N];
LL mmax[N];
void solve() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){
        scanf("%lld", a + i);
        if(i & 1) {
            if(i == 1) odd_sum[i] = a[i];
            else odd_sum[i] = odd_sum[i - 1] + a[i];
            even_sum[i] = even_sum[i - 1];
        } else {
            if(i == 2) even_sum[i] = a[i];
            else even_sum[i] = even_sum[i - 1] + a[i];
            odd_sum[i] = odd_sum[i - 1];
        }
    }
    LL ans = max(even_sum[n], odd_sum[n]);
    if(n % 2 == 0) {
        for(int i = 3; i <= n - 1; i += 2) {
            ans = max(ans, odd_sum[i - 1] + even_sum[n] - even_sum[i - 1]);
        }
        printf("%lld\n", ans);
        return;
    }
    //cout << ans << '\n';
    ans = max(even_sum[n - 1], odd_sum[n - 1]);
    for(int i = n - 1; i >= 2; i -= 2) {
        if(i == n - 1) mmax[i] = odd_sum[n] - odd_sum[i - 1] - even_sum[n] + even_sum[i - 1];
        else mmax[i] = max(mmax[i + 2], odd_sum[n] - odd_sum[i - 1] - even_sum[n] + even_sum[i - 1]);
    }
    for(int i = 2; i <= n; i ++) {
        if(i & 1) {
            res[i] = even_sum[n] - even_sum[i] + odd_sum[i - 1];
        } else {
            res[i] = odd_sum[n] - odd_sum[i] + even_sum[i - 1];
        }
        ans = max(ans, res[i]);
    }
    for(int i = 3; i <= n - 4; i += 2) {
        ans = max(ans, res[i] + mmax[i + 3]);
    }
    for(int i = 4; i <= n - 1; i += 2) {
        ans = max(ans, odd_sum[n] - odd_sum[i] + odd_sum[i - 3]);
    }
    printf("%lld\n", ans);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 11616
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
map<int,int> mmp;
int main()
{
    mmp.clear();
    int n,m;
    cin>>n;
    int x;
    while(n--)
        cin>>x,mmp[x]++;
    cin>>m;
    while(m--){
        cin>>x;
        if(!mmp.count(x)){
            cout<<"NO"<<endl;
            return 0;
        }
        else if(mmp[x]==0){
            cout<<"NO"<<endl;
            return 0;
        }
        mmp[x]--;
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 9600
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)



if N > K:

    


    if N >2*K:
        L=N//K
        N=N-L*K
    else:
        N=N-K
    

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)
    




Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <chrono>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    cout << (m1 == m2 ? 0 : 1) << endl;
}


Measured memory_bytes: 256
# Treap
class Node():
    def __init__(self, k, p):
        self.k = k
        self.p = p
        self.left = None
        self.right = None

def rightRotate(t):
    s = t.left
    t.left = s.right
    s.right = t
    return s

def leftRotate(t):
    s = t.right
    t.right = s.left
    s.left = t
    return s

def insert(t, key, pri):
    if t == None:
        return Node(key, pri)
    if key == t.k:
        return t

    if key < t.k:
        t.left = insert(t.left, key, pri)
        if t.p < t.left.p:
            t = rightRotate(t)
    else:
        t.right = insert(t.right, key, pri)
        if t.p < t.right.p:
            t = leftRotate(t)
    return t

def erase(t, key):
    if t == None:
        return None

    if key == t.k:
        if t.left == None and t.right == None:
            return None
        elif t.left == None:
            t = leftRotate(t)
        elif t.right == None:
            t = rightRotate(t)
        else:
            if t.left.p > t.right.p:
                t = rightRotate(t)
            else:
                t = leftRotate(t)
        return erase(t, key)

    if key < t.k:
        t.left = erase(t.left, key)
    else:
        t.right = erase(t.right, key)
    return t
"""
def find(t, k):
    if t == None:
        return -1
    if t.k == k:
        return 1
    if find(t.left, k) == 1:
        return 1
    if find(t.right, k) == 1:
        return 1
"""
def inorder(t):
    if t == None:
        return 
    inorder(t.left)
    print(" " + str(t.k), end="")
    inorder(t.right)

def preorder(t):
    if t == None:
        return
    print(" " + str(t.k), end="")
    preorder(t.left)
    preorder(t.right)

def output(t):
    inorder(t)
    print()
    preorder(t)
    print()


t = None
data = []
dict = {}
m = int(input())
for i in range(m):
    data.append(list(input().split()))

for i in range(m):
    if data[i][0] == "insert":
        if (data[i][1] in dict) == False:
            t = insert(t, int(data[i][1]), int(data[i][2]))
            dict[data[i][1]] = True
    elif data[i][0] == "print":
        output(t)
    elif data[i][0] == "find":
        #result = find(t, int(data[i][1]))
        #if result == 1:
        #print(dict)
        #result = data[i][1] in dict
        #print("result", result)
        #print("2", result == True)
        #print(data[i][1] in dict, data[i][1])
        if (data[i][1] in dict) == True:
            #print("12345")
            print("yes")
        else:
            print("no")
    else:
        t = erase(t, int(data[i][1]))
        if (data[i][1] in dict) == True:
            del dict[data[i][1]]
        #print(dict)


Measured memory_bytes: 122296
A,B,C,D=list(map(int,input().split()))

t_count=0
a_count=0

if A%D!=0:
    t_count+=1
if C%B!=0:
    a_count+=1

t_count+=int(A/D)
a_count+=int(C/B)

if t_count>=a_count:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(){
	int N,K;
	int dp[11][2001]={};
	int c,g;
	vector<int> tp[11];
	
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d %d",&c,&g);
		tp[g].push_back(c);
	}
	for(int i=1;i<=10;i++){
		sort(tp[i].begin(),tp[i].end());
		reverse(tp[i].begin(),tp[i].end());
		for(int j=1;j<=K;j++){
			int sum=0;
			for(int k=0;k<=(int)tp[i].size();k++){
				if(j-k<0)
				break;
				if(k!=0)
				sum+=tp[i][k-1];
				dp[i][j]=max(dp[i][j],dp[i-1][j-k]+(k-1)*k+sum);
			}
		}
	}
	printf("%d\n",dp[10][K]);
}


Measured memory_bytes: 3400
#include<stdio.h>
int main(void)
{
	int a[10],b[10],i,j,w,k,box;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<9;i++){
		for(j=i+1;j<10;j++){
			if(a[i]<a[j]){
			box=a[i];
			a[i]=a[j];
			a[j]=box;
			}
		}
	}
	for(i=0;i<9;i++){
		for(j=i+1;j<10;j++){
			if(b[i]<b[j]){
			box=b[i];
			b[i]=b[j];
			b[j]=box;
			}
		}
	}
	w=a[0]+a[1]+a[2];
	k=b[0]+b[1]+b[2];
	printf("%d %d\n",w,k);
	return 0;
}


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

long long s[200005];
long long t[200005];

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

    long long n, m, q;
    cin >> n >> m >> q;
    for(long long i= 0; i < n; ++i){
        cin >> s[i];
    }
    for(long long i = 0; i< m; ++i){
        cin >> t[i];
    }

    while(q--){
        long long x;
        cin >> x;
        long long above1 = *lower_bound(s, s + n, x);
        long long above2 = *lower_bound(t, t + m, x);
        long long below1 = *(lower_bound(s, s + n, x) - 1);
        long long below2 = *(lower_bound(t, t + m, x) - 1);

        bool canAbove1 = (lower_bound(s, s + n, x) == s + n ? false : true);
        bool canAbove2 = (lower_bound(t, t + m, x) == t + m ? false : true);
        bool canBelow1 = (lower_bound(s, s + n, x) == s ? false : true);
        bool canBelow2 = (lower_bound(t, t + m, x) == t ? false : true);


        long long res = 987654321987654321;
        if(canAbove1 && canAbove2){
            res = max(above1, above2) - x;
        }
        if(canBelow1 && canBelow2){
            res = min(res, x - min(below1, below2));
        }
        if(canAbove1 && canBelow2){
            if(above1 - x >= x - below2){
                res = min(res, x - below2 + x - below2 + above1 - x);
            }else{
                res = min(res, above1 - x + above1 - x + x - below2);
            }
        }
        if(canAbove2 && canBelow1){
            if(above2 - x >= x - below1){
                res = min(res, x - below1 + x - below1 + above2 - x);
            }else{
                res = min(res, above2 - x + above2 - x + x - below1);
            }
        }

        cout << res << "\n";
    }

    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  vector<string> s(n);
  long long int lasta=0;
  long long int firstb=0;
  long long int both=0;
  long long int ab=0;
  for(long long int i=0; i<n; i++){
    cin>>s.at(i);
    for(long long int j=0; j<s.at(i).size()-1; j++){
      if(s.at(i)[j]=='A'&&s.at(i)[j+1]=='B'){
        ab++;
      }
    }
    if(s.at(i)[0]=='B'&&s.at(i)[s.at(i).size()-1]=='A') {
      both++;
      continue;
    }
    if(s.at(i)[0]=='B') firstb++;
    if(s.at(i)[s.at(i).size()-1]=='A') lasta++;
  }

  while(true){
    if(lasta>0&&both>0){
      ab++;
      both--;
    }else if(firstb>0&&both>0){
      ab++;
      both--;
    }else if(lasta>0&&firstb>0){
      ab++;
      lasta--;
      firstb--;
    }else if(both>=2){
      ab++;
      both--;
    }else{
      break;
    }
  }
  cout<<ab<<endl;
}

Measured memory_bytes: 768
using System;
public class Class1
{
	public static void Main()
	{
		
		
		string line=Console.ReadLine();
		string pString=Console.ReadLine();
				
		char[] cs=line.ToCharArray();
		char[] pChar=pString.ToCharArray();
		string flag="No";
		for(int i=0;i<cs.Length;i++)
		{
			if(pChar[0]==cs[i])
			{   int j=0;
				int k=i;
				while(pChar[j]==cs[k])
					{
					j++;k++;
						if (j==pChar.Length)
						{
						flag ="Yes";
						i=cs.Length;
						break;
						}
						else if(k==cs.Length)
						{
							k=0;
						}						
					}					
				}					
			}
		Console.WriteLine(flag);
		}
			
	}

Measured memory_bytes: 8804
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [usize1; n],
  }
  let mut val_to_popl = vec![0; n];
  for x in a.into_iter() {
    val_to_popl[x] += 1;
  }
  let mut popl_to_count = vec![0; n + 1];
  for p in val_to_popl.into_iter() {
    if p > 0 {
      popl_to_count[p] += 1;
    }
  }
  let mut sum = vec![0; n + 2];
  for (i, &c) in popl_to_count.iter().enumerate() {
    sum[i+1] = sum[i] + c;
  }
  let mut sum_prod = vec![0; n + 2];
  for (i, &c) in popl_to_count.iter().enumerate() {
    sum_prod[i+1] = sum_prod[i] + i * c;
  }
  let mut count_to_len = vec![0; n + 1];
  for x in 1 .. n + 1 {
    count_to_len[x] = (sum_prod[x+1] + x * (sum[n+1] - sum[x+1])) / x;
  }
  count_to_len[0] = n;
  let mut count = n;
  for k in 1 .. n + 1 {
    while count_to_len[count] < k {
      count -= 1;
    }
    puts!("{}\n", count);
  }
}


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

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

    string s;
    cin >> s;
    
    int n = s.size();
    
    int ans[n];
    rep(i,n) ans[i] = 0;
    
    rep(i,n-1){
        //'RL'の並びになってるところを探す
        if(s[i] == 'R' && s[i+1] == 'L'){
            //左に連続しているRの数
            int sumR = 0;
            int j = i;
            while(s[j] == 'R' && j >= 0){
                sumR++;
                j--;
            }
            
            //右に連続しているLの数
            int sumL = 0;
            j = i + 1;
            while(s[j] == 'L' && j < n){
                sumL++;
                j++;
            }
            
            //Rのところに居る人の数
            ans[i] = sumR / 2 + sumL / 2 + sumR % 2;
            ans[i+1] = sumR / 2 + sumL / 2 + sumL % 2;
            
            // cout << sumL << endl;
            // rep(i,n){
            //     cout << ans[i] << ' ';
            // }
            // cout << endl;
        }
    }
    
    rep(i,n){
        cout << ans[i] << ' ';
    }
    
    return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int gcd(int a, int b)
{
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

// range sum query using segment tree

class segment_tree {
	vector<long> t;
	long size;
public:
	segment_tree() {
	}

	segment_tree(long n) {
		t.assign(4 * n + 1, 0);
		size = n;
	}

	void initialize(long n) {
		t.assign(4 * n + 1, 0);
		size = n;
	}

	void initialize_with_array(long startpos, long l, long r, vector<int>& v) {
		if (l == r) {
			t[startpos] = v[l];
		}
		else {
			long m = (l + r) / 2;
			initialize_with_array(2 * startpos, l, m, v);
			initialize_with_array(2 * startpos + 1, m + 1, r, v);

			t[startpos] = gcd(t[startpos * 2], t[startpos * 2 + 1]);
		}
	}

	void initialize_array(vector<int>& v) {

		initialize_with_array(1, 0, size - 1, v);
	}


	void update(long index, long val) { // insert val into location index
		update_full(1, 0, size - 1, index, val);
	}

	void update_full(long startpos, long l, long r, long index, long val) {
		if (l > r) return;
		if (l == r) {
			t[startpos] += val;
		}
		else {
			long m = (l + r) / 2;
			if (index <= m) update_full(2 * startpos, l, m, index, val);
			else update_full(2 * startpos + 1, m + 1, r, index, val);

			t[startpos] = gcd(t[startpos * 2], t[startpos * 2 + 1]);	// range sum
		}
	}

	long query(long l, long r) {  // get range min/max between l and r
		if (l > r) {
			return 0;
		}
		return query_full(1, 0, size - 1, l, r);
	}

	long query_full(long startpos, long left, long right, long l, long r) {	 // left/right = current range, l/r = intended query range
		if ((left >= l) && (right <= r)) return t[startpos];
		long m = (left + right) / 2, ans = -1, x;
		if (m >= l) {
			ans = query_full(startpos * 2, left, m, l, r);
		}
		if (m + 1 <= r) {
			x = query_full(startpos * 2 + 1, m + 1, right, l, r);
			if (ans == -1) ans = x;
			else ans = gcd(ans, x);
		}
		return ans;
	}
};



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

	int n, i, j, k, x, best = 0;

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

	segment_tree st(n);
	st.initialize_array(a);

	best = max(st.query(1, n - 1), st.query(0, n - 2));
	for (i = 1; i < n - 1; i++) {
		x = gcd(st.query(0, i - 1), st.query(i + 1, n - 1));
		best = max(best, x);
	}
	cout << best << "\n";
	


	return 0;
}


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

using namespace std;

int main(){
  string N;
  cin >> N;
  string answer = "No" ;
  
  if(N.at(0) == '7' || N.at(1) == '7' || N.at(2) == '7'){
    answer = "Yes";
  }
  
  cout << answer << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int count(int a)
{
    int cnt = 0;
    while (a % 2 == 0)
    {
        cnt++;
        a /= 2;
    }
    return cnt;
}

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

    int ans = 1 << 30;
    rep(i, n)
    {
        ans = min(ans, count(a[i]));
    }

    cout << ans << endl;

    return 0;
}


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int n; 
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int x = 0;
	for(int i=0;i<n;i++) x^=a[i];
	for(int i=0;i<n;i++) a[i]=x^a[i];
	for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
} 

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,p,ac=0,wa=0;cin>>n>>m;
  map<ll,map<string,ll>> mp;
  string s;
  rep(i,m) {
    cin>>p>>s;
    if(s=="AC") {if((mp[p])["AC"]==0) (mp[p])[s]+=1;}
    else {if((mp[p])["AC"]==0) (mp[p])[s]+=1;}
  }
  for(auto i:mp) {
    ac+=(i.second)["AC"];
    if((i.second)["AC"]==1) wa+=(i.second)["WA"];
  }
  printf("%lld %lld\n",ac,wa);
  return 0;
}

Measured memory_bytes: 20608
S=input()
N=len(S)
flag=0
for i in range(N):
  if S[i]!=S[N-1-i]:
    flag=1
    break
    
if flag==0:
  for i in range((N-1)//2):
    if S[i]!=S[(N-1)//2-1-i]:
      flag=1
      break
    
if flag==0:
  for i in range((N+1)//2,N):
    if S[i]!=S[N-1-i]:
      flag=1
      break

if flag==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

int main() {
    int n;
    cin >> n;
    vector<ll> dums(n);

    ll sum = 0;
    for (size_t i = 0; i < n; i++) {
        cin >> dums[i];
        sum += dums[i];
    }
    
    vector<ll> rain(n);
    rain[0] = sum;
    for (size_t i = 1; i < n; i += 2) {
        rain[0] -= 2 * dums[i];
    }

    for (size_t i = 1; i < n; i++)
    {
        rain[i] = 2 * dums[i-1] - rain[i-1];
    }
    for (auto &&e : rain)
    {
        cout << e <<endl;        
    }
    
}

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

typedef long long ll;
ll dp[200050];
ll INF=(ll)1e13;
int main()
{
    int n,W;
    cin>>n>>W;
    for(int i=1;i<=(int)1e5;i++){
        dp[i]=INF;
    }

    ll maxv=0;
    for(int i=0;i<n;i++){
        long long w,v;
        scanf("%lld%lld",&w,&v);
        for(int j=maxv;j>=0;j--){
            dp[j+v]=min(dp[j+v],dp[j]+w);
            maxv= max(j+v,maxv);
        }
    }

    for(int i=maxv;i>=0;i--){
        if(dp[i]<=W){
            cout<<i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

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

  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;

  return 0;
}


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

const int MAXN = 1e5 + 10;
int n;
char s[MAXN];

int main() {
	scanf(" %s", s + 1);
	n = strlen(s + 1);
	if (s[1] == '0' || s[n] == '1') return puts("-1"), 0;
	for (int i = 1; i < n; ++i)
		if (s[i] != s[n - i]) return puts("-1"), 0;
	int lst = 1, now = 0;
	for (int i = 2; i <= n; ++i)
		if (s[i] == '1') {
			now = i;
			printf("%d %d\n", now, lst);
			for (int j = lst + 1; j < now; ++j) printf("%d %d\n", now, j);
			lst = now;
		}
	printf("%d %d\n", n, n - 1);
	return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define DEBUG(x) cerr << #x << " = " << x << "\n"
#define UCIN ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int> pii;
typedef pair < ll, ll> pll;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef pair < double, double > pt;

const int N = 5e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int LOG = 18;
const int OFF = (1 << LOG);
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll fak[N],n,a,b,k,inv[N];

ll fastpot(ll x, ll y){
    ll cur = x, sol = 1;
    for(;y;y/=2){
        if(y&1) sol = cur * sol % MOD;
        cur = cur * cur % MOD;
    }
    return sol;
}

void precompute(){
    fak[0] = 1;
    inv[0] = 1;
    for(int i = 1;i<N;i++){
        fak[i] = i * fak[i - 1] % MOD;
        inv[i] = fastpot(fak[i], MOD - 2);
    }
}

ll choose(int n,int k){
    return fak[n] * inv[k] % MOD * inv[n - k] % MOD;

}

int main(){
    precompute();
    cin >> n >> a >> b >> k;
    ll sol = 0;
    for(int i = 0;i<=n;i++){
        ll x = i;
        ll y = (k - a * i) / b;
        if(a * x + b * y != k) continue;
        if(y > n || y < 0) continue;
        sol += choose(n, x) * choose(n, y) % MOD;
        sol %= MOD;
    }
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin >> n;
    if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n;
	cin >> n;
	vector<vector<int>> ho(n, vector<int>(n, -1));
	rep(i,n) {
		int a;
		cin >> a;
		rep(j,a){
			int x, y;
			cin >> x >> y;
			x--;
			ho[i][x] = y;
		}
	}
	int ans = 0;
	for(int bit = 0; bit < 1 << n; bit++){
		bool ok = true;
		vector<bool> honest(n, false);
		for(int i = 0; i < n; i++){
			if(1&bit>>i){
				honest[i] = true;
			}
		}
		for(int i = 0; i < n; i++){
			if(honest[i]){
				for(int j = 0; j < n; j++){
					if(i==j) continue;
					if(honest[j]&&ho[j][i]==0){
						ok = false;
					}
				}
			}else{
				for(int j = 0; j < n; j++) {
					if(i==j) continue;
					if(honest[j]&&ho[j][i]==1) {
						ok = false;
					}
				}
			}
		}
		if(ok) {
			int cnt = 0;
			rep(i,n) if(1&bit>>i) cnt++;
			chmax(ans, cnt);
		}
	}


	cout << ans << endl;
			
}

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

bool hav[60][60];
int n,k,z;
vector<int> v[50];

int main(){

	while(cin>>n&&n){

	for(int i=0;i<50;i++)v[i].clear();

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			hav[i][j]=0;
		}
		hav[i][i]=1;
	}

	for(int i=0;i<n;i++){
		cin>>k;
		while(k--){
			cin>>z;
			v[z-1].push_back(i);
		}
	}

	int ans=-1;

	for(int d=0;d<30;d++){

		for(int i=0;i<v[d].size();i++){
			for(int j=i+1;j<v[d].size();j++){

				for(int r=0;r<n;r++){

					bool t=max(hav[v[d][i]][r],hav[v[d][j]][r]);

					hav[v[d][i]][r]=t,hav[v[d][j]][r]=t;

				}

			}

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

			bool ok=true;

			for(int j=0;j<n;j++){
				if(!hav[i][j])ok=false;
			}

			if(ok){
				ans=d+1;
				goto loop;
			}
		}
	}
	loop:
	cout<<ans<<endl;
	}
	return 0;
}

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

const int MAX_N = 100005;

int main() {
  int N, a[MAX_N][3];
  int dp[MAX_N][3];
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i][j] = 0;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        dp[i + 1][k] = max(dp[i][j] + a[i][k], dp[i + 1][k]);
      }
    }
  }
  cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}


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

using namespace std;
using ll=long long;

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x; --x;
    }
    vector<vector<int>> g(n);
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<ll> res(n);
    vector<int> sz(n,1), cnt(n);
    auto calc = [&](ll x){
        return x*(x+1)/2;
    };
    function<void(int,int)> dfs = [&](int u, int p){
        int c = a[u];
        int sub = 0;
        for (int v: g[u])if(v!=p){
            int x = cnt[c];
            dfs(v, u);
            sz[u] += sz[v];
            x = cnt[c]-x;
            sub += x;
            res[c] += calc(sz[v] - x);
        }
        cnt[c] -= sub;
        cnt[c] += sz[u];
    };
    dfs(0,-1);
    for (int c = 0; c < n; c++) {
        res[c] += calc(n - cnt[c]);
    }
    const ll tot = calc(n);
    for (auto& x: res) {
        cout << tot-x << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 42944
import java.util.Scanner;

public class Main {
static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		double l = s.nextDouble();
		
		double k = l/3;
		double v = Math.pow(l/3,3);
		System.out.println(v);
	}

}
//36926037.000000000000

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

using namespace std;

int n;
int ans;

int main() {
	scanf("%d", &n);
	ans = (n / 500) * 1000;
	n %= 500;
	ans += (n / 5) * 5;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
ds = {}
for i in range(3):
    s = input()
    ks = [int(i) for i in s.split(' ')]
    for k in ks:
        if k in ds:
            ds[k] += 1
        else:
            ds[k] = 1


for k in ds:
    if ds[k] == 3:
        print('NO')
        exit()
print('YES')



Measured memory_bytes: 3060
#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 repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int N;
    string S;
    cin >> N >> S;
    if(S.size() % 2 == 1){ pr("No"); return 0;}
    string S1 = S.substr(0,sz(S)/2);
    string S2 = S.substr(sz(S)/2,sz(S)/2);
    if(S1==S2) pr("Yes");
    else pr("No");
}

Measured memory_bytes: 384