akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>
//by Skeef79

typedef long long ll;
typedef long double ld;

typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SZ(a) int(a.size())
#define what_is(x) cout<<#x<<" is "<<x<<en;


using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];

}

const int N = 1e7 + 10;

int lp[N+1];

void sieve()
{
	vector<bool>used(N + 1, false);

	for (ll i = 2; i <= N; i++)
	{
		if (!used[i])
		{
			if (lp[i] == 0)
				lp[i] = i;

			used[i] = true;

			for(ll j =i*i;j<=N;j+=i)
				if (!used[j])
				{
					used[j] = true;
					lp[j] = i;
				}
		}
	}
}

void solve()
{
	ll n;
	cin >> n;

	ll ans = 1;

	sieve();

	for (ll i = 2; i <= n; i++)
	{
		ll res = 1;
		ll x = i;
		map<ll, ll>mp;
		while (lp[x] != x)
		{
			mp[lp[x]]++;
			x /= lp[x];
		}

		mp[lp[x]]++;
		for (auto to : mp)
			res *= (to.second + 1);
		
		ans += res * i;	
	}
	cout << ans;
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("luigi.in", "r", stdin);
	//freopen("luigi.out", "w", stdout);

	int tst = 1;
	//cin >> tst;

	while (tst--)
		solve();
}


Measured memory_bytes: 43584
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <map>
using namespace std;

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

