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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

const string yesno[2] = {"NO", "YES"};

ll N;
ll A[100000];

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

    std::cin >> N;

    if(N == 1){
        std::cout << yesno[1] << std::endl;
        return 0;
    }
    
    ll sum = 0ll;
    
    for(int i=0;i<N;++i){
        std::cin >> A[i];
        sum += A[i];
    }

    ll sum2 = (N % 2 == 0 ? N / 2 * (N + 1) : (N + 1) / 2 * N);
    if(sum % sum2 != 0){
        std::cout << yesno[0] << std::endl;
        return 0;
    }
    
    sum /= sum2;

    for(int i=0;i<N;++i){
        ll x = A[(i+N-1)%N] - A[i] + sum;
        if(x < 0 || x % N != 0){
            std::cout << yesno[0] << std::endl;
            return 0;          
        }
    }

    std::cout << yesno[1] << std::endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int n, i, sum = 0;
    scanf ("%d", &n);

    if (n%10 == 0){
        printf("10\n");
    } else {
        for (i = 0; i < 10; i++)
        {
            sum += n % 10;
            n /= 10;
            if (n < 10){
                sum+=n;
                break;
            }
        }
        printf ("%d\n", sum);       
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	string s;
	ll ans = 0;

	std::cin >> s;
	rep(i, 0, s.size()) {
		if (s[i] == '1') {
			ans++;
		}
	}

	outn(ans);
	return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
count = 0
flag = False
if k==0:
    flag = True
for i in range(k+1,n+1):
    if n%i >= k:
        count += (i-k)*(n//i) + n%i - k + 1
    else:
        count += (i-k)*(n//i)
if flag:
    print(n*n)
else:
    print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, a, b;
	std::cin >> n >> a >> b;
	long long ans = 0;
	int prv = -1;
	for(int i = 0; i < n; i++) {
		int nxt;
		std::cin >> nxt;
		if(prv != -1) {
			ans += std::min((long long) b, (long long) a * (nxt - prv));
		}
		prv = nxt;
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

#define NUM 10

int main(void)
{
	int height[NUM];
	int i = 0, j, temp;

	while (i < NUM) {
		scanf("%d", &height[i]);
		if (height[i] < 0 || height[i] > 10000) {
			scanf("%d", &height[i]);
		}
		else
		{
			i++;
		}
	}

	for (i = 0; i<NUM; i++) {
		for (j = i + 1; j<NUM; j++) {
			if (height[i] < height[j]) {
				temp = height[j];
				height[j] = height[i];
				height[i] = temp;
			}
		}
	}

	for (i = 0; i<3; i++) {
		printf("%d\n", height[i]);
	}

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(void){
    int N,M,i,x,y;
    int load[50];
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++) load[i]=0;
    for(i=0;i<M;i++){
        scanf("%d %d",&x,&y);
        load[x-1]++;
        load[y-1]++;
    }
    for(i=0;i<N;i++) printf("%d\n",load[i]);
    return 0;
}

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



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s; cin>>s;
    int n=s.length();
    for(int i=0;i<n-2;i++)
    {
        if(s[i]==s[i+1] || s[i+1]==s[i+2] || s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    for(int i=0;i<n-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2;
            return 0;
        }
    }
    cout<<-1<<" "<<-1;
    return 0;
}


Measured memory_bytes: 512
import collections
import string

n = int(input())
S = [set() for _ in range(n)]
S_list = []

for i in range(n):
    s = str(input())
    S_list.append(s)
    for w in s:
        S[i].add(w)

new_set = S[0]
for i in range(1,n):
    new_set = new_set & S[i]

Count_dict = {}
for w in new_set:
    new = {w:2500}
    Count_dict.update(new)

for i in range(n):
    for key in Count_dict.keys():
        num = S_list[i].count(key)
        # print(key)
        # print(num)
        if num <= Count_dict[key]:
            Count_dict[key] = num

Count_dict = sorted(Count_dict.items())

ans = ''
for i in range(len(Count_dict)):
    ans += Count_dict[i][0] * Count_dict[i][1]

print(ans)


Measured memory_bytes: 3956
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
    global a,b,c,n
    if i >= n:
        return 0
    if mem[i][p] != -1:
        return mem[i][p]
    av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
    if p != -1:
        av[p] = 0
    ans = max(av)
    mem[i][p] = ans
    return ans
ans = rp(0, -1)
print(ans)
        
    
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# maybe because the values that come later on decide more on what you choose?



Measured memory_bytes: 192328
// https://qiita.com/drken/items/fd4e5e3630d0f5859067
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	m := make(map[int]bool, N)

	var d int
	for i := 0; i < N; i++ {
		fmt.Scan(&d)
		m[d] = true
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if (u == NIL || k ==u->key) return u;

  if(k < u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
  
}


void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;

  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL)x->parent = y->parent;

  if(y->parent == NIL) root = x;

  else if(y == y->parent->left) y->parent->left = x;

  else y->parent->right = x;

  if(y != z)z->key = y->key;
  
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct 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;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20612
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc123d
int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    ll a[1000], b[1000], c[1000];
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a, a+x, greater<ll>());
    sort(b, b+y);
    sort(c, c+z);
    ll bc[1000000];
    rep(i, y)rep(j, z){
        bc[i*z+j] = b[i]+c[j];
    }
    sort(bc, bc+x*y, greater<ll>());
    ll ans[3000000];
    rep(i, x)rep(j, k){
        ans[i*k+j] = a[i]+bc[j];
    }
    sort(ans, ans+x*k, greater<ll>());
    rep(i, k){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 31616
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

using Graph = vector<vector<ll> >;

int main() {
    // 頂点数と辺数
    ll N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (ll i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    //二分グラフの判定
    bool is_bipartite = true;
    vector<ll> dist(N, -1);
    queue<ll> que;
    for (ll v = 0; v < N; ++v) {
        if (dist[v] != -1) continue; // v が探索済みならスルー
        dist[v] = 0, que.push(v);
        while (!que.empty()) {
            ll v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    que.push(nv);
                } else {
                    // 整合性を確認する
                    if (dist[v] == dist[nv]) is_bipartite = false;
                }
            }
        }
    }


    if(!is_bipartite){
      ll ans = N*(N-1)/2 - M;
      cout<<ans<<endl;
    }
    else{
      ll ans = 0;
      rep(i,N){
        if(dist[i] %2 == 0) ans++;
      }
      ans = ans*(N-ans) - M;
      cout<<ans<<endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  vector<vector<int>> activities(n, vector<int>(3));
  for (int i = 0; i < n; ++i) {
    // cin >> a[i] >> b[i] >> c[i];
    cin >> activities[i][0] >> activities[i][1] >> activities[i][2];
  }
  vector<vector<int>> dp(n, vector<int>(3, INT_MIN));
  dp[0][0] = activities[0][0];
  dp[0][1] = activities[0][1];
  dp[0][2] = activities[0][2];
  for (int day = 1; day < n; ++day) {
    for (int activity = 0; activity < 3; ++activity) {
      for (int a = 0; a < 3; ++a) {
        if (activity == a) continue;
        dp[day][activity] =
            max(dp[day][activity], dp[day - 1][a] + activities[day][activity]);
      }
    }
  }
  int ret = INT_MIN;
  for (int v : dp.back()) {
    ret = max(ret, v);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 15400
n, q = [int(i) for i in input().split()]

name = []
time = []

for i in range(n):
    x, y = [i for i in input().split()]
    y = int(y)
    name.append(x)
    time.append(y)

from collections import deque
time = deque(time)
name = deque(name)

count = 0
time_out = []
name_out = []

while len(time) > 0:
    a = time.popleft()
    b = name.popleft()
    if a > q:
        a -= q
        time.append(a)
        name.append(b)
        count += q
    else:
        count += a
        time_out.append(count)
        name_out.append(b)

for i, j in zip(name_out, time_out):
    print(i, j)



Measured memory_bytes: 12192
program probc
    implicit none
    integer::a, b, c, x, y, i, tmp, ans
    read(*,*) a, b, c, x, y

    ans = a*x + b*y
    tmp = ans
    do i = 0, max(x,y)
        tmp = c*2*i + a*max(x-i,0) + b*max(y-i,0)
        ans = min(ans,tmp)
    end do
    write(*,*) ans
    stop
end program

Measured memory_bytes: 2856
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var spl = s.Split(' ');
        var w = int.Parse(spl[0]);
        var a = int.Parse(spl[1]);
        var b = int.Parse(spl[2]);

        if (a <= b && b <= a+w) return 0;
        if (a <= b+w && b+w <= a+w) return 0;

        if(b > a + w) {
            return Math.Abs(b - a - w);
        }
        else {
            return Math.Abs(a - b - w);
        }
    }
}


Measured memory_bytes: 11092
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-23 22:55
# @url:https://atcoder.jp/contests/abc176/tasks/abc176_c
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    A=list(map(int,input().split()))
    mx=A[0]
    ans=0
    for a in A:
        mx=max(a,mx)
        ans+=(mx-a)
    print (ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 114832
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if ((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c=0,i,n;
    string a,b;
    cin>>a>>b;
    for(i=0; i<a.size(); i++)
    {
        if(a[i]!=b[i])
        {
            c++;
        }


    }

cout<<c<<endl;

}


Measured memory_bytes: 3856
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  char s[n+1];
  scanf("%s",s);
  long long int ans = 1;
  int num[26];
  int i;
  for(i=0;i<26;i++){
    num[i] = 0;
  }
  for(i=0;i<n;i++){
    num[(s[i]-'a')]++;
  }
  for(i=0;i<26;i++){
    ans = (ans * (num[i]+1)) % 1000000007;
  }
  ans--;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

#define Yes(x) cout<<(x?"Yes":"No")<<endl;

int main() {
    string S;
    cin >> S;
    int cou = 0;
    rep(i, S.size() ){
        if (S[i] == '+')cou++;
        else cou--;
    }
    cout << cou << endl;





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 41, maxm = 1<<18, mod = 1'000'000'007;
int f[maxn][maxm];
int main(){
	int n, x, y, z; cin >> n >> x >> y >> z;
	int msk = (1<<(x + y + z + 1)) - 1;
	f[0][1] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= msk; j++){
			if(f[i][j]){
				for(int k = 1; k <= 10; k++){
					int nj = (j<<k) | 1; nj &= msk;
					int cn = 0;
					if(nj&(1<<z)) cn++;
					if(nj&(1<<(z+y))) cn++;
					if(nj&(1<<(z+y+x))) cn++;
					if(cn != 3){
						f[i + 1][nj] += f[i][j];
						if(f[i + 1][nj] >= mod) f[i + 1][nj] -= mod;
					}
				}
			}
		}
	}
	int tot = 1;
	for(int i = 0; i < n; i++) tot = 10ll * tot % mod;
	for(int j = 0; j <= msk; j++){
		tot += mod - f[n][j];
		if(tot >= mod) tot -= mod;
	}
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef vector < int > vi ;
typedef pair < int, int > pii ;

const int N = 1e6 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

multiset < int > cur, rem, temp ;
int n, a[N] ;

int main()
{
    fastio; cin >> n ;
    for(int i = 0; i < (1 << n); i++)
    {
        cin >> a[i] ;
        rem.insert(a[i]);
    }

    cur.insert(*rem.rbegin());
    rem.erase(rem.find(*rem.rbegin()));

    for(int i = 1; i <= n; i++)
    {
        temp.clear();
        for(int x : cur)
        {
            auto it = rem.lower_bound(x);
            if(it == rem.begin())
            {
                cout << "No" ;
                return 0 ;
            }
            it-- ;
            temp.insert(*it);
            rem.erase(rem.find(*it));
        }
        for(int x : temp) cur.insert(x);
        // for(int x : cur) cout << x << " " ;
        // cout << endl ;
    }
    cout << "Yes" ;
}



Measured memory_bytes: 19712
#include<iostream>
#include<algorithm>
#define INF 1 << 30
using namespace std;

int main()
{
	int pmin = INF, jmin = INF;
	for (int i = 0; i < 3; i++){
		int in;
		cin >> in;
		pmin = min(pmin, in);
	}
	for (int i = 0; i < 2; i++){
		int in;
		cin >> in;
		jmin = min(jmin, in);
	}
	cout << pmin + jmin - 50 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int num; //??°???
    struct Node *prev;
    struct Node *next;
};

struct Node *note;

void insert(int num) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->num = num;
    note->next->prev = x;
    x->next = note->next;
    note->next = x;
    x->prev = note;
}

struct Node* search(int num) {
    struct Node *x = note->next;
    while(x != note && x->num != num ) {
        x = x-> next;
    }
    return x;
}

void deleteNode(struct Node *t) {
    if (t == note) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
}


int main(void) {
    int num, n;
    char command[20];
    scanf("%d", &n);
    note = (struct Node *)malloc(sizeof(struct Node));
    note->next = note;
    note->prev = note;
    for (int i = 0; i < n; i++) {
        scanf("%s%d",command, &num);
        if(command[0] == 'i') { //insert?????´???
            insert(num);
        }else if(command[0] == 'd') { //delete?????´???
            if(strlen(command) > 6) {
                if(strlen(command) > 10) {
                    deleteNode(note->next); //deleteFirst
                }else if(strlen(command) > 9) {
                    deleteNode(note->prev); //deleteLast
                }
            }else {
                deleteNode(search(num)); //delete
            }
        }
    }
    struct Node *x;
    x = note->next;
    int i = 0;
    while(1) {
        if (x == note) break;
        if(i++ > 0) printf(" ");
        printf("%d", x->num);
        x = x->next;
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 36052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    int H, W;
    cin >> H >> W;

    vector<vector<bool>> isodd(H, vector<bool>(W));
    vector<pii> move;
    int cnt = 0;
    bool above = false;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int a;
            cin >> a;
            if (i == H - 1 && j == W - 1)
                break;
            if (isodd[i][j] = isodd[i][j] ^ (a % 2)) {
                if (j + 1 < W)
                    isodd[i][j + 1] = !isodd[i][j + 1];
                else
                    isodd[i + 1][j] = !isodd[i + 1][j];
                move.push_back({i + 1, j + 1});
            }
        }
    }

    cout << move.size() << '\n';
    for (auto p : move) {
        cout << p.first << " " << p.second << " ";
        if (p.second + 1 <= W)
            cout << p.first << " " << p.second + 1;
        else
            cout << p.first + 1 << " " << p.second;
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 3320
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int mat[20][20];
int to[20][20];
int v[20][20];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)scanf("%d",&mat[i][j]);
	while(b--){
		int o;scanf("%d",&o);
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)to[i][j]=mat[i][j];
		if(o==0){
			int r,c,sz,th;
			scanf("%d%d%d%d",&r,&c,&sz,&th);
			r--;c--;
			if(th==90){
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
					to[r+j][c+sz-1-i]=mat[r+i][c+j];
				}
			}else if(th==180){
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
					to[r+i][c+j]=mat[r+sz-1-i][c+sz-1-j];
				}
			}else if(th==270){
				for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
					to[r+sz-1-j][c+i]=mat[r+i][c+j];
				}
			}
		}else if(o==1){
			int r,c,sz;
			scanf("%d%d%d",&r,&c,&sz);r--;c--;
			for(int i=0;i<sz;i++)for(int j=0;j<sz;j++)to[r+i][c+j]=!to[r+i][c+j];
		}else if(o==2){
			int r;scanf("%d",&r);r--;
			for(int i=0;i<a-1;i++)to[r][i]=mat[r][i+1];
			to[r][a-1]=mat[r][0];
		}else if(o==3){
			int r;scanf("%d",&r);r--;
			for(int i=0;i<a-1;i++)to[r][i+1]=mat[r][i];
			to[r][0]=mat[r][a-1];
		}else{
			int r,c;scanf("%d%d",&r,&c);r--;c--;
			queue<pair<int,int> >Q;
			int color=to[r][c];
			for(int i=0;i<a;i++)for(int j=0;j<a;j++)v[i][j]=0;
			v[r][c]=1;
			Q.push(make_pair(r,c));
			while(Q.size()){
				int row=Q.front().first;
				int col=Q.front().second;
				Q.pop();
				for(int i=0;i<4;i++){
					if(0<=row+dx[i]&&row+dx[i]<a&&0<=col+dy[i]&&col+dy[i]<a&&!v[row+dx[i]][col+dy[i]]&&color==to[row+dx[i]][col+dy[i]]){
						v[row+dx[i]][col+dy[i]]=1;
						Q.push(make_pair(row+dx[i],col+dy[i]));
					}
				}
			}
			for(int i=0;i<a;i++)for(int j=0;j<a;j++)if(v[i][j])to[i][j]=!to[i][j];
		}
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)mat[i][j]=to[i][j];
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if(j)printf(" ");printf("%d",mat[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1044
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for (int i = 1; i <= 100; i++) {
            if (a * i % b == c) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll x; cin >> x;

    ll ans = 0;

    ans += x / 500 * 1000;

    x %= 500;

    ans += x / 5 * 5;

    cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const nmd = input[0].split(' ').map(function(value) { return parseInt(value, 10); });
    const n = nmd[0];
    const m = nmd[1];
    const d = nmd[2];

    let ans = 0;
    if (d === 0) {
        ans = (n * (m - 1)) / Math.pow(n, 2);
    } else {
        ans = (2 * (n - d) * (m - 1)) / Math.pow(n, 2);
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 21192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 3e2+5;
void solve(){
    int x;
    cin>>x;
    if(x>=400 and x<=599)cout<<"8"<<endl;
    if(x>=600 and x<=799)cout<<"7"<<endl;
    if(x>=800 and x<=999)cout<<"6"<<endl;
    if(x>=1000 and x<=1199)cout<<"5"<<endl;
    if(x>=1200 and x<=1399)cout<<"4"<<endl;
    if(x>=1400 and x<=1599)cout<<"3"<<endl;
    if(x>=1600 and x<=1799)cout<<"2"<<endl;
    if(x>=1800 and x<=1999)cout<<"1"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


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

#define int long long

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

signed main()
{
    int h, w;
    cin >> h >> w;
    int cnt = 0;
    for(int i=0; i<h; ++i) {
        string s;
        cin >> s;
        for(int i=0; i<s.size(); ++i)
            if(s[i]=='#') cnt++;
    }
    if(cnt==w+h-1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979;

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> r(n, vector<int>(0));
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    r.at(a-1).push_back(b);
    r.at(b-1).push_back(a);
  }
  
  vector<int> ans(n);
  ans.at(0) = 1;
  queue<int> bfs;
  bfs.push(1);
  int a;
  while((int)bfs.size() > 0){
    int now = bfs.front();
    bfs.pop();
    a = now;
    for(auto k : r.at(now-1)){
      if(ans.at(k-1) != 0) continue;
      bfs.push(k);
      ans.at(k-1) = a;
    }
  }
  
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 10192
#include <iostream>
#include <string>
using namespace std;
int main(){
    int count=0;
    string S,N;
    cin>>S>>N;
    for(unsigned int a=0;a<S.size();a++)
    {  if(S[a]!=N[a])
            count++;}
    cout<<count;
    return 0;
}

Measured memory_bytes: 3436
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, A, B):
    M = [[abs(a-b) for a, b in zip(ar, br)] for ar, br in zip(A, B)]
    S = W*H*80
    dp = [[0 for _ in range(W)] for __ in range(H)]
    dp[0][0] = 1 << (S-M[0][0]) | 1 << (S+M[0][0])
    for i in range(H):
        for j in range(W):
            for k, l in [(-1, 0), (0, -1)]:
                D = M[i][j]
                dp[i][j] |= dp[i+k][j+l] << D
                dp[i][j] |= dp[i+k][j+l] >> D

    ans = None
    cand = dp[H-1][W-1]
    for i in range(H*W*80):
        if cand & (1 << (S+i)) != 0:
            ans = i
            break
    assert ans is not None
    return ans


def main():
    H, W = read_int_n()
    A = [read_int_n() for _ in range(H)]
    B = [read_int_n() for _ in range(H)]
    print(slv(H, W, A, B))

    # H = 80
    # W = 80

    # # A = [[random.randint(0, 1000) for __ in range(W)] for _ in range(H)]
    # # B = [[random.randint(0, 1000) for __ in range(W)] for _ in range(H)]
    # A = [[0 for __ in range(W)] for _ in range(H)]
    # B = [[random.randint(0, 80) for __ in range(W)] for _ in range(H)]
    # print(slv(H, W, A, B))


if __name__ == '__main__':
    main()


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

int pnjg, pnjgout, indexa=2000000, indexz=-1;
string input, A="A", Z="Z";

int main (){
    cin>>input;
    pnjg = input.length ();
    for (int i=0; i<=pnjg; i++){
        if (input [i]==A[0] && i<indexa){
            indexa=i;
        }
        if (input [i]==Z[0] && i>indexz){
            indexz=i;
        }
    }
    cout<<indexz-indexa+1<<endl;
}

Measured memory_bytes: 3744
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<map>
using namespace std;
int  main(){
	int n,i,k;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		if((int)pow(k,i)>n)
		break;
	}
	printf("%d\n",i);
	
	
}









Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
struct edge {
  int to;
  int cost;
  edge(int t, int c): to(t), cost(c) {};
};
using P = pair<int, int>;
int N;
vector<vector<edge>> G;
vector<ll> d;
void dijkstra(int N, int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  d = vector<ll>(N, longinf);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i=0; i<G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main(){
  int n, m;
  ll s;
  cin >> n >> m >> s;
  int N = 2501*n;
  G = vector<vector<edge>>(N);
  rep(i, m) {
    int u, v, a;
    ll b;
    cin >> u >> v >> a >> b;
    --u, --v;
    rep(i, 2501) if(i>=a) {
      G[2501*u+i].push_back(edge(2501*v+i-a, b));
      G[2501*v+i].push_back(edge(2501*u+i-a, b));
    }
  }
  rep(i, n) {
    ll c, d;
    cin >> c >> d;
    rep(j, 2501) {
      if(j+c<2501) G[2501*i+j].push_back(edge(2501*i+j+c, d));
    }
  }
  dijkstra(N, min(2500LL, s));
  rep(i, n) if(i) {
    ll ans = longinf;
    rep(j, 2501) ans = min(d[2501*i+j], ans);
    cout << ans << endl;
  }
  return 0;
}


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

res = []

for i, a in enumerate(A):
    res += [str(i+1)]*a

for i in range(H):
    if i%2 == 0:
        print(" ".join(res[i*W:(i+1)*W]))
    else:
        print(" ".join(reversed(res[i*W:(i+1)*W])))

Measured memory_bytes: 9532
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
int main(){
	int a=read(),b=read(),c=read(),d=read(),k=read();
	cout<<c*60+d-a*60-b-k<<"\n";
	return 0;
}




Measured memory_bytes: 3620
N, M = map(int, input().split())
mod = 7 + 10**9
if abs(N-M) > 1:
    print(0)
else:
    S = min(N, M)
    F = 1
    for i in range(1, S+1):
        F *= i
        F %= mod
    ans = (2 * F * F if N == M else F * F * (S + 1))
    ans %= mod
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9	
#define MOD 1000000007
typedef pair<int, int> PII;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> VI;
typedef vector<VI> VVI;
const int mod = 1000000007;
void printV(VVI dp) {
	for(VI k: dp) {
		for(int i: k) cout << i << " ";
			cout << endl;
	}
	cout << endl;
}
void solve() {
	int n, m;
	cin >> n >> m;
	std::vector<std::vector<char>> adj(n,std::vector<char>(m,0));

	VVI dp(n+1,VI(m+1,0));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin >> adj[i][j];
		}
	}
	if(adj[n-1][m-1] == '#') {
		cout << 0;
		return;
	}
	for (int i = n-1; i >= 0; --i)
	{
		for (int j = m-1; j >= 0; --j)
		{
			if(adj[i][j] == '#') continue;
			if(i == n-1 && j == m-1) {
				dp[i][j] = 1;
				continue;
			}
			int64 left = j < m ? dp[i][j+1]%mod:0;
			int64 down = i < n? dp[i+1][j]%mod:0;

			int64 ans = (left+down)%mod;
			dp[i][j] = ans;
		}
	}
	// printV(dp);
	cout << dp[0][0];
}

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

	return 0;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

bool dp[81][81][12801];

void solve() {
  int h, w;
  cin >> h >> w;
  vector<vi32> a(h, vi32(w));
  vector<vi32> b(h, vi32(w));
  cin >> a >> b;
  
  vector<vi32> c(h, vi32(w));
  rep(i, h) rep(j, w) c[i][j] = abs(a[i][j] - b[i][j]);

  dp[0][0][c[0][0]] = true;
  rep(i, h) rep(j, w) repc(k, 12800) {
    if (!dp[i][j][k]) continue;
    if (i < h - 1) {
      dp[i+1][j][abs(k + c[i+1][j])] = true;
      dp[i+1][j][abs(k - c[i+1][j])] = true;
    }
    if (j < w - 1) {
      dp[i][j+1][abs(k + c[i][j+1])] = true;
      dp[i][j+1][abs(k - c[i][j+1])] = true;
    }
  }
  repc(k, 12800) if(dp[h-1][w-1][k]) {
    cout << k << endl;
    return;
  }
}


Measured memory_bytes: 81408
#include <cstdio>
#include <algorithm>
#include <functional>

#define N 1000

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ];
    int res = 0;
    int n, m;

    scanf ( "%d%d", &n, &m );
    if ( !( n | m ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }
    sort ( d, d + n, greater< int > ( ) );

    for ( i = 0; i < n; ++i )
    {
      res += ( i + 1 ) % m
           ? d[ i ] : 0;
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

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

int main(){
  ll n,k; cin >> n >> k;
  //hyaku = pow(10,100); //多分これはだめ

  ll sum = 0;

  for(ll i = k; i <= n+1; i++){
  ll  minsum = ((0+(i - 1)) * i) / 2;
  ll  maxsum = ((n - i + 1) + n) * i / 2;
  //cout << maxsum - minsum + 1<< endl;
    sum += maxsum - minsum+1;
  }

  sum = sum % (1000000007);

  cout << sum << endl;
}



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

int N, M;
vector<int> graph[10];
bool reached[10];
void search(int position);
int route = 0;

int main(){
    cin >> N >> M;
    for (int i = 1; i <= M; i++){
        int x, y;
        //無向グラフ
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for (int i = 1; i <= N; i++){
        reached[i] = false;
    }
    reached[1] = true;
    search(1);
    cout << route << endl;
}
void search(int position){
    bool all_reached = true;
    for (int i = 1; i <= N; i++){
        if (reached[i] == false){
            all_reached = false;
        }
    }
    if (all_reached){
        route++;
        return;
    }

    for (int i = 0; i < graph[position].size(); i++){
        int nextposition = graph[position][i];
        if (reached[nextposition] == false){
            reached[nextposition] = true;
            search(nextposition);
            reached[nextposition] = false;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vll a(n), b(n);
    REP(i, n)
        cin >> a[i];
    int c = n/2;
    REP(i, n) {
        if (i%2 == 1 && n%2 == 1 || i%2 == 0 && n%2 == 0)
            b[c+(i+1)/2] = a[i];
        if (i%2 == 0 && n%2 == 1 || i%2 == 1 && n%2 == 0)
            b[c-(i+1)/2] = a[i]; 
    }
    REP(i, n)
        cout << b[i] << " ";
    cout << endl;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define error(x) cout << #x << " = " << x << endl


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,m,i,j,k,sum=0;
    cin>>n>>m;
    if(n>9||m>9){
        cout<<-1;
    }
    else{
        cout<<n*m;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};


int main(){
    char c;
    cin>>c;
    if(c>='a' and c<='z'){
        cout<<'a'<<endl;
    }
    else {
        cout<<"A"<<endl;
    }
    return 0;
}







Measured memory_bytes: 3580
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

int fact[1000100];

bool is_odd_C(int n, int k) {
  return fact[n] == fact[k] + fact[n - k];
}

bool solve() {
  int n;
  if (scanf("%d", &n) != 1) { return false; }

  fact[0] = 0;
  for (int i = 1; i <= n; ++i) {
    fact[i] = fact[i - 1] + __builtin_ctz(i);
  }

  static char s[1000100];
  scanf("%s", s);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = s[i] - '0';
  }
  for (int i = 0; i < n - 1; ++i) {
    a[i] = abs(a[i] - a[i + 1]);
  }
  a.pop_back();

  int cnt[3] = {};
  for (int i = 0; i < int(a.size()); ++i) {
    cnt[a[i]]++;
  }
  int odd = 0;
  for (int i = 0; i < int(a.size()); ++i) {
    if (a[i] == 1 && is_odd_C(a.size() - 1, i)) {
      odd ^= 1;
    }
  }
  if (odd) {
    printf("1\n");
    return true;
  }
  if (cnt[1] != 0) {
    printf("0\n");
    return true;
  }
  // 0 or 2?
  int two = 0;
  for (int i = 0; i < int(a.size()); ++i) {
    if (a[i] == 2 && is_odd_C(a.size() - 1, i)) {
      two ^= 2;
    }
  }
  printf("%d\n", two);
  return true;
}

int main() {
  int tt = -1;
  //scanf("%d", &tt);
  while (tt-- && solve());
  return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
using namespace std;

struct UnionFind {

  vector<int> id;
  vector<int> Size;

  UnionFind(int n) {
    id.resize(n); Size.resize(n, 1);
    for (int i = 0; i < n; i++) id[i] = i;
  }

  int find(int u) {
    return (id[u] == u) ? u : id[u] = find(id[u]);
  }

  bool uni(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    id[v] = u;
    Size[u] += Size[v];
    return true;
  }

  int size(int u) {
    u = find(u);
    return Size[u];
  }
};

int n, m;

signed main() {
    fastio;
    cin >> n >> m;
    UnionFind dsu(n);
    int res = 1;
    rep (i, m) {
        int ai, bi;
        cin >> ai >> bi;
        ai--, bi--;
        dsu.uni(ai, bi);
        res = max(res, dsu.size(ai));
    }
    cout << res << endl;
}

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

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n-1);
    for(int i=0; i<n-1; i++){
        cin >> a.at(i);
    }
    vector<int> sum(n);
    for(int i=0; i<n-1; i++){
        sum.at(a.at(i)-1)++;
    }
    for (int i=0; i<n; i++){
        cout << sum.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 5580