akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

int caterpillar(const vector<int>& a, int S) {
   int N = a.size();
   int l = 0, r = 0, s = 0;
   int ans = 0;
   while (l < N) {
      while (r < N && s <= S) {
         s += a[r++];
      }
      ans += r - l + (s <= S ? 0 : -1);
      s -= a[l++];
   }
   return ans;
}

signed main()
{
   int N, Q; cin >> N >> Q;
   V<int> a(N), x(Q);
   REP(i, N) {
      cin >> a[i];
   }
   REP(i, Q) {
      cin >> x[i];
   }
   REP(i, Q) {
      cout << caterpillar(a, x[i]) << endl;
   }
   return 0;
}



Measured memory_bytes: 3560
package main

import (
    "fmt"
    "bufio"
    "os"
)

//FOR I/O : STARTS
var Reader *bufio.Reader = bufio.NewReader(os.Stdin)
var Writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func Printf (f string, a ...interface{}) { fmt.Fprintf(Writer, f, a...) }
func Scanf (f string, a ...interface{}) { fmt.Fscanf(Reader, f, a...) }
func Println (a ...interface{}) { fmt.Fprintln(Writer, a...)}
func Scanln (a ...interface{}) { fmt.Fscanln(Reader, a...)}
//I/O ENDS HERE

func Abs(x int) int {
    if x < 0 {
        return -x
    }
    return x
}

func Min(x, y int) int {
    if x < y {
        return x
    } else {
        return y
    }
}

func Max(x, y int) int {
    if x >= y {
        return x
    } else {
        return y
    }
}

func Ceil(x, y int64) int64 {
    //returns x/y
    if x%y == 0 {
        return x/y
    } else {
        return int64(x/y)+1
    }
}

func main() {
    defer Writer.Flush()

    var x int64
    Scanf("%d\n", &x)

    y := int64(100)
    cnt := 0

    for y < x {
        temp := float64(y)
        temp *= 1.01
        cnt += 1
        y = int64(temp)
    }

    Println(cnt)
}


Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
  lli A,B,C,D=0,E=0,F=INF,N,M;
    cin >> N;
    string S;
    cin >> S;
    rep(i,0,N){
      if(S[i]=='I')D++;
      else D--;
      E=max(D,E);
    }
    Out(E);
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, A, B = LI()
    X = LI()

    ans = 0
    for i in range(N - 1):
        d =X[i+1] - X[i]
        ans += min(A * d, B)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21424
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

/*

 */

int const MaxSize = 2e5 + 5;
LL N, A[MaxSize];

LL cost(LL b) {
	LL c = 0;
	LP(i,0, N)
	{
		c += abs(A[i] - b);
	}

	return c;
}

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);
	cin >> N;

	LL sum = 0;
	LP(i, 0, N)
	{
		cin >> A[i];
		A[i] -= (i + 1);
		sum += A[i];
	}

	sort(A, A + N);

	if (N % 2) {
		cout << cost(A[N / 2]) << endl;
	} else {
		LL avg = (A[N / 2] + A[N / 2 - 1]) / (LL) 2;
//	cout << sum << " " << avg << " " << cost(avg) << " " << cost(avg + 1) << endl;

		LL ans = min(cost(avg), cost(avg + (LL) 1));
		ans = min(ans, cost(avg - (LL) 1));

		cout << ans;
	}

	return 0;
}


Measured memory_bytes: 1792
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
k=int(input())
ans=0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans+=gcd(a,b,c)
      
print(ans)

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> map(h, vector<int>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> map[i][j];
        }
    }

    // 添字を覚えておくための配列
    vector<string> index_map(h * w);
    int index = 0;

    vector<int> map2 = {};
    rep(i, h) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; j++) {
                map2.push_back(map[i][j]);

                index_map[index] = to_string(i + 1) + " " + to_string(j + 1);
                index++;
            }
        } else {
            for (int j = w - 1; j >= 0; j--) {
                map2.push_back(map[i][j]);
                index_map[index] = to_string(i + 1) + " " + to_string(j + 1);
                index++;
            }
        }
    }

    vector<string> res = {};
    int res_cnt = 0;
    rep(i, h * w - 1) {
        if (map2[i] % 2 == 1) {
            res_cnt++;
            map2[i]--;
            map2[i + 1]++;

            res.push_back(index_map[i] + " " + index_map[i + 1]);
        }
    }

    cout << res_cnt << endl;
    rep(i, res.size()) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 17276
