akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m; cin >> n >> m;
	vector<int> x(m);
	for( auto &v : x ) cin >> v;
	if( n >= m ){
		cout << 0 << endl;
		return 0;
	}
	sort( x.begin(), x.end() );
	int diff = abs( x[m-1] - x[0] );
	vector<int> d;
	for( int i = 0; i < m-1; ++i ){
		d.push_back( abs( x[i+1] - x[i] ) );
	}
	sort( d.begin(), d.end(), greater<int>() );
	for( int i = 0; i < n-1; ++i  ){
		diff -= d[i];
	}
	cout << diff << endl;
	return 0;
}

Measured memory_bytes: 1276
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
   int64_t l,r,k,idx=0;
   cin>>l>>r>>k;
   for(int i=l;i<=r;i++){
        if(i%k==0){idx++;}
   }
   cout<<idx<<endl;
}
int main()
{
    FOR(i,R){solution();}
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
//------------------------------------------------------------------//
typedef long long ll;
typedef vector<int> vi;
template <typename T> inline T read() {
	bool f = 1; T x = 0; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = !f;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f ? x : -x;
}
#define gi read<int>()
#define gl read<ll>()
//------------------------------------------------------------------//

const int N = 2e5 + 5, P = 1e9 + 7;
int n, k, A[N]; 
bool cmp(int x, int y) {
	return abs(x) > abs(y);
}
int sign(int x) {
	if (x > 0) return 1;
	else if (x == 0) return 0;
	else return -1;
}
bool unsatisfied(int x, int y) {
	if (x < 1 || x > n || y < 1 || y > n) return 1;
	return 0;
}
int main() {
//	freopen ("test.in", "r", stdin);
	n = gi, k = gi;
	int num = 0;
	for (int i = 1; i <= n; ++i) A[i] = gi, num += (sign(A[i]) == -1);
	sort (A + 1, A + n + 1, cmp);
	if (num == n && (k & 1)) {
		int ans = 1, neg = 1;
		for (int i = n - k + 1; i <= n; ++i) ans = (ll) ans * (P + A[i]) % P;
		cout << ans << '\n';
		return 0;
	}
	sort (A + 1, A + n + 1, cmp);
	int ans = 1;
	int sg = 1;
	for (int i = 1; i <= k; ++i) ans = (ll) ans * (A[i] + P) % P, sg *= sign(A[i]);
	if (sg == 1) {
		cout << ans << '\n';
		return 0;
	} else {
		if (k == n) return cout << ans, 0;
		int i, j;
		for (i = k; i >= 1; --i) if (sign(A[i]) == -1) break;
		for (j = k + 1; j <= n; ++j) if (sign(A[j]) != -1) break;
		int ii, jj;
		for (ii = k; ii >= 1; --ii) if (sign(A[ii]) != -1) break;
		for (jj = k + 1; jj <= n; ++jj) if (sign(A[jj]) == -1) break;
		int III, JJJ;
		if (unsatisfied(i, j) || (!unsatisfied(ii, jj) && (ll)abs((ll)A[jj] * A[i]) >= (ll)abs((ll)A[j] * A[ii])))
			III = ii, JJJ = jj;
		else III = i, JJJ = j;
		i = III, j = JJJ;
		ans = 1;
		for (int I = 1; I <= k; ++I) if (I != i) ans = (ll) ans * (A[I] + P) % P; 
		ans = (ll) ans * (A[j] + P) % P;
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 4396
def is_palindrome(s):
  if s == s[::-1]:
    return True
  else:
    return False
  
s = input()
if is_palindrome(s) and is_palindrome(s[:len(s)//2]) and is_palindrome(s[len(s)//2+1:]):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
     
int main(void){
  char O[51], E[51], A[102];
  int i;
     
  scanf("%s", O);
  scanf("%s", E);
     
    for(i = 0; i < 51; i++){
      A[i * 2] = O[i];
      A[i * 2 + 1] = E[i];
    }
      
    printf("%s\n", A);
     
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
 
    int cou = 0;
    for(int i=0; i<=x; i++){
        if(y == i*2+(x-i)*4){
            cou++;   
        }        
}
        if(cou>0){
       	System.out.println("Yes");
        }else{
        System.out.println("No");
    }
}
}


Measured memory_bytes: 35740
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        if (h == 1 || w == 1) {
            System.out.println(1);
            return;
        }
        System.out.println((h * w + 1) / 2);
    }

}


Measured memory_bytes: 21844
const gInput = require('fs').readFileSync('/dev/stdin', 'utf8')
const input = gInput.split('\n').map( x => parseInt(x))

var id = 1
for(var i =0 ;i<input.length;i++){
    if( input[i] == 0){ break }
    process.stdout.write(`Case ${id}: ${input[i]}\n`)
    id++
}


Measured memory_bytes: 22256
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

int n,m;
int cnt[maxn];
bool solved[maxn];
int num,penalty;
char s[10];

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1,idx;i<=m;i++)
	{
		scanf("%d%s",&idx,s);
		if(s[0]=='W')
		{
			cnt[idx]++;
		}
		else if(!solved[idx])
		{
			solved[idx]=1;
			num++;
			penalty+=cnt[idx];
		}
	}
	printf("%d %d\n",num,penalty);
	return 0;
}


