akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;


int main() {
    int N;
    cin >> N;
    vector<int>vec(N);
    for (int i=0; i < N; i++) {
        cin >> vec.at(i);
    }

    int tmp = 0;
    int count = 0;
    bool can = true;
    for (int i=0; i < N; i++) {
        int n = i + 1;
        if (n != vec[i]) {
            tmp = vec[i];
            count += 1;
            if (vec[tmp-1] != n) {
                can = false;
            }
        }
    }

    if (can && count < 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

int main() {
  int n;cin>>n;
  long an[n];rep(i,n) cin>>an[i];
  long long s=0;rep(i,n) s+=an[i];
  long long sn[n];
  sn[0]=an[0];
  rep(i,n-1) sn[i+1] = sn[i] + an[i+1];
  rep(i,n) sn[i] = abs(s-2*sn[i]);
  long long amin = *min_element(sn, sn+n-1);
  cout << amin;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define lp(i, a, b) for (int i=a;i<=(int)b;++i)
#define lp2(i, a, b) for (ll i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define vll vector<pll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define clr(c, x) memset(c,x,sizeof(c));
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int N = (int) 1e5 + 5, INF = 0x3f3f3f3f, ALPHA = 26;
const ll mod = 998244353;
deque<int> ans;
ll fans = 0;

inline void solve(bool q) {
    while (ans.size() > 1) {
        int a1 = ans.front();
        ans.pop_front();
        int a2 = ans.front();
        ans.pop_front();
        int d = a1 + a2;
        if (d >= 10) {
            ans.pf(d % 10);
            ans.pf(d / 10);
        } else
            ans.pf(d);
        ++fans;
    }
}

int main() {
#ifdef ONLINE_JUDGE
    FAST;
#endif
    int n;
    cin >> n;
    while (n--) {
        int d;
        ll c;
        cin >> d >> c;
        while (c) {
            if (c % 2) ans.pf(d);
            c /= 2;
            d *= 2;
            ll steps = 1;
            if (d >= 10) {
                steps++;
                int a1 = d % 10;
                int a2 = d / 10;
                d = a1 + a2;
            }
            fans += (c * steps);
        }
    }
    solve(0);
    cout << fans << "\n";
    return 0;
}

Measured memory_bytes: 13588
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
#include <list>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string x;
	cin >> x;
	list<char> ls;
	trav(c, x) ls.push_back(c);
	for(auto it = ls.begin(); it != ls.end();){
		if(*it == 'T'){
			++it;
			continue;
		}
		auto nx = it;
		++nx;
		if(nx == ls.end() || *nx == 'S'){
			it = nx;
			continue;
		}
		ls.erase(nx);
		if(it == ls.begin()){
			ls.erase(it);
			it = ls.begin();
		} else {
			nx = it;
			it--;
			ls.erase(nx);
		}
	}
	cout << sz(ls) << endl;
}

Measured memory_bytes: 6676
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int calc(char **A,char N,char *c){
	for(int i=0;i<N;i++){
		if(strcmp(A[i],c)==0){
			return i;
		}
	}
	return -1;
}

int main(){
	int N,M;
	char **A,**B;
	char a[2];
	int r;

	while(scanf("%d",&N)){
		if(N==0){break;}
		A=(char**)malloc(sizeof(char*)*N);
		B=(char**)malloc(sizeof(char*)*N);
		
		for(int i=0;i<N;i++){
			A[i]=(char*)malloc(sizeof(char)*2);
			B[i]=(char*)malloc(sizeof(char)*2);
			scanf("%s %s",A[i],B[i]);
		}

		scanf("%d",&M);
		for(int i=0;i<M;i++){
			scanf("%s",a);
			r=calc(A,N,a);
			if(r==-1){
				printf("%s",a);
			}else{
				printf("%s",B[r]);
			}
		}printf("\n");

		for(int i=0;i<N;i++){
			free(A[i]);
			free(B[i]);
		}
		free(A);
		free(B);
	}

	return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

const string keyence = "keyence";

signed main() {
    string S;
    cin >> S;

    int len = S.size() - 7;
    if (len == 0) {
        cout << (S == keyence ? "YES" : "NO") << endl;
    } else {
        string S1 = "";
        string S2 = S.substr(S.size() - 7);
        rep(i, S.size() - len) {
            cerr << S1 << " - " << S2 << endl;
            if (S1 + S2 == keyence) {
                cout << "YES" << endl;
                return 0;
            }
            S1 += S[i];
            S2 = S2.substr(1);
        }
        cerr << S1 << " - " << S2 << endl;
        if (S1 + S2 == keyence) {
            cout << "YES" << endl;
            return 0;
        }
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
typedef char Bool;
#define true 39
#define false 0 
typedef long long int64;
typedef unsigned long long uint64;
typedef int int32;
typedef unsigned int uint32;
typedef unsigned char byte;
#include <stdio.h>

int main()
{
	int x;
	scanf("%d", &x);
	printf("%d", (x) ? 0 : 1);
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner itr = new Scanner(System.in);
        int N = itr.nextInt();
        int W = itr.nextInt();

        int[] weight = new int[N];
        int[] value = new int[N];

        for (int i = 0; i < N; i++) {
            weight[i] = itr.nextInt();
            value[i] = itr.nextInt();
        }

        long[][] dp = new long[N][W + 1];
        for (int i = weight[0]; i <= W; i++) {
            dp[0][i] = (long) value[0];
        }

        for (int i = 1; i < N; i++) {
            for (int j = 0; j <= W; j++) {
                if (j > weight[i])
                    dp[i][j] = Math.max(dp[i - 1][j], (long)value[i] + dp[i - 1][j - weight[i]]);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }

        System.out.println(dp[N - 1][W]);
    }
}

Measured memory_bytes: 126036
def introduce_rest(no_city_points):
    for no, _, _ in sorted(no_city_points, key=lambda x: (x[1], -x[2])):
        print(no)


def main():
    n = int(input())
    input_ = []
    for i in range(1, n+1):
        city, p = input().split()
        input_.append((i, city, int(p)))
    introduce_rest(input_)
    
main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> x(n, 0);
  for(ll i = 0; i < n; i++){
    cin >> a[i];
    a[i]--;
    x[a[i]]++;
  }
  ll conv = 0;
  for(ll i = 0; i < n; i++){
    if(x[i] >= 2){
      conv += x[i] * (x[i] - 1) / 2;
    }
  }
  ll diff;
  for(ll i = 0; i < n; i++){
    if(x[a[i]] < 2){
      cout << conv << endl;
    }
    else{
      diff = x[a[i]] - 1;
      cout << conv-diff << endl;
    }
  }
  
  return 0;
}

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


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

    int n = s.size();

    rep(i, n){
        if(s[i] != t[i]){
            cout << "No" << endl; 
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define MAXN 155
using namespace std;

long long s;

int main()
{
	scanf("%lld",&s);
	long long p=sqrt(s),x1,x2,x3,y1,y2,y3;
	if (p*p==s)
	{
		printf("0 0 0 %lld %lld 0\n",p,p);
		return 0;
	}
	if (p*p<s) ++p;
	x1=0;y1=0;
	x2=p;y2=1;
	y3=x2;x3=x2*y3-s;
	if (x3>1000000000)
	{
		y2=1;y3=x2-1;x3=x2*y3-s;
	}
	printf("%lld %lld %lld %lld %lld %lld\n", x1,y1,x2,y2,x3,y3);
	return 0;
}

Measured memory_bytes: 256
/* Filename: AGC006A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			int N = input.nextInt();
			String s = input.next();
			String t = input.next();
			StringBuilder ans = new StringBuilder(s);
			
			
			for(int i = 0; i < s.length(); ++i){
				boolean isAllMatch = true;
				int j = 0;
				
				for( ; j < t.length() && i + j < s.length(); ++j){
					if(s.charAt(i + j) != t.charAt(j)){
						isAllMatch = false;
						break;
					}
				}
				
				if(isAllMatch){
					ans.append(t.substring(j));
					break;
				}
			}
			
			if(ans.indexOf(t) == -1){
				ans.append(t);
			}
			
			System.out.println(ans.length());
		}
	}

}


Measured memory_bytes: 9044
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int n,m,x, b=0,c=0;
    cin>>n>>m>>x;
    int a[n+5];
    for (int i=0; i<m; i++) cin>>a[i];
    for (int i=0; i<m; i++)
    {
        if (a[i]<x) b++;
        else c++;
    }
    cout<<min(b,c);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[2]!=s[3] || s[4]!=s[5]){cout<<"No";return 0;}
	if(s[0]==s[1]){cout<<"No";return 0;}
	if(s[2]==s[0]){cout<<"No";return 0;}
	if(s[2]==s[1]){cout<<"No";return 0;}
	if(s[0]==s[4]){cout<<"No";return 0;}
	if(s[1]==s[5]){cout<<"No";return 0;}
	cout<<"Yes";return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef pair<double, int> P;
typedef pair<int, int> PI;
typedef pair<double, PI> S;

double calc(P p, P q){
  double x = p.first - q.first;
  double y = p.second - q.second;
  return sqrt(x * x + y * y);
}

int main(){
  int N;
  while(cin >> N && N){
    int x[100], y[100];
    REP(i, N) cin >> x[i] >> y[i];

    vector<int> hv;
    REP(i, N) hv.push_back(y[i]);
    sort(hv.begin(), hv.end());
    hv.erase(unique(hv.begin(), hv.end()), hv.end());

    vector<P> ps;
    REP(i, N) ps.push_back(P(x[i], y[i]));
    REP(i, N - 1){
      if(y[i] == y[i + 1]) continue;
      int l = min(y[i], y[i + 1]);
      int r = max(y[i], y[i + 1]);
      REP(j, hv.size()){
        int h = hv[j];
        if(l < h && h < r){
          double px = x[i] + double(h - y[i])/(y[i + 1] - y[i]) * (x[i + 1] - x[i]);
          ps.push_back(P(px, h));
        }
      }
    }
    sort(ps.begin(), ps.end());

    priority_queue<S, vector<S>, greater<S> > que;
    map<PI, double> dist;
    dist[PI(0, ps.size() - 1)] = 0;
    que.push(S(0, PI(0, ps.size() - 1)));

    while(!que.empty()){
      S s = que.top(); que.pop();
      int a = s.second.first, b = s.second.second;
      double c = s.first;

      if(dist[PI(a, b)] < c) continue;

      if(a == b){
        printf("%.12f\n", c);
        break;
      }

      for(int da = -1; da <= 1; da++){
        for(int db = -1; db <= 1; db++){
          int na = a + da;
          int nb = b + db;
          PI np(na, nb);
          if(!valid(na, nb, ps.size(), ps.size())) continue;
          if(ps[na].second != ps[nb].second) continue;

          double nc = c;
          nc += calc(ps[a], ps[na]);
          nc += calc(ps[b], ps[nb]);
          if(!dist.count(np) || dist[np] > nc) {
            dist[np] = nc;
            que.push(S(nc, np));
          }
        }
      }
    }
  }
  return 0;
}

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

int n,tmp,bil;

int main(){
    scanf("%d",&n);
    tmp=n; bil=0;
    while(tmp>0){
        bil+=tmp%10;
        tmp/=10;
    }
    if(n%bil==0){printf("Yes\n");}
    else{printf("No\n");}
}


Measured memory_bytes: 256
n,p = map(int,input().split())
if n == 1:
    print(p)
    exit()
if n >=40 or p==1:
    print(1)
    exit()
i =2
ans =1
while i**n <= p:
    if p%(i**n)==0:
        ans *= i
        p =p//(i**n)
 
    elif i==2:
      i+=1
    else:
      i+=2
print(ans)

Measured memory_bytes: 3064
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let mut s: Vec<char> = read::<String>().chars().collect();
    let n = s.len();
    let ans = vec!['x'; n];
    let s: String = ans.into_iter().collect();
    println!("{}", s);
}


Measured memory_bytes: 4352
S = list(input())
S_r = S[::-1]
N = len(S)
if S[:(N - 1)//2] == S_r[:(N - 1)//2]:
    T = S[:(N - 1)//2]
    T_r = T[::-1]
    if T == T_r:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int main(){
    int x, n;
    cin >> x >> n;
    vector<int> d(102);
    rep(i,n) {
        int p;
        cin >> p;
        d[p] = 1;
    }
    P ans(99999, -1);
    for(int i = 0; i <= 101; i++){
        if(d[i] == 1) continue;
        int dif = abs(x - i);
        ans = min(ans, P(dif,i));
    }
    cout << ans.second << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(0),cin.tie(0);
int main(void)
{
	AC;
	int T,a,n,i,err=0;
	int x[100054]={0};
	string s;
	cin>>s;
	for(i=0;i<s.length();i++) x[s[i]]++;
	for(i='a';i<='z';i++)
		if(x[i]==0){
			cout<<(char)i<<"\n";
			err++;
			break;
		}
	
	if(!err) cout<<"None\n";
}



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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
int a[2][100];

int main(){
    cin >> n;
    rep(i,2) rep(j,n) cin >> a[i][j];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            if (i > 0 && j > 0) a[i][j] = a[i][j]+max(a[i-1][j],a[i][j-1]);
            else if (i > 0) a[i][j] = a[i][j]+a[i-1][j];
            else if (j > 0) a[i][j] = a[i][j]+a[i][j-1];
        }
    }
    cout << a[1][n-1] << endl;
}






Measured memory_bytes: 256
/*input
3
131
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

string s;

vector<int> v;

int main(){
	IOS;
	int n;
	cin>>n>>s;

	{
		bool tmp=1;
		REP(i,n) if(s[i]=='2') tmp=0;

		if(tmp){
			REP(i,n-1){
				if(s[i]==s[i+1]) v.pb(0);
				else v.pb(1);
			}
			int res = 0;
			for(int i=0;i<n-1;i++){
				if((i&(n-2))==i){
					res^=v[i];
				}
			}
			cout<<res*2<<'\n';
			return 0;
		}
	}
	int res=0;
	REP(i,n){
		if((i&(n-1))==i){
			res^=((s[i]-'0')%2);
		}
	}
	cout<<res<<'\n';
	return 0;
}


Measured memory_bytes: 7832
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<(n);i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<iostream>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>
using namespace std;
typedef long long ll;

ll solve(ll n){
        if(n%2==0){
            if(n%4==0) return 0^n;
            else return 1^n;
        }
        else{
            if((n-1)%4==0) {
                ll a=(n-1)^n;
                return 0^a;
            }
            else{
                ll b=(n-1)^n;
                return 1^b;
            }
        }
    }

int main(void){
    ll a, b;
    cin>>a>>b;
    
    ll ans=solve(b)^solve(a-1);
    cout<<ans<<endl;
}

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

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for(auto &x : a){
        cin >> x;
    }
    for(auto &x : b){
        cin >> x;
    }
    vector<pair<ll, int>> ok, nk;
    for(int i = 0; i < n; i++){
        if(a[i] >= b[i]){
            ok.PB(MP(a[i], i));
        }else{
            nk.PB(MP(a[i], i));
        }
    }
    ll ans = SZ(nk);
    if(SZ(nk) == 0){
        cout << 0;
        return 0;
    }
    sort(ALL(ok), [&](pair<ll, int> p1, pair<ll, int> p2){
        return abs(p1.F - b[p1.S]) > abs(p2.F - b[p2.S]);
    });
    // sort(ALL(nk), [&](pair<ll, int> p1, pair<ll, int> p2){
    //     return abs(p1.F - b[p1.S]) < abs(p2.F - b[p2.S]);
    // });
    ll sum = 0;
    for(auto &x : nk){
        ll extra = abs(x.F - b[x.S]);
        sum += extra;
    }
    ll csum = 0;
    int cnt = 0;
    for(auto &x : ok){
        csum += abs(x.F - b[x.S]);
        cnt++;
        if(csum >= sum){
            break;
        }
    }
    if(csum >= sum){
        cout << ans + cnt;
    }else{
        cout << -1;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

using namespace std;

long long cnt = 0, p, dp[55][55][10000];

long long subsetsum(long long arr[], long long l, long long r, int sum) {

        if(l > r) {
                if (sum % 2 == p) {
                        return 1;
                }
                return 0;
        }
        if(dp[l][r][sum] != -1) return dp[l][r][sum];
        long long p, q;
        p = subsetsum(arr, l + 1, r, sum + arr[l]);
        q = subsetsum(arr, l + 1, r, sum);

        return dp[l][r][sum] = p + q;
}

void solve() {
        memset(dp, -1, sizeof dp);
        long long n, ans;
        scanf("%lld %lld", &n, &p);
        long long arr[n + 5];
        for (size_t i = 0; i < n; i++) {
                scanf("%lld", &arr[i]);
        }
        ans = subsetsum(arr, 0, n - 1, 0);
        printf("%lld\n", ans);
}

int main(int argc, char const *argv[]) {
        solve();
        return 0;
}


Measured memory_bytes: 236544
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<ll, ll> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define rep(i,a,b) for(i=a;i<=b;i++)
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007LL
// #define hell 163577857LL
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
     if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int M = 1005;
const int N = 1005;
const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll euclid(ll x,ll y,ll a,ll b)
{
  return (a-x)*(a-x)+(b-y)*(b-y);
}
// Constants //
void solve()
{
	string ans[]={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
  ll i;
  cin>>i;
  cout<<ans[i%10];
}
int main()
{ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t,i;
  t=1;
  // cin>>t;
  // preprocess();
  while(t--)
  {
    solve();
    // cout<<endl;
  }
  return 0;
}

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

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
using ll = long long;
using ull = unsigned long long;

int main() {
    FAST;

    string s;
    cin >> s;

    rep(i, size(s)){
        if(s[i] == '7'){
            println("Yes");
            stop;
        }
    }

    println("No");
}

Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a,b; cin>>a>>b; cout<<a-b+1;
}

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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif


signed main()
{
	int a[12] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
//				 1  2  3  4  5  6  7  8  9 10 11 12
	int x, y;
	cin >> x >> y;
	PRINT(a[x-1] == a[y-1]);
}



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


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 rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;



int main() {
    int a,b,c,x,y; cin >> a >> b >> c >> x >> y;
    c*=2; //ABピザは偶数枚買うので
    int ans=INF;

    rep(i,max(x,y)+1){
        int temp=i*c+a*max(0,x-i)+b*max(0,y-i);
        chmin(ans,temp);
    }
    COUT(ans);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();

            if (n == "1")
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var a = int.Parse(Console.ReadLine());
                var b = int.Parse(Console.ReadLine());
                Console.WriteLine(a + b);
            }
        }
    }
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        Console.WriteLine(Math.Abs(XY[0] - XY[1]) <= 1 ? "Brown" : "Alice");
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

int luca(long ans,int count,int n,long a0,long a1){
   count ++; 
  if(count == n){
    return ans;
  }
  
   long long temp = ans;
   ans = a0 + a1;
   luca(ans,count,n,temp,ans);
}



int main(void){
  int  n;
  scanf("%d",&n);
  printf("%ld",luca(1,0,n,2,1));
  
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        var C = input[2];
        var ans = 0;

        int factor = C / A;
        ans += B * factor;


        Console.WriteLine(ans);


        // var N = int.Parse(Console.ReadLine());
        // var S = Console.ReadLine().ToArray();

    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
int MOD = 1000000007;
int Array[100005];
int Fact[100005] , InvFact[100005];

int Power( int base , int exp ){
    if( exp == 0 ) return 1;
    else{
        int middle = Power( base , exp >> 1 );
        int Value = ( middle * 1LL * middle ) % MOD;
        if( exp & 1 ) return ( Value * 1LL * base ) % MOD;
        else return Value;
    }
}

void PreProcess(){
    int i;
    Fact[0] = 1;
    InvFact[0] = Power( Fact[0] , MOD - 2 );

    for( i = 1 ; i <= 100000 ; ++i ){
        Fact[i] = ( Fact[i - 1] * 1LL * i ) % MOD;
        InvFact[i] = Power( Fact[i] , MOD - 2 );
    }
}

long long FindAns( int N , int k ){
    sort( Array + 1 , Array + N + 1 );
    int i;
    long long Value , Ans = 0LL , Num = 1LL * InvFact[k - 1];

    for( i = k ; i <= N ; ++i ){
        Value = ( ( ( Fact[i - 1] * Num ) % MOD ) * InvFact[i - k] ) % MOD;
        Ans = ( Ans + ( ( Value * Array[i] ) % MOD ) ) % MOD;
    }

    for( i = 1 ; i <= N - k + 1 ; ++i ){
        Value = ( ( ( Fact[N - i] * Num ) % MOD ) * InvFact[N - i - (k - 1)] ) % MOD;
        Ans = ( Ans - ( ( Value * Array[i] ) % MOD ) + MOD ) % MOD;
    }

    return Ans;
}

int main(){
    int N , k , i;
    PreProcess();
    scanf( "%d%d" , &N , &k );

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , Array + i );
    
    printf( "%lld\n" , FindAns( N , k ) );
    return 0;
}

Measured memory_bytes: 1408
d,g = map(int,input().split())
p = []
c = []
for i in range(d):
    tp,tc = map(int,input().split())
    p.append(tp)
    c.append(tc)
ans = 1<<50
for i in range(1<<d):#どのコンプリートボーナスを狙うかを決める
    score = 0
    count = 0
    zero_list = []
    for j in range(d):
        if ((i >> j) & 1):
            score += c[j] + p[j]*(j+1)*100 
            count += p[j]
        else:
            zero_list.append(j)
    if score >= g:
        ans = min(ans,count)
    else:#もしまだ点数が届いていないならボーナスを狙わないものから点数が高い問題を解く
        rem = g-score
        # if count == 5:#debag
        #     print("dbg")
        #     print(zero_list)
        #     print(rem)
        #     print((p[max(zero_list)]-1)*(max(zero_list)+1)*100)
        #     print(p[max(zero_list)])
        if rem <= (p[max(zero_list)]-1)*(max(zero_list)+1)*100:
            for i in range(1,p[max(zero_list)]):
                # print("dbg2")
                # print(rem - i*(max(zero_list)+1)*100)
                if rem - i*(max(zero_list)+1)*100 <= 0:
                    count +=  i
                    ans = min(ans,count)
                    break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T' << endl;
  }else if(b == 'T'){
    cout << 'A' << endl;
  }else if(b == 'C'){
    cout << 'G' << endl;
  }else if(b == 'G'){
    cout << 'C' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : agc19b.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	string s;
	cin >> s;
	map<char, int> mp;
	long long count = 1;
	for(int i = 0; i < s.length(); ++i){
		count += i - mp[s[i]];
		++mp[s[i]];
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 640
D,G=map(int, input().split())
PC=[0]+[list(map(int, input().split())) for _ in range(D)]
def function(G,i):
    if i==0:
        return 1e9
    n=min(G//(i*100),PC[i][0]) #determin the number of "100i problem" to be solved
    s=n*i*100
    if n==PC[i][0]:
        s+=PC[i][1] #modify the point for "100i problem" with complete bonus
    if s<G:
        n+=function(G-s,i-1) #calculate until G-Sigma(s)=0
    return min(n,function(G,i-1))
print(function(G,D))

Measured memory_bytes: 3064
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Aug 24 21:22:23 2019
//
package main

import "fmt"

const MOD = 1e9 + 7

func main() {
	var n, k int64
	fmt.Scan(&n, &k)

	arr := make([]int, n)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	var count int64
	for i := range arr {
		for j := i + 1; j < len(arr); j++ {
			if arr[i] > arr[j] {
				count++
			}
		}
	}
	ans := (count * k) % MOD

	count = 0
	for i := range arr {
		for j := range arr {
			if arr[j] < arr[i] {
				count++
			}
		}
	}
	fmt.Println((ans + (count*((k*(k-1)/2)%MOD))%MOD) % MOD)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    long cnt[4] = {1};
    for(char i : s){
        if(i == 'A') cnt[1] = (cnt[1] + cnt[0]) % MOD;
        if(i == 'B') cnt[2] = (cnt[2] + cnt[1]) % MOD;
        if(i == 'C') cnt[3] = (cnt[3] + cnt[2]) % MOD;
        if(i == '?'){
            cnt[3] = (cnt[3] * 3 + cnt[2]) % MOD;
            cnt[2] = (cnt[2] * 3 + cnt[1]) % MOD;
            cnt[1] = (cnt[1] * 3 + cnt[0]) % MOD;
            cnt[0] = (cnt[0] * 3) % MOD;
        }
    }
    cout << cnt[3] << endl;
}


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

int main(void){
  long long X,A,B;
  cin >> X >> A >> B;
  if(A>=B){
    cout << "delicious" << endl;
    return 0;
  }
  else if(A+X>=B){
    cout << "safe" << endl;
    return 0;
  }
  else cout << "dangerous" << endl;
}
  

Measured memory_bytes: 256
s=input()
t=input()
ans=10000
for i in range(len(s)-len(t)+1):
    a=s[i:i+len(t)]
    cnt=0
    for j in range(len(a)):
        if a[j]!=t[j]:
            cnt+=1
    ans=min(ans,cnt)
print(ans)


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

int main(){
  char c; cin >> c;
  if(c == 'A') cout << 'T';
  if(c == 'T') cout << 'A';
  if(c == 'C') cout << 'G';
  if(c == 'G') cout << 'C';
  cout << endl;
  return 0;
}

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

const int N = 2e5 + 7;
char s[N];
bool vis[N];

int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	int ans = 1, last = 1;
	vis[1] = 1;
	for (int i = 2; i <= n; i++) {
		vis[i] = 1;
		if (last == 1) {
			if (s[i] == s[i - 1]) {
				last = 2;
				i++;
			} 
		} else {
			last = 1;
		}
		ans++;
	}
	if (vis[n - 1] && vis[n] && s[n - 1] == s[n]) ans--;
	printf("%d\n", ans);
}

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

int main() {
    string N;
    cin >> N;
    string S = "No";
    rep(i, 3) {
        if (N.at(i) == '7') {
            S = "Yes";
            break;
        }
    }
    cout << S << endl;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int res = n / 1.08;
	while(res * 1.08 < n)
	{
		res++;
	}
	if(floor(res * 1.08) == n)
	{
		printf("%d\n", res);
	}
	else
	{
		printf(":(\n");
	}
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n"<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 500000
#define INF 9223372036854775807
int power(int x, int y, int m=mod) 
{ 
    if (y == 0) 
        return 1; 
    int p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
}  
signed main(){
    fastio
    int N , S ;
    cin >> N >> S ;
    vector< int > a(N);
    f(i,0,N){
    	cin >> a[i] ;
	}
	int MI=power(2,mod-2);
	int dp[N+1][S+1];
	memset(dp,0,sizeof(dp));
	dp[0][0]=power(2,N);
	f(i,0,N){
		f(j,0,S+1){
			dp[i+1][j]=( dp[i+1][j] + dp[i][j] )%mod;
			if( j + a[i] <= S)
			    dp[i+1][j+a[i]]=( dp[i+1][j+a[i]] + dp[i][j]*MI )%mod;
		}
	}
	cout << dp[N][S] ;
	
}

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

int main() {
  string N;
  cin >> N;
  for (int i = 0; i < N.size(); i++) N.at(i) = toupper(N.at(i));

  int count = 0;
  while (1) {
    string S;
    cin >> S;
    if (S == "END_OF_TEXT") break;
    for (int i = 0; i < S.size(); i++) S.at(i) = toupper(S.at(i));
    if (N == S) count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;
ll N;
vector<ll> DP1, DP2,A;

int main() {
	cin >> N;
	A.resize(N + 2,0);
	for (ll n = 1; n <= N; n++)cin >> A[n];
	DP1.resize(N,0);
	for (ll n = 1; n < N; n++) {
		DP1[n] += abs(A[n] - A[n - 1]) + DP1[n - 1];
	}
	DP2.resize(N + 2, 0);
	for (ll n = N; n >= 1; n--) {
		DP2[n] += DP2[n + 1] + abs(A[n + 1] - A[n]);
	}
	for (ll n = 1; n <= N; n++) {
		cout << DP1[n - 1] + DP2[n + 1] + abs(A[n + 1] - A[n - 1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool prime[101];
void init(){
  int i,j;
  prime[0] = prime[1] = false;
  fill(prime+2,prime+101,1);
  for(i=2;i<=7;i++){
    if(!prime[i]) continue;
    for(j=i+i;j<=100;j+=i) prime[j] = false;
  }
}
int main(){
  init();
  int N,CN,c,i,j,k;scanf("%d",&N);
  vector<int> s;
  for(i=2;i<=100;i++){
    if(!prime[i]) continue;
    c = 0;CN = N;
    while(CN){
      CN /= i;c += CN;
    }
    s.emplace_back(c);
  }
  int ans = 0;
  for(i=0;i<s.size();i++) ans += s[i] >= 74;
  for(i=0;i<s.size();i++){
    for(j=0;j<s.size();j++){
      if(i==j) continue;
      ans += s[i] >= 2 && s[j] >= 24;
      ans += s[i] >= 4 && s[j] >= 14;
    }
  }
  for(i=0;i<s.size();i++){
    for(j=0;j<s.size()-1;j++){
      for(k=j+1;k<s.size();k++){
        if(i == j || i == k) continue;
        ans += s[i] >= 2 && s[j] >= 4 && s[k] >= 4;
      }
    }
  }
  printf("%d\n",ans);
}

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

const int limit = 50;

int n,m;
int a[limit],b[limit];

bool graph [limit][limit];
bool visited [limit];

void dfs(int v){
  visited[v]=true;
  for(int v2=0;v2<n;++v2){
    if(!graph[v][v2])continue;
    if(visited[v2])continue;
    dfs(v2);
  }
}

int main(){
  cin >>n >>m;
  for(int i=0;i<m;i++){
    cin>>a[i] >>b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  
  int ans=0;
  
  for(int i=0;i<m;i++){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    
    for(int j=0;j<n;j++) visited[j]=false;
    
    dfs(0);
    
    bool bridge = false;
    for(int j=0;j<n;j++)if(!visited[j])bridge=true;
    if(bridge)ans++;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
	int m;
	scanf("%d",&m);
	ll sum=0,dig=0;
	for(int i=0;i<m;i++)
	{
		ll d,c;
		scanf("%lld %lld",&d,&c);
		sum+=d*c;
		dig+=c;
	}
	printf("%lld\n",dig+(sum-1)/9LL-1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll a, b;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> a >> b;
	if(a*b <= 0){
		print("Zero")
	}
	else{
		if(a > 0){
			print("Positive")
		}
		else{
			if((b - (a - 1)) % 2 == 0){
				print("Positive")
			}
			else{
				print("Negative")
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int r(){
	char c=getchar();int f=1,sum=0;
	while(c>'9' or c<'0') if(c=='-'){f=-1;c=getchar();} while(c<='9' and c>='0'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;}
int gcd(int a,int b){
	if(a==0) return b;
	return gcd(b%a,a);}
int prime(int a){
	if(a==1 or a==0)return 0;
	if(a%2==0 and a!=2) return 0;
	for(int i=3;i*i<=a;i++)if(a%i==0)return 0;
	return 1;//O(sprt(n)/2)
}



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


	return 0;
}


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

int main() {
 
	int n;
	cin >> n;
	int arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];
	
	int bst = INT_MAX;
	
	for (int i=0; i<n; i++) {
		int op = 0;
		while (arr[i] % 2 == 0) {
			arr[i] = arr[i] / 2;
			op++;
		}
		bst = min(bst, op);
	}
	
	cout << bst << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    int a;
    cin >> a;
    a--;
    A[a]++;
  }
  sort(A.begin(),A.end());
  int ans=0;
  rep(i,N-K) ans+=A[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main()
{
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static List<Integer>[] edge = new ArrayList[n];
    static boolean[] visited = new boolean[n];
    static long[] point = new long[n];

    public static void main(String[] args){

        for (int i=0; i<n; i++){
            edge[i] = new ArrayList<>();
        }
        int q = sc.nextInt();
        for (int i=0; i<n-1; i++){
            int s = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            edge[s].add(t);
            edge[t].add(s);
        }

        for (int i=0; i<q; i++){
            int t = sc.nextInt()-1;
            int x = sc.nextInt();
            point[t] += x;
        }

        dfs(0, 0l);

        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++){
            sb.append(point[i]+" ");
        }
        System.out.print(sb.toString());
    }

    private static void dfs(int u, long p){
        visited[u] = true;
        point[u] += p;
        for (int v: edge[u]){
            if (!visited[v]){
                dfs(v, point[u]);
            }
        }

    }
}

Measured memory_bytes: 227804
h1, h2 = gets.split.map(&:to_i)
k1, k2 = gets.split.map(&:to_i)
a, b, c, d, = gets.split.map(&:to_i)
f = -> i, y { a * i + b * y + c * (i / 10) + d * (y / 20) }
h = f[h1, h2]
k = f[k1, k2]
puts h > k ? 'hiroshi' : h < k ? 'kenjiro' : 'even'


Measured memory_bytes: 6872
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        long[] a = new long[M];
        long[] b = new long[M];
        long[] m = new long[M];
        for (int i=0 ; i<M; i++) {
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
            for(int j=0;j<b[i];j++) {
            	m[i]=(long) (m[i]+Math.pow(2, sc.nextInt()-1));
            }
        }
        
        //2^12
        int[] dp=new int[(int) Math.pow(2, N)];
        for(int i=0;i<(int) Math.pow(2, N);i++)dp[i]=9999999;
        dp[0]=0;
        for(int i=1;i<Math.pow(2, N);i++) {
        	for(int j=0;j<M;j++) {
        		int tmp=0;
        		for(int k=0;k<=N;k++) {
        			if((i>>k)%2==1&&(m[j]>>k)%2==0) {
        				tmp=(int) (tmp+Math.pow(2, k));
        			}
        		}
        		if(tmp==i)continue;
        		dp[i]=(int) Math.min(dp[i], dp[tmp]+a[j]);
        	}
        }
        
        int ans=dp[(int) (Math.pow(2,N)-1)];
        if(ans==9999999) {
        	ans=-1;
        }
        System.out.println(ans);  	
               		
    }

}

Measured memory_bytes: 34788