akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main(){
  long n,k;
  cin>>n>>k;
  k--;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
    a.at(i)--;
  }
  
  vector<int>b(2*n+1);
  b.at(0)=0;
  
  rep2(i,1,2*n+1){
    b.at(i)=a.at(b.at(i-1));
  }
  vector<int>c(n,-1);
  int d=0;int e=0;
  rep(i,2*n+1){
    if(c.at(b.at(i))==-1){
      c.at(b.at(i))=i;
    }
    else{
      d=c.at(b.at(i));
      e=i;
      break;
    }
  }
  long f;
  if(k-d+1>=0){
    f=d+(k-d+1)%(e-d);
  }
  else{
    f=k+1;
  }
  cout<<b.at(f)+1<<endl;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int n = 26;

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

    // 満足度が下がる値
    vector<int> bad(n);
    rep(i, n) cin >> bad[i];

    // そのコンテストをその日に開いた時の満足度
    vector<vector<int>> score(days+1, vector<int>(n));
    for(int d = 1; d <= days; d++){
        rep(i, n) cin >> score[d][i];
    }

    // 最後にそのコンテストが開かれたのが何日前か
    vector<vector<int>> preD(days+1, vector<int>(n, 0));

    vector<bool> heldCon(n, false);

    // 日付毎で満足度が最大になるコンテストを開く
    vector<int> sats(days+1, 0), cons(days+1, 0);
    for(int d = 1; d <= days; d++){
        int maxSat = 0, maxCon = 0;

        // d日のi番目のコンテストを開いたときの満足度を計算し、最大になるコンテストと満足度を記録する
        rep(i,n){
            int conSat = score[d][i] + sats[d-1];
            vector<int> copyPreD = preD[d-1];
            rep(j,n){
                if (i == j) continue;
                conSat -= bad[j] * copyPreD[j];
            }
            if (chmax(maxSat, conSat)){
                maxCon = i;
            }
        }

        // 最も良いスコアとコンテストを更新
        sats[d] = maxSat;
        cons[d] = maxCon+1;

        // 開いたコンテストの最終日を更新
        rep(i,n){
            if (i == maxCon){
                heldCon[i] = true;
                preD[d][i] = 0;
            } 
            else if(heldCon[i]) preD[d][i] = preD[d-1][i] + 1;
        }
    }
    
    for(int d = 1; d <= days; d++){
        cout << cons[d] << endl;
    }
}

Measured memory_bytes: 3736
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn solve(a: i32, b: i32) -> &'static str {
    if a % 2 == 0 || b % 2 == 0 {
        return "Even";
    } else {
        return "Odd";
    }
}

#[test]
fn test_solve_odd() {
    assert_eq!(solve(1, 1), "Odd")
}

#[test]
fn test_solve_even() {
    assert_eq!(solve(2, 5), "Even")
}

fn main() {
    input!{
        a: i32,
        b: i32
    }
    println!("{}", solve(a, b))
}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    int maxa=-1;
    rep(i,n) {
        cin>>a[i];
        maxa=max(maxa,a[i]);
    }
    int l=0,r=maxa;
    auto f=[&](int x){
        long long now=0;
        rep(i,n){
            now+=(a[i]-1)/x;
        }
        return now<=k;
    };
    while(l+1<r){
        int x=(l+r)/2;
        if(f(x))r=x;
        else l=x;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 3976
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, orig[310][310], dp[310][310];

signed main() {
    cin >> N;
    rep(i,0,N) rep(j,0,N) {
        cin >> orig[i][j];
        dp[i][j] = orig[i][j];
    }

    rep(k,0,N) rep(i,0,N) rep(j,0,N) chmin(dp[i][j], dp[i][k] + dp[k][j]);
    rep(i,0,N) rep(j,0,N) {
        if(orig[i][j] != dp[i][j]) {
            cout << -1 << endl;
            return 0;
        }
    }

    int ans = 0;
    rep(i,0,N) rep(j,i+1,N) {
        bool remove = false;
        rep(k,0,N) {
            if(i == k || j == k) continue;
            if(dp[i][j] == dp[i][k] + dp[k][j]) remove = true;
        }
        if(!remove) ans += dp[i][j];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
const int H_MAX = 50;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int H, W;
string s[H_MAX];
void dfs (int y, int x) {
    for (int d = 0; d < 4; d++) {
        int ny = y + dy[d];
        int nx = x + dx[d];
        if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == '#') {
            s[y][x] = '.';
            s[ny][nx] = '.';
            dfs(ny, nx);
        }
    }
}
int main (void) {

    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                dfs(i, j);
            }
        }
    }

    bool flag = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                flag = false;
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 512
def inverse(x):
    if len(x)!=2: return []
    a, b = x[0]
    c, d = x[1]
    tmp = 1.0/(a*d-b*c)
    return [[d*tmp, -b*tmp],[-c*tmp, a*tmp]]

