akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

ll ans = 0;
map<ll, ll> memo;

ll solve(ll h)
{
    ll sum = 1;

    if(h == 1) { 
        return 1; 
    }

    if(memo[h] != 0) {
        return memo[h];
    }

    sum += 2 * solve(ceil(h / 2));

    memo[ceil(h/2)] = sum;

    return sum;
}

int main(void)
{
    ll h;    
    cin >> h;
    
    ans = solve(h);
    cout << ans << endl;

	return 0;
}
/** atcodr **/


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int sum = 0;
  if (a >= b) sum += b;
  else sum += a;

  if (c >= d) sum += d;
  else sum += c;

  cout << sum << endl;
}

Measured memory_bytes: 3496
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  int A[N];
  rep(i,N)
    cin>>A[i];
  bool B[N];
  rep(i,N)
    B[i]=false;
  B[0]=true;
  int nex=0;
  int cnt=0;
  rep(i,N){
    int tmp;
    tmp=nex;
    nex=A[tmp]-1;
    cnt++;
    if(B[nex]){
      cout<<-1<<endl;
      return 0;
    }
    if(nex==1){
      cout<<cnt<<endl;
      return 0;
    }
    B[nex]=true;
  }

}
  






Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a,b;
  cin >> a >> b;
  if(a>b) swap(a,b);
  rep(i,b){
    cout<<a;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a,b;
    cin>>a;
    cin>>b;
    if(a>b){
        cout<<"a > b"<<endl;
    }
    else if(a<b){
        cout<<"a < b"<<endl;
    }
    else{
        cout<<"a == b"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n >> m;
  map<ll,int> card;
  rep(i,n){
    ll x;
    cin >> x;
    card[-x]++;
  }
  rep(i,m){
    ll x, b;
    cin >>b >> x;
    card[-x]+=b;
  }
  ll sum = 0;
  int cnt = 0;
  for(auto it :card){
    int c = min(n-cnt,it.se);
    sum+=c*it.fi;
    cnt+=c;
    if(cnt == n)break;
  }
  cout << -sum << endl;
  return 0;
}

Measured memory_bytes: 16052
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	string s; cin >> s;

	if (s == "ARC") cout << "ABC" << endl;
	else cout << "ARC" << endl;
}


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

