akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	vector<int> v;
	vcin(v,3);
	ssort(v);
	P(v[0]+v[1]);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int x=15,sum=0;
  r(i,n)if(s[i]=='o')sum++;

  if(sum+15-n>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll a, b; cin >> a >> b;
    if((a+b)%2) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7748
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    S=input()
    if S=="ABC":print("ARC")
    else:print("ABC")
#%%submit!
resolve()

Measured memory_bytes: 61656
A, B, T = map(int, input().split())

# A, 2A, 3A,...とT+0.5より大きくなるまで増やしていき、その間に得られたビスケットの枚数を数える

ans = 0 # 得られたビスケットの総数
cnt = 1 # Aの係数

while cnt * A <= T + 0.5:
    ans += B
    cnt += 1

print(ans)

Measured memory_bytes: 2940
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        ArrayList<Integer> a = new ArrayList<Integer>();
        for(int i=0; i<n; i++) a.add(fs.nextInt());
        int[] ans = new int[n];

        for(int i=0; i<n; i++) {
            ans[a.get(i)-1] = i+1;
        }

        for(int i:ans) {
            System.out.print(i);
            System.out.print(" ");
        }
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 47008
#include<bits/stdc++.h>
using namespace std;
int dp[1000000];
int ans(vector<int> &v, int n, int i, int k)
{
    if(i==0)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    int mn=INT_MAX;
    for(int j=i-1; j>=max(0, i-k); j--)
    {
        int p=ans(v, n, j, k)+abs(v[j]-v[i]);
        mn=min(p, mn);
    }
    return dp[i]=mn;
}
int main()
{
    int n, k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    for(int i=0; i<1000000; i++)
        dp[i]=-1;
    int a=ans(v, n, n-1, k);
    cout<<a;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a <= b && b <= c)
		cout << a << " " << b << " " << c << endl;
	else if (a <= c && c <= b)
		cout << a << " " << c << " " << b << endl;
	else if (b <= a && a <= c)
		cout << b << " " << a << " " << c << endl;
	else if (b <= c && c <= a)
		cout << b << " " << c << " " << a << endl;
	else if (c <= a && a <= b)
		cout << c << " " << a << " " << b << endl;
	else
		cout << c << " " << b << " " << a << endl;

	return 0;
}

Measured memory_bytes: 3056
n,m = map(int,input().split())
a = [str(input()) for _ in range(n)]
b = [str(input()) for _ in range(m)]
flag = False
for l in range(n-m+1):
    for k in range(n-m+1):
        cnt = 0
        for i in range(m):
            for j in range(m):
                if a[k+i][j+l]==b[i][j]:
                    cnt += 1
            if cnt==m**2:
                flag = True
                break
        if flag:
            break
    if flag:
        break
print('Yes' if flag else 'No')