Measured memory_bytes: 768
def calc(N,X):
    if N%X ==0:
        return 3*N
    else:
        return 3*X*(int(N/X)) + calc(X,N-X*(int(N/X)))


N,X = list(map(int, input().split()))
X = min(X,N-X)
ans = calc(N-X,X)
print('%s' % str(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    bool flag = true;
    rep(i,n){
        if(s[i]%10 != 0){
            flag = false;
        }
    }
    if(flag) {
        cout << 0 << endl;
        return 0;
    }

    int total = 0, min = 0;
    rep(i,n) total += s[i];
    sort(s.begin(), s.end());
    rep(i,n){
        if(s[i]%10 != 0){
            min = s[i];
            break;
        }
    }
    if(total%10 != 0) cout << total << endl;
    else cout << total - min << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    cout << min(a,b) + min(c,d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
    ll a[3];
    cin>>a[0]>>a[1]>>a[2];
    ll sum = a[0]+a[1]+a[2];
    if(sum>=22){
      cout<<"bust"<<endl;
    }
    else{
      cout<<"win"<<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int _=1;
    //cin>>_;
    while(_--)
    {
        ll n,x,y;
        cin>>n>>x>>y;
        vector<ll> v[n+5];
        for(ll i=1;i<n;i++)
        {v[i].push_back(i+1); v[i+1].push_back(i);}
        v[x].push_back(y);
        v[y].push_back(x);
        ll ans[n+100]={0};
        ll level[n+5];
        bool vis[n+5];
        for(ll i=0;i<n+5;i++)
        { level [i]=0;vis[i]=false;}
        for(ll s=1;s<=n;s++)
        {
        queue <ll> q;
        q.push(s);
        level[ s ] = 0 ; 
        vis[ s ] = true;
        while(!q.empty())
        {
            int p = q.front();
            q.pop();
            for(int i = 0;i < v[ p ].size() ; i++)
            {
                if(vis[ v[ p ][ i ] ] == false)
                {   level[ v[ p ][ i ] ] = level[ p ]+1;
                    ans[level[v[p][i]]]++;             
                    q.push(v[ p ][ i ]);
                    vis[ v[ p ][ i ] ] = true;
                }
            }
        }
        for(ll i=1;i<n+4;i++)
        { level [i]=0;vis[i]=false;}
        }
        for(ll i=1;i<=n-1;i++)
            cout<<ans[i]/2<<endl;
    }
    return 0;
}

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

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

// namespace utils
namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    rep (i, mat.size()) {
      rep (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    rep (i, v.size()) cout << v[i] << ' ';
    cout << endl;
  }
}
// end namespace utils

class Heap {

  public:
    Heap(int H) {
      W.resize(H+1);
    }

    vector<int> W;
    bool check(int);
    void maxHeapify(int);
    void buildHeap();
    int parent(int);
    int left(int);
    int right(int);
};


bool Heap::check(int i) {
  if (1 <= i && i < (int)W.size()+1) return true;
  else return false;
}

void Heap::buildHeap() {
  for (int i=((int)W.size()-1)/2; i>0; i--) {
    maxHeapify(i);
  }
}

void Heap::maxHeapify(int i) {
  int l = left(i);
  int r = right(i);

  int largest;
  if (l <= (int)W.size()-1 && W[l] > W[i]) largest = l;
  else largest = i;
  if (r <= (int)W.size()-1 && W[r] > W[largest]) largest = r;

  if (largest != i) {
    swap(W[i], W[largest]);
    maxHeapify(largest);
  }
}

int Heap::parent(int i) {
  return i/2;
}

int Heap::left(int i) {
  return i*2;
}

int Heap::right(int i) {
  return i*2+1;
}


int main() {
  int H;
  vector<int> W;

  cin >> H;
  Heap heap = Heap(H);

  rep (i, H) cin >> heap.W[i+1];
  // utils::print(heap.W);
  heap.buildHeap();
  for (int i=1; i<H+1; i++) {
    cout << " " << heap.W[i];
  }
  cout << endl;

}

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

using namespace std;

const int maxn = 2e5+5;

long long tree[4 * maxn];

void update(int in, int l, int r, int h, long long val) {
	tree[in] = max(tree[in], val);
	if(l==r) {
		return;
	}
	int mid = (l+r)/2;
	if(h<=mid) {
		update(2*in, l, mid, h, val);
	} else {
		update(2*in+1, mid+1, r, h, val);
	}
}

long long query(int in, int l, int r, int ql, int qr) {
	if(ql<=l && r<=qr) {
		return tree[in];
	}
	int mid = (l+r)/2;
	if(qr<=mid) {
		return query(2*in, l, mid, ql, qr);
	}
	if(ql>mid) {
		return query(2*in+1, mid+1, r, ql, qr);
	}
	return max(
		query(2*in, l, mid, ql, qr),
		query(2*in+1, mid+1, r, ql, qr)
	);
}

int main() {
	int n;
	scanf("%d", &n);

	int h[n];
	for(int i=0; i<n; i++) {
		scanf("%d", &h[i]);
	}
	long long a[n];
	for(int i=0; i<n; i++) {
		scanf("%lld", &a[i]);
	}
	
	update(1, 1, n, h[0], a[0]);
	for(int i=1; i<n; i++) {
		long long len_sum = query(1, 1, n, 1, h[i]);
		len_sum += a[i];
		update(1, 1, n, h[i], len_sum);
	}
	printf("%lld\n", query(1, 1, n, 1, n));
    return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int beki(int K){
  if(K==0) return 1;
  else return 2*beki(K-1);
}

int main(){
  	int N, X;
  	cin >> N >> X;

  	int m[N];

  	int minimun = 100000;
  	int sum = 0;
  	for(int i=0;i<N;i++){
  		cin >> m[i];
  		minimun = min(minimun, m[i]);
  		sum += m[i];
  	}

  	cout << (X-sum)/minimun + N <<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        final double a = sc.nextDouble();
        final double b = sc.nextDouble();
        final double n = sc.nextDouble();

        System.out.println((int)(Math.floor(a*Math.min(b-1, n)/b) - a * Math.floor(Math.min(b-1, n)/b)));
    }
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> cant(n + 1);
    for (int i = 0; i < m; i++) {
        int tmp;
        cin >> tmp;
        cant[tmp] = true;
    }

    vector<int> dp(n + 1);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (cant[i])continue;
        dp[i] += dp[i - 1];
        if (i > 1)dp[i] += dp[i - 2];
        dp[i] %= (int) 1e9 + 7;
    }

    cout << dp[n] << endl;
    return 0;
}

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

int main ()
{
  int N ,T ,A ;
 
cin >> N >>T >> A ;
  vector<int> H (N);
int res =0;
int cc = 1 << 30;
for ( int i =0; i < N ; i ++)
{
cin >> H.at(i);
int d =( T *1000 - H.at(i) *6) - A *1000;
if (d <0) d = - d ;
if ( cc > d ) cc =d , res = i ;
}
cout << res+1 << endl;

}

Measured memory_bytes: 256
import math

if __name__ == '__main__':

	x = y = 0
	deg = 90

	while True:

		d,a = map(int,input().split(","))
		if d == 0 and a == 0:
			break

		x += math.cos(math.radians(deg)) * d
		y += math.sin(math.radians(deg)) * d

		deg -= a

	print(int(x))
	print(int(y))



Measured memory_bytes: 5712
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std; 
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 200000
long long int MOD=998244353;
long long int INF=1e18;
                                            /* :-] */
 
int main()
{
         ios_base::sync_with_stdio(false); 
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
         cin>>n>>m;
         long double k1,l1,m1;
         multiset<long double>ms;
           multiset<long double>::iterator it;
        long double A[n];
        for(i=0;i<n;i++)
        {
           cin>>A[i];
            ms.insert(-1*A[i]);
         }
    for(i=0;i<m;i++)
    {
        k1=*(ms.begin());
        ms.erase(ms.begin());
        k1=-1*k1;
        k1=k1/2;
        k1=k1*-1;
        ms.insert(k1);
    }
    for(it=ms.begin();it!=ms.end();it++)
    {
        k1=*it;
        k1=-1*k1;
        k=k1;
        cnt+=k;
    }
    cout<<cnt<<endl;
          
 
    
    
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define lb long double
const int N=1e4+10;
const int mod=10086;
const int mod2=19260811;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    string s;
    cin>>s;
    if(s[3]==s[2]&&s[4]==s[5]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char c1[5], c2[5];
	cin >> c1 >> c2;
	int ans = 0;
	for(int i=0; i<3; i++){
		if(c1[i]==c2[i])
			ans ++;
	}
	cout << ans;
	return 0;
} 

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N, M;
int X[100010], Y[100010];

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

	cin >> N >> M;
	rep(i, 0, N)cin >> X[i];
	rep(i, 0, M)cin >> Y[i];

	int xsum = 0, ysum = 0;

	rep(i, 0, N - 1)
	{
		int res = 1;
		res *= (X[i + 1] - X[i]);
		res %= MOD;
		res *= (i + 1);
		res %= MOD;
		res *= (N - i - 1);
		res %= MOD;
		xsum += res;
		xsum %= MOD;
	}

	rep(i, 0, M - 1)
	{
		int res = 1;
		res *= (Y[i + 1] - Y[i]);
		res %= MOD;
		res *= (i + 1);
		res %= MOD;
		res *= (M - i - 1);
		res %= MOD;
		ysum += res;
		ysum %= MOD;
	}

	cout << (xsum*ysum) % MOD << endl;


	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep0(i, n) for(int i = 0; i < (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    int x, n;
    vector<int> p;
    for(int i=0; i<=101; ++i){
        p.push_back(i);
    }
    cin >> x >> n;
    rep(i, n){
        int e;
        cin >> e;
        p.erase(remove(p.begin(), p.end(), e));
    }
    sort(p.begin(), p.end());
    for(int i=0; i<p.size()-1; ++i){
        if(!(p[i] <= x && x < p[i+1])){
            continue;
        }
        if (x - p[i] <= p[i+1] - x){
            printf("%d\n", p[i]);
            break;
        }
        else{
            printf("%d\n", p[i+1]);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3724
L = int(input())
aList = []
for _ in range(L):
    aList.append(int(input()))

dp = [0 for _ in range(5)]
for a in aList:
    outer = a % 2 if a > 0 else 2
    inner = (a + 1) % 2
    dp[4] = min(dp[:5]) + a
    dp[3] = min(dp[:4]) + outer
    dp[2] = min(dp[:3]) + inner
    dp[1] = min(dp[:2]) + outer
    dp[0] += a

print(min(dp))


Measured memory_bytes: 11040
#include<bits/stdc++.h>
using namespace std;
int main(){
  for(;;){
    int x, y; cin >> x >> y;
    if (x == 0 && y == 0) return 0;
    if (x <= y) cout << x << " " << y << endl;
    else cout << y << " " << x << endl;
  }
}


Measured memory_bytes: 3068
N, M = list(map(int, input().split()))
K = [[0 for _ in range(N)] for _ in range(M)]
for i in range(M):
    for x in list(map(int, input().split()))[1:]:
        K[i][x-1] = 1
p = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
    flag = True
    for m in range(M):
        _sum = 0
        for j in range(N):
            if i >> j & 1:
                _sum += K[m][j]
        if (_sum % 2) != p[m]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)




Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		if(a==b&&b==c)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}


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

using namespace std;

typedef long long int int64;

vector<char> arr;

void generate(int n, char maxi) {
	if(n == 0) {
		for(char c : arr)
			cout << c;
		cout << "\n";
		return;
	}
	for(char c = 'a'; c < maxi; c++) {
		arr.push_back(c);
		generate(n-1, maxi);
		arr.pop_back();
	}
	arr.push_back(maxi);
	generate(n-1, maxi + 1);
	arr.pop_back();
	return;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	generate(n, 'a');
    return 0;
}



Measured memory_bytes: 1536
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
   
   
public class Main {
	static int INF = 2 << 27;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] map = new char[h][w];
		for(int i = 0; i < h; i++) {
			map[i] = sc.next().toCharArray();
		}
		int[][] ans = new int[h][w];
		for(int i = 0; i < h; i++) {
			Arrays.fill(ans[i], -1);
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				for(int k = j; k >= 0; k--) {
					if(map[i][k] == 'c') {
						ans[i][j] = j - k;
						break;
					}
				}
			}
		}
		for(int i = 0; i < h; i++) {
			System.out.print(ans[i][0]);
			for(int j = 1; j < w; j++) {
				System.out.print(" " + ans[i][j]);
			}
			System.out.println();
		}
		
		
		
	}
	
}

Measured memory_bytes: 32916
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;


void main() {
	long dp[][][] = new long[][][](10, 101, 1001);
	//dp[i][j][k]: i個の数字の和で、最大の数がjで、ｋを作る場合の数
	for(int j = 0; j <= 100; ++j) {
		dp[1][j][j] = 1;
	}
	for(int i = 2; i < 10; ++i) {
		for(int j = 0; j <= 100; ++j) {
			for(int k = 0; k <= 1000; ++k) {
				if(k >= j) {
					for(int l; l < j; ++l) {
						dp[i][j][k] += dp[i-1][l][k-j];
					}
				}
			}
		}
	}
	while(true){
		auto ns = readln().strip().split();
		int n = to!int(ns[0]);
		int s = to!int(ns[1]);
		if((n|s) == 0)
			break;
		long sum = 0;
		for(int j = 0; j <= 100; ++j) {
			sum += dp[n][j][s];
		}
		writeln(sum);
	}
}

Measured memory_bytes: 10948
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<double, P> Tuple;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int NMAX = 8, VMAX = 30, INF = 100000;

int dist[VMAX][VMAX];
double dp[1 << NMAX][VMAX];
int ticket[NMAX];
int n, m, p, a, b;

Tuple T(double cost, int S, int v) {
  return Tuple(cost, P(S, v));
}

void init() {
  REP(i, m) REP(j, m) {
    dist[i][j] = INF;
  }

  REP(S, 1 << n) REP(v, m) {
    dp[S][v] = INF;
  }
}

void solve() {
  priority_queue<Tuple, vector<Tuple>, greater<Tuple> > q;
  REP(S, 1 << n) {
    dp[S][b] = 0;
    q.push(T(0, S, b));
  }

  while (!q.empty()) {
    int S = q.top().second.first;
    int v = q.top().second.second;
    double cost = q.top().first;
    q.pop();
    if (cost > dp[S][v]) continue;
    for (int t = 0; t < n; t++) {
      if ((S >> t) & 1) continue;
      for (int u = 0; u < m; u++) {
        if (dist[v][u] != INF and dp[S | (1 << t)][u] > cost + (double)dist[v][u] / ticket[t]) {
          dp[S | (1 << t)][u] = cost + (double)dist[v][u] / ticket[t];
          q.push(T(dp[S | (1 << t)][u], S | (1 << t), u));
        }
      }
    }
  }
}

int main() {
  while (cin >> n >> m >> p >> a >> b and n) {
    a--; b--;
    init();
    REP(i, n) {
      cin >> ticket[i];
    }
    REP(i, p) {
      
      int x, y, z;
      cin >> x >> y >> z;
      x--; y--;
      dist[x][y] = dist[y][x] = z;
    }

    solve();

    double ans = INF;

    REP(S, 1 << n) {
      ans = min(ans, dp[S][a]);
    }

    if (ans >= INF / 2) {
      cout << "Impossible" << endl;
    } else {
      printf("%.4f\n", ans);
    }
  }
}

Measured memory_bytes: 2164
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

void primeFac(uint64_t n, set<uint64_t>& v) {
    for(uint64_t i=2; i*i <= n; ++i) {
        if(n % i == 0) {
            v.insert(i);
            while(n % i == 0 && n > 0) {
//                cout << n << " / " << i << " = " << n/i << endl;
//                cout << i << " *= ";
                n /= i;
            }
        } 
    }
    if(n!=1) {
        v.insert(n);
    }
}

int main() {
    uint64_t A, B;
    cin >> A >> B;
    set<uint64_t> s1;
    set<uint64_t> s2;
    primeFac(A, s1);
    primeFac(B, s2);

#if 0
    cout << "s1 ";
    for(auto itr: s1) {
        cout << itr <<  ",";
    }
    cout << endl;
    cout << "s2 ";
    for(auto itr: s2) {
        cout << itr <<  ",";
    }
    cout << endl;
#endif

    vector<int> result;
    set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(result));
    cout << result.size() + 1u << endl;

    return 0;
}




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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

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

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a += b;
  c += d;
  if(a < c) cout << "Right" << endl;
  else if(a == c) cout << "Balanced" << endl;
  else cout << "Left" << endl;
}