int main()
{
    int h, w;
    for (;;) {
	cin >> h >> w;
	if (h == 0 && w == 0)
	    return 0;
	for (int c1 = 0; c1 < h; c1++) {
	    for (int c2 = 0; c2 < w; c2++) {
		if ((c1 % 2 + c2 % 2) % 2)
		    cout << ".";
		else
		    cout << "#";
	    }

	    cout << endl;

	}
	cout << endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
    int a,p=0;
    cin>>a;
    p=a%11;
    if(!p)p=0;
    else if(p>6)p=2;
    else p=1;
    cout<<(a/11)*2+p<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    ll sum = 0;
    unordered_map<ll,ll> mp;
    rep(i,0,N){
        int X;
        cin >> X;
        sum += X;
        mp[sum]++;
    }
    ll ans = 0;
    for(auto p:mp){
        if(p.first == 0)ans += p.second;
        ans += (p.second * (p.second - 1) ) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8520
fn main() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    println!("{}", min(n % k, k - n % k));
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

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

// =========


Measured memory_bytes: 4352
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(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
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	g := make([][]int, n)
	aa := make([]int, m)
	bb := make([]int, m)
	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		aa[i] = a
		bb[i] = b
		g[a] = append(g[a], b)
		a, b = b, a
		g[a] = append(g[a], b)
	}
	sol := solver{}
	sol.g = g
	sol.visited = make([]int, n)
	var ans int64
	ans = int64(n)*int64(n-1)/2 - int64(m)
	if sol.dfs(0, 2) {
		fmt.Fprintln(writer, ans)
		return
	}
	cc := map[int]int64{}
	for i := 0; i < n; i++ {
		cc[sol.visited[i]] = cc[sol.visited[i]] + 1
	}
	ans -= cc[1]*(cc[1]-1)/2 + cc[2]*(cc[2]-1)/2
	for i := 0; i < m; i++ {
		if sol.visited[aa[i]] == sol.visited[bb[i]] {
			ans++
			continue
		}
	}
	fmt.Fprintln(writer, ans)
}

type solver struct {
	g       [][]int
	visited []int
}

func (sol *solver) dfs(i, c int) bool {
	sol.visited[i] = c
	for _, to := range sol.g[i] {
		if sol.visited[to] == 0 {
			b := sol.dfs(to, 3-c)
			if b {
				return true
			}
			continue
		}
		if sol.visited[to] != c {
			continue
		}
		return true
	}

	return false
}


Measured memory_bytes: 15872
// B - Sum of Three Integers x + y + z = Sとなるx,y,zは何通りあるか
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main () {
  int K, S, count = 0;
  cin >> K >> S;
 
 //rep(x, K){
  rep(x, K+1){
    rep(y ,K+1){
    int z = S - x - y;
    //if (z <= K){  z<0のときもカウントされて3かいぶん多くなっている
     if (z <= K && z >= 0){
        count++;
    }
    }
 }
 cout << count << endl;
}

Measured memory_bytes: 256
n=int(input())

A=list(map(int,input().split()))
        
A.sort(reverse=True)

X=[]

t=-1

for i in A:
    if t==i:
        t=-1
        X.append(i)
        if len(X)>1:
            break
    else:
        t=i
        
if len(X)>1:
    print(X[0]*X[1])
else:
    print(0)

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

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

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

int main(void) {
    int N,Q;
    int cnt;
    string S;
    int times;
    
    cin >> N >> Q >> S;

    vector<pair<int,int>> lr(Q);
    for(int i=0;i<Q;i++) {
        cin >> lr[i].first >> lr[i].second;
    }

    cnt = 0;
    vector<int> sum(N,0);
    for(int i=0;i<(N-1);i++) {
        sum[i] = cnt;
        if(S[i] == 'A' && S[i+1] == 'C') {
            cnt++;
            sum[i] = cnt;
        }
    }

    for(int i=0;i<Q;i++) {
        times = sum[lr[i].second-2] - sum[lr[i].first-2];
        if(times < 0) times = 0;
        cout << times << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>

using st = std::string::size_type;

int n;
int end_a_count = 0;
int start_b_count = 0;
int both_count = 0;
int ab = 0;
int ans = 0;
std::string s;
std::string ab_str = "AB";

int str_count(std::string str, std::string& f) {
    st c = 0;
    for (st i = 0; (i = str.find("AB", i)) != std::string::npos; i+=f.size()) {
        c++;
    }
    return c;
}

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s;
        if (s[0] == 'B' && s[s.size()-1] == 'A') {
            both_count++;
        }
        else if (s[0] == 'B') {
            start_b_count++;
        }
        else if (s[s.size()-1] == 'A') {
            end_a_count++;
        }
        ab += str_count(s, ab_str);
    }
    if (both_count > 0) {
        ans += (both_count - 1);
        if (end_a_count > 0) {
            ans++;
            end_a_count--;
        }
        if (start_b_count > 0) {
            ans++;
            start_b_count--;
        }
    }
    ans = ans + ((start_b_count < end_a_count) ? start_b_count : end_a_count) + ab;
    std::cout << ans << std::endl;

}


Measured memory_bytes: 256
s = input()
l_alph = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = [0]*26
for i in range(26):
	if l_alph[i] in s:
		ans[i] = 1
for i in range(26):
	if not ans[i]:
		print(l_alph[i])
		quit()
print("None")

#l_alph = [i for i in range(26)]


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>
#include <limits>

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> paint;
    paint.insert(a);
    paint.insert(b);
    paint.insert(c);
    cout << paint.size() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
#define FOR(x, to) for(x=0; x<(to); x++)

 int main(){
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    S[K-1] += 32;

    cout << S << endl;

    return 0;
 }

Measured memory_bytes: 256
#include <iostream>

#define SIZE 50

int N, M;
int road[SIZE];

int main() {
    std::cin >> N >> M;
    for (int i=0; i<M; ++i) {
        int a, b;
        std::cin >> a >> b;
        ++road[--a];
        ++road[--b];
    }
    for (int i=0; i<N; ++i) {
        std::cout << road[i] << '\n';
    }
    return 0;
}

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

using namespace std;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n / 2; i++){
		if(s[i] != s[n - 1 - i]){
			ans++;
		}
	}
	cout << ans;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d = 3 * max(max(a, b), c) - a - b - c;
	cout << (d % 2 ? d / 2 + 2 : d / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	string s;
	cin >> s;

	ll answ = 0, cnt = 0;

	for(auto& ch: s)
	{
		if(ch == 'B')
		{
			++cnt;
		}
		else
		{
			answ += cnt;
		}
	}

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 1000000007

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

int main() {
	int n, t;
	cin >> n >> t;

	vector<int> v(n);
	rep(i, n) cin >> v[i];

	sort(v.begin(), v.end());

	ll ans = 1;
	vector<int> res;
	rep(i, n) {
		res.push_back(v[i]);
		int id = lower_bound(res.begin(), res.end(), v[i] - t) - res.begin();
		ans *= (res.size() - id);
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int, int>;
const int INF (1<<30);

vector<int> isBuy;
int N, M, X;
vector<int> C;
vector<vector<int>> A;
int ans = INF;

void solve(void) {
  vector<int> u(M, 0);

  int cost = 0;
  rep(i, N) {
    if (isBuy[i] == 1) {
      cost += C[i];
      rep(j, M) {
        u[j] += A[i][j];
      }
    }
  }

  bool isOk = true;
  rep(i, M) {
    if (u[i] < X) {
      isOk = false;
      break;
    }
  }

  if (isOk) {
    ans = min(ans, cost);
  }

}

void dfs(int id, int x) {
  
  isBuy[id] = x;

  if (id == N-1) {
    solve();
    return;
  }

  dfs(id+1, 0);
  dfs(id+1, 1);
}

int main() {
  cin >> N >> M >> X;
  C.resize(N);
  A.resize(N, vector<int>(M));
  isBuy.resize(N);

  rep(i, N) {
    cin >> C[i];
    rep(j, M) {
      cin >> A[i][j];
    }
  }

  dfs(0, 0);
  dfs(0, 1);

  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;


  return 0;
}


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

int main(void){
    int n;
    string s;
    map<string,int> mp;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        mp[s];
    }
    cout<<mp.size();
}

Measured memory_bytes: 19052
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve;
set<int> st;

template<typename MAIN> ostream & operator<<(ostream & osys,const vector<MAIN> target){ for(MAIN it:target)osys<<it<<" "; return osys; }

int main(){
    cin>>n;
    c=0;
    for(int i=0;i<n;i++){
        cin>>aa[i];
        ab[i]=aa[i];
    }
    sort(ab,ab+n);
    for(int i=0;i<n;i++){
        c+=!(aa[i]==ab[i]);
    }
    C ((c==2 or c==0) ? "YES":"NO") E;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

int N, K;
std::string S;

int main(int argc, char **argv) {
    std::cin >> N >> K;
    std::cin >> S;

    if (S[K-1] == 'A') {
        S[K-1] = 'a';
    } else if (S[K-1] == 'B') {
        S[K-1] = 'b';
    } else {
        S[K-1] = 'c';
    }
    
    std::cout << S << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt;
ll ans;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>n>>s;
  if (n>=3200) cout<<s<<endl;
  else cout<<"red\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, q, A[N];
pair < int , int > B[N];
multiset < int > S;
int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]);
    for (int i = 1; i <= q; i++)
        scanf("%d%d", &B[i].second, &B[i].first);
    sort(B + 1, B + q + 1);
    sort(A + 1, A + n + 1);
    vector < int > vec;
    for (int i = q; i; i --)
        while ((int)vec.size() < n && B[i].second)
            vec.push_back(B[i].first), B[i].second --;
    long long Mx = 0, sum = 0;
    for (int i = 0; i < min(n, (int)vec.size()); i++)
        sum += vec[i] - A[i + 1], Mx = max(Mx, sum);
    for (int i = 1; i <= n; i++)
        Mx += A[i];
    printf("%lld\n", Mx);
    return 0;
}

Measured memory_bytes: 5756
# -*- coding: utf-8 -*-
from collections import deque
n=int(raw_input())
que = deque()
for i in xrange(n):
    o = raw_input()
    if o == 'deleteFirst':
        del que[0]
    elif o == 'deleteLast':
        del que[-1]
    else:
        c,p = o.split()
        p = int(p)
        if c == 'insert':
            que.appendleft(p)
        elif c == 'delete':
            try: que.remove(p)
            except: pass
print ' '.join(map(str,que))
                

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

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line,result="";
            boolean first=true;
            int n=0,i=0,taro=0,hana=0;
            while ((line = br.readLine()) != null) {
            	if(first){
            		result=line;
            		n=Integer.parseInt(br.readLine());
            		first=false;
            	}else{
            		String[] str=line.split(" ");
            		int a=Integer.parseInt(str[1]);
            		int b=Integer.parseInt(str[2]);
            		if(str[0].equals("replace")){
            			if(a==0){
            				result=str[3]+result.substring(b+1, result.length());
            			}else if(b==result.length()-1){
            				result=result.substring(0, a)+str[3];
            			}else{
            				result=result.substring(0, a)+str[3]+result.substring(b+1, result.length());
            			}
            		}else if(str[0].equals("reverse")){
            			if(a==0){
            				result=new StringBuilder(result.substring(a,b+1)).reverse().toString()+result.substring(b+1,result.length());
            			}else if(b==result.length()-1){
            				result=result.substring(0, a)+new StringBuilder(result.substring(a,b+1)).reverse().toString();
            			}else{
            				result=result.substring(0, a)+new StringBuilder(result.substring(a,b+1)).reverse().toString()+result.substring(b+1,result.length());
            			}
            		}else if(str[0].equals("print")){
            			System.out.println(result.substring(a,b+1));
            		}
            		
            		i++;
            		if(i==n){
            			break;
            		}
            	}
            	
            }
        }
    }

}

