akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

int main(){
	int n;
	int c[500], s[500], f[500];
	scanf("%d", &n);
	for(int i = 0; i < n-1; i++){
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	}
	for (int i = 0; i < n; i++){
		int sum = 0;
		for(int j = i; j < n-1; j++){
			if(sum < s[j])
				sum = s[j];
			if(sum % f[j] != 0){
				sum += f[j] - (sum%f[j]);
			}
			sum += c[j];
		}
		printf("%d\n", sum);
	}
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	double ans;
	if (N%2==0){
		ans = 0.5;
	}
	if (N%2==1){
		ans = (N+1.0)/(2.0*N);
	}
	
	cout << ans <<endl;
}



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

double dp[31][31 * 10000];

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

	int n, m, e;
	while(cin >> n >> m >> e, n | m | e) {
		assert(n <= 30 && n * m <= 30 * 10000);
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n * m; j++) {
				dp[i][j] = 0;
			}
		}

		dp[0][0] = 1.0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= m * i; j++) {
				dp[i + 1][j + 1] += dp[i][j] / m;
				dp[i + 1][j + m + 1] -= dp[i][j] / m;
			}
			double s = 0;
			for(int j = 0; j <= m * (i + 1); j++) {
				s += dp[i + 1][j];
				dp[i + 1][j] = s;
			}
		}

		double ans = 0;
		for(int j = n; j <= m * n; j++) {
			int b = j - e;
			if(b <= 1) ans += dp[n][j];
			else ans += b *  dp[n][j];
		}

		cout << setprecision(15) << ans << endl;
	}
}

Measured memory_bytes: 3492
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}
map<ll,ll> prime_factor(ll n){ //素因数分解
	map<ll,ll> ret;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			ret[i]++;
			n /=i;
		}
	}
	if(n!=1) ret[n] =1;
	return ret;
} 

int main(){
	ll a,b,d;
  	cin >> a >> b;
  	d=__gcd(a,b);
  	map<ll,ll> m = prime_factor(d);
  	ll ans=1;
  	for(auto &e: m){
    	if(e.S!=0){
        	ans++;
        }
    }
  	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

const int INF = 1e9+7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){

  int n;
  std::cin >> n;

  int maxp, minp;
  std::vector<int> R;

  for(int i = 0; i < n; i++){
    int tmp;
    std::cin >> tmp;
    R.push_back(tmp);
  }

  maxp = R[1] - R[0];
  minp = R[0];

  for(int i = 1; i < n; i++){
    maxp = std::max(maxp, R[i] - minp);
    minp = std::min(minp, R[i]);
  }

  std::cout << maxp << std::endl;

  return 0;
}

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

vector<vector<int>> way;
int64_t N, M;
vector<int> color;