Measured memory_bytes: 256
ans = []
while line = $stdin.gets.chomp
	data  = line.split(/ /).map( &:to_i )
	n = data[ 0 ]
	m = data[ 1 ]
	break if n == 0 && m == 0

	sum = Array.new( m, 0 )
	n.times{
		q= $stdin.gets.chomp.split(/ /).map( &:to_i )
		m.times{ |i|
			sum[ i ] += q[ i ]
		}
	}
	data2 = []
	m.times{ |i|
		data2 << [ i + 1, sum[ i ]]
	}
#	p data2
	ans << data2.sort{ |a,b| b[1] <=> a[1] }.map{ |e| e[ 0 ] }
end
ans.each{ |a|
	a.each_with_index{ |n,i|
		print ' ' if i > 0
		print n
	}
	puts
}


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

using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<str[0]<<endl;
        return 0;
    }
    int count=0;
    for(int i=0;i<str.length();i++)
    {
        if(str[i]=='1')count++;
        else break;
    }
    //cout<<"count "<<count<<endl;
    if(str[0]=='1'){
    if(n<=count)
    {
        cout<<1<<endl;
        return 0;
    }
    else cout<<str[count];
    return 0;
    }
    else
    {
        cout<<str[0];
    }
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

struct Point {
	int x, y;
	Point(int X, int Y):x(X), y(Y) {}
};

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vector<Point> pts = vector<Point>();
	rep(i, n){
		int x, y; cin >> x >> y;
		pts.pb(Point(x, y));
	}

	auto cmp1 = [](Point p, Point q){
		return (p.x + p.y) <= (q.x + q.y);
	};

	auto cmp2 = [](Point p, Point q){
		return (p.x - p.y) <= (q.x - q.y);
	};

	ll ans = 0;
	Point max1 = *max_element(all(pts), cmp1);
	Point min1 = *min_element(all(pts), cmp1);
	Point max2 = *max_element(all(pts), cmp2);
	Point min2 = *min_element(all(pts), cmp2);

	ll A = max1.x + max1.y - (min1.x + min1.y);
	ll B = max2.x - max2.y - (min2.x - min2.y);
	cout << max({A, -A, B, -B});
}

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

