akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;			//入力値
  int tmpN;
  int TotalN = 0;	//入力値の各桁の和
  
  cin >> N;
  
  
  //入力値の桁数を計算
  tmpN = N;
  while(tmpN > 0){
    TotalN = TotalN + (tmpN % 10);
    tmpN = tmpN /10;
    
	//debug
//    cout << "TotalN=" << TotalN << endl;
//    cout << "tmpN=" << tmpN << endl;
    
  }

  if ( (N % TotalN) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;      
  }

}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// ?¨??????\???????????????????????????????????????
		Scanner sc= new Scanner(System.in);
		final int n = sc.nextInt();
		int i= 1;
		do {
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			}else{
				do{
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
				}while (x != 0);
			}
		}while (++i <= n);
		System.out.println();
	}
}

Measured memory_bytes: 35396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// (1) ?????????s???????????????
// (2) ?????????p???????????????
// (3) ?????????s?????????????????????sMatrix?????¨?????????
// (4) ?????????p?????????????????????pMatrix?????¨?????????
// (5) ?????????s???????????°?????????1??????????????\?????????????????????
	// (5.1) ????±???¨??????1?????????Char??????????????????
	// (5.2) ????????????????????§????????????????¢????????????´????????\?????????????????????
		// (5.2.1) ?????????????????????
	// (5.3) ?????????p???????????°?????????1??????????????\?????????????????????
		// (5.3.1) ????±???¨??????1?????????Char??????????????????
		// (5.3.2)