bool dfs(int x, int col) {
  color.at(x) = col;
  for(int i = 0; i < way.at(x).size(); i++) {
    if(color.at(way.at(x).at(i)) == col) {
      return false;
    }
    if(color.at(way.at(x).at(i)) == -1) {
      if(!dfs(way.at(x).at(i), 1 - col)) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  way.assign(N, {});
  color.assign(N, -1);
  for(int64_t i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(a - 1).push_back(b - 1);
    way.at(b - 1).push_back(a - 1);
  }
  if(!dfs(0, 0)) {
    cout << N * (N - 1) / 2 - M << endl;
  }
  else {
    int64_t total = 0;
    for(int i = 0; i < N; i++) {
      if(color.at(i) == 0) {
        total++;
      }
    }
    cout << total * (N - total) - M << endl;
  }
}

Measured memory_bytes: 9488
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")

using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;

const int INF = 0x3f3f3f3f;

char in[300050];
int sum[300050];
int main() {
	int N, i;
	scanf("%d", &N);
	scanf("%s", in + 1);
	for (i = 1; i <= N; i++) {
		sum[i] = sum[i - 1];
		if (in[i] == 'E') sum[i]++;
	}
	int ans = INF;
	for (i = 1; i <= N; i++) {
		int c = (i - 1 - sum[i - 1]) + (sum[N] - sum[i]);
		ans = min(ans, c);
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 1664
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.append(23)
c.append(0)
count = 0

for i in range(n):
    count += b[a[i]-1]
    #print("added"+str(b[a[i]-1]))
    if ((a[i]+1)==a[i+1]):
        #print("yeah"+str(c[a[i]-1]))
        count += c[a[i]-1]
print(count)



Measured memory_bytes: 3064
#include<iostream>
#include<math.h>

using namespace std;

int pitagoras(int a,int b,int c){
	if(pow(a,2)+pow(b,2) == pow(c,2))
		return 1;
	if(pow(b,2)+pow(c,2) == pow(a,2))
		return 1;
	if(pow(c,2)+pow(a,2) == pow(b,2))
		return 1;
	return 0;
}
int main(){
	int num,i;
	int a[1000],b[1000],c[1000];
	cin >> num;
	for(i = 0; i < num; i++)
		cin >> a[i] >> b[i] >> c[i];
		for(i = 0; i < num; i++){
			if(pitagoras(a[i],b[i],c[i])==1)
				cout << "YES" << endl;
			if(pitagoras(a[i],b[i],c[i])==0)
				cout << "NO"  << endl;
		}
}
	

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    string s;
    cin >> s;
    int res = 0, now = 0;
    rep(i, n){
      if(s[i] == 'I')++now;
      else --now;
      res = max(res, now);
    }
    pri(res);

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  abc106
//
//  Created by 张伟 on 2018/8/18.
//  Copyright © 2018年 张恺. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b;
    cin>>a>>b;
    printf("%d",(a-1)*(b-1));
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

void step(string& s) {
  string t(s.size()-1, '0');
  REP(i, s.size()-1) {
    t[i] += abs(s[i]-s[i+1]);
  }
  swap(s, t);
}

// 1-stepすすめると0, 1, 2だけになる
//

int comb_parity(int64 a, int64 b) {
  int64 ret = 1;
  while (a) {
    if (a%2 == 0 && b%2) ret = 0;
    a /= 2;
    b /= 2;
  }
  return ret;
}

bool is_palindrome(const string& s) {
  REP(i, s.size()/2) {
    if (s[i] != s[s.size()-i-1]) return 0;
  }
  return 1;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long double L;
  cin >> L;
  cout << fixed << setprecision(10) << pow(L/3, 3) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=2e6+1e5,MAX=3e7,MOD=1e9+7;
 
using namespace std;
 
int n;
int a[30][30];

ll memo[25][N];
ll solve(int indx,int mask){

	 if(indx == n)return 1;

	 ll &ret = memo[indx][mask];

	 if(ret !=-1 ) return ret;

	 ret = 0;

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

	 	 if(a[indx][j] && !(mask & (1<<j) )){
                ret = (ret + solve(indx+1,(mask|(1<<j))))%MOD;
	 	 }
	 }

	 return ret;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //#ifndef ONLINE_JUDGE
      //freopen("test.txt","r",stdin);
     //#endif


      scanf("%d",&n);

      for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&a[i][j]);
      
      memset(memo,-1,sizeof(memo));

      printf("%lld\n",solve(0,0) ); 
     
}

Measured memory_bytes: 410368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	int w;
	int h;

	// 白い範囲(x,y)の最大最小値
	int maxX;
	int minX;
	int maxY;
	int minY;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs = br.readLine().split(" ");
		int w = Integer.parseInt(inputs[0]);
		int h = Integer.parseInt(inputs[1]);
		int fillNum = Integer.parseInt(inputs[2]);

		// 塗りつぶし後の白い範囲の最大最小値を得る
		int maxX = w;
		int minX = 0;
		int maxY = h;
		int minY = 0;

		for (int i = 0; i < fillNum; i++) {
			inputs = br.readLine().split(" ");
			int dotX = Integer.parseInt(inputs[0]);
			int dotY = Integer.parseInt(inputs[1]);
			int action = Integer.parseInt(inputs[2]);

			switch (action) {
			case 1:
				if (minX < dotX) {
					minX = dotX;
				}
				break;
			case 2:
				if (maxX > dotX) {
					maxX = dotX;
				}
				break;
			case 3:
				if (minY < dotY) {
					minY = dotY;
				}
				break;
			case 4:
				if (maxY > dotY) {
					maxY = dotY;
				}
				break;
			}
		}
		int resultX = maxX - minX;
		int resultY = maxY - minY;
		int area;
		if (resultX <= 0 || resultY <= 0) {
			area = 0;
		} else {
			area = resultX * resultY;
		}
		System.out.println(area);

	}

}


Measured memory_bytes: 8272
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		int [] L = new int[N];
    		for (int i=0; i<N; i++) {
    			L[i] = sc.nextInt();
    		}

    		Arrays.sort(L);

    		int count = 0;
    		for (int i=0; i<N-2; i++) {
    			for (int j=i+1; j<N-1; j++) {
    				for (int k=j+1; k<N; k++) {
    					if (L[i] < L[j] + L[k] &&
    						L[j] < L[k] + L[i] &&
    						L[k] < L[i] + L[j]) {
    						count++;
    					} else {
    						break;
    					}
    				}
    			}
    		}

    		System.out.println(count);

    	} finally {
    		sc.close();
    	}
    }
}