def Mmult(A, B):
    n1=len(A)
    n2=len(A[0])
    n3=len(B[0])
    C=[[0 for j in range(n3)] for i in range(n1)]
    for i in range(n1):
        for j in range(n2):
            for k in range(n3):
                C[i][k] += A[i][j] * B[j][k]
    return C            

while True:
    try:
        x = map(int, raw_input().split())
    except:
        break
    A=[x[0:2], x[3:5]]
    B=[[x[2]], [x[5]]]
    C = Mmult(inverse(A), B)
    print "%.3f %.3f" %(C[0][0], C[1][0])

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

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

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

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

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

typedef pair<int, int> P;

class DEqueue {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;
        vector<int> v(N);
        REP(i, N) cin >> v[i];

        int res = 0;
        for (int l = 0; l < N; l++) {
            for (int r = N + 1; l + (N + 1 - r) <= K && r > l; r--) {
                int num = K - (l + (N + 1 - r)); // 取り除く回数

                priority_queue<int, vector<int>, greater<int>> pq;
                FOR(i, 1, l) {
                    pq.push(v[i - 1]);
                }
                REV(i, N, r) {
                    pq.push(v[i - 1]);
                }

                while (num > 0 && !pq.empty()) {
                    if (pq.top() >= 0) break;
                    pq.pop();
                    num--;
                }

                int tmp = 0;
                while (!pq.empty()) {
                    tmp += pq.top();
                    pq.pop();
                }
                res = max(res, tmp);
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DEqueue solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#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 reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;


int main() {
	int p, q, r,m;
	cin >> p >> q >> r;
	m = p;
	m = max(m, q);
	m = max(m, r);
	cout << p + q + r - m << endl;
}

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

const int N=1e5+1e3+7;

int n;

vector<int>e[N];

int dep[N],lf[N];

int ad;

long long al;

void dfs(int i,int f)
{
	for(int j=0;j<e[i].size();j++)
	{
		int v=e[i][j];
		if(v==f)
			continue;
		dep[v]=dep[i]+1;
		dfs(v,i);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	ad=0x7fffffff,al=1e15;
	for(int i=1;i<=n;i++)
	{
		for(int t=1;t<=n;t++)
			lf[t]=0,dep[t]=0;
		dfs(i,0);
		int mx=0;
		for(int j=1;j<=n;j++)
			mx=max(mx,dep[j]);
		long long now=1;
		for(int j=0;j<mx;j++)
		{
			int tot=0;
			for(int k=1;k<=n;k++)
				if(dep[k]==j)
					tot=max(tot,(int)e[k].size()-(k!=i));
			now*=tot;
		}
		if(mx<ad)
		{
			ad=mx;
			al=now;
		}
		else if(mx==ad)
			al=min(al,now);
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<e[i].size();j++)
		{
			for(int t=1;t<=n;t++)
				lf[t]=0,dep[t]=0;
			int v=e[i][j];
			if(i>v)
				continue;
			dfs(i,v);
			dfs(v,i);
			int mx=0;
			for(int k=1;k<=n;k++)
				mx=max(mx,dep[k]);
			long long now=1;
			for(int k=0;k<mx;k++)
			{
				int tot=0;
				for(int l=1;l<=n;l++)
					if(dep[l]==k)
						tot=max(tot,(int)e[l].size()-1);
				now*=tot;
			}
			if(mx<ad)
			{
				ad=mx;
				al=now*2;
			}
			else if(mx==ad)
				al=min(al,now*2);
		}
	printf("%d %lld",ad+1,al);
}

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#include <array>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__)
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template<typename T>
T gcd(T a, T b){
    while(b){
        a %= b;
        swap(a, b);
    }
    return a;
}
struct TwoStacks{
    using T = long long;
    struct Node{
        T val, sum;
        Node(const T &val, const T &sum):val(val), sum(sum){}
    };
    T merge(T l, T r){
        return gcd(l, r);
    }
    stack<Node> front, back;
    int size(){
        return front.size() + back.size();
    }
    T eval(){
        //        assert(front.size() + back.size() > 0);
        if(!back.empty()){
            if(!front.empty()){
                return merge(front.top().sum, back.top().sum);
            }else{
                return back.top().sum;
            }
        }else{
            return front.top().sum;
        }
    }
    void pop_front(){
        //        assert(front.size() + back.size() > 0);
        if(front.empty()){
            front.emplace(back.top().val, back.top().val);
            back.pop();
            while(!back.empty()){
                front.emplace(back.top().val, merge(back.top().val, front.top().sum));
                back.pop();
            }
        }
        front.pop();
    }
    void push_back(const T &val){
        if(!back.empty()){
            back.emplace(val, merge(back.top().sum, val));
        }else{
            back.emplace(val, val);
        }
    }
};
int main(){
    ll a, b, k;
    cin >>  a >> b >> k;
    ll t = min(a, k);
    k -= t;
    a -= t;
    t = min(b, k);
    b -= t;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
import copy 
import numpy as np

N = int(input())
*B, = map(int, input().split())

A = [0]*N

for i in range(1, N, 1):
    if i-1==0:
        A[i-1]   = B[i-1]
        A[i] = B[i-1]
    else:
        if B[i-1] >= A[i-1]:
            A[i] = max(A[i-1], B[i-1])
        else:
            A[i] = B[i-1]
            A[i-1] = B[i-1]
print(sum(A))


Measured memory_bytes: 12384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c >= b && c >= a)
		cout << a + b << "\n";
	else if (a >= b && a >= c)
		cout << b + c << "\n";
	else
		cout << a + c << "\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

double graph[1002][1002];
double dist(pair<double, double> p1, pair<double, double> p2){
    return sqrt(pow(p1.first-p2.first, 2)+pow(p1.second-p2.second, 2));
}

int main ()
{
  prep();
  double sx, sy, fx, fy;
  cin >> sx >> sy >> fx >> fy;
  int n;
  cin >> n;
  tuple<double, double, double> before[n];
  for (int i=1; i<=n; i++){
      double x, y, r;
      cin >> x >> y >> r;
      for (int j=1; j<i; j++){
          tuple<double, double, double> p = before[j-1];
          double distt = dist({get<0>(p), get<1>(p)}, {x, y});
          graph[i][j] = max(distt-get<2>(p)-r, 0.0);
          graph[j][i] = max(distt-get<2>(p)-r, 0.0);
      }
      before[i-1] = tuple<double, double, double> (x, y, r);
  }
  for (int j=1; j<=n; j++){
      tuple<double, double, double> p = before[j-1];
      double distt = dist({get<0>(p), get<1>(p)}, {sx, sy});
      double distt2 = dist({get<0>(p), get<1>(p)}, {fx, fy});
      graph[0][j] = max(distt-get<2>(p), 0.0);
      graph[j][0] = max(distt-get<2>(p), 0.0);
      graph[n+1][j] = max(distt2-get<2>(p), 0.0);
      graph[j][n+1] = max(distt2-get<2>(p), 0.0);
  }
  graph[0][n+1] = dist({sx, sy}, {fx, fy});
  graph[n+1][0] = dist({sx, sy}, {fx, fy});
  // from 0 to n+1
 
  double curdist[n+2];
  for (int i=0; i<=n+1; i++){
      curdist[i] = graph[i][0];
  }
  bool vis[n+1] = {false};
  for (int i=0; i<=n+1; i++){
      double minnest = 1000000000000000001.0;
      int ind = 0;
      for (int j=0; j<=n; j++){
          if (vis[j]){
              continue;
          }
          if (curdist[j] < minnest){
              minnest = curdist[j];
              ind = j;
          }
      }
      vis[ind] = true;
      for (int j=1; j<=n+1; j++){
          curdist[j] = min(curdist[j], minnest+graph[ind][j]);
      }
  }
  printf("%.9lf", curdist[n+1]);
  return 0; 
}

Measured memory_bytes: 8192
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

int a[233];
int n ;
int res;

int main ()
{
	int i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",a+i);
	for ( i=1 ; i<=n ; i++ )
	{
		int k=i;
		while ( a[k]==a[k+1] ) k++;
		res+=(k-i+1)>>1;
		i=k;
	}
	printf("%d\n",res);
	return 0 ;
}

Measured memory_bytes: 256
from itertools import *
N=101198;n=range(N);a=list(n);a[1]=0
for i in range(2,int(N**.5)+1):a[i*2::i]=[0]*len(a[i*2::i])

for e in iter(input, '-1 -1'):
    qN, qP = map(int, e.split())
    p=[x for x in a[qN+1:]if x][:qP+1]
    print(sorted(p[i]+p[j]for i in range(qP)for j in range(i,qP))[qP-1])


Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int N,M; cin>>N>>M;
	vector<vector<int>> ans(N+2,vector<int>(M+2,0));
	vector<string> vec(N);
	rep(i,0,N){
		string s; cin>>s;
		vec[i]=s;
	}
	rep(i,0,N){
		string s=vec[i];
		rep(j,0,M){
			if(s[j]=='#'){
				//ans[i+1][j+1]=='#';
				rep(a,-1,2){
					rep(b,-1,2){
						ans[i+1+a][j+1+b]++;
					}
				}
			}
		}
	}
	rep(i,1,N+1){
		rep(j,1,M+1){
			if(vec[i-1][j-1]=='#'){
				cout<<'#';
			}
			else cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

const int MAX = 2e5;
const int INF = 2e9;
typedef long long ll;

ll comb(ll n, ll r) {

    if (n < r) {
        return 0;
    }

    if (n == r || r == 0) {
        return 1;
    }

    ll x = 1;
    ll y = 1;
    for (ll i = 0; i < r; ++i)
    {
        x = x * (n - i);
        y = y * (i + 1);
    }

    return x / y;
}

ll n;
ll a[MAX + 1];
ll cnt[MAX + 1];

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

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

    ll total = 0;
    for (int i = 0; i < MAX + 1; ++i)
    {
        if (cnt[i])
            total += comb(cnt[i], 2);
    }

    for (int i = 0; i < n; ++i)
    {
        cout << total - comb(cnt[a[i]], 2) + comb(cnt[a[i]] - 1, 2) << "\n";
    }

    return 0;
}


Measured memory_bytes: 4736
def segfunc(x,y):
  return set(x)|set(y)
ide_ele=set()
class SegTree():
  def __init__(self,init_val,segfunc,ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n=int(input())
s=input()
q=int(input())
st=SegTree(s,segfunc,ide_ele)
for _ in range(q):
  q,c,r=input().split()
  if q=='1':st.update(int(c)-1,r)
  else:print(len(st.query(int(c)-1,int(r))))

Measured memory_bytes: 303928
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, m, k;
    cin >> n >> m >> k;
    vector<li> as(n), bs(m);
    vector<li> a_acc(n + 1), b_acc(m + 1);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
        a_acc[i + 1] = a_acc[i] + as[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> bs[j];
        b_acc[j + 1] = b_acc[j] + bs[j];
    }

    li ans = 0;
    li ptr = m;
    for (int i = 0; i <= n; ++i) {
        while (ptr >= 0 && b_acc[ptr] + a_acc[i] > k) {
            ptr--;
        }
        if (ptr >= 0) {
            ans = max(ans, i + ptr);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9540
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
 
int waniSort(int number,int times)
{
    int num_h=0,num_l=0,num_k=1,ans;
    vector<int> higi;
    vector<int> low;
     
    int num[times];
    num[1] = number;
    for (int i=0; i<times; i++)
    {
        higi.push_back(num[i+1]%10);
        low.push_back(num[i+1]%10);
        num[i+2] = num[i+1]/10;
    }
     
    sort(higi.begin(), higi.end(),greater<int>());
    sort(low.begin(), low.end());
    for (int i=0; i<times; i++)
    {
        int k = times - i - 1;
        num_h += (higi.at(k)*num_k);
        num_l += (low.at(k)*num_k);
        num_k *= 10;
    }
    ans = num_h - num_l;
    return ans;
};
 
int main()
{
    int number=100,times=100,ans[20];
    int ans_i,ans_j,ans_num;
     
    while ((number + times)!= 0) {
        cin >> number >> times;
        ans_i = -1;
        ans[0] = number;
        for (int i=0; i<21; i++)
        {
            ans[i+1] = waniSort(ans[i], times);
            for (int k=0; k<i+1; k++)
            {
                if (ans[i+1] == ans[k])
                {
                    ans_i = i - k + 1;
                    ans_num = ans[i+1];
                    ans_j = k;
                    break;
                }
            }
             
            if (ans_i != -1)
            {
                break;
            }
        }
        if ((number + times) == 0) {
            break;
        }
        cout << ans_j << " "<< ans_num << " " << ans_i << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
#define vec vector<int>
using namespace std;

main(){
    int n;
    cin>>n;
    int a[N]={},b[N]={};
    rep(i,n){
        int c;cin>>c;
        if(i%2)a[c]++;
        else b[c]++;
    }
    pii m1={0,0},m2={0,0},m3={0,0},m4={0,0};
    rep(i,110000){
        if(a[i]>m2.first){
            m2={a[i],i};
            if(m2.first>m1.first)swap(m1,m2);
        }
        if(b[i]>m4.first){
            m4={b[i],i};
            if(m4.first>m3.first)swap(m4,m3);
        }
    }
    if(m1.second==m3.second){
        int ans1=(n+1)/2-m1.first+n/2-m4.first;
        int ans2=(n+1)/2-m2.first+n/2-m3.first;
        cout<<min(ans1,ans2);
    }
    else{
        cout<<n-m1.first-m3.first;
    }

}

Measured memory_bytes: 8064
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

class Main {
  public static int cnt = 0;
  
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
  	int n = sc.nextInt();
  	int[] a = new int[n];
  	for(int i = 0; i < n; ++i) {
  		a[i] = sc.nextInt();
  	}

  	//insertionSort(a, 1);
  	shellSort(a);
  	System.out.println(cnt);
  	for(int i = 0; i < n; ++i) {
  		System.out.println(a[i]);
  	}
  }
  
  public static void insertionSort(int[] a, int g){
  	for(int i = g; i < a.length; ++i) {
  		int v = a[i];
  		int j = i - g;
  		while(j >= 0 && a[j] > v) {
  			a[j + g] = a[j];
  			j = j - g;
  			cnt += 1;
  		}
  		a[j + g] = v;
  	}
  }
  
  public static void shellSort(int[] a) {
  	List<Integer> g = new ArrayList<Integer>();
  	for(int t = 1; t < a.length; t *= 2){
  		g.add(0, t);
  	}
  	
	if(g.size() == 0){
		g.add(0, 1);
	}
  	
  	int m = g.size();
  	System.out.println(m);
	
	for(int i = 0; i < m; ++i) {
		System.out.print(i == 0 ? "" : " ");
		System.out.print(g.get(i));
	}
  	System.out.println();
  	
  	for(int i = 0; i < m; ++i) {
  		insertionSort(a, g.get(i));
  	}
  }
}

Measured memory_bytes: 298736
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  double x;
  cin >> x;
  
  double m=100;
  int i ;
  
  for(i=1; i<4000; i++){
    m=floor(m*1.01);
    if(m>=x) break;
  }
 cout << i << endl;
}

Measured memory_bytes: 3708
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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; }



int N, K;

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

  ll ans = 0;

  if (K % 2 == 0) {
    ll m1 = N / K;
    ans += (m1 * m1 * m1);

    ll m2 = (N + K/2) / K;
    ans += (m2 * m2 * m2);
  } else {
    ll m1 = N / K;
    ans += (m1 * m1 * m1);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


def main():
    import sys

    read = sys.stdin.buffer.read

    N, Q, *TUV = map(int, read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 52360
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#define rint register int
using namespace std;
inline void read(int &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	x*=f;
}
const int maxn=200003,maxm=100003;
int x[maxm],p[maxm],n,m,dp[maxm],ans[maxn];
vector<int> a[maxn],id[maxn];
#define pb push_back
int main() {
	read(n);read(m);int tot=0;
	for(rint i=1;i<=m;++i) {
		read(x[i]);read(p[i]);
		a[p[i]].pb(x[i]);
	}
	for(rint i=1;i<n;++i) if(!a[i].empty()) {
		sort(a[i].begin(),a[i].end());
		for(auto x:a[i]) id[i].pb(++tot);
	}
	ans[1]=1;
	for(rint i=2;i<=n;++i) {
		int sz=a[i-1].size(),mx=1;
		for(rint j=0;j<sz;++j) {
			auto k=upper_bound(a[i-2].begin(),a[i-2].end(),a[i-1][j])-1;
			if(a[i-2].empty()||k<a[i-2].begin()) {dp[id[i-1][j]]=2;mx=max(mx,dp[id[i-1][j]]);continue;}
			dp[id[i-1][j]]=dp[id[i-2][k-a[i-2].begin()]]+1;
			mx=max(mx,dp[id[i-1][j]]);
		}
		ans[i]=mx;
	}
	memset(dp,0,sizeof dp);
	for(rint i=n-1;i>=1;--i) {
		int sz=a[i].size(),mx=1;
		for(rint j=0;j<sz;++j) {
			auto k=upper_bound(a[i+1].begin(),a[i+1].end(),a[i][j])-1;
			if(a[i+1].empty()||k<a[i+1].begin()) {dp[id[i][j]]=2;mx=max(mx,dp[id[i][j]]);continue;}
			dp[id[i][j]]=dp[id[i+1][k-a[i+1].begin()]]+1;
			mx=max(mx,dp[id[i][j]]);
		}
		ans[i]+=mx-1;
	}
	for(rint i=1;i<n;++i)	printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}
 


Measured memory_bytes: 20292
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  key = ""
  for j in range(n-1):
    key = key + s[j]
    if (i>>j)&1:
      key = key + "+"
  key = key + s[n-1]
  ans += eval(key)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int main(){
  int a,b,c;
  ll sum=0;
  bool ok=false;
  cin>>a>>b>>c;
  for(int i=0;i<100;i++){
    sum+=a;
    if(sum%b==c)ok=true;
  }
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    n = int(input())
    H = readInts()
    cnt = 0
    while True:
        #print(H)
        allzero = True
        i = 0
        while i < n:
            if H[i] != 0:
                l = i
                cnt += 1
                allzero = False
                break
            i += 1
        if allzero:
            print(cnt)
            exit()
        while l < n:
            if H[l] != 0:
                H[l] -=1
            else:
                break
            l += 1
if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	cin>>n;
	lp(i,n){
		string a;
		set<string> ans;
		cin>>a;
		string memo1,memo2;
		for(int i=0;i<a.size();i++){
			memo1=a.substr(0,i);
			memo2=a.substr(i);
			ans.insert(memo1+memo2);
			ans.insert(memo2+memo1);
			reverse(memo1.begin(),memo1.end());
			ans.insert(memo1+memo2);
			ans.insert(memo2+memo1);
			reverse(memo2.begin(),memo2.end());
			ans.insert(memo1+memo2);
			ans.insert(memo2+memo1);
			reverse(memo1.begin(),memo1.end());
			ans.insert(memo1+memo2);
			ans.insert(memo2+memo1);
		}
		cout<<ans.size()<<endl;
	}

	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>

using namespace std;

int main() {
    string input;
    cin >> input;

    if (input == "A") {
        printf("T");
    } else if (input == "T"){
        printf("A");
    } else if (input == "C"){
        printf("G");
    } else {
        printf("C");
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int x, y;
  cin >> x >> y;

  int ans = INF;

  rep(b, bit(2)) {
    int num = __builtin_popcount(b);
    int xx = x, yy = y;
    if ((b >> 0) & 1)
      xx *= -1;
    if ((b >> 1) & 1)
      yy *= -1;
    if (yy < xx)
      continue;
    int temp = num + yy - xx;
    chmin(ans, temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	map<str, int> _m;
	rep(i, n)
	{
		str tmp;
		cin >> tmp;
		_m[tmp]++;
	}
	cout << "AC x " << _m["AC"] << endl;
	cout << "WA x " << _m["WA"] << endl;
	cout << "TLE x " << _m["TLE"] << endl;
	cout << "RE x " << _m["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
using namespace std;
#define mod 1000000007
const int maxn=1000000;
void solve() {
    string s;
    cin>>s;
    if(s[s.size()-1]!='s') cout<<s<<"s";
    else cout<<s<<"es";

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (1<<30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x,y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    if ( !v.empty() ) {
        out << '[';
        copy (v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


/* template end */


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

    int h, w;
    cin >> h >> w;
    
    vector<vector<int>> hl(w);
    for(int i = 0; i < w; i++) {
        hl[i].push_back(-1);
    }
    vector<vector<int>> wl(h);
    for(int i = 0; i < h; i++) {
        wl[i].push_back(-1);
    }
    bool table[h][w];

    for(int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < w; j++) {
            if (s[j] == '.') {
                table[i][j] = true;
            } else {
                table[i][j] = false;
                hl[j].push_back(i);
                wl[i].push_back(j);
            }
        }
    }
    for(int i = 0; i < w; i++) {
        hl[i].push_back(h);
    }
    for(int i = 0; i < h; i++) {
        wl[i].push_back(w);
    }

    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(!table[i][j]) {
                continue;
            }
            int north = 0;
            int south = 0;
            int east = 0;
            int west = 0;
            {
                auto lb = lower_bound(hl[j].begin(), hl[j].end(), i);
                auto rb = lb - 1;
                north = i - *rb;
                south = *lb - i;
            }
            {
                auto lb = lower_bound(wl[i].begin(), wl[i].end(), j);
                auto rb = lb - 1;
                east = j - *rb;
                west = *lb - j;
            }
            ans = max(ans, north + south + west + east - 3);
        }
    }

#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 38400
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, m; read(n), read(m);
  for (RI i = 1, x; i <= m; ++i)
    read(x), n -= x;
  printf("%lld\n", max(n, -1ll));

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 3764
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int height;
		int width;
		
		while(true){
			height = scan.nextInt();
			width = scan.nextInt();
			
			if(height == 0 && height == 0 ){
				break;
			}
			
			for (int i = 0; i <= height-1; i++){
				for (int j = 0; j <= width-1; j++){
					if((i+j)%2 == 0){
						System.out.print("#");
					}else{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}		
	}
}


Measured memory_bytes: 32956
/*raghav0307 - Raghav Gupta*/

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;

int main(){
	fast_io();
	string s;	cin >> s;
	int a = (int)(s[0] - '0')*10 + (int)(s[1]-'0');
	int b = (int)(s[2] - '0')*10 + (int)(s[3]-'0');
	bool u = true;
	if(a < 1 or a > 12) u = false;
	bool v = true;
	if(b < 1 or b > 12)	v = false;
	if(u and v){
		cout << "AMBIGUOUS";
	}
	else if(!u and !v){
		cout << "NA";
	}
	else if(u){
		cout << "MMYY";
	}
	else cout << "YYMM";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
using namespace std;
int n,ans=0;
string s[4];
int main(){
	cin>>n>>s[1]>>s[2]>>s[3];
	for (int i=0;i<n;i++){
		int x[200];
		memset (x,0,sizeof(x));
		x[s[1][i]]++;
		x[s[2][i]]++;
		x[s[3][i]]++;
		ans+=3-max(max(x[s[1][i]],x[s[2][i]]),x[s[3][i]]);
	}
	cout<<ans;
}

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

namespace abc110_c
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string t = Console.ReadLine();
			Dictionary<char, char> rule = new Dictionary<char, char>();
			bool ret = true;
			for (int i = 0; i < s.Length; i++)
			{
				if (!rule.ContainsKey(s[i])) rule[s[i]] = t[i];
				if (rule[s[i]] != t[i]) ret = false;
			}
			List<char> used = new List<char>();
			foreach (var pair in rule)
			{
				if (used.Contains(pair.Value)) ret = false;
				used.Add(pair.Value);
			}
			Console.WriteLine(ret ? "Yes" : "No");
		}
	}
}

Measured memory_bytes: 14816
import java.util.*;
import java.io.*;
public class Main {
  public static void main(String[] args) throws IOException,InterruptedException{
	Scanner sc =new Scanner(System.in);
	PrintWriter pw = new PrintWriter(System.out);
	int n =sc.nextInt(),wei=sc.nextInt();
	long[] cost =new long [n+1],value =new long [n+1];
	for (int i=1;i<=n;++i) {
		cost[i]=sc.nextInt();value[i]=sc.nextInt();
	}
	long [][]memo =new long [n+1][wei+1];
	for (int i=1;i<=n;++i) {
		for (int j =0;j<=wei;++j) {
			if (j>=cost[i])
				memo[i][j]=Math.max(memo[i-1][j], value[i]+memo[i-1][(int) (j-cost[i])]);
			else
				memo[i][j]=memo[i-1][j];
		}
	}
	//System.out.println(Arrays.deepToString(memo));
	pw.println(memo[n][wei]);
	pw.flush();
	}
  static class Scanner {
		StringTokenizer stringTokenizer;
		BufferedReader bfBufferedReader;
		public Scanner(InputStream system) {
			bfBufferedReader=new BufferedReader(new InputStreamReader( system));
		}
		 public Scanner(String file) throws Exception {
	            bfBufferedReader = new BufferedReader(new FileReader( file));
	        }			 
	        public String next() throws IOException {
	            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
	                stringTokenizer = new StringTokenizer( bfBufferedReader.readLine());
	            return stringTokenizer.nextToken();
	        }
	 
	        public String nextLine() throws IOException {
	            return bfBufferedReader.readLine();
	        }
	 
	        public int nextInt() throws IOException {
	            return Integer.parseInt(next());
	        }
	 
	        public double nextDouble() throws IOException {
	            return Double.parseDouble(next());
	        }
	 
	        public char nextChar() throws IOException {
	            return next().charAt(0);
	        }
	 
	        public Long nextLong() throws IOException {
	            return Long.parseLong(next());
	        }
	 
	        public boolean ready() throws IOException {
	            return bfBufferedReader.ready();
	        }
	 
	        public void waitForInput() throws InterruptedException {
	            Thread.sleep(3000);
	        }
  }
  }

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)

int main()
{
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if (n >= b - 1)
    x = b - 1;
  ll ans = a * x / b - (x % b) / b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, P;
  cin >> N >> P;
  vector<long> dp(5001);
  int a;
  dp.at(0) = 1;
  for(int i = 0; i < N; i++){
    cin >> a;
    for(int j = 4900; j >= 0; j--){
      if(dp.at(j) >= 1)dp.at(j + a) += dp.at(j);
    }
  }
  long ans = 0;
  for(int i = 0; i <= 5000; i++){
    if(i % 2 == P)ans += dp.at(i);
  }
  cout << ans << endl;
  return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    string s;
    cin >> s;

    i64 ans = 0, tmp = 0;
    for (auto& e : s) {
        if (e == 'R') tmp++; else tmp = 0;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3652
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[n], cnt = 0;
  for (int i=0; i<n; i++) {
    scanf("%d", a+i);
    while (a[i]%2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256