akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CTreeRestoring {
public:
    void solve(istream& cin, ostream& cout) {
      //SPEED;
      int n; cin >> n;
      vector<int> cnt(101);
      int ma = 0;
      rep(i, n) {
        int a; cin >> a;
        cnt[a]++;
        chmax(ma, a);
      }
      debug(ma);
      if (cnt[ma] < 2) {
        cout << "Impossible" << endl;
        return;
      }
      for(int i=ma-1; i>=0; i--) {
        debug(i);
        if (i > (ma+1)/2) {
          if (cnt[i] < 2) {
            cout << "Impossible" << endl;
            return;
          }
        } else if (i == (ma+1)/2) {
          if (ma%2==0) {
            if (cnt[i] != 1) {
              cout << "Impossible" << endl;
              return;
            }
          } else {
            if (cnt[i] != 2) {
              cout << "Impossible" << endl;
              return;
            }
          }
        } else {
          if (cnt[i] > 0) {
            cout << "Impossible" << endl;
            return;
          }
        }
      }
      cout << "Possible" << endl;
    }
};

signed main() {
  CTreeRestoring solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int R = scan.nextInt();
			
			double a = 2.0*(double)R*3.1415926535897;
			
			System.out.println(a);
			
		}
		
		
	}
		

}


Measured memory_bytes: 35908
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

for i in range(n+1):
    ans = min(ans,W[i] + (n-i)-(W[-1] - W[i]))
print(ans)


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    REP(i,n){
        int32 a;
        cin >> a;
        if(a % 2 == 1){
            cout << "first\n";
            return 0;
        }
    }
    cout << "second\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b" << endl;
	else if (a > b)
		cout << "a > b" << endl;
	else if (a == b)
		cout << "a == b" << endl;
	return 0;
}


Measured memory_bytes: 3108
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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