Measured memory_bytes: 26056
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long d = Integer.parseInt(sc.next());

		int result = 0;
		for (int i = 0; i < n; i++) {

			long x = Integer.parseInt(sc.next());
			long y = Integer.parseInt(sc.next());

			if ((x * x) + (y * y) <= (d * d)) {
				result++;
			}

		}

		System.out.println(result);

	}
}

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int L[10];

void solve(){
	sort(L, L + N);
	int s = 0;
	rep(i, N - 1){
		s += L[i];
	}
	cout << (L[N - 1] < s ? "Yes" : "No") << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> L[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	string a;
	cin>>a;
	if(n&1) cout<<"No"<<'\n';
	else
	{
		int len=n/2;
		bool f=true;
		for(int i=0;i<len;i++) 
		{
			if(a[i]!=a[i+len]) f=false;
		}
		if(f) cout<<"Yes"<<'\n';
		else cout<<"No"<<'\n';
	}
    return 0;
}



Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, k = Is()
if n % k == 0:
    print(0)
else:
    print(1)

Measured memory_bytes: 63852
#include<bits/stdc++.h>
using namespace std;
int n,f[100005],g[100005],ans;
string s;
map<char,int> m;
void initmap(){
	m['p']=1;
	m['g']=0;
	m['P']=1;
	m['G']=0;
}
int pk(int x,int y){
	return x-y;
}
int main(){
	initmap();
	cin>>s;
	n=s.length();
	for(int i=1;i<=n;i++){
		g[i]=m[s[i-1]];
	}
	ans+=pk(0,g[1]);
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(cnt>0){
			if(pk(1,g[i])==1){cnt--;ans++;continue;}
			if(pk(0,g[i])==1){cnt++;ans++;continue;}
			if(pk(0,g[i])==0){cnt++;continue;}
			if(pk(1,g[i])==0){cnt--;continue;}
		}
		else{
			ans+=pk(0,g[i]);
			cnt++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main() {
  // 頂点数と辺数
  int H,W; cin >> H >> W;
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  vv<char> field(H,v<char>(W));
  int cnt=0;
  // グラフ入力受取 (ここでは無向グラフを想定)
  rep(i,H)rep(j,W){
    cin >> field[i][j];
    if(field[i][j]=='#') cnt++;
  }

  // BFS のためのデータ構造
  vv<int> dist(H, v<int>(W,-1)); // 全頂点を「未訪問」に初期化
  queue<P> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0][0] = 1;
  que.push(P(0,0)); // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    P v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    rep(i,4){
      int x=v.first+dx[i];
      int y=v.second+dy[i];
      if(x<0 || x>=H || y<0 || y>=W) continue;
      if(field[x][y]=='#') continue;
      if(dist[x][y]!=-1) continue;
      dist[x][y]=dist[v.first][v.second]+1;
      que.push(P(x,y));
    }
  }
  //cout << dist[H-1][W-1] << endl;
  if(dist[H-1][W-1]==-1) cout << -1 << endl;
  else cout << H*W-cnt-dist[H-1][W-1] << endl;
}


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