Measured memory_bytes: 25120
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cout << #x << " " << x << endl;
#define debugtwo(x) cout << #x << "-------------" << endl;for(auto &it: x) cout << it << " ";cout << endl;
#define debugthree(x, i, j) cout << #x << "------------" << endl;cout << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cout << x[k] << " ";cout << endl;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int p, q, r;
	cin >> p >> q >> r;
	int maxi = max(p, (max(q, r)));
	cout << p + q + r - maxi << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.nextLine();
        String T = scanner.nextLine();
        int count = 0;
        if(S.substring(0,1).equals(T.substring(0,1))){
            count++;
        }
        if(S.substring(1,2).equals(T.substring(1,2))){
            count++;
        }
        if(S.substring(2,3).equals(T.substring(2,3))){
            count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        int x = sc.nextInt();
        int y = sc.nextInt();
        if(x == 0 && y == 0) break;
        if(x < y) System.out.println(x + " " + y);
        else System.out.println(y + " " + x);
        }
    }
}


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

int main() {
  long D,N;
  cin >> D >> N;

  long ans = pow(100, D)*N;

  if(N == 100){
    ans += pow(100, D);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
public class c
{
  public static void Main()
  {
    char[] S=Console.ReadLine().ToCharArray();
    ulong K=ulong.Parse(Console.ReadLine());
    int i;
    int[] ans=new int[S.Length];
    int x=0;
    for(i=0;i<S.Length;i++)
    {
      if(int.Parse(S[i].ToString())==1){ans[i]=1;}
      else {ans[i]=int.Parse(S[i].ToString());x=i;break;}
    }
    if(K<=(ulong)x)Console.WriteLine(1);
    else Console.WriteLine(ans[x]);
  }
}

Measured memory_bytes: 11092
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
	P *= -1
	Q *= -1

if P + Q < 0:
	print(0)
elif P + Q == 0:
	print("infinity")
else:
	S = (-P) // (P + Q)
	T = (-P) % (P + Q)
	if T != 0:
		print(S * 2 + 1)
	else:
		print(S * 2)

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

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

  int a[100001];
  int n; cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  //a[0]が+,-両方試す
  int sum = 0,ans = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
    if(i%2 == 0){
      while(sum <= 0){
        sum++;
        ans++;
      }
    }
    else {
      while(sum >= 0){
        sum--;
        ans++;
      }
    }
  }

  sum = 0;
  int ans2 = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
    if(i%2 == 1){
      while(sum <= 0){
        sum++;
        ans2++;
      }
    }
    else {
      while(sum >= 0){
        sum--;
        ans2++;
      }
    }
  }

  cout << min(ans,ans2) << endl;

  return 0;
}