int main() {
  int n;
  cin >> n;
  int x = (n+1) / 2;
  double ans = (double)x / (double)n;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N : usize = read();
    let mut list = Vec::<i64>::new();
    for i in 0..N {
        let a: i64 = read();
        list.push(a);
    }

    let mut ans = 1000000001;
    for mut v in list {
        let mut tmp = 0;
        while v%2 == 0 {
            tmp += 1;
            v = v/2;
        }

        ans = std::cmp::min(ans, tmp);
    }

    println!("{}", ans);
}

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

int main(){
    int n; cin >> n;
    vector<long long int> A(n);
    for(int i=0; i<n; i++) cin >> A[i];

    long long int steps = 0;
    long long int big = A[0];
    for(int i=0; i<n; i++){
        if(big > A[i]){
            steps += big - A[i];
        }
        big = max(big,A[i]);
    }

    cout << steps << endl;
}

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

int main(){
  int N,K;
  cin>>N;
  K=0;
  
  for(int i=0; i<N; i++){
    string S;
    cin>>S;
     
    if(S=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    K++;
  }
  if(K==N){
    cout<<"Three"<<endl;
  }
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
B = readInts()
biga = 0
bigb = 0
for i in range(n):
    if A[i] > B[i]:
        biga += A[i]-B[i]
    elif A[i] < B[i]:
        bigb += (B[i]-A[i])//2
print('Yes' if bigb >= biga else 'No')


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

#define ll long long
#define ull unsigned long long
#define endl '\n'

using namespace std;


int  main (){
	//freopen("input.txt", "r", stdin);

	ull n;
	cin>>n;

	ull sum = 0;
	for(ull i=1; i<=n; i++){
		if(i%3 == 0 && i%5 == 0){
			continue;
		}
		else if(i%3 == 0){
			continue;
		}
		else if(i%5 == 0){
			continue;
		}
		else sum += i;
	}
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
from collections import deque
H, W = map(int, input().split())
INF = 10**9
sheet = []
log = [[True]*W for i in range(H)]
step = [(-1,0),(1,0),(0,-1),(0,1)]
stuck = deque()
ans = 0

for i in range(H):
  line = input()
  for j in range(W):
    if line[j]=='#':
      stuck += [(i,j,0)]
      log[i][j] = False
      
while stuck:
  y, x, m = stuck.popleft()
  for s in step:
    dx, dy = s
    if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy>H-1:
      continue
    if log[y+dy][x+dx]:
      log[y+dy][x+dx]=False
      stuck += [(y+dy, x+dx, m+1)]
      if ans<m+1:
        ans = m+1
      
print(ans)

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

int N, K;
vector<int> arr;

vector<vector<int> > ccp;
int dpp(int n, int k) {
    if(n == -1) return k == 0;
    int &ret = ccp[n][k];
    if(ret != -1) return ret;

    return ret = (arr[n] <= k && dpp(n - 1, k - arr[n])) | dpp(n - 1, k);
}
vector<vector<int> > ccs;
int dps(int n, int k) {
    if(n == N) return k == 0;
    int &ret = ccs[n][k];
    if(ret != -1) return ret;

    return ret = (arr[n] <= k && dps(n + 1, k - arr[n])) | dps(n + 1, k);
}
vector<int> mx;

int main() {
    scanf("%d %d", &N, &K);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    sort(arr.begin(), arr.end());
    ccp = ccs = vector<vector<int> >(N, vector<int>(K, -1));
    mx = vector<int>(K, 0);
    int cnt = N;
    for(int i = N - 1; i >= 0; i--) {
        int lb = max(0, K - arr[i]);
        for(int j = 0; j < K; j++) {
            if(j == 0 || (i != 0 && dpp(i - 1, j))) if(lb - j <= 0 || lb - j <= mx[j]) {
                cnt--;
                break;
            }
        }
        int c = -1;
        for(int j = K - 1; j >= 0; j--) {
            if(dps(i, K - 1 - j)) c = K - 1 - j;
            mx[j] = max(mx[j], c);
        }
    }
    printf("%d", cnt);
}


Measured memory_bytes: 196224
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#define rep(i,n) for(int i = 0; i < (int)n; i++)

using namespace std;
int main(){
    int K,X;
    cin >> K >> X;

    for (int i = X - (K - 1); i <= X + (K - 1); i++)
    {
        /* code */
        cout << i << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
#include<algorithm>
#include <queue>
#include<vector>
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e6+16;
const ll INF=100000000000005;
const double eps=1e-11;
using namespace std;
ll n,m,p;
int vis[maxn];
int head[maxn];
struct node{
    int e,next;
    int f;
}edge[maxn];
ll cnt=0;
int res=0;
void addedge(int u,int v)
{
    edge[cnt]=node{v,head[u],0};
    head[u]=cnt++;
}
void dfs(int u,int c)
{
    int pos=1;
    for(int i=head[u];~i;i=edge[i].next)
    {
        if(!edge[i].f)
        {
            while(pos==c) pos++;
            edge[i].f=pos;
            res=max(pos,res);
            if(i%2) edge[i-1].f=pos;
            else edge[i+1].f=pos;
            dfs(edge[i].e,pos);
            pos++;
        }
    }
}
int main()
{
    memset(head,-1,sizeof(head));
    scanf("%lld",&n);
    for(int i=1;i<=n-1;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        addedge(x,y);
        addedge(y,x);
    }
    dfs(1,0);
    printf("%d\n",res);
    for(int i=0;i<cnt;i+=2)
        printf("%d\n",edge[i].f);
    return 0;
}


Measured memory_bytes: 10624
n,q = gets.chomp.split.map(&:to_i)
queue = []
n.times {
  arr = gets.chomp.split
  queue << [arr[0],arr[1].to_i]
}
time = 0
while queue.length > 0
  arr = queue.shift
  if arr[1] <= q
    time += arr[1]
    puts "#{arr[0]} #{time}"
  else
    time += q
    queue << [arr[0],arr[1]-q]
  end
end

Measured memory_bytes: 19864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, m, ta = 1;

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		ta *= 2;
	}
	cout << ((n - m) * 100 + m * 1900)*ta << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() {

    int64_t N, K;
    std::cin >> N >> K;

    std::vector<int64_t> Hs(N);
    for (auto& H : Hs) {
        std::cin >> H;
    }

    std::sort(Hs.begin(), Hs.end(), std::greater<int64_t>());

    if (Hs.size() < K) {
        K = Hs.size();
    }
    Hs.erase(Hs.begin(), Hs.begin()+K);

    int64_t ans = 0;
    for (auto& H : Hs) {
        ans += H;
    }

    std::cout << ans << std::endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int a, b, c;
  cin >> a >> b >> c;
  int mx = max({a, b, c});
  mx *= 3;
  int sum = a + b + c;
  int ans;
  if((mx-sum)%2 == 0) ans = (mx-sum)/2;
  else ans = (mx-sum)/2 + 2;
  cout << ans << endl;
  
}

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



int main() {
    int N;
    cin>>N;
    vector<int> A(N),B(N),C(N-1);
    rep(i,N){cin>>A.at(i);A.at(i)--;}
    rep(i,N){cin>>B.at(i);}
    rep(i,N-1){cin>>C.at(i);}
    int ans=0;
    rep(i,N){
        ans+=B.at(A.at(i));
        if(i!=N-1 && A.at(i)+1==A.at(i+1)){
            ans+=C.at(A.at(i));
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void output_array( int* array, int num)
{
	int i;
	for (i = 0; i < num-1; i++)
	{
		printf("%d ", array[i]);
	}
	printf("%d\n", array[i]);
	return;
}


int main(void) 
{
	int N;
	int array[100];
	int i, j;
	int tmp;
	
	scanf("%d", &N);
/*	if (N > 100)
	{
		return 0;
	}*/
	for (i = 0; i < N; i++)
	{
		scanf("%d", &array[i]);
	}
	
	output_array(array, N);
	
	for (i = 1; i < N; i++)
	{
		tmp = array[i];
		for (j = i-1; j >= 0 && array[j] > tmp; j--)
		{
			array[j+1] = array[j];
		}
		array[j+1] = tmp;
		output_array(array, N);
	}
	return 0;
}



Measured memory_bytes: 1828
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: [u64; N],
    }
    let mut A = A;
    A.sort();
    A.reverse();
    let (mut alice, mut bob) = (0,0);
    for i in 0..N{
        if i%2==0{
            alice += A[i];
        }else{
            bob += A[i];
        }
    }
    println!("{}", alice - bob);
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,k,q;
vll a;
set<lli> taboo;
map<lli,vll> m;
lli ans = LONG_MAX;



lli solve(){
  lli r = 0;
  vll b = a;
  vll res;
  for(lli x : taboo){
    sort(b.begin()+r,b.begin()+x);
    for(lli i = r;x-i >= k;i++){
      res.push_back(b[i]);
    }
    r = x+1;
  }
  if(res.size() >= q){
    sort(res.begin(),res.end());
    ans = min(ans,res[q-1]-res[0]);
  }
}

int main(){
  cin >> n >> k >> q;
  a = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i];
  for(lli i = 0;i < n;i++){
    m[a[i]].push_back(i);
  }
  m[0].push_back(n);
  for(auto x : m){
    for(auto y : x.second){
      taboo.insert(y);
      solve();
      taboo.erase(y);
    }
    for(auto y : x.second){
      taboo.insert(y);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,K;cin>>N>>K;
    vector<ll> vx(N),vy(N);
    vector<ll> vx2(N),vy2(N);
    REP(i,N){cin>>vx[i]>>vy[i];vx2[i]=vx[i];vy2[i]=vy[i];}
    sort(all(vx2));sort(all(vy2));
    vector<vector<int> > plane(N+1,vector<int>(N+1,0));
    vector<int> wx(N),wy(N);
    REP(i,N){
        wx[i]=(int)(lower_bound(all(vx2),vx[i])-vx2.begin())+1;
        wy[i]=(int)(lower_bound(all(vy2),vy[i])-vy2.begin())+1;
    }
    REP(i,N){
        plane[wx[i]][wy[i]]=1;
    }
    vector<vector<int> > psum(N+1,vector<int>(N+1,0));
    REP(i,N+1)FOR(j,1,N+1){
        psum[i][j]+=psum[i][j-1]+plane[i][j];
    }
    REP(j,N+1)REP(i,N){
        psum[i+1][j]+=psum[i][j];
    }

    ll res=1LL<<63-1;
    
    REP(i,N)REP(j,N)REP(k,N)REP(l,N){
        int x1=wx[i],x2=wx[j],y1=wy[k],y2=wy[l];
        if(!(x2>x1 && y2>y1)) continue;
        if(K>psum[x2][y2]+psum[x1-1][y1-1]-psum[x2][y1-1]-psum[x1-1][y2]) continue;
        res=min(res,(vx[j]-vx[i])*(vy[l]-vy[k]));
    }
    cout<<res<<endl;
    return 0;
}

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

const int N  = 1e6 + 10;

int tim = 0;
vector<int> v[N];
int bit[N] , beg[N] , endd[N];

void sett(int pos , int val) {
	for(++pos ; pos < N ; pos += pos & -pos) 
		bit[pos] += val;
}

void sett(int a , int b , int val) {
	sett(a , val);
	sett(b + 1 , -val);
}

int get(int pos) {
	int ret = 0;
	for(++pos ; pos > 0 ; pos -= pos & -pos) 
		ret += bit[pos];
	return ret;
}

int get(int a , int  b) {
	return get(b) - get(a - 1);
}

void dfs(int i , int p = -1) {
	beg[i] = ++tim;
	for(int j : v[i]) {
		if(j != p) {
			dfs(j , i);
		}
	}
	endd[i] = tim;
}

	
int main() {
	int n , q; cin >> n >> q;
	for(int i = 0 ; i < n - 1 ; i ++ ) {
		int a , b ; cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(1);
	
	while(q--) {
		int node , val; cin >> node >> val;
		//~ cout << beg[node] << " " << endd[node] << endl;
		bit[beg[node]] += val;
		bit[endd[node] + 1] -= val;
	}
	for(int i = 1 ; i < N ;i ++) bit[i] += bit[i - 1];
	
	//~ cout << bit[1] << " " << bit[4] << endl;
	
	for(int i = 1 ; i <= n ;i ++ ) {
		cout << bit[beg[i]] << " ";
	}
}


Measured memory_bytes: 51968
import sys
import bisect
input = sys.stdin.readline

N = int(input())
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
C = [int(v) for v in input().split()]

A.sort()
B.sort()
C.sort()

ans = 0
for v in B:
    l = bisect.bisect_left(A, v)
    r = bisect.bisect_right(C, v)
    ans += l * (N - r)
    
print(ans)

Measured memory_bytes: 22592
import collections
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())

lst = ["".join(sorted(list(input()))) for i in range(N)]
c = collections.Counter(lst)

ans = 0
for k,v in c.items():
  if (v > 1):
    ans += combinations_count(v, 2)

print(ans)

Measured memory_bytes: 19728
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <iomanip>
#include <algorithm>

using namespace std;

int gcd_util(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd_util(b, a%b);
}

int gcd(int a, int b, int c) {
    int tmp;
    if (a < b) {
        tmp = gcd_util(b, a);
    }
    else {
        tmp = gcd_util(a, b);
    }

    if (tmp < c) {
        return gcd_util(c, tmp);
    }
    else {
        return gcd_util(tmp, c);
    }
}


int main()
{
    int k;
    cin >> k;
    long long int tot = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int p = 1; p <= k; p++) {
                tot += gcd(i, j, p);
            }
        }
    }

    cout << tot << endl;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
 
int mod = 998244353;
int n,s;
int arr[3005];
int cache[3005][3005];
int power[3005];
 
int dp(int pos,int sum)
{
    if(sum==s)
        return power[n-pos];
 
    if(pos==n || sum>s)
        return 0;
 
    int &ans=cache[pos][sum];
    if(ans!=-1)
        return ans;
 
    ans=2*dp(pos+1,sum)+dp(pos+1,sum+arr[pos]);
    ans%=mod;
    return ans;
}
int32_t main() 
{
    IOS;
    power[0]=1;
    for(int i=1;i<=3002;i++)
        power[i]=(2*power[i-1])%mod;
    cin>>n>>s;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    memset(cache,-1,sizeof(cache));
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int a=(power[i]*dp(i+1,arr[i]))%mod;
        ans=(ans+a)%mod;
    }
    print(ans);
}   

Measured memory_bytes: 74424