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

int h[1000000];
int dp[1000000];

int cost(int x,int y){

      if(x==y)
        return 0;
      if(dp[x]!=-1)
        return dp[x];
      int c=abs(h[x]-h[x+1])+cost(x+1,y);
      if(x+2<=y)
        c= min(c,(cost(x+2,y)+abs(h[x+2]-h[x])));

        return  dp[x]=c;

    }


  int main(){

      int n;
      cin>>n;


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


    memset(dp,-1,sizeof(dp));
    cout<<cost(1,n)<<endl;










  }














Measured memory_bytes: 14104
#include <stdio.h>

int abs(int x){
    return x >= 0 ? x : - x;
}

int cfunc(int *a,int *b,int *c,int N){
    int i,count=0;
    for(i = 0;i < N;i++){
        if(a[i] == 0 && b[i] == 0){
            // skip
        }else if(a[i] == -b[i]){
            a[i] = b[i] = 0;
            count++;
        }else if(a[i] == 0 || b[i] == 0){
            //skip
        }else {
            a[i] = b[i] = c[i] = 0;
            count += 2;
        }
    }
    return count;
}
int main(void){
    char A[101],B[101],C[101];
    int ab[101],bc[101],ca[101];
    int N;
    scanf(" %d",&N);
    scanf(" %s",A);
    scanf(" %s",B);
    scanf(" %s",C);

    int i;
    int count = 0;
    for(i = 0;i < N;i++){
        ab[i] = A[i] - B[i];
        bc[i] = B[i] - C[i];
        ca[i] = C[i] - A[i];
    }
    
    count += cfunc(ab,ca,bc,N);
    count += cfunc(bc,ab,ca,N);
    count += cfunc(ca,bc,ab,N);
    
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
#include <boost/integer/common_factor_rt.hpp> // gcd, lcm


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

int64_t N; cin >> N;
VI A(N), B(N); rep(i, 0, N) cin >> A[i] >> B[i];

int64_t cnt = 0;
Rrep(i, N-1, 0){
    int64_t Acnt = A[i] + cnt;
    if (Acnt == 0) continue;
    if (Acnt <= B[i]) cnt += B[i] - Acnt;
    else cnt += (Acnt + B[i] - 1) / B[i] * B[i] - Acnt;
}

cout << cnt << endl;

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 1792
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
using namespace boost::multiprecision;  
using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    string s;
    cin >> s;
    rep(i,s.size()){
        cout << 'x';
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys

def isPrime(n):
    isP = True
    i = 2
    while i*i <= n :
        if n % i == 0:
            isP = False
        i += 1
    
    return isP

def keta_chk(n):
    keta = 0
    while n > 0:
        keta += 1
        n = int(n/10)
    
    return keta

def solve(n):
    ans = sys.maxsize
    i = 1
    while i*i <= n:
        if n % i == 0:
            f = max(keta_chk(int(n/i)),keta_chk(i))
            ans = min(f,ans)
        i += 1
    
    return ans

n = int(input())
ans = solve(n)
print(ans)

Measured memory_bytes: 3064
n = int(input())
i = 0

cardlist = ["S 1","S 2","S 3","S 4","S 5","S 6","S 7","S 8","S 9","S 10","S 11","S 12","S 13",
"H 1","H 2","H 3","H 4","H 5","H 6","H 7","H 8","H 9","H 10","H 11","H 12","H 13",
"C 1","C 2","C 3","C 4","C 5","C 6","C 7","C 8","C 9","C 10","C 11","C 12","C 13",
"D 1","D 2","D 3","D 4","D 5","D 6","D 7","D 8","D 9","D 10","D 11","D 12","D 13"
]
while i < n:
	card = input()
	cardlist.remove(card)
	i += 1
	
for k in range(len(cardlist)):
	print(cardlist[k])


Measured memory_bytes: 5600
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
	string S;
	cin>>S;
	S[3]=S[3]+1;
	cout<<S<<endl;
	return 0;
}	

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var s = readLine()!!.toString()
    var c = mutableMapOf<Char, Int>('R' to 0, 'G' to 0, 'B' to 0)
    var num: Int
    for (i in s) {
        c[i] = c.getOrDefault(i, 0) + 1
    }
    var diff = 0
    var ans = 1L
    for (d in 1..((n-1)/2)){
        for (i in 0..(n-d-d-1)) {
            if (s[i] != s[i+d] && s[i+d] != s[i+d+d] && s[i+d+d] != s[i]) {
                diff += 1
            }
        }
    }
    for ((x, y) in c){ans *= y}
    println(ans-diff)
}


