akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
		return b;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	int a, b;
	cin >>a >> b;
	if (a <= 5)
	{
		cout << "0";
	}
	else
	{
		if (a <= 12)
			cout << b / 2;
		else
			cout << b;
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 256
N = int(input())

a = list(map(int,input().split()))

ans = 0
sum = 0

for i in range(N):
    sum += a[i]

for i in range(N-1):
    sum -= a[i]
    ans += a[i]*sum

m = 10**9 + 7

ans = ans % m

print(ans)

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

vector<long long>vp;
void primeFactor(long long n)
{
    int C = 0;
    long long ans = 1;
    while(n%2 == 0)
    {
        ans *= 2;
        vp.push_back(ans);
        n /= 2;
    }

    for(long long i = 3; i*i <= n; i += 2)
    {
        if(n%i == 0)
        {
            int Count = 0;
            ans = 1;
            while(n%i == 0)
            {
                ans *= i;
                vp.push_back(ans);
                n /= i;
            }
        }
    }
    if(n > 2)
    {
        vp.push_back(n);
    }
}
int main()
{
    long long n; cin >> n;
    if(n == 1)
    {
        cout << "0" << endl;
        return 0;
    }
    primeFactor(n);
    long long Count = 0;
    sort(vp.begin(), vp.end());
    for(int i = 0; i < vp.size(); i++)
    {
        //cout << vp[i] << " ";
        if(n%vp[i] == 0)
        {
            n /= vp[i];
            Count++;
        }
    }
    cout << Count << endl;
    return 0;
}


Measured memory_bytes: 3648
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_H = 80;
int h, w;
int a[MAX_H][MAX_H];
int b[MAX_H][MAX_H];
const int BIAS = MAX_H * MAX_H * 2;
bool dp[MAX_H][MAX_H][2 * BIAS + 1];

bool ok(int i, int j) {
    return 0 <= i && i < h && 0 <= j && j < w;
}

int main() {
    fastio();

    cin >> h >> w;
    forn(i, h) forn(j, w) cin >> a[i][j];
    forn(i, h) forn(j, w) cin >> b[i][j];

    dp[0][0][a[0][0] - b[0][0] + BIAS] = dp[0][0][b[0][0] - a[0][0] + BIAS] = true;

    forn(i, h) forn(j, w) {
        int newi = i + 1, newj = j + 1;

        if (ok(newi, j)) {
            int d = a[newi][j] - b[newi][j];

            for (int k = 0; k <= 2 * BIAS; k++) {
                if (dp[i][j][k]) {
                    dp[newi][j][k + d] = true;
                    if (k >= d)
                        dp[newi][j][k - d] = true;
                }
            }
        }

        if (ok(i, newj)) {
            int d = a[i][newj] - b[i][newj];

            for (int k = 0; k <= 2 * BIAS; k++) {
                if (dp[i][j][k]) {
                    dp[i][newj][k + d] = true;
                    if (k >= d) {
                        dp[i][newj][k - d] = true;
                    }
                }
            }
        }
    }

    int ans = INT_MAX;
    for (int k = 0; k <= 2 * BIAS; k++) {
        if (dp[h - 1][w - 1][k])
            chmin(ans, abs(k - BIAS));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 159104
type dice = { one : int; two : int; three : int; four : int; five : int; six : int}

type direction = N | S | W | E

let move {one=a;two=b;three=c;four=d;five=e;six=f} = function
    N -> {one=b;two=f;three=c;four=d;five=a;six=e}
  | S -> {one=e;two=a;three=c;four=d;five=f;six=b}
  | W -> {one=c;two=b;three=f;four=a;five=e;six=d}
  | E -> {one=d;two=b;three=a;four=f;five=e;six=c}

let rec turn_right d = function
  | 0 -> d
  | i -> let {one=a;two=b;three=c;four=d;five=e;six=f} = d in
    turn_right {one=a;two=c;three=e;four=b;five=d;six=f} (i-1)

let all_pattern d = 
  List.map
    (fun l -> List.fold_left (fun dice direc -> move dice direc) d l)
    [[];[S];[W];[N];[E];[S;S]]
  |> List.fold_left (fun acc d -> List.map
                        (fun t -> turn_right d t)
                        [0;1;2;3] |> (@) acc) []
let is_same d1 d2 =
  all_pattern d2 |> List.filter (fun x -> x=d1) |> function [] -> false | _ -> true
    
let () =
  let read_dice n =
    let rec loop ds = function
        0 -> ds
      | i ->
        let d = Scanf.scanf "%d %d %d %d %d %d\n"
            (fun a b c d e f -> {one=a;two=b;three=c;four=d;five=e;six=f}) in
        loop (d::ds) (i-1)
    in loop [] n in
  let list_of_dice = read_dice (read_int ()) in
  let rec check = function
      [] | [_] -> "Yes"
    | hd::tl ->
      match List.filter (is_same hd) tl with
        [] -> check tl
      | _ -> "No"
  in
  print_endline (check list_of_dice)

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, P;
  cin >> N >> P;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  // 奇数があるかどうか
  bool odd = false;
  for (int i = 0; i < N; i++) {
    if (a[i] & 1) odd = true;
  }

  ll ans;
  if (odd) {
    ans = pow(2, N - 1);
  } else {
    ans = (P ? 0 : pow(2, N));
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int l,i,c=0;
  char s[100010];
  scanf("%s",s);
  for(l=0;s[l];l++);
  for(i=0;i*2<l;i++){
    if(s[i]!=s[l-i-1])c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int cnt[10]={0,2,5,5,4,5,6,3,7,6};
bool can[10];
int dp[10002];
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  while(m--){
    int x;
    scanf("%d",&x);
    can[x]=1;
    for(int i=cnt[x];i<=n;i++)
      dp[i]=max(dp[i],dp[i-cnt[x]]+1);
  }
  int now=n;
  while(now){
    for(int i=9;i;i--)
      if (can[i] && now>=cnt[i] && dp[now-cnt[i]]==dp[now]-1){
        putchar(i+'0'),now-=cnt[i];
        break;
      }
  }
}

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


int main() {

	int count = 0, count_max = 0;
	int tmp;
	int i;

	int N, A, B;
	int sum_dig;
	int sum = 0;
	

	cin >> N;
	cin >> A;
	cin >> B;


	for ( i = 1; i <= N; i++)
	{
		tmp = i;
		sum_dig = 0;
		while (tmp > 0)
		{
			sum_dig += tmp % 10;
			tmp /= 10;
		}
		
		if (sum_dig >= A && sum_dig <= B)
		{
			sum += i;
		}
		
	}
	
		
	cout << sum << endl;
		
	
	
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 334;
const ll INF = LLONG_MAX/3;

int n,a[N],s[N];

ll f(ll x, ll y){
    int c = 0;
    ll ret = 0;
    while(x>0 || y>0 || c>0){
        int xx = x%10, yy = y%10;
        ret += xx*yy + c;

        x /= 10;
        y /= 10;
        c = (xx+yy+c>=10);
    }
    return ret;
}

ll dp[N][N];
ll dfs(int l, int r){
    if(dp[l][r]>=0) return dp[l][r];
    if(r-l == 1) return 0;

    ll ret = INF;
    for(int i=l+1; i<r; ++i){
        ll X = s[i]-s[l];
        ll Y = s[r]-s[i];
        ret = min(ret, dfs(l,i)+dfs(i,r)+f(X,Y));
    }
    return dp[l][r] = ret;
}

int main(){
    scanf(" %d", &n);
    rep(i,n) scanf(" %d", &a[i]);

    rep(i,n) s[i+1] += s[i]+a[i];
    memset(dp, -1, sizeof(dp));
    printf("%lld\n", dfs(0,n));
    return 0;
}



Measured memory_bytes: 4116
from collections import deque


def solve():
    N = int(input())
    q = deque([1,2,3,4,5,6,7,8,9])
    cnt = 0
    l = []
    used = set()

    while cnt<N:
        p = q.popleft()
        if p in used:continue
        used.add(p)
        l.append(p)
        cnt += 1
        for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
            q.append(10*p+i)

    print(l[N-1])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 20972
#include<iostream>
#include<cstdio>
	using namespace std;
int main()
{
	int a=0,n=0,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a),ans+=a-1; 
	printf("%d",ans);
	return 0;
} 

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

using namespace std;
#define int long long
const int MOD = 1000000007;
int modpow(int a, int p) {
	if (p == 0) return 1;
	int res = modpow(a, p / 2);
	res = (res * res) % MOD;
	if (p & 1) res = (res * a) % MOD;
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<vector<int> > X(K + 1);
	for (int i = 1; i <= K; i++) {
		for (int j = i + i; j <= K; j += i) {
			X[j].push_back(i);
		}
	}
	int res = 0;
	vector<int> A(K + 1);
	for (int i = K; i > 0; i--) {
		int x = modpow(K / i, N);
		A[i] = (A[i] + x) % MOD;
		res = (res + A[i] * i) % MOD;
		for (int &j : X[i]) {
			A[j] = (A[j] + MOD - A[i]) % MOD;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 20092
m_num = 1
m_count = 0
for i in range(1, int(input()) + 1):
    count = 0
    tmp = i
    while tmp % 2 == 0:
        tmp //= 2
        count += 1
    if m_count < count:
        m_num = i
        m_count = count
print(m_num)


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

typedef std::pair<double, double> vertex;
typedef std::pair<vertex, vertex> two_vertices;

constexpr vertex operator*(double f, const vertex& v) {
    return {f*v.first, f*v.second};
}
constexpr vertex operator/(const vertex& v, double f) {
    return {v.first/f, v.second/f};
}
constexpr vertex operator+(const vertex& v1, const vertex& v2) {
    return {v1.first+v2.first, v1.second+v2.second};
}

double absv(two_vertices t) {
    return std::sqrt(std::pow(t.first.first - t.second.first, 2)+std::pow(t.first.second - t.second.second, 2));
}

std::vector<vertex> koch(two_vertices t) {
    auto v1 = (2.0*t.first + t.second)/3.0;
    auto v3 = (t.first + 2.0*t.second)/3.0;
    double abs = absv({v1, v3});
    double atan = std::atan2(v3.second-v1.second, v3.first-v1.first);
    auto v2 = v1 + vertex(abs*std::cos(atan+M_PI/3.0), abs*std::sin(atan+M_PI/3.0));
    return {v1, v2, v3};
}

std::vector<vertex> koch_n(std::vector<vertex> t, int ttl) {
    if (ttl==0) {
        return t;
    }
    std::vector<vertex> ret;
    for (int i=0; i<t.size()-1; i++) {
        ret.push_back(t[i]);
        auto newv = koch({t[i], t[i+1]});
        ret.push_back(newv[0]);
        ret.push_back(newv[1]);
        ret.push_back(newv[2]);
    }
    ret.push_back(t[t.size()-1]);
    if (--ttl > 0) {
        return koch_n(ret, ttl);
    } else {
        return ret;
    }
}

int main() {
    int n;
    std::cin >> n;

    auto v=koch_n({{0,0}, {100,0}}, n);
    for (int i=0; i<v.size(); i++) {
        std::cout << std::fixed << std::setprecision(8) << v[i].first << " " << v[i].second << std::endl;
    }

    return 0;
}


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

int main() {
	int a , b;
	cin  >> a >> b ;
	if (a < b){
	cout << "a < b" << endl;
	}
	if (a > b){
	cout << "a > b" << endl;
	}
	if (a == b){
	cout <<"a == b" << endl;
	}
	return 0;
}


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

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

        int N = Integer.parseInt(sc.next());
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        boolean result = true;
        for (int i = N - 2; i >= 0; i--) {
            if (H[i] <= H[i + 1]) {
                continue;
            }
            if (H[i] - 1 == H[i + 1]) {
                H[i]--;
            } else {
                result = false;
                break;
            }
        }

        if (result) {
            out.printf("Yes\n");
        } else {
            out.printf("No\n");
        }
        out.flush();
    }
}


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

int main()
{
    std::string S, T, U;
    int A, B;

    std::cin >> S >> T;
    std::cin >> A >> B;
    std::cin >> U;

    if (U == S)
        A--;
    if (U == T)
        B--;

    std::cout << A << " " << B << std::endl;

    return 0;
}

Measured memory_bytes: 256
MAX = 1000001

class Query:
    def __init__(self, l, r, idx): 
        self.l = l 
        self.r = r 
        self.idx = idx 
  
class BIT:
    def __init__(self,n):
        self.n = n
        self.tree = [0]*(n+1)

    def sum(self,x):
        sum = 0
        while(x>0):
            sum+=self.tree[x]
            x-=x&(-x)
        return sum

    def update(self,x,k):
        while(x<=self.n):
            self.tree[x]+=k
            x+=x&(-x)

    def build(self,a):
        for i in range(len(a)):
            k = a[i]
            x = i+1
            while(x<=self.n):
                self.tree[x]+=k
                x+=x&(-x)
  
def answeringQueries(arr, n, queries, q): 
  
    # initialising bit array 
    bit = BIT(n)
  
    # holds the rightmost index of  
    # any number as numbers of a[i] 
    # are less than or equal to 10^6 
    last_visit = [-1] * MAX
  
    # answer for each query 
    ans = [0] * q 
  
    query_counter = 0
    for i in range(n): 
  
        # If last visit is not -1 update -1 at the 
        # idx equal to last_visit[arr[i]] 
        if last_visit[arr[i]] != -1: 
            bit.update(last_visit[arr[i]] + 1, -1)
  
        # Setting last_visit[arr[i]] as i and  
        # updating the bit array accordingly 
        last_visit[arr[i]] = i 
        bit.update(i + 1, 1)
  
        # If i is equal to r of any query store answer 
        # for that query in ans[] 
        while query_counter < q and queries[query_counter].r == i: 
            ans[queries[query_counter].idx] = bit.sum(queries[query_counter].r + 1) -bit.sum(queries[query_counter].l)
            query_counter += 1
  
    # print answer for each query 
    for i in range(q): 
        print(ans[i]) 
  
# Driver Code 
if __name__ == "__main__": 
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    # n = len(a)
    queries = []
    for i in range(q):
        l,r = map(int,input().split())
        queries.append(Query(l-1,r-1,i))
    # queries = [Query(0, 4, 0),
    #            Query(1, 3, 1),
    #            Query(2, 4, 2)]
    # q = len(queries)
  
    queries.sort(key = lambda x: x.r) 
    answeringQueries(a, n, queries, q)


Measured memory_bytes: 243852
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T : FromStr>() -> T {
  let token: String = stdin().lock()
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parse")
}

#[allow(dead_code)]
fn read2<T : std::str::FromStr>() -> (T, T) {
  (read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn read3<T : std::str::FromStr>() -> (T, T, T) {
  (read::<T>(), read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn reads<T : std::str::FromStr>() -> Vec<T> {
  let mut line = String::new();
  stdin().read_line(&mut line).ok();
  line.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let k : usize = read();
  let res = "ACL".repeat(k);

  println!("{}", res);
}

Measured memory_bytes: 2072
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight=0) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  REP(u, L) if (matchTo[u] >= 0) // make explicit matching
    matching.push_back( Edge(u, matchTo[u]) );
  return match;
}

int n,a,b;
bool sat(int x){
  x=abs(x);
  return x<=a||(b<=x&&x<=2*a);
}

int main(){
  cin>>n>>a>>b;
  vi c(n);
  rep(i,n){
    int x,y;
    cin>>x>>y;
    c[i]=x-y;
  }
  int ans=0;
  vi neg,pos;
  rep(i,n){
    if(sat(c[i]))
      ans++;
    else{
      if(c[i]<0)neg.push_back(c[i]);
      else pos.push_back(c[i]);
    }
  }
  Graph g(neg.size()+pos.size());
  rep(i,neg.size()){
    rep(j,pos.size()){
      if(sat(neg[i]+pos[j])){
	g[i].push_back(Edge(i,neg.size()+j));
      }
    }
  }
  Edges e;
  cout<<ans+bipartiteMatching(g,neg.size(),e)<<endl;
      
}



Measured memory_bytes: 3668
# after reading explanation
n, m = gets.split.map(&:to_i)
ac = Array.new(n,false)
pe = Array.new(n,0)
m.times{
  pi, si = gets.split
  pi = pi.to_i - 1
  pe[pi] += 1 if si == "WA" && (!ac[pi])
  ac[pi] = true if si == "AC"
}
n.times{|i| pe[i]=0 unless ac[i] }
accept = ac.count(true)
penalty = pe.inject(:+)
puts [accept, penalty].join(" ")

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  string s;
  cin>>s;
  int ans=0;
  int n=s.size();
 
  bool ok1=true;
  for(int i=0;i<n;i++){
     if(s[i]!=s[n-1-i]){
       ok1=false;
     }
   }
  bool ok2=true;
  int k=(n-1)/2;
  for(int i=0;i<k;i++){
     if(s[i]!=s[k-1-i]){
       ok2=false;
     }
   }  
  bool ok3=true;
  int d=(n+3)/2;
  for(int i=d-1;i<n-1;i++){
     if(s[i]!=s[n-1-i]){
       ok2=false;
     }
   }
   
  if(ok1&&ok2&&ok3){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

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

struct Creature {
    int color;
    long long size;
    bool operator<(const Creature& r) const {
        return size < r.size;
    }
};

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

    vector<Creature> vs;
    for (int i=0; i<N; i++) {
        long long a;
        cin >> a;
        vs.push_back( Creature{i, a} );
    }

    sort(vs.begin(), vs.end());
    
    long long sz = vs[0].size;
    int ans = 1;
    for (int i=1; i<N; i++) {
        if (2*sz >= vs[i].size) { // 継続して食べられる
            sz += vs[i].size;
            ans++;
        } else { // 継続して食べられないので、i番目の生き物が逆に食べる
            sz += vs[i].size; 
            ans = 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define INF 2e9
using namespace std;
const int N=1e6+1;
const int mod=1e9+7;
ll fastexp(ll base,ll exp){
	base%=mod;
	ll ans=1;
	while(exp>0){
		if(exp&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		exp/=2;
	}
	return ans;
}
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int sumofdigits(int n){
	int sum = 0;
	while(n!=0){
		sum += n%10;
		n = n/10;
	}
	return sum;
}
int arr[N];
int ar[N];
int main() {
		string s;
		cin >> s;
		char p = s[0];
		char q = s[1];
		char r = s[2];
		if(p == 'R' && q == 'R' && r == 'R'){
			cout << "3" << endl;
		}
		else if ((p == 'R' && q == 'R') || (q == 'R' && r == 'R')){
			cout << "2" << endl;
		}
		else if(p != 'R' && q != 'R' && r != 'R'){
			cout << "0" << endl;
		}
		else {
			cout << "1" << endl;
		}
		return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n+1];
  int ans = 0;
  for(int i = 1;i<=n;i++)cin >> a[i];
  
  for(int i = 1;i<=n-1;i++)
    for(int j = i+1;j<=n;j++){
      ans+=a[i]*a[j];
      
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include    <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a,b)  for(int i=a;i<b;++i)
#define fore(i,a)  for(__typeof(a.begin()) i=a.begin();i!=a.end();++i)
#define __unique(V) V.resize(unique(V.begin(),V.end())-V.begin())
#define cntbit(X)   __builtin_popcount(X)
#define fi  first
#define se  second
#define LL  long long
#define ii  pair<int,int>
#define iii pair<int,ii>
#define TASK "sevens"
using   namespace   std;
int F[65][65][2],m,a[10],b[10],n;
bool ok[15];
///--------------------------
void    readf(){
    memset(ok,0,sizeof(ok));
    ok[7]=1;
    fo(i,1,6) cin>>a[i],ok[a[i]]=1;
    m=0;
    fo(i,1,13) if (!ok[i]) b[++m]=i;
}
///--------------------------
inline void on(int &X,int i) {X=(X|(1<<(i-1)));}
inline int bit(int X,int i) {return ((X>>(i-1))&1);}
///--------------------------
bool    dp(int mask1,int mask2,int id){
    if (F[mask1][mask2][id]!=-1) return F[mask1][mask2][id];
    bool rs=&F[mask1][mask2][id];
    if (mask1==0 && id==0) return (rs=1);
    if (mask2==0 && id==1) return (rs=1);
    int tmp=0;
    on(tmp,7);
    fo(i,1,6) if (!bit(mask1,i)) on(tmp,a[i]);
    fo(i,1,6) if (!bit(mask2,i)) on(tmp,b[i]);
    rs=0;
    if (id==0){
        int yes=0;
        fo(i,1,6) if (bit(mask1,i) &&
            ((a[i]>1 && bit(tmp,a[i]-1)) || bit(tmp,a[i]+1))){
            rs|=(!dp(mask1&(~(1<<(i-1))),mask2,1));
            yes=1;
        }
        if (yes==0) rs|=(!dp(mask1,mask2,1));
        return rs;
    }else {
        int yes=0;
        fo(i,1,6) if (bit(mask2,i) &&
            ((b[i]>1 && bit(tmp,b[i]-1)) || bit(tmp,b[i]+1))){
            rs|=(!dp(mask1,mask2&(~(1<<(i-1))),0));
            yes=1;
        }
        if (yes==0) rs|=(!dp(mask1,mask2,0));
        return rs;
    }
}
///--------------------------
void    solve(){
    memset(F,-1,sizeof(F));
    cout<<(dp(63,63,0) ? "yes\n" : "no\n");
}
///--------------------------
int     main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    while (n--){
        readf();
        solve();
    }
}







Measured memory_bytes: 3252
x,k,d = map(int,input().split())
sho =  abs(x)//d
amari = abs(x)%d
tmp = []
tmp.append([sho,abs(amari)])
tmp.append([sho+1,abs(amari-d)])
#print(tmp)
#print(sho,amari,amari-d)
if k>=sho:
    if (k-sho)%2==0:
        print(tmp[0][1])
    else:
        print(tmp[1][1])
else:
    print(abs(x)-k*d)


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
 
    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i];
    }
 
    int ans = 0;
 
    for(int i = 0; i < n; ++i){
        if(v[i] > c[i])ans += v[i]-c[i];
    }
 
    cout << ans << endl;
 
 
}

Measured memory_bytes: 256
import numba
from numba import njit, i8
import sys
import numpy as np
read = sys.stdin.readline


@njit((i8, i8[:], i8[:]), cache=True)
def main(n, a, b):
    ans = 0
    for i in range(n):
        d = min(a[i], b[i])
        ans += d
        b[i] -= d
        e = min(a[i + 1], b[i])
        ans += e
        a[i + 1] -= e
    print(ans)


if __name__ == '__main__':
    n = int(input())
    a = np.fromstring(read(), dtype=np.int64, sep=' ')
    b = np.fromstring(read(), dtype=np.int64, sep=' ')
    main(n, a, b)


Measured memory_bytes: 109120
n = int(input())
f_list = []
for i in range(n):
  f_list.append(list(map(int,input().split())))
p_list = []
for i in range(n):
  p_list.append(list(map(int,input().split())))

all_cand = []
for i in range(2**10):
  p_m_list = [False for i in range(10)]
  for j in range(10):
    if ((i >>j) & 1):
      p_m_list[j] = True
  all_cand.append(p_m_list)
all_cand.pop(0)
result_list = []

for cand in all_cand:
  result = 0
  for j in range(n):
    c = 0
    for i in range(10):
      if cand[i] == True and f_list[j][i] == 1:
        c += 1
    result += p_list[j][c]
  result_list.append(result)
  
print(max(result_list))
      

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, Z, W;
    cin >> N >> Z >> W;
    int A[N];
    rep(i,N) cin >> A[i];
    int X[N]{}, Y[N]{};
    for(int i=N-2;i>=0;i--){
        X[i] = abs(A[i]-A[N-1]);
        for(int j=i+1;j<=N-2;j++){
            chmin(X[i], Y[j]);
        }
        Y[i] = abs(A[i]-A[N-1]);
        for(int j=i+1;j<=N-2;j++){
            chmax(Y[i], X[j]);
        }
    }
    int ans = abs(A[N-1] - W);
    rep(i,N-1){
        chmax(ans, X[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;


int main(void) {
  string S;
  while(cin >> S, S != "#") {
    int H = 0, W = 0, m[10][10];
    REP(i, 0, S.length()) {
      char c = S[i];
      if(c == '/') {
        H++;
        W = 0;
      } else if('0' <= c && c <= '9') {
        REP(j, 0, c - '0') {
          m[H][W++] = 0;
        }
      } else if(c == 'b') {
        m[H][W++] = 1;
      }
    }
    H++;

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    m[a - 1][b - 1] = 0;
    m[c - 1][d - 1] = 1;

    string ans = "";
    REP(i, 0, H) {
      REP(j, 0, W) {
        if(m[i][j] == 0) {
          int cnt = 1;
          while(j + 1 < W && m[i][j + 1] == 0) {
            cnt++;
            j++;
          }
          ans += ('0' + cnt);
        } else {
          ans += 'b';
        }
      }
      if(i + 1 != H) {
        ans += '/';
      }
    }

    cout << ans << endl;
  }
}

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

string s;
long int n, cnt = 0, clc = 0, answ = 0;
int main() {
	cin >> s;
	n = s.length();
	for (int i = 0; i < n; i++){
		if (s[i] == 'A'){
			cnt = i;
			break;
		}
	}
	for (int i = n; n >= 0; i--){
		if (s[i] == 'Z'){
			clc = i;
			break;
		}
	}
	answ = clc - cnt + 1;
	cout << answ << endl;
	return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if cnt==0:
        n=n-k
        cnt+=1
        
    else:
        n=n-(k-1)
        cnt+=1
        
    if n<=0:
        break
print(cnt)

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

ll N, A, B;

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

    ll div = N / (A+B);
    ll mod = N % (A+B);

    ll ans = A * div;
    if (A < mod) ans += A;
    else ans += mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int>v(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < min(n, k); i++) {
		sum += v[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
int mod = 1e9 + 7;

int main() {
	ll n;
	cin >> n;
	ll ans = 1;
	for (ll i = 1; i <= n; ++i) {
		ans = ((ans % mod)  * (i % mod)) % mod; 
	}
    cout << ans;
}



















Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        int l = scan.nextInt() + scan.nextInt();
        int r = scan.nextInt() + scan.nextInt();

        if(l>r) System.out.println("Left");
        else if(l<r) System.out.println("Right");
        else System.out.println("Balanced");
        
        scan.close();
        
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

using PII = pair<int, int>;
using VII = vector<PII>;
using VI = vector<int>;

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

  int pt = 0, px = 0, py = 0;
  bool ok = true;
  rep(i, N) {
    int t, x ,y;
    int dt, dx, dy;

    cin >> t >> x >> y;
    dt = t - pt;
    dx = abs(x - px);
    dy = abs(y - py);

    int s = dt + dx + dy;

    if (s % 2 != 0 || s / 2 > dt) ok = false;
  }

  cout << (ok ? "Yes": "No") << endl;

  return 0;
}


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

#define ll long long int
#define all(x) x.begin(), x.end()

ll sum, n;
vector<ll> values;
vector<vector<ll>> dp;

ll recur(int left, int right) {
    // returns the max diff (the current player is more)
    if (left == right) return values[left];
    else if (dp[left][right] != -1) 
        return dp[left][right];
    return dp[left][right] = max(values[left]-recur(left+1, right), values[right]-recur(left, right-1));
}

int main() {
    cin >> n;
    values = vector<ll> (n);
    dp = vector<vector<ll>> (n, vector<ll>(n, -1));

    for (auto &value: values)
        cin >> value;

    sum = accumulate(all(values), 0LL);
    // Taro tries to maximize X − Y , while Jiro tries to minimize X − Y
    // Taro starts the game

    cout << recur(0, n-1) << '\n';

    return 0;
}


Measured memory_bytes: 70912
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
int b[10][10];

void set_(int x, int y){
  if(x >= 0 && x < 10 && y >= 0 && y < 10)b[x][y] += 1;
}

int main(int argc, char const* argv[])
{
  string ss;
  while(cin >> ss){
    int x = -1, y = -1, s;
    string tmp = "";
    rep(i, ss.size()){
      if(ss[i] != ',')tmp += ss[i];
      else{
        if(x == -1)x = stoi(tmp);
        else y = stoi(tmp);
        tmp = "";
      }
    }
    s = stoi(tmp);
    if(s == 1){
      set_(x, y-1);
      set_(x-1, y); set_(x, y); set_(x+1, y);
      set_(x, y+1);
    }else if(s == 2){
      rep(i, 3){
        rep(j, 3){
          set_(x + i - 1, y + j - 1);
        }
      }
    }else{
      set_(x, y - 2);
      set_(x, y + 2);
      set_(x - 2, y);
      set_(x + 2, y);
      rep(i, 3){
        rep(j, 3){
          set_(x + i - 1, y + j - 1);
        }
      }
    }
  }
  int res = 0;
  int maxi = 0;
  rep(i, 10){
    rep(j, 10){
      if(b[i][j] == 0)res++;
      maxi = max(maxi, b[i][j]);
    }
  }
  cout << res << endl;
  cout << maxi << endl;
	return 0;
}



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum[600][600],pos,q,l[ohara],r[ohara],ma[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>m>>q;
      //pair<ll,ll> p[ohara];
      map<ll,ll> kazu;
      map<pair<ll,ll>,ll> mp;
      rep(i,m){
        cin>>a>>b;
        if(ma[a]<=b)ma[a]=b;
        kazu[a]++;
        sum[a][b]++;
       // l[i]=make_pair(a,b);
        mp[{a,b}]++;
      }
      rep(i,n){
        rep(j,n){
          sum[i][j+2]+=sum[i][j+1];
        }
      }
     // rep(j,n)cout<<sum[2][j+1]<<" ";

      //sort(p,p+m);
      rep(i,q){
        cin>>a>>b;
        cnt=0;
        rrep(j,a,n+1){
          if(ma[j]<=b){ans+=kazu[j];}
          else{
            //Cout("b");
            
           cnt=sum[j][n]-sum[j][b];
            /*
            if(cnt==0){
              cout<<j<<"\n";
              cout<<"-------";
              rep(kk,n)cout<<sum[j][kk+1];
              cout<<"----------";
            }
            */
            
            ans+=max(kazu[j]-cnt,0LL);
          }
         // Cout(ans);
        }
        Cout(ans);
        ans=0;
      }
  //Cout(ma[2]);
     

       
return 0;
}


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

using namespace std;

int main()
{
    int n, i, j, a, b, l, sum = 0;

    cin >> n;

    vector < int > v(n);

    for(i=0; i<n; i++) cin >> v[i];

    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            sum += v[i]*v[j];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;

const int INF = 1 << 30;

/* typedef */

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

struct Stat {
  int d, i, mm;
  Stat() {}
  Stat(int _d, int _i, int _mm) : d(_d), i(_i), mm(_mm) {}

  bool operator<(const Stat& st0) const { return d > st0.d; }

  void print() {
    printf("Stat: d=%d, i=%d, mm=%d\n", d, i, mm);
  }
};

/* global variables */

int n, m, l, k, a, h;
vpii nbrs[MAX_N];
int dists[MAX_N][MAX_M + 1];
bool frdgs[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m >> l >> k >> a >> h;
    if (n == 0) break;
    //printf("n=%d, m=%d, l=%d, k=%d, a=%d, h=%d\n", n, m, l, k, a, h);
    
    for (int i = 0; i < n; i++) {
      frdgs[i] = false;
      nbrs[i].clear();
      for (int j = 0; j <= m; j++) dists[i][j] = INF;
    }
    //frdgs[a] = frdgs[h] = true;
    
    for (int j = 0; j < l; j++) {
      int i;
      cin >> i;
      frdgs[i] = true;
    }
    
    for (int i = 0; i < k; i++) {
      int x, y, t;
      cin >> x >> y >> t;
      nbrs[x].push_back(pii(y, t));
      nbrs[y].push_back(pii(x, t));
    }
    
    priority_queue<Stat> q;
    q.push(Stat(0, a, m));
    dists[a][m] = 0;
    
    while (! q.empty()) {
      Stat u = q.top();
      q.pop();
      //u.print();

      if (u.d != dists[u.i][u.mm] || u.i == h) continue;

      vpii& nbru = nbrs[u.i];
      int max_w = frdgs[u.i] ? m - u.mm : 0;

      for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int vi = vit->first;
	int vc = vit->second;

	for (int w = 0; w <= max_w; w++) {
	  int vd = u.d + vc + w;
	  int vmm = u.mm - vc + w;
	  if (vmm >= 0 && dists[vi][vmm] > vd) {
	    dists[vi][vmm] = vd;
	    q.push(Stat(vd, vi, vmm));
	  }
	}
      }
    }

    int mind = INF;
    for (int j = 0; j <= m; j++)
      if (mind > dists[h][j]) mind = dists[h][j];
    
    if (mind >= INF)
      cout << "Help!" << endl;
    else
      cout << mind << endl;
  }

  return 0;
}

Measured memory_bytes: 1572
#include <bits/stdc++.h>
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

map <int, vector < pair <ll, ll> > > wxw;
vector < pair <ll, ll> > tmp;
int n, x, d;
ll ans;

ll s(int x) { return 1ll * x * (x + 1) / 2; }

int main() {
    read(n); read(x); read(d);
    if(d == 0) {
        if(x == 0) {
            cout << 1 << endl;
        } else {
            cout << n + 1 << endl;
        }
        return 0;
    }
    if(d < 0) x = -x, d = -d;
    for(register int i = 0; i <= n; i++) wxw[(1ll * x * i % d + d) % d].push_back(make_pair((1ll * x * i - (1ll * x * i % d + d) % d) / d + s(i - 1), (1ll * x * i - (1ll * x * i % d + d) % d) / d + s(n - 1) - s(n - i - 1)));
    for(auto it : wxw) {
        tmp = it.second;
        sort(tmp.begin(), tmp.end());
        ll l = tmp[0].first, r = tmp[0].second;
        for(register int i = 1; i < (int)tmp.size(); i++) {
            if(tmp[i].first > r) {
                ans += r - l + 1;
                l = tmp[i].first; r = tmp[i].second;
            } else r = max(r, tmp[i].second);
        }
        ans += r - l + 1;
    }
    print(ans, '\n');
    return 0;
}

Measured memory_bytes: 22144
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

template<typename T>
constexpr T Abs(T a) {
  return a > 0 ? a : -a;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> h(N);
  F0R(i, N) {
    cin >> h[i];
  }

  vector<int> dp(N + 1);
  dp[0] = 0;
  dp[1] = Abs(h[1] - h[0]);
  FOR(i, 2, N) {
    dp[i] = min(dp[i - 2] + Abs(h[i] - h[i - 2]), dp[i - 1] + Abs(h[i] - h[i - 1]));
  }
  cout << dp[N - 1];
}
#endif


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int factorial(int k);

int main(){
	int N, a, b;
	cin >> N;
	int P[N], Q[N];
	for(int i = 0; i < N; i++){
		cin >> P[i];
	}
	for(int i = 0; i < N; i++){
		cin >> Q[i];
	}
	a = 1;
	b = 1;
	for(int i = 0; i < N; i++){
		a += (P[i]-1)*factorial(N-1-i);
		for(int j = i+1; j < N; j++){
			if(P[j] > P[i]){
				P[j]--;
			}
		}
	}
	for(int i = 0; i < N; i++){
		b += (Q[i]-1)*factorial(N-1-i);
		for(int j = i+1; j < N; j++){
			if(Q[j] > Q[i]){
				Q[j]--;
			}
		}
	}
	if(a < b){
		cout << b-a;
	}else{
		cout << a-b;
	}
	return 0;
}


int factorial(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

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

int main() {
  ll n,k; cin>>n>>k;
  vector<pll> v(1+100000);
  rep(i,100001){
    v[i].first=i;
    v[i].second=0;
  }
  rep(i,n){
    int a,b; cin>>a>>b;
    v[a].second+=b;
  }
  ll sum=0,i=0;
  while(true){
    sum+=v[i].second;
    if(sum>=k){cout<<v[i].first;break;}
    i++;
  }
}



Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    int x, n; cin >> x >> n;
    set<int> p;
    fo(i, n) {
        int pi; cin >> pi;
        p.insert(pi);
    }
    if (!p.count(x)) {
        cout << x;
        return;
    }
    int diff = 1;
    while (1) {
        if (!p.count(x-diff)){
            cout <<x-diff;
            return;
        }
        if (!p.count(x+diff)) {
            cout << x+diff; 
            return;
        }
        diff++;
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3580
n, m, x = map(int, input().split())
C = []
A = []
ans = float("inf")
for _ in range(n):
    tmp = list(map(int, input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

for i in range(2**n):
    now = [0] * m
    ns = 0

    for j in range(n):
        if i&(1<<j):
            ns += C[j]

            for k in range(m):
                now[k] += A[j][k]

    if min(now) >= x:
        ans = min(ans, ns)

if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 73340
import java.util.Scanner;

public class Main {
	static final int Big_Num = 1000000000;
	static long mul(int n,int h) {
		int ans = n;
		if(h==0)
			return 1;
		if(h==1)
			return ans;
		for(int i=0;i<h-1;i++) {
			ans *= n;
		}
		return ans;
	}
	
	static long f(String str,int n) {
		
		int[] an = new int[str.length()];
		int k = 0;
		for(int i=0;i<str.length();i++) {
			char s = str.charAt(i);
			if(Character.isDigit(s)) {
				an[k] = Integer.parseInt(String.valueOf(s));
				k++;
			}
		}
		
		long ans = 0;
		int kk = 0;
		for(int aa:an) {
			ans += mul(n,aa);
			kk++;
			if(kk==k)break;
		}
		return ans;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
			int n = sc.nextInt();
			int t = sc.nextInt();
			String str = sc.next();
			
			long ans = f(str,n);
			if(ans*t <= Big_Num && ans > 0) 
				System.out.println(ans*t);
			else
				System.out.println("TLE");
	}
}


Measured memory_bytes: 26360
import heapq
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[]
for i in range(n):
    heapq.heappush(B,-A[i])
for j in range(m):
    x=heapq.heappop(B)
    if x//2==0:
        heapq.heappush(B,x//2)
    else:
        heapq.heappush(B,(x+1)//2)
print(-sum(B))

Measured memory_bytes: 64792
import numpy as np
import sys

N = int(input())
ls = [list(map(int,input().split())) for i in range(N)]
ls = np.array(ls)
ls = ls[ls[:,0].argsort(), :]
ls = ls[ls[:,1].argsort(), :]
# print(ls)
k=ls[0,0]
if ls[0,0]>ls[0,1]:
  print('No')
  sys.exit()
for i in range(1,N):
  k += ls[i,0]
  if k > ls[i,1]:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 62500
N, M, X = map(int, input().split())
CAAA = [input().split() for i in range(N)]

ans = 1000000000
for k in range(1, 2**N):
  price = 0
  rikaido=[0]*M
  for l in range(N):
    if k>>l & 1:
      #if CAAA[m][1] < price:
      price += int(CAAA[l][0])
      for t in range(M):
        rikaido[t] += int(CAAA[l][t+1])
        for r in rikaido:
          if r < X:
            break
        else:
          ans = min(ans, price)
if ans == 1000000000:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 9112
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

s = input()

tmp = 0
res = "ABC"

if s == "ABC":
    res = "ARC"

print(res)


Measured memory_bytes: 30900