akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int weight[100000];

	int sum,L,R,mid,i,j,n,k;	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&weight[i]);

	L=0,R=1000000001;

	while(R-L>1){
		mid=(R+L)/2;

		j=0;
		for(i=0; i<k; i++){
			sum=0;
			while(j<n){
				if(sum+weight[j]<=mid){
					sum+=weight[j];	j++;
					continue;
				}else break;
			}
		}

		if(j<n)L=mid;
		else R=mid;
	}

	printf("%d\n",R);


	return 0;
}



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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back
#define eb emplace_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int a = in(), b = in();
    if (a > b)
    {
        rep(i, a) cout << b;
        cout << endl;
    }
    else if (a < b)
    {
        rep(i, b) cout << a;
        cout << endl;
    }
    else
    {
        rep(i, a) cout << b;
        cout << endl;
    }
}

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


Measured memory_bytes: 256
n,m,q=gets.split.map(&:to_i)
abcds=q.times.map{gets.split.map(&:to_i)}
ans=0
[*1..m].repeated_combination(n).to_a.each do |vs|
  now=0
  abcds.each do |ai,bi,ci,di|
    if vs[bi-1]-vs[ai-1]==ci
      now+=di
    end
  end
  ans=[ans,now].max  
end
puts ans


Measured memory_bytes: 27888
N, Ma, Mb = (list)(map(int, input().split()))
l = []
inf = 10**6
dp = [[[inf]*401 for _ in range(401)] for _ in range(41)]


for _ in range(N):
    l.append((list)(map(int, input().split())))

dp[0][0][0] = 0

for i in range(N):
    for ca in range(401):
        for cb in range(401):
            if dp[i][ca][cb] != inf:
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                t_a = l[i][0]
                t_b = l[i][1]
                dp[i+1][ca+t_a][cb+t_b] =\
                    min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])

ans = inf
for i in range(1, 401):
    for j in range(1, 401):
        if i*Mb == j*Ma:
            ans = min(ans, dp[N][i][j])

if ans == inf:
    ans = -1
print(ans)


Measured memory_bytes: 59476
N = input()
a=0
b=0
for i in range(len(N)):
	if N[i] == 'A' or N[i] ==  'T' or N[i] ==  'C' or N[i] ==  'G' :
		a+=1
	else: 
		if a > b: b = a
		a=0

print(max(b,a))


Measured memory_bytes: 2940
S = input()
T = input()

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])


if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Measured memory_bytes: 38384
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	A = np.array(LI())
	A.sort()
	count = 0
	a_max = A[-1]
	dp = [1]*a_max
	for a in A:
		point = dp[a-1]
		if point == 1:
			dp[a-1] = 2
			count += 1
			for ai in range(a*2,a_max+1,a):
				dp[ai-1] = 0
		elif point == 2:
			count -= 1
			dp[a-1] = 0
	print(count)






if __name__ == '__main__':
    main()

