akhauriyash/Code-Regression huggingface dataset:
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(H)]
ans = []
cnt = 0

for h in range(H):
    for w in range(W):
        if A[h][w] % 2 != 0:
            if w < W - 1:
                A[h][w] -= 1
                A[h][w + 1] += 1
                ans.append((h + 1, w + 1, h + 1, w + 2))
                cnt += 1
            elif h < H - 1:
                A[h][w] -= 1
                A[h + 1][w] += 1
                ans.append((h + 1, w + 1, h + 2, w + 1))
                cnt += 1

print(cnt)
for a in ans:
    print(*a)


Measured memory_bytes: 75484
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
        int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int64_t> p,q,r;
    for(int i=0;i<a;i++) {
        int64_t s;
        cin >> s;
        p.push_back(s);
    }
    for(int i=0;i<b;i++) {
        int64_t s;
        cin >> s;
        q.push_back(s);
    }
    for(int i=0;i<c;i++) {
        int64_t s;
        cin >> s;
        r.push_back(s);
    }

    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    sort(q.begin(),q.end());
    reverse(q.begin(),q.end());

    if(a!=x) for(int i=0;i<a-x;i++) p.pop_back();
    if(b!=y) for(int i=0;i<b-y;i++) q.pop_back();

    for(int i=0;i<q.size();i++) p.push_back(q.at(i));
    for(int i=0;i<r.size();i++) p.push_back(r.at(i));

    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());

    int64_t sum=0;
    for(int i=0;i<(x+y);i++) sum += p.at(i);

    cout << sum << endl;
}

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#define llint long long
#define mod 1000000007

using namespace std;

llint Q;
priority_queue<llint> leftQ;
priority_queue<llint, vector<llint>, greater<llint> > rightQ;

int main(void)
{
	cin >> Q;
	llint t, a, b;
	llint lsum = 0, rsum = 0, bsum = 0;
	for(int q = 0; q < Q; q++){
		cin >> t;
		if(t == 1){
			cin >> a >> b;
			bsum += b;
			if(leftQ.size() == 0 || leftQ.top() >= a){
				leftQ.push(a);
				lsum += a;
				if(leftQ.size() >= rightQ.size()+2){
					rightQ.push(leftQ.top());
					rsum += leftQ.top();
					lsum -= leftQ.top();
					leftQ.pop();
				}
			}
			else{
				rightQ.push(a);
				rsum += a;
				if(rightQ.size() >= leftQ.size()+1){
					leftQ.push(rightQ.top());
					lsum += rightQ.top();
					rsum -= rightQ.top();
					rightQ.pop();
				}
			}
		}
		else{
			llint x = leftQ.top();
			llint ans = x * leftQ.size() - lsum;
			ans += rsum - x * rightQ.size();
			cout << x << " " << ans + bsum << endl;
		}
		//cout << lsum << " " << rsum << endl;
	}
	return 0;
}

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

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

template <typename T> T vec_max(vector<T>& a) {
	return *(max_element(a.begin(), a.end()));
}

struct segtreelz {
	int n;
	vector<ll> tree, lazy;

	explicit segtreelz(int _n) {
		n = _n;
		tree.resize(4 * _n, 0);
		lazy.resize(4 * _n, 0);
	}

	static void add(vector<ll> &v, int node, ll val) {
		v[node] += val;
	}

	void lz(int node) {
		add(lazy, 2 * node, lazy[node]);
		add(tree, 2 * node, lazy[node]);
		add(lazy, 2 * node + 1, lazy[node]);
		add(tree, 2 * node + 1, lazy[node]);
		lazy[node] = 0;
	}

	void update(int l, int r, int ql, int qr, ll val, int node) {
		if (ql > qr) return;
		if (ql > r || qr < l) return;
		if (ql <= l && qr >= r) {
			add(tree, node, val);
			add(lazy, node, val);
			return;
		}
		lz(node);
		int mid = l + (r - l) / 2;
		update(l, mid, ql, qr, val, 2 * node);
		update(mid + 1, r, ql, qr, val, 2 * node + 1);
		tree[node] = max(tree[2 * node], tree[2 * node + 1]);
	}

	ll query(int l, int r, int ql, int qr, int node) {
		if (ql > qr) return -1e18;
		if (ql > r || qr < l) return -1e18;
		if (ql <= l && qr >= r) return tree[node];
		lz(node);
		int mid = l + (r - l) / 2;
		return max(query(l, mid, ql, qr, 2 * node), query(mid + 1, r, ql, qr, 2 * node + 1));
	}

};

const ll INF = 1e18;