Measured memory_bytes: 1024
package main

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

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

	h := make([]int, n, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		scanner.Scan()
		h[i], _ = strconv.Atoi(scanner.Text())
	}

	dp := make([]int, n, n)
	dp[0] = 0
	dp[1] = abs(h[1] - h[0])
	for i := 2; i < n; i++ {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
	}
	fmt.Println(dp[n - 1])
}

func abs(n int) int {
	if n >= 0 {
		return n
	}
	return -n
}

func min(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}


Measured memory_bytes: 2688
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

int n,w;
LL arr[2][3007];
LL dpT[MAX/4][200];
LL dp(int points, int pos)
{
	if(pos<0)
		if(points!=0)
			return LINF;
		else
			return 0;
	if(points<0)
		return LINF;
	if(dpT[points][pos]!=-1LL)
		return dpT[points][pos];
	return dpT[points][pos] = min(dp(points,pos-1),dp(points-arr[1][pos],pos-1)+arr[0][pos]);
}



int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
	FILL(dpT,-1);
	cin >> n>>w;
	FOR(i,0,n)
		cin >> arr[0][i] >> arr[1][i];
	LL ans=0;
	FOR(i,0,MAX/4)
		FOR(j,0,n)
			if(dp(i,j)<=w)
				ans=max(ans,i);