Measured memory_bytes: 45936
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[20010],to[4000010],nt[4000010],co[4000010],F[20010],it[20010],l[20010];
void mklsd(int v,int e,int *a,int *b,int *c){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i]=ta[a[i]];
    to[i]=b[i];
    co[ta[a[i]]=i]=c[i];
  }
}
int MF(int e,int s,int t,int min){
  if(s==t)return min;
  int i,r;
  for(;it[s]+1;it[s]=nt[it[s]]){
    if(co[it[s]]==0||l[s]>=l[to[it[s]]])continue;
    r=MF(e,to[it[s]],t,MIN(min,co[it[s]]));
    co[it[s]]-=r;
    co[(it[s]+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
//呼び出す方
int q[4000010];
//頂点v、辺eのグラフでsからgに流す
int maxf(int v,int e,int s,int g){
  int i,a=0,t,r,c=3;
  while(1){
    for(i=t=0;i<v;i++)l[i]=0;
    for(r=l[q[0]=s]=1;r-t;t++){
      for(i=ta[q[t]];i+1;i=nt[i]){
	if(co[i]&&l[to[i]]==0)l[q[r++]=to[i]]=l[q[t]]+1;
      }
    }
    if(l[g]==0)return a;
    for(i=0;i<v;i++)it[i]=ta[i];
    while(r=MF(e,s,g,1e9))a+=r;
  }
}
  int h,w,s,g,r=0,a[2000010],b[2000010],c[2000010],e=0,ans,i,j,k,d[110][110];
int main(){
  char p;
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      d[i][j]=-1;
      scanf(" %c",&p);
      if(p=='S')s=r;
      if(p=='T')g=r;
      if(p-'.')d[i][j]=r++;
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(d[i][j]<0)continue;
      a[e  ]=d[i][j]+r;
      b[e  ]=d[i][j];
      c[e++]=d[i][j]==s||d[i][j]==g?1e9:1;
      for(k=0;k<h;k++){
	if(d[k][j]<0||i==k)continue;
	if((d[i][j]==s&&d[k][j]==g)||(d[i][j]==g&&d[k][j]==s))goto END;
	a[e  ]=d[i][j];
	b[e  ]=d[k][j]+r;
	c[e++]=1e9;
      }
      for(k=0;k<w;k++){
	if(d[i][k]<0||k==j)continue;
	if((d[i][j]==s&&d[i][k]==g)||(d[i][j]==g&&d[i][k]==s))goto END;
	a[e  ]=d[i][j];
	b[e  ]=d[i][k]+r;
	c[e++]=1e9;
      }
    }
  }
  mklsd(r*2,e,a,b,c);
  printf("%d\n",maxf(r*2,e,s,g));
  return 0;
 END:;
  printf("-1\n");//printf("%d %d %d\n",i,j,k);
  return 0;
}


Measured memory_bytes: 59776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int m,n,i;
    cin>>n>>m;
    n--;
    m--;
	cout<<(n+m-1)/n<<endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import math

def main():
    na = list(map(int, input().split()))
    D, G = na[0], na[1]
    p = []
    c = []
    ts = []
    for i in range(D):
        na = list(map(int, input().split()))
        p.append(na[0])
        c.append(na[1])
        ts.append(100 * (i + 1) * na[0] + na[1])

    max_i = 2 ** D
    min_q = 1000
    for i in range(max_i):
        q = 0
        s = 0
        max_uc = -1
        for j in range(D):
            if i & (2 ** j) != 0:
                q += p[j]
                s += ts[j]
            else:
                max_uc = j
        if G <= s:
            min_q = min(min_q, q)
        elif G <= s + 100 * (max_uc + 1) * (p[max_uc] - 1):
            min_q = min(min_q, q + math.ceil((G - s) / 100 / (max_uc + 1)))

    print(min_q)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	
	for(int i=0; i<n; i++){
		if(a[i]%4==0) a[i]=4;
		else if(a[i]%2==0) a[i]=2;
		else a[i] = 1;
	}
	
	int one=0, four=0, two=0;
	for(int i=0; i<n; i++){
		if(a[i]==1) one+=1;
		else if(a[i]==4) four+=1;
		else if(a[i]==2) two+=1;
	}
	
	if(two==0){
		if(one>four+1) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	else{
		if(one>four) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap

int main(){
  int N,X; cin>>N>>X;
  ll x[N+1]; CINA(x,N);
  x[N] = X;
  sort(x,x+N+1);
  ll d[N];
  ll r;
  REP(i,N){
    if(i==0) r = x[1]-x[0];
    else r = gcd(x[i+1]-x[i],r);
  }
  cout <<r <<"\n";
  
}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  ll res = 1e18;
  for(int i = 1; i <= n -1; i++) {
    int a = i;
    int j = n - i;
    ll ans = 0;
    while(j) ans += j%10, j/=10;
    while(a) ans += a%10, a/=10;
    res = min(ans, res);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n;cin>>n;
   VI A(n+1);
   rep(i,n+1)cin>>A[i];
   VI L(n+1),R(n+1);
   L[n]=R[n]=A[n];
   for(int i=n-1;i>=0;i--){
      L[i]=A[i]+(L[i+1]+2-1)/2;
      R[i]=A[i]+R[i+1];
   }
   if(L[0]>1){
      cout<<-1<<Endl;
      return 0;
   }
   ll ans=0;
   ll cur=1;
   rep(i,n+1){
      ans+=cur;
      cur-=A[i];
      if(i<n)cur=min(cur*2,R[i+1]);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n, g, w[105], v[105], sumv, dp[100005], newval, res;
int main() {
    DAU
    cin >> n >> g;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
        sumv += v[i];
    }
    for (int i = 1; i <= sumv; ++i)
        dp[i] = 1e9 + 1;
    dp[0] = 0;
    for (int i = 1; i <= n; ++i)
        for (int val = sumv; val >= 0; --val)
            if (dp[val] + w[i] <= g) {
                newval = val + v[i];
                dp[newval] = min(dp[newval], dp[val] + w[i]);
                res = max(res, newval);
            }
    cout << res;
    PLEC
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


int bitcnt[1 << 18];
int dp[1<<18][18];
int a[18], b[18];

int value(int pos, int ind){
    if((pos - ind) % 2)return b[ind];
    else return a[ind];
}
            

int flip(int pos, int bit){
    return bitcnt[bit & ((1<<18)-(1<<pos))];
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++) cin >> a[i];
    for(int i = 0;i < n;i++) cin >> b[i];
    for(int i = 0;i < 1<<18;i++)
        for(int j = 0;j < 18;j++)
            dp[i][j] = INF;
    
    dp[0][0] = 0;
    int ans = INF;
    for(int bit = 0;bit < 1<<n;bit++){
        if(bit)bitcnt[bit] = bitcnt[bit/2] + bit % 2;
        for(int last = 0;last < n;last++){
            if(bit == (1 << n)-1)ans = min(ans, dp[bit][last]);
            if(bit > 0 && (bit & (1<<last)) == 0)continue;
            for(int nxt = 0;nxt < n;nxt++){
                if(bit & (1<<nxt))continue;
                int nxtbit = bit + (1<<nxt);
                
                if(bit > 0 && value(bitcnt[bit]-1, last) > value(bitcnt[bit], nxt))continue;
                dp[nxtbit][nxt] = min(dp[nxtbit][nxt], dp[bit][last] + flip(nxt, bit));
            }
        }
    }
    if(ans == INF)ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19712
#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;
    cin >> s;
    map<int,int> cnt;
    rep(i,4){
      cnt[s[i]]++;
    }
  if(cnt.size() == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

// cout << fixed << setprecision(15) <<  << endl;


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

bool ans = true;
int N, L;
string S;

bool isPalindrome(string S){
    bool flag = true;

    int K = S.size();

    if(K==2){
        return S[0] == S[1];
    }

    rep(i, (K-1)/2){
        if(S[i] != S[K - 1 - i]){
            // cout << S[i] << " " << S[K - 1 - i] << endl;
            flag = false;
            break;
        }
    }

    return flag;
}

void solve(){
    L = (N-1)/2;

    // cout << S.substr(0,L) << endl;
    // cout << S.substr(L+1, L) << endl;

    if(!isPalindrome(S)){
        ans = false;
        }
    if(!isPalindrome(S.substr(0,L))){
        ans = false;
    }
    if(!isPalindrome(S.substr(L+1, L))){
        ans = false;
    } 

    if(ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> S;
    N = S.size();

    solve();
}


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

int main() {
    //入力
    int n;
    string s[100010];
    cin >> n;
    int c0 = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    string a0 = "AC";
    string a1 = "WA";
    string a2 = "TLE";
    string a3 = "RE";
    for (int i=0; i<n; i++) cin >> s[i];
    for (int i=0; i<n; i++) {
        if (s[i] == a0) c0++;
        else if (s[i] == a1) c1++;
        else if (s[i] == a2) c2++;
        else if (s[i] == a3) c3++;
    }
    cout << a0 << " " << "x" << " " << c0 << endl;
    cout << a1 << " " << "x" << " " << c1 << endl;
    cout << a2 << " " << "x" << " " << c2 << endl;
    cout << a3 << " " << "x" << " " << c3 << endl;
    return 0;
}

Measured memory_bytes: 6752
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int N;
	cin >> N;

	vector<int>a(N);
	repin(a, N);

	sort(a.rbegin(), a.rend());

	int ans=0;
	rep(i, N) {
		i % 2 == 0 ? ans += a[i] : ans -= a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pyton3

date = input().split()
B_date = input().split()

N = int(date[0])
M = int(date[1])
C = int(date[2])

B = []

for i in range(1,M+1):
    B.append(int(B_date[i-1]))

A = []

for j in range(1, N +1):
    A_sub = []
    a = input().split()
    for k in range(1,M+1):
        A_sub.append(int(a[k-1]))
    A.append(A_sub)


ans = 0

for i in range(1, N +1):
    total = 0
    for m in range(1, M + 1):
        total += A[i-1][m-1]*B[m-1]
    total += C

    if total > 0:
        ans += 1

print(ans)
    

    


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

int main(){
  int N;
  cin >> N;
  vector<int> num(N);
  for(int i = 0; i < N; ++i){
    cin >> num.at(i);
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  int Alice=0,Bob=0;
  for(int i = 0; i < N; ++i){
    if(i%2==0){
      Alice += num.at(i);
    } else {
      Bob += num.at(i);
    }
  }
  cout << Alice-Bob << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	getline(cin,s);
	for(int i=0;i<s.length();i++)
	{
		if(s[i]>='a'&&s[i]<='z')s[i]-='a'-'A';
		else if(s[i]>='A'&&s[i]<='Z')s[i]+='a'-'A';
	}
	cout<<s<<endl;
	return 0;
}


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

int h[100010];
int main(){
    int n;
    int flog[100010];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    flog[0]=0;
    flog[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        flog[i]=min(flog[i-1]+abs(h[i]-h[i-1]),flog[i-2]+abs(h[i]-h[i-2]));
    }
    printf("%d\n",flog[n-1]);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s,hanbun,ss;
    int k;
    cin >> k >> s;
    

    for(int i = 0;i < k /2;i++){
        hanbun += s.at(i);
    }

    ss = hanbun + hanbun;

    if(s == ss)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
        
} 

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    ll K;
    cin >> K;
    ll keizoku = 0;
    REP(i,S.size()){
        if(S[i] == '1'){
            keizoku++;
        }else{
            break;
        }
    }
    cout << (keizoku < K? S[keizoku] : to_string(1)[0]) << "\n";
}

Measured memory_bytes: 256
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------
 
const int nax=1e4+5;
int ans[nax];

int val(int x, int y, int z){
	return x*x+y*y+z*z+x*y+x*z+z*y;
}

int count(int x, int y, int z){
	map<int,int> mp, fact;
	mp[x]++;
	mp[y]++;
	mp[z]++;
	fact[0]=fact[1]=1;
	fact[2]=2;
	fact[3]=6;
	int ans=6;
	for(auto it: mp){
		ans/=(fact[it.y]);
	}
	// trace(x,y,z,ans);
	return ans;
}

signed main() {
	tezz

	int n;
	cin >> n;

	for(int i=1; i<100; i++){
		for(int j=i; j<100; j++){
			for(int k=j; k<100; k++){
				int x = val(i,j,k);
				if(x>n)break;
				ans[x]+=count(i,j,k);
			}
		}
	}

	for(int i=1; i<=n; i++)cout << ans[i] << endl;
 
	return 0;
}  

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 30;
const int MOD = 1e9 + 7;
const int maxN = 2e5 + 1;

int lower(set<int>& st, int x) {
	auto it = st.lower_bound(x);
	if (it == st.begin()) return -1;
	it--;
	return *it;
}

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	x1--; y1--; x2--; y2--;
	vector<set<int>> hor(n), ver(m);
	vector<vector<char>> a(n, vector<char>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = c;
			hor[i].insert(j);
			ver[j].insert(i);
		}
	}

	vector<vector<int>> dp(n, vector<int>(m, INF));
	
	queue<pair<int, int>> q;
	q.push({ x1, y1 });
	dp[x1][y1] = 0;
	hor[x1].erase(y1);
	ver[y1].erase(x1);
	while(!q.empty()){
		auto p = q.front();
		q.pop();
		int x = p.first;
		int y = p.second;

		while (hor[x].lower_bound(y) != hor[x].end()) {
			int yy = *hor[x].lower_bound(y);
			if (yy - y > k || a[x][yy] == '@') break;
			hor[x].erase(yy);
			ver[yy].erase(x);
			dp[x][yy] = dp[x][y] + 1;
			q.push({ x, yy });
		}

		while (lower(hor[x], y) != -1) {
			int yy = lower(hor[x], y);
			if (y - yy > k || a[x][yy] == '@') break;
			hor[x].erase(yy);
			ver[yy].erase(x);
			dp[x][yy] = dp[x][y] + 1;
			q.push({ x, yy });
		}

		while (ver[y].lower_bound(x) != ver[y].end()) {
			int xx = *ver[y].lower_bound(x);
			if (xx - x > k || a[xx][y] == '@') break;
			ver[y].erase(xx);
			hor[xx].erase(y);
			dp[xx][y] = dp[x][y] + 1;
			q.push({ xx, y });
		}

		while (lower(ver[y], x) != -1) {
			int xx = lower(ver[y], x);
			if (x - xx > k || a[xx][y] == '@') break;
			ver[y].erase(xx);
			hor[xx].erase(y);
			dp[xx][y] = dp[x][y] + 1;
			q.push({ xx, y });
		}
	}

	cout << (dp[x2][y2] == INF ? -1 : dp[x2][y2]);
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 160520
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N;
    cin>>N;
    v a(N);
    rep(i,0,N)cin>>a[i];
    ll sum = 0;
    rep(i,0,N)sum += a[i];
    ll temp = 0,diff = INF;
    rep(i,0,N-1){
        temp+=a[i];
        diff = min({diff,abs(2*temp-sum)});
    }
    cout<<diff;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ld thre = (ld)1 / 4 / m * sum;

    int ans = 0;
    rep(i, n) if(a[i] >= thre) ans++;
    if(ans >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int n;
    cin>>n;
    int a[2][n];
    int s=0;
    int ans =0;
    rep(i,n){
      cin>>a[0][i];
    }
    rep(i,n){
      cin>>a[1][i];
    }

    rep(i,n){
      s+=a[0][i];
      int tmp = s*1;
      for(int j=i;j<n;j++){
        tmp+=a[1][j];
      }
      ans=max(ans,tmp);
    }
  cout<<ans<<endl;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1<<18;
typedef pair<int,int> P;
int n_;
P dat[2*MAX_N-1];

void init(int n) {
  n_=1;
  while (n>n_) {
    n_*=2;
  }
  for (int i=0; i<2*n_-1; i++) {
    dat[i].first=-1;
    dat[i].second=INT_MAX;
  }
}
int find(int i) {
  i+=n_-1;
  P p=dat[i];
  while (i>0) {
    i=(i-1)/2;
    p=max(p,dat[i]);
  }
  return p.second;
}

void update(int a,int b,P p,int k=0,int l=0,int r=n_) {
  if (r<=a || b<=l) {
    return;
  }
  if (a<=l && r<=b) {
    dat[k]=p;
  } else {
    update(a,b,p,k*2+1,l,(l+r)/2);
    update(a,b,p,k*2+2,(l+r)/2,r);
  } 
}
int main() {
  int n, q;
  cin >> n >> q;
  init(n);
  for (int i=0;i<q;i++) {
    int f;
    cin >> f;
    if (!f) {
      int s, t, x;
      cin >> s >> t >> x;
      update(s,t+1,P(i,x));
    } else {
      int u;
      cin >> u;
      printf("%d\n",find(u));
    }    
  }
  return 0;
}

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

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

  vector<int> h(n);
  long long int total = 0;
  for(int i=0;i<n;i++) {
    cin >> h[i];
  }

  sort(h.rbegin(), h.rend());

  if(k >= n) cout << 0 << endl;
  else {
    for(int i=k;i<n;i++) {
      total += h[i];
    }

    cout << total << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

int main() {
	int n, a;
	cin >> n >> a;
	map<int,int> m;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x -= a;
		m[x]++;
	}
	
	map<ll, ll> cnt;
	for (auto it1 = m.begin(); it1 != m.end(); it1++) {
		
		for (int i = 0; i < it1->second; i++) {
			map<ll, ll> tmp_cnt;
			for (auto it2 = cnt.begin(); it2 != cnt.end(); it2++) {
				tmp_cnt[it2->first + it1->first] += it2->second;
				//cout << it2->second << endl;
			}
			tmp_cnt[it1->first]++;

			for (auto it2 = tmp_cnt.begin(); it2 != tmp_cnt.end(); it2++) {

				cnt[it2->first] += it2->second;
			}
			//cout << i << endl;
		}

		/*
		for (auto it2 = cnt.begin(); it2 != cnt.end(); it2++) {

			cout << it2->first << " "<< it2->second << endl;
		}
		cout << endl;
		*/
	}
	cout << cnt[0] << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  cin>>N>>H;
  //vec v(N);
  cout<<(N^H)<<endl;
  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int d,w;
int garden[10][10];

int  serchMinMax(int xmin,int xmax,int ymin,int ymax){
  //int maxD = -1;
  int minD = 10;
  int depth = 0;
  // deside max and min-----
  for(int i = ymin;i<=ymax; i+= (ymax-ymin) ){
    for(int j = xmin ; j <= xmax; j++){
      //maxD = max(garden[i][j] ,maxD);
      minD = min(garden[i][j],minD);
    }
  }
  for(int i = ymin+1; i < ymax; i++){
    for(int j = xmin; j <= xmax; j+= (xmax - xmin) ){
      //maxD = max(garden[i][j] ,maxD);
      minD = min(garden[i][j],minD);
    }
  }
  //cout << "max" << maxD << endl;
  //cout << "min" << minD << endl;
  // serch Pond depth

  for(int i= ymin + 1; i < ymax ; i++){
    for(int j = xmin + 1; j < xmax; j++){
      if(minD > garden[i][j]) depth +=  minD - garden[i][j] ;
      else return 0;
    }
  }
  return depth;
}

int main(){

  while(true){
    int ans = 0;
    scanf("%d %d",&d,&w);
    if(d == 0 && w == 0) break;
    //--------------------------input
    for(int i = 0; i < d; i ++){
      for(int j=0; j < w; j++){
        scanf("%d",&garden[i][j]);
      }
    }

    // select xmin ymin xmax ymax
    for(int i= 0; i <= w - 3; i++){//xmin
      for(int j = i+2; j < w; j++){//xmax
        for(int k = 0; k <= d - 3; k++){//ymin
          for(int l = k+2; l < d; l++){//ymax
            ans = max(ans,serchMinMax(i, j, k, l));
            //cout << "hi" << endl;
          }
        }
      }
    }
    //cout << "hi" << endl;
    //int x = serchMinMax(0, 3, 0, 2);
    //cout << x << endl;
    cout << ans << endl;

  }
  return 0;
}



Measured memory_bytes: 3160
def solve():
    N, M = map(int, input().split())
    
    if N == 1 and M == 1:
        print(1)
    elif N == 1 or M == 1:
        print(N * M - 2)
    else:
        print(N * M - (N * 2 + M * 2 - 4))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend() 
const int N = 2e5+5;
const ll MAX = 1e9 +7;

int main()
{
	bolt;
	//ll ans =0;
	int n;
	cin>>n;
	int a[n];
	int x = 1 , cnt = 0;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(a[i] == x)
		{
			cnt++;
			x++;
		}
	}
	if(cnt == 0)
	cout<<"-1\n";
	else
	cout<<n-cnt<<"\n";
	return 0;
}
	
	


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct block{
	long long sum; 
	int W; int S;  
	long long V; 
}; 
bool cmp(const block &a, const block &b){
	return a.sum < b.sum; 
}
int main(){
	int N; cin >> N; 
	block B[1010]; 
	for(int i = 0; i < N; i++){
		cin >> B[i].W >> B[i].S >> B[i].V; 
		B[i].sum = B[i].W + B[i].S; 
	}
	sort(B, B+N, cmp); 
	long long dp[1010][10010] = {}; 
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= 10001; j++){
			dp[i][j] = -1e18;
		}
	}
	dp[0][0] = 0; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= 10000; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]); 
			if(j <= B[i].S) dp[i+1][min(j+B[i].W, 10001)] = max(dp[i+1][min(j+B[i].W, 10001)], dp[i][j] + B[i].V); 
		}
		dp[i+1][10001] = max(dp[i+1][10001], dp[i][10001]); 
	}
	long long ans = 0; 
	for(int i = 0; i <= 10001; i++) ans = max(ans, dp[N][i]); 
	cout << ans << endl; 
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;
ll mat[51][51],extr[51][51],n;

void mul(ll b[51][51]){

ll m[n][n];
    forn(i,n)
    {
        forn(j,n)
        {
            m[i][j] = 0;
            forn(k,n)
            {
                ll temp=((mat[i][k]%mod)*(b[k][j]%mod))%mod;
                m[i][j] = ((m[i][j]%mod)+(temp%mod))%mod;
            }
        }
    }
    forn(i,n) forn(j,n) mat[i][j] = m[i][j]%mod;

}

void rec(ll k){
	if(k<=1) return ;
	rec(k/2);
	mul(mat);
	if(k%2) mul(extr);
}

int main(){

    sync
   // file();
    ll k;
    cin>>n>>k;
    forn(i,n) forn(j,n) cin>>mat[i][j], extr[i][j] = mat[i][j];
    rec(k);
    ll ans = 0;
    forn(i,n) forn(j,n) ans = (ans+mat[i][j])%mod;
    cout<<ans;

  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main()
{
    unsigned long long int a,b,c,d,e,f;
    scanf("%lld%lld%lld",&a,&b,&c);
    d=(b/c)-(a/c);
    if(a%c==0) printf("%lld",d+1);
    else printf("%lld",d);
    return 0;

}


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

int main() {
  int n,a[25],temp;
  int sum=0;
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++){
    cin >> temp;
    if(temp<a[i])sum+=a[i]-temp;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
ll n,l; cin>>n>>l;
ll a[n]={};
rep(i,n) cin>>a[i];
ll b[n-1]={};
ll k = 0;
rep(i,n-1){
b[i]=a[i]+a[i+1];
k = max(b[i],k);}
ll r = 0;
rep(i,n-1){
if(b[i]==k){
r = i;
break;}
}
if(k>=l){
cout << "Possible" << endl;
for(ll i=0; i<r; i++){
cout << i+1 << endl;
}
for(ll i=n-2; i>r; i--){
cout << i+1 << endl;}
cout << r+1 << endl;}
else{
cout << "Impossible" << endl;}}


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

#define PI 3.141592653589793238462643383279
typedef long long ll;
const long double EPS = 1e-9;
const ll MOD = 1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    #ifdef LOCAL_TEST
    freopen("input.txt","r",stdin);
    #endif
    int n, m; cin >> n >> m;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++) {
        int k; cin >> k;
        for(int j=0;j<k;j++) {
            int a; cin >> a;
            ++mp[a];
        }
    }
    int ans = 0;
    for(auto &p : mp) if(p.second == n) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}




signed main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; ++i){
        cin >> c[i];
        for(int j = 0; j < m; ++j)
            cin >> a[i][j];
    }
    i64 ans = INF;
    for(int i = 0; i < (1 << n); ++i){
        vector<int> p(m, 0);
        i64 an = 0;
        for(int j = 0; j < n; ++j){
            if(i & (1 << j)){
                an += c[j];
                for(int k = 0; k < m; ++k)
                    p[k] += a[j][k];
            }
        }
        bool fl = true;
        for(int j = 0; j < m; ++j)
            fl &= (p[j] >= x);
        if(fl)
            chmin(ans, an);
    }
    if(ans >= 1e12){
        cout << -1 << endl;
    }
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
X = int(input())

last_two = X % 100
other = X - last_two
# print(last_two)
count = 0
flag = 0

for i in range(5, 0, -1):
    count += last_two // i
    last_two = last_two % i
    if last_two % i == 0:
        if count <= other // 100:
            flag = 1
            break
if flag == 1:
    print(1)
else:
    print(0)

Measured memory_bytes: 38256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      	String t = sc.next();
      	int count = 0;
      	for(int i = 0; i < s.length(); i++){
        	if(s.charAt(i) != t.charAt(i)) count++;
        }
      	System.out.println(count);
    }
}

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