Measured memory_bytes: 3064
// ------------------------------------
// Date:2018/ 3/17
// Problem:collecting bells easy f.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1;

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

  CIN(N, K);
  vector< int > x(N);
  ll ans = 0;
  REP(i, N) {
    cin >> x[i];
    ans += min(x[i], abs(K - x[i]));
  }
 
  cout << ans * 2 << endl;

  

  return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);//その日までにやらなきゃいけない仕事
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);//何日目までにやらなきゃいけないかはm-a
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (auto b : jobs[i]) {
      q.push(b);//jobsをpriority_queueに突っ込む
    }
    if (!q.empty()) {
      ans += q.top();//top()→先頭要素を取り出す関数
      q.pop();//pop()→先頭要素を削除する関数
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <set>
int main()
{
    for (int i = 1; true; i++)
    {
        int a;
        std::cin >> a;
        if (a == 0)
        {
            break;
        }
        else
        {
            std::cout << "Case " << i << ": " << a << "\n";
        }
    }
    return 0;
}


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

int main(){
    int n = 0;
    string s;
    cin >> s;
    int flag=0;
    int ans=0;

    for (int i = 0; i < 4; i++){
        if(s[i]=='+')ans++;
        else ans--;
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < 100; i++) {
    int I = i + 1, ansn = 0;
    for (int j = 0; j < N; j++) {
      ansn += (a.at(j) - I) * (a.at(j) - I);
    }
    if (i == 0) {
	  ans = ansn;
    }
    else {
      ans = min(ans, ansn);
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    string S, T = "MARCH";
    vector<int> A(5, 0), V(5, 0);
    rep(i, N) {
        cin >> S;
        rep(j, 5) {
            if (S[0] == T[j]) A[j]++;
        }
    }
    ll ans = 0;
    rep(i, 5) V[i] = i;
    do {
        ll x = 1;
        rep(i, 3) x *= A[V[i]];
        ans += x;
    } while (next_permutation(V.begin(), V.end()));
    cout << ans / 12 << "\n";
}

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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> Edg;
  int ma = N;
  if(N%2 == 0) ++ma;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < i; ++j){
      if(i+j+2 == ma) continue;
      Edg.emplace_back(i+1,j+1);
    }
  }
  cout << Edg.size() << endl;
  for(auto e : Edg) cout << e.first << " " << e.second << endl;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
if n==0:
	if a[0]==1:
		print(1)
		exit()
	else:
		print(-1)
		exit()
M=[1]
now=2
r=sum(a)
for i in range(n):
	M.append(now)
	now-=a[i+1]
	if now<0:
		print(-1)
		exit()
	elif now<r:
		now*=2
now=a[-1]
for i in range(n):
	M[-i-1]=min(now,M[-i-1])
	now=min(now,M[-i-1])
	now+=a[-i-2]
if a[0]!=0:
	print(-1)
	exit()
for i in range(n+1):
	if M[i]<=0:
		print(-1)
		exit()
print(sum(M))


Measured memory_bytes: 20024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int solve(int N)
{
	vector<int> v;
	v.push_back(1);
	for (int x = 6; x <= N; x *= 6) {
		v.push_back(x);
	}
	for (int x = 9; x <= N; x *= 9) {
		v.push_back(x);
	}
	sort(v.begin(), v.end());

	vector<bool> vis(N + 1, false);

	queue<int> q;
	q.push(N);
	vis[N] = true;
	for (int ans = 0; !q.empty(); ++ans) {
		queue<int> next;
		while (!q.empty()) {
			int M = q.front();
			q.pop();
			if (M == 0) {
				return ans;
			}
			for (auto x : v) {
				if (x <= M) {
					if (!vis[M - x]) {
						next.push(M - x);
						vis[M - x] = true;
					}
				}
			}
		}
		q = move(next);
	}
	return -1;
}


int main()
{
	int N;
	cin >> N;
	cout << solve(N) << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	int N;
	cin >> N;
	vector<int>a(N);
	int num;
	rep(i, N) {
		cin >> num;
		a[i] = num - 1;
	}
	int button = 0;
	int cnt = 0;
	while (1) {
		button = a[button];
		cnt++;
		if (button == 1) {
			cout << cnt;
			return 0;
		}
		if (cnt >= N + 2) {
			cout << -1;
			return 0;
		}
	}
}

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

namespace ABC042
{
	class Q3
	{
		static void Main()
		{
			List<int> buff = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
			int N = buff[0];
			int M = buff[1];

			List<string> nums = Console.ReadLine().Split(' ').ToList();

			int sum = 0;
			for(int i = 0; true; i++)
			{
				sum = N + i;
				bool flag = true;
				for(int j = 0; j < M; j++)
				{
					if (sum.ToString().Contains(nums[j].ToString()))
					{
						flag = false;
					}
				}
				if (flag)
				{
					Console.WriteLine(sum);
					break;
				}
			}
		}
	}
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

int A[200001];

int main()
{
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

	int n, i, j, k, x, y, z, ans = 0;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> x;
		A[x] = 1 + A[x-1];
		ans =  max(ans, A[x]);
	}
	cout << n - ans << endl;

	return 0;
}

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

#define ll long long
#define NM_MAX 100002

using namespace std;

const int MOD = 1e9+7;

int pwr (int a, int b)
{
    if(b == 0)
        return 1;
    if(b & 1)
        return 1LL * pwr(a, (b ^ 1)) * a % MOD;
    int p = pwr(a, (b >> 1));
    return 1LL * p * p % MOD;
}

int fact[2 * NM_MAX];
int ifact[2 * NM_MAX];

int comb (int a, int b)
{
    return 1LL * fact[a] * ifact[b] % MOD * ifact[a - b] % MOD;
}

int f (int a, int b)
{
    return comb(a - 1 + b - 1, a - 1);
}

int n, m, a, b;

int main()
{
    cin >> n >> m >> a >> b;
    fact[0] = 1;
    for(int i = 1; i <= n + m; i++)
        fact[i] = 1LL * fact[i - 1] * i % MOD;
    ifact[n + m] = pwr(fact[n + m], MOD - 2);
    for(int i = n + m - 1; i >= 0; i--)
        ifact[i] = 1LL * ifact[i + 1] * (i + 1) % MOD;
    int sum = 0;
    for(int i = 1; i <= b; i++)
        sum = (sum + 1LL * f(n - a, i) * f(a, m - i + 1)) % MOD;
    cout << (1LL * f(n, m) - sum + MOD) % MOD;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll H,W,N;
	cin >> H >> W >> N;
	map< pair<ll,ll>, ll > mp;
	FOR(i,0,N){
		ll a,b;
		cin >> a >> b;
		FOR(j,0,3)FOR(k,0,3){
			if((a-j)>=1&&(b-k)>=1){
				mp[{a-j,b-k}]++;
			}
		}
	}
	ll ans[10]={0};
	for(pair< pair<ll,ll>,ll > x : mp){
		ll a = x.first.first;
		ll b = x.first.second;
		ll c = x.second;
		if(a<=(H-2)&&b<=(W-2))ans[c]++;
	}
	ans[0] = (H-2)*(W-2);
	FOR(i,1,10)ans[0]-=ans[i];
	FOR(i,0,10)cout<<ans[i]<<endl;
}

Measured memory_bytes: 56576
#include<stdio.h>
#define MAX 100000

 typedef struct {
  int parent;
  int left;
  int right;
}Tree;

Tree a[MAX];

int getDepth(int);

int main(){
  int i,j,n;
  int num,deg,child,k = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    a[i].parent = -1;
    a[i].left = -1;
    a[i].right = -1;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&num,&deg);

    for(j=0;j<deg;j++){
      scanf("%d",&child);
      if(j==0) a[num].left=child;
      else a[k].right=child;
      k=child;
      a[child].parent=num;
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d",i,a[i].parent,getDepth(i));

    if(getDepth(i) == 0){
      printf(", root, [");
    }
    else if(a[i].left == -1){
      printf(", leaf, [");
    }
    else{
      printf(", internal node, [");
    }

    j=a[i].left;

    while(j != -1){
      printf("%d", j);
      j = a[j].right;

      if(j != -1){
    printf(", ");
      }
    }
    printf("]\n");
  }

  return 0;
}
int getDepth(int num){
  int depth = 0;

  for(depth = 0; a[num].parent != -1; depth++){
    num = a[num].parent;
  }
return depth;
}

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

