akhauriyash/Code-Regression huggingface dataset:
n = input()
A = [int(raw_input()) for i in xrange(n)]
rest = 0
bits = [0]*32
rbits = [0]*32
for i in xrange(n):
    comm = A[i] & (A[i] - 1)
    rest ^= comm
    bit = (A[i] - comm).bit_length()
    bits[bit] += 1
for i in xrange(32):
    if (rest >> i) & 1:
        rbits[i+1] = 1
ans = 0
for i in xrange(31):
    if rbits[31-i] and not bits[31-i]:
        print -1
        exit(0)
    if (bits[31-i]&1 and not rbits[31-i]) or (bits[31-i]&1==0 and rbits[31-i]):
        ans += 1
        for j in xrange(i, 31):
            rbits[31-j] ^= 1
su = 0
for i in xrange(31):
    su += ((bits[31-i]&1)^rbits[31-i])
print -1 if su else ans


Measured memory_bytes: 5892
n, x, m = map(int, input().split())
X = [-1] * m
P = []
sum_p = 0
while X[x] == -1: # preset
    X[x] = len(P) # pre length
    P.append(sum_p) # pre sum_p
    sum_p += x # now sum_p
    x = x*x % m
P.append(sum_p) # full sum_p

p_len = len(P) - 1
if n <= p_len:
    print(P[n]) # sum_p
    exit()

cyc_times, nxt_len = divmod(n - X[x], p_len - X[x])
cyc = (sum_p - P[X[x]]) * cyc_times
remain = P[X[x] + nxt_len]
print(cyc + remain)


Measured memory_bytes: 13844
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	if(n >= 1000) cout << "ABD\n";
	else cout << "ABC\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;
 
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

lli mod = 1e9 +7, inp[3010];
pair<lli, bool> dp[2][3010][3010];
int n;

inline lli max(lli a, lli b)
{
	if(a>b)
		return a;
	else
		return b;
}

inline lli min(lli a, lli b)
{
	if(a<b)
		return a;
	else
		return b;
}

inline lli solve(bool op, int l, int r)
{
    if(dp[op][l][r].SS==1)
        return dp[op][l][r].FF;
    dp[op][l][r].SS=1;
    if(l>r)
    	return 0;
    else if(op==0)
        dp[op][l][r].FF = max(inp[l]+solve(1, l+1, r), inp[r]+solve(1, l, r-1));
    else
        dp[op][l][r].FF = min(solve(0, l+1, r)-inp[l], solve(0, l, r-1)-inp[r]);
    return dp[op][l][r].FF;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> inp[i];
    cout<<solve(0, 1, n);
}

Measured memory_bytes: 167504
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();
    let mut dp: Vec<u32> = vec![0;s.len()];
    if dp.len() == 1{
        println!("1");
    }
    dp[0] = 1;

    if s[0] != s[1]{
        dp[1] = 2;
    }else{
        dp[1] = 1;
    }
    for i in 2..s.len(){
        if s[i] != s[i-1]{
            dp[i] = dp[i-1] + 1;
        }else{
            if i > 2{
                dp[i] = dp[i-3] + 2;
            }else{
                dp[i] = 2;
            }
        }
    }
    println!("{}", dp.last().unwrap());
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

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

struct UnionFind {
    int node[40010], sz;
    UnionFind(int N) {
        memset(node, -1, sizeof(node));
        sz = N;
    }
    int find(int x) {
        return node[x] < 0 ? x : node[x] = find(node[x]);
    }
    void unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v) return;

        sz--;
        node[v] += node[u];
        node[u] = v;
    }
    int get_size() {
        return sz;
    }
};

int N, H, W;
map< int, vector<int> > vec_row, vec_col;

void unite_slimes(UnionFind &uf, map< int, vector<int> > &vecs) {
    for(auto e : vecs) {
        const vector<int> &vec = e.second;
        int S = vec.size();
        for(int i=0; i<S-1; i++) {
            int u = vec[i], v = vec[i+1];
            uf.unite(u, v);
        }
    }
}

