akhauriyash/Code-Regression huggingface dataset:
# -*- coding:utf-8 -*-
import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        tmp2 = (a[tmp]+a[tmp+1]) - x #差分を出す。
        if a[tmp+1] - tmp2 >= 0:
            a[tmp+1] -= tmp2
            ans += tmp2
        else: #足りない場合
            ans += tmp2
            a[tmp] += a[tmp+1] - tmp2 #足りない部分はa[tmp]から引く。
            tmp2 += a[tmp+1] - tmp2
            a[tmp+1] -= tmp2
print(ans)

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

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

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &x : arr) {
        cin >> x;
    }
    vector<vector<ll> > dp(2, vector<ll>(n));
    dp[0][n-1] = arr[n-1];
    dp[1][n-1] = -arr[n-1];
    for (int i = n-2; i >= 0; --i) {
        dp[0][i] = max(arr[i]+dp[0][i+1], -arr[i]+dp[1][i+1]);
        dp[1][i] = max(-arr[i]+dp[0][i+1], arr[i]+dp[1][i+1]);
    }
    cout << dp[0][0] << "\n";
}

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

int n, a[101010];

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1, greater<int>() );
  for(int i = 1; i < n; i++) {
    if(a[i + 1] < i + 1) {
      int ans = a[i] - i & 1;
      int cnt = 0;
      for(int j = i + 1; a[j] == i; j++) {
	cnt ^= 1;
      }
      return puts((ans | cnt) ? "First" : "Second"), 0;
    }
  }
  puts((a[n] - n & 1) ? "First" : "Second");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e5 + 3;

ll n, k, a[N], res[N];