const int64_t MOD = 1000000007;

int64_t accum(int64_t num) { return num * (num + 1) / 2; }

int main() {
  int64_t N, K;
  cin >> N >> K;

  int64_t ans = 1;
  for (int i = K; i <= N; i++) {
    int64_t min = accum(i - 1);
    int64_t max = accum(N) - accum(N - i);
    ans += ((max - min) + 1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    B = [0]*(M+1)
    ans = 0
    A.sort()
    
    for i in A:
        B[i] += 1
    
    for i in A:
        if B[i] == 1:
            ans += 1
        for j in range(i, M+1, i):
            B[j] += 1
    
    print(ans)

main()

Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int H,W,K; cin>>H>>W>>K;
    vector<string> s(H);
    for (int i = 0; i < H; ++i) {
        cin>>s[i];
    }
    int ans=0;
    for (int rbit = 0; rbit < (1 << H); ++rbit) {
        vector<bool> r(H,true);
        for (int i = 0; i < H; ++i) {
            if(rbit&(1<<i)) r[i]= false;
        }
        for (int cbit = 0; cbit < (1 << W); ++cbit) {
            vector<bool> c(W, true);
            for (int i = 0; i < W; ++i) {
                if(cbit&(1<<i)) c[i]= false;
            }
            int cnt=0;
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if(s[i][j]=='#'&&r[i]&&c[j]) cnt++;
                }
            }
            if(cnt==K) ans++;

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


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),[](auto a,auto b){return a>b;});
	int size=min(s.size(),t.size());
	bool yes;
	if(size==s.size()&&size!=t.size())yes=true;
	else yes=false;
	for(int i=0;i<size;++i){
		if(s.at(i)==t.at(i))continue;
		if(s.at(i)<t.at(i))yes=true;
		else yes=false;
		break;
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main()
{
  int i,j,k,l,n,p[N + 1],m[N + 1][N + 1];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
    scanf("%d %d",&p[i - 1],&p[i]);
  }
  for(i=1;i<=n;i++)
  m[i][i] = 0;
  for(l=2;l<=n;l++)
  {
    for(i=1;i<=n-l+1;i++)
    {
      j=i+l-1;
      m[i][j] = 2097152;
      for(k=i;k<=j-1;k++)
      {
        if(m[i][j] > m[i][k] + m[k + 1][j] + p[i -1]*p[k]*p[j])
        m[i][j] = m[i][k] + m[k + 1][j] + p[i -1]*p[k]*p[j];
      }
    }
  }
printf("%d\n",m[1][n]);
return 0;
}



Measured memory_bytes: 2104
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(ReadLine());
      List<int> b = ReadLine().Split().ToList().ConvertAll(x=>int.Parse(x));
      List<int> ans = new List<int>();
     
      for (int i=0;i<n;i++)
      {
        for (int j=b.Count-1;j>=0;j--)
        {
          if ((j+1)==b[j])
          {
            ans.Add(j+1);
            b.RemoveAt(j);
            break;
          }
        }
      }
      ans.Reverse();
      if (ans.Count==n)
      {
        foreach (var i in ans)
        {
          WriteLine(i);
        }
      }
      else
      {
        WriteLine(-1);
      }
      
    }
}

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

