akhauriyash/Code-Regression huggingface dataset:
def chmin(l, i, v):
  if l[i] > v:
    l[i] = v
    return True
  return False

def main():
    N, M = map(int, input().split())
    keys = []
    for i in range(M):
        a, b = map(int, input().split())
        C = map(int, input().split())
        # mask: nビット目が1なら、n番目のカギを開けられる
        mask = 0
        for c in C:
            mask |= 1 << (c-1)
        keys.append((a, mask))
    
    # N 個のカギを選ぶ、選ばないのパターンを考えると、その組み合わせは2^N 通り
    # コスト無限大で初期化
    patterns = 1 << N
    INF = float("inf")
    # dp[i]: iのnビット目が1なら、n番目のカギを開けられて、その開けられるカギの組み合わせでの最安値を示している
    # 例: dp[3]: 1番目と2番目のカギをあけたいときの最安値
    dp = [ INF ] * patterns
    dp[0] = 0

    # 計算量: O(2^N * M) => 最大でも 4096 * 10^3 ~= 10^6
    for a, mask in keys:
        for i in range(patterns):
            chmin(dp, i|mask, dp[i] + a)

    ans = dp[patterns-1]
    print(-1 if ans == INF else ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

void bubbleSort(int A[], int N){
  int flag = 1, i, t, c = 0;
  while(flag){
    flag = 0;
    for(i = N-1; i > 0; i--){
      if(A[i] < A[i-1]){
	t = A[i];
	A[i] = A[i-1];
	A[i-1] = t;
	flag = 1;
	c++;
      }
    }
  }
  for(i = 0; i < N; i++){
    printf("%d",A[i]);
    if(i <= N-2) printf(" ");
  }
  printf("\n%d\n", c);
}


int main(void){
  int i, n;
  scanf("%d", &n);
  int *a;
  a = malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  bubbleSort(a, n);
  return 0;
}

Measured memory_bytes: 1804
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    ll sum=0;
    ll cnt=0;
    ll mi=INF;
    rep(i,n){
        sum+=abs(a[i]);
        if(a[i]<0)++cnt;
        chmin(mi,abs(a[i]));
    }
    cout<<(cnt%2?sum-2*mi:sum)<<endl;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


signed main()
{
    // cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;

    if (abs(a - b) & 1) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/agc005/tasks/agc005_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    string S;
    cin >> S;
    int cnt_s = 0, cnt_t = 0, ans = S.length();
    for (auto &x : S) {
        if (x == 'S') {
            cnt_s++;
        } else {
            cnt_t++;
            // TがSより多くなったらカウントしない
            if (cnt_t > cnt_s) {
                cnt_t = cnt_s;
            }
        }
        // STのペアができたら削る
        if (cnt_s >= 1 && cnt_t >= 1) {
            cnt_s--;
            cnt_t--;
            ans -= 2;
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin>>N;
  int kazu=N.size();
  int countE=0;
  int countW=0;
  int countN=0;
  int countS=0;
  bool hanteiE=false;
  bool hanteiW=false;
  bool hanteiN=false;
  bool hanteiS=false;
  for(int i=0;i<kazu;i++){
    if(N[i]=='E'){
      countE++;
      hanteiE=true;
    }
    if(N[i]=='W'){
      countW++;
      hanteiW=true;
    }
    if(N[i]=='N'){
      countN++;
      hanteiN=true;
    }
    if(N[i]=='S'){
      countS++;
      hanteiS=true;
    }
  }
  bool tate=false;
  bool yoko=false;
  if(hanteiE==true&&hanteiW==true){
    yoko=true;
  }
  if(hanteiN==true&&hanteiS==true){
    tate=true;
  }
  if(countE-countW==0){
    yoko=true;
  }
  if(countN-countS==0){
    tate=true;
  }
  if(tate==true&&yoko==true){
    cout <<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

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

using namespace std;

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

	long long tmp=0;
	rep(i,n){
		if(i%2==0) tmp+=a[i];
		else       tmp-=a[i];
	}

	vector<int> x(n);
	x[0]=tmp;
	rep(i,n-1) x[i+1]=2*a[i]-x[i];
	rep(i,n) cout<<x[i]<<" ";

	return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
  static Scanner in = new Scanner(System.in);
  public static void main(String[] args) {
    String str = in.nextLine();
    if (str.endsWith("s")) {
      str = str + "es";
    } else {
      str = str + "s";
    }
    System.out.println(str);

  }
}


Measured memory_bytes: 38496
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,inf=1e9+10;
int a[M],n;
void print(int x,int y)
{
	y=y xor x;
	if(y==1)cout<<"Second";
	else cout<<"First";
	exit(0);
}
void bt(int now)
{
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		cnt+=a[i]%2;
	}
	if(cnt>=2)
	{
		if(cnt%2==n%2)
		{
			print(1,now);
		}
		else print(0,now);
	}
	bool flag=0;
	if(cnt==1)
	{
		if(cnt%2!=n%2)
		{
			print(0,now);
		}
		else
		{
			flag=1;
			for(int i=1;i<=n;i++)
			{
				if(a[i]%2){
					if(a[i]==1)
					{
						print(1,now);
					}
					a[i]--;
				}
			}
			int tmp=0;
			for(int i=1;i<=n;i++)tmp=__gcd(tmp,a[i]);
			for(int i=1;i<=n;i++)a[i]/=tmp;
			bt(1-now);
		}
	}
}
main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1)
	{
		if(a[1]%2==1)cout<<"Second";
		else cout<<"First";
		return 0;
	}
	bt(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define  endl 			"\n"
#define  FOR(i, a, n)   for (ll i = a; i < n; i++)
#define  ROF(i, a, n)   for (ll i = a; i >= n; i--)
#define  all(x)         (x).begin(), (x).end()
#define  dline          cout<<"///REACHED///\n";

typedef long long ll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  4e+5+7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int N;
	cin >> N;
	int x = N%10;
	if (N%10 == 3) cout << "bon" << endl;
	else if (x == 0 or x == 1 or x == 6 or x == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}



Measured memory_bytes: 3576
# -*- coding: utf-8 -*-

import sys


def f(x):
    return x*x

lineNumber = 0
#for line in [ "20", "10" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # except line
    if lineNumber == 1:
        cars = []
    
    # get data
    List = map(int, line.strip().split())

    # program
    d = List[0]
    x = 0
    ans = 0
    while x < 600:
        ans += f(x) * d
        x += d
    print ans

Measured memory_bytes: 4204
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;

long long arr[82];

int main() {
    int n;
    cin >> n;
    long long sum = 1000, buy = 0;
    for(int i = 1;i <= n;i ++) scanf("%lld", &arr[i]);
    arr[0] = 10000; arr[n+1] = -10000;
    for(int i = 1;i <= n;i ++) {
        if(arr[i] <= arr[i+1]) {
            buy += sum / arr[i];
            sum -= (sum/arr[i]) * arr[i];
        }
        else if(arr[i] > arr[i+1]) {
            sum += buy * arr[i];
            buy = 0;
        }
//        cout << i << " " << sum << " " << buy << endl;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3700
from math import gcd

t = int(input())
queries = [tuple(int(x) for x in input().split()) for _ in range(t)]
for a, b, c, d in queries:
    if a < b:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if b - c <= 1:
        print("Yes")
        continue

    g = gcd(b, d)
    m = a + ((b - a) // g) * g
    if m >= b:
        m -= g
    if c < m:
        print("No")
    else:
        print("Yes")


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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

ll a, b, c;

int main() {
  cin >> a >> b >> c;
  if (c - 1 <= a + b) cout << b + c << endl;
  else cout << b + a + b + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * Title: C - Distinct or Not
 * Url: https://atcoder.jp/contests/abc154/tasks/abc154_c
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    bool flag = true;
    for(int i=1; i<n; i++) {
        if(a[i]==a[i-1]) {
            flag = false; 
            break;
        }
    }
    if(flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

ans = 0
"""
if a[0] == 0:
  #a[1] とa[0]を足して|1|かつa[0]とa[1]+a[0]の符号を逆にしたい
  if a[1] > 0:
    a[0] = 1 - a[1]    
  elif a[1] < 0:
    a[0] = -1 - a[1]
  else: # a[0] a[1] 共に0の場合、a[2]に依存する　-> 両方やればいい
奇数番目と偶数ばんめのどちらを＋にするか  
"""
ans_odd = 0
total_odd = 0
ans_even = 0
total_even = 0
for i in range(n):
  if (i+1) % 2 == 1: #奇数ばんめ
    #奇数番目を＋、偶数番目を-にするパターン
    total_odd += a[i]
    if total_odd <= 0:
      ans_odd += abs(total_odd) + 1
      total_odd = 1
      
    #偶数番目を＋、奇数番目を-にするパターン
    total_even += a[i]
    if total_even >= 0:
      ans_even += (abs(total_even)+1)
      total_even = -1
      
  else: #偶数番目
    #奇数番目を＋、偶数番目を-にするパターン
    total_odd += a[i]
    if total_odd >= 0:
      ans_odd += abs(total_odd)+1
      total_odd = -1
      
    #偶数番目を＋、奇数番目を-にするパターン
    total_even += a[i]
    if total_even <= 0:
      ans_even += abs(total_even)+1
      total_even = 1
  """    
  print("total,ans_odd")    
  print(total_odd)
  print(ans_odd)
  print("total,ans_even")
  print(total_even)
  print(ans_even)
  """   
print(min([ans_odd, ans_even]))
#print()

Measured memory_bytes: 14332
import sys
readline = sys.stdin.readline
write = sys.stdout.write

L = 1000
D = [(0, 0), (1, 0)]
x = 1; y = 0
for i in range(L-1):
    d = (x**2 + y**2)**.5
    x, y = x - y/d, y + x/d
    D.append((x, y))

def solve():
    N = int(readline())
    if N == -1:
        return False
    x, y = D[N]
    write("%.16f\n%.16f\n" % (x, y))
    return True
while solve():
    ...



Measured memory_bytes: 5736
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==1)cout<<"No"<<endl;
    else if(n==2)cout<<"No"<<endl;
    else if(n==3)cout<<"No"<<endl;
    else if(n==5)cout<<"No"<<endl;
    else if(n==6)cout<<"No"<<endl;
    else if(n==9)cout<<"No"<<endl;
    else if(n==10)cout<<"No"<<endl;
    else if(n==13)cout<<"No"<<endl;
    else if(n==17)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    map<int, _LL> c;
    rep(i, n) 
    {
        int t;
        cin >> t;
        t--;
        a.push_back(t);
        c[t]++;
    }
    _LL total = 0;
    rep(i, n)
    {
        if( c[i] > 1 )
        {
            total +=  c[i] *  (c[i] - 1) / 2;
        }
    }
    
    rep(k, n)
    {

        _LL diff = 0;
        _LL ct = c[a[k]];
        if( ct > 1 )
        {
            diff = (ct - 1) * (ct - 2) / 2 - ct * (ct - 1) / 2;
        } 
        cout << total + diff << endl;
    }

    return 0;    
}

Measured memory_bytes: 16536
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);
    zip(A, B).sort();
    long ans;
    foreach (i; 0 .. N)
    {
        if (M == 0)
        {
            writeln(ans);
            return;
        }
        ans += A[i] * min(M, B[i]);
        M -= min(M, B[i]);
    }
    writeln(ans);
}


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

class Solve {
private:
	std::string str;
	int length;

	std::string decodeCipher(int& s_i)
	{
		std::string ret;
		while (s_i != length && str[s_i] != ']')
			ret += decodeString(s_i);
		return ret;
	}

	std::string decodeString(int& s_i)
	{
		if (str[s_i] == '[')
		{
			s_i++;
			std::string ret{decodeCipher(s_i)};
			std::reverse(ret.begin(), ret.end());
			s_i++;
			return ret;
		}
		else
		{
			return decodeLetter(s_i);
		}
	}

	std::string decodeLetter(int& s_i)
	{
		if (str[s_i] == '+')
		{
			s_i++;
			std::string ret{decodeLetter(s_i)};
			if (ret.front() != '?')
				ret.front() = (ret.front() - 'A' + 1) % 26 + 'A';
			return ret;
		}
		else if (str[s_i] == '-')
		{
			s_i++;
			std::string ret{decodeLetter(s_i)};
			if (ret.front() != '?')
				ret.front() = (ret.front() - 'A' + 25) % 26 + 'A';
			return ret;
		}
		else
		{
			s_i++;
			return std::string(1, str[s_i - 1]);
		}
	}

public:
	bool is_last_query{};
	Solve()
	{
		std::cin >> str;
		if (str == ".")
		{
			is_last_query = true;
			return;
		}
		length = (int)str.size();
		int s_i{};
		std::string ans{decodeCipher(s_i)};
		for (auto& e: ans)
			if (e == '?') putchar('A');
			else putchar(e);
		putchar('\n');
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main()
{
    int64_t n,k,a=0,m=1e9+7;
    cin>>n>>k;
    for(int i=k;i<n+2;i++)
        a=(a+i*(n-i+1)+1)%m;
    cout<<a<<endl;
}


Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    vector<int> a(4);
    rep(i,4) cin>>a[i];
    sort(all(a));
    bool f=1;
    cout<<((a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)?"YES":"NO")<<endl;
}/*
./problem.exe
*/

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

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

int main()
{
	int n;
	vector<int> v;
	string s;

	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(All(v));

	double ans = v[0];
	REPS(i, n - 1) {
		ans = (ans + v[i]) / 2;
	}
	printf("%.10f\n", ans);
}

Measured memory_bytes: 256
import sys

def is_macth(x, t, n):
    for i in range(n):
        if x[i] != '?' and x[i] != t[i]:
            return False
    return True


s = input()
t = input()
len_s = len(s)
len_t = len(t)

if len_s < len_t:
    print('UNRESTORABLE')
    sys.exit(0)

segs = [s[i:i+len_t] for i in range(len_s - len_t + 1)]
ans = 'z' * 51

for i, seg in enumerate(segs):
    if is_macth(seg, t, len_t):
        tmp = s[0:i] + t + s[i+len_t:]
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

if len(ans) > 50:
    print('UNRESTORABLE')
else:
    print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int n,a,b,min=99999999,qwq[100005];
	scanf("%d",&n);
	for(b=1;b<n;b++)
	{
		a=b;
		qwq[b]=a/100000;
		a%=100000;
		qwq[b]+=a/10000;
		a%=10000;
		qwq[b]+=a/1000;
		a%=1000;
		qwq[b]+=a/100;
		a%=100;
		qwq[b]+=a/10;
		a%=10;
		qwq[b]+=a;
	}
	for(a=1;a<=n/2+1;a++)
	{
		if(qwq[a]+qwq[n-a]<min)
		min=qwq[a]+qwq[n-a];
	}
	if(n==2)
	printf("2");
	else
	printf("%d",min);
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define previous fake_previous
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 41;
const LL MAXK = 20;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	LL n, m;
	cin >> n >> m;
	VPLL a(m);
	FOR(i, 0, m)
		cin >> a[i].X >> a[i].Y;

	set<int> may;
	may.insert(1);
	VI num(n + 1, 1);

	LL x, y;
	FOR(i, 0, m)
	{
		x = a[i].X;
		y = a[i].Y;

		if (may.count(x))
		{
			may.insert(y);
			if (num[x] == 1)
				may.erase(x);	
		}
		num[x]--;
		num[y]++;
	}


	cout << SZ(may);
	return 0;
}

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

const int NUM =1000000000;

int main(){
  int N;
  cin>>N;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin>>h.at(i);
  }
  vector<int> DP(N,NUM);
  DP[0]=0;
  for(int i=1;i<N;i++){
    DP[i] = min(DP[i], DP[i-1]+abs(h[i]-h[i-1]));
    if(i>1){
      DP[i] = min(DP[i], DP[i-2]+abs(h[i]-h[i-2]));
    }
  }
  cout<<DP[N-1]<<endl;
  return 0;
}

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

const int INF = 1000000007;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pr;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    string u[256];
    string t;
    while(cin >> n){
        for(int i = 0; i < n; i++){
            cin >> u[i];
        }
        cin >> m;
        int st = 0;
        for(int i = 0; i < m; i++){
            cin >> t;
            int j = 0;
            for(j = 0; j < n; j++){
                if(t == u[j]) break;
            }
            if(j == n){
                cout << "Unknown ";
            }else{
                st = 1 - st;
                cout << ((st == 1) ? "Opened" : "Closed") << " by ";
            }
            cout << t << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
def d_c(s):
  count = 0
  x = ''
  for i in range(len(s)):
    if x == s[0]:
      count += 1
      x = ''
    else:
      x = s[0]
    s = s[1:]
  return count
 
def num_con(s):
  x = s[0]
  s = s[1:]
  count = 1
  for i in range(len(s)):
    if s[0] == x:
      count += 1
      x = s[0]
      s = s[1:]
    else:
      break
  return count
      
    
s = input()
k = int(input())
 
if len(s)==1:
  print(k//2)
elif num_con(s)==len(s):
  print((len(s)*k)//2)
elif s[0]==s[-1]:
  f = num_con(s)
  m = num_con(s[::-1])
  dis = (f//2 + m//2 - (f+m)//2)*(k-1)
  print(d_c(s)*k-dis)
else:
  print(d_c(s)*k)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A, x, y;

  std::cin >> N;

  std::vector<std::vector<int>> a(N), b(N);

  for (int i = 0; i < N; i ++) {
    std::cin >> A;

    for (int j = 0; j < A; j ++) {
      std::cin >> x >> y;

      (y == 1 ? a[i] : b[i]).push_back(x - 1);
    }
  }

  int cp = 0;

  for (int i = 0; i < 1 << N; i ++) {
    bool valid = true;
    
    for (int j = 0; j < N; j ++)
      if (i & (1 << j)) {
        bool f = true;

        for (const auto& k : a[j])
          if (! (i & (1 << k))) {
            f = false;

            break;
          }

        for (const auto& k : b[j])
          if (i & (1 << k)) {
            f = false;

            break;
          }

        if (! f) {
          valid = false;

          break;
        }
    }

    if (valid)
      cp = std::max(__builtin_popcount(i), cp);
  }

  std::cout << cp << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c[10000+1],d,i,f=0;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&c[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&d);
    if(search(c,a,d))f++;
  }
  printf("%d\n",f);
}

int search(int A[],int a,int b){
  int i=0;
  A[a]=b;
  while(A[i] != b)i++;
  return i != a;
}
  



Measured memory_bytes: 2104
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Half and Half
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c, x, y;
  scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);

  int sum = 0;

  if (x > 0 && y > 0 && a + b >= 2 * c) {
    int xy = min(x, y);
    sum += xy * (2 * c);
    x -= xy, y -= xy;
  }

  if (x > 0 && a >= 2 * c) {
    sum += x * (2 * c);
    x = 0;
  }

  if (y > 0 && b >= 2 * c) {
    sum += y * (2 * c);
    y = 0;
  }

  sum += a * x + b * y;

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>

bool check (std::vector<std::tuple<int, int>> const & v, int M) {

  if (std::get<0>(v.front()) != 0) { return false; }

  int bound = std::get<1>(v[0]);
  for (int i = 1; i < v.size(); ++i) {
    if (std::get<0>(v[i]) > bound) {
      return false;
    }
    bound = std::max(bound, std::get<1>(v[i]));
  }
  if (bound != M) { return false; }
  return true;
}

int main () {

  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string line;
  std::getline(std::cin, line);

  char * p = &*line.begin();

  int N = std::strtol(p, &p, 10);
  int W = std::strtol(p, &p, 10);
  int H = std::strtol(p, &p, 10);

  std::vector<std::tuple<int, int>> X;
  std::vector<std::tuple<int, int>> Y;

  for (int i = 0; i < N; ++i) {
    std::getline(std::cin, line);

    char * p = &*line.begin();
    int x = std::strtol(p, &p, 10);
    int y = std::strtol(p, &p, 10);
    int w = std::strtol(p, &p, 10);

    X.emplace_back(std::max(0, x - w), std::min(W, x + w));
    Y.emplace_back(std::max(0, y - w), std::min(H, y + w));
  }

  std::sort(X.begin(), X.end(), [&] (std::tuple<int, int> const & l, std::tuple<int, int> const & r) {
    if (std::get<0>(l) < std::get<0>(r)) {
        return true;
    }
    if (std::get<0>(l) == std::get<0>(r)) {
      return std::get<1>(l) < std::get<1>(r);
    }
    return false;
  });

  std::sort(Y.begin(), Y.end(), [&] (std::tuple<int, int> const & l, std::tuple<int, int> const & r) {
    if (std::get<0>(l) < std::get<0>(r)) {
        return true;
    }
    if (std::get<0>(l) == std::get<0>(r)) {
      return std::get<1>(l) < std::get<1>(r);
    }
    return false;
  });

  if (W < H) {
    std::cout << (check(X, W) ? "Yes" : "No") << std::endl;
  } else if (W > H) { 
    std::cout << (check(Y, H) ? "Yes" : "No") << std::endl;
  } else {
    bool f1 = check(X, W);
    bool f2 = check(Y, H);
    std::cout << ((f1 || f2) ? "Yes" : "No") << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon

const int N=42,M=17,mod=1e9+7;
ll dp[N][1<<M];
int32_t main(){
    ll n,x,y,z;
    cin >> n >> x >> y >> z;
    dp[0][0]=1;
    ll mask=(1<<16)-1;
    ll b=(1<<(x+y+z-1)) | (1<<(y+z-1)) | (1<<(z-1));
    for (int i=0;i<n;i++){
        for (int j=0;j<(1<<16);j++){
            for (int k=1;k<=10;k++){
                ll nxt=(j<<k);
                nxt |=(1<<(k-1));
                if ((nxt & b)==b){
                    continue;
                }
                nxt &=mask;
                dp[i+1][nxt]+=dp[i][j];
                dp[i+1][nxt]%=mod;
            }
        }
    }
    ll ans=1;
    for (int i=0;i<n;i++){
        ans*=10;
        ans%=mod;
    }
    for (int i=0;i<(1<<17);i++){
        ans-=dp[n][i];
        ans+=mod;
        ans%=mod;
    }
    cout << ans;
}


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

using namespace std;

struct Route {
    int cost;
    int tm;

    Route(int c, int t) {
        cost = c;
        tm = t;
    }

    bool operator<(const Route &param) const {
        return cost < param.cost;
    }
};

int main() {
    vector<Route> route;
    int N, T;
    cin >> N >> T;
    for (int i = 0; i < N; i++)
    {
        int c, t;
        cin >> c >> t;
        route.push_back(Route(c, t));
    }
    sort(route.begin(), route.end());
    for (int i = 0; i < N; i++) {
        if (route[i].tm <= T) {
            cout << route[i].cost << "\n";
            return 0;
        }
    }
    cout << "TLE\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=  1e5+10;
char s[maxn];
int main (void) {
    scanf ("%s", s);
    int len = strlen (s);
    if (s[0] == s[len-1]) len--;
    if (len % 2 == 1) printf ("First\n");
    else printf ("Second\n");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), r(m), b(m);
    int asum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        asum += a[i];
    }
    int rsum = 0, bsum = 0;
    for (int i = 0; i < m; i++) {
        cin >> r[i];
        rsum += r[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        bsum += b[i];
    }
    sort(all(a));
    sort(all(r));
    sort(all(b));
    reverse(all(a));
    reverse(all(r));
    reverse(all(b));
    vector<vector<vector<int>>> dp(
        n + 1, vector<vector<int>>(m + 1, vector<int>(50 * (n + 1), INF)));
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= 50 * (i + 1); k++) {
                if (i >= j && i - j < m) {
                    chmin(dp[i + 1][j][k],
                          dp[i][j][k] + max(0, a[i] - b[i - j]));
                }
                if (j > 0 && k >= a[i]) {
                    chmin(dp[i + 1][j][k],
                          dp[i][j - 1][k - a[i]] + max(0, a[i] - r[j - 1]));
                }
            }
        }
    }
    int res = INF;
    for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= 50 * n; k++) {
            if (k <= rsum && asum - k <= bsum) {
                chmin(res, dp[n][j][k]);
            }
        }
    }
    if (res == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;
}


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

typedef unsigned long long ll;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(),x.end()
#define DEBUG
#define MAX (int)1e9

int main()
{
    int a, p;
    cin >> a >> p;

    p += a * 3;
    int ans = (p - (p%2)) / 2;

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


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

const string YES = "Yes";
const string NO = "No";

bool kaibun(string s)
{
    for(int i=0; i<s.length()/2; i++)
    {
        if(s.at(i) != s.at(s.length() - 1 - i)) return false;
    }
    return true;
}

void solve(std::string s){
    string s2 = "";
    for(int i=0; i<(s.length() - 1)/2; i++) s2 += s.at(i);
    string s3 = "";
    for(int i=(s.length() + 3)/ 2 - 1; i<s.length(); i++) s3 += s.at(i);
    if(kaibun(s) && kaibun(s2) && kaibun(s3)) cout << YES << endl;
    else cout << NO << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<deque>

#define INF (1e9)

using namespace std;

typedef long long int Int;

int main(void) {
    int K;
    cin>>K;
    vector<int> cost(K,INF);
    cost[1] = 1;
    deque<int> q;
    q.push_front(1);
    while(!q.empty()) {
        int x = q.front();q.pop_front();
        int y = (x+1) % K;
        if(cost[y] > cost[x]+1) {
            cost[y] = cost[x]+1;
            q.push_back(y);
        }
        int z = (x*10)%K;
        if(cost[z] > cost[x]) {
            cost[z] = cost[x];
            q.push_front(z);
        }
    }

    cout<<cost[0]<<endl;

    return 0;
}


Measured memory_bytes: 896
n=int(input())
al=[int(input()) for _ in range(n)]
ans=1
pd=set([0])
t=1
while True:
    t=al[t-1]
    if t==2:
        print(ans)
        exit()
    if t in pd:
        print(-1)
        exit()
    pd.add(t)
    ans+=1

Measured memory_bytes: 13220
#include <iostream>
using namespace std;
#define NIL -1
#define MAX 10000

struct Node    {int parent, left, right;};//????????????
Node T[MAX];
int n, D[MAX], H[MAX];
int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if(T[u].right != NIL)
        h1 = setHeight(T[u].right)+1;
    if(T[u].left != NIL)
        h2 = setHeight(T[u].left)+1;

    return H[u] = max(h1, h2);
}
void setDepth(int u, int d)
{
    if(u == NIL)   return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}
int getSlibing(int u)
{
    if(T[u].parent == NIL)    return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}
void print(int u)
{
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSlibing(u) << ", ";
    int degree = 0;
    if(T[u].left != NIL)   degree++;
    if(T[u].right != NIL)  degree++;
    cout << "degree = " << degree << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";
    if(T[u].parent == NIL)    cout << "root" << endl;
    else if(T[u].left == NIL && T[u].right == NIL)
        cout << "leaf" << endl;
    else   cout << "internal node" << endl;
}

int main()
{
    int v, l, r, root;
    cin >> n;
    for(int i=0; i<n; i++)
        T[i].parent = NIL;
    for(int i=0; i<n; i++)
    {
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if(l != NIL)   T[l].parent = v;
        if(r != NIL)   T[r].parent = v;
    }
    for(int i=0; i<n; i++)
    {
        if(T[i].parent == NIL)
            root = i;
    }
    setHeight(root);
    setDepth(root, 0);
    for(int i=0; i<n; i++)
        print(i);
    return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;cin >> n >> q;
	vector<vector<int>> G(n,vector<int>());
	vector<ll> ans(n);
	rep(i,n-1){
		int a,b;cin >> a >> b;
		G.at(a-1).pb(b-1);
		G.at(b-1).pb(a-1);
	}
	rep(i,q){
		int p,x;cin >> p >> x;
		ans.at(p-1) += x;
	}
	vector<bool> used(n,true);
	queue<pair<int,ll>> que;
	que.push(mp(0,0));
	used.at(0) = false;
	while(!que.empty()){
		pair<int,ll> cur = que.front();que.pop();
		int num = cur.first;
		ll sum = cur.second;
		ll nextsum = sum + ans.at(num);
		ans.at(num) = sum + ans.at(num);
		rep(i,G.at(num).size()){
			if(used.at(G.at(num).at(i))){
				used.at(G.at(num).at(i)) = false;
				que.push(mp(G.at(num).at(i),nextsum));
			}
		}
	}
	rep(i,n){
		if(i == n-1) cout << ans.at(i) << endl;
		else cout << ans.at(i) << " ";
	}
}

Measured memory_bytes: 18804
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
sum=0
for i in range(n):
    sum+=a[i]
    b.append(sum)
b=sorted(b)
b.append(float("inf"))
k=0
for i in range(n):
    if b[i]==b[i+1]:
        k+=1
    else:
        if not k==0:
            ans+=k*(k+1)//2
        k=0
for i in range(n):
    if b[i]==0:
        ans+=1
print(ans)

Measured memory_bytes: 25976
n,m=map(int,input().split())
edge=[[]for _ in range(n)]
color=[11*[0]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
q=int(input())
udc=[list(map(int,input().split()))for _ in range(q)][::-1]
for u,d,c in udc:
  x=u-1
  Q=[x]
  if color[x][d]:continue
  for k in range(d,-1,-1):
    if color[x][k]:break
    color[x][k]=c
  while Q and d!=-1:
    d-=1
    P=[]
    for i in Q:
      for j in edge[i]:
        if color[j][d]:continue
        for k in range(d,-1,-1):
          if color[j][k]:break
          color[j][k]=c
        P.append(j)
    Q=P
for i in color:print(i[0])

Measured memory_bytes: 114848
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI V(N), C(N);
	REP(i, N) {
		cin >> V[i];
	}
	REP(i, N) {
		cin >> C[i];
	}
	int ans = 0;
	REP(i, N) {
		
		if (V[i] >C[i]) {
			ans += V[i];
			ans -= C[i];
		}
		//cout << ans << endl;
	}
	
	cout << ans << endl;
	return 0;
}



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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  res=1,buf=1;
  rep(i,0,n){
    res*=3;
    if(a[i]&1)buf*=1;
    else buf*=2;
  }
  cout<<res-buf<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    ostringstream os;
    string str;
    int q;
    cin >> str >> q;
    REP(i, q){
        string order;
        int fr, to;
        cin >> order >> fr >> to;
        if(order == "replace"){
            string newstr;
            cin >> newstr;
            str.replace(fr, to-fr+1, newstr);
        }
        else if (order == "reverse"){
            string temp = str.substr(fr, to-fr+1);
            REP(j, to-fr+1){
                str[to-j] = temp[j];
            }
        }
        else if (order == "print")
            os << str.substr(fr, to-fr+1) << endl;
    }
    cout << os.str();
    return 0;
}

Measured memory_bytes: 1264
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  const int INF=2000000000;
  int n,dp[100010],i,a;
  scanf("%d\n",&n);
  for(i=0;i<=n;i++){
    dp[i]=INF;
  }
  for(i=0;i<n;i++){
    scanf("%d\n",&a);
    int min=-1,max=n,mid;
    while(abs(min-max)>1){
      mid=(min+max)/2;
      if(a<=dp[mid]){
        max=mid;
      }
      else{
        min=mid;
      }
    }
    dp[max]=a;
  }
  for(i=0;i<n;i++){
    if(dp[i]==INF){
      break;
    }
  }
  printf("%d\n",i);
  return 0;
}


Measured memory_bytes: 3580
/*

Author: @karngyan
Team: BlundersPride

*/

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5 + 10;
ll n , m;
vll g[N];
ll dp[N];

ll dfs(ll s)
{
	if(dp[s] != -1)
		return dp[s];
	
	ll &ans = dp[s];
	ans = 0;
	for(auto x : g[s])
		ans = max(ans , 1 + dfs(x));
	return ans;
}
signed main()
{
	fast;
	memset(dp , -1 , sizeof dp);

////////////////////////////////////////////////////////////////////////////////////////////
	cin >> n >> m;
	rep(i,1,m+1)
	{
		ll u , v;
		cin >> u >> v;
		g[u].pb(v);
	}
	ll ans = 0;
	rep(i,1,n+1)
	{
		ans = max(ans , dfs(i));
	}
	cout<<ans<<endl;


////////////////////////////////////////////////////////////////////////////////////////////
	
	return 0;
}


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

int main(){
  int N , K;
  cin >> N >> K;
  int p = 1;
  for(int i=0;i<N;i++){
    if(p*2 < p+K){
      p *= 2;
    }
  else{
    p += K;
  }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
using System;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Converter(Console.ReadLine());
            Console.WriteLine(Calc(array));
            Console.ReadLine();
        }

        static int[] Converter(string str)
        {
            var array = str.Split(' ');
            return Array.ConvertAll(array, int.Parse);
        }

        static string Calc(int[] array)
        {
            string result = "No";
            if (array[0] < array[1])
                if (array[1] < array[2])
                    result = "Yes";
            return result;
        }
    }
}



Measured memory_bytes: 8904
def main():
    n = int(input())

    evidences = [[] for _ in range(n)]

    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = map(int, input().split())
            evidences[i].append((x - 1, y))

    ans = 0

    for i in range(1, 2 ** n):
        consistent = True
        for j in range(n):
            if (i >> j) & 1 == 0:
                continue
            for x, y in evidences[j]:
                if (i >> x) & 1 != y:
                    consistent = False
                    break
            if not consistent:
                break
        if consistent:
            ans = max(ans, bin(i)[2:].count('1'))

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>

using namespace std;

long long int nCr(int n,int r)
{
    long long m = 1;
    if(n < 2 * r)
	r = n - r;

    for(int i = 1;i < r+1;i++)
	m = m * (n - i + 1) / i;

    return m;
}

int main(void)
{
    int N,P;
    int A[100];

    cin>>N;
    cin>>P;

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

    long long comb = 0;
    int even = 0,odd = 0;
    for(int i = 0;i < N;i++) {
	if(A[i] % 2 == 1)
	    odd++;
	else
	    even++;
    }

    int counter = 0;
    for(int i = 0;i <= odd;i += 2)
	counter += nCr(odd,i);
    
    comb += pow(2,even)*counter;

    if(P == 1)
    {
	comb = pow(2,N) - comb;
    }

    cout<<comb<<endl;

    return 0;
}


Measured memory_bytes: 256