akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void init();
void last();

void init() {

}

const int MAX = 15;
int h[MAX], hd[MAX];
map<int, int> hmp, hdmp;
void solve(int w, int d) {
    for (int i = 0; i < w; i++) {
        scanf("%d", h + i);
        hmp[h[i]]++;
    }
    for (int i = 0; i < d; i++) {
        scanf("%d", hd + i);
        hdmp[hd[i]]++;
    }
    auto cpmp = hmp;
    int ans1 = accumulate(h, h + w, 0);
    for (int i = 0; i < d; i++) {
        if (!(cpmp.count(hd[i]) && cpmp[hd[i]] != 0)) {
            ans1 += hd[i];
        } else {
            if (cpmp.count(hd[i])) cpmp[hd[i]]--;
        }
    }
    cpmp = hdmp;
    int ans2 = accumulate(hd, hd + d, 0);
    for (int i = 0; i < w; i++) {
        if (!(cpmp.count(h[i]) && cpmp[h[i]] != 0)) {
            ans2 += h[i];
        } else {
            if (cpmp.count(h[i])) cpmp[h[i]]--;
        }
    }
    printf("%d\n", min(ans1, ans2));
    hmp.clear();
    hdmp.clear();
}

void last() {
    exit(0);
}

int main(void) {
	int a, b, c, x, y, z, n, m, p;
	string s;
	while (cin >> n >> m, n) {
		solve(n, m);
		//break;
	}
    last();
}

Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

struct P { double x, y; };
double th = M_PI * 60.0 / 180.0;

void p(P p) {
	cout << p.x << " " << p.y << endl;
}

void koch(int n, P p1, P p2) {
	if (n == 0)return;

	P s, t, u;
	s.x = (2 * p1.x + p2.x) / 3;
	s.y = (2 * p1.y + p2.y) / 3;
	t.x = (p1.x + 2 * p2.x) / 3;
	t.y = (p1.y + 2 * p2.y) / 3;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;
	//p(s);
	//p(t);
	//p(u);

	koch(n - 1, p1, s);
	p(s);
	koch(n - 1, s, u);
	p(u);
	koch(n - 1, u, t);
	p(t);
	koch(n - 1, t, p2);

}