int main() {
    cin >> N >> W >> H;
    UnionFind uf(N);
    
    bool find_edge = false;
    for(int i=0; i<N; i++) {
        int col, row; cin >> col >> row;
        if(vec_col.count(col)) {
            vec_col[col].push_back(i);
        }
        else {
            vec_col[col] = vector<int>{i};
        }

        if(vec_row.count(row)) {
            vec_row[row].push_back(i);
        }
        else {
            vec_row[row] = vector<int>{i};
        }

        find_edge |= (col == 1 || col == W);
        find_edge |= (row == 1 || row == H);
    }

    unite_slimes(uf, vec_row);
    unite_slimes(uf, vec_col);

    int rest_slimes = uf.get_size();
    if(rest_slimes == 1) {
        cout << N - rest_slimes << endl;
    }
    else {
        cout << N + rest_slimes - 1 - find_edge << endl;
    }
    return 0;
}


Measured memory_bytes: 10492
// ARC088-D
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

string s;

void solve1() {
   int n = s.size();
   int ans = n;
   for (int i = 1; i < n; i++) {
      if (s[i] != s[i-1]) {
         ans = min(ans, max(i, n-i));
      }
   }

   cout << ans << endl;
}

void solve2() {
   int n = s.size();
   vec<int> acc(n+1);
   rep (i, n) {
      acc[i+1] = acc[i] + (s[i] - '0');
   }
   int k = n;
   while (acc[n-k] - acc[k] != 0 && acc[n-k] - acc[k] != n-2*k) {
      k--;
   }
   cout << k << endl;
}

int main() {
   cin >> s;

   solve2();

   return 0;
}

Measured memory_bytes: 896
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys
import cmath

X = int(input())


def solve(X):
    loc = 0 + 1j
    direction = 0 + 1j
    cnt = 1
    while True:
        if abs(loc - 0) < 1e-6:
            break
        direction *= cmath.rect(1.0, X / 360.0 * 2.0 * math.pi)
        # print("dir: ", direction)
        # print("dir abs: ", abs(direction))
        # loc += 
        loc += direction
        cnt += 1
    return cnt

# for X in range(1, 180):
#     print(X, solve(X))

print(solve(X))





Measured memory_bytes: 10904
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;