//	cout<<dp(2999,0)<<endl;
//	cout<<dp(2999,-1)<<endl;
//	cout<<dp(2999,0)<<endl;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 156544
m,i,j,k,c[],p,d;	//c[16]
main(n){
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",j>m?-1:j)){
		for(k=3;k--;)
			for(scanf("%d",&i);i--;c[j]=k)scanf("%d",&j);
		for(j=k=0;k++<n;p=c[k]*2+p&3)
			j+=pow(3,n-k)*abs(p-c[k]);
		j=fmin(j,pow(3,n)+~j);
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,t,a[200010],neg=0,del_neg=-2e9,del_pos=2e9,add_neg=2e9,add_pos=-2e9,zero=0;

bool cmp(LL x,LL y)
{
	return abs(x)>abs(y);
}

int main()
{
	cin>>n>>t;
	rep(i,n) scanf("%lld",&a[i]);
	sort(a,a+n,cmp);
	LL ans=1;
	rep(i,t)
	{
		ans=(ans*a[i]+MOD*MOD)%MOD;
		if(a[i]<0)
		{
			neg++;
			del_neg=max(del_neg,a[i]);
		}
		if(a[i]>0) del_pos=min(del_pos,a[i]);
		if(a[i]==0)
		{
			puts("0");
			return 0;
		}
	}
	if(neg%2==0)
	{
		cout<<ans<<endl;
		return 0;
	}
	for(int i=t;i<n;i++)
	{
		if(a[i]<0) add_neg=min(add_neg,a[i]);
		if(a[i]>0) add_pos=max(add_pos,a[i]);
		if(a[i]==0) zero++;
	}
	if(del_neg==-2e9||add_pos==-2e9) add_pos=0;
	if(add_neg==2e9||del_pos==2e9) add_neg=0;
	del_neg=-del_neg;
	add_neg=-add_neg;
	bool ok=false;
	if(add_pos*del_pos>add_neg*del_neg)
	{
		ans=1;
		rep(i,t)
		{
			if(a[i]==-del_neg&& !ok) ok=true;
			else ans=(ans*a[i]+MOD*MOD)%MOD;
		}
		ans=(ans*add_pos)%MOD;
		cout<<ans<<endl;
	}
	else if(add_neg!=0)
	{
		ans=1;
		rep(i,t)
		{
			if(a[i]==del_pos&& !ok) ok=true;
			else ans=(ans*a[i]+MOD*MOD)%MOD;
		}
		ans=(ans*(-add_neg)+MOD*MOD)%MOD;
		cout<<ans<<endl;
	}
	else
	{
		if(zero>0) puts("0");
		else
		{
			reverse(a,a+n);
			ans=1;
			rep(i,t) ans=(ans*a[i]+MOD*MOD)%MOD;
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5196
#if 0
2019.12.17

假设所有点都是关键点，记 f(u, k) 表示集合 {x | dis(u, x) < k} 。
问题相当于求所有本质不同的 f(u, k) 数量。

点的全集比较特殊，单独考虑。
对于点 u ，设其作为根时的树深度为 d ，那么满足 k < d 的 f(u, k) 都可以被计入答案。
但是这样会算重，因为存在 f(u, k1) = f(v, k2) 且 u != v 。
对于每个可行的点集，能表示出来的 f(u, k) 中一定存在一个 k 最小的唯一的 u ，
如果仅在 k 最小的 u 上统计该点集就不会算重，

考虑每个 f(u, k) 的 k 需要满足什么条件才能满足上述条件，
设 u 的深度最大的儿子为 v ，如果 f(v, k - 1) = f(u, k) 那么 k 不可行，
也就是说 k 还需要满足 k - 1 <= d2 ，其中 d2 是除去 v 子树后的树深度。
综上，答案为 1 + sum(min(d - 1, d2 + 1)) 。

现在考虑存在非关键点的情况。
一个 naive 的想法是只对关键点统计上述贡献，
但可能有一个合法点集应在 f(u, k) 处被统计，而 u 现在成了非关键点，这样就漏记了。

考虑非关键点 u 作为根时，k 要额外满足什么条件才能统计 f(u, k) 。
事实上当 f(u, k) 包含了任一包含关键点的 v 的子树时才能被统计，其中 v 是 u 的儿子。
也就是说需要满足 k >= bd ，其中 bd 是所有包含关键点的 v 子树的深度的最小值。

实现时只需要用换根 DP 求出每个点作为根时的 d, d2, bd 即可，
辅助转移需要记 c 表示子树内关键点的数量。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
int head[maxn], nxt[maxn << 1], to[maxn << 1], hp = 1;
char s[maxn];

inline void add(int u, int v) {
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
}

struct Data {
	int d, d2, bd, c;

	inline void update(Data an) {
		if(an.d + 1 > d) {
			d2 = d;
			d = an.d + 1;
		} else
			d2 = std::max(d2, an.d + 1);
		if(an.c)
			bd = std::min(bd, an.d);
		c += an.c;
	}

	inline void undo(Data an) { // only need "d" and "c" to update
		if(an.d + 1 == d)
			d = d2;
		c -= an.c;
	}
};
Data f[maxn];

void dfs1(int u, int fa) {
	f[u] = {1, 1, maxn, s[u] == '1'};

	for(int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v != fa) {
			dfs1(v, u);
			f[u].update(f[v]);
		}
	}

	/* debug("%d : %d %d %d\n", u, f[u].d, f[u].d2, f[u].bd); */
}

ll ans = 1;
void dfs2(int u, int fa, Data ff) {
	Data g = f[u];
	g.update(ff);

	int L = s[u] == '1' ? 1 : g.bd + 1;
	int R = std::min(g.d - 1, g.d2 + 1);
	if(L <= R) ans += R - L + 1;

/* 	debug("%d : %d %d %d\n", u, g.d, g.d2, g.bd); */
/* 	debug("from %d %d\n", ff.d, ff.bd); */
/* 	debug("ans %d-%d\n", L, R); */

	for(int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v != fa) {
			Data vff = g;
			vff.undo(f[v]);
			dfs2(v, u, vff);
		}
	}
}

int main() {
	int n = read;
	for(int i = 1; i < n; i ++) {
		int u = read, v = read;
		add(u, v);
		add(v, u);
	}
	scanf("%s", s + 1);

	dfs1(1, 0);
	dfs2(1, 0, {0, 0, maxn, 0});

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


Measured memory_bytes: 21632
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int nn = n-1;

    long long int cnt = 0; 
    for(int i=1; i<n; i++){
        cnt += nn/i;
        /*
        for(int j=i+1; j<=n; j++){
            const long long int ij = i*j;
            if(ij < n){
                
                const long long int tmp = n - i*j;
                if(tmp != i && tmp != j){
                    cnt++;
                }
                
                cnt++;
            }
        }
        */
    }
 
 
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3628
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)

vector<int> makeFactor(int x) {
	vector<int> factors;
	factors.push_back(2);
	for (size_t i = 3; i <= sqrt(x); i+=2)
	{
		bool flag = false;
		Foreach(item, factors) if (i%item == 0) { flag = true; break; }
		if (!flag) factors.push_back(i);
	}
	return factors;
}

int main(){
	ll x;
	cin >> x;
	ll ans = ceil((long double)x / 11);
	if (ans * 11 - 5 >= x) { out(ans * 2 - 1); return 0; }
	out(ans * 2);
}



Measured memory_bytes: 256
/**
 *      ABC 95 C
 *      author  : kyomukyomupurin
 *      created : 2018/08/26
**/

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

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    if (X == Y){
        cout << min(A * X + B * Y, C * 2 * X) << endl;
    }
    else if (X > Y){
        cout << min(A * X + B * Y, min(2 * C * Y + (X - Y) * A, 2 * C * X)) << endl;
    }
    else {
        cout << min(A * X + B * Y, min(2 * C * X + (Y - X) * B, 2 * C * Y)) << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
N = int(input())
A = [0] + [int(i) for i in input().split()] + [0]
total = 0
for i in range(len(A) - 1):
    total += abs(A[i + 1] - A[i])
for i in range(1, len(A) - 1):
    print(
        total - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1])
    )


Measured memory_bytes: 14048
K,N=map(int,input().split())
la=list(map(int,input().split()))
la.sort()
maxd=0
ans=0
for i in range(N):
    tmpd=(la[i]-la[i-1])%K
    ans+=tmpd
    if tmpd>maxd:
        maxd=tmpd
print(ans-maxd)


Measured memory_bytes: 25580
n = int(input())
s1 = input()
s2 = input()

if s1[0] == s2[0]:
    now = True
    ans = 3
    i = 1
else:
    now = False
    ans = 6
    i = 2

while i < n:
    if now:
        ans *= 2
        if s1[i] != s2[i]:
            i += 1
            now = False
    else:
        if s1[i] == s2[i]:
            now = True
        else:
            ans *= 3
            i += 1
    i += 1
print(ans % 1000000007)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string s,t;
int i;

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

    s = s + s;
    if(s.find(t) != s.npos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main() {
  uint64_t n, m;
  std::cin >> n >> m;

  std::multimap<uint64_t, uint64_t> map;
  for (uint64_t i = 0; i < n; i++) {
    uint64_t a, b;
    std::cin >> a >> b;
    map.insert(std::make_pair(a, b));
  }

  uint64_t yen = 0, num = 0;

  for (const auto &val : map) {
    const auto price = val.first;
    const auto n = val.second;

    if (n < m - num) {
      yen += price * n;
      num += n;
    } else {
      yen += price * (m - num);
      num += m - num;
      break;
    }
  }

  std::cout << yen << std::endl;
  return 0;
}


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

int main()
{
  ios::sync_with_stdio(0);
  int k;
  string s;
  cin >> k >> s;
  for(int i = 0 ; i < min((int)s.size(), k); i++)
  {
    cout << s[i];
  }
  if(s.size() > k)
    cout << "...\n";
  else
    cout << "\n";
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
 	int k, x;
 	cin >> k >> x;
	int a = x-k+1;
	int b = x+k-1;
	if( a<-1000000 ) {
		a = -1000000;
	}
	if( b>1000000 ) {
		b = 1000000;
	}
	for( int i=a; i<=b; i++ ) {
		pfd(i);
		if( i<b ) {
			pfk;
		}
	}
	return 0;
}


Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static char solve(int x, int a, int b) {
        int dist_a = Math.abs(x-a);
        int dis_b = Math.abs(x-b);

        return dist_a < dis_b ?  'A': 'B';
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int x = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(solve(x,a,b));
    }
}

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

long func(long x, long y){
    long r = y % x, tmpgcd;

    while(r != 0){
        y = x;
        x = r;
        r = y % x;
    }
    tmpgcd = x;
    
    return tmpgcd;
}

int main() {
	long a, b, c, d;
	std::cin >> a >> b >> c >> d;
	
	long sum = b - a + 1;
	
	//std::cout << sum << std::endl;
	
	long lcm = c * d / func(c, d);
	//std::cout << lcm << std::endl;
	
	long sumc = (b / c) - ((a - 1) / c);
	long sumd = (b / d) - ((a - 1) / d);
	long candd = (b / lcm) - ((a - 1) / lcm);
	
	/*
	std::cout << sumc << std::endl;
	std::cout << sumd << std::endl;
	std::cout << candd << std::endl;
	*/
	
	long ans = sum - sumc - sumd + candd;
	
	std::cout << ans << std::endl;
	
	return 0;
}

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

using namespace std;



int main()
{
    int cnt = 0;
    string str1, str2;
    cin >> str1 >> str2;

    for(int i = 0; i < str1.length(); i++)
    {
        if(str1[i] != str2[i])
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,w;
  cin >> n >> w;
  vector<pair<ll,ll>> a(n);
  for(int i = 0;i < n;i++){
    ll noww,nowv;
    cin >> noww >> nowv;
    a[i] = make_pair(noww,nowv);
  }
  vector<vector<ll>> dp(n,vector<ll>(w + 1));
  for(int i = 0;i < n;i++)for(int j = 0;j < w + 1;j++)dp[i][j] = 0;
  for(int i = 0;i < w + 1;i++){
    if(a[0].first <= i)dp[0][i] = a[0].second;
    //cout << dp[0][i] << " " << a[0].first << endl;
  }
  for(int i = 1;i < n;i++){
    for(int j = 0;j < w + 1;j++){
      if(j - a[i].first >= 0)dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - a[i].first] + a[i].second);
      else dp[i][j] = dp[i - 1][j];
    }
  }
  ll res = 0;
  for(int i = 0;i < w + 1;i++)res = max(res,dp[n - 1][i]);
  cout << res << endl;
  /*for(int i = 0;i < n;i++){
    for(int j = 0;j < w + 1;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
}

Measured memory_bytes: 79360
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  int* a = new int[100000];
  for(int i=0;i<n;i++) cin >> a[i];
  int ans = (n-1)/(k-1);
  if((n-1)%(k-1)!=0) ans ++;

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


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

const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int N,K;
  cin>>N>>K;
  for(int i=1;i<=K;++i){
    cout<<(COM(K-1,i-1)*COM(N-K+1,i))%MOD<<endl;
  }
}


Measured memory_bytes: 12160
use proconio::{*, marker::*};
use std::collections::BTreeSet;

fn main() {
    input! {
        h: usize,
        w: usize,
        m: usize,
        hw: [(Usize1, Usize1); m],
    }

    let mut hh = vec![0; h];
    let mut ww = vec![0; w];

    for &(y, x) in hw.iter() {
        hh[y] += 1;
        ww[x] += 1;
    }

    let mut h_max = 0;
    for i in 0..h {
        h_max = h_max.max(hh[i]);
    }

    let mut w_max = 0;
    for i in 0..w {
        w_max = w_max.max(ww[i]);
    }

    let mut h_maxs = BTreeSet::new();
    for i in 0..h {
        if h_max == hh[i] {
            h_maxs.insert(i);
        }
    }
    let mut w_maxs = BTreeSet::new();
    for i in 0..w {
        if w_max == ww[i] {
            w_maxs.insert(i);
        }
    }

    let mut cross_cnt = 0;
    for &(y, x) in hw.iter() {
        if h_maxs.contains(&y) && w_maxs.contains(&x) {
            cross_cnt += 1;
        }
    }

    let mut ans = h_max + w_max - 1;

    // println!("{:?}", h_maxs);
    // println!("{:?}", w_maxs);
    // println!("{}", cross_cnt);
    if cross_cnt < h_maxs.len() * w_maxs.len() {
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 25064
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int x;
	cin>>x;
	int lcm=(x*360)/(__gcd(x,360));
	cout<<lcm/x;
}

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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define pi 3.14159265358979323846

using namespace std;

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

	sort( a, a+n );

	if( a[0] != 0 ){
		for( int i = 0; i < n; i++ ){
			if( a[i] <= 1000000000000000000 / prod ){
				prod *= a[i];
			}else{
				cout << "-1" << endl;
				return 0;
			}
		}
		cout << prod << endl;
	}else{
		cout << "0" << endl;
	}


	return 0;
}


Measured memory_bytes: 4424
def sumitb2019_a
    m1,d1 = gets.chomp.split(/\s/).map{|x| x.to_i}
    m2,d2 = gets.chomp.split(/\s/).map{|x| x.to_i}

    md = [[1,31], [2,28], [3,31], [4,30], [5,31], [6,30], [7,31], [8,31], [9,30], [10,31], [11,30], [12,31]]
    md.each do |mmdd|
        if mmdd[0] == m1 and mmdd[1] == d1
            puts 1
            exit
        end
    end

    puts 0
end

sumitb2019_a

Measured memory_bytes: 1916