class TaskW {
public:
	void solve(std::istream& in, std::ostream& out) {
		int N, M;
		in >> N >> M;
		vector<int> ls(M), rs(M);
		vector<ll> a(M), dp(N + 1, -INF);
		vector<vector<int>> st(N + 1), en(N + 1);
		for (int i = 0; i < M; i++) {
			in >> ls[i] >> rs[i] >> a[i];
			st[ls[i]].push_back(i);
			en[rs[i]].push_back(i);
		}
		dp[0] = 0;
		segtreelz root = segtreelz(4 * N + 5);
		for (int i = 1; i <= N; i++) {
			for (int idx : st[i]) {
				root.update(0, N, 0, i - 1, a[idx], 1);
			}
			dp[i] = root.query(0, N, 0, i - 1, 1);
			root.update(0, N, i, i, dp[i], 1);
			for (int idx : en[i]) {
				root.update(0, N, 0, ls[idx] - 1, -a[idx], 1);
			}
		}
		out << vec_max(dp);
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskW solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int N,M;
int imos[100010];
int main(){
    cin >> N >> M;
    int l,r;
    for(int i=1;i<=M;i++){
        cin >> l >> r;
        imos[l]++; imos[r+1]--;
    }
    int ans = 0;
    for(int i=1;i<=(int) 1e5;i++){
        imos[i] += imos[i-1];
        ans += (imos[i]==M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  ll ans = 0;
  FOR(i,0,s.length()) {
    ans += s[i]-'0';
  }
  FOR(i,0,s.length()) {
    if(s[i] == '0') continue;
    ll tmp = s[i] - '0' - 1;
    tmp += 9 * (s.length() - i - 1);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll f(ll n, ll v);

ll N,W;
ll value[110], weight[110];
vector<vector<ll>> dp(110, vector<ll>(1000010,-1));

ll max_sum = 0, max_value = 0;

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

    cin>>N>>W;
    for(ll i=1; i<=N; i++)
    {
        cin>>weight[i]>>value[i];
        max_sum+=value[i];
    }
    max_value = (max_sum+(max_sum+1))/2;

    for(ll i=max_value; i>=0; i--)
    {
            if(f(1,i) <= W)
            {
                cout<<i<<endl;
                return 0;
            }
    }

    return 0;
}

ll f(ll n, ll v)
{
    if(dp[n][v] != -1)
    {
        return dp[n][v];
    }
    if(v == 0)
    {
        return 0;
    }
    if(n == N)
    {
        if(v != value[n])
        {
            return INF;
        }
        else
        {
            return dp[n][v] = weight[n];
        }
    }

    if(value[n] > v)
    {
        return dp[n][v]  = f(n+1, v);
    }

    return dp[n][v] = min( weight[n]+f(n+1,v-value[n]) , f(n+1,v) );
}

Measured memory_bytes: 867840
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.


Measured memory_bytes: 1372
from bisect import bisect_left, bisect_right

N = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0

for a in range(N):
    for b in range(a + 1, N):
        c = bisect_left(L, L[a] + L[b])
        ans += c - b - 1
print(ans)


Measured memory_bytes: 42988
n,m = map(int, input().split())

x = [False]*n
y = [0]*n

for i in range(m):
  a,b = input().split()
  a = int(a) - 1
  if b =='AC' and x[a] == False:
    x[a] = True
  elif b == 'WA' and x[a] == False:
    y[a] += 1

ac = 0
wa = 0
for i in range(n):
  if x[i]:
    ac += 1
    wa += y[i]
print(ac,wa)

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

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

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

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

const int MAX_N = 2000;
int n;
pli a[MAX_N];
ll dp[MAX_N + 1][MAX_N + 1];

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> a[i].fst;
        a[i].snd = i;
    }

    sort(a, a + n, greater<pli>());

    for (int s = 1; s <= n; s++) {
        int i = s - 1;
        for (int x = 0; x <= s; x++) {
            int y = s - x;
            if (x > 0)
                chmax(dp[x][y], dp[x - 1][y] + a[i].fst * abs(a[i].snd - (x - 1)));
            if (y > 0)
                chmax(dp[x][y], dp[x][y - 1] + a[i].fst * abs((n - y) - a[i].snd));
            //printf("dp[%d][%d]=%lld\n", x, y, dp[x][y]);
        }
    }

    ll ans = 0;
    for (int x = 0; x <= n; x++) {
        chmax(ans, dp[x][n - x]);
    }

    cout << ans << endl;

    return 0;
}

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

long long int m;
string c;
vector<long long int> a;
long long int digit;
long long int mod=1e9+7;
long long int digsum[10];

long long int pow(long long int a,int b){
    //cout<<a<<" "<<b<<endl;
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    long long int res;
    res=pow(a,b/2)*pow(a,b/2)%mod;
    if(b%2==1){
        res*=a;
    }
    return res%mod;
}


int main(){
    
    cin>>m;
    cin>>c;
    if(m==0&&c.size()==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0; i<c.size(); i++){
        long long int a=10;
        digit=pow(a,int(c.size())-i-1);
        //cout<<int(c[i]-'0')<<endl;
        digsum[int(c[i]-'0')]+=digit;
        digsum[int(c[i]-'0')]%=mod;
        //cout<<digsum[int(c[i]-'0')]<<endl;
    }
    /*for(int i=0; i<10; i++){
        cout<<digsum[i]<<endl;
    }*/
    for(int i=0; i<10; i++) a.push_back(i);
    do{
        long long int sum=0;
        for(int i=0; i<10; i++){
            sum+=digsum[i]*a[i];
            sum%=mod;
        }
        //cout<<sum<<endl;
        if(sum==m && a[int(c[0]-'0')]!=0){
            for(int i=0; i<c.size(); i++){
                cout<<a[int(c[i]-'0')];
            }
            cout<<endl;
            return 0;
        }
    }while(next_permutation(a.begin(), a.end()));
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3340
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> masu(h,vector<char>(w));
  REP(i,h) {
    REP(j,w) {
      cin >> masu[i][j];
    }
  }
  REP(i,h) {
    REP(j,w) {
      if(masu[i][j] == '#') continue;

      int cnt = 0;
      if(i   != 0 && j   != 0 && masu[i-1][j-1] == '#') cnt++;
      if(i   != 0             && masu[i-1][j]   == '#') cnt++;
      if(i   != 0 && j+1 != w && masu[i-1][j+1] == '#') cnt++;
      if(            j   != 0 && masu[i]  [j-1] == '#') cnt++;
      if(            j+1 != w && masu[i]  [j+1] == '#') cnt++;
      if(i+1 != h && j   != 0 && masu[i+1][j-1] == '#') cnt++;
      if(i+1 != h             && masu[i+1][j]   == '#') cnt++;
      if(i+1 != h && j+1 != w && masu[i+1][j+1] == '#') cnt++;
      masu[i][j] = (char)(cnt+'0');
    }
  }
  REP(i,h) {
    REP(j,w) {
      cout << masu[i][j];
      if(j+1 == w) {
        cout << endl;
        continue;
      }
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int max = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int[] b = new int[100010];
		for (int i = 0; i < n; i++) {
			b[a[i]]++;
		}
		for (int i = 0; i < 100005; i++) {
			int c = b[i]+b[i+1]+b[i+2];
			if (c >= max) {
				max = c;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 49996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String[] s = fs.nextLine().split("");
		String[] t = fs.nextLine().split("");
		
		Arrays.sort(s);
		Arrays.sort(t);
		
		StringBuffer sb_s = new StringBuffer();
		for(int i = 0; i < s.length; i++) {
			sb_s.append(s[i]);
		}
		
		StringBuffer sb_t = new StringBuffer();
		for(int i = t.length - 1; i >= 0; i--) {
			sb_t.append(t[i]);
		}
		
		if(sb_s.toString().compareTo(sb_t.toString()) < 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

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

int h, w;
string a[1010];
int mas[1010][1010];

struct xyc
{
    int x, y, cnt;
    xyc() {}
    xyc(int x, int y, int cnt) : x(x), y(y), cnt(cnt) {}
};

int main()
{
    queue<xyc> que;
    
    ci >> h >> w;
    rep(i, h) {
	ci >> a[i];
	rep(j, w) {
	    if(a[i][j] == '#') {
		mas[i][j] = 0;
		que.push(xyc(j, i, 0));
	    } else {
		mas[i][j] = -1;
	    }
	}
    }

    int ans = 0;
    
    while(!que.empty()) {
	xyc q = que.front(); que.pop();

	rep(i, 4) {
	    int nx = q.x + dx[i];
	    int ny = q.y + dy[i];

	    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
	    if(mas[ny][nx] != -1) continue;
	    ans = mas[ny][nx] = q.cnt + 1;
	    que.push(xyc(nx, ny, q.cnt + 1));
	}
	
    }
    
    co << ans << en;
    
    return 0;
}


Measured memory_bytes: 17424
import sys

n, m = map(int, input().split())

a = []
for i in range(n):
    a.append(list(input()))

b = []
for i in range(m):
    b.append(list(input()))

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if k <= m-2:
                if a[i+k][j:j+m] == b[k]:
                    continue
                else:
                    break
            else:
                if a[i+k][j:j+m] == b[k]:
                    print("Yes")
                    sys.exit()
                else:
                    break

print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    rep(i, s.size()-2){
        if(s.substr(i, 3)=="ABC") cnt++;
    }
    cout << cnt << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
from math import ceil
n,h=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
dmax=max(a)
b.sort(reverse=True)
ans=0
for d in b:
  if h<=0:
    print(ans)
    exit()
  if d<dmax:
    break
  h-=d
  ans+=1
if h<=0:
  print(ans)
  exit()
print(ans+ceil(h/dmax))

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

int main() {
    string str;

    while (true) {
        cin >> str;
        if (str == "0") break;

        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
            sum += (int)(str[i] - '0');
        }

        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
#include <stdio.h>

int main(void){
    
    int n;
    scanf("%d",&n);

    int a[1000000];
    for(int i=1; i<=n+1; i++){
        scanf("%d",&a[i]);
    }

    int b[1000000];
    for(int i=1; i<=n; i++){
        scanf("%d",&b[i]);
    }

    long long cnt = 0;
    
    for(int i=1; i<=n+1; i++){
       if(a[i]+a[i+1]>=b[i]){
           cnt+=b[i];
           if(a[i]<=b[i]){
               a[i+1]=a[i]+a[i+1]-b[i];
           }
       }
       else{
            cnt+=a[i]+a[i+1];
            a[i+1]=0;
       }
    }

    printf("%lld\n", cnt);

    return 0;
}


Measured memory_bytes: 4480
#include<stdio.h>
int main()
{
    long long int n,m,a,x,r=0,i;
    scanf("%lld %lld",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%lld",&a);
        r+=a;

    }
      if(n>r){
            printf("%lld\n",n-r);

        }
        else if(r>n){
            printf("-1\n");
        }
        else if(r==n){
            printf("0\n");
        }


    return 0;
}



Measured memory_bytes: 1708
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
x=[[int(i) for i in input().split()] for i in range(m)]
ans=min(A)+min(B)

for s,t,u in x:
    tmp=A[s-1]+B[t-1]-u
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 32544
#include<bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define int long long
using namespace std;
typedef long long ll;

struct Mat {
	ll m[4][4];
};//存储结构体
Mat a,e; //a是输入的矩阵，e是输出的矩阵
Mat Mul(Mat x,Mat y) {
	Mat c;
	for(int i=1; i<=2; ++i) {
		for(int j=1; j<=2; ++j) {
			c.m[i][j] = 0;
		}
	}
	for(int i=1; i<=2; ++i) {
		for(int j=1; j<=2; ++j) {
			for(int k=1; k<=2; ++k) {
				c.m[i][j] = (c.m[i][j] + x.m[i][k]*y.m[k][j]%mod)%mod;
			}
		}
	}
	return c;
}
Mat pow(Mat x,ll y) { //矩阵快速幂
	Mat ans;
	ans.m[1][1]=ans.m[2][2]=1;
	ans.m[1][2]=ans.m[2][1]=0;
	while(y) {
		if(y&1) ans = Mul(ans,x);
		x = Mul(x,x);
		y>>=1;
	}
	return ans;
}
char mapp[1005][1005];
int mappp[1005][1005];
ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b&1) res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
signed main() {
	int n, m;
	ll k;
	cin >> n >> m >> k;
	int ok1, ok2;
	ll cnt = 0;
	ok1=ok2=0;
	for(int i=1; i<=n; i++) {
		scanf("%s",mapp[i]+1);
	}
	if(k==0) {
		printf("1\n");
		return 0;
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			mappp[i][j] = mapp[i][j]=='#';
			cnt += mapp[i][j]=='#';
		}
	}
	for(int i=1; i<=n; i++) {
		ok1 += mappp[i][1]&&mappp[i][m];
	}
	for(int i=1; i<=m; i++) {
		ok2 += mappp[1][i]&&mappp[n][i];
	}
	if(ok1&&ok2) {
		printf("1\n");
		return 0;
	} else if((!ok1)&&(!ok2)) {
		printf("%lld\n",qpow(cnt, k-1));
		return 0;
	}
	if(ok1) {
		Mat q;
		int count=0;
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=m-1; j++) {
				count+=mappp[i][j]&&mappp[i][j+1];
			}
		}
		q.m[1][1] = cnt;
		q.m[1][2] = count;
		q.m[2][2] = ok1;
		q.m[2][1] = 0;
		q = pow(q, k-1);
		printf("%lld\n",((q.m[1][1]-q.m[1][2])%mod+mod)%mod);
		return 0;
	} else if(ok2) {
		Mat q;
		int count=0;
		for(int i=1; i<=n-1; i++) {
			for(int j=1; j<=m; j++) {
				count+=mappp[i][j]&&mappp[i+1][j];
			}
		}
		q.m[1][1] = cnt;
		q.m[1][2] = count;
		q.m[2][2] = ok2;
		q.m[2][1] = 0;
		q = pow(q, k-1);
		printf("%lld\n",((q.m[1][1]-q.m[1][2])%mod+mod)%mod);
		return 0;
	}

}




Measured memory_bytes: 12644
from collections import deque

def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head)

if __name__ == '__main__':
	n, q = map(int, input().split())
	A = deque()

	for i in range(n):
		name, time = input().split()
		A.append([name, int(time)])
	
	round_robin_scheduling(n, q, A)

Measured memory_bytes: 16140
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
using namespace std;
 
 
int main(){
    int64_t n;
    cin>>n;
    vector<int> a(n),ans(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
       ans.at(a.at(i)-1)=i;
    }
   for(int i=0;i<n-1;i++)cout<<ans.at(i)+1<<" ";
   cout<<ans.at(n-1)+1<<endl;
    
   
    
}

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

using namespace std;

int N, M, K;
int A[100005], B[100005], C[100005], D[100005];

int con[100005];

vector<int> Adj[100005];
vector<int> Adj_B[100005];

int p;

int E[100005];

void DFS(int k) {
	con[k] = p;

	for (auto y : Adj_B[k]) {
		if (con[y] == con[k]) { E[y]++; E[k]++; }
	}

	for (auto y : Adj[k]) {
		if (con[y] == 0) { DFS(y); }
	}

	/*for (auto y : Adj_B[k]) {
		if (con[y] == con[k]) { E[y]++; E[k]++; }
	}*/
}

int NUM[100005];

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

	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		Adj[A[i]].push_back(B[i]);
		Adj[B[i]].push_back(A[i]);
	}

	for (int i = 1; i <= K; i++) {
		cin >> C[i] >> D[i];
		Adj_B[C[i]].push_back(D[i]);
		Adj_B[D[i]].push_back(C[i]);
	}

     p = 1;
	for (int i = 1; i <= N; i++) {
		if (con[i] == 0) { DFS(i); p++; }
	}

	for (int i = 1; i <= N; i++) {
		NUM[con[i]]++;
	}

	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << NUM[con[i]] - 1 - Adj[i].size() - E[i];
	}cout << endl;

	/*for (int i = 1; i <= N; i++) {
		cout << i << " E= " << E[i] << endl;
	}*/
	return 0;
}

Measured memory_bytes: 14208
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll a[8];
ll p[8];
ll q[8];
int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> p[i];
	rep(i, 0, n) {
		cin >> q[i];
		a[i] = q[i];
	}

	sort(a, a + n);

	ll p_i = 0;
	ll q_i = 0;
	ll i = 0;
	do {
		i++;
		bool sameP = true;
		bool sameQ = true;

		rep(i, 0, n)sameP &= a[i] == p[i];
		if (sameP)p_i = i;

		rep(i, 0, n)sameQ &= a[i] == q[i];
		if (sameQ)q_i = i;
	} while (next_permutation(a,a+n));

	cout << abs(p_i - q_i) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main(){
  int n, l;
  std::cin >> n >> l;
  long ans;
  if(l <= 0 && l+n-1 >= 0)
    ans = n*(l-1) + n*(n+1)/2;
  else if(l <= 0)
    ans = n*(l-1) + n*(n+1)/2 - (l+n-1);
  else
    ans = n*(l-1) + n*(n+1)/2 - l;
  std::cout << ans << std::endl;
  return 0;
}

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

int main(void){
  int n=0;
  scanf("%d",&n);
  char * string=(char *)malloc(n);
  scanf("%s",string);
      if(n%2){
    printf("No");
    return 0;
  }
  for(int i=0;i<=(n-2)/2;i++){
	 
    if(string[(n-2)/2-i]!=string[n-1-i]){
          printf("No\n");
              return 0;
    }
  }
  printf("Yes");
  return 0;
}

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

ans=[[None]*W for _ in range(H)]
x,y=0,0
d=1

for (i,j) in enumerate(a,start=1):
    # iがj個
    for k in range(j):
        ans[y][x]=i
        
        y+=d
        if not 0<=y<H:
            y-=d
            x+=1
            d*=-1

for i in ans:
    print(*i)


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
int main(){
	cout << fixed << setprecision(12);
	ld r; cin >> r;
	cout << r * PI * 2 << endl;
}

Measured memory_bytes: 3796
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[2][N];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < N; j++) A[i][j] = sc.nextInt();
		}
		int[] upper_sum = new int[N];
		int[] lower_sum = new int[N];
		for(int i = 0; i < N; i++) {
			upper_sum[i] = (i == 0) ? A[0][i] : upper_sum[i - 1] + A[0][i];
		}
		for(int i = N - 1; i >= 0; i--) {
			lower_sum[i] = (i == N - 1) ? A[1][i] : lower_sum[i + 1] + A[1][i];
		}
		int ans = 0;
		for(int i = 0; i < N; i++) {
			ans = Math.max(ans, upper_sum[i] + lower_sum[i]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
using System;
using System.Linq;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var r = 1L;
		var t = Enumerable.Repeat(-1, 3).ToArray();
		for (int i = 0; i < n; i++)
		{
			r = r * t.Count(x => x == a[i] - 1) % 1000000007;
			for (int j = 0; j < 3; j++) if (t[j] == a[i] - 1) { t[j]++; break; }
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 25296
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=998244353;
int n;
vector<pair<int,int>>E[maxn];
vector<pair<int,int>>ans;
int f[maxn];
int max1=0;
bool cmp(pair<int,int>a,pair<int,int>b)
{
    return a.second<b.second;
}

void dfs(int u,int fa)
{
    int cnt=0;
    for(auto &v:E[u])
    {
        int z=v.first;
        if(z==fa)
            continue;
        cnt++;
        if(f[u]==cnt)
            cnt++;
        max1=max(max1,cnt);
        ans.pb({cnt,v.second});
        f[z]=cnt;
        dfs(z,u);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        E[u].pb({v,i});
    }
    dfs(1,0);
    sort(ans.begin(),ans.end(),cmp);
    cout<<max1<<'\n';
    for(auto &v:ans)
        cout<<v.first<<'\n';






}


Measured memory_bytes: 15996
#include<iostream>
#include<string>
using namespace std;
int main( ){
  int j=1,ans;
  string a;
  cin>>a;
  while(1){
    string b;
    for(int i=0;i<a.size()-j;i++){
      b+=a[i];
    }
    j++;
    if(b.size()%2==1)continue;
    string c;
    for(int i=0;i<b.size()/2;i++){
      c+=b[i+b.size()/2];
    }
    c+=c;
    if(b==c){
      ans=b.size();
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
averages = []

while True:
    amount = int(input())
    if amount == 0:
        break
    scores = [int(input()) for i in range(amount)]
    scores.remove(max(scores))
    scores.remove(min(scores))
    averages.append(sum(scores) // (amount - 2))

for i in range(len(averages)):
    print(averages[i])

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

A = ord("a")
a2z = [chr(A + i) for i in range(26)]

all_patterns = []

def fill(values, c, i, n):
#	print(values, a2z[c], i, n)
	if i == N:
		if n == N:
			all_patterns.append("".join(values))
		else:
			for i in range(N):
				if values[i] == None:
					values[i] = a2z[c + 1]
					fill(values, c + 1, i + 1, n + 1)
					values[i] = None
					break
	else:
		if values[i] == None:
			values[i] = a2z[c]
			fill(values, c, i + 1, n + 1)
			values[i] = None
		fill(values, c, i + 1, n)

fill([a2z[0]] + [None] * (N - 1), 0, 1, 1)
#fill([None] * N, 0, 0, 0)

all_patterns.sort()
for pattern in all_patterns:
	print(pattern)



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

#define rep(i, n) for ( int i = 0; i < (n); ++i )
using namespace std;
using ll =  long long;
using P = pair<ll, ll>;


int main( void )
{
	string s;
	cin >> s;
	reverse(begin(s), end(s));

	ll cnt[2019]	= {};
	ll num			= 0;
	ll d			= 1;
	cnt[0]			= 1;
	for ( char& c : s ) {
		num += (c - '0') * d;
		num %= 2019;

		d *= 10;
		d %= 2019;

		cnt[num]++;
	}

	ll ans = 0;
	rep ( i, 2019 ) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}

	cout << ans;

	return 0;
}


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

int main(){
	int n;scanf("%d",&n);
	int x=1;
	ll ans=0;
	rep(i,n){
		int a;scanf("%d",&a);
		if(a<x)continue;
		if(a==x){x++;continue;}
		ans+=(a-1)/x;
		if(i==0)x++;
	}
	cout<<ans<<endl;
}

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

int n,p[1000000],dp[1000000];

long long int solve (int i)
{
    int ans;
if(i>=n)
  return 0;
if(i==(n-1))
  return dp[i]=abs(p[i+1]-p[i]);
if(dp[i] != -1)
return dp[i];
  
return dp[i] = min( abs(p[i+2]-p[i]) + solve(i+2) , abs(p[i+1]-p[i]) + solve(i+1));
}

int main()
{
    cin>>n;
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    for(int i=1;i<=n;i++)
    cin>>p[i];
    cout<<solve(1);
   
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  vvll A(3, vll(3, 0));
  REP(i,3) REP(j,3) IN(A[i][j]);
  vvb F(3, vb(3, false));
  ll N;
  IN(N);
  REP(i,N){
    ll b;
    IN(b);
    REP(i,3) REP(j,3){
      if(A[i][j]==b) F[i][j]=true;
    }
  }

  bool ans = false;
  REP(i,3){
    if(F[i][0] && F[i][1] && F[i][2]) ans = true;
    if(F[0][i] && F[1][i] && F[2][i]) ans = true;
  }
  if(F[0][0] && F[1][1] && F[2][2]) ans = true;
  if(F[2][0] && F[1][1] && F[0][2]) ans = true;

  if(ans){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e6 + 7;
typedef pair<ll,ll> LL;

ll n,a,b,ans1,ans2;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n>>a>>b;
    if ((b - a)%2 == 0) cout<<(b - a)/2;
    else{
        ans1 = a + (b - a - 1)/2;
        ans2 = n - b + 1 + (b - a - 1)/2;
        cout<<min(ans1,ans2);
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
	int n;
  cin >> n;
  vector<int>a(n);
  for(int i =0;i<n;i++){
   cin >> a.at(i); 
  }
  ll s;
  for(int i=0;i<n;i++){
   s^=a.at(i); 
  }
  for(int i=0;i<n;i++){
   ll ans = s^a.at(i);
    if(i==n-1){
     cout<<ans<<endl; 
    }
    else cout<<ans<<" ";
  }
}
    



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

#define rep(loop, N) for (int loop = 0; loop < N; loop++)
using namespace std;

struct Node {
	Node* parent;
	vector<Node*> child;
	long long value = 0;
};
struct Edge {
	int parent = 0;
	int child = 0;
	bool operator <(const Edge& right) const { return parent < right.parent; }
};
struct Tree {
	vector<Node> node;
	Tree(int, vector<Edge>);
};
Tree::Tree(int nodeNum, vector<Edge> edge) {
	node.resize(nodeNum);
	for (Edge& it : edge) {
		node[it.child].parent = &node[it.parent];
		node[it.parent].child.push_back(&node[it.child]);
	}
}

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A(void) {

	int A, B; cin >> A >> B;

	cout << max(A + B, max(A - B, A * B)) << flush;
	return;
}

void B_One_Clue(void) {

	int K, X; cin >> K >> X;

	int loopMin = max(X - K + 1, -1000000);
	int loopMax = min(X + K - 1, 1000000);
	
	for (int loop = loopMin; loop <= loopMax; loop++) cout << loop << " ";
	cout << flush;
	return;
}

int main(void) {

	//A();
	B_One_Clue();
	return 0;
}


Measured memory_bytes: 256
D = int(input())
C = [int(a) for a in input().split()]
S = [[int(a) for a in input().split()] for _ in range(D)]
T = [int(input()) - 1 for _ in range(D)]

def calc():
    s = 0
    last = [-1] * 26
    for i, t in enumerate(T):
        s += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            s -= c * (i - last[j])
        print(s)
    return s

calc()


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

int main(){
	/*input*/
	long int n, m;	cin >> n >> m;
	/*calculation*/
	long int ans = 0;
	if(n >= 2 && m >= 2)ans = (n - 2)*(m - 2);
	else if(n == 1 && m >= 2) ans = m - 2;
	else if(n >= 2 && m == 1) ans = n - 2;
	else ans = 1;
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split();
        var n = int.Parse(nk[0]);
        var k = int.Parse(nk[1]);
        var s = Console.ReadLine();

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

        ans = Math.Max(1, ans - k * 2);
        Console.WriteLine(n - ans);
    }
}


Measured memory_bytes: 13116
def partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i = i + 1
            (A[i], A[j]) = (A[j], A[i])

    (A[i+1], A[r]) = (A[r], A[i+1])

    return i+1
    
def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)

def stable(A, B):
    for i in range(len(A)):
        if A[i] != B[i]:
            return "Not stable"
    return "Stable"

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []

    for i in range(n1):
        L.append(A[left+i])
    for i in range(n2):
        R.append(A[mid+i])

    L.append([0, 10**9])
    R.append([0, 10**9])

    i = 0
    j = 0

    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
X = []
for i in range(n):
    a = input().split()
    X.append([a[0], int(a[1])])
    
Y = X[:]
quicksort(X, 0, n-1)
mergeSort(Y, 0, n)
print(stable(X, Y))
for elem in X:
    print(" ".join(map(str, elem)))



Measured memory_bytes: 19164
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int k,cnt=0,h[100005],dis[100005];
struct Edge{
	int to,next,w;
}e[400005];
queue<int> q;
inline void add(int u,int v,int w){
	e[++cnt].to=v;
	e[cnt].next=h[u];
	e[cnt].w=w;
	h[u]=cnt;
}
inline void init(){
	scanf("%d",&k);
	for(int i=0;i<k-1;i++){
		add(i,i*10%k,0);
		add(i,i+1,1);
	}
	add(k-1,(k-1)*10%k,0);
	add(k-1,0,1);
	memset(dis,127/3,sizeof(dis));
	dis[1]=0;
}
int main(){
	init();
	q.push(1);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=h[x];i;i=e[i].next)
			if(dis[e[i].to]>dis[x]+e[i].w){
				dis[e[i].to]=dis[x]+e[i].w;
				q.push(e[i].to);
			}
	}
	printf("%d\n",dis[0]+1);
	return 0;
}

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

#define Rep(i,n) for(int i=0;i<(n);i++)
#define For(i,n1,n2) for(int i=(n1);i<(n2);i++)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=(n-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(n1);i<(n2);i++)
#define put(a) cout<<(a)<<"\n";
#define all(a)  (a).begin(),(a).end();
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;

ll gcd(ll u, ll v) {
    ll r;
    while (v) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll u,ll v){
    ll r;
    r=u/gcd(u,v);
    r*=v;
    return r;
}
int main(){
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll res =  1;
    REP(i,n){
        res = lcm(res,a[i]);
    }
    put(res);
    return 0;
}


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

using namespace std;

const int N = 110;

int a[N];
int n;

int main()
{
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        if(i & 1)
            if(a[i] & 1)
                ans++;
    }

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

Measured memory_bytes: 3564
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,f[21][1<<21|1];char str[1<<21|1];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;++i){
		scanf("%s",str);
		for(int j=0;j<1<<i;++j)
			f[0][j<<n-i+1|1<<n-i]=str[j]-'0';
	}
	for(int i=0;i<n;++i)
		for(int j=0;j<1<<n+1;++j)
			if(f[i][j]){
				int a=j&(1<<i)-1,b=j^a,c=__builtin_ctz(b);
				b^=1<<c;
				if(b){
					f[i+1][b|1<<i|a]+=f[i][j];
				}
				if(b+(1<<c+1)<(1<<n+1)){
					int nc=__builtin_ctz(~b>>c+1<<c+1);
					f[i+1][b>>nc<<nc|1<<nc|a]+=f[i][j];
				}
			}
	for(int i=n;~i;--i)
		for(int j=0;j<1<<i;++j){
			int res=0;
			for(int k=0;k<1<<n+1-i;++k)
				res+=f[i][k<<i|j];
			if(res>=m){
				for(int k=i-1;~k;--k)putchar('0'+(j>>k&1));
				return puts(""),0;
			}
		}
	return 0;
}


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


int main() {
    int n;
    cin >> n;
    vector <int> a(n,0);
    vector <int> b(n,0);
    for (int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    if (n%2 == 0) {
        cout << (b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2])  +1<< endl;
    } else {
        cout << b[(n-1)/2] - a[(n-1)/2] + 1 << endl;
    }

    
    return 0;
}

Measured memory_bytes: 4828
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int size = a * b;
      int r = 2 * (a + b);
      System.out.println(size + " " + r);
  }
}


Measured memory_bytes: 26236
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  if(a>b)cout << 0 << endl;
  else if(a!=b&&n==1)cout << 0 << endl;
  else if(n==1&&a==b)cout << 1 << endl;
  else{
    n-=2;
    long long co=n*(b-a)+1;
    cout << co << endl;
  }
  return 0;
}


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

using namespace std;
using int64 = long long;

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

    string ss = s.substr(0, min((int)s.size(), k));
    cout << ss;

    if (ss.size() < s.size())
        cout << "...";

    cout << endl;
}


Measured memory_bytes: 3132