using namespace std;


int main() {
  
   
    int h,w,h1,w1;
    scanf("%d%d",&h1,&w1);
  scanf("%d%d",&h,&w);
  printf("%d",(h1-h)*(w1-w));
   
   
    	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vint sum(n+1,0);
    vint ac(n,0);
    for(int i=1;i<n;i++){
        if(s[i-1]=='A'&&s[i]=='C'){
            sum[i+1]=sum[i]+1;
            ac[i]=1;
        }else{
            sum[i+1]=sum[i];
        }
    }
    REP(i,q){
        int l,r;
        cin >> l >> r;
        cout << sum[r]-sum[l-1] - ac[l-1]<< endl;
    }
    return 0;
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;
const int mod = 1000000007;

int main()
{
  ll n;
  cin>>n;
  vector<ll>a(n);
  vector<ll>b(n,0);
  vector<ll>c(n,0);
  rep(i,n){
    cin>>a[i];
    b[a[i]-1]+=1;
  }
  ll ans=0;

  rep(i,n){
    c[i]=b[i]*(b[i]-1)/2;
    ans+=c[i];
  //  cout<<c[i]<<endl;
}

//cout<<ans<<endl;
rep(i,n){
  ll ans_now=ans;
  ll anow=a[i]-1;
  ans_now-=c[anow];
  ll cnew=(b[anow]-1)*(b[anow]-2)/2;
  ans_now+=cnew;
  cout<<ans_now<<endl;

}
}


Measured memory_bytes: 7296
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(n, m, k; usize);
    scan!(array; Vec<usize>);
    scan!(brray; Vec<usize>);

    let mut sum_array = vec![0; n+1];
    let mut sum_brray = vec![0; m+1];
    sum_array[0] = 0;
    for i in 1..=n {
        sum_array[i] = sum_array[i-1] + array[i-1];
    }
    sum_brray[0] = 0;
    for i in 1..=m {
        sum_brray[i] = sum_brray[i-1] + brray[i-1];
    }

    // println!("beep");

    let mut res = 0;
    let mut best = m;
    for i in 0..=n {
        if sum_array[i] > k {
            break;
        }
        let limit = k - sum_array[i];
        for j in (0..=best).rev() {
            if sum_brray[j] <= limit {
                best = j;
                break;
            }
        }

        if i + best > res { res = i + best; }
    }

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


Measured memory_bytes: 12528
n, k = list(map(int, input().split(' ')))
abn = [None] * n
for i in range(n):
    abn[i] = list(map(int, input().split(' ')))

abn = sorted(abn, key=lambda ab: ab[0])

ans = -1
temp = 0
i = 0
while True:
    if temp + abn[i][1] >= k:
        ans = abn[i][0]
        break
    temp += abn[i][1]
    i += 1
print(ans)



Measured memory_bytes: 59864
//
//  coffee.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/03/31.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <string>

int main(int argc, const char* argv[]) {
    std::string input;
    std::cin >> input;
    int size = (int)input.size();
    if (size != 6) {
        std::cout << "number of characters must be 6" << std::endl;
        exit(1);
    }
    else {
        for (int i=0; i<size; i++) {
            if (int(input[i] < 97 || int(input[i]) > 122)) {
                std::cout << "input must be English character in lower case" << std::endl;
            }
        }
    }
    if (input[2] == input[3] && input[4] == input[5]) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
//    std::cout << input.c_str() << std::endl;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
l = input()
n = len(l)
dp = [[0, 0] for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
    num = l[i - 1]
    if num == "1":
        dp[i][0] = dp[i - 1][0]*2
        dp[i][1] = dp[i - 1][1]*3 + dp[i - 1][0]
    else:
        dp[i][0] = dp[i - 1][0]
        dp[i][1] = dp[i - 1][1]*3
    dp[i][0] %= mod
    dp[i][1] %= mod
print(sum(dp[-1]) % mod)

Measured memory_bytes: 54256
#include<stdio.h>
int main()
{
	int num;
	int m = 0, n = 0, q = 0;
	scanf("%d", &num);
	m = num / 100;
	q = num % 100 / 10;
	n = num % 10;
	if(m == q && q == n)
		printf("%d", num);
	else if(m < q ||(m == q && m < n))
		printf("%d%d%d", m + 1, m+1, m+1);
	else if(m > q || (m == q && m > n))
		printf("%d%d%d", m,m,m);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    int i;
    double s[1000]={},sum=0,a=0;
    for(i=0;i<n;i++){
      cin >> s[i];
      sum+=s[i];
    }
    for(i=0;i<n;i++){
      a+=((sum/n)-s[i])*((sum/n)-s[i])/n;
    }
    printf("%.5f\n",sqrt(a));
    cin >> n;
  }
  
  return 0;
}



Measured memory_bytes: 3208
use std::str::FromStr;
use std::io::Read;
use std::ops::Sub;
use std::convert::From;

pub trait Convert {
    fn to_val<T>(&mut self) -> T
    where
        T: FromStr;

    fn to_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: FromStr;

    fn to_vec_1origin<T>(&mut self, n: usize) -> Vec<T>
    where
        T: FromStr + Sub<T, Output = T> + From<u8>;

    fn to_vecs_1origin<T>(&mut self, n: usize) -> Vec<Vec<T>>
    where
        T: FromStr + Sub<T, Output = T> + From<u8>;
}

impl<'a> Convert for ::std::str::SplitWhitespace<'a> {
    fn to_val<T>(&mut self) -> T
    where
        T: FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }

    fn to_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: FromStr,
    {
        (0..n)
            .map(|_| self.next().unwrap().parse().ok().unwrap())
            .collect::<Vec<_>>()
    }

    fn to_vec_1origin<T>(&mut self, n: usize) -> Vec<T>
    where
        T: FromStr + Sub<T, Output = T> + From<u8>,
    {
        (0..n)
            .map(|_| {
                self.next().unwrap().parse::<T>().ok().unwrap() - T::from(1)
            })
            .collect::<Vec<_>>()
    }

    fn to_vecs_1origin<T>(&mut self, n: usize) -> Vec<Vec<T>>
    where
        T: FromStr + Sub<T, Output = T> + From<u8>,
    {
        (0..n)
            .map(|_| {
                let val = self.to_val();
                self.to_vec_1origin(val)
            })
            .collect::<Vec<_>>()
    }
}

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

type ConnectedList = Vec<Vec<usize>>;
fn evaluate(v: &ConnectedList, ps: &Vec<u64>, on: Vec<bool>) -> bool {
    for (ss, &p) in v.iter().zip(ps.iter()) {
        let c = ss.iter().filter(|&s| on[*s]).count() as u64;
        if c % 2 != p {
            return false;
        }
    }
    return true;
}

fn force(v: &ConnectedList, ps: &Vec<u64>, n: usize) -> u64 {
    (0..2_u32.pow(n as u32))
        .filter(|on_src| {
            let on: Vec<bool> = (0..n).map(|i| ((on_src >> i) & 1) == 1).collect();
            evaluate(v, ps, on)
        })
        .count() as u64
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.to_val();
    let m: usize = iter.to_val();
    let v: ConnectedList = iter.to_vecs_1origin(m);
    let ps: Vec<u64> = iter.to_vec(m);

    println!("{}", force(&v, &ps, n));
}


Measured memory_bytes: 4352
// Solution from pinglei

#include <bits/stdc++.h>
using namespace std;
int a[256];
char s[256];
int main()
{
    cin>>s;
    int l=1;
    for(int i=0; s[i]; i++)a[s[i]]=1,l++;
    for(int c='z'; c>='a'; c--)
        if(!a[c])s[l++]=c;
    if(next_permutation(s,s+l))
        cout<<s;
    else
        cout<<-1;
    return 0;
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int n,m,k,dp[4333][2333],ans;
int main()
{
	get3(n,m,k);
	int t=(n+m-1)/(k-1);
	dp[0][0]=1;
	for(int i=0;i<t;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(dp[i][j]==0)continue;
			int j2=i*(k-1)-j;
			for(int tk=0;tk<k;tk++)
			{
				if(j+tk>n)continue;
				if(j2+(k-1)-tk>m)continue;
				dp[i+1][j+tk]+=dp[i][j];
				if(dp[i+1][j+tk]>=mod)dp[i+1][j+tk]-=mod;
			}
		}
	}
	for(int i=1;i<=t;i++)
	{
		for(int j=n;j>0&&i*(k-1)-j<m;j-=k-1)
		{
			if(i==t&&j!=n)continue;
			ans+=dp[i][j];
			if(ans>=mod)ans-=mod;
			ans-=dp[i-1][j];
			if(ans<0)ans+=mod;
//			printf("%d %d dp %d ans %d\n",i,j,dp[i][j],ans);
		}
	}
	printendl(ans);
	return 0;
}

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

using namespace std;

constexpr char nl = '\n';

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

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  /*for (int i = 0; 1; i++) {
    if (i % 2 == 0) {
      C -= B;
    } else {
      A -= D;
    }
    if (A <= 0 || C <= 0) {
      break;
    }
  }
  cerr << A << "!" << C << nl;
  if (A <= 0) {
    cout << "No" << nl;
  } else {
    cout << "Yes" << nl;
  }*/

  int X = (A + D - 1) / D;
  int Y = (C + B - 1) / B;
  // cerr << X << ":" << Y << nl;
  cout << (X >= Y ? "Yes" : "No") << nl;
}