int main() {
	cout << fixed << setprecision(6);

	int n; cin >> n;

	P p1, p2;
	p1.x = 0; p1.y = 0;
	p2.x = 100; p2.y = 0;

	p(p1);
	koch(n, p1, p2);
	p(p2);
	return 0;
}

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

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}
void process();
int main(){
    process();
    return 0;
}
void process(){
    string s;
    int i;
    cin >> s;
    for(i=0;i<s.length();i++){
        if( (i+1) % 2 == 0 ){
            if(s[i] == 'R'){
                cout << "No" << endl;
                return;
            }
        }else{
            if(s[i] == 'L'){
                cout << "No" << endl;
                return;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import numpy as np
from itertools import combinations

h, w, k = map(int, input().split())
graph = []

for i in range(h):
  row = [1 if x == '#' else 0 for x in input()]
  graph.append(row)

graph = np.array(graph)
h_combi = []
w_combi = []

for i in range(1, h + 1):
    h_combi.extend(list(combinations(range(h), i)))
for i in range(1, w + 1):
    w_combi.extend(list(combinations(range(w), i)))

ans = 0

for hi in h_combi:
  for wi in w_combi:
    cnt = 0
    for y in hi:
      if cnt > k:
        break
      for x in wi:
        cnt += graph[y][x]
    if cnt == k:
      ans += 1

print(ans)      

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

int n,m;
string a[30][30];

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(a[i][j]=="snuke")
				{ cout<<(char)(j+'A'-1)<<i<<endl; return 0; }
	return 0;
}

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

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    multiset<int> s;
    int N;
    vector<int> A;

    cin>>N;
    for(int i=0;i<N;i++){
        int in;
        cin>>in;
        A.push_back(in);
    }

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

    int ans=0;
    for(int i=A.size()-1;i>=0;i--){
        int n=A[i];
        if(s.size()==0){
            s.insert(n);
        }
        else{
            int k=*(s.rbegin());
            ans+=k;
            s.erase(s.find(k));
            s.insert(n);
            s.insert(n);
        }
    }

    cout<<ans<<endl;
}



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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 9

using namespace std;

typedef unsigned long long ull;

const string Y = "YES", N = "NO";
int n,field[MAX][MAX],V;
vector<int> V_sum;
vector<int> coor;

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

inline bool isValid(int x,int y){ return 0 <= x && x < n && 0 <= y && y < n; }

bool dfs(ull used,int cur,int pre,int x,int y,int sum){
  if( cur >= V ) return true;

  rep(i,4){
    if( i == pre ) continue;
    int nx = x + dx[i];
    int ny = y + dy[i];
    if( !isValid(nx,ny) ) continue;
    if( (used>>(nx+ny*n)) & 1 ) continue;
    if( sum + field[ny][nx] > V_sum[cur] ) continue;

    int ncur = cur;
    int npre = ( i + 2 ) % 4;
    int nsum = sum + field[ny][nx];
    ull nused = used | (1ULL<<(nx+ny*n));
    if( sum + field[ny][nx] == V_sum[cur] ){
      ncur++;
      npre = -1;
      nsum = 0;
      nx = coor[ncur] % n;
      ny = coor[ncur] / n;
    }
    if( dfs(nused,ncur,npre,nx,ny,nsum) ) return true;
  }

  return false;  
}

int main(){

  while( scanf("%d",&n), n ){
    ull initial_state = 0ULL;
    V = 0;
    coor.clear();
    V_sum.clear();
    int sum = 0;
    rep(i,n)rep(j,n){
      scanf("%d",&field[i][j]);
      sum += field[i][j];
      if( field[i][j] < 0 ){
	V++;
	ull tmp = (1ULL<<(j+i*n));
	coor.push_back(j+i*n);
	initial_state |= (1ULL<<(j+i*n));
	V_sum.push_back(-field[i][j]);
      }
    }

    if( sum != 0 ){
      cout << N << endl;
      continue;
    }

    bool res = dfs(initial_state,0,-1,coor[0]%n,coor[0]/n,0);
    cout << (res?Y:N) << endl;
  }

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	  string s, t;
  cin >> s >> t;
  int n = size(s), m = size(t);
  int res = m;
  for (int start = 0; start + m <= n; ++start) {
    int cur = 0;
    for (int i = 0; i < m; ++i) {
      cur += s[start + i] != t[i];
    }
    res = min(res, cur);
  }
  cout << res << '\n';
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<set>
#include<vector>
using namespace std;


int N, M;
int A, B;
set<int> adj[100010];
set<int> visited;
int end_now[2];
int end_first[2];
vector<int> path_before;
vector<int> path_after;


int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> A >> B;
        adj[A].insert(B);
        adj[B].insert(A);
    }


    end_first[0] = end_now[0] = 1;
    end_first[1] = end_now[1] = *(adj[1].begin());
    visited.insert(end_now[0]);
    visited.insert(end_now[1]);

    while(1){
        bool all_visited = true;
        for(set<int>::iterator it = adj[end_now[0]].begin(); it != adj[end_now[0]].end(); it++){
            if(visited.count(*it) == 0){
                all_visited = false;
                end_now[0] = *it;
                path_before.push_back(*it);
                visited.insert(*it);
                break;
            }
        }
        if(all_visited == true){
            break;
        }
    }

    while(1){
        bool all_visited = true;
        for(set<int>::iterator it = adj[end_now[1]].begin(); it != adj[end_now[1]].end(); it++){
            if(visited.count(*it) == 0){
                all_visited = false;
                end_now[1] = *it;
                path_after.push_back(*it);
                visited.insert(*it);
                break;
            }
        }
        if(all_visited == true){
            break;
        }
    }
    cout << 2 + path_before.size() + path_after.size() << endl;
    for(int i = 0; i < path_before.size(); i++){
        if(i) cout << " ";
        cout << path_before[path_before.size() - 1 - i];
    }
    if(path_before.size() != 0){
        cout << " ";
    }
    cout << end_first[0] << " " << end_first[1];
    for(int i = 0; i < path_after.size(); i++){
        cout << " " << path_after[i];
    }
    cout << endl;
}

Measured memory_bytes: 19960
# include "iostream"
# include "cstdio"
# include "vector"

using namespace std;

vector<pair<int,int> > Map;

int N,BadEdge;

int main(){
	register int i,j;
	scanf("%d",&N);
	BadEdge=N+(!(N&1));
	for(i=1;i<=N;i++){
		for(j=i+1;j<=N;j++){
			if(i+j==BadEdge) continue;
			Map.push_back(make_pair(i,j));
		}
	}
	printf("%d\n",Map.size());
	for(i=0;i<Map.size();i++){
		printf("%d %d\n",Map[i].first,Map[i].second);
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N =1e6+5;
const long long M = (long long)1e9+7;
#define     ll      long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%I64d",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>t abs(t a) {
    if(a>=0)return a;
    return -a;
}
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     vi          vector<int>
#define     vl          vector<ll>
#define     pb          push_back
#define     all(x)      x.begin(),x.end()
#define     LB          lower_bound
#define     UB          upper_bound
#define     Mx(a,b)     (a>b)?a:b
#define     Mn(a,b)     (a<b)?a:b

int main() {
    int n=Int,m=Int,k=Int,l=Int;
    n=max(n,k);
    m=min(m,l);
    (n<=m)?printf("%d\n",m-n):puts("0");
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// list up all factors
template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    auto facs = factors(sum);
    ll ret    = 1;
    for (auto &f : facs) {
        if (f == 1)
            continue;
        vl b   = a;
        ll sum = 0;
        for (auto &x : b) {
            x %= f;
            sum += x;
        }
        sort(b.begin(), b.end());
        ll step = 0;
        for (int i = 0; i < n - (sum / f); ++i) {
            step += b[i];
        }
        if (step <= k)
            chmax(ret, f);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void swap(int* a, int* b)
{
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

int main(void)
{
	int i, j;
	int arr[5];

	for(i=0; i<5; i++)
		scanf("%d", &arr[i]);

	for(i=0; i<4; i++)
	for(j=i; j<5; j++)
	{
		if(arr[j] > arr[i])
			swap(&arr[j], &arr[i]);
	}

	printf("%d", arr[0]);
	for(i=1; i<5; i++)
		printf(" %d", arr[i]);
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll H, N; cin >> H >> N;
  vector<pair<ll,ll>> AB(N); rep(i,N) cin >> AB[i].first >> AB[i].second;
  // i番目までの技でHPがjの最小コスト
  vector<vector<ll>> dp(N+1, vector<ll>(H+1, 1e17));
  rep(x,N+1){
    dp[x][H] = 0;
  }
  rep(i,N){
    ll dam = AB[i].first;
    ll co = AB[i].second;
    for(int j=H; j>=0; j--){
      dp[i+1][j] = min({dp[i][j], dp[i][min(H,j+dam)]+co, dp[i+1][min(H,j+dam)]+co});
    }
  }
  cout << dp[N][0] << endl;
  return 0;
}


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

int main() {
  char s[4];

  scanf("%s",&s);

  int a=s[0]-'0', b=s[1]-'0', c=s[2]-'0', d=s[3]-'0';

  if (a+b+c+d==7) {
    printf("%d+%d+%d+%d=7\n", a, b, c, d);
  } else if (a+b+c-d==7){
    printf("%d+%d+%d-%d=7\n", a, b, c, d);
  } else if (a+b-c-d==7){
    printf("%d+%d-%d-%d=7\n", a, b, c, d);
  } else if (a-b-c-d==7){
    printf("%d-%d-%d-%d=7\n", a, b, c, d);
  } else if (a-b+c-d==7){
    printf("%d-%d+%d-%d=7\n", a, b, c, d);
  } else if (a-b-c+d==7){
    printf("%d-%d-%d+%d=7\n", a, b, c, d);
  } else if (a+b+c-d==7){
    printf("%d+%d+%d-%d=7\n", a, b, c, d);
  } else if (a+b-c+d==7){
    printf("%d+%d-%d+%d=7\n", a, b, c, d);
  } else if (a-b+c+d==7){
    printf("%d-%d+%d+%d=7\n", a, b, c, d);
  }
}


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

int main()
{
  int64_t N, K, x, ans = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
  {
    cin >> x;
    ans += 2 * min(x, K - x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 3

int main(){
    int h,w,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(x>=r&&y>=r&&x<=w-r&&y<=h-r){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

#define endl '\n'

using namespace std;

const int MAXS=1e4+3,MAXD=103,MOD=1e9+7;

int dp[MAXS][MAXD][2];

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

    string s;
    int d;
    cin>>s>>d;
    int n=s.size();

    dp[0][0][0]=1;
    for(int pos=0;pos<n;++pos){
        int curr=s[pos]-'0';
        for(int sum=0;sum<d;++sum){
            for(int smaller=0;smaller<2;++smaller){
                for(int digit=0;digit<10;++digit){
                    if(digit>curr and !smaller){
                        break;
                    }
                    dp[pos+1][(sum+digit)%d][smaller or (digit<curr)]=(dp[pos+1][(sum+digit)%d][smaller or (digit<curr)]+dp[pos][sum][smaller])%MOD;
                }
            }
        }
    }

    int res=(dp[n][0][0]+dp[n][0][1])%MOD;
    --res;
    cout<<(res==-1 ? MOD-1 : res)<<endl;

return 0;
}

Measured memory_bytes: 8320
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	min := a[0]
	max := a[0]

	for _, i := range a {
		if i < min {
			min = i
		} else if i > max {
			max = i
		}
	}

	fmt.Println(max - min)
}


Measured memory_bytes: 512
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
int N,A,B,C,X;
int Y[100];
int nextRand(){
  int ret = X;
  X = ((A * X) + B)%C;
  return ret;
}

int solve(){
  int count = 0;
  for(int i = 0;i < N;i++){
    while(true){
      count++;
      if(count > 10001)return 0;
      int x = nextRand();
      if(x == Y[i]){
	break;
      }
    }
  }
  return count;
}

int main(){
  ios::sync_with_stdio(false);
  while((cin >> N >> A >> B >> C >> X) && N+A+B+C+X != 0){
    for(int i = 0;i < N;i++){
      cin >> Y[i];
    }
    cout << solve() -1 << endl;
  }
}

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

int main(){
  int a,b;
  cin >>a >>b;
  int ans = a+b;
  if(ans%2 == 0) cout << ans/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])puts("YES");
	else puts("NO");
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> judge(N);
  vector<int> count(4);

  for(int i = 0; i < N; i++){

    cin >> judge.at(i);
    string _judge = judge.at(i);
    if(_judge == "AC") count.at(0)++;
    if(_judge == "WA") count.at(1)++;
    if(_judge == "TLE") count.at(2)++;
    if(_judge == "RE") count.at(3)++;
  }

  cout << "AC x " + to_string(count.at(0)) << endl;
  cout << "WA x " + to_string(count.at(1)) << endl;
  cout << "TLE x " + to_string(count.at(2)) << endl;
  cout << "RE x " + to_string(count.at(3)) << endl;

}

Measured memory_bytes: 6304
using System;
using System.Linq;
using System.Collections.Generic;

namespace _0030
{
    
    class Program
    {

        static int cnt;
        static long n;

        //k桁までの357の組み合わせを考える
        //組み合わせる値はｓ
        //そこから条件に合致するものをカウント
        //小さい順に組み合わせを見ていくので、もしnを超えたらメソッドを終了
        static void Solutionn(string s, string str, int cnt3, int cnt5, int cnt7)
        {

            if(s == "3")
            {
                cnt3++;
            }
            else if(s == "5")
            {
                cnt5++;
            }
            else if(s == "7")
            {
                cnt7++;
            }

            //Console.WriteLine(str);

            str += s;

            if (!string.IsNullOrEmpty(str))
            {
                if (n < long.Parse(str))
                {
                    //Console.WriteLine($"{str}なのでreturn");
                    return;
                }
            }
            
            if(cnt3 > 0 && cnt5 > 0 && cnt7 > 0)
            {
                //Console.WriteLine($"{str}をカウント");
                cnt++;
            }

            Solutionn("3", str, cnt3, cnt5, cnt7);
           
            Solutionn("5", str, cnt3, cnt5, cnt7);
            
            Solutionn("7", str, cnt3, cnt5, cnt7);

        }
        
        static void Main(string[] args)
        {

            n = long.Parse(Console.ReadLine());

            cnt = 0;                        
           

            string str = null;

            Solutionn(null, str, 0, 0, 0);

            Console.WriteLine(cnt);

        }
    }
}

Measured memory_bytes: 13140
x = int(input())
if 400 <= x:
    if x >= 600:
        if x >= 800:
            if x >= 1000:
                if x >= 1200:
                    if x >= 1400:
                        if x >= 1600:
                            if x >= 1800:
                                print(1)
                            else:
                                print(2)
                        else:
                            print(3)
                    else:
                        print(4)
                else:
                    print(5)
            else:
                print(6)
        else:
            print(7)
    else:
        print(8)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

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

    int sx = 0,sy = 0,diff = 0;
    
    string ans = "Yes";
    for(int i = 0;i < n;i++){
        int a,b,c; cin >> a >> b >> c;
        sx = abs(sx-b); sy = abs(sy-c);
        diff = abs(a-diff);
        if(sx+sy > diff || diff % (sx+sy) != 0){
            ans = "No";
            break;
        }
        sx = b; sy = c; diff = a;
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int i,flag=0;
    for(i=0;i<s.length();i++)
    {
        if(i%2==0)
        {
            if(s[i]=='R'||s[i]=='U'||s[i]=='D')
                continue;
            else 
            {
                flag=1;
                break;
            }
        }
        else
        {
            if(s[i]=='L'||s[i]=='U'||s[i]=='D')
                continue;
            else
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==0)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
const ll mod = 998244353ll;
// const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    assert(n >= r);
    assert(n >= 0);
    assert(r >= 0);
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,a,b,c,d,e,q;

ll x[100005], y[100005], z[100005];
ll k;

void solve(){
    cin >> n >> k;
    for(ll i=0;i<k;i++){
        cin >> m;
        for(ll i=0;i<m;i++){
            cin >> a;
            x[a] ++;
        }
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)if(x[i])ans ++;
    p(n - ans);
    return;
}

int main(){

    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 3664
X, Y = map(int, input().split())

res = 10**10

if abs(X) == abs(Y):
    res = 1

if abs(X) < abs(Y):
    cnt = 0
    if X < 0:
        cnt += 1
    cnt += abs(abs(X)-abs(Y))
    if Y < 0:
        cnt += 1
    res = min(cnt, res)

if abs(X) > abs(Y):
    cnt = 0
    if X > 0:
        cnt += 1
    cnt += abs(abs(X)-abs(Y))
    if Y > 0:
        cnt += 1
    res = min(cnt, res)

print(res)

Measured memory_bytes: 9112
"use strict";
    
const main = arg => {
    const N = parseInt(arg.split("\n")[0]);
    
    if(N === 1 || N === 2) {
        console.log(1);
        return;
    }
    
    for(let i=1; i<N; i++) {
        if(Math.pow(i, 2) > N) {
            console.log(Math.pow(i-1, 2));
            return;
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    
    int count = 0;
    int minj;
    for(int i = 0;i < n;i++){
        minj  = i;
        for(int j = i;j < n;j++){
            if(a[j] < a[minj]){
                minj = j; 
            }
        }
        if(a[i] != a[minj]){
            count++;
        }
        int x;
        x = a[minj];
        a[minj] = a[i];
        a[i] = x;
        
    }
    for(int i = 0;i < n;i++){
        cout << a[i];
        if(i != n - 1){
            cout << " ";    
        }
    }
    cout << endl << count << endl;
}


Measured memory_bytes: 3092
#include<cstdio>
#define MAX 100005
#define NIL -1

struct Node{int p, l, r;};
Node T[MAX];
int n, D[MAX];


void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("depth = %d, ", D[u]);

    if(T[u].p == NIL) printf("root, ");
    else if(T[u].l == NIL) printf("leaf, ");
    else printf("internal node, ");

    printf("[");

    for(int i=0, c = T[u].l; c!= NIL; i++, c =T[c].r){
        if(i) printf(", ");
        printf("%d", c);
    }

    printf("]\n");
}


// 再帰的に深さを求める
int rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p); // 右の兄弟に同じ深さを設定
    if(T[u].l != NIL) rec(T[u].l, p+1); // 最も左の子に自分の深さ+1を設定
}

int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for(int i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    int v, d, l, c; // 接点の番号, 次数, , j番目の子の接点番号
    for(int i=0; i<n; i++){
        scanf("%d %d", &v, &d);
        for(int j = 0; j<d; j++){ // 子の接点番号ループ
            scanf("%d", &c);
            if(j==0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    int r;
    for(int i=0; i<n;i++){
        if(T[i].p ==NIL) r=i;
    }
    rec(r,0);

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



Measured memory_bytes: 7336
n,m=map(int,raw_input().split())
a=[map(int,raw_input().split()) for i in range(n)]
b=[input() for i in range(m)]
c=[0 for i in range(n)]
for i in range(n):
    for j in range(m):
        c[i]=c[i]+(a[i][j]*b[j])
for i in range(n):
    print c[i]


Measured memory_bytes: 4872
#ifdef ONPC
    # define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <unordered_set>
#include <complex>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <cassert>
#include <random>
#include <iomanip>

#ifdef ONPC
    #define deb(a) cerr << "      " << #a << " = " << a << endl;
#else
    #define deb(a)
#endif

#define sz(a) (a).size()

using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnd(time(0));

typedef long long ll;
typedef long double ld;

int solve()
{
    int n;
    if (!(cin >> n))
        return 1;
    int q;
    cin >> q;
    string s;
    cin >> s;
    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        cnt[i + 1] = cnt[i];
        if (i + 1 < n && s[i + 1] == 'C' && s[i] == 'A')
            cnt[i + 1]++;
    }
    while (q--)
    {
        int l, r;
        cin >> l >> r;
        cout << cnt[r - 1] - cnt[l - 1] << ' ';
    }
    cout << '\n';
    return 1;
}

int32_t main()
{
    #ifdef ONPC
        freopen("in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1e9;
    //cin >> T;
    while (T--)
    {
        if (solve())
            break;
        #ifdef ONPC
            cout << "\n__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
    return 0;
}



Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll H, W; cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }
    return 0;
}

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


int main(){
	int n;cin>>n;
	vector<vector<int> > arr(n,vector<int>(2));
	int w ; cin>>w;
	for(int i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1];
	}
	vector<long long> dp(w+1,INT_MIN);
	dp[0] = 0;
	long long ans =0;
	for(int i=0;i<n;i++){
		for(int j=w;j>0;j--){
			if(j-arr[i][0]>=0)
			dp[j] = max(dp[j],dp[j-arr[i][0]] + arr[i][1] );
			ans = max(ans,dp[j]);
		}
			
	}
	cout<<ans;
	
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n,m;
	cin>>n>>m;
	ll s =0;
	ll t;
	for(ll i=0; i<m; i++){
		cin>>t;
		s += t;
	}
	if(s>n){
		cout<<"-1";
	}
	else{
		cout<<n-s;	}
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int X;
    cin >> X;
    int ans = 1;
    FOR(p, 2, sqrt(X)) {
        int b = p * p;
        while (b <= X) {
            chmax(ans, b);
            b *= p;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    string s; cin >> s;
    rep(i, 3) {
        if(s[i] == '1') s[i] = '9';
        else if(s[i] == '9') s[i] = '1';
    }
    cout << s;
}


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

int main() {
  int x, y=0;
  cin >> x;
  
  if(x>81){
    cout<< "No" << endl;
  }
  
  else{
  	//判定
  	for(int i=1;i<=9;i++){
      for(int j=1;j<=9;j++){
      	if(i*j==x){
          cout <<"Yes" << endl;
          y = 1;
          break;
        }
      }
      if(y==1){
        break;
      }
    }
    if(y==0){
       cout<< "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vc<ll> a(n),b(n);
    rep(i,n){
        ll x,y; cin >> x >> y;
        a[i] = x;
        b[i] = y;
    }
    sort(all(a)); sort(all(b));
    if(n % 2 == 1){
        ll x,y; x = a[n/2]; y = b[n/2];
        cout << y-x+1 << endl;
    } else {
        ll x,y; x = a[n/2]+a[n/2-1]; y = b[n/2]+b[n/2-1];
        cout << y-x+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 6428
import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))


Measured memory_bytes: 9148
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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


#############
# Main Code #
#############

N = getN()

next = [
[0, 1],
[0, 1, 2],
[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 5, 6],
[5, 6, 7],
[6, 7, 8],
[7, 8, 9],
[8, 9]
]

ans = []

def dfs(s):
    global ans
    if len(s) >= 11:
        return
    # 上限を超えない範囲で実行
    else:
        ans.append(int(s))
        # dfs
        s_last = int(s[-1])
        for i in next[s_last]:
            dfs(s + str(i))

# 始点は1~9
for i in range(1, 10):
    dfs(str(i))

ans.sort()
print(ans[N - 1])

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in(),K=in();
	vector<int> pos,neg,spos,sneg;
	REP(i,N){
		int x=in();
		if(x<0) neg.push_back(x);
		else pos.push_back(x);
	}
	reverse(ALL(neg));

	for(int i=0,ei=pos.size();i<ei;i++){
		if(i==0) spos.push_back(pos[0]);
		else spos.push_back(pos[i]-pos[i-1]);
	}
	for(int i=0,ei=neg.size();i<ei;i++){
		if(i==0) sneg.push_back(-neg[0]);
		else sneg.push_back(-neg[i]+neg[i-1]);
	}

	int pos_end = K<=pos.size() ? K : pos.size();
	int old = 0;
	int pos_sum = 0;
	for(int i=0;i<pos_end;i++){
		pos_sum += spos[i];
	}
	old = 0;
	int neg_sum = 0;
	int neg_end = K-pos_end;
	for(int i=0;i<neg_end;i++){
		neg_sum += sneg[i];
	}
	int sum = min(2*pos_sum+neg_sum,pos_sum+2*neg_sum);
	int max_neg_end = K<=neg.size() ? K : neg.size();
	for(neg_end++;neg_end<max_neg_end;neg_end++,pos_end--){
		pos_sum -= spos[pos_end-1];
		neg_sum += sneg[neg_end-1];
		int lsum = min(2*pos_sum+neg_sum,pos_sum+2*neg_sum);
		sum = min(sum,lsum);
	}
	
	cout << sum << endl;
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,K,Q;
ll pt[101010], A[101010];
ll i, j, k;
int main(){
    scanf("%lld%lld%lld", &N, &K, &Q);
    fornum(i,0,Q){
        scanf("%lld", &A[i]);
        pt[A[i]]++;
    }
    fornum(i,0,N){
        printf("%s\n", pt[i + 1]+K - Q > 0 ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct SCC
{
	vector<vector<int> > G;
	vector<vector<int> > rG;
	vector<int> vs;
	vector<bool> used;
	vector<int> cmp;
	int sz,newsz;
	SCC(int n):G(n),rG(n),used(n,false),cmp(n){sz = n;}
	
	void add_edge(int from,int to)
	{
		G[from].PB(to);
		rG[to].PB(from);
	}
	
	void dfs(int v)
	{
		used[v] = true;
		REP(i,G[v].size())
		{
			if(!used[G[v][i]])dfs(G[v][i]);
		}
		vs.PB(v);
	}
	
	void rdfs(int v,int k)
	{
		used[v] = false;
		cmp[v] = k;
		REP(i,rG[v].size())
		{
			if(used[rG[v][i]])rdfs(rG[v][i],k);
		}
	}
	
	int reMake()
	{

		vs.clear();
		REP(i,sz)if(!used[i])dfs(i);
		int k = 0;
		for(int i = sz-1;i >= 0;i--)
		{
			if(used[vs[i]])
			{
				rdfs(vs[i],k++);
			}
		}
		return newsz = k;
	}
	
	
	
	void makeList(vector<vector<int> > &v)
	{
		REP(i,sz)
		{
			REP(j,G[i].size())
			{
				if(cmp[i] == cmp[G[i][j]])continue;
				v[cmp[i]].PB(cmp[G[i][j]]);
			}
		}
	}

	void makeReverseList(vector<vector<int> > &v)
	{
		REP(i,sz)
		{
			REP(j,G[i].size())
			{
				if(cmp[i] == cmp[G[i][j]])continue;
				v[cmp[G[i][j]]].PB(cmp[i]);
			}
		}
	}
	
	int scc_node(int n)
	{
		return cmp[n];
	}
};


#define MOD 1000000007 

vector<vector<int> > v(1000);
vector<vector<int> > rv(1000);

bool check[10001];
ll dp[1111];

void dfs(int n)
{
	check[n] = true;
	
	if(rv[n].size() == 0)
	{
		dp[n] = 1;
		return;
	}
	
	REP(i,rv[n].size())
	{
		dfs(rv[n][i]);
	}

	ll tmpa = 1;
	ll tmpb = 1;	
	REP(i,rv[n].size())
	{
		tmpa = (tmpa * ((1+dp[rv[n][i]])%MOD))%MOD;
	}
	dp[n] = tmpa;
	
	return;
}
	

int main()
{
	int n,m;cin >> n >> m;
	
	SCC scc(n);
	REP(i,m)
	{
		int a,b;cin >> a >> b;
		a--;b--;
		scc.add_edge(a,b);
	}
	
	scc.reMake();
	scc.makeList(v);
	scc.makeReverseList(rv);
	
	
	ll ans = 1;
	REP(i,scc.newsz)
	{
		if(v[i].size() == 0 && !check[i])
		{
			dfs(i);
			ans = (ans * (1+dp[i]))%MOD;
		}
	}		
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3260
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		int x=Integer.parseInt(scan.next());
    		int y=Integer.parseInt(scan.next());
    		
    	    int[] a={0,1,3,1,2,1,2,1,1,2,1,2,1};
    	    if(a[x]==a[y]){
    	      System.out.println("Yes");
    	    }else{
    	      System.out.println("No");
    	    }
    		
    	
  
    				
 
     
    }
    }

Measured memory_bytes: 21844
H,W=map(int,input().split())
N=int(input())
a=list(map(int, input().split()))

g = [[0]*W for i in range(H)]
h = 0
w = 0
for i in range(N):
  for j in range(a[i]):
    g[h][w] = i+1
    if h % 2 == 0:
      if w == (W-1):
        h += 1
      else:
        w += 1
    else:
      if w == 0:
        h += 1
      else:
        w -= 1
        
for i in range(H):
  for j in range(W):
    print(g[i][j], end=" ")
  print("")

Measured memory_bytes: 9512
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <cmath>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int a = 0;
    int b = 0;
    int ab = 0;
    int ans = 0;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        for(int j=0; j<s.size() - 1; j++){
            if(s[j] == 'A' && s[j+1] == 'B'){
                ans++;
            }
        }
        if(s[0] == 'B' && s[s.size()-1] == 'A'){
            ab++;
        }else if(s[0] == 'B' && s[s.size()-1] != 'A'){
            b++;
        }else if(s[0] != 'B' && s[s.size()-1] == 'A'){
            a++;
        }
    }
    int add = 0;
    add += ab - 1;
    add += a < b ? a : b;
    if(a >= 1 || b >= 1){
        add++;
    }
    if(a == 0 && b == 0 && ab == 0){
        add = 0;
    }
    ans += add;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		double [] in = new double [a];
        for(int i=0;i<a;i++){
                             in[i] = (sc.nextInt()+1)*0.5;
                            }
		double [] in2 = new double [a-b+1];
        for(int i=0;i<a-b+1;i++){if(i==0){for(int j=0;j<b;j++){in2[i]+=in[j];}
                                         }else{in2[i]=in2[i-1]+in[b+i-1]-in[i-1];
                                             }                                                 
                                }
        Arrays.sort(in2);
		System.out.println(in2[a-b]);
	}
}

Measured memory_bytes: 85212
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i = s;i <= t;i ++)
#define dow(i,t,s) for(int i = t;i >= s;i --)
#define REP(i,x) for(int i = 0;i < x.size();i ++)
#define DOW(i,x) for(int i = (int)s.size();i >= 0;i --)

#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound


#define eps 1e-6
#define N
#define INF

#define SZ(x) ((int)(x).size())


using namespace std;

typedef vector<int> VI;
typedef long long LL;
typedef double db;
typedef pair<int,int> PII;

int n , m , c[20][20] , ans , a;

int main ()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    scanf("%d%d",&n,&m);
    rep(i,0,9)rep(j,0,9)scanf("%d",&c[i][j]);
    rep(k,0,9)rep(i,0,9)rep(j,0,9)
        c[i][j] = min(c[i][j] , c[i][k] + c[k][j]);

    rep(i,1,n)rep(i,1,m)scanf("%d",&a) , ans += (a == -1) ? 0 : c[a][1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        while(true){
            int H =sc.nextInt();
            int W =sc.nextInt();
            if(H==0 && W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if( (i+j) % 2 == 1 )System.out.printf(".");
                    if( (i+j) % 2 == 0 )System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 62260