int main() {
  int n, i;
  cin >> n;
  
  vector<int> h(n);
  for(i = 0; i < n; i++) cin >> h.at(i);
  
  int a[n];
  
  a[0] = 0;
  a[1] = abs(h.at(0) - h.at(1));
  
  for(i = 2; i < n; i++){
    a[i] = min(a[i - 2] + abs(h.at(i) - h.at(i - 2)), a[i - 1] + abs(h.at(i) - h.at(i - 1)));
  }
  
  cout << a[n - 1] << endl;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

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

typedef long long ll;

class TaskA {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;
		vector<int> h(n);
		for (int i = 0; i < n; i++) in >> h[i];
		vector<ll> dp(n, 1e18);
		dp[0] = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 1; j <= min(2, i); j++) {
				dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
			}
		}
		out << dp[n - 1];
	}
};


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4448
#include <iostream>
#include <cmath>

using namespace std;

int H[101010];
int dp[101010];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  dp[0] = 0;
  dp[1] = abs(H[1] - H[0]);
  for (int i = 2; i < N; ++i) {
    dp[i] = min(abs(H[i] - H[i - 1]) + dp[i - 1], abs(H[i] - H[i - 2]) + dp[i - 2]);
  }
  cout << dp[N - 1] << endl;
  return 0;
}

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