Measured memory_bytes: 3652
class Array
	def accum
		ac = Array.new(size + 1)
		ac[0] = 0
		(1..size).each do |i|
			ac[i] = ac[i-1] + self[i-1]
		end
		ac
	end
end

loop do
	n, s, w, q = gets.split.map(&:to_i)
	break if n == 0

	g = s
	a = Array.new(n)
	(0..n-1).each do |i|
		a[i] = g / 7 % 10
		g = (g.even? ?  g / 2 : (g / 2) ^ w)
	end
	a.reverse!

	k = 0
	if q == 2 || q == 5
		t = 0
		a.each_with_index do |x, i|
			if x % q == 0
				k += n - i 
				t += 1
				k -= t if x == 0
			end
		end
		puts k
		next
	end

	t = 1
	mod = a.map do |x|
		y = x * t % q
		t = t * 10 % q
		y
	end
	mod_accum = mod.accum.map {|x| x % q}

	count = Hash.new(0)
	(0..n).each do |i|
		x = mod_accum[i]
		k += count[x] if i > 0 && a[i-1] > 0
		count[x] += 1
	end
	p k
end

Measured memory_bytes: 84548
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 2005;
ll s[MAXN], t[MAXN],sum[MAXN][MAXN];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>s[i];
    for(int i=0; i<m; i++)
        cin>>t[i];   
    for(int i=0; i<=n; i++)
        sum[i][0] = 0;
    for(int i=0; i<=m; i++)
        sum[0][i] = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            sum[i][j] = (sum[i-1][j] + sum[i][j-1] + MOD - sum[i-1][j-1])%MOD;
            if(s[i-1] == t[j-1])
            {
                sum[i][j] += (sum[i-1][j-1] + 1)%MOD;
            }
            sum[i][j]%=MOD;
        }
    }
    cout<<(sum[n][m]+1)%MOD;
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<math.h>
#include<stack>
#include<unordered_map>