int main(void){
  int n, m;
  cin >> n >> m;
  if(n <= m){
    cout << n << endl;
  }else{
    cout << n-1 << endl;
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  double count=0.0;
  vector<double> x(N);
  vector<string> u(N);
  for(int i=0; i<N; i++) {
    cin >> x.at(i) >> u.at(i);
  }
  for(int i=0; i<N; i++) {
    if(u.at(i)=="BTC") {
      count+=x.at(i)*380000;
    }
    else {
      count+=x.at(i);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int,input().split())))

if N%2==0:
  B = [2*(n//2)+1 for n in range(N)]
else:
  B = [2*(n//2) for n in range(1,N+1)]

if A==B:
  print(pow(2,N//2,10**9+7))
else:
  print(0)

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}//-1で初期化
  int root(int x) {
    if (d[x] < 0) return x;//rootを負にする（構成node数x(-1))
    //root以外は親の番号
    return d[x] = root(d[x]);
    //return(root(d[x]))とするとメモできないが上の書き方だとメモができる
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    //swapすることで小さい方を大きい方につけられ計算量減らせる
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  //同じグループ化
  int size(int x) { return -d[root(x)];}
  //グループのnode数
    int group_num(int n){
        set<int> s;
        for(int i = 0; i < n; ++i){
            s.insert(root(i));
        }
        return int(s.size());}
};

int main() {
  int n,m;
  cin>>n>>m;
  UnionFind uf(n);
  rep(i,m){
    int a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    uf.unite(a1,b1);
  }
  int ans=0;
  rep(i,n){
    ans=max(ans,uf.size(i));
  }
  cout<<ans;

}


Measured memory_bytes: 4020
#include<stdio.h>
int main(void){
  int a,b,g;
  scanf("%d%d",&a,&b);
  if(a<b){
    g=a;
    a=b;
    b=g;
  }
  while(1){
    g=a%b;
    a=b;
    b=g;
    if(g == 0)break;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		StringBuffer str=new StringBuffer(sc.nextLine());
		int[] eng=new int[26];
		for(int i=0;i<str.length();i++)
		{
			for(int j=0;j<26;j++)
			{
				if(j+'a'==str.charAt(i))
				{
					eng[j]++;
				}
			}
		}
		
		int count=0;
		
		for(int i=0;i<26;i++)
		{
			if(eng[i]==0)
			{
				System.out.println((char)(i+'a'));
				break;
			}
			else
			{
				count++;
			}
			if(count==26)
			{
				System.out.println("None");
				break;
			}
		}
	}
}

Measured memory_bytes: 26540
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int N,M,K;
	cin>>N>>M>>K;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			int bla=i*(M-j)+j*(N-i);
			if(bla==K){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    reverse(all(a));
    priority_queue<int> q;
    q.push(a[0]);
    int cnt=0;
    ll ans=0;
    while(cnt<n-1){
        int x=q.top();
        ans+=x;
        cnt++;
        q.pop();
        q.push(a[cnt]);
        q.push(a[cnt]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5824
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define int long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

int maxk(int A[], int n, int k) 
{ 
    sort(A, A + n); 
  
    int product = 1; 
  
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (int i = n - 1; i >= n - k; i--) 
            product =(product%mod) * A[i]; 
        return product%mod; 
    } 
  
    int i = 0; 
  
    int j = n - 1; 
  
    
    if (k & 1) { 
        product =(product%mod) *  A[j]; 
        j--; 
        k--; 
    } 
    k >>= 1; 
  
    for (int itr = 0; itr < k; itr++) { 
  
        int left_product = A[i] * A[i + 1]; 
  
        int right_product = A[j] * A[j - 1]; 
  
        if (left_product > right_product) { 
            product =(product%mod) *  left_product; 
            i += 2; 
        } 
        else { 
            product =(product%mod) *  right_product; 
            j -= 2; 
        } 
    } 
  
    return product%mod; 
} 

void virus(){
    ll len;
    cin>>len;
    vector<ll> arr(len);
    for(auto &i:arr) cin>>i;
    sort(arr.begin(),arr.end(),greater<ll>());
    if(len == 1){
        cout<<"0\n"; return;
    }
    if(len == 2){
        cout<<arr[0]<<endl; return;
    }
    ll sum = arr[0];
    ll left = len-2, last;
    for(auto i=1;i<len;i++){
        sum += (arr[i]*2);
        last = arr[i];
        left-=2;
        if(left<=0) break;
    }
    if((len-2)&1) cout<<sum-last; else cout<<sum;

}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 4856
str = gets.split
N,K = str[0].to_i, str[1].to_i
S = gets.chomp
c = 0
answer = 0

for i in 0...N-1 do
    if S[i] == S[i+1]
        answer += 1
    else
        c += 1
    end
end

answer += 2*K
if answer >= N
    answer = N-1
end

puts answer

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

const int INF = 1001001001;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, 0, m) cin >> b[i];
    vector<vector<int>> a(n, vector<int> (n));
    rep(i, 0, n) rep(j, 0, m) cin >> a[i][j];
    int ans = 0;
    rep(i, 0, n){
        int sum = 0;
        rep(j, 0, m) sum += a[i][j]*b[j];
        if(sum > -c) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
N, M = gets.split.map(&:to_i)
neighbors = Array.new(N) { Array.new(N) {false} }

edges = []
M.times do
  a, b = gets.split.map(&:to_i)
  edges << [a - 1, b - 1]
  neighbors[a - 1][b - 1] = true
  neighbors[b - 1][a - 1] = true
end

def dfs(v, neighbors, visited)
  # p "visited #{v} #{visited}"
  if visited.all? {|v| v == true }
    return true
  end

  neighbors[v].each_with_index do |u, i|
    if u && visited[i] == false
      visited[i] = true
      # connected
      if dfs(i, neighbors, visited)
        return true
      end
      # visited[i] = false
    end
  end

  return false
end

num = 0
edges.each do |edge|
  # puts "delete #{edge[0]} #{edge[1]}"
  neighbors[edge[0]][edge[1]] = false
  neighbors[edge[1]][edge[0]] = false
  visited = Array.new(N) { false }
  visited[0] = true
  if dfs(0, neighbors, visited) == false
    num += 1
  end
  neighbors[edge[0]][edge[1]] = true
  neighbors[edge[1]][edge[0]] = true
end

puts num


Measured memory_bytes: 2172
N = int(input())
S = input()
ans = 0
for i in range(N):
    a = S[:i+1]
    b = S[i+1:]
    c = 0
    for j in range(26):
        if chr(j+97) in a and chr(j+97) in b:
            c += 1
    ans = max(ans,c)
print(ans)

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        m: usize,
        edges: [(usize1, usize1); m],
    }

    let edge_map = (0..n)
        .into_iter()
        .map(|i| {
            (
                i,
                edges
                    .iter()
                    .flat_map(|&(a, b)| match i {
                        _ if i == a => Some(b),
                        _ if i == b => Some(a),
                        _ => None,
                    })
                    .collect(),
            )
        })
        .collect::<HashMap<usize, Vec<usize>>>();
    println!("{}", walk(n, 0, &edge_map, vec![0]));
}

fn walk(n: usize, start: usize, edge_map: &HashMap<usize, Vec<usize>>, used: Vec<usize>) -> usize {
    let edges = edge_map.get(&start).unwrap();
    if edges.iter().all(|e| used.contains(e)) {
        if (0..n).all(|node| used.contains(&node)) {
            return 1
        } else {
            return 0
        }
    }

    edges.iter().filter(|e| !used.contains(e)).fold(0, |acc, e| {
        let mut used = used.clone();
        used.push(*e);
        acc + walk(n, *e, edge_map, used)
    })
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int N;
string A,B,C;
const int ALP='z'-'a'+1;
int cnt[ALP];
int main(){
	cin>>N>>A>>B>>C;
	int ans=0;
	REP(i,N){
		memset(cnt,0,sizeof(cnt));
		cnt[A[i]-'a']++;
		cnt[B[i]-'a']++;
		cnt[C[i]-'a']++;
		ans+=3-*max_element(cnt,cnt+ALP);
	}
	cout<<ans<<endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int a, b; cin >> a >> b;
  vector<int> v = {a+b, a-b, a*b};
  sort(v.begin(), v.end());
  cout << v.back() << endl;

  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s;
  int k;
  cin>>s>>k;
  vector<int> vec(s.size());
  for (int i = 0; i < s.size(); ++i)
  {
    vec[i]=('z'-s[i]+1)%26;
  }
  for (int i = 0; i < s.size(); ++i)
  {
    if(vec[i]<=k){
      k-=vec[i];
      s[i]='a';
    }
  }
  
  s[s.size()-1]+=k%26;
  cout<<s;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    bool c = false, f = false;
    rep(i, s.size()){
        if(!c){
            if(s[i] == 'C') c = true;
        }
        else{
            if(s[i] == 'F') f = true;
        }
    }
    (c && f) ? Yes() : No();
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int a,b,ans;
    scanf("%d %d",&a,&b);
   if(b>0){
       ans=a+b;
   }
   else{
       ans=a-b;
   };
   if(ans<a*b){
       ans=a*b;
   };
   printf("%d",ans);
    return 0;
};

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, k);
    if(k <= a) Return(k);
    if(k <= b) Return(a);
    Cout(2*a + b - k);
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>

using namespace std;



int main() {

	int n; cin >> n;
	int* arr1 = new int[n + 1];
	for (int i = 0; i < n; i++)	{
		scanf("%d", &arr1[i]);
	}

	int q; cin >> q;
	int count = 0;

	int j = 0;
	for (int i = 0; i < q; i++)	{
		int key;
		scanf("%d", &key);
		arr1[n] = key;
		while (key != arr1[j]) {
			j++;
		}
		if (j != n) count++;
		j = 0;
	}
	
	cout << count << endl;


	return 0;
}



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

int main()
{
	int size = 0;
	int sum;
	vector<int> a = {};
	cin >> size;

	for (int i = 0; i < size; i++)
	{
		int temp;
		cin >> temp;
		a.push_back(temp);
	}
	sort(a.begin(), a.end());
	
	for (int i = a.at(0); i < a.at(a.size() - 1); i++)
	{
		int hold = 0;
		for (int j = 0; j < a.size(); j++)
		{
			int temp = a.at(j);
			hold += ((temp - i)*(temp - i));
		}
		if (i == a.at(0))
			sum = hold;
		else
			if (hold < sum)
				sum = hold;
	}
	
	cout << sum << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
import sys
readline = sys.stdin.readline

while True:
    N = int(readline())
    if N == 0: break
    lo = 1
    hi = 2
    s = lo + hi
    cnt = 0
    while lo < N:
        if s < N:
            hi += 1
            s += hi
        elif s > N:
            s -= lo
            lo += 1
        else:
            cnt += 1
            hi += 1
            s += hi
    print(cnt)

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

int main() {
  int x,y;
  cin >> x >> y;
  vector<int>vec;
  vec = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(vec.at(x) == vec.at(y)){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);

int a[11];

bool ch(int n){
    bool ret=0;
    while(n){
        if(a[n%10])ret=1;
        n/=10;
    }
    return ret;
}

void solve(int T){
    int n,l;
    cin>>n>>l;
    for(int i=0;i<l;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    while(ch(n))n++;
    cout<<n<<"\n";
}
int main() {
    fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    int count=0;
    bool flag=0;
    while(n--)
    {
        int x,y; cin>>x>>y;
        if(x==y)
        {
            count++;
            if(count>=3)
            {
                flag=1;
                break;
            }
        }
        else
        {
            count=0;
        }
    }
    (flag)?cout<<"Yes":cout<<"No";
}
int main(){
    solve();
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#define rep(i,n) for(long long i=0;i<(long long)(n);++i)
typedef long long ll;
using namespace std;
int mod = 1000000007;
int dp[100010][13];


int main()
{
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  int n = s.size();
  int d = 1;
  
  //初期条件
  dp[0][0] = 1;
  rep(i,n){
    if(s[i] == '?'){
      rep(j,13){
        rep(k,10){
          dp[i+1][(j+k*d)%13] += dp[i][j];
          dp[i+1][(j+k*d)%13] %= mod;
        }
      }
    }else{
      int c = s[i] - '0';
      rep(j,13){
        dp[i+1][(j+c*d)%13] += dp[i][j];
        dp[i+1][(j+c*d)%13] %= mod;
      }
    }
    d *= 10;
    d %= 13;
  }
  cout << dp[n][5] << endl;  
  return 0;
}


Measured memory_bytes: 5568
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    char s[200100]; scanf("%s",s);;
    int start = 0;
    int end = 0;
    rep(i,strlen(s)){
        if(s[i]=='A'){
            start = i;
            break;
        }
    }
    for(int i=strlen(s)-1; i>=0; --i){
        if(s[i]=='Z'){
            end = i;
            break;
        }
    }
    pr(end-start+1);
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

ll h,w,k;
ll white, black;
vector<vector<char>> c(h, vector<char>(w));
ll ans = 0;
// vector<ll> a(N);
const int M = 2;
void dfs(vector<int> &A) {
    // 終端条件 --- 10 重ループまで回したら処理して打ち切り
    

    if(A.size() == h+w){
      // rep(i, A.size()) cout << A[i];
      // cout << " ";
      vector<vector<char>> tmp(h, vector<char>(w));
      rep(i, h){
        rep(j, w) tmp[i][j] = c[i][j];
      }
      ll cnt = black;
      for(ll i = 0; i < h; i++){
        if(A[i] == 1){
          // cout << i << " ";
          rep(j, w){
            if(tmp[i][j] == '#'){
              tmp[i][j] = 'r';
              cnt--;
            }
          }
        }
      }
      for(ll i = h; i < h+w; i++){
        if(A[i] == 1){
          // cout << i << " ";
          rep(j, h){
            if(tmp[j][i-h] == '#'){
              tmp[j][i-h] = 'r';
              cnt--;
            }
          }
        }
      }

      // cout << cnt << endl;
      if(cnt == k) ans++;
      
      return;
    }

    for (int v = 0; v < M; ++v) {
        A.push_back(v);
        dfs(A);
        A.pop_back(); // これが結構ポイント
    }
}

int main(){
  
  cin>>h>>w>>k;
  c.resize(h);
  rep(i, h) c[i].resize(w);
  
  rep(i, h){
    rep(j, w){
      // cout << i << " " << j << endl;
      cin >> c[i][j];
      if(c[i][j] == '.') white++;
      if(c[i][j] == '#') black++;
    } 
  }

  // cout << "black : " << black << endl;

  vector<int> A;
  dfs(A);
  
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3608
h,w,k=map(int,input().split())
c=[]
for _ in range(h):
  c.append(list(input()))
ans=0
for i in range(2**h):
  for j in range(2**w):
    q=0
    for i_ in range(h):
      for j_ in range(w):
        if ((i>>i_)&1) and ((j>>j_)&1) and c[i_][j_]=='#':
          q+=1
    if q==k:
      ans+=1
print(ans)    

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

int main(){
    int n;
    cin >> n;
    int k = n%10;
    if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) cout << "hon" << endl;
    else if( k == 3) cout << "bon" << endl;
    else cout << "pon" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	lli x;
	cin>>x;
	lli a=(x-1)/11,b=1+(x-1)%11;
	if(b<=6)cout<<2*a+1;
	else cout<<2*a+2;
}

Measured memory_bytes: 256
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

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

    int bigger = max(H, W);
    int smaller = min(H, W);
    int n = int(N / bigger);
    int amari = 0;
    if (N % bigger != 0) {
        amari = 1;
    }

    cout << n + amari << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
//提出するときC++に帰る
//--------------------------

int main() {

  ll K, N;
  cin >> K >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  vector<ll> B;
  rep(i, N-1) {
    B.push_back(A[i+1]-A[i]);
  }
  B.push_back(A[0]+(K-A[N-1]));

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

  ll ans = 0;
  rep(i, B.size()-1) {
    ans += B[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4084
#include <stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(a<b&&b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}



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

 int main(){
     long long  a,b,c,d;
     long long max;
    std:cin>>a>>b>>c>>d;
   long long m1=a*c;
   long long m2=a*d;
   long long m3=b*c;
   long long m4=b*d;
    if(m1>m2)
    max=m1;
    else max=m2;
    if(max<m3)
    max=m3;
    if(max<m4)
    max=m4;
   cout<<max<<"\n"<<endl;

 }

Measured memory_bytes: 3196
fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let mut a: Vec<i64> = sc.read_vec(n);
    for i in 0..n {
        a[i] -= (i + 1) as i64;
    }
    a.sort();

    let b = if a.len() % 2 == 1 {
        a[a.len() / 2] as f64
    } else {
        (a[a.len() / 2 - 1] as f64 + a[a.len() / 2] as f64) / 2.0
    };

    let mut sum = 0.0;
    for &a in &a {
        sum += (a as f64 - b).abs();
    }

    println!("{}", sum as i64);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 6396
#include <iostream>
using namespace std;
int main(){
  long n;
  string s;
  int arr[4]={0, 0, 0, 0};
  cin>>n;
  for(int i =0 ;i<n;i++){
    cin>>s;
    if(s == "AC")
      arr[0]++;
  	else if(s == "WA")
      arr[1]++;
    else if(s == "TLE")
      arr[2]++;
    else if(s == "RE")
      arr[3]++;
  }
  cout<<"AC x "<<arr[0]<<endl;
  cout<<"WA x "<<arr[1]<<endl;
  cout<<"TLE x "<<arr[2]<<endl;
  cout<<"RE x "<<arr[3]<<endl;
  return 0;
}

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

int max_n = 1e6 + 6;
vector<int> spf;

void sieve()
{
	spf.resize(max_n, 1);
	
	for(int num = 2; num < max_n; num++)
		spf[num] = num;

	for(int num = 2; num < max_n; num++)
	{
		if(spf[num] != num)
			continue;

		for(int mult = 2*num; mult < max_n; mult += num)
			spf[mult] = num;
	}
}

void solve()
{
	int n;
	cin >> n;

	vector<int> a(n);
	for(auto &ele : a)
		cin >> ele;

	vector<bool> present(max_n, false);
	bool first = true;

	for(int i = 0; i < n; i++)
	{
		int num = a[i];
		while(num != 1)
		{
			int pf = spf[num];
			if(present[pf] == true)
				first = false;
			
			present[pf] = true;
			while(num % pf == 0)
				num /= pf;
		}
	}
	
	int g = a[0];
	for(int i = 1; i < n; i++)
		g = __gcd(g, a[i]);

	if(first)
		cout << "pairwise coprime" << endl;
	else if(g == 1)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
}

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

	sieve();
	solve();
	return 0;
}


Measured memory_bytes: 11152
N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = 1 << 60
for i in range(1 << N):
    if i % 2 == 0:
        continue
    
    selected = [j for j in range(N) if i & (1 << j)]
    if len(selected) != K:
        continue
    
    h_max = a[0]
    cost = 0
    for j in range(1, N):
        if j in selected:
            if a[j] <= h_max:
                cost += h_max + 1 - a[j]
                h_max += 1
            else:
                h_max = a[j]
        else:
            h_max = max(h_max, a[j])
    
    ans = min(ans, cost)

print(ans)

Measured memory_bytes: 3188
a,b,c,d=map(int,input().split())

def gcd(x,y):
	if y==0:return x
	return gcd(y,x%y)

def lcb(a,b):
	return a*b//gcd(a,b)

max_num=lcb(c,d)
ans=(b-a+1)-((b//c)+(b//d)-(b//max_num))+(((a-1)//c)+((a-1)//d)-((a-1)//max_num))

print(ans)

Measured memory_bytes: 3064
n = STDIN.gets.to_i

activities = Array.new(n)

n.times do |i|
  activities[i] = STDIN.gets.split.map(&:to_i)
end

happiness = Array.new(n) { Array.new(3) }

happiness[0] = activities[0]

for i in 1...n do
  candidates = []
  # choose a
  happiness[i][0] = [activities[i][0] + happiness[i-1][1], activities[i][0] + happiness[i-1][2]].max
  # choose b
  happiness[i][1] = [activities[i][1] + happiness[i-1][0], activities[i][1] + happiness[i-1][2]].max
  # choose c
  happiness[i][2] = [activities[i][2] + happiness[i-1][0], activities[i][2] + happiness[i-1][1]].max
end

p happiness[-1].max


Measured memory_bytes: 16124
from queue import Queue

INF = 10 ** 5
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
d1 = [INF] * N
d2 = [INF] * N
d1[0] = 0
d2[N-1] = 0

q1 = Queue()
q1.put((0,0))

while not q1.empty():
    x, c = q1.get()
    for u in edges[x]:
        if d1[u] == INF:
            d1[u] = c + 1
            q1.put((u,c+1))

q2 = Queue()
q2.put((N-1,0))

while not q2.empty():
    x, c = q2.get()
    for u in edges[x]:
        if d2[u] == INF:
            d2[u] = c + 1
            q2.put((u,c+1))

black = 0
white = 0
for i in range(N):
    if d1[i] <= d2[i]:
        black += 1
    else:
        white += 1

if black <= white:
    print('Snuke')
else:
    print('Fennec')

Measured memory_bytes: 29928
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void init();
void last();

void init() {

}

const int MAX_M = 20;
const int MAX_N = 20010;
int C[MAX_M], x[MAX_N];
int dp[MAX_N][256];

void solve(int n, int m) {
    for (int i = 0; i < m; i++) {
        scanf("%d", C + i);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", x + i);
    }
    for (int i = 0; i < MAX_N; i++) {
        for (int j = 0; j < 256; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][128] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 256; j++) {
            if (dp[i][j] == INF) continue;
            for (int k = 0; k < m; k++) {
                int jj = max(min(j + C[k], 255), 0);
                chmin(dp[i + 1][jj], dp[i][j] + (int)pow(jj - x[i], 2));
            }
        }
    }
    printf("%d\n", *min_element(begin(dp[n]), end(dp[n])));
}

void last() {
    exit(0);
}

int main(void) {
	int a, b, c, x, y, z, n, m, p;
	string s;
	while (cin >> n >> m, n) {
		solve(n, m);
		//break;
	}
    last();
}

Measured memory_bytes: 23240
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<sstream>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<map>
#include<chrono>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
int n;

void compute(vector<ll> &vec) {
  ll denom = (ll)( (ll)n * (ll)(n+1)  ) / 2LL;
  ll sum = 0;
  rep(i,n) sum += vec[i];
  if( sum % denom ) { puts("NO"); return; }
  int k = sum / denom;
  rep(i,n) {
    ll diff = vec[(i+1)%n] - vec[i] - k;
    if( !( diff <= 0LL && diff % n == 0 ) ) { puts("NO"); return; }
  }
  puts("YES");
}

int main() {
  cin >> n;
  vector<ll> vec(n);
  rep(i,n) cin >> vec[i];
  compute(vec);
  return 0;
}


Measured memory_bytes: 1152
# INPUT
n = int(input())

# PROCESS
answer = "No"
flags = [0 for i in range(101)]
cake = 4
dunut = 7

if (n % 7 == 0):
  answer = "Yes"
else:
  for i in range(4, 101, 4):
    flags[i] = 1
    for j in range(i, 101, 7):
      flags[j] = 1
  if (flags[n] == 1):
    answer = "Yes"


# PROCESS
print(answer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam -1];
#define range(n) for(int i = 0; i < n; i++)
#define forn(x, n) for(int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
ll n;
vector<ll> divisores;

int main(){
    sc("%lld\n", &n);
    for(ll i = 1; i*i <= n; i++) {
        if (n%i == 0LL){
            divisores.pb(i);
            if (i*i != n){
                divisores.pb(n/i);
            }
        }
    }
    ll res = 0;
    sort(divisores.begin(), divisores.end());
    //trace(n);
    for(int i = 0; i < (int)divisores.size(); i++) {
        ll d = divisores[i];
        ll quo = n/d;
        if (d-1LL != 0LL && quo == n/(d-1LL)){
            res += d-1;
        }
    }
    pr("%lld\n", res);
 	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
const int BA = 1000;
const int INFTY = (1<<21);
typedef pair<int,string> p;
int main(){
  int up[3] = {-1,1,4};
  int under[3] = {-1,1,-4};
  map<string,bool> m;
  map<string,int> ans;
  string s = "01234567",hoge="";
  char c;
  queue<p> q;
  q.push(make_pair(0,s));
  while(!q.empty()){
    p a = q.front();q.pop();
    int b = a.second.find('0');
    m[a.second] = true;
    ans[a.second] = a.first;
    a.first++;
    string ss;
    for(int i=0;i<3;i++){
      ss = a.second;
      if(b < 4){
	if(!(b == 0 && i == 0) &&!(b == 3 && i == 1) ){
	  swap(ss[b],ss[b+up[i]]);
	  if(!m[ss]){
	    q.push(make_pair(a.first,ss));
	  }
	}
      }
      else{
	if(!(b == 4 && i == 0) && !(b == 7 && i == 1)){
	  swap(ss[b],ss[b+under[i]]);
	  if(!m[ss]){
	    q.push(make_pair(a.first,ss));
	  }
	}
      }
    }
  }
  while(1){
    cin >> c;
    if(cin.eof())break;
    hoge += c;
    for(int i=1;i<=7;i++){
      cin >> c;
      hoge += c;
    }
    cout << ans[hoge] << endl;
    hoge = "";
  }
  
  
}

Measured memory_bytes: 5708
#include <iostream>
#include <cctype>
#include <string>
#include <cstdio>
using namespace std;
int main () {

  string  ch;

  getline(cin,ch);


  for(int i=0;i <ch.size() ;i++){
    if( islower(ch[i]) ){
      printf("%c",toupper(ch[i]));
    }else if( isupper(ch[i]) ){
      printf("%c",tolower(ch[i]));
    }else {
      printf("%c",ch[i]);
    }

 
  }
  cout <<"\n";
return 0;
}

Measured memory_bytes: 1184
#include "bits/stdc++.h"
using namespace std;

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

	string ans = "-1";
	if (s.size() < 26) {

		vector<bool> vec(26, false);
		for (auto& ch : s) {
			vec[ch - 'a'] = true;
		}

		ans = s;
		for (int i = 0; i < 26; i++) {
			if (vec[i]) continue;
			ans += ('a' + i);
			break;
		}
	}
	else {
		for (int i = 25; i > 0; i--) {
			if (s[i] > s[i - 1]) {
				char ch = '~';
				for (int j = i - 1; j < 26; j++) {
					if (s[i - 1] < s[j]) ch = min(ch, s[j]);
				}
				ans = s.substr(0, i - 1) + ch;
				break;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i);


sum = 0

for i in 0..(a.length-1) do
	sum +=a[i]
end

ans =0
for i in 0..(a.length-2)
	sum = sum-a[i]
	ans += a[i]*sum
end

puts ans.modulo(1000000007)



Measured memory_bytes: 35776
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
const int SIZEN = 5010;
int N,K;
int p[SIZEN];
LL c[SIZEN];
int cir[SIZEN];
int loc[SIZEN];
int cnt = 0;
vector<int> v[SIZEN];
LL val[SIZEN];
void dfs(int x){
    if(cir[x])return;
    cir[x] = cnt;
    v[cnt].push_back(x);
    val[cnt] += c[x];
    loc[x] = v[cnt].size() - 1;
    dfs(p[x]);
}
int main(){
    scanf("%d%d",&N,&K);
    for(int i = 1;i <= N;i++)scanf("%d",&p[i]);
    for(int i = 1;i <= N;i++)scanf("%lld",&c[i]);
    for(int i = 1;i <= N;i++){
        if(cir[i])continue;
        ++cnt;
        dfs(i);
    }
    LL ans = -0x3f3f3f3f3f3f3f3fLL;
    LL k = K;
    for(int i = 1;i <= N;i++){
        K = k;
        int circle = cir[i];
        int sz = v[circle].size();
        LL tmp = 0;
        if(val[circle] <= 0)tmp = 0;
        else {
            LL n = K / sz;
            if(K % sz == 0)n--;
            tmp = val[circle] * n;
            K -= n * sz;
        }
        // printf("tmp = %lld\n",tmp);
        int lim = min(K,sz);
        LL ttmp = 0;
        for(int j = 1;j <= lim;j++){
            int now = (loc[i] + j) % sz;
            ttmp += c[v[circle][now]];
            ans = max(ans,ttmp + tmp);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3680