akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n, x;

	std::cin >> n >> x;

	std::vector<int> v(n);

	int min = 100000000;
	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
		min = std::min(min, v[i]);
		x -= v[i];
	}

	int ans = n + x / min;

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



	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	
	int x, y;
	
	while( cin >> x >> y) {
		
		int A[100][100] = {}, B[100][1] ={}, C[100][1] = {};
		
		for(int i=0;i<x;i++)
		for(int j=0;j<y;j++)
		cin >> A[i][j];	

		for(int i=0;i<y;i++)
		cin >> B[i][0];	
	
		for(int i=0;i<x;i++)
			for(int j=0;j<y;j++)
			C[i][0] += A[i][j] * B[j][0]; 
		
		for(int i=0;i<x;i++)
		cout << C[i][0] << "\n";
}
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;

    int s[m], c[m];
    for (int i=0; i<m; i++) {
        cin >> s[i] >> c[i];
    }

    int target[n];
    for (int i=0; i<n; i++) {
        target[i] = -1;
    }

    for (int i=0; i<m; i++) {
        if (n != 1) {
            if (s[i] == 1 && c[i] == 0) {
                cout << -1 << endl;
                return 0;
            }
        }

        if (target[s[i] - 1] == -1) {
            target[s[i] - 1] = c[i];
        } else if (target[s[i] - 1] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    int answer = 0;
    for (int i=0; i<n; i++) {
        if (target[i] == -1) {
            if (n == 1) {
                answer = 0;
            } else if (n - i == n) {
                answer += std::pow(10, n-i-1);
            }
        } else {
            answer += target[i] * (std::pow(10, n-i-1));
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
import numpy as np
num =  int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c = collections.Counter(prime_factorize(num))
ln = np.array(list(c.values()) )# 各素因数の乗数
#print('ln = ', ln )
minus = 1
number = 0
#print(number)
if len(ln) == 0:
    ln = [-1]
    
while max(ln) >= 0:
    ln = ln - minus
    #print(ln)
    for i in range(len(ln)):
        if ln[i] >= 0:
            number += 1
    
    minus += 1
print(number)    


Measured memory_bytes: 27224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long

int s[200005];

signed main(){
	
	int n;cin>>n;
	int ans = 0;
	while(n)
	{
		ans +=n%10;
		n /=10;
		
	}
	
	
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
int a[4][4], n, b[100], i, j, k, c[4][4]={};
for(i=1;i<=3;i++)
{
    for(j=1;j<=3;j++)
    {
        scanf("%d", &a[i][j]);
    }
}
scanf("%d", &n);
for(i=1;i<=n;i++)
{
    scanf("%d", &b[i]);
    for(j=1;j<=3;j++)
    {
        for(k=1;k<=3;k++)
        {
            if(a[j][k]==b[i])
                c[j][k]++;
        }
    }
}
    if(c[1][1]+c[1][2]+c[1][3]==3)
        printf("Yes");
    else if(c[2][1]+c[2][2]+c[2][3]==3)
        printf("Yes");
    else if(c[3][1]+c[3][2]+c[3][3]==3)
        printf("Yes");
    else if(c[1][1]+c[2][1]+c[3][1]==3)
        printf("Yes");
    else if(c[1][2]+c[2][2]+c[3][2]==3)
        printf("Yes");
    else if(c[1][3]+c[2][3]+c[3][3]==3)
        printf("Yes");
    else if(c[1][1]+c[2][2]+c[3][3]==3)
        printf("Yes");
    else if(c[3][1]+c[2][2]+c[1][3]==3)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
import sys

w, h, x, y = map(int, sys.stdin.readline().split())

def main():
    s = w * h / 2
    f = (x == w / 2 and y == h / 2) & 1
    return s, f

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define MAX_N 200005
#define INF 1000000000
#define bit(mask, i) (mask & (1<<i))
 
using namespace std;
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef long long ll;
typedef double lf;
 
lf PI = 2.0*acos(0.0);
 
int lis(vi &v) {
    set<int> p;
    for(int i = 0; i < (int)v.size(); ++i) {
        set<int>::iterator it = p.lower_bound(v[i]);
        if(it != p.end()) { p.erase(it); }
        p.insert(v[i]);
    }
    return p.size();
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    //freopen("acmproject.in", "r", stdin);
    //freopen("acmproject.out", "w", stdout);
 
    ii a, b;
    int n;
    cin>>a.first>>a.second>>b.first>>b.second>>n;
    vii fountains(n);
    while(n--) {
        cin>>fountains[n].first>>fountains[n].second;
    }
    sort(fountains.begin(), fountains.end());
    vi interval;
    if(a > b) { swap(a, b); }
    int x1 = a.first, x2 = b.first;
    int y1 = min(a.second, b.second), y2 = max(a.second, b.second);
    int c = a.second > b.second ? -1 : 1;
    for(int i =0; i < (int)fountains.size(); ++i) {
        if(fountains[i].first >= x1 && fountains[i].second >= y1 && fountains[i].first <= x2 && fountains[i].second <= y2) {
            interval.push_back(c*fountains[i].second);
        }
    }
    int l = lis(interval), x = b.first - a.first, y = abs(b.second - a.second);
    lf sol = 100.0*(lf)(x + y);
    sol += 5.0*(PI - 4.0)*(lf)l;
    if(l == min(x, y) + 1) { sol += 5.0*PI; }
 
    cout<<setprecision(16)<<fixed<<sol<<"\n";
 
    return 0;
}

Measured memory_bytes: 12020
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int K = stdIn.nextInt();
		int N = stdIn.nextInt();
		
		ArrayList<Integer> A = new ArrayList<Integer>();
		for(int i = 0; i < N; i ++) {
			A.add(stdIn.nextInt());
		}
		
		Collections.sort(A);
		int distance = 0;
		for(int i = 0; i < A.size(); i ++) {
			if(i == 0) {
				distance += A.get(i);
			}else {
				distance += A.get(i) - A.get(i - 1);
			}
			
			if(i == A.size() - 1) {
				distance += K - A.get(i);
			}
		}
		
		int longest = A.get(0) + K - A.get(A.size() - 1);
		
		for(int i = 1; i < A.size(); i ++) {
			longest = Math.max(longest, A.get(i) - A.get(i - 1));
		}
		
		System.out.println(distance - longest);
	}
}

Measured memory_bytes: 91888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int w, h, n;
	cin >> w >> h >> n;
	pair<int, int> cw, ch;
	cw.first = 0; cw.second = w;
	ch.first = 0; ch.second = h;
	int x, y, a;

	REP(i, n){
		cin >> x >> y >> a;
		switch (a){
			case 1:
				if (cw.first < x and x < cw.second) cw.first = x;
				else if (cw.second <= x) cw.second = cw.first;
				break;

			case 2:
				if (cw.first < x and x < cw.second) cw.second = x;
				else if (cw.first >= x) cw.first = cw.second;
				break;

			case 3:
				if (ch.first < y and y < ch.second) ch.first = y;
				else if (ch.second <= y) ch.second = ch.first;
				break;

			case 4:
				if (ch.first < y and y < ch.second) ch.second = y;
				else if (ch.first >= y) ch.first = ch.second;
				break;
		}
	}
	if (ch.second <= ch.first or cw.second <= cw.first) cout << 0 << endl;
	else cout << (ch.second - ch.first) * (cw.second - cw.first) << endl;

}


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


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

  int x[100010];
  int y[100010];
  int t[100010];

  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  
  for(int i=1;i<N+1;++i){
    cin >> t[i] >> x[i] >> y [i];
  }

  bool can = true;

  for(int i=0;i<N;++i){
    int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    int delta_t = t[i+1]-t[i];

    if(dist>delta_t || dist%2 != delta_t%2){
      can = false;
      break;
    }
    
    
  }



  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;


}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3000;

int N, M;
char S[MAXN+10], T[MAXN+10];
int dp[MAXN+10][MAXN+10], memo[MAXN+10][MAXN+10];
string ans;

int main()
{
    int i, j;

    scanf("%s%s", S+1, T+1);
    N=strlen(S+1); M=strlen(T+1);

    for(i=1; i<=N; i++) for(j=1; j<=M; j++)
    {
        if(S[i]==T[j]) dp[i][j]=dp[i-1][j-1]+1, memo[i][j]=1;
        else if(dp[i][j-1]>dp[i-1][j]) dp[i][j]=dp[i][j-1], memo[i][j]=2;
        else dp[i][j]=dp[i-1][j], memo[i][j]=3;
    }
    for(i=N, j=M; i>0 && j>0; )
    {
        if(memo[i][j]==1) ans+=S[i], i--, j--;
        else if(memo[i][j]==2) j--;
        else i--;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
}


Measured memory_bytes: 70912
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

int main(){
	
	while(true){
		int h, w;
		cin >> h >> w;
		if(h == 0){
			break;
		}
		string str[100];
		for(int i = 0; i < h; i++){
			cin >> str[i];
		}
		
		map<string, int> m;
		string ans = "";
		
		int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
		int dy[8] = {1, -1, 1, 0, -1, 1, 0, -1};
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				for(int k = 0; k < 8; k++){
					bool used[h][w] = {};
					string S = "", D = " ";
					int y = i, x = j;
					while(true){
						if(used[y][x]){
							break;
						}
						used[y][x] = true;
						D[0] = str[y][x];
						S += D;
						y += dy[k] + h;
						x += dx[k] + w;
						y %= h;
						x %= w;
						if(m.find(S) == m.end()){
							m[S] = 1;
						}else{
							if(ans.size() < S.size()){
								ans = S;
							}else if(ans.size() == S.size() && ans > S){
								ans = S;
							}
						}
					}
				}
			}
		}
		if(ans.size() == 1){
			cout << 0 << endl;
		}else{
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 37960
import sys

S = input()
center = len(S) // 2

if len(S) % 2 == 1:
    b = S[center]
    for i in range(1, center + 1):
        if S[center - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
else:
    b = S[center - 1]
    for i in range(center):
        if S[center - i - 1] != b or S[center + i] != b:
            print(center + i)
            sys.exit()

print(len(S))

Measured memory_bytes: 3188
#include <stdio.h>
#define MAX 1000

int main(){
	int H[MAX],W[MAX];
	int a,b,i;
	
	for(i=0;i<MAX;i++){
		scanf("%d %d",&H[i],&W[i]);
		if(H[i]==0||W[i]==0){
			break;
		}
	}
	
	for(i=0;i<MAX;i++){
		if(H[i]==0||W[i]==0){
			return 0;
		}
		for(a=0;a<H[i];a++){
			for(b=0;b<W[i];b++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    string c;
    cin >> c;

    vector<int> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
        s[i + 1] = s[i] + (c[i] == 'W');
    }

    int k = 1 << 30;
    for (int i = 0; i <= n; i++) {
        int r = s[i];
        int w = (n - i) - (s[n] - s[i]);
        k = min(k, max(r, w));
    }

    cout << k << endl;

    return 0;
}

Measured memory_bytes: 4400
#include <iostream>
int main() {
	int a, b, c, d;
	int m = 0;
	std::cin >> a >> b >> c >> d;
	if (a >= b) {
		m = b;
	}
	else {
		m = a;
	}
	if (c >= d) {
		m = m + d;
	}
	else {
		m = m + c;
	}
	std::cout << m;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		double a=s.nextDouble();
		double b=s.nextDouble();
		
		double h=s.nextDouble();
		double m=s.nextDouble();
		
		double cosh=Math.cos(Math.toRadians(angleh(h,m)));
		double sinh=Math.sin(Math.toRadians(angleh(h,m)));
		
		double cosm=Math.cos(Math.toRadians(anglem(m)));
		double sinm=Math.sin(Math.toRadians(anglem(m)));
		
		double dist=Math.pow((a*cosh)-(b*cosm),2)+Math.pow((a*sinh)-(b*sinm), 2);
		dist=Math.sqrt(dist);
		
		System.out.println(dist);
		
	}
	
	public static double angleh(double h,double m)
	{
		double degree=0;
		
		degree=degree+(360d/12d)*h;
		degree=degree+((360d/(12*60))*m);
		
		return degree;
	}
	
	public static double anglem(double m)
	{
		double degree=0;
		
		degree=degree+((360d/60d)*m);
		
		return degree;
	}
	
}

Measured memory_bytes: 37508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int x,y;cin>>x>>y;
    for(int i=0;i<=x;i++){
        if(2*i+4*(x-i)==y){co("Yes");return 0;}
    }
    co("No");return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <stack>

using namespace std;

int main()
{
  int buf;
  stack<int> st;
  while(cin >> buf)
  if(buf==0)
  {
    cout << st.top() << endl;
    st.pop();
  }
  else
    st.push(buf);
  return 0;
}

Measured memory_bytes: 1196
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int m, a, b, p[200];

int main(){
  while (cin >> m >> a >> b, m){
    rep(i, m) cin >> p[i];
    sort(p, p + m, greater<int>());
    int mx = 0, res = 0;
    rep(i, a, b + 1){
      chmax(mx, p[i - 1] - p[i]);
      if (mx == p[i - 1] - p[i]){
        res = i;
      }
    }
    cout << res << endl;
  }
}

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

using namespace std;

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

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

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

    int sum = 0;
    for (int i = 0; i < N; i++) {
        int p = V[i] - C[i];
        if (p > 0) {
            sum += p;
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    d=INT()
    print('Christmas'+' Eve'*(25-d))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
ll modpow(ll a, ll n, ll mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(void){
  initialize();
  ll n,k,i,j,result=0,x;
  ll dp[LIMIT2]={0};

  scanf("%lld %lld",&n,&k);
  for(x=k;x>=1;x--){
    dp[x]=modpow((ll)floor(k/x),n,MOD1);
    for(i=2*x;i<=k;i+=x){
      dp[x]-=dp[i];
      if(dp[x]<0) dp[x]+=MOD1;
    }
    //printf("%lld\n",dp[x]);
    result+=dp[x]*x;
    result%=MOD1;
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n,m; cin >> n >> m;
    int a[m],b[m];
    int ans = 0;
    rep(i,m) cin >> a[i] >> b[i];
    
    for(int i = 0; i < m; i++){
        vector<int> G[n];
        bool visit[n];
        rep(i,n) visit[i] = false;
        for(int j = 0; j < m; j++){
            if(i == j) continue;
            else{
                G[a[j]-1].push_back(b[j]-1);
                G[b[j]-1].push_back(a[j]-1);
            }
        }
        queue<int> que;
        que.push(0);
        while(!que.empty()){
            int now = que.front(); que.pop();
            visit[now] = true;
            for(auto next : G[now]){
                if(!visit[next]) que.push(next);
            }
        }
        rep(i,n){
            if(!visit[i]){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

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


int main(void)
{
  std::string s,t,u;
int countS,countT;
std::cin >> s >> t >> countS >> countT >> u;

if(u == s)
{
  countS--;
}
else
{
  countT--;
}
  std::cout << countS << " " << countT << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define NN 100010

int main(void)
{
  int i, k, id, N, K;
  scanf("%d",&N);
  int X[NN];
  int c, benefit, sum=0;
  for(i=0;i<N;i++)  scanf("%d",&X[i]);
  for(i=0;i<N;i++){
    scanf("%d",&c);
    benefit = X[i] - c;
    if(benefit > 0) sum+= benefit;      
  }
  printf("%d", sum); 
  return (0);
}


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

int main(){
  int N,fn,n;
  cin >> N;
  n = N;
  while(N > 0){
    fn += N % 10;
    N /= 10;
  }
  if(n % fn == 0)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int result=0;
    int r,g,b;

    cin>>r>>g>>b;


    result=result*10 + r;

    result=result*10 + g;

    result=result*10 + b;


    if(result%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    string S; cin >> S;
    if(S <= "2019/04/30") cout << "Heisei" << endl;
    else cout << "TBD" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
// clang-format on
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  //  std::random_device rd;std::mt19937 ran(rd());

  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    int tmp = 0;
    for (int j = 0; j < m; ++j) {
      cin >> a;
      tmp += a * b[j];
    }
    ans += tmp + c > 0;
  }

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


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

const int MAX_N = 101;
const int MAX_V = 1e+3 + 1;
const int INF = 1 << 30;

ll v[MAX_N], w[MAX_N], dp[MAX_N][MAX_V * MAX_N + 1];

int main() {
    int N;
    ll W;
    cin >> N >> W;
    for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
    for (int i = 0; i <= N; i++) {
        for (ll j = 0; j <= MAX_V * MAX_N; j++) dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (ll j = 0; j <= MAX_V * MAX_N; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i] >= 0 && dp[i - 1][j - v[i]] < INF) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }
    for (ll j = MAX_V * MAX_N; j >= 0; j--) {
        if (dp[N][j] <= W) {
            cout << j << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 80000
#include<iostream>
#include<string>

typedef long long ll;
#define f first
#define s second
#define pb push_back

using namespace std;

int main(void){
    string s,t;
    cin >>s;
    cin >>t;
    int count = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]){
            count++;
        }
    }
    cout << count<<"\n";
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    int n;
    cin >> n;
    int a[n+2];
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    int left[n+2]={0}, right[n+2]={0};
    int gc = 0;
    for(int i=1; i<=n; i++){
        gc = __gcd(a[i], gc);
        left[i] = gc;
    }
    gc = 0;
    for(int i=n; i>0; i--){
        gc = __gcd(gc, a[i]);
        right[i] = gc;
    }
    int mx = 0;
    for(int i=1; i<=n; i++){
        mx = max(mx, __gcd(left[i-1], right[i+1]));
    }
    cout << mx << '\n';

    return 0;
}


Measured memory_bytes: 4780
D, G = map(int, input().split())
PC = [0] + [list(map(int, input().split())) for _ in range(D)]
def dfs(i, g):
  if i == 0:
    return 1e9
  mc = min(g // (i * 100), PC[i][0])
  s = 100 * i * mc
  if mc == PC[i][0]:
    s += PC[i][1]
  if s < g:
    mc += dfs(i - 1, g - s)
  return min(mc, dfs(i - 1, g))
print(dfs(D, G))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


// 二部マッチング：構造体--------------------------------------
// 二部グラフ。容量が全て1である最大流問題に帰着できる。
// がここではsupersourceとsupersinkを追加する必要はない
// verifyはここ <http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp>

struct Bipartite_Matching {
  int V;                 // 頂点数
  vector<vector<int>> G; // グラフの隣接リスト表現
  vector<int> match;     // マッチングのペア
  vector<bool> used;     // DFSで既に調べたかのフラグ

  Bipartite_Matching(int n) : V(n), G(n), match(n, -1), used(n, false) {}

  // uとvを結ぶ辺をグラフに追加する
  void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  // 増加パスをDFSで探す
  bool dfs(int v){
    used[v] = true;
    for (int i=0; i<G[v].size(); i++){
      int u = G[v][i], w = match[u];
      if (w < 0 || !used[w] && dfs(w)){
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }

  // 二部グラフの最大マッチングを求める
  int bipartite_matching() {
    int res = 0;
    match.assign(match.size(), -1);
    for (int v=0; v<V; v++){
      if (match[v] < 0){
        used.assign(used.size(), false);
        if (dfs(v)) res++;
      }
    }
    return res;
  }
};

void solve(int M, int N){
  Bipartite_Matching bm(M+N);
  vector<int> b(M); rep(i, M) cin >>b[i];
  rep(j, N){
    int red = M+j;
    int r; cin >>r;
    rep(i, M){
      int blue = i;
      if (gcd(b[i], r) > 1) bm.add_edge(blue, red);
    }
  }
  int res = bm.bipartite_matching();
  cout <<res <<endl;
}

int main() {
  int M,N; cin >>M >>N;
  while (M > 0 && N > 0){
    solve(M, N);
    cin >>M >>N;
  }
}



Measured memory_bytes: 4440
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s[2];
    cin >> s[0] >> s[1];
    vector<int> a;
    rep(i, 0, s[0].size()){
        if(s[0][i] == s[1][i]){
            a.push_back(1);
        }else{
            a.push_back(2);
            i++;
        }
    }
    // for(int ii = 0; ii < a.size(); ii++){
    //     if(ii) cout << ' ';
    //     cout << a[ii];
    // }
    // cout << endl;
    int ans = 0;
    if(a[0] == 1) ans = 3;
    else ans = 6;
    rep(i, 1, a.size()){
        if(a[i - 1] == 2){
            if(a[i] == 2) (ans *= 3) %= mod;
        }else{
            (ans *= 2) %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int d[7][7]={
  {0,300,500,600,700,1350,1650},
  {6,0,350,450,600,1150,1500},
  {13,7,0,250,400,1000,1350},
  {18,12,5,0,250,850,1300},
  {23,17,10,5,0,600,1150},
  {43,37,30,25,20,0,500},
  {58,52,45,40,35,15,0}
};
int main(){
  int a,b,h1,h2,m1,m2;
  while(cin>>a&&a){
    cin>>h1>>m1>>b>>h2>>m2;
    m1+=h1*100,m2+=h2*100;
    a--,b--;
    if(a>b)swap(a,b);
    int tmp=d[a][b];
    if(d[b][a]<=40&&((1730<=m1&&m1<=1930)||(1730<=m2&&m2<=1930)))tmp/=2;
    if(tmp%50>0)tmp+=50-tmp%50;
    cout<<tmp<<endl;
  }
  return 0;
}

Measured memory_bytes: 3080
import numpy as np
N,M=map(int,input().split())
A=[]
 
for i in range(N):
    A+=[[i for i in map(int,input().split())]]
A=np.array(A)
A=A[A[:,0].argsort(),:]

count=0
price=0
for i in range(N):
    if A[i,1]>=M-count:
        price+=A[i,0]*(M-count)
        break
    else:
        price+=A[i,0]*A[i,1]
        count+=A[i,1]

print(price)

Measured memory_bytes: 31696
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

map<vector<int>,int> mp;

int main(){
    vector<int> ans(8);
    rep(i,8)ans[i]=i;

    queue<vector<int>> que;
    que.push(ans);
    mp[ans] = 0;
    
    while(que.size()){
        vector<int> q = que.front();
        que.pop();
        int x,y;
        rep(i,8)if(q[i]==0){
            y = i/4;
            x = i%4;
        }
        int dy[]={1,0,-1,0};
        int dx[]={0,1,0,-1};
        
        rep(i,4){
            int ddy = y + dy[i];
            int ddx = x + dx[i];
            if(ddy<0||ddx<0||ddy>=2||ddx>=4)continue;
            vector<int> t = q;
            swap(t[4*ddy + ddx],t[4*y + x]);
            
            if(mp.count(t)!=0)continue;
            que.push(t);
            mp[t]=mp[q]+1;
        }
    }
    
    vector<int> v(8);
    while(cin>>v[0]){
        rep(i,7)cin>>v[i+1];

        cout<<mp[v]<<endl;
    }
}

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

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

  if (a >= b) {
    cout << "delicious" << endl;
  } else {
    if (b - a <= x) {
      cout << "safe" << endl;
    } else {
      cout << "dangerous" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll M,K;
	scan(M>>K);
	if(M==0&&K==0){
		prin("0 0");
	}
	else if(M==1&&K==0){
		prin("0 0 1 1");
	}
	else if(M>=2&&K<(1<<M)){
		if(K==0){
			rep(i,(1<<M)) printf("%d %d ",i,i);
			kaigyo;
		}
		else{
			bool alre[200000]={};
			int ini;
			if(K==1) ini=2;
			else ini=1;
			int num=(1<<M);
			rep(i,num){
				if(alre[i]==0){
					int j1=i+ini;
					int j2=(j1^K);
					int ip=(i^K);
					printf("%d %d %d %d %d %d %d %d ",j1,ip,i,j1,j2,i,ip,j2);
					alre[i]=1,alre[ip]=1,alre[j1]=1,alre[j2]=1;
				}
			}
			kaigyo;
		}
	}
	else{
		prin("-1");
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	int32_t cnt = 0;
	char prev = ' ';
	for (size_t i = 0; i < S.size(); i++) {
		if (S[i] == prev)
			continue;
		cnt++;
		prev = S[i];
	}

	cout << cnt - 1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

int main() {
    int a[5];
    for (int i = 0; i < 5; ++i) {
        scanf ("%d", &a[i]);
    }

    int k;
    scanf ("%d", &k);

    for (int i = 0; i < 5; ++i) {
        for (int j = i + 1; j < 5; ++j) {
            if (a[j] - a[i] > k) {
                printf(":(\n");
                return 0;
            }
        }
    }
    printf ("Yay!\n");
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a=0;
    for(int i=0;i<n;i++){
        if(s[i]=='.')a++;
    }
    int min=a;
    for(int i=0;i<n;i++){
        if(s[i]=='.')a--;
        if(s[i]=='#')a++;
        if(a<min)min=a;
    }
    cout << min << endl;
}

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

int main(){
    int N;
    cin >> N;
    long long mod = 1000000007;
    int A = 0; int G = 1; int C = 2; int T = 3;
    long long dp[N+1][4][4][4];

    rep2(n, 3, N+1){
        rep(i, 4){
            rep(j, 4){
                rep(k, 4){
                    dp[n][i][j][k] = 0;
                }
            }
        }
    }

    rep(i, 4){
        rep(j, 4){
            rep(k, 4){
                if(i == A && j == G && k == C) continue;
                else if(i == G && j == A && k == C) continue;
                else if(i == A & j == C & k == G) continue;
                else{
                    dp[3][i][j][k] = 1;
                }
            }
        }
    }

    rep2(n, 3, N){
        rep(i, 4){
            rep(j, 4){
                rep(k, 4){
                    rep(l, 4){
                        if(j == A && k == G && l == C) continue;
                        else if(j == G && k == A && l == C) continue;
                        else if(j == A && k == C && l == G) continue;
                        else if(i == A && k == G && l == C) continue;
                        else if(i == A && j == G && l == C) continue;
                        else{
                            dp[n+1][j][k][l] += dp[n][i][j][k];
                            dp[n+1][j][k][l] %= mod;
                        }
                    }
                }
            }
        }
    }

    long long ans = 0;

    rep(i, 4){
        rep(j, 4){
            rep(k, 4){
                ans += dp[N][i][j][k];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
  
int main()
{
  int64 N, H, d[100000], h[100000];
  int64 now[100000];
  
  scanf("%lld %lld", &N, &H);
  for(int i = 0; i < N - 1; i++) {
    scanf("%lld %lld", &d[i], &h[i]);
  }
  
  int64 power = H, ret = 0LL;
  for(int i = 0; i < N - 1; i++) {
    now[i] = power;
    power -= d[i];
    while(power <= 0) {
      int MaxPos = i;
      int64 hoge = H;
      for(int j = i; j >= 0; j--) {
        hoge = min(hoge, H - now[j]);
        h[j] = min(h[j], hoge);
        if(h[MaxPos] < h[j]) MaxPos = j;
        if(hoge == 0) break;
      }
      int64 hori = min(-power / h[MaxPos] + 1, (H - now[MaxPos]) / h[MaxPos]);
      ret += hori;
      power += hori * h[MaxPos];
      for(int j = MaxPos; j <= i; j++) {
        now[j] += hori * h[MaxPos];
        now[j] = min(now[j], H);
      }
    }
  }
  printf("%lld\n", ret);
}

Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  cout << a.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n;
    vector<int>hist1(100001);
    vector<int>hist2(100001);
    for(int i=1;i<=n;i++){
        int v;
        cin >> v;
        if(i%2==1) hist1[v]++;
        if(i%2==0) hist2[v]++;
    }
    //vector<int>hist1(100001);
    vector<int>hist2_copy(hist2);
    auto hist1_max=max_element(hist1.begin(),hist1.end());
    auto hist2_max=max_element(hist2.begin(),hist2.end());
    auto hist2_copy_max=max_element(hist2_copy.begin(),hist2_copy.end());
    if(hist1_max-hist1.begin()!=hist2_max-hist2.begin()){
        cout<<(n/2-*hist1_max)+(n/2-*hist2_max);
    }else{
        hist2.erase(hist2_max);
        auto hist2_second=max_element(hist2.begin(),hist2.end());
        int x=(n/2-*hist1_max)+(n/2-*hist2_second);

        hist1.erase(hist1_max);
        auto hist1_second=max_element(hist1.begin(),hist1.end());
        int y=(n/2-*hist2_copy_max)+(n/2-*hist1_second);

        cout <<min(x,y);
    }
}

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

int main()
{
	long long n; cin >> n;
	long long ans = 0;
	if (n >= 500)
	{
		ans += (n / 500)*1000;
		n -= ((n / 500) * 500);
	}
	ans += (n / 5) * 5;
	cout << ans;


}

Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n], b = new int[n], c = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        int[][] x = new int[3][n];
        x[0][0] = a[0];
        x[1][0] = b[0];
        x[2][0] = c[0];
        for(int i = 1; i < n; i++){
            x[0][i] = Math.max(x[1][i-1], x[2][i-1]) + a[i];
            x[1][i] = Math.max(x[2][i-1], x[0][i-1]) + b[i];
            x[2][i] = Math.max(x[0][i-1], x[1][i-1]) + c[i];
        }
        System.out.println(Math.max(x[0][n-1], Math.max(x[1][n-1], x[2][n-1])));
    }
}

Measured memory_bytes: 96072
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main(){cout<<fixed<<setprecision(20);
		  //Sr-Slがmの倍数　→ Sr=Sl(mod m)
          // Si = k (0<=k<=m-1)となる iの個数を記録して
           // Σi C 2 =Σi(i-1)/2
           ll n,m;
           cin>>n>>m;
           vll a(n);
           vll sum(n,0);
           
           map<ll ,ll> cnt;
           cnt[0]++;
           
           rep(i,0,n){
            cin>>a[i];
             
            sum[i]+=a[i];
            if(i-1>=0)sum[i]+=sum[i-1];
             
            sum[i]%=m;
            
             cnt[sum[i]]++;
           }
           
           ll ans=0;
           for(auto v:cnt){
             ans+=v.second*(v.second-1)/2;
           }
           cout<<ans<<endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

struct UnionFind{
  /*データメンバ*/
  vector<int> par; //par[i]:iの親の番号。
  /*コンストラクタ。独自の初期化処理などを行いたいときにコンストラクタを使う。引数の数を変えることで複数のコンストラクタを定義可能。*/
  UnionFind(int N) : par(N) {/*:の後ろに記述されたデータメンバの初期化を行う。*/
    rep(i,N)par[i]=i;
  }

  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){//unite trees
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
/*https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396*/

int main(){
  ll N,M; cin>>N>>M;
  vector<int> P(N);
  rep(i,N)cin>>P.at(i);
  UnionFind tree(N+1);
  rep(i,M){
    int x,y; cin>>x>>y;
;
    tree.unite(x,y);
  }
  int res = 0;
  rep(i,N){
    if(P.at(i)==i+1)res++;
    else{
      if(tree.same(P.at(i),i+1))res++;
    }
  }
  cout<<res<<endl;
  return 0;
}

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

int main() {
  int n,k,ans;
  ans = 0;
  cin >> n  >> k;
  vector<int> a(n);
  for(int i=0;i<k;i++){
    int d;
    cin >> d;
    vector<int> vec(d);
    for(int j=0;j<d;j++){
      int p;
      cin >> p;
      a.at(p-1) = 1;
    }
  }
  for(int i=0;i<n;i++){
    if(a.at(i) == 0)
      ans++;
  }
  cout << ans;
}
    

Measured memory_bytes: 3600
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e6+5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;

int n;
vector<int> adj[N];
int val[N], L[N], R[N];
void kill(){cout << "No\n"; exit(0);}
void pdfs(int node, int par){

  for(auto v : adj[node])if(v!=par){
    pdfs(v, node);
    L[node] = max(L[node], L[v] - 1);
    R[node] = min(R[node], R[v] + 1);
  }

  if(L[node] > R[node])
    kill();

}
void dfs(int node, int par){

  for(auto v : adj[node])if(v != par){

    if(~val[v]){
      if(abs(val[v]-val[node])!=1)kill();
      dfs(v,node);
    } else {
      if(L[v]<=val[node]-1&&val[node]-1<=R[v]){
        val[v]=val[node]-1;
      } else if(L[v]<=val[node]+1&&val[node]+1<=R[v]){
        val[v]=val[node]+1;
      } else kill();
      dfs(v,node);
    }
  }

}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n;
  memset(val,-1,sizeof val);
  fill(L,L+n+1,-1e9);
  fill(R,R+n+1,1e9);

  f(i,1,n){
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  int mx = -1;
  int k;
  cin >> k;
  int r;
  f(i,0,k){
    int x, y;
    cin >> x >> y;
    val[x] = L[x] = R[x] = y;
    if(y > mx){
      mx = y;
      r = x;
    }
  }

  pdfs(r,r);
  dfs(r,r);

  cout << "Yes\n";
  f(i,1,n+1)cout << val[i] << '\n';


  return 0;
}


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

int dp[100001][3];
vector <int> a,b,c;
int n,x,y,z;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> x >> y >> z;
		a.push_back(x);
		b.push_back(y);
		c.push_back(z);
	}

	memset(dp,0,sizeof(dp));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for(int i=1;i<n;i++)
	{
		dp[i][0] = max(dp[i][0],max(dp[i-1][1],dp[i-1][2]) + a[i]);
		dp[i][1] = max(dp[i][1],max(dp[i-1][0],dp[i-1][2]) + b[i]);
		dp[i][2] = max(dp[i][2],max(dp[i-1][0],dp[i-1][1]) + c[i]);
	}

	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << '\n';

	return 0;
}


Measured memory_bytes: 2924
#include <vector>
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define MOD 1000000007

int main() {

	int n; cin >> n;
	vector<vector<int>> a(n, vector<int>(n, 0));
	for (int i = 0; i <= n - 1; i++) for (int j = 0; j <= n - 1; j++) cin >> a[i][j];

	vector<vector<long long>> dp(n, vector<long long>((1 << n), 0));
	long long ans = 0;

	for (int m = 1; m <= (1 << n) - 1; m++) {
		int cnt = __builtin_popcount(m);

		for (int j = 0; j <= n - 1; j++) {

			if (a[cnt - 1][j] == 1 and (m & (1 << j)) != 0) {

				if (cnt == 1) dp[cnt - 1][m] = 1;

				else {
					dp[cnt - 1][m] += dp[cnt - 2][m - (1 << j)];
					if (dp[cnt - 1][m] >= MOD) dp[cnt - 1][m] %= MOD;
				}

			}
		}

		if (cnt == n) {
			ans += dp[cnt - 1][m];
			if (ans >= MOD) ans %= MOD;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 363796