int main()
{
    int64_t N, M;
    cin >> N >> M;
    int64_t total, camari;
    camari = M - N * 2;
    if (camari <= 0)
    {
        total = M / 2;
        cout << total << endl;
    }
    else
    {
        int64_t camari4 = camari / 4;
        total = N + camari4;
        cout << total << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cmath>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=1e2+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int n,top,cnt1,cnt2;
char s[N],ans[N<<1],stack[N<<1];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void push(char c){stack[++top]=c;}
void pop(){if(top>=1) top--;}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	scanf("%s",s+1);
	rep(i,n){
		push(s[i]);
		if((stack[top]==')'&&stack[top-1]=='(')) pop(),pop();
	}
	rep(i,top) if(stack[i]=='(') cnt1++;else cnt2++;
	rep(i,cnt2) putchar('(');
	printf("%s",s+1);
	rep(i,cnt1) putchar(')');
	return 0;
}

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

int main() {
	string S;
	int D;
	cin >> S;
	if (S == "SUN") {
		D = 7;
	}
	else if (S == "MON") {
		D = 6;
	}
	else if (S == "TUE") {
		D = 5;
	}
	else if (S == "WED") {
		D = 4;
	}
	else if (S == "THU") {
		D = 3;
	}
	else if (S == "FRI") {
		D = 2;
	}
	else if (S == "SAT") {
		D = 1;
	}
	cout << D << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 1;
int n , m , dp[N][N] , mod = 1e9 + 7;
string s[N];
int calc(int i , int j){
    if(i < 0 || i >= n || j >= m || j < 0 )
        return 0;
    if(s[i][j] == '#')
        return 0;
    if(i == n - 1 && j == m - 1)
        return 1;
    int &ret = dp[i][j];
    if(ret != -1)return ret % mod;
    return ret = (1LL * calc(i + 1 , j ) + calc(i , j + 1)) % mod;
}
int main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
        cin >> s[i];
    memset(dp , -1 , sizeof dp);
    cout<<calc(0 , 0);
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    vector<int> p_sort(N);
    int count=0;
    int flag;
    for(int i=0; i < N; i++){
        cin >> p[i];
    }
    for(int i=0; i<N;i++){
        p_sort[i] = i+1;
    }
    for(int i=0; i<N;i++){
        if(p[i] != p_sort[i]) count++;
        if(count > 2) {
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout << "YES" <<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  // vector<P> p(n);
  // rep(i,n) cin >> p[i].first >> p[i].second;
  vector<int> ls(n), rs(n);
  rep(i,n) cin >> ls[i] >> rs[i];
  sort(ls.begin(), ls.end());
  sort(rs.begin(), rs.end());
  int ans = 0;
  if (n%2 == 1) {
    int l = ls[n/2];
    int r = rs[n/2];
    ans = r-l+1;
  } else {
    // rep(i,n) ls[i] *= 2, rs[i] *= 2;
    int l2 = ls[n/2-1]+ls[n/2];
    int r2 = rs[n/2-1]+rs[n/2];
    ans = r2-l2+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4760
import sys

def dump(x):
    print(x, file=sys.stderr)


N = int(input())
buf = 0
for i in range(N):
    a,b = input().split()
    if a == b :
        buf += 1
        if buf >=3:
            break
    else:
        buf = 0

if buf >= 3:
    print('Yes')
else:
    print('No')







Measured memory_bytes: 9172
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
string s;
long n;
long N10;
int used[10];
long ans,ansm=-1;
void f(int i,long a)
{
	if(i==s.size())
	{
		if(ansm<min(abs(n-a),N10-abs(n-a)))
			ansm=min(abs(n-a),N10-abs(n-a)),ans=a;
	}
	else
	{
		for(int j=0;j<10;j++)
		{
			if(used[j])continue;
			used[j]=1;
			f(i+1,a*10+j);
			used[j]=0;
		}
	}
}
main()
{
	cin>>s;
	n=stol(s);
	N10=1;
	for(int i=0;i<s.size();i++)N10*=10;
	f(0,0);
	cout<<setfill('0')<<setw(s.size())<<ans<<endl;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,T,A;
  cin>>N>>T>>A;
  vector<int> B(N);
  vector<double> a(N);
  double b=1000;
int count;
  for(int i=0;i<N;i++){
  cin>>B[i];
     a[i]=T-B[i]*0.006;
     b=min(b,abs(A-a[i]));
  if(b==abs(A-a[i])){
  count=i+1;
  }
  }
  
cout<<count<<endl;
  }



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
  cin>>s;
  long long int k=0;
 // cout<<(n%x==0)? (n/x)*t : ((n/x)+1)*t;
  for(int i=0;i<int(s.length());i++)
      { k+=s[i]-'0';}
    if(k % 9 ==0){
    cout<<"Yes";}
  else
    cout<<"No";
        return 0;}

Measured memory_bytes: 3732
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

ll a[200500];
const ll INF = 1e10;

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

  int n, k;
  cin >> n >> k;
  REP(i, n)cin >> a[i];

  //使わない
  int zero_place = lower_bound(a, a+n, 0)-a;

  //相対的にずらしていく, 0からの相対位置に応じて足す
  ll ans = INF;
  for(int i=0; i+k-1<n; i++){
    ll tmp = a[i+k-1]-a[i];
    //両方とも左
    if((a[i]<0) && (a[i+k-1]<0)) tmp += abs(a[i+k-1]);
    //両方とも右
    if((a[i]>0) && (a[i+k-1]>0)) tmp += a[i];
    //間
    if((a[i]<0) && (a[i+k-1]>0)) tmp += min(-a[i], a[i+k-1]);
    ans = min(ans, tmp);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
using namespace std;


int main() {
	int num = 1;
	int tmp;
	while (1) {
		cin >> tmp;
		if (tmp == 0)
			break;
		cout << "Case " << num << ": " << tmp << endl;
		num++;
	}
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mem(x,n) memset(x,n,sizeof(x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=(l).begin();it!=(l).end();it++)
#define pnl printf("\n")
#define len(x) (x).length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
const double EPS=1e-10;
//const double PI=acos(-1.0);
const int INF=1<<30;
const LL LLINF=1ll<<60;
const int MOD=1e9+7;
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};

/****************************************************************************************\
 __    __               __ /\/|   ___ _           _       /\/|__               __    __
 \ \  / /  _____ __ ____\ \/\/   / __| |__ _ _ __(_)___  |/\// /____ __ _____  \ \  / /
  \ \| |  |___\ V  V /___| |    | (__| / _` | '_ \ / -_)    | |___\ V  V /___|  | |/ /
   \_\ |  |___|\_/\_/|___| |     \___|_\__,_| .__/_\___|    | |___|\_/\_/|___|  | /_/
      \_\               /_/                 |_|              \_\               /_/
\****************************************************************************************/

bool cek(string a,string b){
	return a==b;
}

int main(){
	string s;
	cin>>s;
	
	if(	cek(s,"AKIHABARA")
		||cek(s,"AKIHABAR")||cek(s,"AKIHABRA")||cek(s,"AKIHBARA")||cek(s,"KIHABARA")
		||cek(s,"AKIHABR")||cek(s,"AKIHBAR")||cek(s,"KIHABAR")||cek(s,"AKIHBRA")||cek(s,"KIHABRA")||cek(s,"KIHBARA")
		||cek(s,"AKIHBR")||cek(s,"KIHABR")||cek(s,"KIHBRA")||cek(s,"KIHBAR")
		||cek(s,"KIHBR")){
			printf("YES\n");
		}
		else printf("NO\n");
}

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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
	int n;
	cin >> n;
	string a,b;
	cin >> a >> b;
	string ans = "";
	for(int i = 0; i < n; ++i) {
		ans.pb(a[i]);
		ans.pb(b[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll N, A, B;
ll h[100010];

bool check(ll m) {
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    ll rem = h[i] - m * B;
    if (rem <= 0) continue;
    cnt += (rem + (A-B) - 1) / (A-B);
  }
  return cnt <= m;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> A >> B;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  ll ng = 0, ok = 1LL << 30;
  while (ok - ng > 1) {
    ll m = (ng + ok) / 2;
    if (check(m)) ok = m;
    else ng = m;
  }
  cout << ok << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n,x,t;
  cin>>n>>x>>t;
  int m = n/x + (n%x != 0);
  print(m * t);

  return 0;
}

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

using ll=long long;

ll n,a[100005][3],mem[100005][3],ans=0;
bool b[3];

ll dp(ll i,int noo)
{
	if (i==n)
	return 0;
	
	if (mem[i][noo]!=-1)return mem[i][noo];
	
	ll path1=0,path2=0,path3=0;
	if (noo!=0)path1=a[i][0]+dp(i+1,0);
	if (noo!=1)path2=a[i][1]+dp(i+1,1);
	if (noo!=2)path3=a[i][2]+dp(i+1,2);
	
	return mem[i][noo]=max({path1,path2,path3});
}




int main()
{
	memset(b,1,sizeof b);
    memset(mem,-1,sizeof mem);
    scanf("%lld",&n);
    for (ll i=0;i<n;i++)
    {
    	scanf("%lld%lld%lld",&a[i][0],&a[i][1],&a[i][2]);
    }
    printf("%lld",max({dp(0,0),dp(0,1),dp(0,2)}));
}


Measured memory_bytes: 11136
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		String s[]=new String [N];
		for(int i=0;i<N;i++) {
			s[i]=sc.next();
		}
		int M=sc.nextInt();
		String t[]=new String [M];
		for(int i=0;i<M;i++) {
			t[i]=sc.next();
		}
		int b=0;
		for(int i=0;i<N;i++) {
			int a=0;
			for(int k=0;k<N;k++) {
				if(s[i].equals(s[k])) {
					a=a+1;
				}
			}
			for(int k=0;k<M;k++) {
				if(s[i].equals(t[k])) {
					a=a-1;
				}
			}
			if(a>b) {
				b=a;
			}
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    ll n; cin >> n;
    ll res = n - 1;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res = min(res, i + (n / i) - 2);
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
#define INF 10e20
static const int MAX_N=10e5,MAX_M=10e5;
int N,M;
int maxs=-1,mini=INF,ans,res;
int A[MAX_N],B[MAX_N],C[MAX_N];
int main(void){
	cin >> N;
	for(int i=0;i<N;i++){
		int a;
			cin >> a;
		ans+=a;
		res=max(res,a);
	}
	cout << ans-res/2 << endl;
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];

	int hi = arr[0];
	int lo = arr[0];

	int hindex = 0;
	int lindex = 0;
	
	F0R(i, N) {
		if (arr[i] > hi) {
			hi = arr[i];
			hindex = i;
		}
		if (arr[i] < lo) {
			lo = arr[i];
			lindex = i;
		}
	}

	print(2 * N - 2);

	if (abs(hi) > abs(lo)) {
		F0R(i, N) if (i != hindex) {
			print(hindex + 1, i + 1);
		}

		F0R(i, N-1) {
			print(i+1, i+2);
		}
	} else {
		F0R(i, N) if (i != lindex) {
			print(lindex + 1, i + 1);
		}

		R0F(i, N-1) {
			print(i+2, i+1);
		}
	}
}

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

int a[114514], b[114514];
int s[114514];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < n; i++) {
		s[a[i]]++,s[b[i]]++;
	}
	int flg = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] & 1)flg = 1;
	}
	if (flg)cout << "NO" << endl;
	else cout << "YES" << endl;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  map<ll, ll> mp1, mp2;
  for (ll i = 0; i < N; i++) {
    ll d; cin >> d;
    mp1[d]++;
  }
  ll M; cin >> M;
  for (ll i = 0; i < M; i++) {
    ll d; cin >> d;
    mp2[d]++;
  }
  for (auto t : mp2) {
    ll x, n; tie(x, n) = t;
    if (mp1[x] < n) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	int t[n];
	int sum=0;
	FOR(i,n){
		cin >> t[i];
		sum+=t[i];
	}
	int m;
	cin >> m;
	int a,b;
	FOR(i,m){
		cin >> a >> b;
		cout << sum+b-t[a-1] <<"\n";
	}



	return 0;
}

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


int main() { 
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    int count1 = 0;
    int count2 = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && s[i] == '1') count1 += 1;
        if (i % 2 != 0 && s[i] == '0') count1 += 1; 
        if (i % 2 == 0 && s[i] == '0') count2 += 1;
        if (i % 2 != 0 && s[i] == '1') count2 += 1;
    }
    cout << min(count1, count2) << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
int i,n,m,j;
ll r=0;
cin>>n;
vector<int>v;
while(n--)
{
cin>>m;
v.pb(m);
sort(v.begin(),v.end());
}
for(i=0;i<v.size();i++)
{
    for(j=i+1;j<v.size();j++)
    {
        r+=v[i]*v[j];
    }
}
cout<<r<<endl;
return 0;
}

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

int main()
{
	int n; cin >> n;
	vector<double> X(n);
	double y, sum=0.0, sum2=0.0, sum3=0.0, xymax=0.0, tmp;

	for(auto &x : X) cin >> x;
	for(auto &x : X) { 
		cin >> y; 
		x = fabs(x-y); 
		xymax = (xymax>x) ? xymax : x;
		sum += (tmp=x); 
		sum2 += (tmp*=x);
		sum3 += (tmp*=x);
	}

	cout << fixed << setprecision(5);
	cout << sum << '\n' << sqrt(sum2) << '\n' << pow(sum3, 1.0/3.0) << '\n' << xymax << endl;

	return 0;
}



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

import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

class SegTree:
    """
    セグメント木
    1.update:  i番目の値をxに更新する
    2.query: 区間[l, r)の値を得る
    """

    def __init__(self, n, func, intv, A=[]):
        """
        :param n: 要素数(0-indexed)
        :param func: 値の操作に使う関数(min, max, add, gcdなど)
        :param intv: 要素の初期値(単位元)
        :param A: 初期化に使うリスト(オプション)
        """
        self.n = n
        self.func = func
        self.intv = intv
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.intv] * (n2 << 1)
        # 初期化の値が決まっている場合
        if A:
            # 1段目(最下段)の初期化
            for i in range(n):
                self.tree[n2+i] = A[i]
            # 2段目以降の初期化
            for i in range(n2-1, -1, -1):
                self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])

    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 0:
            i >>= 1
            self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])

    def query(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        l = a + self.n2
        r = b + self.n2
        s = self.intv
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(s, self.tree[r])
            if l & 1:
                s = self.func(s, self.tree[l])
                l += 1
            l >>= 1
            r >>= 1
        return s

    def get(self, i):
        """ 一点取得 """
        return self.tree[i+self.n2]

    def all(self):
        """ 全区間[0, n)の取得 """
        return self.tree[1]

N, M = MAP()
LRC = []
for i in range(M):
    l, r, c = MAP()
    l -= 1
    r -= 1
    LRC.append((l, r, c))

LRC.sort()
st = SegTree(N, min, INF)
st.update(0, 0)
for l, r, c in LRC:
    mn = st.query(l, r)
    if mn+c < st.get(r):
        st.update(r, mn+c)

ans = st.get(N-1)
if ans != INF:
    print(st.get(N-1))
else:
    print(-1)


Measured memory_bytes: 25792
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t,u;
  cin >> s;
  for(int i=0; i<7; i++) {
    t=s.substr(0,i+1);
    u=s.substr(s.size()-6+i,7-i+1);
    if(t+u=="keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int fr[200010],ta[200020],to[400040],nt[400040];
void f(int s){printf("!%d\n",s);
  int i;
  for(i=ta[s];i+1;i=nt[i]){
    if(fr[to[i]]!=-1)continue;
    fr[to[i]]=s;
    f(to[i]);
  }
}
int main(){
  int n,m,i,j,a,b,q[200010],t,r=1;
  scanf("%d %d",&n,&m);
  for(i=1;i<=n;i++)ta[i]=fr[i]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[i  ]=ta[a];
    nt[i+m]=ta[b];
    to[i  ]=b;
    to[i+m]=a;
    ta[a]=i;
    ta[b]=i+m;
  }
  /* for(i=0;i<n;i++){printf("%d:",i+1);
    for(j=ta[i];j+1;j=nt[j])printf("%d ",to[j]);printf("\n");
    }//*/
  q[t=0]=1;
  for(r=1;r-t;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(fr[to[i]]!=-1)continue;
      fr[to[i]]=q[t];
      q[r++]=to[i];
    }
  }  
  printf("Yes\n");
  for(i=2;i<=n;i++)printf("%d\n",fr[i]);
  return 0;
}


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

int main() {
    int INF = 9999999;
    string s;
    cin >> s;
    int N = s.size();
    vector<int> a(N, 0);
    for (int i = 0; i < N; i++) {
        int d = (1 << (int)(s[i]-'a'));
        if (i == 0) a[0] = d;
        else a[i] = a[i-1]^d;
    }
    vector<int> opt(N+1, INF);
    opt[0] = 0;
    map<int, int> dp;
    dp[0] = 1;
    for (int i = 1; i <= N; i++) {
        int m = INF;
        if(dp[a[i-1]]>0) m = min(m, dp[a[i-1]]);
        for (int k = 0; k < 26; k++) {
            int ak = a[i-1]^(1 << k);
           if(dp[ak]>0) m = min(m, dp[ak]);
        }
        opt[i] = m;
        if (dp[a[i-1]]>0)dp[a[i-1]] = min(dp[a[i-1]], m+1);
        else dp[a[i-1]] = m+1;
    }
    cout << opt[N] << endl;
    return 0;
}


Measured memory_bytes: 205828
#include<iostream>
using namespace std;
int main(){
    int n,x,i,j,k,num;
    while(1){
        cin>>n>>x;
        num=0;
        if(n==0&&x==0)break;
        for(i=1;i<=n-2;i++){
            for(j=i+1;j<=n-1;j++){
                for(k=j+1;k<=n;k++){
                    if((i+j+k)==x)num++;
                }
            }
        }cout<<num<<endl;
    }
    return 0;
}


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

vector<int> z_algo(const string& S) {
	int N = S.size();
	vector<int> A(N);
	A[0] = N;
	int i = 1, j = 0;
	while (i < N) {
		while (i + j < N && S[j] == S[i + j]) j++;
		A[i] = j;
		if (j == 0) {
			i++;
			continue;
		}
		int k = 1;
		while (i + k < N && k + A[k] < j) {
			A[i + k] = A[k];
			k++;
		}
		i += k;
		j -= k;
	}
	return A;
}

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int res = 0;
	for (int i = 0; i < N; i++) {
		auto vs = z_algo(S.substr(i));
		for (int j = 0; j < (int)vs.size(); j++) {
			res = max(res, min(j, vs[j]));
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256