akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <math.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18+1;
const int N = 4e5+1;
const ll mod = 1e9+7;
const int bits = 19;


int main(){
    FASTIO;
    PRECISION;

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans+=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    ans-=min(c,k);
    cout<<ans<<"\n";
}

Measured memory_bytes: 3660
package main

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

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (n, a, b int) {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n = scanInt(sc)
	a = scanInt(sc)
	b = scanInt(sc)
	return
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

func resolve(n, a, b int) int {
	setLen := a + b
	setNum := n / setLen
	num := 0
	num += setNum * a
	lastLen := n - setNum*setLen
	if lastLen < a {
		num += lastLen
	} else {
		num += a
	}
	return num
}


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

xl = [a,b]
yl = [c,d]
for x in xl:
  for y in yl:
    xy = x*y
    if(x == a and y == c):
      xy_m = xy
	
    xy_m = max(xy_m,xy)

print(xy_m)

Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
typedef long long ll;
using namespace std;
int main()
{
	ll l, r;
	cin >> l >> r;
	int cnt = 0;
	while(l <= r){
		l = l*2;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,m,i;
    int l,r;
    cin>>n>>m;
    int pre[100005]={0};
    int cnt=0;
    for(i=0;i<m;i++)
    {cin>>l>>r;
    pre[l]++;
    pre[r+1]--;
    }
    for(i=1;i<=n;i++)
    {
        pre[i]+=pre[i-1];
    }
    //cout<<pre[9]<<e;
    for(i=1;i<=n;i++)
    {
        if(pre[i]==m)
            cnt++;
    }
    cout<<cnt<<e;
}


Measured memory_bytes: 640
// OURL: https://atcoder.jp/contests/abc165/tasks/abc165_f
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


vector<bool> used;
vector<int> dp;
vector<int> ans;
stack<pair<int, int>> st;
vector<vector<int>> tree;
vector<int> as;

void traverse(int t, int parent) {
  auto it = lower_bound(dp.begin(), dp.end(), as[t]);
  auto idx = it - dp.begin();
  auto bk = make_pair(idx, dp[idx]);
  dp[idx] = as[t];

  ans[t] = lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin();

  debug(t, ans[t]);
  for (auto i : tree[t]) {
    if (i != parent) {
      traverse(i, t);
    }
  }
  dp[bk.first] = bk.second;
}

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

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

  tree = make_v<int>(n, 0);
  for (int i = 0; i < n-1; ++i) {
    int u, v;
    cin >> u >> v;
    tree[u-1].push_back(v-1);
    tree[v-1].push_back(u-1);
  }
  debug(tree);

  used = make_v<bool>(n);
  dp = make_v<int>(n);
  fill_v(dp, INT_MAX);
  ans = make_v<int>(n);
  traverse(0, -1);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 27904
#include <stdio.h>

int main(void) {
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(r<=y && W>=(x+r) && r<=x && H>=(y+r)){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#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>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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





int main() {
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size()/2;i++){
        if(s.at(i)!=s.at(s.size()-1-i)){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char p[105];
main()
{
	int a,b,c=0;
	scanf("%d%d",&a,&b);
	for(int i = 0;i < a;i++)
	{
		scanf("%s",p);
		for(int j = 0;j < b;j++)
		{
			if(p[j]=='#')
			c++;
		}
	}
	if(c==a+b-1)
	printf("Possible");
	else
	printf("Impossible");
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << '\n';
    return 0;
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        while (true)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 0) return;
            var converter = new Dictionary<string, string>();
            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split();
                converter[input[0]] = input[1];
            }
            n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string data = Console.ReadLine();
                Console.Write(converter.ContainsKey(data) ? converter[data] : data);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9264
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 a, b, t;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &t);
  i32 ans = 0;
  while (t >= a) {
    t -= a;
    ans += b;
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}

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

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

    int h, w, n;
    cin >> h >> w >> n;

    cout << min((n + h - 1) / h, (n + w - 1) / w) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc136_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int A, B, C;
  cin >> A >> B >> C;

  int lim = A - B;
  int ans = C - lim;
  cout << (ans > 0 ? ans : 0) << endl;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(void){
    int s;
    cin >> s;
    if (s == 1 || s == 2 || s == 4) {
        cout << 4 << endl;  return 0;
    }
    
    for (int i = 1; i <= 1000000; i++) {
        if (s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
        if (s == 4) {
            cout << i + 4 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>


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


using namespace std;

using P = pair<int, int>;

struct SizeAwareUnionFind {
    vector<int> par, cnt;
    SizeAwareUnionFind(int N) : par(N), cnt(N) {
        rep(i, N) par[i] = i, cnt[i] = 1;
    }

    int find(int x) {
        return (par[x] == x) ? x : (par[x] = find(par[x]));
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return;
        if(cnt[x] < cnt[y]) swap(x, y);
        par[y] = x, cnt[x] += cnt[y];
    }

    int count(int x) {
        return cnt[find(x)];
    }   

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

int main() {
    int N, M, K; cin >> N >> M >> K;
    SizeAwareUnionFind uf(N);
    vector<int> fn(N);

    rep(i, M) {
        int a, b; cin >> a >> b;
        --a, --b;
        uf.unite(a, b);
        ++fn[a], ++fn[b];
    }

    while(K--) {
        int c, d; cin >> c >> d;
        --c; --d;
        if(uf.same(c, d)) ++fn[c], ++fn[d];
    }

    rep(i, N) {
        int t = uf.count(i);
        printf("%d ", t - 1 - fn[i]);
    }
    puts("");
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}



signed main()
{
	//IOS();
	int H,W;
	cin>>H>>W;
	string s[H];
	int a[H][W]={};
	rep(i,0,H){
		cin>>s[i];
		rep(j,0,W){
			if(s[i][j]=='#')a[i][j]=0;
			else a[i][j]=INF;
		}
	}
	rep(i,0,H){
		int cnt=INF;
		rep(j,0,W){
			if(a[i][j]==0&&cnt==INF)cnt=0;
			else if(a[i][j]!=INF&&cnt==INF)chmin(cnt,a[i][j]);
			else if(cnt!=INF){
				cnt++;
				chmin(a[i][j],cnt);
				chmin(cnt,a[i][j]);
			}
		}
	}
	rep(i,0,H){
		int cnt = INF;
		rrep(j,0,W){
			if(a[i][j]==0&&cnt==INF)cnt=0;
			else if(a[i][j]!=INF&&cnt==INF)chmin(cnt,a[i][j]);
			else if(cnt!=INF){
				cnt++;
				chmin(a[i][j],cnt);
				chmin(cnt,a[i][j]);
			}
		}
	}
	rep(j,0,W){
		int cnt = INF;
		rep(i,0,H){
			if(a[i][j]==0&&cnt==INF)cnt=0;
			else if(cnt==INF&&a[i][j]!=INF)chmin(cnt,a[i][j]);
			else if(cnt!=INF){
				cnt++;
				chmin(a[i][j],cnt);
				chmin(cnt,a[i][j]);
			}
		}
	}
	rep(j,0,W){
		int cnt = INF;
		rrep(i,0,H){
			if(a[i][j]==0&&cnt==INF)cnt=0;
			else if(a[i][j]!=INF&&cnt==INF)chmin(cnt,a[i][j]);
			else if(cnt!=INF){
				cnt++;
				chmin(a[i][j],cnt);
				chmin(cnt,a[i][j]);
			}
		}
	}
	int ans = 0;
	rep(i,0,H){
		rep(j,0,W){
			chmax(ans,a[i][j]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9088
n, m = map(int, input().split())
kosu = [1 for i in range(n)]
flag = [0 for i in range(n)]
flag[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    kosu[x] -= 1
    kosu[y] += 1
    if flag[x] == 1:
        flag[y] = 1
    if kosu[x] == 0:
        flag[x] = 0
print(sum(flag))

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		int ans = 0;
		for (int j = 0; j < m; j++) {
			if (a[j] == i || b[j] == i) {
				ans++;
			}
		}
		cout << ans << '\n';
	}
		
	
	return 0;
}


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

int main(){
  long long A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  if(W>=V){ cout << "NO"; return 0;}
  if(abs(A-B) <= (V-W)*T) cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

satisfy = 0
for i in range(n):
    satisfy += bn[an[i] - 1]

for i in range(n - 1):
    if an[i] + 1 == an[i + 1]:
        satisfy += cn[an[i] - 1]

print(satisfy)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int h,w;
  cin >> h >> w;
  vector<vector<int>> v(h,vector<int>(w));
  REP(i,h)REP(j,w)cin >> v[i][j];
  bool is = false;
  int count = 0;
  vector<tuple<int,int,int,int>> tu;
  REP(i,h){
    if(!(i & 1)){
      REP(j,w){
        if(is)get<2>(tu[tu.size()-1]) = i+1,get<3>(tu[tu.size()-1]) = j+1,is = false,v[i][j]++,count++;
        if(v[i][j] & 1){
          tu.push_back(make_tuple(i+1,j+1,0,0));
          is = true;
        }
      }
    }else{
      REPD(j,w){
        if(is)get<2>(tu[tu.size()-1]) = i+1,get<3>(tu[tu.size()-1]) = j+1,is = false,v[i][j]++,count++;
        if(v[i][j] & 1){
          tu.push_back(make_tuple(i+1,j+1,0,0));
          is = true;
        }
      }
    }
  }

  cout << count << endl;
  REP(i,count)cout << get<0>(tu[i]) << " " << get<1>(tu[i]) << " " << get<2>(tu[i]) << " " << get<3>(tu[i]) << endl;




  

  return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

ll n,ans;

void check(ll x,ll y){
	ll a=x,m=y-1;
	if (a<m) ans+=m;
}

int main(){
	cin>>n;
	for (ll i=1;i*i<=n;i++)
		if (n%i==0){
			check(i,n/i);
			if (i*i!=n) check(n/i,i);
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/*
读题不规范，爆零两行泪。
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int N=300,M=300;
int n,m,mod;
int comb[N+1][N+1];
int dp[N+1][M+2];
int Sum[N+1][M+2];
int main(){
	cin>>n>>m>>mod;
	comb[0][0]=1;
	for(int i=1;i<=n;i++)for(int j=0;j<=i;j++)comb[i][j]=((j?comb[i-1][j-1]:0)+(j<i?comb[i-1][j]:0))%mod;
	for(int i=1;i<=m+1;i++)Sum[0][i]=(Sum[0][i-1]+(dp[0][i]=1))%mod;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=1;k<=i;k++)(dp[i][j]+=1ll*dp[i-k][j]*comb[i-1][k-1]%mod*(Sum[k-1][m+1]-Sum[k-1][j])%mod)%=mod;
			Sum[i][j]=(Sum[i][j-1]+dp[i][j])%mod;
//			printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
		}
		Sum[i][m+1]=Sum[i][m];
	}
	cout<<(dp[n][1]+mod)%mod;
	return 0;
}

Measured memory_bytes: 4704
package main

import (
  "fmt"
)

func main() {
  var x,a,b,c,d int
  fmt.Scanf("%d", &x)
  d = x % 10
  x /= 10
  c = x % 10
  x /= 10
  b = x % 10
  x /= 10
  a = x % 10

  ans := createAnswer(a,b,c,d)
  fmt.Println(ans)
}

// a op1 b op2 c op3 d = 7 となる組み合わせを検索する
func createAnswer(a,b,c,d int) (ans string) {


  var op1,op2,op3 string
  for x := 0; x <= 1; x++ {
    for y := 0; y <= 1; y++ {
      for z := 0; z <= 1; z++ {
        verify := a

        if x == 0 {
          verify += b
          op1 = "+"
        } else {
          verify -= b
          op1 = "-"
        }

        if y == 0 {
          verify += c
          op2 = "+"
        } else {
          verify -= c
          op2 = "-"
        }

        if z == 0 {
          verify += d
          op3 = "+"
        } else {
          verify -= d
          op3 = "-"
        }

        if verify == 7 {
          ans = fmt.Sprintf("%v%v%v%v%v%v%v%v",a, op1, b , op2, c, op3, d, "=7")
          return ans
        }
      }
    }
  }

  return "there is no variation [a op1 b op2 c op3 d = 7"
}


Measured memory_bytes: 512
import sys
a,b,c,d = input()
a,b,c,d = int(a),int(b),int(c),int(d)
op=["-","+"]
for i in op:
  for j in op:
    for k in op:
      if i=="-":
        now=a-b
      else:
        now=a+b
      
      if j=="-":
        now=now-c
      else:
        now=now+c
      
      if k=="-":
        now=now-d
      else:
        now=now+d
      
      if now==7:
        print(str(a)+i+str(b)+j+str(c)+k+str(d)+"="+"7")
        sys.exit()
      else:
        now=0

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    ll L,R;cin>>L>>R;
    if(R-L>2019){
        cout<<0<<endl;
    }else{
        ll ans=2018;
        for(ll i=L;i<=R;i++){
            for(ll j=i+1;j<=R;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,n-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,n-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int d;
vector<int> c(26);
vector<vector<int>> s;
vector<int> t, now;
vector<int> last(26, -1);
ll best = 0;

ll score(){
    ll res = 0;
    rep(i,26)last[i] = -1;
    rep(i,d){
        res += s[i][now[i]];
        last[now[i]] = i;
        rep(j,26) res -= c[j] * (i - last[j]);
    }
    return res;
}

int main(){
    random_device seed;
    mt19937 mt(seed());
    uniform_int_distribution<int> rnd1(0,25);

    cin >> d;
    uniform_int_distribution<int> rnd2(0,d-1);
    rep(i,26) cin >> c[i];
    s.resize(d);
    rep(i,d)s[i].resize(26);
    rep(i,d)rep(j,26) cin >> s[i][j];
    t.resize(d);now.resize(d);
    rep(i,d){now[i] = i%26;t[i] = now[i];}
    best = score();
    ll now_s;
    rep(__,10){
        rep(i,d)now[i] = rnd1(mt);
        now_s = score();
        if(best < now_s){
            best = now_s;
            rep(j,d)t[j] = now[j];
        }        
        rep(_,500){
            // cout << best << endl;
            // rep(i,d)now[i] = rnd1(mt);
            int choice = rnd2(mt);
            rep(i,26){
                now[choice] = i;
                now_s = score();
                if(best < now_s){
                    best = now_s;
                    rep(j,d)t[j] = now[j];
                }
            }
        }
    }

    // cout << score() << endl;
    rep(i,d)cout << t[i]+1 << endl;

    return 0;
}

Measured memory_bytes: 3700
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,x,y = li()
xs = [x]
ys = [y]

xs = xs + list(li())
ys = ys + list(li())

print("No War") if max(xs) < min(ys) else print("War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long HCF(long long A,long long B)
{
    if(A==0) return B;
    return HCF(B%A,A);
}
int main()
{
  //  ifstream cin("input.in");
  //  ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long long N,K,X,Y,M=0;
    cin>>N>>K>>X;
    M=X;
    for(long i=1;i<N;i++)
    {
        cin>>Y;
        X=HCF(X,Y);
        M=max(M,Y);
    }
    if(K<=M && K%X==0)
        cout<<"POSSIBLE";
    else
        cout<<"IMPOSSIBLE";
    return 0;
}

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

const int INF = 1 << 30;
const int N = 2e4 + 10;
int m, n;
int dp[N];


int32_t main() {
  int m, n;
  cin >>  m >> n;
  fill(dp, dp + N, INF);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    int A, B;
    cin >> A >> B;
    for (int j = 0; j + A < N; ++j) {
      dp[j + A] = min(dp[j + A], dp[j] + B);
    }
  }
  int ret = INF;
  for (int i = m; i < N; ++i) {
    ret = min(ret, dp[i]);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int[] numArr = {
            Integer.parseInt(strArr[0]),
            Integer.parseInt(strArr[1]),
            Integer.parseInt(strArr[2])
        };
        int i, j, temp;
        for (i = 0; i < 2; i++) {
            for (j = 0; j < 2 - i; j++) {
                if (numArr[j] > numArr[j+1]) {
                    temp = numArr[j];
                    numArr[j] = numArr[j+1];
                    numArr[j+1] = temp;
                }
            }
        }
        System.out.println(numArr[0]+" "+numArr[1]+" "+numArr[2]);
    }
}

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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 1000000007;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

map<int, int> m;
int n;

bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

void check(int x)
{
       if(isPrime(x) && m.count(x)==0)
       {
              int temp=n;
              while(temp%x==0)
              {
                     m[x]++;
                     temp/=x;
              }
       }
}

void solve()
{
       int ans=0;
       cin>>n;
       for(int c=1;c<=sqrt(n);c++)
       {
              if(n%c==0)
              {
                     check(c);
                     check(n/c);
              }
       }
       for(auto x:m)
       {
              ans+=floor((sqrt(1+8*(x.se))-1)/2);
       }
       cout<<ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
//#include <tuple>
//#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const ll MOD = 1e9 + 7;

int main(){
	int n, t;
	cin >> n >> t;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	sort(ALL(v));

	ll ans = 1;
	rep(i, v.size()){
		int x = v[i] - t;
		int cnt = i + 1 - (lower_bound(v.begin(), v.begin() + i, x) - v.begin());
		ans = (ans * cnt) % MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1524
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        string tmp = to_string(i);
        if (tmp.length() % 2 == 1) ans++;
    }
    print(ans);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353

vi dp;

ll fun(ll i){
  if(i==0)return 1;

  if(dp[i]!=-1)return dp[i];
  ll res = 0;

  for(int j=3;j<=2000;j++)
  if(j>i)break;
  else res=(res+fun(i-j))%mod;

  return dp[i]=res;
}

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif  
 
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      ll n;
      cin>>n;
      dp.resize(n+1,-1);

      cout<<fun(n);





    }
     
      

      

    

    
return 0;
}     



Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long X;
    // X は正の整数
    cin >> X;

    //A, Bの組で作れる値は限られている
    const int max_num = 200;
    vector<ll> elem(max_num);
    for(size_t i=0;i<=max_num; i++)
    {
        elem[i] = pow(i, 5);
    }
    //Aループ+
    for(int i=0;i<=max_num; i++)
    {
        //Bループ+
        for(int j=0;j<=max_num; j++)
        {
            if(elem[i] - elem[j] == X)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
        //Bループ-
        for(int j=0;j<=max_num; j++)
        {
            if(elem[i] + elem[j] == X)
            {
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
    //Aループ-
    for(int i=0;i<=max_num; i++)
    {
        //Bループ+
        for(int j=0;j<=max_num; j++)
        {
            if(-elem[i] - elem[j] == X)
            {
                cout << -i << " " << j << endl;
                return 0;
            }
        }
        //Bループ-
        for(int j=0;j<=max_num; j++)
        {
            if(-elem[i] + elem[j] == X)
            {
                cout << -i << " " << -j << endl;
                return 0;
            }
        }
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 4056
int main(){
  int a, c;

  for(int i = 0; ; i++){
    scanf("%d %d", &a, &c);
    if(a==0 && c==0)break;
    if(a>c)printf("%d %d\n", c, a);
    else printf("%d %d\n", a, c);

  }
  return 0;
}


Measured memory_bytes: 1944
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long LL;

const LL maxn = 200009;
const long double r = acos(-1) * 5;
LL x[maxn], y[maxn], X[maxn], rk[maxn], c[maxn], f[maxn];
LL sx, sy, tx, ty, n, N, cnt, flag, ans, p;

LL search(LL k){
	LL l = 1, r = cnt, mid;
	while (l < r){
		mid = (l + r) >> 1;
		if (k <= X[mid]) r = mid;
		else l = mid + 1;
	}
	return l;
}

bool cmp(LL a, LL b){
	return y[a] < y[b];
}

void update(LL x, LL y){
	for (; x<=cnt; x+=lowbit(x)) c[x] = max(c[x], y);
}

LL query(LL x){
	LL res = 0;
	for (; x; x-=lowbit(x)) res = max(res, c[x]);
	return res;
}

signed main(){
	scanf("%lld%lld%lld%lld%lld", &sx, &sy, &tx, &ty, &n);
	if (sx <= tx && sy > ty){
		flag = 1; 
		sy = 1e8 - sy; ty = 1e8 - ty;
	}
	else if (sx > tx && sy > ty){
		flag = 2; 
		sx = 1e8 - sx; sy = 1e8 - sy;
		tx = 1e8 - tx; ty = 1e8 - ty;
	}
	else if (sx > tx && sy <= ty){
		flag = 3; 
		sx = 1e8 - sx; tx = 1e8 - tx;
	}
	for (LL i=1; i<=n; i++){ N++;
		scanf("%lld%lld", &x[N], &y[N]);
		if (flag == 1) y[N] = 1e8 - y[N];
		else if (flag == 2) { x[N] = 1e8 - x[N]; y[N] = 1e8 - y[N]; }
		else if (flag == 3) x[N] = 1e8 - x[N];
		if (x[N] < sx || x[N] > tx || y[N] < sy || y[N]  > ty){
			N--; continue;
		}
		X[++cnt] = x[N]; rk[N] = N;
	}
	if (sx == tx || sy == ty || !N){
		if (N) printf("%.16Lf\n", 100.0*(tx-sx + ty-sy) - 20 + 2*r);
		else printf("%.16lf\n", 100.0*(tx-sx + ty-sy));
		return 0;
	}
	sort(X+1, X+cnt+1); sort(rk+1, rk+N+1, cmp);
	
	for (LL i=1; i<=N; i++){
		f[i] = query(search(x[rk[i]])) + 1;
		ans = max(ans, f[i]);
		update(search(x[rk[i]]), f[i]);
	}
	if (ans == tx-sx+1 || ans == ty-sy+1) printf("%.16Lf\n", 100.0*(tx-sx + ty-sy) + ans*(r-20) + r);
	else printf("%.16Lf\n", 100.0*(tx-sx + ty-sy) + ans*(r-20));
	
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
//#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
//#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
//#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
//template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
//template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
//
//using Graph = vector<vector<int>>;
//using P = pair<int, int>;
//using Tuple = tuple<int, int, int>;

//ll dp[200005][2][3];

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<vector<ll>> dp(n, vector<ll>(2, -1LL<<60));
    dp[0][0] = 0;
    dp[0][1] = a[0];
    dp[1][0] = max(a[0], a[1]);
    dp[1][1] = max(a[0], a[1]);

    for(int i=2; i<n; i++) {
        // iを選んで, i/2の状態
        dp[i][0] = max(dp[i][0], dp[i-2][0] + a[i]);
        // iをえらばず, i/2の状態
        dp[i][0] = max(dp[i][0], dp[i-1][1]);

        if(i%2==0) {
            // iを選んで, (i+1)/2個選ばれてる状態
            dp[i][1] = max(dp[i][1], dp[i-2][1] + a[i]);
        } else {
            // iを選んで, (i+1)/2個選ばれてる状態(偶数個の場合はi/2の状態と同じ)
            dp[i][1] = max(dp[i][1], dp[i][0]);
        }
        // iを選ばず, (i+1)/2個選ばれてる状態(ありえないはず)
//        cout << dp[i][0] << endl;
//        cout << dp[i][1] << endl;
    }

    if(n%2==0) {
        cout << dp[n-1][0] << endl;
    } else {
        cout << dp[n-1][0] << endl;
    }

    return 0;
}

Measured memory_bytes: 15664
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int M = Integer.parseInt(S[1]);
    int ans = 1;
    int now = 0;
    String[] T = sc.nextLine().split(" ");
    for(int i = 0; i < N && now < M; i++){
      int n = Integer.parseInt(T[i]);
      now += n;
      if(now <= M){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

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

#define ll long long

int main() {
	ll n;	cin >> n;
	bool ok = 0;
	while (n > 0) {
		ll x = n % 10;
		if (x == 7)	ok = 1;
		n /= 10;
	}
	if (ok)	cout << "Yes\n";
	else	cout << "No\n";

}


Measured memory_bytes: 3632
num2alpha = lambda c: chr(c+64)
alpha2num = lambda c: ord(c) - ord('A') + 1
N = int(input())
S = input()
s_list = list(S)
ANS = ''
if N >= 27:
    kazu = int(N/26)
    hiku = int(kazu * 26)
    N = (N - hiku)
for i in s_list:
    AA = (N + alpha2num(i))
    if AA >= 27:
        AA = AA - 26
    ANS += num2alpha(AA)
print(ANS)

Measured memory_bytes: 3064
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

c = input()
color_list = list(map(int, list(c)))

N= len(color_list)

f0_num = 0
filter_0 = [i % 2 for i in range(N)]
f1_num = 0
filter_1 = [i % 2 for i in range(1, N + 1)]

for c, f0, f1 in zip(color_list, filter_0, filter_1):
    if c != f0:
        f0_num += 1
    if c != f1:
        f1_num += 1

print(min(f0_num, f1_num))



Measured memory_bytes: 14980
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<lint, lint> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    lint n,m; cin>>n>>m;
    vector<P > p(n);
    REP(i,n) cin>>p[i].first>>p[i].second;
    sort(all(p));
    lint ans = 0;
    REP(i,n){
        if(p[i].second<=m){
            ans+=p[i].first*p[i].second;
            m-=p[i].second;
        } else {
            ans+=p[i].first*m;
            m=0;
        }
        if(m==0) break; 
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

aa = [0]
a = aa + a
a.append(0)

sub = 0
for i in range(n + 1):
    sub += abs(a[i + 1] - a[i])

for i in range(1, n + 1):
    print(sub - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i + 1] - a[i - 1]))


Measured memory_bytes: 14040
#include <bits/stdc++.h>
#ifndef DBG
#define dbg(...)
#else
#define dbg(...) {cerr << "\033[1;96m"; ostream& cout = cerr; \
(void)(cout); __VA_ARGS__; cerr << "\033[0m";} 
#endif
#define ddmp(...) dbg(dmp(__VA_ARGS__))
#define prt(...) print(cout, __VA_ARGS__)
#define dprt(...) dbg(print(cerr, __VA_ARGS__))
#define dmp(...) print(cerr, #__VA_ARGS__, '=', __VA_ARGS__)
#define all(...) begin(__VA_ARGS__), end(__VA_ARGS__)
#define whr() __LINE__,  __PRETTY_FUNCTION__
using namespace std; using ll = long long;
template< typename... t > using V = vector< t... >;
template< typename t > void print(ostream& os, const t& a)
{os << a <<  '\n';} template< typename t, typename... v >
void print(ostream& os, const t& a, v&&... b){os << a << ' '; print(os, b...);}


int foo(int v)
{
    int s = 0;
    while (v > 0)
        s += v % 10, v /= 10;
    return s;
}

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

    int n; cin >> n;

    prt(n % foo(n)? "No" : "Yes");
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
m1 = sum(a) // n
m2 = (sum(a) + n - 1) // n

res1 = 0
res2 = 0
for i in range(n):
    res1 += (a[i] - m1) ** 2
    res2 += (a[i] - m2) ** 2

print(min(res1, res2))


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int n = sc.nextInt();
    		int m = sc.nextInt();
    		int p = sc.nextInt();
    		if(n==0 && m==0 && p==0) break;
    		int uma[] = new int[n+1];
    		int sum = 0;
    		for(int i=1;i<=n;i++) {
    			uma[i] = sc.nextInt();
    			sum += 100*uma[i];
    		}
    		//System.err.println(sum);
    		
    		double d = sum*(100-p)/100;
    		//System.err.println(d);
    		
    		if(uma[m]==0) {
    			System.out.println("0");
    		}else {
    			System.out.printf("%d",(int)(d/uma[m]));
    			System.out.println();
    		}
    	}
    }
}



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

using namespace std;

using ll = long long;

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

    int a, b;

    cin >> a >> b;
    cout << (max(a, b) <= 8 ? "Yay!" : ":(") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <climits>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

double dp[3000][3000];
double p[3001];
int n;

double solve() {

	for (int i = n - 1; i >= 0; --i) {
		for (int j = 1; j <= n + 1; ++j) {
			dp[i][j] = p[i] * dp[i + 1][j - 1] + (1 - p[i]) * dp[i + 1][j];
		}
	}
	double ans = 0;
	for (int y = (n + 1) / 2 + 1; y <= n + 1; ++y) {
		ans += dp[0][y];;
	}
	return ans;
}

int main() {

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < 3000; ++i) {
		for (int j = 0; j < 3000; ++j) {
			dp[i][j] = 0;
		}
	}
	dp[n][1] = 1;
	cout << setprecision(12) << solve();

	return 0;
}


Measured memory_bytes: 70528
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int A[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), K = getint();
	rep(i, N) A[i] = getint() - 1;

	int L = 0, R = 1000000000;
	while (L + 1 < R) {
		int H = (L + R) / 2;
		ll k = 0;
		rep(i, N) k += A[i] / H;
		if (k <= K) R = H;
		else L = H;
	}
	printf("%d\n", R);


	Would you please return 0;
}

Measured memory_bytes: 2484
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter:Vec<&str> = buf.split_whitespace().collect();
	let mut s:Vec<String> = Vec::new();
	for i in 0..3 {
		s.push(iter[i].to_string());
	}
	s.sort();
	let x = s[2].parse::<i32>().ok().unwrap() * 10 + s[1].parse::<i32>().ok().unwrap();
	let y = s[0].parse::<i32>().ok().unwrap();
	println!("{}", x+y);
}

Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc= new Scanner(System.in);
		
		int n=sc.nextInt();
		int m=sc.nextInt();
		
		
		ArrayList<Integer> list=new ArrayList<>();
		
		for(int i=0;i<n;i++) {
			int c=sc.nextInt();
			list.add(c);
		}
		int c=0,total=0;
		for(int i=0;i<n;i++) {
	
			total=total+list.get(i);
		}

		
		double limit=(double)1/(4*m)*(double)total;
		for(int i=0;i<n;i++) {
			if(list.get(i)>=limit) {
				
		//	System.out.println(limit);
				c++;
				
			}
			
		}
		if(c>=m) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
		
	}
}


Measured memory_bytes: 21844
N, K = list(map(int,input().split()))
C = []
for _ in range(K):
  d = int(input())
  A = list(map(int,input().split()))
  for i in range(len(A)):
    C.append(A[i])
NC = []
for a in range(1,N+1):
  if a <= N and a not in C:
    NC.append(a)
print(len(NC))

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;
const int MAX_V=10000;

int main(){
	int a,b,c;
	int x,y;
	cin>>a>>b>>c;
	cin>>x>>y;
	int res=0;
	if(a+b>2*c){
		int cntc=min(x,y);
		res+=2*c*cntc;
		x-=cntc;
		y-=cntc;
		res+=min(a*x+b*y,2*c*max(x,y));
	}else{
		res=min(a*x+b*y,2*c*max(x,y));
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=list(map(int,input()))
if int("".join(map(str,n)))%sum(n)==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3668
fun main(args: Array<String>) {
    val (w, h, x, y) = readLine()!!.split(' ').map(String::toLong)
    val multi = if (w == x * 2 && h == y * 2) 1 else 0
    println("${(w * h).toDouble() / 2.0} $multi")
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n,h,W; cin >> n >> W >> h;
	vector<int> x(n),y(n),w(n);
	for(int i = 0; i < n ;i++){
		cin >> x[i] >> y[i] >> w[i];
	}
	vector<int> r(2*W+2), c(2*h+2);
	for(int i = 0; i < n; i++){
		int l = 2*(x[i]-w[i]);
		int R = 2*(x[i]+w[i])+1;
		if(l < 0)l = 0;
		if(R > 2*W+1)R = 2*W+1;
		int u = 2*(y[i]-w[i]);
		int d = 2*(y[i]+w[i])+1;
		if(u < 0)u = 0;
		if(d > 2*h+1)d = 2*h+1;
		r[l]+=1; r[R]-=1;
		c[u]+=1; c[d]-=1;
	}
	for(size_t i = 1; i < r.size(); i++){
		r[i] += r[i-1];
	}
	for(size_t i = 1; i < c.size(); i++){
		c[i] += c[i-1];
	}
	bool flag = true;
	for(size_t i = 0; i < r.size()-1; i++){
		if(r[i] == 0){
			flag = false;
			break;
		}
	}
	bool flag1 = true;
	for(size_t i = 0; i < c.size()-1; i++){
		if(c[i] == 0){
			flag1 = false;
			break;
		}
	}
	if(flag || flag1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}



	return 0;
}




Measured memory_bytes: 5488