using namespace std;
vector<int> v;
unsigned long long Logn(unsigned long long n, unsigned long long r)
{
    return (n > r - 1) ? 1 + Logn(n / r, r) : 0;
}
const int N = 1e6;
int x[N], y[N];
void solve() {

    int a,b,m; cin >> a >> b >> m;
    int minv = 1e6, minv2 = 1e6;
    for (int i = 0; i < a; i ++) {
        cin >> x[i];
        minv = min(minv, x[i]);
    }
    for (int i = 0; i < b; i ++) {
        cin >> y[i];
        minv2 = min(minv, y[i]);
    }
    int temp_min = minv + minv2;
    for (int i = 0; i < m; i ++) {
        int q,w,e; cin >> q >> w >> e;
        temp_min = min(temp_min, (x[q - 1] + y[w - 1] - e));
    }
    cout << temp_min;
    return;

}

int main() {
        solve();
    return 0;
}

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

n,T = map(int,input().split())
c = [0] * n
t = [0] * n
for i in range(n):
    c[i],t[i] = map(int,input().split())

cost_min = 100000

for i in range(n):
    if cost_min > c[i] and t[i] <= T:
        cost_min = c[i]

if cost_min == 100000:
    print("TLE")
else:
    print(cost_min)


Measured memory_bytes: 3060
def dist2(A, B):
    return (A[0]-B[0])**2 + (A[1]-B[1])**2