// ????????°????????£??????????????´???

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String p = br.readLine();
		int sLen = s.length();
		int pLen = p.length();

		boolean foundP = false;

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

			for(int j = 0; j < pLen; j++) {
				int k = (i + j) % sLen;
				char sc = s.charAt(k);
				char pc = p.charAt(j);

				if(sc != pc) {
					break;
				}

				if(j == pLen-1) {
					foundP = true;
					break;
				}
			}

			if(foundP) {
				break;
			}
		}

		if(foundP) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		br.close();
	}
}

Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,k,q,b,c,v,count=0,sum=0,flag=0,max=0;
	string s;
	cin>>n>>k>>q;
    vector<long long> a(n,k);
    for(int i=0;i<q;i++){
        cin>>b;
        a[b-1]++;
        count++;
        }
    for(int i=0;i<n;i++){
        if(a[i]-count>0){
            cout<<"Yes"<<'\n';
        }
        else{
            cout<<"No"<<'\n';
        }
    }
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main() {
	int H, W;
	char C[110][110];
	cin >> H >> W;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			cin >> C[i][j];
		}
	}

	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			cout << C[i][j];
		}
		cout << endl;
		for (int j = 1; j <= W; ++j) {
			cout << C[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
    int r,m,l;
    int i,j,k;
    int a[150][150],b[150][150];
    long long Sum=0;
    
    scanf("%d %d %d",&r,&m,&l);
    
    for (i=0;i<r;i++) {
        for (j=0;j<m;j++) {
            scanf ("%d",&a[i][j]) ;
        }
    }
    
    for (i=0;i<m;i++) {
        for (j=0;j<l;j++) {
            scanf ("%d",&b[i][j]) ;
        }
    }
    
    for (i=0;i<r;i++) {
        for (j=0;j<l;j++) {
            for (k=0;k<m;k++) {
                Sum+=a[i][k]*b[k][j];
            }
            printf("%lld",Sum);
            Sum=0;
            if(j!=l-1)putchar(' ');
        }
        putchar('\n');
    }
    return 0;
}


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

template<class Cost = int>
struct Edge {
    int from, to;
    Cost cost;
    Edge(const int &from = -1, const int &to = -1, const Cost &cost = 1)
        : from(from), to(to), cost(cost) {}

    bool operator<(const Edge<Cost> &rhs) const { return this->cost < rhs.cost; }
    bool operator>(const Edge<Cost> &rhs) const { return this->cost > rhs.cost; }
};

template<class Cost = int>
struct Graph : vector<vector<Edge<Cost>>> {
    int n;
    Graph(int _n = 0) : n(_n) { this->resize(n); }

    void add_edge(const int &src, const int &dst, const Cost &cost = 1) {
        assert(0 <= src && src < n && 0 <= dst && dst < n);
        (*this)[src].emplace_back(src, dst, cost);
    }
    void add_biedge(const int &src, const int &dst, const Cost &cost = 1) {
        add_edge(src, dst, cost), add_edge(dst, src, cost);
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    Graph<> g(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        g.add_biedge(--a, --b);
    }
    vector<int> d(N, -1);
    vector<int> ans(N, -1);
    d[0] = 0;
    auto bfs = [&]() {
        queue<int> q;
        q.push(0);
        while (!q.empty()) {
            int c = q.front(); q.pop();
            for (auto &e: g[c]) {
                if (d[e.to] == -1) {
                    ans[e.to] = c;
                    d[e.to] = d[c] + 1;
                    q.push(e.to);
                }
            }
        }
    };
    
    bfs();
    for (int i = 0; i < N; i++) {
        if (d[i] == -1) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    for (int i = 1; i < N; i++) {
        cout << ans[i] + 1 << "\n";
    }

    return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  int length;
  length = A - B*2;
  if (length < 0) {
    cout << 0 << endl;
  } else {
    cout << length << endl;
  }
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch, Cw, Dh, Dw = Ch-1, Cw-1, Dh-1, Dw-1

maze = [list(input()) for _ in range(H)]
visit = [[-1] * W for _ in range(H)]
visit[Ch][Cw] = 0

DQ = deque([(Ch, Cw)])
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while DQ:
    px, py = DQ.popleft()
    if (px, py) == (Dh, Dw):
        print(visit[px][py])
        exit()

    for i in range(4):
        nx = px + dx[i]
        ny = py + dy[i]
        if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and (visit[nx][ny]>visit[px][py] or visit[nx][ny]==-1):
            visit[nx][ny] = visit[px][py]
            DQ.appendleft((nx, ny))

    for i in range(-2, 3):
        for j in range(-2, 3):
            if i == j == 0:
                continue

            nx = px + i
            ny = py + j

            if 0<=nx<=H-1 and 0<=ny<=W-1 and maze[nx][ny]=="." and visit[nx][ny]==-1:
                visit[nx][ny] = visit[px][py] + 1
                DQ.append((nx, ny))

    # for a in visit:
    #     print(a)

print(-1)

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int f0 = 0, f1 = 0;
    string a1, a2;

    for(int i = 0; i < n; i++) {
        if(i % 2 == 0) {
            if(s[i] == '0')
                f0++;
            else
                f1++;
        }
        if(i % 2 == 1) {
            if(s[i] == '1')
                f0++;
            else
                f1++;
        }
    }
    if(f0 <= f1)
        cout << f0 << endl;
    else
        cout << f1 << endl;
}


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

int main()
{
	ll K, X, Y;
	cin >> K >> X >> Y;
	if (abs(X) + abs(Y) == K) {
		cout << 1 << endl;
		cout << X << ' ' << Y << endl;
		return 0;
	}
	if (K % 2 == 0 && (abs(X) + abs(Y)) % 2 != 0) {
		cout << -1 << endl;
		return 0;
	}
	ll x = X + Y;
	ll y = X - Y;
	bool f1 = x < 0, f2 = y < 0;
	if (f1) x = abs(x);
	if (f2) y = abs(y);
	ll c = max(2LL, max((x + K - 1) / K, (y + K - 1) / K));
	if (K % 2 != 0) {
		if (c % 2 == 0) {
			c += x % 2;
		}
		else {
			c += (x % 2 == 0);
		}
	}
	vector<ll> xs, ys;
	for (int i = 0; i < c; i++) {
		xs.push_back(K);
		ys.push_back(K);
	}
	ll tx = 1LL * K * c, ty = 1LL * K * c;
	for (int i = c - 1; i >= 0; i--) {
		if (tx - K * 2 >= x) xs[i] = -K, tx -= K * 2;
		if (ty >= y) ys[i] = -K, ty -= K * 2;
	}
	xs[0] -= tx - x;
	ys[c - 1] += y - ty;
	for (int i = 1; i < c; i++) {
		xs[i] += xs[i - 1];
		ys[i] += ys[i - 1];
	}
	if (f1) {
		for (int i = 0; i < c; i++) {
			xs[i] = -xs[i];
		}
	}
	if (f2) {
		for (int i = 0; i < c; i++) {
			ys[i] = -ys[i];
		}
	}
	cout << c << '\n';
	for (int i = 0; i < c; i++) {
		cout << (xs[i] + ys[i]) / 2 << ' ' << (xs[i] - ys[i]) / 2 << '\n';
	}
	return 0;
}


Measured memory_bytes: 5476
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

int main()
{
	int hit, blow;
	string num, tmp;
	
	while (1) {
		hit = 0; blow = 0;
		
		cin >> num;
		cin >> tmp;
		if (num=="0" && tmp=="0") break;
		
		for (int i=0; i<4; i++)
			for (int j=0; j<4; j++)
				if (num[i] == tmp[j]) {
					if (i == j) hit++;
					else		blow++;
				}
		cout << hit << " " << blow << endl;
		
	}
	return 0;
}

Measured memory_bytes: 1184
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	
	vector<ll> b(3);

	rep(i, 0, 3) {
		
		cin >> b[i];
	
	}
	sort(b.begin(), b.end());

	

	cout << (b[2] -b[1]) + (b[1] -b[0]) << endl;

}
	

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





int main(void){
    // Your code here!
    int N;

    int count=0;

  
  
  //入力
  cin >> N;
vector<int> vc(N);
  for(int i=0;i<N;i++)  cin >> vc[i];
  
  
  //どれかが奇数になるまで全て割り続ける
  //true部分を関数にするのもよいが今回はif
  while(true) {
    //   bool isOdd = false;
      
      //奇数が一個でもあるかどうか
      for(int i=0;i<N;i++){
          if(vc[i]%2==1){
                cout << count << endl;
                return 0;
            //   isOdd = true;
          }
      }
      
      
    //  if(!isOdd){
     //全要素2で割り算をする
        for(int i=0;i<N;i++){
          vc[i] /= 2;
         
        }
         count++;
    //  }
    //  else break;
      
  }
  
   
   
   
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endll "\n"
#define show(a) cerr<<""#a""<<" is "<<a<<endll;
int caseno=0;
#define print_case cout<<"Case "<<++caseno<<": ";
#define fout freopen("output.txt","w",stdout);
#define fin freopen("input.txt","r",stdin);
#define srt(v) sort(v.begin(),v.end());
#define greatersrt(v) sort(v.begin(),v.end(),greater<ll>())
#define pb push_back
#define mp make_pair
#define here cerr<<"here\n";
#define PI acos(-1.0)
#define ll long long
#define ld long double
#define reto exit(0);
#define sspace <<" "<<
#define print(arr,xx) for(int i=1;i<xx;i++)cerr<<arr[i]<<" \n"[i==n];
bool sortbysec(pair<int,int>a,pair<int,int>b){return a.second>b.second;}
ll gc(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
ll lc(ll a,ll b){return a/gc(a,b)*b;}
const int primemod=1e9+7;
const ld eps=1e-9;
#define inl(x) scanf("%lld",&x)
#define in(x) scanf("%d",&x)
#define pii pair<int,int>
/**Code Goes Here**/
#define maxsize 1000+9
#define rshuffle(r...)rshuffle(r,[](int _){return rand()%_;})
const int mod = 1000000000+7;
int h,w;
bool arr[maxsize][maxsize];
long ans[maxsize][maxsize];
int main()
{
    char x;
    in(h),in(w);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>x;
            if(x=='.')arr[i][j]=true;
        }
    }
    ans[1][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if((i==1 and j==1) or !arr[i][j])continue;
            ans[i][j]=(ans[i-1][j]+ans[i][j-1])%mod;
        }
    }
    printf("%d\n",ans[h][w]);

}


Measured memory_bytes: 9216
#!/usr/bin/env python
# -*- coding: utf-8 -*-

H, W = map(int, input().split())
b = []
[b.append(list(input())) for i in range(H)]

c = [[0] * (W + 2) for i in range(H + 2)]
for i in range(H):
    for j in range(W):
        if b[i][j] == "#":
            c[i][j] += 1
            c[i + 1][j] += 1
            c[i + 2][j] += 1
            c[i][j + 1] += 1
            # c[i+1][j+1] += 1
            c[i + 2][j + 1] += 1
            c[i][j + 2] += 1
            c[i + 1][j + 2] += 1
            c[i + 2][j + 2] += 1
d = [""] * H
for i in range(H):
    for j in range(W):
        if b[i][j] == ".":
            d[i] += str(c[i + 1][j + 1])
        else:
            d[i] += "#"

for i in range(H):
    print(d[i])

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int dp[10010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int> v(N), w(N); rep(i, 0, N) { cin >> v[i] >> w[i]; }
	memset(dp, 0, sizeof(dp));
	rep(i, 0, N) {
		rep(j, 0, W) {
			if (j + w[i] > W)continue;
			chmax(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 3248
cards = [[False for j in range(14)]for i in range(4)]
n = int(input())
for i in range(n):
	suit,rank = input().split()
	r = int(rank)
	if suit == "S":
		s = 0
	elif suit == "H":
		s = 1
	elif suit == "C":
		s = 2
	else:
		s = 3
	cards[s][r] = True
  	
name = ["S","H","C","D"]
for s in range(4):
	for r in range(1,14):
		if not cards[s][r]:
			print(name[s],r)

Measured memory_bytes: 7676
// ある部屋から部屋1までの最短経路が複数ある場合はどうする？
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    // ダイクストラで点0からの最短経路を求める
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    que.push(make_pair(0, 0));
    vector<int> fa(N, -1);
    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        if (fa[p.second] != -1) continue;
        fa[p.second] = p.first;
        for (auto &v : G[p.second]) {
            if (fa[v] == -1) {
                que.push(make_pair(p.first + 1, v));
            }
        }
    }

    //for (auto &v : fa) cout << v << " ";
    //cout << endl;
    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) {
        for (auto &nxt : G[v]) {
            if (fa[v] == fa[nxt] + 1) {
                cout << nxt + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n);
        for(int i = 0; i<n; i++) dat[i] = 0;
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            add(s, dat[i]);
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        int64_t res = sum(j);
        if(i>0) add(res, MOD - sum(i-1));
        return res;
    }

    void plus(int i, T x){
        while(i < n){
            add(dat[i], x);
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

void solve1(int N){
    static int64_t dp[200001][2][2] = {0};
    dp[0][0][0] = dp[0][1][1] = 1;
    for(int i=0; i<N-1; i++){
        for(int j=0; j<2; j++){
            add(dp[i+1][0][j], dp[i][0][j] + dp[i][1][j]);
            add(dp[i+1][1][j], dp[i][0][j]);
        }
    }
    int64_t ans = (dp[N-1][0][0] + dp[N-1][1][0] + dp[N-1][0][1]) % MOD;
    cout << ans << endl;
    exit(0);
}

int main(){
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    if(S[0] == 'B'){
        for(int i=0; i<M; i++) S[i] = (S[i] == 'B' ? 'R' : 'B');
    }

    int len = 0, first = -1, lim = N;
    for(int i=0; i<M; i++){
        if(S[i] == 'R'){
            len++;
        }else if(len > 0){
            if(first == -1){
                first = len;
            }else{
                if(len%2) lim = min(lim, len+1);
            }
            len = 0;
        }
    }
    if(len == M){
        solve1(N);
    }
    if(N%2){
        cout << 0 << endl;
        return 0;
    }
    lim = min(lim, (first/2+1)*2);

    BIT<int64_t> bit(N+1);
    bit.plus(0, 1);
    for(int i=2; i<=N; i+=2){
        int l = max(0, i-lim);
        int64_t res = bit.sum_between(l, i-1);
        bit.plus(i, res);
    }

    int64_t ans = 0;
    for(int i=1; i<=min(N-1, lim-1); i+=2){
        add(ans, (i+1) * bit.sum_between(N-i-1, N-i-1) % MOD);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,k,a[100050];
LL F[100050][2];
int main() {
	scanf("%d%d",&n,&k);
	for (int _=1;_<=n;_++) scanf("%d",&a[_]);
	F[0][0] = 1LL;
	for (int _=1;_<=n;_++) {
		int t = a[_]&1;
		F[_][0] = F[_-1][0] + F[_-1][0^t];
		F[_][1] = F[_-1][1] + F[_-1][1^t];
	}
	cout << F[n][k] << endl;
	
	return 0;		
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int p,q,k; 
  while(cin>>p>>q){
    p%=q;
    int num[1000000];
    for(int i=0;i<1000000;i++)
      num[i] = -1;
    for(k=0;;k++){
      if(p>=q)p%=q;
      if(num[p]<0)num[p] = k;
      else break;
      p*=10;
      if(p)cout<<p/q;
    }
    cout<<endl;
    if(p){
      for(int i=0;i<num[p];i++)cout<<" ";
      for(int i=num[p];i<k;i++)cout<<"^";
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4776
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    for(int i = s.size() - t.size();i >= 0;i--)
    {
        bool flag = true;
        for(int j = 0;j < t.size();j++)
        {
            if(s[i + j] != t[j] && s[i + j] != '?')
            {
                flag = false;
                break;
            }
        }
        if(flag)
        {
            for(int j = 0;j < s.size();j++)
            {
                if(s[j] == '?' && (j < i || j > i + t.size() - 1))
                {
                    cout << "a";
                }
                else if(j >= i && j < i + t.size())
                {
                    cout << t;
                    j += t.size() - 1;
                }
                else
                {
                    cout << s[j];
                }
            }
            cout << "\n";
            return 0;
        }
    }
    cout << "UNRESTORABLE\n";

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
    //    #include <boost/multiprecision/cpp_int.hpp>
        #include<functional>
      #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define  mp make_pair
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------


signed main(){
string s;
int k,t;
	int a[110];
	cin>>k>>t;
	int sum=0;
	int ma=0;
	for(int i=1;i<=t;i++) {
		cin>>a[i];
		sum+=a[i];
		ma=max(ma,a[i]);
	}
	if(t==1) {
		cout<<a[1]-1<<endl;
		return 0;
	}
	
	if(sum-ma>=ma-1){
		cout<<0<<endl;
	}
	else{
		cout<<ma-(sum-ma)-1<<endl;
	}
	
	
//	cout<<ans<<endl;
	return 0;
}

//printf("%.10f\n",ans);


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    int y = ty - sy, x = tx - sx;
    cout << string(y, 'U') << string(x, 'R');
    cout << string(y, 'D') << string(x, 'L');
    cout << 'L' << string(y + 1, 'U') << string(x + 1, 'R') << 'D';
    cout << 'R' << string(y + 1, 'D') << string(x + 1, 'L') << 'U' << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cassert>
#include<sstream>
#define F first
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
map<string,int> index;
int dex;


void add(VVI &G,string s)
{
  rep(i,s.size())
    if(s[i] == ':' || s[i] == ',' || s[i] == '.')s[i] = ' ';
  stringstream ss;
  ss << s;
  int fir = -1;
  while(!(ss >> s).fail())
    {
      if(!index[s])index[s] = dex++;      
      int v = index[s];
      if(fir == -1)
	fir = v;
      else
	{
	  assert(fir < 1100);
	  G[fir].push_back(v);
	}
    }
}

int count(VVI &G,bool used[],int p)
{
  
  if(used[p])return 0;
  used[p] = true;
  if(G[p].empty())return 1;
  int cnt = 0;
  rep(i,G[p].size())
    cnt += count(G,used,G[p][i]);
  return cnt;
}

int main()
{
  int n;
  while(cin >> n,n)
    {
      dex = 1;
      index.clear();
      VVI G(1100);
      rep(i,n)
	{
	  string s;
	  cin >> s;
	  add(G,s);
	}

      bool used[dex];
      rep(i,dex)used[i] = false;
      cout << count(G,used,1) << endl;
    }
  return 0;
}

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

using namespace std;
#define BUF (1000)

int n;
char a[BUF],b[BUF];
int main(void){

	cin >> a ;
	cin >> b ;

	int ans = 1;
	for(int i=0;i<3;i++){
		if(a[i]!=b[2-i]) ans = 0;
	}
	
	if(ans==1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m = map(int, input().split())
time = h * 60 + m
p = 2 *math.pi
lk = p * m / 60
sk = p * (h * 60 + m) /720
rad = max(lk,sk) - min(lk,sk)
if rad > math.pi:
    rad = p - rad
ans = (a**2) + (b**2) - 2*a*b*math.cos(rad)
print(ans**0.5)


Measured memory_bytes: 9504
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left, insort
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

N, H = inpl()
T = sorted([inpl() for _ in range(N)], reverse=True)
mta, mtb = T[0]
sT = sorted([t[1] for t in T[1:]])
sT = sT[bisect(sT, mta):] # 投げたほうが良い刀達

S = sum(sT)
if S + mtb >= H: # 投げるだけで勝てるとき
    insort(sT, mtb)
    A = list(accumulate(sT[::-1]))
    print(bisect_left(A, H)+1)
else:
    print(len(sT) + 1 + ((H-S-mtb)//mta + ((H-S-mtb)%mta!=0)))

Measured memory_bytes: 22012
fun main(args: Array<String>) {
    var (k, a, b) = readLongList()

    var ans = 1L
    do {
        when {
            ans >= a && k >= 2 && a + 2 < b -> {
                ans += (b - a)
                k--
            }
            else -> {
                ans++
            }
        }
    } while (--k > 0)
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36396
s=input()
a=(len(s)-1)//2-1
b=[]
for i in range(0,a):
    if s[i]!=s[len(s)-i-1]:
        b.append(1)
    elif s[i]!=s[a-i]:
        b.append(1)
    else:
        b.append(0)
if 1 in b:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2];
}

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

typedef long long ll;

ll N;
vector<ll> A;
const ll V = 1000000;
const ll MOD = 998244353;
vector<ll> Inv;
vector<ll> W;
ll R;

int main() {
  cin >> N;
  A.resize(V + 1);
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    ++A[a];
  }

  Inv.resize(V + 1);
  Inv[1] = 1;
  for (ll i = 2; i <= V; ++i) {
    Inv[i] = MOD - (MOD / i) * Inv[MOD % i] % MOD;
    assert(Inv[i] * i % MOD == 1);
  }

  W.resize(V + 1);
  for (ll i = 1; i <= V; ++i) W[i] = Inv[i];
  for (ll i = 1; i <= V; ++i) {
    for (ll k = 2 * i; k <= V; k += i) W[k] += MOD - W[i];
  }
  for (ll i = 1; i <= V; ++i) {
    ll sum = 0, sum2 = 0;
    for (ll k = i; k <= V; k += i) {
      (sum += A[k] * k) %= MOD;
      (sum2 += A[k] * (k * k % MOD)) %= MOD;
    }
    ll prodsum = (sum * sum + MOD - sum2) % MOD * Inv[2] % MOD;
    (R += W[i] * prodsum % MOD) %= MOD;
  }
  cout << R << endl;

  return 0;
}


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

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    
    rep(i, 9) q.push(i+1);
    
    ll x;
    rep(i, k){
        x = q.front();
        q.pop();
        if(x%10 != 0) q.push(10 * x + x%10 - 1);
        q.push(10 * x + x%10);
        if(x%10 != 9) q.push(10 * x + x%10 + 1);
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;



public class Main {
    public static void main(String [] args) {
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        int [] color = new int[n];
        for (int i = 0; i < n; ++i) {
            color[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 1; i < n; ++i) {
            if (color[i] == color[i - 1]) {
                ++count;
                if (i + 1 < n && color[i - 1] - 1 != color[i + 1]) {
                    color[i] = color[i] - 1;
                } else {
                    color[i] = color[i - 1] + 1;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
signed main()
{
    int a, b;
    cin >> a >> b;
    //cerr << gcd(4, 6) << endl;
    cout << a / gcd(a, b) * b << endl;

    return 0;
}

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

using namespace std;

long long arr[200005];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    long long totalSum = 0;

    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];

        totalSum += arr[i];

        arr[i] += arr[i - 1];
    }

    long long ans = LLONG_MAX;

    for (int i = 1; i < n; ++i) {
        long long x = arr[i];
        long long y = totalSum - arr[i];

        if (abs(x - y) < ans) {
            ans = abs(x - y);
        }
    }

    cout << ans;

    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  cout << (n % 1000 == 0 ? 0 : 1000 - n % 1000) << endl;

  return 0;
}


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


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a+b;
    int r = c+d;
    if(l > r){
        puts("Left");
    }else if(  r > l){
        puts("Right");
    }else{
        puts("Balanced");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<string>
#include<map>
using namespace std;
int x, y, num;

long long N, M,K,Y[100000],P[100000],a,b,c,d;
string s;

map<long long, long long>m;
int main(){
	cin >> N >> K;
	double ans;
	ans = 0;
	double t=0;
	for (int i = 1; i <= N; i++) {
		a = i;
		t = 1.0/N;
		while (a < K) {
			t*=0.5;
			a *= 2;
		}
		ans += t;
	}
	printf("%.12f\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[200005],dp[200005],n;

ll dfs(ll x,ll c)
{
	if(x>n)
		return ass;
	if(dp[x]!=-1)
		return dp[x]+abs(arr[x]-c);
	if(x==n)
		return abs(arr[x]-c);
	dp[x]=min(dfs(x+1,arr[x]),dfs(x+2,arr[x]));
	return dp[x]+abs(arr[x]-c);
}

int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i];
		dp[i]=-1;
	}
	cout<<min(dfs(2,arr[1]),dfs(3,arr[1]));
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int w, h, n;
  cin >> w >> h >> n;
  vii f(h,vi(w));
  rep(i,n) {
    int x, y, a;
    cin >> x >> y >> a;
    if(a==1) {
      rep(i,h)rep(j,x) {
        if(f[i][j] == 0) f[i][j] = 1;
      }
    }
    else if(a==2) {
      rep(i,h)for(int j = x; j < w; j++) {
        if(f[i][j] == 0) f[i][j] = 1;
      }
    }
    else if(a==3) {
      rep(i,y)rep(j,w) {
        if(f[i][j] == 0) f[i][j] = 1;
      }
    }
    else if(a==4) {
      for(int i = y; i < h; i++)rep(j,w) {
        if(f[i][j] == 0) f[i][j] = 1;
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) {
    if(f[i][j] == 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a,f=1;c(char*v){return(*v-*1[&v])*f;}main(n,s){for(scanf("%d",&n);n--;printf("%d\n",atoi(s)-a))for(scanf("%s",s);qsort(s,8,1,c),f=-f,f<0;a=atoi(s));exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int n;
	cin >> n;
	if(n%1000==0)
	cout << "0";
	else
	{
		int x=n/1000;
		int y=n-1000*x;
		cout << 1000-y;
	}
}



Measured memory_bytes: 3620
n, m = map(int, input().split())
pair = []
for i in range(m):
	pair.append(list(map(int, input().split())))
pair = pair[::-1]
ans = []
ans.append(int(n*(n-1)/2))

class UnionFind:
    def __init__(self, n):
        self.par = [-1] * (n+1)
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def size(self, x):
        return -self.par[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.size(x) < self.size(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        return

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u = UnionFind(n)
for i in range(len(pair) - 1):
    if u.find(pair[i][0]) != u.find(pair[i][1]):
        ans.append(max(0, int(ans[i] - u.size(pair[i][0]) * u.size(pair[i][1]))))
    else:
        ans.append(ans[i])
    u.union(pair[i][0], pair[i][1])
ans = ans[::-1]
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 35468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    REP(i, H) REP(j, W) cin >> a[i][j];
    vector<vector<int>> ans;
    REP(i, H) {
        REP(j, W) {
            if (a[i][j] % 2 == 1) {
                if (j < W - 1) {
                    a[i][j+1]++;
                    ans.push_back({i+1, j+1, i+1, j+2});
                } else if (i < H - 1) {
                    a[i+1][j]++;
                    ans.push_back({i+1, j+1, i+2, j+1});
                }
            }
        }
    }
    cout << ans.size() << '\n';
    REP(i, ans.size()) {
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << '\n';
    }
}

Measured memory_bytes: 10032
#include <iostream>
#include <cstdio>
#include <queue>
#define N 300005
using namespace std;

typedef long long ll;
priority_queue<ll> qu;
ll n, s, mx = -9e15, a[N], d1[N], d2[N];
int main()
{
	ll i, t;
	cin >> n;
	for (i = 0; i < n * 3; i++) {
		scanf ("%lld", &a[i]);
	}
	for (i = 0; i < n; i++) {
		qu.push(-a[i]);
		s += a[i];
	}
	d1[n - 1] = s;
	for (i = n; i < n * 2; i++) {
		qu.push(-a[i]);
		t = qu.top(); qu.pop();
		t *= -1;
		s -= t;
		s += a[i];
		d1[i] = s;
	}
	while (!qu.empty()) qu.pop();
	s = 0;
	for (i = 3 * n - 1; i >= n * 2; i--) {
		qu.push(a[i]);
		s += a[i];
	}
	d2[n * 2] = s;
	for (i = n * 2 - 1; i >= n; i--) {
		qu.push(a[i]);
		t = qu.top(); qu.pop();
		s -= t;
		s += a[i];
		d2[i] = s;
	}
	for (i = n - 1; i < n * 2; i++) {
		mx = max(mx, d1[i] - d2[i + 1]);
	}
	cout << mx;
    return 0;
}


Measured memory_bytes: 6900
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll A, B;
  cin >> A >> B;

  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll count = 1;
  ll b = B - A;
  while (b > 0) {
    b -= (A - 1);
    count++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

struct UnionFind {
    vi r;
 
    UnionFind(int N) : r(N, -1) {
    }
 
    int root(int x) {
        if (r[x] < 0)
          return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)
          return false;
        if (r[x] > r[y])
          swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};

int main() {
  ll n, m;
  cin >> n >> m;
  
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
  }
  
  int ans = -1;
  vi u(n);
  rep(i, n) {
    int r = uf.root(i);
    if(!u[r]) {
      ans++;
      u[r] = 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll l,r,n,k=0;
        cin>>l>>r>>n;
        for(ll i=l;i<=r;i++)
        {
            if(i%n==0)
            k++;
        }
        cout<<k;
    }
    return 0;
}


Measured memory_bytes: 3612
n, a, b = map(int, input().split())

MOD = 10 ** 9 + 7

def rep_pow(x, n):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x) % MOD
    x = (x*x) % MOD
    n = n >> 1 #ビットシフト
  return ans

ans = rep_pow(2, n) - 1

#print(ans)

def comb(c, n):
    x = 1
    y = 1
    for i in range(c):
        x = (x * (n - i)) % MOD
        y = (y * (i + 1)) % MOD
    return (x * rep_pow(y, MOD - 2)) % MOD

ans = ans + MOD * 2 - comb(a, n) - comb(b, n)

print(ans % MOD)

Measured memory_bytes: 38768
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W;
  cin >> H >> W;

  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >> A[i][j];

  REP(i, H) REP(j, W){
    int B;
    cin >> B;
    A[i][j] -= B;
  }


  const int MAX = 10000;
  vector<vector<vector<bool>>> dp(H+1, vector<vector<bool>>(W+1, vector<bool>(MAX, false)));
  dp[0][0][0] = true;

  auto f = [&](int i, int j, int x){
    x = abs(x);
    if(x >= MAX) return;
    dp[i+1][j][x] = true;
    dp[i][j+1][x] = true;
  };

  REP(i, H) REP(j, W) REP(k, MAX){
    if(dp[i][j][k]){
      f(i, j, k-A[i][j]);
      f(i, j, k+A[i][j]);
    }
  }

  REP(k, MAX){
    if(dp[H-1][W][k] || dp[H][W-1][k]){
      cout << k << "\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 8832
#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];
  sort(A.begin(), A.end());

  cout << abs(A[N-1]-A[0]) << endl;
}

Measured memory_bytes: 256