/*
最小公倍数を求めればよい
Aの倍数をA*Bまで見ていく

or

gcd
*/

int main() {
    long A, B;
    cin >> A >> B;

    for (long i = 1; i <= B; i++)
    {
        /* code */
        long num = A * i;
        if (num % B == 0) {
            cout << num << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n, num;
    char m;
    cin >> n;
    int a[4][13] = {};

    for(int i=0;i<n;i++){
        cin >> m >> num;
        switch(m){
            case 'S':
            a[0][num-1] = 1;
            break;
            case 'H':
            a[1][num-1] = 1;
            break;
            case 'C':
            a[2][num-1] = 1;
            break;
            case 'D':
            a[3][num-1] = 1;
            break;
        }
    }
    
    
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(a[i][j]==0){
                switch(i){
                case 0:
                cout << "S " << j+1 << endl;
                break;
                case 1:
                cout << "H " << j+1 << endl;
                break;
                case 2:
                cout << "C " << j+1 << endl;
                break;
                case 3:
                cout << "D " << j+1 << endl;
                break;
                }
            }
        }
    }
}


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

namespace B_018_43
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //new Logic_A().Start();//OK
            new Logic_B().Start();//OK
            Console.ReadLine();
        }

        public class Logic_B
        {
            public void Start()
            {
                var S = Console.ReadLine();
                var result = new List<string>();

                for (int i = 0; i < S.Length; i++)
                {
                    if (S[i] != 'B')
                    {
                        result.Add(S[i].ToString());
                    }
                    else
                    {
                        if (result.Count != 0)
                        {
                            result.RemoveAt(result.Count - 1);
                        }
                    }
                }
                var r = string.Empty;
                foreach (var t in result)
                {
                    r += t;
                }
                Console.WriteLine(r);
            }
        }
}
}

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

const int N = 55;
ll dp[N][2];
int n, p;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> p;
    dp[0][0] = 1;
    dp[0][1] = 0;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        int c;
        cin >> c;
        if(c & 1) {
            dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
            dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
        } else {
            dp[i][0] = 2 * dp[i - 1][0];
            dp[i][1] = 2 * dp[i - 1][1];
        }
        ans = max(ans, dp[i][p]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
d = defaultdict(list)
h = {}
for i in range(n):
    m = list(input().split())
    d[m[0]].append(int(m[1]))
    h[int(m[1])] = i +1
l = sorted(d)
j = sorted(h, reverse = True)
for word in l:
    for num in j:
        if num in d[word]:
            print(h[num])


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
int main()
{
  string w, s;
  int N;
  cin >> w >> N;
  int cnt = 0;
  Rep(i,N) {
    cin >> s;s += s;
    cnt += s.find(w) != string::npos;
  }
  cout << cnt << endl;
  return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  string s,t; cin >> s >> t;
  int n = s.size();
  rep(i,n){
    if(s[i] != t[i]){
      out("No");
      return 0;
    }
  }
  out("Yes");
}

Measured memory_bytes: 3648