def cross(A, B, C):
    return (B[0]-A[0])*(C[1]-A[1]) - (C[0]-A[0])*(B[1]-A[1])
def convex_hull(PS):
    n = len(PS)
    PP = sorted([p + [i] for i, p in enumerate(PS)])
    Q = []
    for i in range(n):
        while len(Q) > 1 and cross(PP[Q[-2]], PP[Q[-1]], PP[i]) >= 0:
            Q.pop()
        Q.append(i)
    k = len(Q)
    for i in range(n-2, -1, -1):
        while len(Q) > k and cross(PP[Q[-2]], PP[Q[-1]], PP[i]) >= 0:
            Q.pop()
        Q.append(i)
    return list(PP[i][2] for i in Q)

from math import sqrt
v, r = map(int, input().split())
PS = [list(map(int, input().split())) for i in range(v)]
CH = convex_hull(PS)

*parent, = range(v)
def root(x):
    if x == parent[x]:
        return x
    parent[x] = root(parent[x])
    return parent[x]
def unite(x, y):
    px = root(x); py = root(y)
    if px < py:
        parent[py] = px
    else:
        parent[px] = py

ans = 0
for i in range(len(CH)-1):
    unite(CH[i], CH[i+1])
    ans += sqrt(dist2(PS[CH[i]], PS[CH[i+1]]))
R = [list(map(int, input().split())) for i in range(r)]
R.sort(key=lambda x: dist2(PS[x[0]-1], PS[x[1]-1]))
for s, t in R:
    if root(s-1) != root(t-1):
        unite(s-1, t-1)
        ans += sqrt(dist2(PS[s-1], PS[t-1]))
print(ans)

Measured memory_bytes: 7948
#include<stdio.h>
int main()
{
	long long int a,b,k;
	scanf("%lld %lld %lld",&a,&b,&k);
	if(a>k) printf("%lld %lld\n",a-k,b);
	else if(a<=k&&a+b>k) printf("%lld %lld\n",a=0,(a+b)-k);
	else printf("0 0\n");
	return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int f[N],sum[N];
int get(int x){
	if(f[x]!=x){
		f[x]=get(f[x]);
		sum[x]=sum[f[x]];
	}
	return f[x];
}
int main(){
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=n;i++)f[i]=i,sum[i]=1;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		int f1=get(a),f2=get(b);
		if(f1!=f2){
			f[f1]=f2;
			sum[f2]+=sum[f1];
		}
	} 
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,sum[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,a[22],b[22],c[22],ans;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n-1)cin>>c[i];
	rep(i,n){
		ans+=b[a[i]-1];
		if(i){
			if(a[i]==a[i-1]+1)ans+=c[a[i]-2];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    fact();
    REP(i, 1, K) {
        int blue = Div(F[K - 1], Mul(F[K - i], F[i - 1]));
        int red = 0;
        if (N - K - i + 1 >= 0)
            red = Div(F[N - K + 1], Mul(F[N - K - i + 1], F[i]));
        //cout << blue << " " << red << endl;
        cout << Mul(blue, red) << endl;
    }

    return 0;
}


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

int main() {
  int A;
  int f = 0;
  cin >> A;
  int B = A;
  for (int i = 0;;i++){
    if(B > 0){
      f += B%10;
      B /= 10;
    }
    else{
      break;
    }
  }
  if (A%f == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/**
 *    author:  border
 *    created: 06.01.2019 17:22:09     
**/
#include <bits/stdc++.h>

using namespace std;

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a,val,sizeof a)

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define endl '\n'

int a[100010][3],dp[100010][3];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  /*#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    freopen("out","w",stdout);
  #endif*/
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[n-1][0] = a[n-1][0];
  dp[n-1][1] = a[n-1][1];
  dp[n-1][2] = a[n-1][2];
  for(int i = n-2; i >= 0; --i){
    dp[i][0] = max(dp[i+1][1],dp[i+1][2])+a[i][0];
    dp[i][1] = max(dp[i+1][0],dp[i+1][2])+a[i][1];
    dp[i][2] = max(dp[i+1][0],dp[i+1][1])+a[i][2];
  }
  cout << max(dp[0][0],max(dp[0][1],dp[0][2])) << endl;
}




Measured memory_bytes: 2560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 2000
vector<int>e[N];
int c[N];
int xx, yy;
bool vv;

void dfs(int k, int cc) {
	c[k] = cc;
	if (cc == 0)xx++;
	else yy++;
	f(i, e[k].size()) {
		if (c[e[k][i]] == -1)dfs(e[k][i], (cc + 1) % 2);
		else if (c[e[k][i]] != (cc + 1) % 2)vv = false;
	}
	return;
}

int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int n, m, k;
	int x, y;

	while (true) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)return 0;
		f(i, N) {
			e[i].clear();
			c[i] = -1;
		}
		f(i, m) {
			scanf("%d %d", &x, &y);
			e[x - 1].push_back(y - 1);
			e[y - 1].push_back(x - 1);
		}
		xx = 0;
		yy = 0;
		vv = true;
		dfs(0, 0);
		if (vv) {
			if (xx % 2 == 0)xx /= 2;
			else xx = -1;
			if (yy % 2 == 0)yy /= 2;
			else yy = -1;
			if (xx >= 0) {
				if (yy >= 0) {
					if (xx < yy) printf("2\n%d\n%d\n", xx, yy);
                  else if(xx>yy) printf("2\n%d\n%d\n", yy, xx);
					else printf("1\n%d\n", xx);
				}
				else printf("1\n%d\n", xx);
			}
			else {
				if (yy >= 0)printf("1\n%d\n", yy);
				else printf("0\n");
			}
		}
		else printf("0\n");
	}



	return 0;
}