Measured memory_bytes: 37392
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int h, w, cnt, x, y;
	const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
	const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
	string s[50];
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') { continue; }
			cnt = 0;
			for (int k = 0; k < 8; k++) {
				x = i + dy[k];
				y = j + dx[k];
				if (x < 0 || h <= x) { continue; }
				if (y < 0 || w <= y) { continue; }
				if (s[x][y] == '#') { cnt++; }
			}
			s[i][j] = char(cnt + '0');
		}
	}
	for (int i = 0; i < h; i++) {
		cout << s[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    if(a>=k)
    cout<<k;
    else if((a+b)>=k)
    cout<<a;
    else
    cout<<a-(k-a-b);
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int d=sc.nextInt();
        int t=sc.nextInt();
        int s=sc.nextInt();
        if (d<=(t*s)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35612
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repk(i,k,n) for (int i = k; i <= (int)(n); i++)
#define MAX 100010

using namespace std;

typedef pair<int,int> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main(){
    int N;
    cin >> N;
 
    P a[MAX];
    repk(i,1,N){
        a[i].first = i;
        cin >> a[i].second;
    }

    sort(a+1,a+1+N,compare_by_b);

    repk(i,1,N){
        cout << a[i].first << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
bitset<maxn * maxn> dp;
int main()
{
    ios::sync_with_stdio(false);
    int n ; cin >> n;
    dp[0] = 1;
    int sum = 0;
    for (int i = 1 ; i <= n ; i++){
        int a ; cin >> a;
        dp |= (dp << a);
        sum += a;
    }
    int ans = 0 ,low = (sum - 1) / 2 + 1;
    for (int i = low ; i <= sum ; i++){
        if (dp[i]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5116
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
	a[i] = [int(j) for j in input().split()]
for i in range(r):
	rowSum = 0
	for j in range(c):
		rowSum += a[i][j]
	a[i].append(rowSum)
for i in range(c+1):
	columnSum = 0
	for j in range(r):
		columnSum += a[j][i]
	a[r][i] = columnSum
for i in range(r+1):
	for j in range(c):
		print(a[i][j],end=' ')
	print(a[i][c])

Measured memory_bytes: 8292
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import numpy as np
# from scipy.special import comb

INF = 100100100


def main():
    N = int(input())

    memo = [INF] * (N + 1)
    memo[0] = 0

    for i in range(1, N + 1):
        for nine in range(1, i + 1):
            if 9**nine > i:
                break
            memo[i] = min(memo[i], memo[i - 9**nine] + 1)
        for six in range(1, i + 1):
            if 6**six > i:
                break
            memo[i] = min(memo[i], memo[i - 6**six] + 1)
        memo[i] = min(memo[i], memo[i - 1] + 1)

    print(memo[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 42860
import sys
import numpy as np

def solve(dpa, dpb, dpc, a, b, c):
    dpa[N - 1] = a[N - 1]
    dpb[N - 1] = b[N - 1]
    dpc[N - 1] = c[N - 1]
    for n in range(N - 2, -1, -1):
        dpa[n] = max(dpb[n + 1], dpc[n + 1]) + a[n]
        dpb[n] = max(dpc[n + 1], dpa[n + 1]) + b[n]
        dpc[n] = max(dpa[n + 1], dpb[n + 1]) + c[n]

nin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
N = nin[0]
abc = nin[1: 3 * N + 1].reshape(N, 3).T
a = abc[0]
b = abc[1]
c = abc[2]
dpa = np.zeros_like(a)
dpb = np.zeros_like(b)
dpc = np.zeros_like(c)
solve(dpa, dpb, dpc, a, b, c)
print(max(dpa[0], dpb[0], dpc[0]))


Measured memory_bytes: 18408
#include<stdio.h>
#include<limits.h>
#define N 2000000
int heap_size;
int A[N];

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
} 
int right(int i){
  return 2*i+1;
}
void heapIncreaseKey(int i, int key){
  int temp;
  if(key < A[i]){
    printf("新しいキーは現在のキーより小さい\n");
  }
  A[i] = key;
  while( i > 1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;
    i = parent(i);
  }
}
void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  A[heap_size] = INT_MIN;
  heapIncreaseKey(heap_size,key);
}


void maxHeapify(int i){
  int l,r,largest,temp;  

  l = left(i);
  r = right(i);
  if(l <= heap_size && A[l] > A[i]){
    largest = l;
  }
  else largest = i;
  if(r <= heap_size && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

int heapExtractMax(){
  int max;
  if(heap_size < 1){
    return 0;
  }
  max = A[1];
  A[1] = A[heap_size];
  heap_size = heap_size - 1;
  maxHeapify(1);
  return max;
}

int main(){
  char M[10];
  int n;
  while(1){
    scanf("%s",M);
    if(M[2] == 'd'){
      break;
    }
    else if(M[2] == 's'){
      scanf("%d",&n);
      maxHeapInsert(n);
      
    }
    else if(M[2] == 't'){
      printf("%d\n",heapExtractMax());
    }
  }
  return 0;
}

Measured memory_bytes: 4700
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *z;
  Node *x = root;
  
  z = (Node *) malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if (y == NIL)
    root = z;
  else if (z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 26612
#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;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int sum(0); stack<int>s1; stack<pair<int, int>>s2;
	rep(i, 0, s.size()) {
		if (s[i] == '\\')s1.push(i);
		else if (s[i] == '/' && !s1.empty()) {
			int x = s1.top(); s1.pop();
			sum += i - x;
			int a = i - x;
			while (!s2.empty() && x < s2.top().first) {
				a += s2.top().second; s2.pop();
			}
			s2.push(make_pair(x, a));
		}
	}

	cout << sum << endl;
	
	vector<int>ans;
	while (!s2.empty()) {
		ans.emplace_back(s2.top().second);
		s2.pop();
	}
	reverse(all(ans));
	cout << ans.size();
	rep(i, 0, ans.size()) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3280
def root(parents, i):
    depth = 0
    while parents[i] != i:
        i = parents[i]
        depth += 1

    return i, depth

def isSame(parents, a, b):
    return root(parents,a)[0] == root(parents, b)[0]

def union(parents, size, a, b):
    pa, deptha = root(parents, a)
    pb, depthb = root(parents, b)
    if pa == pb: # already same group
        return
    if deptha < depthb:
        parents[pa] = pb
        size[pb] += size[pa]
    else:
        parents[pb] = pa
        size[pa] += size[pb]

def resolve():
    N, M, K = list(map(int, input().split()))
    parents = [i for i in range(N)]
    size = [1] * N
    ans = [0] * N

    for i in range(M):
        A, B = list(map(int, input().split()))
        ans[A-1] += 1
        ans[B-1] += 1
        union(parents, size, A-1, B-1)

    for i in range(N):
        pi = root(parents, i)[0]
        ans[i] = size[pi] - ans[i] -1 # eliminate friend count from candidate

    for i in range(K):
        A, B = list(map(int, input().split()))
        if isSame(parents, A-1, B-1):
            ans[A-1] -= 1
            ans[B-1] -= 1

    print(" ".join(map(str, ans)))

resolve()

Measured memory_bytes: 76192
#include<iostream>
using namespace std;
int main(){
    int ans,count;
    ans=700;
    count=0;
    char str[3];
    cin>>str;
    
    for(int i=0;i<3;i++){
        if(str[i]=='o'){
            count++;
        }
    }
    cout << ans+(count*100) << endl;
    return 0;
}

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

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, Q) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<int>().ToArray();
            var ft = new FenwickTree(N);
            for (var i = 0; i < N; i++)
            {
                ft.Add(i, A[i]);
            }

            for (var i = 0; i < Q; i++)
            {
                var (t, p, x) = Scanner.Scan<int, int, int>();
                if (t == 0) ft.Add(p, x);
                else Console.WriteLine(ft.Sum(p, x));
            }
        }

        public class FenwickTree
        {
            private readonly int _n;
            private readonly long[] _data;

            public FenwickTree(int n = 0)
            {
                _n = n;
                _data = new long[n];
            }

            public void Add(int p, long x)
            {
                if (p < 0 || _n <= p) throw new ArgumentException(nameof(p));
                p++;
                while (p <= _n)
                {
                    _data[p - 1] += x;
                    p += p & -p;
                }
            }

            public long Sum(int l, int r)
            {
                if (0 > l || l > r || r > _n) throw new ArgumentException();
                return Sum(r) - Sum(l);
            }

            private long Sum(int r)
            {
                var s = 0L;
                while (r > 0)
                {
                    s += _data[r - 1];
                    r -= r & -r;
                }

                return s;
            }
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 86600
#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>
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()
{
  int n;
  bool kaigyou = false;
  while(cin >> n, n) {
    if(kaigyou) cout << endl;
    kaigyou = true;
    int cnt[4]; FOR(i,0,4) cin >> cnt[i];
    int ans[4]; CLR(ans);
    int yen[4] = {10, 50, 100, 500};
    FOR(i,0,4) {
      while(cnt[i]) {
        n -= yen[i];
        cnt[i]--;
        ans[i]++;
      }
    }

    if(n < 0) {
      while(abs(n) % 50) {
        n += 10;
        ans[0] = max(0, ans[0] - 1);
      }
      while(abs(n) % 100) {
        n += 50;
        ans[1] = max(0, ans[1] - 1);
      }
      while(abs(n) % 500) {
        n += 100;
        ans[2] = max(0, ans[2] - 1);
      }
      while(n < 0) {
        n += 500;
        ans[3] = max(0, ans[3] - 1);
      }
    }
    FOR(i,0,4) if(ans[i] > 0) cout << yen[i] << " " << ans[i] << endl;

  }
  return 0;
}

Measured memory_bytes: 3096
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
// also tink all answers possible for a question
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e9;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
    cin>>a[i];
  ll ans=0;
  for(ll i=1;i<n;i++)
  {
    if(a[i]-a[i-1]<0)
    {
      ans=ans+abs(a[i]-a[i-1]);
      a[i]=a[i-1];
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 5196
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {

	public static void main(String[] args)throws Exception {

		int num , h , m , s ;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("");
		num = Integer.parseInt(br.readLine());

		h = num / 3600;
		m = (num % 3600) / 60;
		s = (num % 3600) % 60;

		System.out.println(h + ":" + m + ":" + s);



	}

}

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

int main() {
  int N;
  cin >> N;
  vector<int>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  int ans = vec[0];
  if(vec[0] == 2){
    cout << 1 << endl;
    return 0;
  }
  for(int i=0; i<N; i++){
    ans = vec[ans-1];
    if(ans == 2){
      cout << i+2 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3736
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, ans int
	var baseT, comfortableT, gessT, hight float64
	fmt.Scan(&n, &baseT, &comfortableT)

	for i := 0; i < n; i++ {
		fmt.Scan(&hight)
		diff := math.Abs(comfortableT - (baseT - hight*0.006))
		if i == 0 || gessT > diff {
			gessT = diff
			ans = i + 1
		}
	}
	fmt.Println(ans)
}


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

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

  int n;
  cin >> n;
  const int MAX = 1e6 + 5;
  vector<int> freq(MAX), cnt(MAX);
  int g = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    freq[a]++;
    if (g == 0) {
      g = a;
    }
    g = __gcd(g, a);
  }
  for (int i = 1; i < MAX; i++) {
    for (int j = i; j < MAX; j += i) {
      cnt[i] += freq[j];
    }
  }
  int pairwise = 1;
  for (int i = 2; i < MAX; i++) {
    if (cnt[i] > 1) {
      pairwise = 0;
    }
  }
  if (pairwise) {
    cout << "pairwise coprime\n";
  } else if (g == 1) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
  return 0;
}


Measured memory_bytes: 11112
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] array = br.readLine().split(" ");
        int a = Integer.parseInt(array[0]);
        int b = Integer.parseInt(array[1]);
        int c = Integer.parseInt(array[2]);
        int count=0;
        for(int i=a;i<b+1;i++){
        	if(c%i==0) count++;
        }
        System.out.println(count);
	}
}

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

int main(){
    long long a, b ,c, x, y;
    cin >> a >> b >> c >> x >> y;

    long long min_money = 1e12;
    long long X = x, Y = y;
    for(long long i = 0; i <= 100000; i++){
        long long now_money = 2*i*c;
       
        x = X - i;
        y = Y - i;
        if(x > 0){
            now_money += x*a;
        }
        if(y > 0){
            now_money += y*b;
        }

        min_money = min(min_money, now_money);

    }

    cout << min_money << endl;

    return 0;
}

Measured memory_bytes: 256
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def solve():
    memo = A[0]
    for i in range(1, N):
        memo = lcm(memo, A[i])

    ans = 0
    for i in range(N):
        ans += memo // A[i]

    return ans % (10 ** 9 + 7)

print(solve())


Measured memory_bytes: 6072
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,k,a[103];
int dp[103][100004];
int num[100004];
int main(){
	read(n),read(k);
	for (int i=1;i<=n;i++) read(a[i]);
	dp[0][0]=1;
	for (int i=1;i<=n;i++){
		memset (num,0,sizeof(num));
		for (int j=0;j<=k;j++) num[j]=dp[i-1][j];
		for (int j=1;j<=k;j++) num[j]=(num[j]+num[j-1])%MOD;
		for (int j=0;j<=k;j++){
			int l=max(0,j-a[i]);
			int go=(l==0)?num[j]:(num[j]-num[l-1]+MOD)%MOD; 
			dp[i][j]=go;
		}
	}
	write(dp[n][k]); 
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;


int main() {
	string s,t;
	cin >> s;
	cin >> t;
	if (s.size() + 1 == t.size() && t.substr(0,s.size()) == s) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 3644
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == '__main__':
    a, b = [int(x) for x in input().split()]
    print (gcd(a, b))


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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	double a, b, c; cin >> a >> b >> c;
	cout << (int)((a + b) / 2.0 * c) << '\n';
}


Measured memory_bytes: 256
import numpy as np
def main():
	A, B, H, M = map(float, input().split())
	R = H/12 + M*0.5/360
	r = M/60
	cos = np.cos((R-r)*2*np.pi)
	C = np.sqrt(A*A + B*B - 2*A*B*cos)
	print(C)
 
if __name__ == '__main__':
	main()

Measured memory_bytes: 27140
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <deque>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (size_t i=0; i<n; ++i)
    scanf("%d", &a[i]);

  std::deque<int> b;
  for (size_t i=0; i<n; ++i) {
    if (i % 2 == 0) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }

  if (n % 2 > 0)
    std::reverse(b.begin(), b.end());

  for (size_t i=0; i<n; ++i)
    printf("%d%c", b[i], i+1<n? ' ':'\n');
}


Measured memory_bytes: 3712
import sys

a = list(map(int, input().split()))

A = a[0]
B = a[1]
K = a[2]

m = min([A, B])

ans = []

for i in range(1, m+1):
  if A % i == 0 and B % i== 0:
    ans.append(i)
ans.reverse()
print(ans[K-1])    


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = 
                    new BufferedReader( new InputStreamReader(System.in));
            String seedStr = stdReader.readLine();

            String[] inputStr = seedStr.split(" ");

            String tateStr = inputStr[0];
            String yokoStr = inputStr[1];

            Integer tate = Integer.valueOf(tateStr);
            Integer yoko = Integer.valueOf(yokoStr);
 
            System.out.println(tate*yoko + " " + 2*(tate+yoko));
            System.exit(0);

            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        } 
    }
}

Measured memory_bytes: 24324
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans;
char s[15];
signed main(){
	scanf("%s",s);int n=strlen(s);
	for (int i=0;i<1<<(n-1);i++){
		int now=0;
		for (int j=0;j<n;j++){
			now=now*10+s[j]-48;
			if ((1<<j)&i)ans+=now,now=0;
		}
		ans+=now;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=200008;
int n,a[N],b[N],c[29][N];
int main(void)
{
	int i,j,k,ans;ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",a+i);
	for(i=1;i<=n;i++)scanf("%d",b+i);
	for(i=0;i<=27;i++)
	{
		k=(1<<(i+1))-1;
		for(j=1;j<=n;j++)c[i][j]=b[j]&k;
		sort(&c[i][1],(&c[i][n+1]));
	}
	sort(b+1,b+1+n);
	j=0;for(i=1;i<=n;i++){j^=(n+1-(lower_bound(b+1,b+n+1,(1<<28)-a[i])-b))&1;ans=j;}
	for(k=27;k>=0;k--)
	{
		j=0;
		for(i=1;i<=n;i++)
		{
			a[0]=a[i]&((1<<(k+1))-1);
			j^=(n+1-(lower_bound(&c[k][1],&c[k][n+1],(1<<(k+1))+(1<<k)-a[0])-(&c[k][0])))&1;
			j^=(lower_bound(&c[k][1],&c[k][n+1],(1<<(k+1))-a[0])-lower_bound(&c[k][1],&c[k][n+1],(1<<k)-a[0]))&1;
		}
		ans=(ans<<1)+j;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

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

	vector<pair<int, int>> p(n);
	rep(i, n) {
		int x, l;
		cin >> x >> l;
		p[i] = make_pair(x + l, x - l);
	}
	sort(all(p));
	//for(auto i : p){ cout << i.first << ' ' << i.second << endl; }

	int sum = 0;
	int cur = -1e10;
	rep(i,n){
		if (p[i].second >= cur) {
			cur = p[i].first;
			sum++;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAX 4000000
using namespace std;

int main() {
	int n;
	int mincost = MAX;
	cin >> n;
	vector<int> input;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		input.push_back(temp);
	}
	sort(input.begin(), input.end());
	for (int i = input.at(0); i <= input.at(n - 1); i++) {
		int cost = 0;
		for (int j = 0; j < n; j++) {
			cost += (input.at(j) - i) * (input.at(j) - i);
		}
		if (cost < mincost) mincost = cost;
	}

	cout << mincost << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int n, r, x1, x2, h;
	while(scanf("%d%d", &r, &n), r){
		map<int,int> mp;
		for(int i = 0; i < n; ++i){
			scanf("%d%d%d", &x1, &x2, &h);
			for(int x = x1; x < x2; ++x){
				int &t = mp[x];
				t = max(t, h);
			}
		}

		double ans = 1e99;
		for(int x = -r; x < r; ++x){
			double p = (x < 0 ? x + 1 : x);
			ans = min(ans, mp[x] + r - sqrt(r * r - p * p));
		}

		printf("%f\n", ans);
	}
}

Measured memory_bytes: 1068
import java.util.*;
import java.math.*;

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

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			String[] no = new String[n];
			BigInteger[] sum = new BigInteger[n];
			int size = 0;

			for(int i=0;i<n;i++){
				String s = sc.next();
				BigInteger mul = sc.nextBigInteger().multiply(sc.nextBigInteger());
				int j;

				for(j=0;j<size;j++){
					if(no[j].equals(s)){
						sum[j] = sum[j].add(mul);
						break;
					}
				}

				if(j == size){
					no[size] = s;
					sum[size] = mul;
					size++;
				}
			}

			boolean naflg = true;
			for(int i=0;i<size;i++){
				if(sum[i].compareTo(million) >= 0){
					System.out.println(no[i]);
					naflg = false;
				}
			}

			if(naflg) System.out.println("NA");
		}
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
// using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,k,c;
  cin >> n >> k >> c;

  string s;
  cin >> s;
  vec a(n);//i日目以降、できるだけ頑張って働いたときの最大日数
  vec b(n);//i日目からさかのぼって、できるだけ頑張って働いたときの最大日数

  vec d;//働ける日を記録
  for(ll i=0;i<n;i++)if(s[i]=='o')d.emplace_back(i);

  for(ll i=n-1;i>=0;i--){
    if(i+c+1>=n){
      if(s[i]=='o')a[i]=1;
      else if(i<d[d.size()-1])a[i]=1;
    }
    else{
      if(s[i]=='o')a[i]=a[i+c+1]+1;
      else if(i!=n-1)a[i]=a[i+1];
    }
  }

  for(ll i=0;i<n;i++){
    if(i<c+1){
      if(s[i]=='o')b[i]=1;
      else if(d[0]<i)b[i]=1;
    }
    else{
      if(s[i]=='o')b[i]=b[i-c-1]+1;
      else if(i!=0)b[i]=b[i-1];
    }
  }

  vec e;//愚直に働いた場合、どこで働くか
  ll t=mod;
  for(ll i=0;i<n;i++){
    if(s[i]=='x'){
      t++;
      continue;
    }
    else{
      if(t<c)t++;
      else{
        e.emplace_back(i);
        t=0;
      }
    }
  }

  //for(ll i=0;i<3;i++)cout << e[i] << endl;

  vec ans;
  for(ll i=0;i<n;i++){
    if(s[i]=='x')continue;
    if(i<=e[0]){
      if(i!=(n-1)){
        if(a[i+1]<k)ans.emplace_back(i+1);
      }
      else if(k==1)ans.push_back(i+1);
    }
    else if(d[d.size()-1]==i){
      if(b[i-1]<k)ans.emplace_back(i+1);
    }
    else{
      ll p=lower_bound(e.begin(),e.end(),i)-e.begin()-1;
      //if(i==9)cout << e[p] << endl;
      p=e[p];
      if(max(p+c,i+1)>=n)continue;
      if(b[p]+a[max(p+c,i+1)]<k)ans.emplace_back(i+1);
    }
  }


  for(ll i=0;i<ans.size();i++)cout << ans[i] << endl;
  
  //for(ll i=0;i<4;i++)cout << d[i] << " ";

  //cout << b[9] << " " << a[10] <<  endl;

  return 0;
}

Measured memory_bytes: 12820
import sys
input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    a = [[int(x) for x in input().split()] for _ in range(H)]
    ans = []
    for i in range(H):
        for j in range(W):
            if a[i][j] & 1:
                if j == W - 1 and i == H - 1:
                    continue
                if j == W - 1:
                    ans.append((i + 1, j + 1, i + 2, j + 1))
                    a[i + 1][j] += 1
                else:
                    ans.append((i + 1, j + 1, i + 1, j + 2))
                    a[i][j + 1] += 1

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



if __name__ == '__main__':
    main()



Measured memory_bytes: 26132
M = input()
m = int(M)
N = list(M)
if len(N) == 1:
  print(m)
elif len(N) == 2:
  print(9)
elif len(N) == 3:
  print(9+(m-100)+1)
elif len(N) == 4:
  print(909)
elif len(N) == 5:
  print(909+(m-10000)+1)
elif len(N) == 6:
  print(90909)
elif m == 100000:
  print(90910)
  

Measured memory_bytes: 3060
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << '\n';
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n = in(), l = in();
  vector<string> v(n);
  REP(i, n) cin >> v[i];
  sort(ALL(v));
  string ans;
  REP(i, n) ans += v[i];
  print(ans);

  return 0;
}



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

   int main() {
   string str;
   cin>>str;
   int q,a,b;
   cin>>q;
   string S,p;
   while(q--){
    cin>>S>>a>>b;

    if(S=="replace"){cin>>p;str=str.replace(a,b-a+1,p);}
     else if(S=="reverse"){
       string K=str.substr(a,b-a+1);
       reverse(K.begin(),K.end());
       str=str.replace(a,b-a+1,K);}
     else if(S=="print"){cout<<str.substr(a,b-a+1)<<endl;}
   }
   return 0;
   }


Measured memory_bytes: 3228
use std::io::*;
use std::str::FromStr;

fn main() {
    let (n, m, q): (usize, usize, usize) = (read(), read(), read());
    let s: Vec<Vec<i64>> = (0..n)
        .map(|_| {
            read::<String>()
                .chars()
                .map(|x| if x == '1' { 1 } else { 0 })
                .collect()
        })
        .collect();

    let mut black: Vec<Vec<i64>> = vec![vec![0; m + 1]; n + 1];
    let mut tate: Vec<Vec<i64>> = vec![vec![0; m + 1]; n + 1];
    let mut yoko: Vec<Vec<i64>> = vec![vec![0; m + 1]; n + 1];

    for i in 0..n {
        for j in 0..m {
            black[i + 1][j + 1] = black[i + 1][j] + s[i][j];
            tate[i + 1][j + 1] += tate[i + 1][j];
            if i > 0 && s[i - 1][j] == 1 && s[i][j] == 1 {
                tate[i + 1][j + 1] += 1;
            }
            yoko[i + 1][j + 1] += yoko[i + 1][j];
            if j > 0 && s[i][j - 1] == 1 && s[i][j] == 1 {
                yoko[i + 1][j + 1] += 1;
            }
        }
    }
    for i in 0..n {
        for j in 0..m {
            black[i + 1][j + 1] += black[i][j + 1];
            tate[i + 1][j + 1] += tate[i][j + 1];
            yoko[i + 1][j + 1] += yoko[i][j + 1];
        }
    }

    for _ in 0..q {
        let (x1, y1, x2, y2): (usize, usize, usize, usize) = (read(), read(), read(), read());
        let b = black[x2][y2] - black[x2][y1 - 1] - black[x1 - 1][y2] + black[x1 - 1][y1 - 1];
        let t = tate[x2][y2] - tate[x2][y1 - 1] - tate[x1][y2] + tate[x1][y1 - 1];
        let y = yoko[x2][y2] - yoko[x2][y1] - yoko[x1 - 1][y2] + yoko[x1 - 1][y1];
        println!("{}", b - t - y);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 169724
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))
#define MOD 1000000007

typedef long long ll;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<1000000007>;

ll  dp[21][1001];
ll  COM[1005][1005];
int main() {
    int n,k; cin >> n >> k;
    vector<ll> a(k); rep(i,k) cin >> a[i];
    vector<mint> fact(1005);
    fact[0] = 1;
    for (int i = 1; i < fact.size(); ++i) {
        fact[i] = fact[i - 1] * i;
    }
    const auto comb = [&fact](int n, int r) {
        return fact[n] / fact[r] / fact[n - r];
    };

    rep(i,1005) rep(j,1005) COM[i][j] = 1;

    rep(i,n+1){ 
        for(int j=0;j<=i;j++) COM[i][j] = comb(i,j).a;
    }
    rep(i,k+1) rep(j,n+1) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i,k) for(int l=0;l<=a[i];l++) for(int j=0;j<=n-l;j++){
                dp[i+1][j+l] = (dp[i+1][j+l] + (((COM[n-j][l] * COM[n-l][a[i]-l]) % MOD) * dp[i][j]) % MOD) % MOD;  
    }

    rep(i,k+1){ 
       // rep(j,n+1) cout << dp[i][j] << " ";
     //   cout << endl;
    }

    cout << dp[k][n] << endl;
    return 0;
}


Measured memory_bytes: 8320
#include <stdio.h>

static const int MAX_CARD_SIZE = 52;
static const int SENTINEL = 1000;

int main(void) {
    int i, j, k, t, n, r, c;
    int p_a, p_b, p_c, deck_A[MAX_CARD_SIZE/2], deck_B[MAX_CARD_SIZE/2], deck_C[MAX_CARD_SIZE];

    while (EOF != scanf(" %d %d", &n, &r)) {
        for (i = 0; i < n; i++) {
            deck_C[i] = i;
        }

        for (i = 0; i < r; i++) {
            scanf(" %d", &c);

            t = n / 2;
            for (j = 0; j < t; j++) {
                deck_B[j] = deck_C[j];
            }
            deck_B[j] = SENTINEL;

            for (j = t; j < n; j++) {
                deck_A[j - t] = deck_C[j];
            }
            deck_A[j - t] = SENTINEL;

            /*
             * for (j = 0; deck_A[j] != SENTINEL; j++) {
             *     printf("%d ", deck_A[j]);
             * }
             * printf("\n");
             * for (j = 0; deck_B[j] != SENTINEL; j++) {
             *     printf("%d ", deck_B[j]);
             * }
             * printf("\n");
             */

            // merge
            p_a = p_b = p_c = 0;
            while (deck_A[p_a] != SENTINEL || deck_B[p_b] != SENTINEL) {
                for (k = 0; k < c; k++) {
                    if (deck_A[p_a] == SENTINEL) {
                        break;
                    }
                    deck_C[p_c++] = deck_A[p_a++];
                }

                for (k = 0; k < c; k++) {
                    if (deck_B[p_b] == SENTINEL) {
                        break;
                    }
                    deck_C[p_c++] = deck_B[p_b++];
                }
            }

            /*
             * for (j = 0; j < n; j++) {
             *     printf("%d ", deck_C[j]);
             * }
             * printf("\n");
             */
        }
        printf("%d\n", deck_C[n - 1]);
    }

    return 0;
}

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

 
int main() {
    ll n,k;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    long long res = 0;
    int right = 0;
    int sum = 0; // AND 和
    for (int left = 0; left < n; ++left) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            ++right;
        }
        res += right - left;
        if (left == right) ++right;
        else {
            sum -= a[left]; // a[left] を削除 (sum ^= a[left] でも OK)
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

//WeightedUnionFind
template<typename T>
struct WeightedUnionFind {
private:
    vector<int> par;
    vector<int> rank;
    vector<T> diff_weight;
public:
    WeightedUnionFind(int n) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    T weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // y - x = w
    bool unite(int x, int y, T w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    // y - x
    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int n, q; cin >> n >> q;
    WeightedUnionFind<ll> wuni(n);
    REP(i, q) {
        int p; scanf("%d", &p);
        if (p == 0) {
            int x, y, z; scanf("%d %d %d", &x, &y, &z);
            wuni.unite(x, y, z);
        }
        else {
            int x, y; scanf("%d %d", &x, &y);
            if (!wuni.same(x,y)) puts("?");
            else printf("%lld\n", wuni.diff(x,y));
        }
    }
    return 0;
}


Measured memory_bytes: 4404