#include <stdio.h>

int main(){
    int n, m=0, t=0;
    scanf("%d", &n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i]==i+1){
            t = a[i];
            a[i+1] = a[i];
            a[i] = t;
            m++;
        }
    }
    printf("%d", m);
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	d := getNextInt(scanner)
	n := 26
	cc := make([]int, n)
	ll := make([]int, n)
	for i := 0; i < n; i++ {
		cc[i] = getNextInt(scanner)
		ll[i] = -1
	}
	ss := makeGrid(d, n)
	for i := 0; i < d; i++ {
		for j := 0; j < n; j++ {
			ss[i][j] = getNextInt(scanner)
		}
	}
	tt := make([]int, d)
	for i := 0; i < d; i++ {
		tt[i] = getNextInt(scanner) - 1
	}
	scores := getScore(cc, ll, tt, ss)
	for i := 0; i < d; i++ {
		fmt.Fprintln(writer, scores[i])
	}
}
func getScore(cc, ll, tt []int, ss [][]int) []int {
	var score int
	d := len(tt)
	n := 26
	scores := make([]int, d)
	for i := 0; i < d; i++ {
		t := tt[i]
		score += ss[i][t]
		ll[t] = i
		for j := 0; j < n; j++ {
			score -= cc[j] * (i - ll[j])
		}

		scores[i] = score
	}
	return scores
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 2048
#!/usr/bin/env python3
# GRL_5_D: Tree - Range Query on Tree
# Eular Tour Technique
# DFSの結果でサブツリーの範囲がわかるので、range add queryを利用して
# add/getを行う


class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


class RAQ:
    """Segment Tree
    """
    def __init__(self, n, initial=0):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [initial] * self.size

    def add(self, i, j, v):
        def _add(r, lo, hi):
            if hi < i or lo > j:
                return
            elif i <= lo and hi <= j:
                self.data[r] += v
            else:
                mid = lo + (hi - lo)//2
                _add(r*2 + 1, lo, mid)
                _add(r*2 + 2, mid+1, hi)

        return _add(0, 0, self.size//2)

    def get(self, i):
        def _get(r, lo, hi, v):
            v += self.data[r]
            if lo == hi:
                return v
            mid = lo + (hi - lo)//2
            if mid >= i:
                return _get(r*2 + 1, lo, mid, v)
            else:
                return _get(r*2 + 2, mid+1, hi, v)

        return _get(0, 0, self.size//2, 0)


class PathSum:
    def __init__(self, graph, root):
        self.seg = RAQ(graph.v)
        self._in = [0] * graph.v
        self._out = [0] * graph.v
        self.dfs(graph, root)

    def dfs(self, graph, root):
        visited = [False] * graph.v
        stack = [root]
        i = 0
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                self._in[v] = i
                i += 1
                stack.append(v)
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        stack.append(w)
            else:
                self._out[v] = i - 1

    def add(self, v, val):
        i = self._in[v]
        j = self._out[v]
        self.seg.add(i, j, val)

    def get(self, v):
        return self.seg.get(self._in[v])


def run():
    n = int(input())
    g = Graph(n)

    for i in range(n):
        k, *cs = [int(i) for i in input().split()]
        if k > 0:
            for j in cs:
                g.add(Edge(i, j))

    raq = PathSum(g, 0)
    q = int(input())
    for _ in range(q):
        com, *args = [int(i) for i in input().split()]
        if com == 0:
            u, val = args
            raq.add(u, val)
        elif com == 1:
            u, = args
            print(raq.get(u))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 40128
#include <iostream>
using namespace std;
int main()
{
    int D;
    cin>>D;
    if(D==22)
        cout<<"Christmas Eve Eve Eve"<<endl;
    else if(D==23)
        cout<<"Christmas Eve Eve"<<endl;
    else if(D==24)
        cout<<"Christmas Eve"<<endl;
    else
        cout<<"Christmas"<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
balls=[1 for i in range(n)]
pro=[False for i in range(n)]
pro[0]=True

for inp in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    balls[a]-=1
    balls[b]+=1
    if pro[a]:
        pro[b]=True
    if balls[a]==0:
        pro[a]=False


#print(pro)
print(pro.count(True))

Measured memory_bytes: 4760
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,k,x,y,sum=0;
    cin>>n>>k>>x>>y;
    if(k>=n){
        cout<<(n*x)<<endl;
        return 0;
    }
    else{
        sum=(k*x)+((n-k)*y);
    cout<<sum<<endl;
    return 0;
    }
}

Measured memory_bytes: 3608
io = STDIN
n=io.gets.to_i
$dist={}
$ans=Array.new(n+1)
$tree=Hash.new{|h,k|h[k]=[]}
(n-1).times.each do 
  u,v,w=io.gets.split.map(&:to_i)
  $dist[[u,v]]=w.even? ? 0 : 1
  $dist[[v,u]]=w.even? ? 0 : 1
  $tree[u]<<v
  $tree[v]<<u
end
$queue=[]
def bfs(root)
  $queue<<root
  $ans[root]=0
  while node=$queue.shift
    $tree[node].each do |leaf|
      next if $ans[leaf]
      $ans[leaf]=$ans[node]^$dist[[node,leaf]]
      $queue << leaf
    end
  end
end
bfs($tree.keys.first)
puts $ans[1..-1]


Measured memory_bytes: 47468
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

    int n, p; cin>>n>>p;
    string s; cin>>s;

    ll ans = 0;
    if(p == 2 || p == 5){
        for(int i=0; i<n; i++){
            if((s[i] - '0') % p == 0) ans += (i + 1);
        }
    }
    else{
        reverse(s.begin(), s.end());
        ll base = 1, cur = 0;
        vector<ll> mod(n);
        for(int i=0; i<n; i++){
            mod[i] = ((s[i] - '0') * base + cur) % p;
            cur = mod[i];
            base *= 10;
            base %= p;
        }

        vector<ll> cnt(p, 0);
        cnt[0]++;
        for(int i=0; i<n; i++){
            cnt[mod[i]]++;
        }

        for(int i=0; i<p; i++){
            ans += cnt[i] * (cnt[i] - 1) / 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


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

    int ans = 0;
    rep(i,s.length()) {
        int tmp = 0;
        for(int j = i; j < s.length() - 0; j++) {
            if (s[j] == 'A' || s[j] == 'C' 
             || s[j] == 'G' || s[j] == 'T') {
                tmp++;
                if (s[j+1] != 'A' && s[j+1] != 'C' 
                 && s[j+1] != 'G' && s[j+1] != 'T'){
                    break;
                }
            }
        }
        ans = max(ans, tmp);
    }

    cout << ans;
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8').strip()
    change = 0
    L = len(S)
    for i in range(1,L):
        if S[i-1]!=S[i]:
            change += 1
    print(change)

if __name__ == '__main__':
    main()

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

int main() {
    int n, K;
    scanf("%d%d", &n, &K);
    long long tot = 0;
    for (int b = 1; b <= n; b++) {
        if (b - 1 < K) {
            continue;
        }
        tot += (long long)(n / b) * (b - K);
        int max_K = n - (n / b) * b;
        if (max_K >= K) {
            tot += max_K - K + 1;
        }
    }
    if (K == 0) {
        tot -= n;
    }
    printf("%lld\n", tot);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
 
class ModInt{
private:
  long long val;
  static const int default_mod = 1e9 + 7;
  static int mod;
  static vector<ModInt> facts;
public:
  ModInt(long long val)
  {
    if(mod == 0){
      mod = default_mod;
    }
    this->val = ((val % mod) + mod) % mod;
  }
  ModInt()
    : ModInt(0)
  {
  }
  static void setMod(int mod){
    if(ModInt::mod != 0){
      throw "The modulo is already set.";
    }
    ModInt::mod = mod;
  }

  const ModInt operator* (const ModInt& another) const{
    return ModInt(val * another.val);
  }
  ModInt operator+ (const ModInt& another){
    return ModInt(val + another.val);
  }
  ModInt operator- (const ModInt & another){
    return ModInt(val - another.val + mod);
  }
  ModInt operator/(const ModInt& rhs){
    return (*this) * rhs.inv();
  }
  ModInt& operator*=(const ModInt& rhs){
    (*this) = (*this) * rhs;
    return *this;
  }
  ModInt& operator+=(const ModInt& rhs){
    (*this) = (*this) + rhs;
    return *this;
  }
  ModInt& operator-=(const ModInt& rhs){
    (*this) = (*this) - rhs;
    return *this;
  }
  ModInt pow(long long exponent) const{
    exponent %= mod;
    if(exponent == 0){
      return ModInt(1);
    }else{
      if(exponent % 2){
        return ((*this) * (*this)).pow(exponent / 2) * (*this);
      }else{
        return ((*this) * (*this)).pow(exponent / 2);
      }
    }
  }
  ModInt inv() const{
    return this->pow(mod - 2);
  }
  static ModInt fact(long long n){
    if(n >= mod){
      return 0;
    }
    if(facts.size() < static_cast<size_t>(n + 1)){
      if(facts.size() == 0){
        facts.push_back(1);
      }
      for(int i = facts.size(); i <= n; i++){
        facts.push_back(facts[i - 1] * i);
      }
    }
    return facts[n];
  }
  static ModInt comb(long long n, long long r){
    if(r > n){
      return 0;
    }
    return ModInt::fact(n) * ModInt::fact(r).inv() * ModInt::fact(n - r).inv();
  }
 
  friend ostream& operator<< (ostream& os, const ModInt& modint){
    os << modint.val;
    return os;
  }
  friend istream& operator>>(istream& is, ModInt& modint){
    long long val;
    is >> val;
    modint.val = val % modint.mod;
    return is;
  }
};
int ModInt::mod = 0;
vector<ModInt> ModInt::facts;
const ModInt operator* (const long long lhs, const ModInt& rhs){
  return ModInt(lhs) * rhs;
}

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

  vector<ModInt> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }

  ModInt prob = ModInt::fact(N - 1);
  ModInt ans;
  for(int i = 1; i < N; i++){
    ans += prob * (x[i] - x[i - 1]);
    prob += ModInt::fact(N - 1) / (i + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define print(x) cout<<x<<"\n"

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}


void Main()
{
	ll n;
	ll resa=0,resb=0;
	cin>>n;

	for(ll a=-200;a<200;a++){
		for(ll b=-200;b<200;b++){
			if(pow(a,5)-pow(b,5)==n) {
				resa=a;
				resb=b;
			}
		}
	}


	cout << resa<<" "<<resb << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for (int i=0; i<n-2; i++){
    if (s[i]!='A') continue;
    if (s[i+1]!='B') continue;
    if (s[i+2]!='C') continue;
    ans +=1;
  }
cout<<ans;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s[0] == 'W' || s[2*n-1] == 'W')
    {
        cout << 0 << endl;
        return 0;
    }
    vector<int> lr(2*n); // -1 : L, 1 : R
    lr[0] = -1;
    int lcount = 1;
    ll ans = 1;
    for(int i = 1; i < s.size(); i++)
    {
        if(s[i] == s[i-1]) lr[i] = -1 * lr[i-1];
        else lr[i] = lr[i-1];

        if(lr[i] == -1) 
        {
            lcount++;
        }
        else
        {
            ans = ans * lcount % MOD;
            lcount--;
        }
    }
    if(lcount != 0)
    {
      cout << 0 << endl;
      return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        ans = ans * i % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1412
fun main(args: Array<String>) {
    a54(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a54(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    print(if (args[0].toInt() < 1200) "ABC" else "ARC")
}


Measured memory_bytes: 33568
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>

using namespace std;
typedef long long int ll;


int main(int argc, char const *argv[])
{
	ll n, l;
	cin >> n >> l;

	ll ans = LLONG_MAX;
	ll min = LLONG_MAX;
	ll sum = 0;
	for (ll i = 1; i <= n; i++)
	{
		sum += l + i - 1;
		if(min > abs(l+i-1)){
			min = abs(l + i - 1);
			ans = l + i - 1;
		}
	}

	cout << sum - ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll A[100005];
ll dp[100005];

int main(){

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

cin>>N;
rep(i,N+1) cin>>A[i];
if(N==0){
	if(A[0]!=1){
		cout<<-1<<endl;
		return 0;
	}
}
dp[0]=1-A[0];
if(N){
	if(dp[0]<=0){
		cout<<-1<<endl;
		return 0;
	}
}
rep1(i,N+1){
	if(dp[i-1]>1e18) dp[i]=INF;
	else dp[i]=2*(dp[i-1]-A[i-1]);
	if(i<N){
		if(dp[i]<=A[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(i==N){
		if(dp[i]<A[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
}
ll ans=A[N];
ll son=A[N];
for(ll i=N; i>=1; i--){
	ll parent=dp[i-1]-A[i-1];
	if(son>2*parent){
		cout<<-1<<endl;
		return 0;
	}
	else if(son<parent){
		son=son+A[i-1];
	}
	else{
		son=parent+A[i-1];
	}
	ans+=son;
}
cout<<ans<<endl;


}
    


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << min(a,b)+min(c,d) <<endl; 
    return 0;
}

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

int main() {
  long long N,M;
  cin >> N;
  cin >> M;
  long long a[N],b[N];
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    cin >> b[i];
  }

  vector<pair<long long,long long>> AB(N);
  for(int i = 0; i < N; ++i){
    AB[i] = make_pair(a[i],b[i]);
  }
  sort(AB.begin(),AB.end());

  long long count = 0;
  int i = 0;

  for(int i=0;i<N;i++){
    int buy = min(M,AB[i].second);
    count += buy*AB[i].first;
    M -= buy;
  }

  cout << count << endl;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v[i] = x - (i + 1);
    }
    sort(v.begin(), v.end());
    ll med = 0;
    if (n % 2 == 0)
        med = (v[n / 2] + v[n / 2 - 1]) / 2;
    else
        med = v[n / 2];
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(v[i] - med);
    }
    cout << ans << "\n";
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;
//using mint=ModInt<998244353>;
int N;
mint dp[222222];

mint sum[222222];
signed main(){
	cin>>N;
	vint C;
	rep(i,N){
		int c;cin>>c;
		if(C.size()==0||C.back()!=c)C.pb(c);
	}

	dp[0]=1;
	for(int i=0;i<C.size();i++){
		sum[C[i]]+=dp[i];
		dp[i+1]=sum[C[i]];
	}


	cout<<dp[C.size()]<<endl;
	return 0;
}

Measured memory_bytes: 5236
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <functional>
using namespace std;

int N, A[100009];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	cout << A[N - 1] - A[0] << endl;
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int seki = a*b;
  if(seki%2==0){
  	cout << "Even" << endl;
  }else{
  	cout << "Odd" << endl;  	
  }
}

Measured memory_bytes: 3568
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  /*for(o=1;o<=n;o++)
    {
      if(o == n){printf("%d\n",A[o]);}
      else printf("%d ",A[o]);
    }
  */
  for(j=1;j<=n;j++)
    {   
	      key = A[j];		
	      i = j-1;
	      while(i>0 && A[i]>key)
		{
		  A[i+1]=A[i];  
		  i = i-1;
		}
	      A[i+1] = key;
	      for(k=1;k<=n;k++){
		if(k == n)printf("%d\n",A[k]);
		else printf("%d ",A[k]);
	      }
    }
  
  return 0;
}



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

int main() {
  int a;
  cin >> a;
  if ((a / 10) % 111 == 0 || (a % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    int n,d,cnt = 0;
    cin >> n >> d;
    int x[n][d];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < d;j++){
            cin >> x[i][j];
        }
    }
    for(int i = 0;i < n;i++){
        //int tmp = 0;
        for(int j = i+1;j < n;j++){
            int tmp = 0;
            for(int k = 0;k < d;k++){
                tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(int z = 0;z <= 300;z++){
                if(z*z == tmp) cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps=1e-10;
double adj[21][21];
double hero[20];
bool visited[20]={false};
#define MAOU 20

bool backTrack(int last,double r,int now,int n,
	   bool *visited){
  rep(i,n){
    if ( visited[i]==false && adj[MAOU][i]<=r)return false;
    if ( visited[i]==false &&  adj[MAOU][i]<=r+adj[last][i])return false;
  }
  if ( now == n)return true;
  
  rep(i,n){
    if ( visited[i]==true)continue;
    visited[i]=true;
    if ( backTrack(i,r+adj[last][i],now+1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

double dist(int x,int y){
  //return (x*x+y*y);
  return sqrt(x*x+y*y);
}

int solve(int n,int *x,int *y,int rx,int ry,int mx,int my){
  rep(i,n){
    adj[i][i]=0;
    adj[MAOU][i]=adj[i][MAOU]=dist(x[i]-rx,y[i]-ry);
    REP(j,i+1,n){
      adj[i][j]=adj[j][i]=dist(x[i]-x[j],y[i]-y[j]);
    }
    hero[i]=dist(mx-x[i],my-y[i]);
    if ( hero[i]>=adj[MAOU][i])return false;
    visited[i]=false;
  }
  
  rep(i,n){
    visited[i]=true;
    if ( backTrack(i,hero[i],1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

main(){
  int n,mx,my,rx,ry;
  while(scanf("%d%d%d%d%d",&n,&mx,&my,&rx,&ry) && n){
    int x[n],y[n];
    rep(i,n)scanf("%d%d",&x[i],&y[i]);
    if ( solve(n,x,y,rx,ry,mx,my))puts("YES");
    else puts("NO");
  }
}

Measured memory_bytes: 848
n=gets.chomp.to_i
w=gets.chomp.split().map(&:to_i)
s=w.inject(0,&:+)
s1=0;s2=s
d=s
(0..(n-1)).each{|k|
  s1+=w[k]
  s2-=w[k]
  temp_d = (s1-s2).abs
  s = temp_d if temp_d < s
}
puts s



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

bool check(vector<int> v,int n){
	for (int i = 1; i < n; i++){
		if (v[i] - v[i - 1] != v[i + 1] - v[i]){
			return false;
		}
	}
	return true;
}

int main(){
	int N;
	while (cin >> N){
		if (N == 0){
			break;
		}
		vector<int> h;
		for (int i = 0; i < N + 1; i++){
			int x;
			cin >> x;
			h.push_back(x);
		}
		for (int i = 0; i < N + 1; i++){
			vector<int> t = h;
			t.erase(t.begin() + i);
			if (check(t, N - 1)){
				cout << h[i] << endl;
				break;
			}
		}
		
	}
}


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

int main() {
    string O, E;
    cin >> O >> E;
    for (int i = 0; i < E.length(); i++) cout << O[i] << E[i];
    if (O.length() != E.length()) cout << O[O.length() - 1];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
#define MOD LLONG_MAX

using namespace std;
using ll = unsigned long long;
using P = pair<int, int>;

ll binary_square(ll x, ll n);

int main()
{
    int n;
    vector<ll> a, ok;
    ll limit = binary_square(10, 14);
    cin >> n;
    rep(i, n + 1)
    {
        ll x;
        cin >> x;
        a.push_back(x);
        // sum+=x;
    }

    if(n==0){
        int ans;
        if(a[0]==1){
            ans = 1;
        }else{
            ans = -1;
        }
        cout << ans << endl;
        return 0;
    }

    if (n < 47)
    {
        ll oknum = 1ULL;
        ok.push_back(1);
        // bool flag = true;
        rep(i, n)
        {
            if (oknum <= a[i])
            {
                cout << -1 << endl;
                return 0;
            }
            oknum -= a[i];
            // flag = false;
            oknum <<= 1;
            ok.push_back(oknum);
        }
        ok.pop_back();
    }
    else
    {
        ll oknum = 1ULL;
        ok.push_back(1);
        // bool flag = true;
        rep(i, n)
        {
            
            if (oknum <= a[i])
            {
                cout << -1 << endl;
                return 0;
            }
            oknum -= a[i];
            // flag = false;
            oknum <<= 1;
            ok.push_back(oknum);
        }

        //bool flag = true;
        // rep2(i, 51, n){

        //     ok.push_back(limit);
        // }
        ok.pop_back();
    }

    ll ans = a[n], nowp = a[n];
    for (int i = n - 1; i >= 0; i--)
    {
        ll tmp = min(nowp + a[i], ok[i]);
        if (nowp % 2 == 0)
        {
            if (tmp < nowp / 2)
            {
                cout << -1 << endl;
                return 0;
            }
        }
        else
        {
            if (tmp < nowp / 2 + 1)
            {
                cout << -1 << endl;
                return 0;
            }
        }
        nowp = tmp;
        //cout << i << " : " << nowp << endl;
        ans += nowp;
    }

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

ll binary_square(ll x, ll n)
{
    ll m = MOD;
    ll ans = 1ULL;
    while (n)
    {
        if (n % 2 == 1)
        {
            ans = ans * x % m;
        }
        x = x * x % m;
        n >>= 1;
    }
    return ans % m;
}


Measured memory_bytes: 5572
a,b,k = map(int,input().split())
ans = []
for i in range(a,a+k):
    if i <= b:
        ans.append(i)
for i in range(b-k+1,b+1):
    if a < i and i not in ans:
        ans.append(i)
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    int N,M,C;
    cin>>N>>M>>C;
    int B[M];
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    int A[M];
    int sum=0;
    int count=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin>>A[j];
            sum+=A[j]*B[j];
        }
        if(sum+C>0){
            count++;
        }
        sum=0;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<cmath>
#include<stdio.h>
#include<string>
int main(void){
    std::string str(100,'a');
    std::string str2(100,'a');
    std::cin>>str>>str2;
    std::cout<<str2<<str<<std::endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
mode = 0
ans_1 = ""
ans_2 = ""
for i in range(Q):
    K = input().split()
    if K[0] == "1":
        if mode == 0:
            mode = 1
        else:
            mode = 0
    else:
        if K[1] == "1":
            if mode == 0:
                ans_1 += K[2]
            else:
                ans_2 += K[2]
        else:
            if mode == 0:
                ans_2 += K[2]
            else:
                ans_1 += K[2]
ans_1 = ans_1[::-1]
K = ans_1+S+ans_2
if mode == 1:
    print(K[::-1])
else:
    print(K)

Measured memory_bytes: 4468
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

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

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    string x; cin >> x;
    string y = x;
    int(d);
    rep(i, n){
      if(d == 0)break;
      if(x[i] == '0'){
        x[i] = '1';
        --d;
      }
    }

    per(i, n){
      if(d == 0)break;
      if(x[i] == y[i]){
        x[i] = '0';
        --d;
      }
    }
    pri(x);


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3280
#include <iostream>
using namespace std;
#include <vector>
#include <climits>
 
int main() {
	// your code goes here
  int n;
  cin>>n;
  vector<int> val(n+1 , 0);
  for(int i=1;i<=n;i++){
    cin>>val[i];
  }
  vector<int> dp(n+1 , 0);
  dp[1]=0;
  dp[2]=abs(val[1]-val[2]);
  
  for(int i=3;i<=n;i++){
    dp[i]=min(dp[i-1]+abs(val[i]-val[i-1]),dp[i-2]+abs(val[i]-val[i-2]));
  }
  cout<<dp[n]<<endl;
  return 0;
	
}


Measured memory_bytes: 3956
import java.util.*;

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

        int n = sc.nextInt();
        int v[] = new int[n];
        int c[] = new int[n];

        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }

        int result = 0;

        for (int i = 0; i < n; i++) {
            if (v[i] > c[i]) {
                result = result + v[i] - c[i];
            }
        }

        System.out.println(result);
	}
}


Measured memory_bytes: 21844
from math import ceil
A = [int(input()) for _ in range(5)]
A = sorted(A, key=lambda x:x%10)
B = list(map(lambda x: 10*ceil(x/10), A))
C = [0]*5
for i in range(5):
  C[i] = B[i] - A[i]
max_c = max(C)
print(sum(B)-max_c)

Measured memory_bytes: 3064
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    vec = [0] * 8
    over_red = 0
    for a in A:
        if a >= 3200:
            over_red += 1
        else:
            vec[a // 400] += 1

    c = 0
    for v in vec:
        if v > 0:
            c += 1
    if c > 0:
        print(c, c + over_red)
    else:
        print(1, over_red)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62008
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cout << k * (int) pow(k - 1, n - 1) << endl;
}

Measured memory_bytes: 256
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b #最大公約数を求める
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  if n == 1: return ans
  for cursor in two_and_odds(max_n):
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
  if n != 1: ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()


Measured memory_bytes: 40044
N,M=map(int,input().split())
ls=[list(map(int,input().split())) for _ in range(M)]
if N==1:
  b=0
  c=10
else:
  b=10**(N-1)
  c=10**N
  
for i in range(b,c):
  a=str(i)
  for j in range(M):
    if a[ls[j][0]-1]==str(ls[j][1]):
      continue
    else:
      break
  else:
    print(i)
    break
else:
  print(-1)  

Measured memory_bytes: 3064
import java.util.Scanner;


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();
		int D = sc.nextInt();
		
		int time = 0;
		
		if(B<C)
		{
			time = 0;
		}
		else if(D<A)
		{
			time = 0;
		}
		else if(A<C&&D<B)
		{
			time = D-C;
		}
		else if(C<A&&B<D)
		{
			time = B-A;
		}
		else if(A<C)
		{
			time=B-C;
		}
		else if(C<A)
		{
			time=D-A;
		}
		else if(C==A)
		{
			time = B<D ?(B-A):(D-C); 
		}

		System.out.println(time);

	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
 
int main(){
 int a,b;cin>>a>>b;
  cout<<a*b  <<endl;
  return 0;
  }

Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int test=in.nextInt();
        ArrayList<Integer> ar=new ArrayList<>();
        for (int i = 0; i < test; i++) {
            int a,b = 0;
            a=in.nextInt();
            if(a!=2){
              b=in.nextInt();  
            }
            if(a==0){
                ar.add(b);
            }
            else if(a==2){
                ar.remove((ar.size()-1));
            }
            else{
                System.out.println(ar.get(b));
            }
        }
    }
}


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

int main(){
  int N;
  cin >> N;
  int customer = 0;
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    customer += (r - l + 1);
  }
  cout << customer << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	double x;

	while(1){
		if(scanf("%lf",&x) == EOF){break;}
		if(48.00 >= x){
			puts("light fly");
		}else if(48.00 < x &&51.00 >= x){
			puts("fly");
		}else if(51.00 < x &&54.00 >= x){
			puts("bantam");
		}else if(54.00 < x &&57.00 >= x){
			puts("feather");
		}else if(57.00 < x &&60.00 >= x){
			puts("light");
		}else if(60.00 < x &&64.00 >= x){
			puts("light welter");
		}else if(64.00 < x &&69.00  >= x){
			puts("welter");
		}else if(69.00 < x &&75.00  >= x){
			puts("light middle");
		}else if(75.00 < x &&81.00  >= x){
			puts("middle");
		}else if(81.00 < x &&91.00  >= x){
			puts("light heavy");
		}else if(91.00 < x){
			puts("heavy");
		}
	}
	return 0;
}

Measured memory_bytes: 0