Measured memory_bytes: 2836
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>


using namespace std;

typedef long long LL;



int main()
{
    int n;
    LL maxn= -1;
    LL ans = 0;
    LL lla;
    cin >>n;
    while (n--)
    {
        cin >>lla;
        maxn= max(maxn,lla);
        ans +=lla;
    }
    ans -= maxn/2;
    cout<<ans<<endl;





#ifdef VSCode
    system("pause");
#endif
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

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

const int inf = INT_MAX;
const long long MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll K, N;
ll A[201010];
ll cntneg;

int main() {
  cin >> N >> K;
  rep(i, 0, N) {
    cin >> A[i];
    if (A[i] < 0) ++cntneg;
  }

  if (N == K) {
    ll ans = 1;
    rep(i, 0, N) {
      ans *= A[i];
      ans += MOD * MOD;
      ans %= MOD;
    }
    cout << ans;
    return 0;
  }

  if (K % 2 == 1 && cntneg == N) {
    sort(A, A + N, greater<ll>());
    ll ans = 1;
    rep(i, 0, K) {
      ans *= A[i];
      ans += MOD * MOD;
      ans %= MOD;
    }
    cout << ans;
    return 0;
  }

  sort(A, A + N, [](ll a, ll b) { return abs(a) > abs(b); });
  ll ans = 1;
  ll negink = 0;
  rep(i, 0, K) {
    ans *= A[i];
    ans += MOD * MOD;
    ans %= MOD;
    if (A[i] < 0) ++negink;
  }
  if (negink % 2 == 0) {
    cout << ans;
    return 0;
  }

  ll negpos = -1;
  ll pospos2 = -1;
  for (ll i = K - 1; i >= 0; --i) {
    if (negpos == -1 && A[i] < 0) {
      negpos = i;
    }
    if (pospos2 == -1 && A[i] >= 0) {
      pospos2 = i;
    }
  }

  ll pospos = -1;
  ll negpos2 = -1;
  for (ll i = K; i < N; ++i) {
    if (pospos == -1 && A[i] >= 0) {
      pospos = i;
    }
    if (negpos2 == -1 && A[i] < 0) {
      negpos2 = i;
    }
  }

  if (pospos2 != -1 && negpos2 != -1 &&
      (pospos == -1 || (A[negpos] * A[negpos2] > A[pospos] * A[pospos2]))) {
    ans = 1;
    rep(i, 0, K) {
      if (i == pospos2) continue;
      ans *= A[i];
      ans += MOD * MOD;
      ans %= MOD;
    }
    ans *= A[negpos2];
    ans += MOD * MOD;
    ans %= MOD;

    cout << ans;
  } else {
    ans = 1;
    rep(i, 0, K) {
      if (i == negpos) continue;
      ans *= A[i];
      ans += MOD * MOD;
      ans %= MOD;
    }
    ans *= A[pospos];
    ans += MOD * MOD;
    ans %= MOD;

    cout << ans;
  }
}


Measured memory_bytes: 5156