akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
    
  int A;
  int B;
  int C;
  
  cin >> A;
  cin >> B;
  cin >> C;
  
  if ( C > A - B ) {
    
    cout << C - A + B << endl;
  }
  
  if ( C <= A - B ) {
    
    cout << 0 << endl;
    
    return 0;
  }
  
}


Measured memory_bytes: 3608
num = [0 for i in range(4)]

for i in range(4):
    num[i] = int(input())

count = 0
for i in range(num[0]+1):
    for j in range(num[1]+1):
        for k in range(num[2]+1):
            sum_1 = 500*i+100*j+50*k
            if sum_1 == num[3]:
                count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    if((a + b) % 2) return cout << "IMPOSSIBLE", 0;
    cout << (a + b) / 2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <functional>


using namespace std;

int main() {
  int x,n;
  cin>>x>>n;
  vector<int> a(n,0);

  map<int,int> A;
  int s;
  for(int i=0;i<n;i++){
    cin>>s;
    A[s] = 1;  
  }
  /*
  sort(a.begin(),a.end(),greater<int>());

  int min = 1000;
  int minnam = 0;
  for(int i=0;i<n;i++){
    if(abs(x - a[i]) <=min){
      minnam = a[i]
    }
    }*/

  int ans = x;
  bool flag = false;
  int i=0;
  while(!flag){
    decltype(A)::iterator it = A.find(x-i);
    if (it == A.end()){ // 見つからなかった
      ans = x-i;
      flag = true;
      break;
    }
    decltype(A)::iterator iT = A.find(x+i);
    if (iT == A.end()){ // 見つからなかった
      ans = x+i;
      flag = true;
      break;
    }
    i++;
    
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <cstring>

using namespace std;

const char t[20]="CODEFESTIVAL2016";

int main(){
	char s[20];//,t[20];
	scanf("%s",s);
	int cnt=0;
	//strcpy()
	for (int i=0;i<strlen(s);i++)
		if (s[i]!=t[i]) cnt++;
	cout << cnt<<endl;
	return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
const int maxn=100+10;
int a[maxn];
int n;
void bubble_sort(int a[],int n)
{
    int swap_cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>0;j--)
        {
            if(a[j]<a[j-1])
            {
                int tmp=a[j];
                a[j]=a[j-1];
                a[j-1]=tmp;
                swap_cnt++;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",swap_cnt);


}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
bubble_sort(a,n);
    return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int main(){
string N;
  cin>>N;
  bool majika=false;
  for(int i=0;i<N.size();i++){
   if(N.at(i)=='7'){
   majika=true;
   }
  }
if(majika){
cout<<"Yes";
}
  else{
  cout<<"No";
  }
}


Measured memory_bytes: 3532
#include <iostream>
#include <queue>
#define INF 300000

using namespace std;

typedef pair<int, int> p;

int w, h, n, result, steps;
int visited[1000][1000];
bool map[1000][1000];
p start, last_start, goal, cur, cheese[10];
queue<p> myqueue;

void init(int in){
    start = last_start;

    while(!myqueue.empty()) myqueue.pop();

    for(int i=0; i<w; ++i){
        for(int j=0; j<h; ++j){
            if(map[i][j] == false){
                visited[i][j] = -1;
            }else{
                visited[i][j] = INF;
            }
            goal = cheese[in];
        }
    }
    /*for(int i=0; i<w; ++i){
        for(int j=0; j<h; ++j){

            cout << visited[i][j] << " ";

        }
        cout << endl;
    }*/

    return ;
}

int main(){
    cin >> w >> h >> n;

    char input;
    for(int i=0; i<w; ++i){
        for(int j=0; j<h; ++j){
            cin >> input;
            if(input == 'X') map[i][j] = false;
            else             map[i][j] = true;
            if(input == 'S')
                last_start = make_pair(i, j);
            if(input != 'X' && input != 'S' && input != '.'){
                cheese[input-'0'] = make_pair(i, j);
            }
        }
    }


    result = 0;
    for(int i=1; i<=n; ++i){
        init(i);
        myqueue.push(start);
        visited[start.first][start.second] = 0;

        while(!myqueue.empty()){

            /*for(int k=0; k<w; ++k){
                for(int j=0; j<h; ++j){

                    cout << visited[k][j] << " ";

                }
                cout << endl;
            }
            cout << endl;*/

            cur = myqueue.front();
            myqueue.pop();

            if(cur == goal){
                //cout << "goal " << cur.first << " , " << cur.second << "\n";
                break;
            }

            //visited[cur.first][cur.second] = 0;

            int x = cur.first, y = cur.second;
            if(x-1 >= 0 && visited[x-1][y]==INF){
                myqueue.push(make_pair(x-1, y));
                visited[x-1][y] = visited[x][y]+1;
            }
            if(y-1 >= 0 && visited[x][y-1]==INF){
                myqueue.push(make_pair(x, y-1));
                visited[x][y-1] = visited[x][y]+1;
            }
            if(x+1 < w && visited[x+1][y]==INF){
                myqueue.push(make_pair(x+1, y));
                visited[x+1][y] = visited[x][y]+1;
            }
            if(y+1 < h && visited[x][y+1]==INF){
                myqueue.push(make_pair(x, y+1));
                visited[x][y+1] = visited[x][y]+1;
            }
        }

        result += visited[goal.first][goal.second];
        //cout << visited[goal.first][goal.second] << endl;
        last_start = goal;
    }

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 8016
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    ll ganpon = 100;
    ll n = 0;
    while (ganpon < x) {
        ganpon *= 1.01;
        n++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll countGreater(ll arr[], ll n, ll k) 
{ 
    ll l = 0; 
    ll r = n - 1; 
  
 
    ll leftGreater = n; 
  
 
    while (l <= r) { 
        ll m = l + (r - l) / 2; 
  
        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
 
        else
            l = m + 1; 
    } 
  
   
    return (n - leftGreater); 
}
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}

ll ans(ll A[],ll left,ll right,ll x)
{
    if(A[left]==x)return 1;

    else if(A[right==x])return 1;

   ll m=left+(right-left)/2;
   while(left<=right)
   {
    if(A[m]>x)right=m-1;
    else if(A[m]<x)left=m+1;
    else return 1;
   }
   return 0;
} 
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n,a,b,i,ans=0,temp;
cin>>n>>a>>b;
  

  ans=n/(a+b);

  temp=n-ans*(a+b);

ans*=a;
  if(temp<=a)ans+=temp;
  else ans+=a;

  
 

  cout<<ans<<endl;

    return 0;
    
}


 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  string ans;
  REPr(i, n){
    if(s[i] != 'B'){
      ans += s[i];
    }else{
      int j = 0;
      while(i >= 0 && s[i] == 'B'){
        i--;
        j++;
      }
      i -= j-1;
    }
  }
  reverse(ALL(ans));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
ss=raw_input().split()
w=int(ss[0])
h=int(ss[1])
a=[]
b=[]
for i in range(w):
    p=input()
    a.append(p)
for i in range(h):
    p=input()
    b.append(p)
a.sort()
b.sort()
h1=0
h2=0
ans=0
while ((h1<w) and (h2<h)):
    if a[h1]<b[h2]:
        ans+=a[h1]*(h - h2+1)
        h1+=1
    else :
        ans += b[h2] * (w-h1+1)
        h2 += 1
while (h1<w):
    ans+=a[h1]
    h1+=1
while (h2<h):
    ans+=b[h2]
    h2+=1
print ans

Measured memory_bytes: 12404
n=int(input())
cnt=0
cnta=0
cntb=0
cntba=0
for i in range(n):
    s=input()
    for i in range(1,len(s)):
        if s[i]=='B' and s[i-1]=='A':
            cnt+=1
    if s[-1]=='A' and s[0]=='B':
        cntba+=1
    elif s[-1]=="A":
        cnta+=1
    elif s[0]=="B":
        cntb+=1
#print(cnt,cnta,cntb,cntba)
if cntb==0 and cntba==0:
    print(cnt)
elif cntb==0 and cntba!=0:
    print(cnt+min(cntba+cntb,cntba+cnta-1))
else:
    print(cnt+min(cntb+cntba,cnta+cntba))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

long long n, sum;

long long getSum(long long x, long long base) {
  long long res = 0;
  while (x) {
    res += x % base;
    x /= base;
  }
  return res;
}

int main() { 

  cin >> n >> sum;

  // long long stupidAns = -1;
  // for (long long i = 2; i <= n + 1; i++) {
  //   if (getSum(n, i) == sum) {
  //     stupidAns = i;
  //     break;
  //   }
  // }
  // cerr << "stupid: " << stupidAns << endl;

  // map <long long, vector<int>> mp;
  // for (int i = 2; i <= n + 1; i++) {
  //   mp[getSum(n, i)].push_back(i);
  // } 

  // cerr << "Total: " << sz(mp) << endl;
  // for (auto p : mp) {
  //   cerr << p.first << ": ";
  //   for (int bs : p.second) {
  //     cerr << bs << " ";
  //   }
  //   cerr << endl;
  // }

  if (sum == n) {
    cout << n + 1 << endl;
    return 0;
  }

  long long mx = (n + 1) / 2;
  if (sum > mx) {
    cout << -1 << endl;
    return 0;
  }

  long long ans = n - (sum - 1);
  for (long long i = 2; i * i <= n; i++) {
    if (getSum(n, i) == sum) {
      ans = min(ans, i);
      break;
    }
  }

  long long base = n - (sum - 1);
  for (long long i = 1; i * i <= n; i++) {
    long long cur = base + i;
    if (cur % (i + 1) == 0) {
      if (getSum(n, cur / (i + 1)) == sum) {
        ans = min(ans, cur / (i + 1));
      }
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

int main() {
  int n;
  string s;
  int k;
  cin >> n;
  cin >> s;
  cin >> k;

  char t = s[k - 1];

  for (int i = 0; i < n; ++i) {
    if (s[i] != t) {
      cout << "*";
    } else {
      cout << t;
    }
  }

  END;
}


Measured memory_bytes: 256
N = int(input())
c = str(input())

if 'R' in c:
  rc = c.count('R')
  change = c[:rc].count('W')
  right = 0
  for i in range(N):
    if c[N-1-i] == 'R':
      right = N-i
      break
  paint = c[:right].count('W')
  ans = min(change, paint)
else:
  ans = 0
print(ans)

Measured memory_bytes: 9352
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin2(n,l);
    int eat = 10000000000;
    int taste = 0;
    int apple_id = 0;
    for(int i=1;i<=n;i++){
        taste += (l+i-1);
        if(abs(l+i-1)<eat){
            eat = abs(l+i-1);
            apple_id = i;
        }
    }
    cout<<taste-(l+apple_id-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x=0,i,j;
	string s;
	cin>>s;
	for(i=s.length()-1;i>=0;i--)
	{
	    //cout<<x<<" "<<s[i]<<endl;
		if(s[i]>'5' || (i!=0 && s[i]=='5' && s[i-1]>='5'))
		{
			x+=10-(s[i]-'0');
			j=i-1;
			while(j!=-1)
			{
			    if(s[j]<'9')
			    {
			        s[j]++;
			        break;
			    }
			    else
			    {
                    s[j]='0';
			        j--;
			    }
			}
			if(j==-1)
			{
			    x++;
			}
		}
		else
		{
		    x+=(s[i]-'0');
		}
	}
	cout<<x;
	return 0;
}

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

double bd[3000][3000], p;

int main() {
	int n;
	cin >> n;
	bd[0][0] = 1;
	for (int i=1; i<=n; i++) {
		cin >> p;		
		for (int j=0; j<=i; j++) {
			if (j==0) 
				bd[i][j] = bd[i-1][j]*p;
			else if (j==i)
				bd[i][j] = bd[i-1][j-1]*(1-p);
			else bd[i][j] = bd[i-1][j-1]*(1-p)+bd[i-1][j]*p;
		}
	}
	double ans=0;
	for (int i=0; 2*i<n; i++)
		ans += bd[n][i];
	cout.precision(10);
	cout << ans << "\n"; 
}

Measured memory_bytes: 68864
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_D

# W,H,x,y,r
input_data = input().split(' ')

W, H, x, y, r = [int(i) for i in input_data]

if (x-r) >= 0 and (y-r) >= 0 and W >= (x+r) and H >= (y+r):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7704
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int h, w, n, a[10003], i, j, ci, cj, ni, nj, t, count, dir, ans[103][103] = {};

    scanf("%d%d%d", &h, &w, &n);
    i = 0;
    while (i < n)
    {
        scanf("%d", &a[i]);
        i++;
    }

    ci = cj = 0;
    t = 0;
    count = 0;
    dir = 0;
    while (t < n)
    {
        ans[ci][cj] = t + 1;
        count++;
        if (count == a[t])
        {
            count = 0;
            t++;
        }
        ni = ci + di[dir];
        nj = cj + dj[dir];
        if (ni == -1 || ni == h || nj == -1 || nj == w || ans[ni][nj] != 0)
            dir = (dir + 1) % 4;
        ci = ci + di[dir];
        cj = cj + dj[dir];
    }

    i = 0;
    while (i < h)
    {
        j = 0;
        while (j < w)
        {
            printf("%d", ans[i][j]);
            if (j == w - 1)
                printf("\n");
            else
                printf(" ");
            j++;
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 3840
/*
AizuOnline A0510
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int ia,ma,sa,ea;
int ib,mb,sb,eb;
int ta,tb;
//
main()
{
  scanf("%d %d %d %d",&ia,&ma,&sa,&ea);
  scanf("%d %d %d %d",&ib,&mb,&sb,&eb);
  ta=ia+ma+sa+ea;
  tb=ib+mb+sb+eb;

  printf("%d\n",(ta>tb)?ta:tb);


return(0);
}

Measured memory_bytes: 588
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0;v < n;v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0;u < n;u++) color[u] = WHITE;
    tt = 0;
    for(u = 0;u < n;u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n;u++){
        printf("%d %d %d\n",u + 1,d[u],f[u]);
    }
}

int main(){
    int u,v,k,i,j;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        for(j = 0;j < n;j++) M[i][j] = 0;
    }
    for(i = 0;i<n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j = 0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


Measured memory_bytes: 2112
H, W, D = gets.split.map(&:to_i)
board = H.times.map { gets.split.map(&:to_i) }
Q = gets.to_i
lrs = Q.times.map { gets.split.map(&:to_i) }

n_to_cell = {}
board.each.with_index do |row, i|
  row.each.with_index do |n, j|
    n_to_cell[n] = [i, j]
  end
end
costs = Array.new(H * W + 1) { 0 }
D.times do |n|
  n += 1
  cost = 0
  i = nil
  j = nil
  n.step(by: D, to: H * W) do |m|
    x, y = n_to_cell[m]
    if i && j
      cost += (x - i).abs + (y - j).abs
    end
    costs[m] = cost
    i = x
    j = y
  end
end

lrs.each do |(l, r)|
  ans = costs[r] - costs[l]
  puts ans
end


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

int main(void)
{
    char s[4];
    cin >> s;
    if (s[1] == 'B')
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
  int a,b,real,i,count=0;
  scanf("%d%d", &a,&b);
  if(b<10) real=a*10+b;
  else if(b==100) real=a*1000+b;
  else real=a*100+b;
  for(i=4; i*i<=100100; i++)
  {
    if(real==i*i) count=1;
  }
  if(count==1) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if i1==1:
    ans=clist[i2-1]
  elif l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-2]-1
  else:
    ans=clist[i2-1]-clist[i1-2]
  print(ans)


Measured memory_bytes: 6872
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int abc(int a,int b) {
	int x = 0;
	for (int i = b; i <= a; i++) {
		for (int j = b; j <= a; j++) {
			if (j % i >= b)x++;
		}

	}
	return x;
}

int main() {
	int a;
	int x = 0;
	int y = 0;
	cin >> a;
	vector<int> s(a);
	rep(i, a) {
		cin >> s[i];
	}
	sort(s);
	for (int j = a - 1; j >= 0; j--) {
		if ((a - j) % 2 == 1)x += s[j];
		else y += s[j];
	}
	cout << x - y << endl;
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}

void solve()
{
    ll N; cin >> N;
    vll A(N); REP(i, N) cin >> A[i];
    vll t(N, -1);
    ll g = A[0];
    for(int i = 1; i < N; i++)
    {
        g = gcd(g, A[i-1]);
        if(t[i] == -1) t[i] = g;
    }
    g = A[N-1];
    for(int i = N-2; i >= 0; i--)
    {
        g = gcd(g, A[i+1]);
        if(t[i] == -1) t[i] = g;
        else t[i] = gcd(g, t[i]);
    }
    cout << *max_element(ALL(t)) << endl;
}
    
signed main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int no_of_input;
  int input;
  vector<int> vect1;
  multiset<int> currhas;
  cin >> no_of_input;
  for(int i=0;i<(1<<no_of_input);i++){
    cin >> input;
    vect1.push_back(input);
  }
  multiset<int> set1;
  sort(vect1.begin(),vect1.end());
  currhas.insert(vect1[vect1.size()-1]);
  for(int i=0;i<vect1.size()-1;i++){
    set1.insert(vect1[i]);
  }
  for(int i=0;i<no_of_input;i++){
    vector<int> temp;
    for(auto k:currhas){
      auto j = set1.lower_bound(k);
      if(j==set1.begin()){
        cout << "No";
        return 0;
      }
      j--;
      temp.push_back(*j);
      set1.erase(j);
    }
    for(auto k:temp){
      currhas.insert(k);
    }
  }
  cout << "Yes";

}

Measured memory_bytes: 16112
s = input()
flag = 1
while len(s)>4:
    if s[-5:]=='dream':
        s = s[:-5]
    elif s[-5:]=='erase':
        s = s[:-5]
    elif s[-6:]=='eraser':
        s = s[:-6]
    elif s[-7:]=='dreamer':
        s = s[:-7]
    else:
        flag = 0
        break
if len(s):
    flag = 0
if flag:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
int cnt[MAXN][26];
int dp[MAXN][26];
int letter[MAXN];
int now_term[MAXN];
int start_here[MAXN];
int cur=1;
ll ans=0;
void dfs(int s)
{
    for (int i=0;i<26;i++)
    {
        if (cnt[s][i]!=0)
        {
            dfs(cnt[s][i]);
            for (int f=0;f<26;f++)
                dp[s][f]+=dp[cnt[s][i]][f];
            now_term[s]+=now_term[cnt[s][i]];
        }
    }
//    cout<<s<<" "<<letter[s]<<" "<<start_here[s]<<" "<<now_term[s]<<'\n';
    for (int i=0;i<26;i++) {
        if (cnt[s][i]!=0) {
        //    cout<<s<<" "<<start_here[cnt[s][i]]<<" "<<dp[s][letter[cnt[s][i]]] - start_here[cnt[s][i]]<<'\n';
            ans += 1ll*start_here[cnt[s][i]] * (dp[s][letter[cnt[s][i]]] - start_here[cnt[s][i]]);
        }
    }
    if (s!=0) {
        dp[s][letter[s]] = now_term[s];
    }
}
void solve()
{
    int n;
    cin>>n;
    vector <string> s(n);
    rep(i,n) {
        cin >> s[i];
        reverse(all(s[i]));
    }
    for (auto &to:s)
    {
     //   cout<<to<<'\n';
        int now=0;
        int f=0;
        for (auto x:to)
        {
           // cout<<now<<'\n';
            if (cnt[now][x-'a']==0)
            {
                cnt[now][x-'a']=cur++;
                now=cur-1;
                letter[now]=x-'a';
            } else
                now=cnt[now][x-'a'];
            f++;
        }
    //    cout<<now<<'\n';
        now_term[now]++;
        start_here[now]++;
    }
    dfs(0);
    cout<<ans<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
//    cin>>_t;
    _t=1;
    while (_t--)
        solve();


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 303888
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int count=0;
    for(int i = 0; i< N; i++){
        int a,b;
        cin >> a >> b;

        if(a==b) count++;
        if(a != b && count < 3) count = 0;
    }
    if(count >= 3){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

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

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> b;
	for (int i = 3; i < 30000; i += 2) {
		if (i % 3 == 0 || i % 5 == 0) b.push_back(i);
	}
	vector<int> a;
	for (int i = 0; i+1 < N-1 && i+1 < (int)b.size(); i += 2) {
		a.push_back(b[i]);
		a.push_back(b[i+1]);
	}
	int p = 2;
	while ((int)a.size() < N-1) {
		a.push_back(p);
		p += 2;
	}
	int sum = 0;
	for (auto x : a) sum += x;
	while ((sum + p) % 30 != 0) p += 2;
	for (auto x : a) cout << x << " ";
	cout << p << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define ex5 (100000+10)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
int main()
{
#ifdef COMPILE_IN_VCPP
	SetWindowPos(GetConsoleHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
		(SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW));
#endif
	static int n, a[200000 + 10], i, j,max1=0,max2=0,nm=0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		max1 = max(max1, a[i]);
	}
	for (i = 1; i <= n; i++)
	{
		if (a[i] != max1) max2 = max(max2, a[i]);
		if (a[i] == max1) nm++;
	}
	for (i = 1; i <= n; i++)
	{
		if (a[i] == max1 && nm == 1) cout << max2 << endl;
		else cout << max1 << endl;
	}
}

Measured memory_bytes: 2432
import bisect

n = int(input())
l = sorted([int(li) for li in input().split()])

sum = 0
for i in range(n-1,-1,-1):
    for j in range(i-1,-1,-1):
        k = bisect.bisect_right(l,l[i]-l[j])
        sum += j-k if j>k else 0

print(sum)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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


    ll first = 0;
    rep(i, n) {
        if (i % 2 == 0) first += dam[i];
        else first -= dam[i];
    }
    cout << first << endl;

    rep(i, n) {
        if (i == 0) continue;
        first -= dam[i - 1];
        first = -first;
        first += dam[i - 1];
        cout << first << endl;
    }

}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N,M;cin>>N>>M;
  std::vector<int> v(M);
  for(int i=0;i<M;i++)cin>>v[i];
  sort(v.begin(),v.end());
  if(N>=M){cout<<0<<endl;return 0;}
  std::vector<int> w(M-1);
  for(int i=0;i<M-1;i++)w[i]=v[i+1]-v[i];
  sort(w.begin(),w.end());
  int ans=0;
  for(int i=0;i<M-1-(N-1);i++)ans+=w[i];
  cout<<ans<<endl;
}


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

using namespace std;

int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int t1 = h1 * 60 + m1;
	int t2 = h2 * 60 + m2;
	int len = t2 - t1;
	int ans = max(0, len - k);
	cout << ans << endl;
}

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

public class Main{
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] cmd=br.readLine().split(" ");
		int x=Integer.valueOf(cmd[0]);
		int y=Integer.valueOf(cmd[1]);
		int a=y-2*x;
		int b=4*x-y;
		if(a>=0 && a%2==0 && b>=0 && b%2==0)
		{
			System.out.println("Yes");
		}
		else
			System.out.println("No");
	}

}


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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin>>N;
  int p[N],max=0,maxnumber=0;
  for(int i=0;i<N;i++){
    cin>>p[i];
    if(max<=p[i]){
      max=p[i];
      maxnumber=i;
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(i==maxnumber){
      ans+=p[i]/2;
    }else{
      ans+=p[i];
    }
  }
  cout<<ans;


  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			
			String str = sc.next();
			
			for(int i = 0; i < n; i++){
				StringBuilder sb = new StringBuilder();
				int before = -1;
				int count = 0;
				
				for(char c : str.toCharArray()){
					if(before == -1 || before == c - '0'){
						before = c - '0';
						count++;
					}else if(before != c - '0'){
						sb.append(count + "" + before);
						before = c - '0';
						count = 1;
					}	
				}
				
				if(before != -1 && count > 0){
					sb.append(count + "" + before);
				}
				
				str = sb.toString();	
			}
			
			System.out.println(str);
			
		}
		
	}
}

Measured memory_bytes: 13000
/**
*    author:  boutarou
*    created: 14.06.2020 21:50:21
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;
const lint INF = 3e18;
const int dy[] = { 0, 0, -1, 1 };
const int dx[] = { 1, -1, 0, 0 };

int h, w, k;
int sy, sx, gy, gx;
vector<char>c[1000005];
vector<lint>shortest[1000005];
queue<P>que;

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

	cin >> h >> w >> k;
	cin >> sy >> sx >> gy >> gx;
	sy--, sx--, gy--, gx--;
	rep(i, h) {
		rep(j, w) {
			shortest[i].push_back(INF);
		}
	}
	rep(i, h) {
		rep(j, w) {
			char now;
			cin >> now;
			c[i].push_back(now);
			if (now == '@') {
				shortest[i][j] = -1;
			}
		}
	}
	
	shortest[sy][sx] = 0;
	que.push({ sy, sx });
	while (!que.empty()) {
		P now = que.front(); que.pop();
		int now_y = now.first, now_x = now.second;
		rep(i, 4) {
			int ny = now_y + dy[i], nx = now_x + dx[i];
			rep(j, k) {
				if (ny < 0 || ny >= h || nx < 0 || nx >= w) break;
				if (shortest[ny][nx] <= shortest[now_y][now_x]) break;
				if (shortest[ny][nx] == shortest[now_y][now_x] + 1) {
					ny += dy[i], nx += dx[i];
					continue;
				}
				que.push({ ny, nx });
				shortest[ny][nx] = shortest[now_y][now_x] + 1;
				ny += dy[i], nx += dx[i];
			}
		}
	}
	if (shortest[gy][gx] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << shortest[gy][gx] << endl;
	}

	return 0;
}

Measured memory_bytes: 60300
class Dice(object):
    def __init__(self, numbers: list):
        self.numbers = dict(zip(("T", "S", "E", "W", "N", "B"), numbers))

    def _roll(self, old_part: tuple):
        new_part = old_part[1:] + (old_part[0],)
        new_numbers = [self.numbers[face] for face in new_part]

        for old, new in zip(old_part, new_numbers):
            self.numbers[old] = new

    def vroll(self, reverse=False):
        """北方向に回転"""
        old_part = ("N", "T", "S", "B")
        self._roll(old_part if not reverse else old_part[::-1])

    def hroll(self, reverse=False):
        """時計回りに回転"""
        old_part = ("N", "W", "S", "E")
        self._roll(old_part if not reverse else old_part[::-1])

    def roll_to(self, direction: str):

        if direction == "N":
            self.vroll()
        elif direction == "S":
            self.vroll(reverse=True)
        elif direction == "E":
            self.hroll(reverse=True)
            self.vroll()
            self.hroll()
        elif direction == "W":
            self.hroll()
            self.vroll()
            self.hroll(reverse=True)
        else:
            raise AssertionError

    def set_pos(self, top, front):
        numbers = self.numbers
        if top in (numbers["E"], numbers["W"]):
            self.hroll()
        while top != numbers["T"]:
            self.vroll()
        while front != numbers["S"]:
            self.hroll()


numbers = list(map(int, input().split()))
dice = Dice(numbers)

outs = []
for _ in range(int(input())):
    top, front = map(int, input().split())
    dice.set_pos(top, front)
    outs.append(dice.numbers["E"])

print(*outs, sep="\n")



Measured memory_bytes: 5620
using System.Linq;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadLine().Split().Select(int.Parse).ToList();
            var n = nm[0];
            var m = nm[1];

            var a = ReadLine().Split().Select(int.Parse).ToList();

            var leftDays = n;
            for(int i = 0; i < m; i++)
            {
                leftDays = leftDays - a[i];
                if(leftDays < 0)
                {
                    leftDays = -1;
                    break;
                }
            }
            WriteLine(leftDays);
        }
    }
}


Measured memory_bytes: 29076
fun main(args: Array<String>) {
  var N = readLine()!!.toInt()
  var AC_count = 0
  var WA_count = 0
  var TLE_count = 0
  var RE_count = 0
  for (n in 0 until N) {
    var result = readLine()!!
    
    when(result) {
      "AC" -> AC_count++
      "WA" -> WA_count++
      "TLE" -> TLE_count++
      "RE" -> RE_count++
    }
  }
  println("AC x $AC_count")
  println("WA x $WA_count")
  println("TLE x $TLE_count")
  println("RE x $RE_count")
}

Measured memory_bytes: 57532
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
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; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll n;
ll a[500][500];
int main(){
  cin >> n;
  ll cou;
  ll tmp3,tmp4;
  rep(i,n){
    REP(j,i+1,n){
      cou = 1;
      while(1){
        tmp1 = i / (ll)pow(2,cou);
        tmp2 = j / (ll)pow(2,cou);
        if(tmp1 == tmp2){
          a[i][j] = cou;
          break;
        }else{
          cou++;
        }
      }
    }
  }
  rep(i,n){
    REP(j,i+1,n){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 2432
/*****************************************************
 				*	Logged in : HABIBUR RAHMAN						 *
				*	Dept	  : COMPUTER SCIENCE AND ENGINEERING	 *
				*													 *
				*	KHULNA UNIVERSITY OF ENGINEERING AND TECHNOLOGY  *
				******************************************************/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
#define fast_io 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 				v.begin(),v.end()
#define allr(v) 			v.rbegin(),v.rend()
#define rep(i,a,b) 			for(ll i=a;i<=b;i++)
#define rep0(i,n)			for(ll i=0;i<n;i++)
#define rrep0(i, n) 		for(ll i=(ll)(n);i>0;--i)
#define rrep(i, a, b) 		for(ll i=(ll)(a);i>=(ll)(b);--i)
#define pb(z) 				push_back(z)
#define ff					/first
#define ss 					second
#define caset 				int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define sz(X) 				((ll)(X).size())
#define scan(X) 			scanf("%s", (X))
#define ms(v,val)			memset((v),(val),sizeof((v)))
#define ms0(X) 				memset((X), 0, sizeof((X)))
#define ms1(X) 				memset((X), -1, sizeof((X)))
#define m_p(a,b)            make_pair(a,b)
#define get_pos(c,x) 		(lower_bound(c.begin(),c.end(),x)-c.begin())
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define INF9                1000000010
#define INF18               4000000000000000010
#define bpll(a)             __builtin_popcountll(a)
#define sqr(a)              ((a)*(a))
#define nl					"\n"
#define mod					1e9+7;
#define mx_el(v)			*max_element(all(v));
#define mn_el(v)			*min_element(all(v));
#define pcase(z,x)    		cout<<"Case "<<z<<": "<<x<<"\n"
const double pi = 2*acos(0) ;
#define display(v)			vi :: iterator it;for(it=(v).begin();it!=(v).end();it++){cout << *it << " " ;}cout << endl;
#define taking(n,v) 		for(ll i=0;i<(n);i++){ll inp;cin>>inp;(v).push_back(inp);}

void start(){
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
}

void solve()
{
 	ll n;cin>>n;
 	ll a[n+3],b[n+1],c[n];
 	for(int i=1;i<=n;i++){
 		cin>>a[i];
	 }
	 for(int i=1;i<=n;i++){
 		cin>>b[i];
	 }
	 for(int i=1;i<n;i++){
 		cin>>c[i];
	 }
	 ll sum=b[a[1]];
	 for(int i=2;i<=n;i++){
	 	if(a[i]-a[i-1]==1){
	 		sum+=(b[a[i]]+c[a[i]-1]);
		 }
		 else sum+=b[a[i]];
	 }
	 cout << sum << nl;
}

int main(){
	fast_io
	//start();
    //caset{
    	//cout << "Case " << tt << ": ";

		  solve();
	//}
	
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<31)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//enum LR{L=-1,R=1};
int w,h;
char s[65][35];
int ddx[9]={1,1,1,1,1,2,2,2,3};
int ddy[9]={2,1,0,-1,-2,1,0,-1,0};
int dis[65][35][2];

struct cliff{
	int x;
	int y;
	int cost;
	int LR;
	cliff(int _x,int _y,int _cost,int _LR){
		x=_x;
		y=_y;
		cost=_cost;
		LR=_LR;
	};
	bool operator<(const cliff& c) const{
		return cost>c.cost;
	}
};
priority_queue<cliff> PP;
int main(){
	while(1){
		cin>>w>>h;
		if(w==0&&h==0)break;
		REP(i,65)
			REP(j,35)
				REP(k,2)
				dis[i][j][k]=1e8;
		for(int i=h-1;i>=0;i--){
			for(int j=0;j<w;j++){
				cin>>s[i][j];
				if(s[i][j]=='S'){
					PP.push(cliff(j,i,0,-1));//右足がついている
					PP.push(cliff(j,i,0,1));//左足
					dis[i][j][0]=0;
					dis[i][j][1]=0;
				}
			}
		}
		//cout<<PP.size()<<endl;
		int cou=0;
		while(PP.size()){
			
			cliff c=PP.top();PP.pop();
			//if(cou<=4)cout<<c.x<<c.y<<c.LR<<endl;
			for(int i=0;i<9;i++){
				int nx=c.x+ddx[i]*c.LR;
				int ny=c.y+ddy[i];
				if(0<=nx&&nx<w&&0<=ny&&ny<h){
					if(s[ny][nx]!='X'){
						int nLR;
						if(c.LR==-1)nLR=1;
						else nLR=0;
						int ncost;
						if(s[ny][nx]=='T')ncost=0;
						else if(s[ny][nx]>='1'&&s[ny][nx]<='9')ncost=s[ny][nx]-'0';
						else continue;
						if(dis[ny][nx][nLR]==1e8){
							dis[ny][nx][nLR]=ncost+c.cost;
							if(ncost!=0){
								PP.push(cliff(nx,ny,dis[ny][nx][nLR],c.LR*-1));
							}
						}
					}
				}
			}
			cou++;
		}
		int ans=1e8;
		for(int i=h-1;i>=0;i--){
			for(int j=0;j<w;j++){
				//printf("%10d",dis[i][j][0]);
				if(s[i][j]=='T'){
					ans=min(min(ans,dis[i][j][0]),dis[i][j][1]);
				}
			}
			//cout<<endl;
		}
		//cout<<endl;
		/*for(int i=h-1;i>=0;i--){
			for(int j=0;j<w;j++){
				printf("%10d",min(dis[i][j][1],dis[i][j][0]));
			}
			cout<<endl;
		}*/
		
		if(ans==1e8)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}
		


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

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256