ll _abs(ll x) {
	return x < 0 ? -x : x;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fill(res, res+N, INT_MAX);
	
	cin >> n >> k;
	for (ll i = 1; i <= n; ++i) cin >> a[i];
	
	res[1] = 0;
	res[2] = _abs(a[1] - a[2]);
	for (ll i = 2; i <= n; ++i) {
		for (ll j = 1; j <= k && i - j >= 1; ++j) {
			res[i] = min(res[i], res[i-j] + _abs(a[i] - a[i-j]));
		}
	}
	cout << res[n];
	
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r, D, x := ReadInt(), ReadInt(), ReadInt()
	for i := 0; i < 10; i++ {
		x = r*x - D
		fmt.Println(x)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc128_c

N, M = map(int, input().strip().split())
k = [[] for _ in range(M)]
for i in range(M):
    switches = list(map(int, input().strip().split()))
    k[i] = switches[1:]
p = list(map(int, input().strip().split()))

res = 0
for i in range(2**N):
    b = format(i, '0' + str(N) + 'b')
    can_light_up = True
    for j in range(M):
        count = 0
        for s in k[j]:
            if b[s-1] == '1':
                count += 1
        if count % 2 != p[j]:
            can_light_up = False
    if can_light_up:
        res += 1

print(res)


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

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

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

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

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

int main(){
    int n;cin>>n;
    vl a(n);
    ll sum[n+1];
    sum[0]=0;
    rep(i,n){
        cin>>a[i];
        sum[i+1]=(sum[i]+a[i])%MOD;
    }
    ll ans=0;
    rep(i,n){
        ll m=sum[n]-sum[i+1];
        while(m<0){
            m+=MOD;
        }
        ans+=a[i]*m;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    double n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    double mn=min({a,b,c,d,e});
    ll ans=ceil(n/mn)+4;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var n = parseInt(input[0], 10);
    var f = new Array(n);
    for (var i = 0; i < n; i++) {
        f[i] = new Array(10);
        var args = input[1 + i].split(' ');
        for (var j = 0; j < 10; j++) {
            f[i][j] = parseInt(args[j], 10);
        }
    }
    var p = new Array(n);
    for (var i = 0; i < n; i++) {
        p[i] = new Array(10);
        var args = input[1 + n + i].split(' ');
        for (var j = 0; j < 10; j++) {
            p[i][j] = parseInt(args[j], 10);
        }
    }

    var ret = Number.MIN_SAFE_INTEGER;
    for (var i = 1; i < 1024; i++) {
        var cc = 0;
        for (var j = 0; j < n; j++) {
            var c = 0;
            for (var k = 0; k < 10; k++) {
                if ((i >> k & 1) == 1 && f[j][k] > 0) {
                    c++;
                }
            }
            cc += p[j][c];
        }
        if (ret < cc) {
            ret = cc;
        }
    }

    console.log(ret);

    return 0;
}



Measured memory_bytes: 21320
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, m;
  cin >> n >> m;
  vi32 cnt(m);
  rep(i, n) {
    int k;
    cin >> k;
    rep(_, k) {
      int a;
      cin >> a;
      a--;
      cnt[a]++;
    }
  }
  int ans = 0;
  rep(i, m) {
    if (cnt[i] == n) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define M_DEBUG if (1)
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
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; }


/******************************************************************************
	typedef
******************************************************************************/
using lint = long long;
typedef unsigned long long int ullint;

/******************************************************************************
	Main
******************************************************************************/
int main()
{
    long double l = -1.0;
    cin >> l;
    assert(l >= 1.0 && l <= 1000.0);

    long double r = l / 3.0;
	cout << std::fixed << std::setprecision(12) << pow(r, 3) << endl;

	return 0;
}


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

using namespace std;

int main()
{
   int A, B, C;
   int K;
   cin >> A >> B >> C;
   cin >> K;

   int k = 1;
   for (int i = 0; i < K; i++){
       k *= 2;
   }

    int ans = max ({
        k * A + B + C,
        A + k * B + C,
        A + B + k * C,
    });
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=2e5+5;
int n,q,a,b,X[N];

ll abs(ll x) {return (x<0)?-x:x;}
template <typename _Tp> inline void IN(_Tp&x) {
    char ch;bool flag=0;x=0;
    while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    if(flag) x=-x;
}

struct Segment_Tree {
    #define mid ((l+r)>>1)
    #define lc(x) ((x)<<1)
    #define rc(x) ((x)<<1|1)
    ll f[N<<2][3],tag[N<<2];
    void add(int x,ll v) {f[x][0]+=v,f[x][1]+=v,f[x][2]+=v,tag[x]+=v;}
    void pushdown(int x) {add(lc(x),tag[x]),add(rc(x),tag[x]),tag[x]=0;}
    void pushup(int x) {
        f[x][0]=min(f[lc(x)][0],f[rc(x)][0]),
        f[x][1]=min(f[lc(x)][1],f[rc(x)][1]),
        f[x][2]=min(f[lc(x)][2],f[rc(x)][2]);
    }
    void init(int x,int l,int r) {
        f[x][0]=f[x][1]=f[x][2]=1e18;
        if(l!=r) init(lc(x),l,mid),init(rc(x),mid+1,r);
    }
    void update(int x,int l,int r,int pos,ll val) {
        if(l==r) {f[x][0]=val,f[x][1]=val+l,f[x][2]=val-l;return void();}
        if(tag[x]) pushdown(x);
        (pos<=mid)?update(lc(x),l,mid,pos,val):update(rc(x),mid+1,r,pos,val);
        pushup(x);
    }
    ll query(int x,int l,int r,int L,int R,int op) {
        if(L==l&&r==R) return f[x][op];
        if(tag[x]) pushdown(x);
        if(R<=mid) return query(lc(x),l,mid,L,R,op);
        else if(L>mid) return query(rc(x),mid+1,r,L,R,op);
        else return min(query(lc(x),l,mid,L,mid,op),query(rc(x),mid+1,r,mid+1,R,op));
    }
}Tree;

int main() {
    IN(n),IN(q),IN(a),IN(b);
    for(int i=1;i<=q;++i) IN(X[i]);
    Tree.init(1,1,n);
    Tree.update(1,1,n,a,abs(b-X[1])),Tree.update(1,1,n,b,abs(a-X[1]));
    for(int i=2;i<=q;++i) {
        ll _1=Tree.query(1,1,n,X[i-1],X[i-1],0)+abs(X[i]-X[i-1]);
        ll _2=Tree.query(1,1,n,1,X[i],2)+X[i];
        ll _3=Tree.query(1,1,n,X[i],n,1)-X[i];
        ll res=min(_1,min(_2,_3));
        Tree.add(1,abs(X[i]-X[i-1])),Tree.update(1,1,n,X[i-1],res);
    }
    printf("%lld\n",Tree.f[1][0]);
    return 0;
}

Measured memory_bytes: 21504
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, d, pos, cnt;
int main() {
    IOS
    cin >> n >> d;
    pos = d*2+1;
    cnt = 1;
    while (pos < n) {
        pos += d*2+1;
        cnt++;
    }
    cout << cnt << endl;


    return 0;


}


Measured memory_bytes: 256
#include<iostream>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
using namespace std;
typedef long long ll;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c;
	cin>>a>>b>>c;
	if (((a == b) + (a == c) + (b == c)) == 1) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) < TMPend; (i)++)
#define RFOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) >= TMPend; (i)--)
#define REP(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

long long dp[50 + 1][50 + 1][50 * 50 + 1];
int x[50];

long long dfs(int j, int k, int s) {
  if(dp[j][k][s] != -1) return dp[j][k][s];
  if(j == 0 && k == 0 && s == 0) return dp[0][0][0] = 1;

  long long result = 0;
  if(j >= 1) {
    if(x[j - 1] > s) {
      result = dfs(j - 1, k, s);
    } else if(k >= 1) {
      result = dfs(j - 1, k, s) + dfs(j - 1, k - 1, s - x[j - 1]);
    }
  }
  return dp[j][k][s] = result;
}

int main(){
  rep(i, 50 + 1) rep(j, 50 + 1) rep(k, 50 * 50 + 1) {
    dp[i][j][k] = -1;
  }

  int input(n, a);
  rep(i, n) cin >> x[i];

  long long sum = 0;
  FOR(k, 1, n + 1) {
    sum += dfs(n, k, k * a);
  }
  cout << sum << endl;
}


Measured memory_bytes: 51072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	double w,h,x,y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(9) << (w*h)/2 << " ";
	if(w/2==x and h/2==y)
		cout << 1 << endl;
	else 
		cout << 0 << endl;

	
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

int A;
int K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> K;
    cin >> A;

    cout << (K/A + min(K%A,1)) << endl;
    

}

Measured memory_bytes: 256
import itertools
import collections
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = [0] + list(itertools.accumulate(A))
d = collections.defaultdict(int)
for i in B:
    d[i%M] += 1
d = list(d.values())
ans = 0
for i in d:
    ans += i*(i-1)//2
print(ans)

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template< typename T >
int64_t largest_rectangle(vector< T > height)
{
  stack< int > st;
  height.push_back(0);
  vector< int > left(height.size());
  int64_t ret = 0;
  for(int i = 0; i < height.size(); i++) {
    while(!st.empty() && height[st.top()] >= height[i]) {
      ret = max(ret, (int64_t) (i - left[st.top()]) * (height[st.top()] + 1));
      st.pop();
    }
    left[i] = st.empty() ? -1 : st.top();
    st.emplace(i);
  }
  return (ret);
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int h, w; cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;++i) {
    cin >> s[i];
  }

  vvi par(h-1, vi(w-1));
  for(int i=0;i<h-1;++i) {
    for(int j=0;j<w-1;++j) {
      par[i][j] = (s[i][j] == '#') ^ (s[i+1][j] == '#') ^ (s[i][j+1] == '#') ^ (s[i+1][j+1] == '#');
    }
  }

  vvi hist(h-1, vi(w-1));
  for(int i=0;i<w-1;++i) {
    hist[0][i] = !par[0][i];
    for(int j=1;j<h-1;++j) {
      if(par[j][i]) {
        hist[j][i] = 0;
      } else {
        hist[j][i] = hist[j-1][i] + 1;
      }
    }
  }

  int64_t ans = max(h, w);
  for(int i=0;i<h-1;++i) {
    ans = max(ans, largest_rectangle(hist[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 35968
sx,sy,tx,ty = map(int,input().split())

x1 = tx-sx
y1 = ty-sy
print("U"*y1+"R"*x1+"D"*y1+"L"*x1+"L"+"U"*(1+y1)+"R"*(1+x1)+"D"+"R"+"D"*(1+y1)+"L"*(1+x1)+"U")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int N;
string S;

int main()
{
    cin >> N >> S;

    vector<string> v1, v2;
    for (lint i = 0; i < 1 << N; i++)
    {
        string tmp1, tmp2, tmp3, tmp4;
        for (int d = 0; d < N; d++)
        {
            if ((i>>d) & 1)
            {
                tmp1 += S[d];
                tmp3 += S[2 * N - 1 - d];
            }
            else
            {
                tmp2 += S[d];
                tmp4 += S[2 * N - 1 - d];
            }
        }
        reverse(tmp2.begin(), tmp2.end());
        reverse(tmp4.begin(), tmp4.end());
        v1.push_back(tmp1 + "_" + tmp2);
        v2.push_back(tmp3 + "_" + tmp4);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    lint ans = 0;
    for (auto val : v1)
    {
        ans += distance(lower_bound(v2.begin(), v2.end(), val), upper_bound(v2.begin(), v2.end(), val));
    }
    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int btn[100000];
    bool pushed[100000];

    for (int i = 1; i <= N; ++i) {
        cin >> btn[i];
        pushed[i] = false;
    }

    int btn_on = 1;
    int count = 0;

    while (btn_on != 2) {
        count += 1;
        pushed[btn_on] = true;
        btn_on = btn[btn_on];
        if (pushed[btn_on] == true) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>//?????§?????????
#define N 500000

void max(int);
void build(void);
void printout(void);
int count,i;
int A[N];

int main() {
 int i;
 
  scanf("%d", &count);
  for( i=0 ; i<count ; i++ ) scanf("%d", &A[i]);
  build( );
  printout( );
  return 0;
}

void max( int j ){
  int largest,small;    
    if( 2*j+1<=count && A[2*j+1]>A[j] ) largest = 2*j+1;
    else largest = j;
    if( 2*j+2<=count && A[2*j+2]>A[largest] ) largest = 2*j+2;
    if( largest!=j ){
      small = A[largest];
      A[largest] = A[j];
      A[j] = small;
      max( largest );
    }
}

void build( ){
  int j;
  for( j=count/2-1 ; j>=0 ; j-- ) max(j);  
}

void printout( ){
  for( i=0 ; i<count ; i++ ) printf(" %d",A[i]);
  printf("\n");
}

Measured memory_bytes: 2552
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s[3];
	string ans="";
	rep(i,3){
		cin>>s[i];
		ans+=(char)(s[i][0]-'a'+'A');
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

struct nod{
	int x, y;
	nod(int x_,int y_): x(x_), y(y_){};
};

bool operator<(nod & a, nod & b){
  return a.y < b.y;
}

char tab[207][207];

vector<string> printVertically(string s) {
	for(int i = 0; i < 207; i++){
		for(int j = 0; j < 207; j++)
			tab[i][j] = ' ';
	}
	s += "$";
	vector<string> v;
	int r = 1,c = 1;
	for(int i = 0; i < (int)s.size(); i++){
		
		c = 1;
		while( s[i] != ' ' && s[i] != '$'){
			
			tab[r][c] = s[i];
			i++;
			c++;
			
		}
		r++;
	
	}
	
	for(int i = 1; i < 207; i++){
		string str = "";
		bool flag = false;
		for(int j = 206; j >= 1; j--){
			if(tab[j][i] != ' ')
				flag = true;
			if(flag){
				str+= tab[j][i];
			}
		}
		if(str.size() > 0){
			reverse(str.begin(),str.end());
			v.push_back(str);
		}
		
	}
	
	for(string x: v)
		cout<<x<<"-"<<endl;
	return v;
}
    
//~ int main(){
	
	//~ int n, m; cin>> n >> m;
	//~ if(n <= m){
		//~ cout<<"Yes";
	//~ }
	//~ else
		//~ cout<<"No";
	//~ return 0;
//~ }

int main(){
	int a, b; cin>> a >> b;
	if(a > b){
		for(int i = 0; i < a; i++)
			cout<<b;
	}
	else {
		for(int i = 0; i < b; i++){
			cout<<a;
		}
	}
	
	return 0;
}


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

int main(){
  const int denomi = 1000000000+7;
  long int power=1;
  //整数入力
  int n;
  cin >> n;

  //大きい順にかけないとオーバーフロー起こす可能性あり
  for(int i=n; i>=1; i--){
    while(power>denomi){
      power-=denomi;
    }
    power*=i;
  }
  
  cout << power << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

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

    int max = 0;
    for (int i = 0; i < str.size(); i++) {
        int cnt = 0;
        for (int j = i; j < str.size(); j++) {
            if (str[j] == 'A' || str[j] == 'C' || str[j] == 'G' || str[j] == 'T') cnt++;
            else break;
        }
        if (max < cnt) max = cnt;
    }
    cout << max << endl;
}


Measured memory_bytes: 256
f1, n1 = (int(x) for x in input().split())
f2, n2 = (int(x) for x in input().split())
f3, n3 = (int(x) for x in input().split())
f4, n4 = (int(x) for x in input().split())

if f1 == 1:
    print(6000*n1)
if f1 == 2:
    print(4000*n1)
if f1 == 3:
    print(3000*n1)
if f1 == 4:
    print(2000*n1)
    
if f2 == 1:
    print(6000*n2)
if f2 == 2:
    print(4000*n2)
if f2 == 3:
    print(3000*n2)
if f2 == 4:
    print(2000*n2)

if f3 == 1:
    print(6000*n3)
if f3 == 2:
    print(4000*n3)
if f3 == 3:
    print(3000*n3)
if f3 == 4:
    print(2000*n3)
    
if f4 == 1:
    print(6000*n4)
if f4 == 2:
    print(4000*n4)
if f4 == 3:
    print(3000*n4)
if f4 == 4:
    print(2000*n4)


Measured memory_bytes: 5612
/*author : Yashvardhan
Tuesday, April 07, 2020
8:30 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int l;
	cin >> l;
	
	double val = (double) l / (double) 3;
	double maxi = val * val * val;

	cout << setprecision(10) << fixed;
	cout << maxi << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String S = input.next();
		int N = S.length();
		int[] ans = new int[N];
		int curIndex = 0;
		while (curIndex < N) {
			int numLeft = 0;
			int numRight = 0;
			while (S.charAt(curIndex)=='R') {
				numRight++;
				curIndex++;
				if (curIndex==N) break;
			}
			//curIndex--; //After last ever L/R, curIndex is incremented which causes array 
			//out of bounds
			int R = curIndex-1;
			while (S.charAt(curIndex)=='L') {
				numLeft++;
				curIndex++;
				if (curIndex==N) break;
			}
			int left = numLeft;
			int right = numRight;
			if ((left+right)%2==0) { //Children cascade into adjacent numbers as close to 
				//each other as possible
				int sum = left+right;
				left=sum/2;
				right=sum/2;
			}else {
				int sum = left+right;
				if (right%2==1) { //The greater number is given to the R/L count with odd parity
					right=sum/2;
					left=sum-right;
				}else {
					left=sum/2;
					right=sum-left;
				}
			}
			ans[R]=left;
			ans[R+1]=right; //Children moving swaps squares 
			if (curIndex==N-1) break;
		}
		for (int i = 0; i < N; i++)
			System.out.print(ans[i]+" ");
	}
}

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

#define ll long long 

ll dp[3005][3005][2]; //limit to check if 0 then turn of X else turn of y 
ll ans(int i, int j, int arr[], bool limit){
	if(i > j)
		return 0;
	if(dp[i][j][limit] != -1)
		return dp[i][j][limit];
	if(!limit){
		ll uno = ans(i+1, j, arr, !limit) + arr[i];
		ll dos = ans(i, j-1, arr, !limit) + arr[j];
		return dp[i][j][limit] = max(uno, dos);
		}
	else{
		ll uno = ans(i+1, j, arr, !limit) - arr[i];
		ll dos = ans(i, j-1, arr, !limit) - arr[j];
		return dp[i][j][limit] = min(uno, dos);
		}
		
	}


int main(){
	memset(dp, -1, sizeof(dp));
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0; i<n; i++){
		cin>>arr[i];
		}
	cout << ans(0, n-1, arr, 0) << endl;
	
	return 0;
	}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string S;
    int s=0, e=0, i, j;
    cin >> S;
    for (i=0; i<S.size(); i++){
        if(S[i]=='A'){
            s=i;
            break;
        }
    }
    for(j=S.size(); j>=i; j--){
        if(S[j]=='Z'){
            e=j;
            break;
        }
    }
    cout << e - s + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = 0;
    ll K;
    cin >> K;
    for(ll a = 1; a <= K; a++) {
        for(ll b = 1; b <= K; b++) {
            for(ll c = 1; c <= K; c++) {
                ll g = __gcd(a, b);
                g = __gcd(g, c);
                ans += g;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b+c||b==a+c||c==a+b)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main(){
  set<int> st;
  int n, k, d, a;
  cin >> n >> k;
  for(int m=0; m<k; m++){
    cin >> d;
    int tmp = 0;
    for(int i=0; i<d; i++){
      cin >> a;
      st.insert(a);
    }
  }
  
  cout << n - st.size() << endl;

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  int b[m][n];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cin >> b[i][j];
    }
  }

  int score[n];
  for (int i = 0; i < n; i++) {
    score[i] = 0;
  }

  for (int i = 0; i < m; i++) {
    int target = a[i];
    int wrong = n;
    for (int j = 0; j < n; j++) {
      if (b[i][j] == target) {
	score[j]++;
	wrong--;
      }
    }
    score[target - 1] += wrong;
  }

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

Measured memory_bytes: 3108
from functools import reduce
from math import gcd, sqrt,ceil


n = int(input())
a = list(map(int,input().split()))
m = 10**6

a_gcd = reduce(gcd,a)
if a_gcd != 1:
    print("not coprime")
    exit(0)
isset = a_gcd == 1
hurui = [i for i in range(m+1)]
for i in range(2,ceil(sqrt(m))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,m,i):
            if hurui[k] != k:
                continue
            hurui[k] = i
    continue
s = set()
p_f = True
for ai in a:
    t = set()
    while(ai > 1):
        t.add(hurui[ai])
        ai //= hurui[ai]
    for ti in t:
        if ti in s:
            print("setwise coprime")
            exit(0)
        else:
            s.add(ti)

print("pairwise coprime")

Measured memory_bytes: 127764
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 100000001
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int dp[120][1050];

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    //double mini=INF;
    int maxi=0,f=0,sum=0,mini=INF;
    string str,str1,str2;
    int i;
    int n;
    int a,b,d,c;
    int e,weight;
    cin>>str>>str1;
    rep(i,str.length()){
        char temp=str[str.length()-1];
        for(ll j=str.length()-1;j>=1;j--){
            str[j]=str[j-1];
        }
        str[0]=temp;
        if(str==str1){
            Yes;
            return 0;
        }
        //cout<<str<<endl;
    }
    No;

    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,ans = 0;
    cin >> h >> w;
    int c[10][10],a[h][w];
    for(int i = 0;i < 10;i ++){
        for(int j = 0;j < 10;j ++){
            cin >> c[i][j];
        }
    }
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cin >> a[i][j];
        }
    }
    for(int k = 0;k < 10;k ++){
        for(int i = 0;i < 10;i ++){
            for(int j = 0;j < 10;j ++){
                if(c[i][j]>c[i][k]+c[k][j])c[i][j]=c[i][k]+c[k][j];
            }
        }
    }
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            if(a[i][j]==-1) continue;
            else ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void) {
    char op;
    int x, y;
    while(1) {
        scanf("%d %c %d", &x, &op, &y);
        if(op == '?') {
            break;
        }else if(op == '+') {
            printf("%d\n", x + y);
        }else if(op == '-') {
            printf("%d\n", x - y);
        }else if(op == '*') {
            printf("%d\n", x * y);
        }else if(op == '/') {
            printf("%d\n", x / y);
        }else{
        }
    }
    return 0;
}
    



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <queue>

struct Edge {
    int u, v;

    Edge(int from, int to)
    {
        u = from;
        v = to;
    }

    bool operator<(const Edge &another) const
    {
        return (u != another.u)?(u < another.u):(v < another.v);
    }
};

int main(int argc, char *argv[])
{
    int n, m;
    int s, t;
    std::vector<Edge> e, f;

    // input
    std::cin >> n >> m;
    e.reserve(m);

    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        e.push_back(Edge(u - 1, v - 1));
    }
    
    std::cin >> s >> t;
    s--;
    t--;

    f.reserve(3 * m);

    for (int i = 0; i < m; i++) {
        const auto u = e[i].u;
        const auto v = e[i].v;
        f.push_back(Edge(u        , v +     n)); // L1 -> L2
        f.push_back(Edge(u +     n, v + 2 * n)); // L2 -> L3
        f.push_back(Edge(u + 2 * n, v        )); // L3 -> L1
    }

    std::sort(f.begin(), f.end());

    // make index
    std::vector<int> f_index(3 * n + 1, 0);
    int fPtr = 0;
    for (int i = 0; i <= 3 * n; i++) {
        while(fPtr < f.size() && f[fPtr].u < i) {
            fPtr++;
        }
        f_index[i] = fPtr;
    }

    // search
    std::vector<int> nodeDist(3 * n, INT_MAX);
    std::queue<int> q;

    q.push(s);
    nodeDist[s] = 0;
    while(!q.empty()) {
        const auto currentNode = q.front();
        q.pop();

        const auto currentDist = nodeDist[currentNode];
        const auto indexStart = f_index[currentNode];
        const auto indexEnd = f_index[currentNode + 1];
        for (int i = indexStart; i < indexEnd; i++) {
            const auto nextNode = f[i].v;
            if (nextNode == t) {
                const auto nextDist = currentDist + 1;
                std::cout << (nextDist / 3) << std::endl;
                return 0;
            }
            if (nodeDist[nextNode] > currentDist + 1) {
                nodeDist[nextNode] = currentDist + 1;
                q.push(nextNode);
            }
        }
    }

    std::cout << -1 << std::endl;

    return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int dp[42][410][410];
int a[42],b[42],c[42];
int n,ma,mb;

int main()
{
	//give the fucking vjudge a flying flying fucking ♂ 
	scanf("%d%d%d",&n,&ma,&mb);
	memset(dp,0x3f,sizeof(dp));
	for(int i=0; i<n; i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	dp[0][0][0]=0;
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<=400; j++)
		{
			for(int k=0; k<=400; k++)
			{
				if(dp[i][j][k]==inf)
				{
					continue;
				}
				dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}
	int ans=inf;
	for(int i=1;i<=400;i++)
	{
		for(int j=1;j<=400;j++)
		{
			if(i*ma==j*mb)
			{
				ans=min(ans,dp[n][j][i]);
			}
		}
	}
	printf("%d\n",ans>=inf?-1:ans);
}

Measured memory_bytes: 27776
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 07, 2020 5:41 PM
 *    Problem Name  : D - Knapsack 1
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_d
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

ll knapsack(ll n, ll capacity, ll profit[], ll weight[])
{
	ll mat[n+1][capacity+1];
	for(ll i=0; i<=n; i++){
		for(ll j=0; j<=capacity; j++){
			if(i==0 || j==0){
				mat[i][j] = 0;
			}
			else if(weight[i-1]<=j){
				mat[i][j] = max(profit[i-1] + mat[i-1][j-weight[i-1]], mat[i-1][j]);
			}
			else{
				mat[i][j] = mat[i-1][j];
			}
		}
	}
	return mat[n][capacity];

}

int main(){
    ios_base::sync_with_stdio(false);

    ll n, capacity;
    cin >> n >> capacity;

    ll weight[n] , profit[n];

    for(ll i=0; i<n; i++){
        cin >> weight[i] >> profit[i];
    }
    
    cout << knapsack(n,capacity,profit,weight) << endl;

    return 0 ;
}


Measured memory_bytes: 82384
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll=long long;

int main(){
	ll MAX=1000000000,s[10010],t[10010];
	int n;
	ll a[10010],c[10010];
	int tmps=0,ans=0;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[i]=a[i];
		s[i]=t[i]=0;
	}
	t[n]=MAX;
	for(int i=0;i<n;i++){
		while(c[i]%2==0)t[i]++,c[i]/=2;
		ans+=t[i];
	}
	cout<<ans;
}

		

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxS=1e5+5;
int main()
{
        int n;
        cin>>n;
        double t,a;
        cin>>t>>a;
        double arr[n];
        double mn=1e9;
        int pos=0;
        for(int i=0;i<n;i++)
        {
                cin>>arr[i];
                double temp=t-arr[i]*0.006;
                if(abs(temp-a)<mn)
                {
                        mn=abs(temp-a);
                        pos=i+1;
                }
        }
        cout<<pos<<endl;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  string s, t; cin >> s >> t;
  if(t.substr(0, sz(s)) == s)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# 整数の入力
N = int(input())
#配列の入力
A = list(map(int, input().split()))
nmin = A[0]
su = 0
for ai in A:
    if ai < nmin:
        su += nmin - ai
    else:
        nmin = ai

print(su)

Measured memory_bytes: 33736