void solve()
{
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int x=tx-sx,y=ty-sy;
    for (int i = 0; i < y; ++i) cout<<"U";
    for (int i = 0; i < x; ++i) cout<<"R";
    for (int i = 0; i < y; ++i) cout<<"D";
    for (int i = 0; i < x; ++i) cout<<"L";
    cout<<"L";
    for (int i = 0; i < y+1; ++i) cout<<"U";
    for (int i = 0; i < x+1; ++i) cout<<"R";
    cout<<"D";
    cout<<"R";
    for (int i = 0; i < y+1; ++i) cout<<"D";
    for (int i = 0; i < x+1; ++i) cout<<"L";
    cout<<"U"<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
long long t,a,b;
long long ans;

using namespace std;

int main()
{
	scanf("%lld%lld%lld",&t,&a,&b);
	
	while(t--)
	{
		long long u,o;
		scanf("%lld%lld",&u,&o);
		if(u>=a&&o>=b)
		ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#ifndef CLion
//#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m)%m)
#define rep(i,s,e) for (int i = s; i < e; ++i)
#define rev(i,s,e) for (int i = s; i > e; --i)
#define mem(a,v) memset(a , v , sizeof a)
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const int N = 5e5 + 9;

const int BLOCK_SIZE = 700;
struct qry{
    int l , r , id;
    bool operator < ( const qry& q ) const{
        if (l / BLOCK_SIZE != q.l / BLOCK_SIZE)
            return make_pair(l,r) < make_pair(q.l,q.r);
        return ( ((l / BLOCK_SIZE) & 1) ? (r < q.r) : (r > q.r) );
    }
};

int n , Q , a[N] , ans[N] , freq[N] , cnt;
qry q[N];

void add( int i ){
    if ( !freq[a[i]]++ ) cnt++;
}
void del( int i ){
    if ( !--freq[a[i]] ) cnt--;
}

void Mo(){
    int l = 0 , r =0;
    rep(i,0,Q){
        while ( l > q[i].l ) add(--l);
        while ( r < q[i].r ) add(r++);
        while ( l < q[i].l ) del(l++);
        while ( r > q[i].r ) del(--r);
        ans[q[i].id] = cnt;
    }
}

void Main(int cse , bool last){
    cin >> n >> Q;
    rep(i,0,n) cin >> a[i];
    rep(i,0,Q) cin >> q[i].l >> q[i].r , q[i].id = i , q[i].l--;
    sort(q , q + Q);
    Mo();
    rep(i,0,Q) cout << ans[i] << "\n";
}

int main(){
#ifndef CLion
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
    //freopen( "out.txt", "w" , stdout );
#endif

    int t = 1;
    //cin >> t;
    for ( int cse = 1; cse <= t; ++cse ) Main(cse, cse == t);
    return 0;
}

Measured memory_bytes: 15500
#include<iostream>
#include<vector>
using namespace std;
#define int long long
int n,m,cnt=0;
int h[100010];
vector<int> g[100010];
void dfs(int i,int hh){
	for(int j=0;j<g[i].size();j++){
		int x=g[i][j];
		if(hh<=h[x])return;}cnt++;
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=0;i<m;i++){
		int p,q; cin>>p>>q;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	for(int i=1;i<=n;i++){
		int y=h[i];
		dfs(i,y);
	}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 10200
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T = int > T in() {
  T x;
  cin >> x;
  return (x);
}
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K, X;
  cin >> K >> X;
  FORS(i, X - K + 1, X + K - 1) { cout << i << " "; }
  cout << "\n";
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  const int N = S.length();
  int ans = (int) 1e9;
  for (int i = 0; i < 2; i++) {
    int pre = 0;
    for (int j = 0; j < N; j++) {
      const char cur = '0' + (i + j) % 2;
      if (cur != S[j]) pre++; 
    }
    ans = min(ans, pre);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var X = cin.ReadInt;

            WriteLine(1000 * (X / 500) +  5 * (X % 500 / 5 ));
        }

        public void Display(int[] array)
        {
            var txt = "";
            foreach (var item in array)
            {
                txt += " " + item.ToString();
            }
            WriteLine("{0}", txt);
        }

        public void Display(int index,int[] array)
        {
            var txt = "";
            foreach (var item in array)
            {
                txt += " " + item.ToString();
            }
            WriteLine("{0} : {1}", index,txt);
        }

        public void Display(List<int>[] list) 
        {
            for (int i = 0; i < list.Length; i++)
            {
                Display(i, list[i].ToArray());
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 27764
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort(all(v))
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

ll N, W;
ll dp[110][100010];
ll w[110], v[110];

ll dfs(ll i, ll j) {
  if(dp[i][j]) return dp[i][j];
  ll res;
  if(i == N) res = 0;
  else if(j < w[i]) res = dfs(i + 1, j);
  else res = max(v[i] + dfs(i + 1, j - w[i]), dfs(i + 1, j));
  dp[i][j] = res;
  return res;
}

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

  cin >> N >> W;
  rep(i, N) cin >> w[i] >> v[i];
  cout << dfs(0, W) << endl;
  return 0;
}


Measured memory_bytes: 78080
s = list(input())
a = 0

for i in range(len(s)):
    if i%2 == 0:
        if s[i] == 'L':
            a += 1
    else:
        if s[i] == 'R':
            a += 1
        else:
            a = a

if a == 0:
    print('Yes')
else:
    print('No')

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

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

#define INF 
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N, M;
  in(N, M);
  vector<char> s(N);

  if (N == 1 && M == 0) {
    print(0);
    return;
  }

  rep(i, M) {
    int si;
    char ci;
    in(si, ci);

    if (si == 1 && N != 1 && ci == '0') {
      print(-1);
      return;
    }

    if (s[si - 1] != 0) {
      if (s[si - 1] != ci) {
        print(-1);
        return;
      }
    }

    s[si - 1] = ci;
  }

  rep(i, N) {
    char pad = i == 0 ? '1' : '0';
    cout << (s[i] == 0 ? pad : s[i]);
  }
  cout << endl;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: usize,
        uvabs: [(Usize1, Usize1, usize, usize); m],
        cds: [(usize, usize); n],
    };

    let mut edges = vec![vec![]; n];
    let mut max_c = 0_usize;
    for (u, v, c, d) in uvabs {
        edges[u].push((v, c, d));
        edges[v].push((u, c, d));
        max_c = std::cmp::max(max_c, c);
    }
    let max_s = max_c * (n - 1);
    let inf = 1_000_000_000_000_000_000_usize;

    let mut dp = vec![vec![inf; max_s + 1]; n];
    dp[0][std::cmp::min(s, max_s)] = 0_usize;
    let mut pq = std::collections::BinaryHeap::new();
    pq.push(std::cmp::Reverse((0_usize, 0, std::cmp::min(s, max_s))));
    while let Some(std::cmp::Reverse((t, u, s))) = pq.pop() {
        let (c, d) = cds[u];
        if s + c <= max_s {
            let (nv, nt, ns) = (u, t + d, s + c);
            if nt < dp[nv][ns] {
                dp[nv][ns] = nt;
                pq.push(std::cmp::Reverse((nt, nv, ns)));
            }
        }
        for &(v, c, d) in edges[u].iter() {
            if c <= s {
                let (nv, nt, ns) = (v, t + d, s - c);
                if nt < dp[nv][ns] {
                    dp[nv][ns] = nt;
                    pq.push(std::cmp::Reverse((nt, nv, ns)));
                }
            }
        }
    }
    for cs in dp.iter().skip(1) {
        let c = cs.iter().min().unwrap();
        println!("{}", c);
    }
}


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

using namespace std;
int n;
string s;

bool ok(int x)
{
    if (2 * x - 1 <= n) return true;
    int tek = 0;
    for (int i = 1; i <= n - x + 1; i++)
        if ((tek + s[i - 1] - '0') % 2 == 1) tek++;
    for (int i = n - x + 2; i <= x; i++)
        if ((tek + s[i - 1] -'0') % 2 == 1) return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    n = (int) s.length();
    int l = 1, r = n + 1;
    while (l + 1 < r)
    {
        int m = (l + r) / 2;
        if (ok(m))
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
int main(){
    int a;
    std::cin>>a;
    std::vector<int>vec(a);
    for(int i=0;i<a;i++){
        std::cin>>vec[i];
    }
    int mini=0,count=0;
    for(int i=0;i<a;i++){
        mini=i;
        for(int j=i;j<a;j++){
            if(vec[mini]>vec[j]){
                mini=j;
            }
            
        }
        if(mini!=i)count++;
        std::swap(vec[mini],vec[i]);
    }
    for(int i=0;i<a;i++){
        std::cout<<vec[i];
        if(i<a-1)std::cout<<" ";
    }
    std::cout<<std::endl;
    std::cout<<count<<std::endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    string s, t; cin >> s >> t;

    int ans = 0;
    rep(i, s.size()) {
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int N;
vector<string> s;

int main () {
  cin >> N;
  s.resize(N);

  map<string, ll> m;
  rep(i,N) {
    cin >> s[i];
    sort(all(s[i]));
    m[s[i]] += 1;
  }

  ll ans = 0;
  for(auto kv: m) {
    ans += kv.second*(kv.second-1)/2;
  }

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


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

int main()
{
  // int a, b, c;
  // cin >> a >> b >> c;
  // cout << a + b + c << endl;
  // 入力は文字列として与えられているので上記は利用不可

  // string s;
  // int cnr;
  // cin >> s;

  // if (s[1] == '1')
  //   cnr++;
  // if (s[2] == '1')
  //   cnr++;
  // if (s[3] == '1')
  //   cnr++;

  // cout << cnr << endl;
  // 初期化不足と、配列間違い

  // string s;
  // int cnr = 0;
  // cin >> s;

  // if (s[0] == '1')
  //   cnr++;
  // if (s[1] == '1')
  //   cnr++;
  // if (s[2] == '1')
  //   cnr++;

  // cout << cnr << endl;
  // ループを使ってみる

  string s;
  int cnr = 0;
  cin >> s;
  for (int i = 0; i < 3; i++)
  {
    if (s[i] == '1')
      cnr += 1;
  }
  cout << cnr << endl;
}

Measured memory_bytes: 256
// D - String Formation
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

int main(){
	string S; int Q; cin>>S>>Q;
	int st = Q, ed = st + S.size(), cnt = 0;
	S = string(Q,'-') + S + string(Q,'-');
	while(Q--){
		int t; cin>>t; t--;
		if(t){//type2
			int f; char c; cin>>f>>c; f--;
			if(cnt%2) S[f? --st: ed++] = c;//odd:reverse
			else S[f? ed++: --st] = c;//even
		}
		else cnt++;//type1
	}
	if(cnt%2) irp(i, ed-1, st-1) cout<<S[i];//odd
	else rp(i, st, ed) cout<<S[i];//even
	puts("");
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int x_dir[] = {-1, 1, 0, 0};
int y_dir[] = {0, 0, -1, 1};

int H, W;
typedef long long ll;

int dfs(const string *S, vector<vector<int>> &dist, int h, int w, int c, int& count)
{
    int new_h, new_w;
    for (int i = 0; i < 4; ++i)
    {
        new_h = h + y_dir[i];
        new_w = w + x_dir[i];
        if (new_h < 0 || new_h >= H || new_w < 0 || new_w >= W)
            continue;
        if (S[h][w] == '#')
        {
            if (dist[new_h][new_w] == 0 && S[new_h][new_w] == '.')
            {
                dist[h][w] = dist[new_h][new_w] = c;
                dfs(S, dist, new_h, new_w, c, ++count);
            }
        }
        else
        {
            if (dist[new_h][new_w] == 0 && S[new_h][new_w] == '#')
            {
                dist[h][w] = dist[new_h][new_w] = c;
                dfs(S, dist, new_h, new_w, c, ++count);
            }
        }
    }
    return count;
}

int main()
{
    cin >> H >> W;
    vector<vector<int>> dist(H, vector<int>(W));
    string S[H];
    for (int i = 0; i < H; ++i)
    {
        cin >> S[i];
    }

    int c = 1, count;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            count = 1;
            dfs(S, dist, i, j, c, count);
            if (count > 1)
                ++c;
        }
    }

    ll brack, white, ans = 0;
    for (int t = 1; t < c; ++t)
    {
        brack = white = 0;
        for (int h = 0; h < H; ++h)
        {
            for (int w = 0; w < W; ++w)
            {
                if (t == dist[h][w])
                {
                    if (S[h][w] == '#')
                        ++brack;
                    else
                        ++white;
                }
            }
        }
        ans += brack * white;
    }
    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int dig = 0;
    for (char c : s) {
        dig += c - 48;
    }
    cout << (dig % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((abs(b-a) <= d && abs(c-b) <= d) || abs(c-a)<=d ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
char c[20], d[20];
std::string b[110];
int a, e, f = 0;
int main()
{
	std::cin >> a;
	for(int i = 1; i <= a; i++)
	{
		std::cin >> c;
		if( i > 1)
		{
			if(c[0] != d[e-1])
			{
				f = 1;
			}
		}
		strcpy(d, c);
		e = strlen(d);
		b[i] = std::string(d);
		for(int j = 1; j < i; j++)
		{
			if(b[i] == b[j])
			{
				f = 1;
			}
		}
	}

	if(f == 1)
	{
		std::cout << "No";
	}else{
		std::cout << "Yes";
	}
}

Measured memory_bytes: 256
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    point_A = bisect.bisect_left(A, b)
    possible_A = point_A
    point_C = bisect.bisect_right(C, b)
    possible_C = N - point_C
    ans += possible_A * possible_C

print(ans)


Measured memory_bytes: 23744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long n = Long.parseLong(sc.next()); 
		Long a = (long) Math.sqrt(n);		
		
		
		Long ans = 0l;
		for(long i = a ; 1 <= i ; i--) {
			if(n % i == 0 ) {
				ans = (i + n/i) - 2;
				break;
			}
		}
		
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#!/usr/bin/env python3

import sys


def main():
    n, m, q = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]

    x = [[0 for j in range(n+1)] for i in range(n+1)]
    c = [[0 for j in range(n+1)] for i in range(n+1)]
    z = [[0 for j in range(n+1)] for i in range(n+1)]

    for i in range(m):
        l, r = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
        x[l][r] += 1
    
    for i in range(1, n+1):
        for j in range(1, n+1):
            c[i][j] = c[i][j-1] + x[i][j]

    for j in range(1, n+1):
        for i in range(1, n+1):
            z[i][j] = z[i-1][j] + c[i][j]
    
    for i in range(q):
        qp, qq = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
        print(z[qq][qq] - z[qq][qp-1] - z[qp-1][qq] + z[qp-1][qp-1])


if __name__=='__main__':
    main()

Measured memory_bytes: 19764
N = int(input())
rs = []
jys = []
for _ in range(N):
    r,jy=input().split()
    rs.append(float(r))
    jys.append(jy)
sum_r = 0
for i in range(len(rs)):
    if jys[i] == 'JPY':
        sum_r += rs[i]
    else:
        sum_r += 380000 * rs[i]
print(sum_r)

Measured memory_bytes: 3060
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    if n < k:
        return 0
    if n == k:
        return 1
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return 1
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv


def solve():
    n, k = getList()
    nums = getList()
    nums.sort()
    kai, _ = fact_and_inv(n+2)
    # print(kai)
    # print(kai)
    # print(npk(5,5,kai))
    # print(nck(5,4,kai))
    # for nn in nums:
    #     print(nn)
    # print(MOD)
    mn, mx = 0, 0
    for i in range(n-k+1):
        # print(n-i-1, k-1)
        pat = nck(n-i-1, k-1, kai)
        mn += pat * nums[i]
        mx += pat * nums[-i-1]

        mn %= MOD
        mx %= MOD
        # print(mx, mn)
    print((mx - mn + MOD) % MOD)


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()







Measured memory_bytes: 90968
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i,m,n) for(int i = m,i##_len=(n);i < i##_len;i++)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(void)
{
    int n,m;
    ll sum = 0;
    priority_queue<int> pq;
    vector<vector<int>> d(pow(10,5)+1,vector<int>());
    cin >> n >> m;

    REP(i, n) {
        int a,b;
        cin >> a >> b;
        d[a].push_back(b);
    }
    
    FOR(i,1,m+1){
        if(d[i].size() > 0){
            REP(j,d[i].size()){
                pq.push(d[i][j]);
            }
        }
        if(pq.size() > 0){
            sum += pq.top();
            pq.pop();
        }
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 5632
from collections import deque
K = int(input())
q = deque([1,2,3,4,5,6,7,8,9])

for i in range(K):
  x = q.popleft()
  if x % 10 != 0: q.append(10*x + x % 10 - 1)
  q.append(10*x + x % 10)
  if x % 10 != 9: q.append(10*x + x % 10 + 1)

print(x)

Measured memory_bytes: 74880
#include <stdio.h>
#define NUM 100001

int main(void) {
    int i,n,ans,ans2,ans3,num1,num2;
    int v[NUM] = {0};
    int numodd[NUM] = {0};//奇数用の配列 
    int numeven[NUM] = {0};//偶数用の配列
    int oddmax,evenmax,oddmax2,evenmax2;

    scanf("%d",&n);

    for(i = 0; i < n; i++) {
        scanf("%d",&v[i]);//値の読み込み
    }

    for(i = 0; i < n; i+=2) {
        numodd[v[i]]++;//奇数部の数字を配列に格納　
        numeven[v[i+1]]++;//偶数部の数字を配列に格納
    }

    oddmax = numodd[0];
    evenmax = numeven[0];
    oddmax2 = numodd[1];
    evenmax2 = numeven[1];

    for(i = 1; i < NUM; i++) {
        if(oddmax < numodd[i]){
            oddmax2 = oddmax;
            oddmax = numodd[i];
            num1 = i;
        } else if(oddmax2 < numodd[i]) {
            oddmax2 = numodd[i];
        }

        if(evenmax < numeven[i]){
            evenmax2 = evenmax;
            evenmax = numeven[i];
            num2 = i;
        } else if(evenmax2 < numeven[i]){
            evenmax2 = numeven[i];
        }
    }
    ans = n -(oddmax+evenmax);
    ans2 = n - (oddmax2+evenmax);
    ans3 = n - (oddmax+evenmax2);

    if(oddmax != evenmax){
        printf("%d\n",ans);
    }else if(num1 == num2){
        if(oddmax2 > evenmax2) {
            printf("%d\n",ans2);
        } else {
            printf("%d\n",ans3);
        }
    }else {
        printf("%d\n",ans);
    }

    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(){
int n;
  scanf("%d",&n);
  int h[n];
  for(int i=0;i<n;i++){
	scanf("%d",&h[i]);
  }
int sum=1,count=0,max=h[0];
  for(int i=1;i<n;i++){
	if(h[i]>=max){sum++;
                  max=h[i];
                 }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


void solve() {
     int n;
     cin>>n;
     int rm=n%1000;
     if(rm>0) {
		   cout<<1000-rm<<endl;
		   return;
		 }
	 cout<<rm<<endl;   
    					   
 }

    
int32_t main() {
	cool;
	int t=1;

	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ABC105D solver = new ABC105D();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC105D {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();
      int[] ar = new int[n];
      long[] integral = new long[n + 1];
      HashMap<Long, Integer> hm = new HashMap<>();
      long res = 0;
      for (int i = 0; i < n; i++) {
        ar[i] = in.nextInt();
        integral[i + 1] = (ar[i] + integral[i]) % m;
      }

      for (int i = 1; i <= n; i++) {
        if (integral[i] % m == 0) {
          res++;
        }
        if (hm.containsKey(integral[i])) {
          hm.replace(integral[i], hm.get(integral[i]) + 1);
        } else {
          hm.put(integral[i], 1);
        }
      }

      for (long x : hm.values()
      ) {
        res += x * (x - 1) / 2;
      }

      out.println(res);
    }

  }
}



Measured memory_bytes: 61604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int t,f;
  t = c - b;
  f = a - d;
  for(int i=0; ; i++){
    if(t <=0){
      cout << "Yes" << endl;
      return 0;
    }
    if(f <=0){
      cout << "No" << endl;
      return 0;
    }
    t = t - b;
    f = f - d;
  }
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        
        var input = Console.ReadLine().Split(' ');
        string X = input[0];
        string Y = input[1];
        string Z = input[2];
        
        var A = Y;
        var B = X;
        
        var C = A;
        A = Z;
        
        System.Console.WriteLine(A+" "+B+" "+C);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> a, vector<long long> b){
    long long ab = 0;
    long long ba = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] > b[i]) {
            ab += a[i] - b[i];
        } else {
            ba += (b[i] - a[i])/2;
        }
    }
    if (ba < ab) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> a(N-1+1);
    vector<long long> b(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&a[i]);
    }
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&b[i]);
    }
    solve(N, a, b);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S;
  cin >> S;

  int h,m,s;

  h = S / 3600;
  m = (S - 3600 * h) / 60;
  s = S - (3600 * h + 60 * m);

  cout << h << ":" << m << ":" << s << endl;
}


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

int main( void )
{
    int r,g,b;
    cin >> r >> g >> b;
    
    int rgb = r * 100 + g * 10 + b;
    if ( rgb % 4 == 0 )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <memory.h>
#include <math.h>

#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define SWAP(t, a, b) do{t c = a; a = b; b = c;}while(0)

int main (int argc, char **argv)
{
  int_least64_t a = 0;
  int_least64_t b = 0;
  int_least64_t c = 0;

  scanf("%lld %lld %lld", &a, &b ,&c);

  printf("%lld\n", MIN(b / a, c));

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)


int main(int argc, char *argv[])
{
    int N, T, A;
    cin >> N >> T >> A;

    vector<int> H;
    Rep(i, N) {
        int h;
        cin >> h;
        H.emplace_back(h);
    }

    double v = 10000000;
    int idx;
    Rep(i, N) {
        double a = abs(T - H[i] * 0.006 - A);
        if (a < v) {
            v = a;
            idx = i;
        }
    }

    cout << idx + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n)); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;
 
int main(){
  int a[32];
  a[0] = 1;
  a[1] = 1;
  a[2] = 1;
  a[3] = 2;
  a[4] = 1;
  a[5] = 2;
  a[6] = 1;
  a[7] = 5;
  a[8] = 2;
  a[9] = 2;
  a[10] = 1;
  a[11] = 5;
  a[12] = 1;
  a[13] = 2;
  a[14] = 1;
  a[15] = 14;
  a[16] = 1;
  a[17] = 5;
  a[18] = 1;
  a[19] = 5;
  a[20] = 2;
  a[21] = 2;
  a[22] = 1;
  a[23] = 15;
  a[24] = 2;
  a[25] = 2;
  a[26] = 5;
  a[27] = 4;
  a[28] = 1;
  a[29] = 4;
  a[30] = 1;
  a[31] = 51;
  
  int N; cin >> N;
  N--;
  cout << a[N] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[201];
	while(scanf("%s",str)){
		if(!strcmp(str, "-")) break;
		
		int m, h = 0,b ,i;
		scanf("%d", &m);
		for(i = 0; m > i; i++){
			scanf("%d", &b);
			h += b;
		}
		h %= strlen(str);
		for(i = h; strlen(str) + h > i; i++){
			printf("%c", str[i%strlen(str)]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 568
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rep(i, x, y)   for (__typeof(x) i = x; i < y; ++i)
#define repr(i, x, y)   for (__typeof(x) i = x; i > y; i --)
#define f(p) p.first
#define s(p) p.second
#define vdp(n,x) vector<vector<ll>>dp(n+1,vector<ll>(x+1,0));
const ll mod=1000000007;
const ll AM=2e6+5;
using namespace std;
int main()
{
    fast;
 	ll n,m; cin>>n>>m;
 	char s[n+1][m+1];
 	for(ll i=1;i<=n;i++)
 	{
 		for(ll j=1;j<=m;j++)
 			cin>>s[i][j];
 	}
 	vdp(n,m); dp[1][1]=1;
 	
 	for(ll i=1;i<=n;i++)
 	{
 		for(ll j=1;j<=m;j++)
 		{
 			if(s[i][j]=='#')
 				dp[i][j]=0;
 			else
 			{
 				dp[i][j]=max(dp[i][j],dp[i-1][j]+dp[i][j-1])%mod;
 			}
 			//cout<<dp[i][j]<< " ";
 		}
 		//cout<<endl;
 	}   
 	cout<<dp[n][m];
}

Measured memory_bytes: 9088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    vs v;
    for(int i = 0; i < 3; i++){
        string s;
        cin >> s;
        v.pb(s);
    }
    cout << "A" << v[1][0] << "C";
    }

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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

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

	int min = N;
	int n = N / 9;
	REP(i, n + 1)
	{
		int n_sum = 0;
		int m = 1;
		int s = 9 * i;
		while (s >= 9)
		{
			m *= 9;
			if (m == s)
			{
				n_sum++;
				s = 0;
				break;
			}
			if (m > s)
			{
				n_sum++;
				s -= m / 9;
				m = 1;
			}
		}

		s = (N - 9 * i);
		m = 1;
		int s_sum = 0;
		while (s >= 6)
		{
			m *= 6;
			if (m == s)
			{
				s_sum++;
				s = 0;
				break;
			}
			if (m >= s)
			{
				n_sum++;
				s -= m / 6;
				m = 1;
			}
		}
		min = std::min(min, s + s_sum + n_sum);
	}

	cout << min << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int w[10],k[10];
    for(int i = 0;i < 10; i++)scanf("%d",&w[i]);
    for(int i = 0;i < 10; i++)scanf("%d",&k[i]);
    
    sort(w,w+10);
    w[9] += w[8]+w[7];
    
    sort(k,k+10);
    k[9] += k[8]+k[7];
    
    printf("%d %d\n",w[9],k[9]);
    return 0;
}

Measured memory_bytes: 1040
N, x = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
A = [0] * N

for i in range(N):
    A[i] = B[i]
    if A[i] > x:
        A[i] = x
for i in range(N - 1):
    tmp = A[i] + A[i + 1]
    if tmp <= x: continue
    A[i + 1] -= tmp - x
print(sum([B[_] - A[_] for _ in range(N)]))


Measured memory_bytes: 14260
package main

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

func main() {
	var h, w, m int
	fmt.Scan(&h, &w, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	bs := make([][]int, m)
	bm := make(map[int]map[int]bool)
	for i := range bs {
		sc.Scan()
		bh, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		bw, _ := strconv.Atoi(sc.Text())
		bh--
		bw--
		bs[i] = []int{bh, bw}
		if _, ok := bm[bh]; !ok {
			bm[bh] = make(map[int]bool)
		}
		bm[bh][bw] = true
	}

	my := make([]int, w)
	mx := make([]int, h)
	for _, b := range bs {
		y, x := b[0], b[1]
		my[x]++
		mx[y]++
	}
	//fmt.Println(my)
	//fmt.Println(mx)
	ys := make([][]int, w)
	for i := range my {
		ys[i] = []int{i, my[i]}
	}
	sort.Slice(ys, func(i, j int) bool { return ys[i][1] > ys[j][1] })
	yc := make([]int, 0)
	ymax := ys[0][1]
	for i := 0; i < w && ys[i][1] == ymax; i++ {
		yc = append(yc, ys[i][0])
	}

	xs := make([][]int, h)
	for i := range mx {
		xs[i] = []int{i, mx[i]}
	}
	sort.Slice(xs, func(i, j int) bool { return xs[i][1] > xs[j][1] })
	xc := make([]int, 0)
	xmax := xs[0][1]
	for i := 0; i < h && xs[i][1] == xmax; i++ {
		xc = append(xc, xs[i][0])
	}

	//fmt.Println("yc:", yc)
	//fmt.Println("xc:", xc)
	//fmt.Println("bm:", bm)
	for _, yi := range yc {
		for _, xi := range xc {
			//fmt.Println("yi, xi: ", yi, xi)
			if _, ok := bm[xi]; !ok {
				fmt.Println(my[yi] + mx[xi])
				return
			}
			if _, ok := bm[xi][yi]; !ok {
				fmt.Println(my[yi] + mx[xi])
				return
			}
		}
	}
	fmt.Println(ymax + xmax - 1)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 135972
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}
int main(){
  int n;
  cin >> n;
  vector<int> monster(n);
  for(int i = 0; i < n; ++i) cin >> monster[i];
  int ans = monster[0];
  for(int i = 1; i < n; ++i){
    ans = gcd(ans, monster[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val a, b = BigDecimal(Scanner.next)

	pw.println((a * b).setScale(0, BigDecimal.RoundingMode.FLOOR))
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54784