fn solve() {
    input! {
        n: usize,
        a: [usize;n]
    }

    let mut ans: usize = 1;
    let mut over = false;

    for i in 0..n {
        if a[i] == 0 {
            over = false;
            ans = 0;
        }
        if ans.checked_mul(a[i]) == None {
            over = true;
        } else {
            ans *= a[i];
            if ans > 1000000000000000000 {
                over = true;
            }
        }
    }

    if over {
        println!("{}", -1);
    } else {
        println!("{}", ans);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2280
#include<stdio.h>

int main(){

  int N;

  // input N
  scanf("%d",&N);

  if (N < 0 || N > 100 ){
    return 1;
  }

  int a[2*N];
  // input Li until 2N
  for (int i=0; i < 2*N; i++ ){
    scanf("%d",&a[i]);
    if (a[i] < 0 || a[i] > 100 ){
      return 1;
    }
  }

  // sort a[] from smallest to largest

  int tmp;
  for (int i=0; i<2*N; ++i) {
    for (int j=i+1; j<2*N; ++j) {
      if (a[i] > a[j]) {
        tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }


  int sum=0;
  // calculate sum
  for (int i=0; i < 2*N; i++ ){
    if ( i%2==0){
    //printf ("%d ",a[i]);
    sum+=a[i];
    }
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include <stdlib.h>


//クイックソート用　昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//qsort(配列の先頭ポインタ, データ数, 1データのサイズ, compare_int);


int main()
{
    int s[3];
    scanf("%s",s);
  if((strcmp(s, "ABC\0") == 0) )
  {
    printf("ARC");
  }
  else
  {
      printf("ABC");
  }
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL n;
  cin >> n;
  vector<LL> a(n);
  REP(i,n){
    cin >> a[i];
  }

  LL sum = 0;
  REP(i,n){
    sum += a[i]-1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import heapq

N = int(input())
v = list(map(int, input().split()))

heapq.heapify(v)

res = 0
for _ in range(N-1):
  a = heapq.heappop(v)
  b = heapq.heappop(v)
  res = (a+b)/2
  heapq.heappush(v, res)
    
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define met(a) memset(a,0,sizeof(a))
using namespace std;
const int mod=1e9+7;
const int N=1e6+10;
int a[320][320];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int i,j,k,m,n;
    ll ans=0,cnt,sum;
    std::cin>>n;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            std::cin>>a[i][j];
    for(i=1; i<=n; i++)
        for(j=0; j<=i; j++)
        {
            sum=0;
            for(k=1; k<=n; k++)
                if(i==k||j==k)
                    continue;
                else if(a[i][j]==(a[i][k]+a[k][j]))
                    sum=1;
                else if(a[i][j]>a[i][k]+a[k][j])
                {
                    cout<<-1<<endl;
                    return 0;
                }
            if(!sum)
                ans+=a[i][j];
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>

using namespace std;

struct Plan
{
    int a;
    int b;
};

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

    vector<Plan> p;
    for(int i=0; i<N; i++)
    {
        Plan temp;
        scanf("%d %d\n",&(temp.a),&(temp.b));
        p.push_back(temp);
        //test printf("%d %d\n",p[i].a, p[i].b);
    }

    auto fa=[](Plan an, Plan bn){ return an.a < bn.a; };
    sort(p.begin(), p.end(), fa);
    priority_queue<int> q;
    long long int res=0;

    for(int i=1, count=0; i<=M; i++)
    {
        while(p[count].a==i&&count<N)
        {
            //test printf("%d %d\n",p[count].a, p[count].b);            
            q.push(p[count].b);
            count++;
        }
        if(!q.empty()){ res+=q.top(); q.pop(); }
    }

    printf("%lld\n",res);

    return 0;
}

Measured memory_bytes: 1908
N = int(input())
a = list(map(int, input().split()))

# ある値がaに存在するとき、その＋ー1の値を足す
## ans_list[-1]となる場合向けにlistは1個余分に値を設けておく
ans_list = [0] * (10 ** 5 + 2)

for i in a:
    ans_list[i] += 1
    ans_list[i + 1] += 1
    ans_list[i - 1] += 1

ans = max(ans_list)

print(ans)


Measured memory_bytes: 13964
#include<stdio.h>
#include<string.h> 
int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	
	int r;
	int h[N];
	int p=0;
	
	for(r=0; r<N; r++){
		scanf("%d", &h[r]);
		if(h[r] >= K) p++;
	}
	
	printf("%d", p);

}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int main(){
  short *A, *B;

  int C[10001];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for ( i = 0; i <= 10000; i++ ) C[i] = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }
  for ( i = 1; i <= 10000; i++ ) C[i] = C[i] + C[i - 1];
  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8460
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cassert>
#include<iomanip>
#define M 256
#define MAX 257
using namespace std;
int N;
int I[MAX],O[MAX],R[MAX];
int cnt[MAX];
const double EPS = 1e-7; 

void makeR(int S,int A,int C)
{
  R[0] = S;
  for(int i=1;i<=N;i++)
    R[i] = (A*R[i-1]+C)%M;    
}

void makeO(int S,int A,int C)
{
  for(int i=0;i<N;i++)
    O[i] = (I[i]+R[i+1])%M;
}

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

double getH()
{
  double ret = 0;
  
  for(int i=0;i<MAX;i++)
    {
      if(cnt[i] == 0)continue;
      if(cnt[i] == N)continue;
      ret += (cnt[i]/(double)N)*log(cnt[i]/(double)N);
    }
  
/*
  for(int i=0;i<N;i++)
    {
      if(cnt[O[i]] == N)continue;
      ret += (cnt[O[i]]/(double)N)*log(cnt[O[i]]/(double)N);
    }
*/
  return -ret;
}

bool check(int s,int a,int c,int ss,int aa,int cc)
{
  if(s != ss)return s < ss;
  if(a != aa)return a < aa;
  if(c != cc)return c < cc;
}

int main()
{ 
  while(cin >> N,N)
    {
      for(int i=0;i<N;i++)cin >> I[i];

      /*
      makeR(0,0,0);
      makeO(0,0,0);
      for(int l=0;l<MAX;l++)cnt[l]=0;
      for(int i=0;i<N;i++)cnt[O[i]]++;     
      for(int i=0;i<N;i++)
        cout << R[i] << " ";
      cout << endl;
      
      for(int i=0;i<N;i++)
        cout << O[i] << " ";
      cout << endl;

      for(int i=0;i<N;i++)
        cout << cnt[O[i]] << " ";
      cout << endl;
      
      cout << "H = " << setiosflags(ios::fixed) << setprecision(20) << getH() << endl;
      cout << endl;
      makeR(8,7,14);
      makeO(8,7,14);
      for(int l=0;l<MAX;l++)cnt[l]=0;
      for(int i=0;i<N;i++)cnt[O[i]]++;     
      for(int i=0;i<N;i++)
        cout << R[i] << " ";
      cout << endl;
      
      for(int i=0;i<N;i++)
        cout << O[i] << " ";
      cout << endl;

      for(int i=0;i<N;i++)
        cout << cnt[O[i]] << " ";
      cout << endl;
      
      cout << "H = " << setiosflags(ios::fixed) << setprecision(20) << getH() << endl;
      return 0;
      */
      /*
      makeR(0,1,1);
      makeO(0,1,1);
      for(int i=0;i<N;i++)
        cout << R[i] << " ";
      cout << endl;

      for(int i=0;i<N;i++)
        cout << O[i] << " ";
      cout << endl;

      cout << "H = " << getH() << endl;

      return 0;
      */

      int aS,aA,aC;
      aS=aA=aC=0;
      double men = (1<<29);

      for(int S=0;S<16;S++)
        {
          for(int A=0;A<16;A++)
            {
              for(int C=0;C<16;C++)
                {
                  makeR(S,A,C);
                  makeO(S,A,C);
                  for(int l=0;l<MAX;l++)cnt[l]=0;
                  for(int i=0;i<N;i++)cnt[O[i]]++;
                  //cout << S << " " << A << " " << C << " x" << endl; 
                  double H = getH();
                  //cout << "H = " << H << endl;
                  if(men > H &&  !equal(men,H))
                    {                  
                      men = H;
                      aS = S;
                      aA = A;
                      aC = C;
                    }
                }
            }
        }

   


      cout << aS << " " << aA << " " << aC << endl; 
    }
  return 0;
}

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

#define ll long long 
 
using namespace std ;
 
ll z , ans , o ;

ll mod = 1e9 + 7 ;
ll N = 1e5 + 7 ;


int main( ){

	string s ;

	cin >> s ;

	if( s == "ABC" ){

		cout << "ARC" << endl ;

	}

	else{

		cout << "ABC" <<endl ;

	}
}	



Measured memory_bytes: 3624
n,k=map(int,input().split())
x=list(map(int,input().split()))

l_x=[i for i in x if i<0]
r_x=[i for i in x if i>=0]

ans=10**12
for r_num in range(k+1):
  l_num=k-r_num
  
  if l_num>len(l_x) or r_num>len(r_x):
    continue
  if l_num==0: #右片道
    ans=min(ans,r_x[r_num-1])
  elif r_num==0: #左片道
    ans=min(ans,abs(l_x[-1*l_num]))
  elif abs(l_x[-1*l_num])<=r_x[r_num-1]: #左往復右片道
    ans=min(ans,abs(l_x[-1*l_num])*2+r_x[r_num-1])
  else: #右往復左片道
    ans=min(ans,abs(l_x[-1*l_num])+(r_x[r_num-1])*2)
print(ans)

Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5005,M=205;
int a[N],sum[N],ans,x,p[M][N],v[M][N],t[M],n,m;
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=2;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			scanf("%lld",&x);
			for (;t[j]&&v[j][t[j]]<=x;t[j]--){
				sum[p[j][t[j]]]-=v[j][t[j]];
				sum[p[j][t[j]-1]]+=v[j][t[j]];
			}
			sum[p[j][t[j]]]-=x;
			v[j][++t[j]]=x;p[j][t[j]]=i;
			sum[i]+=x;
		}
		int s=0;
		for (int j=i;j;j--){
			s+=sum[j];
			ans=max(ans,s-a[i]+a[j]);
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,sum=0;
  for(int i=0;i<4;i++){
    cin >> a;
    sum+=a;
  }
  cout << sum/60 << endl;
  sum-=sum/60*60;
  cout << sum << endl;
  return 0;
}

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

vector<int> nodeByA[2500];
vector<int> nodeByB[2500];
bool reachableByA[2500];
bool reachableByB[2500];
bool reachable[2500];

void dfsByA (int n) {
    if (reachableByA[n]) {
        return;
    }

    reachableByA[n] = true;

    for (int a: nodeByA[n]) {
        dfsByA(a);
    }
}

void dfsByB (int n) {
    if (reachableByB[n]) {
        return;
    }

    reachableByB[n] = true;

    for (int b: nodeByB[n]) {
        dfsByB(b);
    }
}

int main() {
    int N, M, P;
    cin >> N >> M >> P;

    vector<tuple<int, int, int>> edges;
    rep (i, M) {
        int A, B, C;
        cin >> A >> B >> C;

        A -= 1;
        B -= 1;
        C = -1 * (C - P);

        nodeByA[A].push_back(B);
        nodeByB[B].push_back(A);
        edges.emplace_back(A, B, C);
    }
    dfsByA(0);
    dfsByB(N - 1);

    rep(i, N) {
        reachable[i] = reachableByA[i] && reachableByB[i];
    }

    // const int INF = 1001001001;
    vector<int> d(N, 1001001001);
    d[0] = 0;

    bool update = true;
    int count = 0;

    while (update) {
        update = false;

        rep(i, M) {
            int a, b, c;
            tie(a, b, c) = edges[i];

            if (!(reachable[a] && reachable[b])) {
                continue;
            }

            int newD = d[a] + c;
            if (newD < d[b]) {
                d[b] = newD;
                update = true;
            }
        }

        count++;
        if (count > N) {
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << max(-d[N - 1], 0) << endl;
    return 0;
}


Measured memory_bytes: 640
import math
import itertools


#B
n, d = map(int,input().split())

X = list()

for num in range(n):
    x = list(map(int,input().split()))
    X.append(x)

ans_count = int()

if d > 1:
    for v in itertools.combinations(X, 2):
        dist = int()
        for num in range(d):
            dist += (v[0][num] - v[1][num])**2
        ans_dist = math.sqrt(dist)
        if ans_dist.is_integer():
            ans_count += 1
    print(ans_count)
    
else:
    for v in itertools.combinations(X, 2):
        dist = int()
        dist = (v[0][0]- v[1][0])**2
        ans_dist = math.sqrt(dist)
        if ans_dist.is_integer():
            ans_count += 1
    print(ans_count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
int N, M;
vector<int> A;

//=================================================
void input()
{
    cin >> N >> M;
    A = vint(N);
    rep(i, N)
    {
        cin >> A[i];
    }
}

//=================================================
void solve()
{
    vector<ll> Aac(N + 1);
    Aac[0] = 0;
    for (int i = 0; i < N; ++i)
    {
        Aac[i + 1] = (Aac[i] + A[i]) % M;
    }

    int cnt = 0;
    map<int, int> mp;
    mp[0] = 1;

    for (int i = 1; i < N + 1; ++i)
    {
        mp[Aac[i]]++;
    }

    for (auto x : mp)
    {
        cnt += (x.second - 1) * x.second / 2;
    }

    cout << cnt << endl;
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n;cin>>n;
    
    vector<int> D(n);cin>>D;
    
    int m;cin>>m;
    vector<int> T(m);cin>>T;
    
    map<int, int> cnt;
    
    rep(i,n){
        cnt[D[i]]++;
    }
    
    rep(i,m){
        if(cnt[T[i]]==0){cout<<"NO"<<endl;return 0;}
        cnt[T[i]]--;
    }
    
    cout<<"YES"<<endl;
    
    
    
    return 0;
    
    
}




Measured memory_bytes: 11136
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))

Measured memory_bytes: 38148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int arraymax = 1000005;
        int[] X = new int[M]; 
        int[] gap = new int[arraymax];
        int gapMax = 0; 
        int ans = 0;
        
        for(int i = 0; i < M; i++){
            X[i] = sc.nextInt();
        }
        Arrays.sort(X);

        for(int i = 0; i < 1000005; i++){
            gap[i] = 0; 
        }
        for(int i = 0; i < M-1; i++){
            gap[i] = X[i+1] - X[i]; 
        }
        Arrays.sort(gap);

        for(int i = 0; i < N-1; i++){
            gap[(arraymax - 1) - i] = 0;
        }

        for(int i = 0; i < arraymax; i++){
            ans += gap[i];
        }

        System.out.print(ans);
    }
}


Measured memory_bytes: 63076
#B
#入力
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
#処理
C=[[0 for i in range(3)] for j in range(3)]
for a in B:
    for b in range(3):
        for c in range(3):
            if a==A[b][c]:
                C[b][c]=1
t=0
for i in range(3):
    if C[i][0]*C[i][1]*C[i][2]==1:
        print("Yes")
        t=1
        break
    if C[0][i]*C[1][i]*C[2][i]==1:
        print("Yes")
        t=1
        break
if t==0:
    if C[0][0]*C[1][1]*C[2][2]==1:
        print("Yes")
    elif C[0][2]*C[1][1]*C[2][0]==1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int n = 0;

void countingSort(int A[], int B[], int k){
    int C[k+1];

    for (int i=0; i<=k; i++){
        C[i] = 0;
    }
    for(int j=0; j<n; j++){
        C[A[j]]++;
    }
    for(int i=1; i<=k; i++){
        C[i] = C[i] + C[i-1];
    }
    for(int j=n-1; j>=0; j--){
        B[C[A[j]]-1] = A[j];
        C[A[j]]--;
    }
}

int main()
{
    scanf("%d",&n);
    int arr[n];
    int B[n];
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    countingSort(arr, B, 10001);
    for(int j=0; j<n-1; j++){
        printf("%d ", B[j]);
    }
    printf("%d\n", B[n-1]);
    return 0;
}


Measured memory_bytes: 17400
#include<stdio.h>

int main(){
		int c[3][3],i,j,ab[2][3][2];
		for(i=0;i<3;i++){
				for(j=0;j<3;j++)scanf("%d",&c[i][j]);
		}
		for(i=0;i<3;i++){
				ab[0][i][0]=c[i][0]-c[i][1];
				ab[0][i][1]=c[i][1]-c[i][2];
		}
		for(i=0;i<3;i++){
				ab[1][i][0]=c[0][i]-c[1][i];
				ab[1][i][1]=c[1][i]-c[2][i];
		}
		if(ab[0][0][0]==ab[0][1][0]&&ab[0][1][0]==ab[0][2][0]&&
		ab[0][0][1]==ab[0][1][1]&&ab[0][1][1]==ab[0][2][1]&&
		ab[1][0][0]==ab[1][1][0]&&ab[1][1][0]==ab[1][2][0]&&
		ab[1][0][1]==ab[1][1][1]&&ab[1][1][1]==ab[1][2][1]){
				puts("Yes");
				return 0;
		}
		puts("No");
		return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_set>

const int MAX_N = 50;
std::vector<int> edge[MAX_N];
std::unordered_set<int> visitedList;

bool dfs(const int& x, const int& n, const int& a, const int& b, const int& last = -1)
{
  if (visitedList.find(x) == visitedList.end())
  {
    visitedList.emplace(x);
  }

  if (visitedList.size() == n)
  {
    return true;
  }
  bool ret = false;
  for (const auto& to : edge[x])
  {
    bool isVisited = false;
    for (const auto& visited : visitedList)
    {
      if (to == visited)
      {
        isVisited = true;
        break;
      }
    }
    if (isVisited == true) continue;
    if ((a == x && b == to) || ( a == to && b == x)) continue;
    ret = dfs(to, n, a, b, x);
    if (ret == true) break;
  }
  return ret;
}

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::vector<int> onDirectionEdge[MAX_N];
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    std::cin >> a >> b; --a; --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
    onDirectionEdge[a].push_back(b);
  }
  int ans = m;
  for (int i = 0; i < n; ++i)
  {
    for (const auto& clamp : onDirectionEdge[i])
    {
      const bool isConnected = dfs(0, n, i, clamp);
      if (isConnected == true)
      {
        --ans;
      }
      visitedList.clear();
    }
  }
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(a,n) for(ll i=a;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(v) v.begin(),v.end()
using namespace std;
const ll mod=(1e+9)+7;
const ll size = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}


void solve()
{
    ll n = 0;
    string s;
    cin>>s;
    f(0,s.size())
    {
        if(s[i] == '+')
        n++;
        else
        n--;
    }
    cout<<n<<endl;
}

int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

pii a[100005];
int main(){
    std::ios::sync_with_stdio(false);

    int N,i;
    cin >> N;
    ll tot = 0;
    a[0].ss= 0; a[0].ff=0;
    f(i,1,N+1){
	ll k; cin >> k;
	a[i].ff = k;
	a[i].ss = abs(a[i-1].ff-k);     
	tot += a[i].ss;
    }

    a[0].ss = abs(a[N].ff);
    tot+=a[0].ss;
    for(int i = 1; i <= N; i++) {
	if(i == N){
	    cout << tot - a[0].ss-a[N].ss 
	    + abs(a[i-1].ff) << endl;
	}
	else {     
	    cout << tot - a[i].ss - a[i+1].ss
	    + abs(a[i-1].ff - a[i+1].ff) << endl;
	}
    }

    return 0;
    
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d);
    Cout(a < b ? 0 : 10);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int

using namespace std;

int const MAXN = 1e6 + 5;
char s[MAXN];
int a[MAXN];

int main() {
//  freopen("a.in", "r", stdin);
//  freopen("a.out", "w", stdout);
  scanf("%s", s);
  int len = strlen(s), sum = 0;
  for (RI i = 0; i < len; ++i)
    a[len - i] = s[i] ^ 48;
  for (RI i = 1; i <= len; ++i)
    a[i] *= 9, a[i] += a[i - 1] / 10, a[i - 1] %= 10;
  --len;
  for (; a[len + 1]; ++len)
    a[len + 2] += a[len + 1] / 10, a[len + 1] %= 10;
  for (RI i = 1; i <= len; ++i)
    sum += a[i];
  for (RI i = 1; i <= len; ++i) {
    sum += 9;
    int now = 1;
    a[now] += 9;
    while (a[now] > 9) sum -= 9, a[now] -= 10, ++a[now + 1], ++now;
    if (sum <= 9 * i) return printf("%d\n", i), 0;
  }
  return 0;
}


Measured memory_bytes: 4608
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	int v1, v2, v3;
	v1 = n % 10;
	v2 = (n / 10) % 10;
	v3 = (n / 100) % 10;
	if (v1 == v3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
#define pi acos(-1)
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/* keep hungry and keep calm! */

int a[maxn],b[maxn],deg[maxn];
int Sheryang(){

    for(int i=1;i<=3;i++){
        a[i]=read,b[i]=read;
        deg[a[i]]++;deg[b[i]]++;
    }

    for(int i=1;i<=4;i++){
        if(deg[i]>=3){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 4352
#[allow(unused)]
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        n: usize,
        a: [i64; n],
    }

    let mut mut_a = a.clone();
    mut_a.sort();
    let max = mut_a[n - 1];

    for i in 0..n {
        if a[i] < max {
            println!("{}", max);
        } else {
            println!("{}", mut_a[n - 2]);
        }
    }
}

Measured memory_bytes: 9724
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

struct Bipartite_Matching {
  // グラフ表現のベクトル　a->b,a->c etc...
  vector< vector< int > > graph;
  //
  vector< int > match, alive, used;
  int timestamp;

  Bipartite_Matching(int n) {
    timestamp = 0;
    // 要素数の変更
    graph.resize(n);
    // n個に1,0,-1を代入する
    alive.assign(n, 1);
    used.assign(n, 0);
    match.assign(n, -1);
  }

  // 枝を加えて二部グラフを作成
  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  // 深さ優先探索
  bool dfs(int v) {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }

  // 最大マッチングを求める問題
  int bipartite_matching() {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  }
};

// int main(){
//   int N;
//   int a[105],b[105],c[105],d[105];
//   cin >> N;
//   for(int i=0;i<N;++i){
//     cin >> a[i] >> b[i];
//   }
//   for(int i=0;i<N;++i){
//     cin >> c[i] >> d[i];
//   }
//
//   Bipartite_Matching flow(N+N);
//
//   for(int i=0;i<N;++i){
//     for(int j=0;j<N;++j){
//       if((a[i] < c[j]) && (b[i] < d[j])){
//         flow.add_edge(i,j+N);
//       }
//     }
//   }
//   cout << flow.bipartite_matching() <<  endl;
// }

int main(){
  int N,a[105],b[105],c[105],d[105];
  cin >> N;
  Bipartite_Matching graphs(N+N);
  for(int i=0;i<N;++i){
    cin >> a[i] >> b[i];
  }
  for(int i=0;i<N;++i){
    cin >> c[i] >> d[i];
    for(int j=0;j<N;++j){
      if(a[j]<c[i] && b[j]<d[i]){
        graphs.add_edge(j,i+N);
      }
    }
  }
  cout << graphs.bipartite_matching() << endl;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	vi h(n);
	REP(i, n)cin >> h[i];
	ll r = INF, l = 0;
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll cnt = 0;
		REP(i, n) {
			if (h[i] > mid*b)cnt += (h[i] - mid*b+a-b-1) / (a - b);
		}
		if (cnt > mid)l = mid;
		else r = mid;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main()
{
  int n,m, ret = 0; cin>>n>>m;
  int t[n+2][m+2];
  rep(i,n+1)rep(j,m+1) t[i][j] = 0;
  rep(i,n)
  {
    rep(j,m)
    {
      cin>>t[i][j];
      t[i][m] += t[i][j];
      t[n][j] += t[i][j];
      ret+=t[i][j];
    }
  }
  t[n][m] = ret;
  rep(i,n+1)
  {
    rep(j,m+1)
    {
      cout << t[i][j];
      if(j!=m) cout << " ";
    }
    cout << "\n";
  }
}


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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 500006
#define mod 1000000007
#define mod2 998244353
#define inf 1e18


vector <pii> edges;
set <int> st[N];


int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    
    int n,W;

    cin >> n >> W;

    int dp[W+1];
    memset(dp,0,sizeof dp);
    int i,j;
    int w[n],v[n];
    for(i=0;i<n;i++)
    {
        cin >> w[i] >> v[i];
    }

    for(i=0;i<n;i++)
    {
        for(j=W;j>=w[i];j--)
        {
            dp[j]=max(dp[j],v[i]+dp[j-w[i]]);
        }
    }

    cout << dp[W] << endl;


}

Measured memory_bytes: 24448
# PyPy で提出しないと通らない
import sys
input = sys.stdin.readline

n, k = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

dp = [0] * n

for i in range(1, n):
    min_cost = 1e19
    for j in range(1, min(k + 1, i + 1)):
        cost = dp[i - j] + abs(hs[i] - hs[i - j])
        min_cost = min(cost, min_cost)
    dp[i] = min_cost

print(dp[n - 1])


Measured memory_bytes: 84940
class ReversePopHeap
  attr_accessor :nodes, :size
  def initialize(n)
    @nodes = Array.new(n)
    @size = 0
  end

  def push(x)
    current_index = @size
    @size += 1
    while current_index > 0 do
      parent_index = (current_index - 1)>>1
      parent_value = @nodes[parent_index]
      break if parent_value >= x
      @nodes[current_index] = parent_value
      current_index = parent_index
    end
    @nodes[current_index] = x
  end

  def pop
    top = @nodes[0]
    current_node_index = 0
    current_node_value = @nodes[0] = @nodes[@size - 1]
    @nodes[@size - 1] = nil
    @size -= 1

    while
      child_node_index_r = (current_node_index + 1) << 1
      child_node_index_l = child_node_index_r - 1
      return top unless child_node_index_l < @size
      child_node_value_l = @nodes[child_node_index_l]
      child_node_value_r = @nodes[child_node_index_r]
      if child_node_value_r&.>child_node_value_l
        max_child_value = child_node_value_r
        max_child_index = child_node_index_r
      else
        max_child_value = child_node_value_l
        max_child_index = child_node_index_l
      end
      return top unless max_child_value > current_node_value
      change(current_node_index, max_child_index)
      current_node_index = max_child_index
    end
  end

  private

  def change(index_i, index_j)
    @nodes[index_i], @nodes[index_j] = @nodes[index_j], @nodes[index_i]
  end
end

n, m = gets.split.map(&:to_i)

values = []
n.times do
  a = gets.split.map(&:to_i)
  values << (a[0] << 17) + a[1]
end
values.sort!

mask = (1 << 17) - 1

rhp = ReversePopHeap.new(n)
ans = 0
ite = 0
1.step(m) do |limit_day|
  while true
    break unless values[ite] && (values[ite] >> 17) == limit_day
    rhp.push(values[ite] & mask)
    ite += 1
  end
  ans += rhp.pop.to_i if rhp.size > 0
end

puts ans

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(1); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1010;
int n,p[N];
int f[50][1010];
char s[3010];
string info;

int a[110],b[110];

void gao(int *a) {
	rep(j,0,100) {
		int x=0;
		rep(c,0,30) x|=(s[j*30+c]-'0')<<c;
		a[j]=x;
	}
}

int main() {
	scanf("%s",s);
	rep(c,0,30) rep(j,0,1000) f[c][j]=rnd(2);
	if (s[0]=='A'||s[0]=='B') {
		rep(i,0,100) {
			scanf("%s",s);
			rep(j,0,1000) p[j]=s[j]-'0';
			rep(c,0,30) {
				int x=0;
				rep(j,0,1000) if (f[c][j]) x^=p[j];
				info.pb('0'+x);
			}
		}
		printf("%s\n",info.c_str());
		fflush(stdout);
	} else {
		scanf("%s",s);
		gao(a);
		scanf("%s",s);
		gao(b);
		rep(i,0,100) {
			scanf("%s",s);
			int msk=0;
			rep(j,0,1000) p[j]=s[j]-'0';
			rep(c,0,30) {
				int x=0;
				rep(j,0,1000) if (f[c][j]) x^=p[j];
				msk|=x<<c;
			}
			rep(x,0,100) rep(y,0,100) if ((a[x]^b[y])==msk) {
				printf("%d %d\n",x+1,y+1);
				goto end;
			}
			end:;
		}
	}
}



Measured memory_bytes: 3728
#include<iostream>
using namespace std;
int main(){
    int n,b,f,r,v;
    int count[4][3][10] = {{{}}};
    cin >>n;
    for (int i=0; i<n; i++){
        cin >>b >>f >>r >>v;
        count[b-1][f-1][r-1] += v;
        
    }for (int i=0; i<4;i++){
        for (int j=0; j<3;j++){
            for (int k=0; k<10; k++){
                if(count[i][j][k] == 0){
                    cout <<" 0";
                }else{
                    cout <<" "<<count[i][j][k];
                }
            }cout <<endl;
        }if (i!= 3){
            cout <<"####################"<<endl;
        }
    }
}


Measured memory_bytes: 3084
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

//template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define fn(num) for(int n=0 ; n<num ; ++n)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define fnr(num) for(int n=num-1 ; n>=0 ; --n)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
int EuclideanAlgorithm(int N, int *array){ fn(N - 1) {while (true) {if (array[n] % array[n + 1] == 0 || array[n + 1] % array[n] == 0) {array[n + 1] = min(array[n], array[n + 1]);break;}if (array[n] > array[n + 1]) {array[n] %= array[n + 1];}else {array[n + 1] %= array[n];}}}return array[N - 1];}

signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	gi(N);
	int life[100000];
	fn(N){
		gi(life[n]);
	}

	int *p[2];

	ret = EuclideanAlgorithm(N, life);
	ans(ret);

	wait();

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int d[N];
    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i;j<N-1;j++){
            ans += d[i]*d[j+1];
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B;
  cin>>A>>B;
  if((A+B)%2==0){
    cout<<(A+B)/2;
  }else{
    cout<<"IMPOSSIBLE";
  }
  

  return 0;
}

Measured memory_bytes: 256