akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

fn solve() {
	let(k,n) = read!(i64,usize);
	let a = read!([i64]);
	let mut diff = 0;
	for i in 0..n {
		let tmp = (a[(i+1)%n]-a[i]+k)%k;
		diff = max(diff,tmp);
	}
	println!("{}", k-diff);
}

fn run() {
    solve();
}


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

typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define no "NO"
#define yes "YES"
#define con continue;


int main()
{
    ios_base::sync_with_stdio(false);
	long long t, q;
	
	//seive();
	LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
	//LL aa[10000];
	LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
	LL ma=0, mi=100000000;
	LL mid=0, temp=0, stop=0, start=0, ans=0;
	double pi= 3.141592653589793;
	double d1=0.0, d2, d3, d4;
	VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
	VS vs, vs1, vs2, vs3, vs4;
	VP vp, vp1,vp2;
	char ch, ch1, ch2[1001];
	string str, str1, str2, str3, str4, str5;
	pair<LL, LL> pa;
	list<LL> li, li1;
	map<LL, LL> mp, mp1;
	set<LL> st;
	map<LL ,LL> :: iterator imll;
	VLL :: iterator ivl, low, up;
	set<LL> :: iterator it;
	VP :: iterator ivp;
	
	cin>>n;
	for(i=0; i<n; i++)cin>>a, v.pb(a);
	x = v[0];
	for(i=1; i<n; i++)
	{
		if(v[i]<v[i-1])
		{
			co+= (v[i-1]-v[i]);
			v[i]=v[i-1];
		}
	}
	cout<<co<<endl;
	
	
	
	
	
	

	return 0;
 
}



Measured memory_bytes: 5376
#include <stdio.h>
#define FOR(i,a,n) for(i=a;i<n;i++)
#define INF 10000000000000LL
#define ll long long

typedef struct{
	int from;
	int to;
	int cost;
} Edge;
Edge edge[2000];
ll d[1000];
int neg[1000];
int main(void)
{
	int m,n,i,j;
	Edge e;
	scanf("%d%d",&n,&m);
	FOR(i,0,n) d[i]=INF;
	FOR(i,0,m){
		scanf("%d%d%d",&edge[i].from,&edge[i].to,&edge[i].cost);
		edge[i].from--;
		edge[i].to--;
		edge[i].cost*=-1;
	}
	d[0]=0;
	FOR(i,0,n-1){
		FOR(j,0,m){
			e=edge[j];
			if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
			}
		}
	}
	FOR(i,0,n){
		FOR(j,0,m){
			e=edge[j];
			if(d[e.from]==INF) continue;
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				neg[e.to]=1;
			}
			if(neg[e.from]) neg[e.to]=1;
		}
	}
	if(neg[n-1]) puts("inf");
	else printf("%lld\n",-d[n-1]);
	return 0;
}
    
    
    


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

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

    for(int i=0; i<s.size()-1; i++){
        if(s[i] == 'B' && s[i+1] == 'C'){
            s.replace(i, 2, 1, 'S');
        }
    }

    long int count = 0;
    long int a_count = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'S')
            count += a_count;
        else if(s[i] == 'A')
            a_count++;
        else
            a_count = 0;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

T = sys.stdin.buffer.readline().decode().rstrip()
print(T.replace('?', 'D'))


Measured memory_bytes: 27284
/**
 *    author:  itmo1
 *    created: 21.08.2016 15:00:37       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

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

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;
char s[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    scanf("%s", s);
    map<char, int> M;
    for (int i = 0; s[i]; ++i) M[s[i]]++;
    bool ok = true;
    ok &= (M['W'] > 0) ^ (M['E'] == 0);
    ok &= (M['N'] > 0) ^ (M['S'] == 0);
    if (ok) printf("Yes\n");
    else printf("No\n");
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, a[1000],i,j,k;
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (j = i-1; j > 0; j--) {
		if (j == 1) {
			cout << a[1];
		}
		else {
			cout << a[j] << " ";
		}
	}
	cout << endl;
	return 0;

}

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

int main()
{
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xs {x};
  vector<int> ys {y};
  for (auto i = 0; i < n; i++) {
    int t;
    cin >> t;
    xs.push_back(t);
  }
  for (auto j = 0; j < m; j++) {
    int t;
    cin >> t;
    ys.push_back(t);
  }
  cout << (*max_element(begin(xs), end(xs)) < *min_element(begin(ys), end(ys))? "No War" : "War") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a, b;
int main() {
  cin >> n;
  read_n(a, 1 << n);
  init_n(b, 1 << n);
  i64 m = 1 << n;

  for (i64 e = 1; e < m; e <<= 1) {
    for (i64 s = 0; s < m; ++s) {
      if (!(e & s)) {
        i64 t = e | s;
        b[t] = max(b[t], a[s]);
        if (a[t] < b[t]) swap(a[t], b[t]);
        b[t] = max(b[t], b[s]);
      }
    }
  }

  i64 ans = 0;
  for (i64 k = 1; k < m; ++k) {
    ans = max(ans, a[k] + b[k]);
    cout << ans << '\n';
  }
  return 0;
}


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

int main(){
	
    string str;
	int N;
	int X = 0 ;
	int L = 0 ;
	
	scanf("%d" , &N);
	cin>>str;
	
	for(int i = 0 ; i < N ; i++)
	{
		if(str.at(i) == 'I')
	      X++;
	    if(str.at(i) == 'D')
		  X--;
		if(X > L)
		 L = X ;
	} 
	printf("%d",L);
	return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())

tlis = [[0] * (T+1) for i in range(N+1)]
AB = []

for i in range(N):

    A,B = map(int,input().split())
    AB.append([A,B])

AB.sort()

for i in range(N):

    A = AB[i][0]
    B = AB[i][1]

    for j in range(T+1):

        tlis[i+1][j] = tlis[i][j]

    tlis[i+1][min(T,A)] = max(tlis[i+1][min(T,A)],B)
    
    for j in range(T):

        if tlis[i][j] != 0:
            tlis[i+1][ min(T , j+A) ] = max(tlis[i+1][ min(T , j+A) ] , tlis[i][j] + B)
    

    
ans = 0
for i in range(T+1):

    ans = max(ans , tlis[-1][i])
    
print (ans)


Measured memory_bytes: 117596
#include <iostream>
using namespace std;
 
typedef long long ll;
 
ll A, B, C, N;
struct block{
  ll x,y,z;
};
 
#include <vector>
 
ll surfaces;
vector<block> deleted;
 
ll block_index(const vector<block> & v, ll x, ll y, ll z){
  for(ll i=0; i< v.size(); ++i){
    auto & block = v[i];
    if(block.x == x && block.y == y && block.z == z) return i;
  }
  return -1;
}
 
bool exist(ll x, ll y, ll z){
  if(block_index(deleted, x, y, z) != -1) return false;
  if( 0 <= x && x < A && 0 <= y && y < B && 0 <= z && z < C) return true;
  return false;
}
 
int main(){
  cin >> A >> B >> C >> N;
  surfaces = A * B * 2 + A * C * 2 + B * C * 2;
  for(int i = 0; i < N; ++i){
    ll x,y,z;
    cin >> x >> y >> z;
    
    int surface = 0;
    for(int d : {-1, 1}) if(!exist(x+d,y,z)) surface++;
    for(int d : {-1, 1}) if(!exist(x,y+d,z)) surface++;
    for(int d : {-1, 1}) if(!exist(x,y,z+d)) surface++;
 
    surfaces += 6 - surface * 2;
    deleted.push_back({x,y,z});
  }
 
  cout << surfaces << endl;
}

Measured memory_bytes: 3180
//============================================================================
// Name        : HelloCPP.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

	int n;
	int b,f,r,v;
	int rooms[5][4][11];

	for(int i = 1; i <= 4; i++)
		for(int j = 1; j <= 3; j++)
			for(int k = 1; k <= 10; k++)
				rooms[i][j][k] = 0;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		rooms[b][f][r] += v;
	}

	for(int i = 1; i <= 4; i++){
		if(i > 1) cout << "####################\n";
		for(int j = 1; j <= 3; j++){
			for(int k = 1; k <= 10; k++){
				cout << " " << rooms[i][j][k];
			}
			cout << endl;
		}
	}

}

Measured memory_bytes: 3108
#include<stdio.h>
#include<string.h>
int main(){
  int unused __attribute__((unused));
  int i, cnt = 0;
  char S[11], T[12];
  unused = scanf("%s", S);
  unused = scanf("%s", T);

  for(i=0; i<strlen(S); i++){
    if(S[i]==T[i]) cnt++;
  }
  if(cnt==strlen(S) && strlen(S)+1==strlen(T)) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1708
# -*- coding: utf-8 -*-
"""
D - Lazy Faith
https://atcoder.jp/contests/abc119/tasks/abc119_d

"""
import sys
from bisect import bisect_left, bisect_right

def solve(x):
    i = bisect_right(shrines, x)
    s_left = x - shrines[i-1]
    j = bisect_right(temples, x)
    t_left = x - temples[j-1]

    i = bisect_left(shrines, x)
    s_right = shrines[i] - x
    j = bisect_left(temples, x)
    t_right = temples[j] - x

    ans1 = max(s_left, t_left)
    ans2 = max(s_right, t_right)
    ans3 = min(s_right, t_left) * 2 + max(s_right, t_left)
    ans4 = min(s_left, t_right) * 2 + max(s_left, t_right)
    return min(ans1, ans2, ans3, ans4)


shrines = None
temples = None

def main(args):
    global shrines, temples
    A, B, Q = map(int, input().split())
    shrines = [float('-inf')] + [int(input()) for _ in range(A)] + [float('inf')]
    temples = [float('-inf')] + [int(input()) for _ in range(B)] + [float('inf')]
    for _ in range(Q):
        x = int(input())
        ans = solve(x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

typedef struct edge_ {
    int from,to,cost;
} edge;
edge e[500000];
int d[10000];

void Wchk(int n, int ni)
{
    int i, flg=1;
    for(i=1; i<n; i++) d[i]=500001;
       
    while(flg != 0){
        flg=0;
        for(i=0; i<ni; i++){
            if(d[e[i].from] !=500001 && d[e[i].from]+e[i].cost < d[e[i].to]) {
                d[e[i].to] = d[e[i].from]+e[i].cost;
                flg++;
            }
        }
    }
}
  
int main()
{
    int n,ni,nn;
    int i, j, d1;
    scanf("%d", &n);
   
    ni=0;
    for(i=0; i<n; i++) {
        scanf("%d", &d1);
        scanf("%d", &nn);
        for(j=1; j<=nn; j++) {
            e[ni].from=d1;
            scanf("%d %d", &e[ni].to, &e[ni].cost);
            ni++;
        }
    }
    Wchk(n, ni);
    for(i=0; i<n; i++)  printf("%d %d\n", i, d[i]);
    return 0;
}


Measured memory_bytes: 7712
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<pair<int,int> > d;
	while(a--)
	{
		int s;
		cin>>s;
		d.push(make_pair(s,1));
	}
	while(b--)
	{
		int s;
		cin>>s;
		d.push(make_pair(s,2));
	}
	while(c--)
	{
		int s;
		cin>>s;
		d.push(make_pair(s,3));
	}
	int z=x+y,num=0;
	while(z)
	{
		pair<int,int> k=d.top();
		d.pop();
		if(k.second==3)
		{
			num+=k.first;
			z--;
		}
		else if(k.second==1&&x)
		{
			num+=k.first;
			x--;
			z--;
		}
		else if(k.second==2&&y)
		{
			num+=k.first;
			y--;
			z--;
		}
	}
	cout<<num;
}

Measured memory_bytes: 10476
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const ll INF = 1e18;
vvi to, ot;
vb seen_1, seen_n, seen;

void dfs(int v) {
    if (seen_1[v]) return;
    seen_1[v] = true;
    for (int u : to[v]) dfs(u);
}

void rdfs(int v) {
    if (seen_n[v]) return;
    seen_n[v] = true;
    for (int u : ot[v]) rdfs(u);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> edges;
    to.resize(n);
    ot.resize(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges.eb(a, b, -c);
        to[a].pb(b);
        ot[b].pb(a);
    }
    seen_1 = seen_n = seen = vb(n, false);
    dfs(0);
    rdfs(n-1);
    rep(i, n) seen[i] = (seen_1[i] && seen_n[i]);
    
    vll d(n, INF);
    d[0] = 0;
    for (int t = 0; ; ++t) {
        bool upd = false;
        rep(i, m) {
            int a, b, w;
            tie(a, b, w) = edges[i];
            if (!seen[a] || !seen[b]) continue;
            if (chmin(d[b], d[a] + w)) upd = true;
        }
        if (!upd) break;
        if (t == n-1) {
            cout << "inf" << endl;
            return 0;
        }
    }
    cout << -d[n-1] << endl;

}

Measured memory_bytes: 384
using System;
using System.Text;

namespace Solution
{
    class Solution
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();
            for(int i = 1; i <= 9; i++)
            {
                for(int j = 1; j <= 9; j++)
                {                    
                    sb.AppendLine(string.Format("{0}x{1}={2}", i, j, i * j));
                }
            }

            Console.WriteLine(sb.ToString().Trim());

        }

    }
}


Measured memory_bytes: 9008
input_list = input().rstrip().split(' ')
max_num = max(input_list)
max_index = input_list.index(max_num)

big_str = str(input_list.pop(max_index))
big_str += str(input_list.pop())
big_num = int(big_str)
other_num = int(input_list.pop())

result = big_num + other_num
print(result)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


ll dp[100005];

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

    ll ww, vv;
    for(int i=0;i<n;i++)
    {
        cin >> ww >> vv;

        for(int wn = w-ww; wn>=0;wn--)
            dp[wn+ww] = max(dp[wn]+vv, dp[wn+ww]);
    }

    ll ans = 0;
    for(int i=0;i<w+1;i++)
        ans = max(ans, dp[i]);

    cout << ans << endl;

    

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
    string s; cin>>s;
    ll k; cin>>k;
    int ans=1;
    FOR(i,0,min((ll)s.size(),k)){
        if(s[i]!='1'){
            ans=s[i]-'1'+1; 
            break;
        }
    }
    co(ans);
}


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

namespace ABC122B
{
    class Program
    {
        public static string[] st;
        public static int counter = 0;
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            st = new string[s.Length];
            for (int i = 0; i < s.Length; i++)
            {
                st[i] = s.Substring(i, 1);
            }
            int max = 0;
            int tmp = 0;
            for (int i = 0; i <s.Length ; i++)
            {
                counter = 0;
                tmp=nextString(i);
                if (tmp > max) max = tmp;
            }
            Console.WriteLine(max);
        }
        public static int nextString(int n)
        {
            if ((st[n] == "A") || (st[n] == "C") || (st[n] == "G") || (st[n] == "T"))
            {
                counter++;
                if(n<st.Length-1)  nextString(n + 1);//文字列の長さを超えないように
            }
            return counter;
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    sc.close();
    int mod = 9;
    int ans = 0;
    for(int i = 0; i < n.length(); i++){
      ans = ans + (n.charAt(i) - '0');
      ans = ans % mod;
    }
    System.out.println(ans == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 40500
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int                          long long
#define mod                          1000000007  // 1e9 + 7 >>>  ans%mod
#define greator_sort(arr,n)          sort(arr, arr+n, greater<int>())  //descending order sorting of array
#define mk(arr,n,type)               type*arr = new type[n];    //to make array dynamically // n = size_of_array  |  type = int or long long etc;                      
#define w(x)                         int x;cin>>x; while(x--)   //x = test cases
#define pb                           push_back

//void c_p_c()
//{
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
//#endif
//}
//WINES PROBLEMS TUTORIAL EXPLANATION-----------------------------------------------------------------------
/*int profit(int wines[], int i, int j, int y, int dp[][100]) {
	//base case
	if (i > j) {
		return 0;
	}

	//return if dp[i][j]
	if (dp[i][j] != 0) {
		return dp[i][j];
	}

	//recursive case
	int op1 = wines[i] * y + profit(wines, i + 1, j, y + 1, dp);
	int op2 = wines[i] * y + profit(wines, i, j - 1, y + 1, dp);

	return dp[i][j] =  max(op1, op2);

}



int32_t main()
{
	c_p_c();
	int wines[] = {2, 3, 5, 1, 4};
	int dp[100][100] = {0};
	int y = 1;
	int n = sizeof(wines) / sizeof(int);
	cout << profit(wines, 0, n - 1, y, dp);

	return 0;

}
*/
//-------------------------------------------------------------------------------------------------------------------------//
//
//
//SOLUTION OF   FROG 1---------------------------------------------------->

int ans(int a[], int n, int dp[]) {
	//base case
	dp[1] = 0;

	//recursive case
	for (int i = 2; i <= n ; ++i)
	{
		int op2;
		int op1 = abs(a[i] - a[i - 1]) + dp[i - 1];
		if (i != 2)
			op2 = abs(a[i] - a[i - 2]) + dp[i - 2];
		if (i == 2)
			dp[i] = op1;
		else
			dp[i] = min(op1, op2);
	}
	return dp[n];
}



int32_t main()
{
	//c_p_c();
	int n; cin >> n; //size of the array
	int a[n];//height array
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	int dp[n + 1] = {0};
	cout << ans(a, n, dp) << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main() {
  map<int,int> mpd,mpt;
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for(int i = 0; i < n; i++) {
    mpd[d[i]]++;
  }
  int m;
  cin >> m;
  int t[m];
  for(int i = 0; i < m; i++) {
    cin >> t[i];
  }
  for(int i = 0; i < m; i++) {
    mpt[t[i]]++;
  }
  for(int i = 0; i < m; i++) {
    if(mpt[t[i]] > mpd[t[i]]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 20608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRGBTriplets solver = new DRGBTriplets();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRGBTriplets {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            char[] c = in.next().toCharArray();
            long r = 0;
            long g = 0;
            long b = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == 'R') r++;
                if (c[i] == 'G') g++;
                if (c[i] == 'B') b++;
            }

            long m = 0;
            for (int i = 0; i < n; i++) {
                for (int dif = 1; dif < n; dif++) {
                    if (i - dif >= 0 && i + dif < n) {
                        if (c[i] != c[i - dif] && c[i + dif] != c[i - dif] && c[i] != c[i + dif]) m++;
                    }
                }
            }

            out.println(r * g * b - m);

        }

    }
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    double T, X;
    cin >> T >> X;
    printf("%.10f\n", T / X);
    return 0;
}


Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
#include <map>
#include <utility>
//using
using namespace std;
using vi = vector <int>;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
 //各位の和　
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A'))->大なら真


//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll x,y;
  cin>>x>>y;
  while (x<=y)
  {
    x*=2;
    p++;
  }

  print(p)
  
}

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

#define FOR(i,N) for(int i=0;i<N;i++)
#define ROF(i,N) for(int i=N-1;i>=0;i--)
#define ROF1(i,a,b) for(int i=(b);i>=(a);i--)
#define FOR1(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b,c) for(int i=(a);i<=(b);i+=(c))

#define read freopen("IN.txt","r",stdin)
#define write freopen("OT.txt","w",stdout)
#define fastread {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mem(a,b)          memset(a,b,sizeof(a))
#define EPS 1e-9
#define PI              acos(-1.0)
#define INF             2e16

#define ll              long long
#define ull             unsigned long long
#define ft              first
#define sd              second
#define bn              begin
#define en              end
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(x) x.begin(), x.end()


#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};

int main()
{
#ifdef SunWalker
    //read;
   //write;
#endif

     int n,k,flip=0,same=0;
     string s;
     cin>>n>>k>>s;
     FOR(i,n-1)
     {
          if(s[i]!=s[i+1])flip++;
          else same++;
     }
     cout<<same+min(flip,2*k)<<"\n";


return 0;
}



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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<int> {a, b, c, d};
	cout << max({ a * c, a * d, b * c, b * d}) << endl;
	// if (  ( a > 0 and c > 0 ) ) cout << b*d << endl;
	// else if( b < 0 and d < 0 ) cout << a*c << endl;
	// else if( )

	// else if( c >=0 || d >= 0 ) cout << 0 << enld;
	// else cout << c*


}

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

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















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

public class Main {
	static final long INF = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		long power = 1;
		
		for(int i = 1; i <= n; i++) {
			power = power * i % INF;		
		}
		out.println(power % INF);
		
		out.close();
	}

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



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

const ll MOD = 1e9+7;

ll power(ll a,ll b){
    ll ret=1;
    if(b>0){
        ret = power(a,b/2);
        if(b%2==0)ret = (ret*ret)%MOD;
        else ret = (((ret*ret)%MOD)*a)%MOD;
    }
    return ret;
}


int main(){
    int n;
    cin>>n;
    
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    vector<int> teach(n);
    rep(i,n){
        teach[i] = abs(i-(n-i-1));
    }
    
    sort(all(teach));
    sort(all(v));
        
    if(teach!=v){
        cout<<0<<endl;
        return 0;
    }
    
    
    int t = n/2;
    
    cout<<power(2,t)<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <numeric>


using namespace std;

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

int main() {

    string S;

    cin >> S;

    if (S == "ABC")
    {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
N,M=map(int,input().split())
res = 0
flag = True
#任意の数Kに対してたどり着く通り数
INF = 100000000000
stepList = [INF]*(N+1)
stepList[0] = 1
stepList[1] = 1
def stepF(K):
  if K == 0:
    return stepList[0]
  else:
    for i in range(1,K+1):
      if i == 1:
        pass
      else:
        if stepList[i]==INF:
          stepList[i]= stepList[i-2] + stepList[i-1]
    return stepList[K]
  
if M == 0:
  res = stepF(N)
  
else:
  List = []
  for i in range (M):
    List.append(int(input()))
  #任意の数aが壊れている場合
  
  for i in range(M):
    if i == 0:
      res = stepF(List[i]-1)
    else:
      if List[i] - List[i-1] == 1:
        flag = False
        break
      res = res * stepF(List[i]-List[i-1]-2)
  res = res * stepF(N-List[M-1]-1)
if flag:
  print(res%1000000007)
else:
  print(0)

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];
  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
  rep(i, N) rep(x, W + 1) {
    if (x >= w[i])
      dp[i + 1][x] = max(dp[i][x], dp[i][x - w[i]] + v[i]);
    else
      dp[i + 1][x] = dp[i][x];
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
s1 = int(input())
s2 = [int(x) for x in input().split(" ")]

def allEven(l):
    result = True
    for n in l:
        result = n % 2 == 0 and result
    return result
ns = s2
count = 0
while allEven(ns):
    ns = [x / 2 for x in ns]
    count += 1
print(count)

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

int main(){
  int n;
  string s;
  cin >> s;
  n=s.size();

  int t[26]={};
  int k=26,x=0;
  for(int i=0;i<n;i++){
      t[s[i]-'a']++;
  }

  int ans=26;
  for(int i=0;i<26;i++){
    if(t[i]==0){
      ans=i;
      break;
    }
  }
  if(ans==26){
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
     cout<<"-1"<<endl;
     return 0;
   }else{
     string l;
     char b;
     for(int i=n-1;i>0;i--){
       t[s[i]-'a']--;
       if(s[i]>s[i-1]){
         int h;
         h=s[i-1]-'a';
         for(int j=h+1;j<26;j++){
           if(t[j]==0){
             x=j;
             break;
           }
         }
         for(int j=0;j<i-1;j++) cout<<s[j];
         break;
       }
     }
     b=x+'a';
     cout<<b<<endl;
     return 0;
   }
  }else{
    char a;
    a=ans+'a';
    cout<<s<<a<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a = Array.new(n).map { Array.new(n, Float::INFINITY) }
(0..n-1).each {|i| a[i][i] = 0 }
m.times do
  i, j, d = gets.split.map(&:to_i)
  a[i][j] = d if d < a[i][j]
end

(0..n-1).each do |k|
  (0..n-1).each do |i|
    (0..n-1).each do |j|
      x = a[i][k] + a[k][j]
      a[i][j] = x if x < a[i][j]
    end
  end
end

catch :exit do
  (0..n-1).each do |k|
    (0..n-1).each do |i|
      (0..n-1).each do |j|
        x = a[i][k] + a[k][j]
        if x < a[i][j]
          puts 'NEGATIVE CYCLE'
          throw :exit
        end
      end
    end
  end

  a.each do |row|
    puts row.map {|x| x == Float::INFINITY ? 'INF' : x } * ' '
  end
end


Measured memory_bytes: 8912
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(){
	int n,i,c=0;
	long long int a,b,data[100000]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&data[i]);
	}

	qsort(data, n, sizeof(long long int), compare_int);
	
	for(i=0;i<n;i++){
		if(i==0){
			a=data[i];
		}else{
			if(a==data[i]){
				c+=1;
				if(c==2){
					break;	
				}
				b=a;
				a=0;
			}else{
				a=data[i];
			}
		}
	}
	if(c==2){
		printf("%lld\n",a*b);
	}else{
		printf("0\n");	
	}
	
return 0;
}

Measured memory_bytes: 1788
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var n , x = sc.nextInt()
  var a = Array.fill(n)(sc.nextInt()).sorted
  var ans = 0
  for (i <- 0 until n if x >= a(i) & !(x - a(i) != 0 & i == n-1)){
    x -= a(i)
    ans += 1
  }
  println(ans)
}


Measured memory_bytes: 55708
import sys

input_line = input()
N= int(input_line)

input_line = input()
student_num = list(map(int,input_line.split()))

buff = [0 for i in range(N)]
for i in range(len(student_num)):
    buff[student_num[i]-1] = i+1
print(' '.join(map(str, buff)))

Measured memory_bytes: 18944
#include <stdio.h>
int main(void){
    int h, w;
    while (1) {
        scanf("%d%d", &h, &w);
        if (h == 0) break;
        for (int i=0; i < h;i++) {
            for (int j=0; j < w; j++) {
                if ((i == 0) || (i == h -1)) printf("#");
                else if (j == 0 || j == w -1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}



Measured memory_bytes: 2028
#include<iostream>
using namespace std;
int main(void)
{
    int n,A,B,card1,card2;
    while(1){
            A=0;B=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>card1>>card2;
            if(card1>card2)A+=card1+card2;
            else if(card2>card1)B+=card1+card2;
            else{
                A+=card1;
                B+=card2;
            }
        }
        cout<<A<<" "<<B<<"\n";
    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int m, d;
	cin>>m>>d;
	int ans=0;
	for(int i=4; i<=m; i++){
		for(int j=10; j<=d; j++){
			int d1=j%10;
			int d2=j/10;
			if(d1>=2 && d2>=2 && i==d1*d2){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	ll n;
	cin>>n;
	ll h[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	ll c[n]={};
	c[0]=0;c[1]=abs(h[1]-h[0]);
	for(ll i=2;i<n;i++)
	{
	    c[i]=min(c[i-1]+abs(h[i]-h[i-1]),c[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<c[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
int a[maxn];
int n; 
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int c1, c2;
	for (int i = 1; i <= n; i++)
		if (a[i] >= n - i + 1) {
			int ns = n - i + 1;
			c1 = a[i] - ns + 1;
			c2 = 1;
			for (int j = i - 1; j >= 1; j--)
				if (a[j] >= ns) c2++;
			break;
		}
	if (c1 % 2 == 1 && c2 % 2 == 1) cout << "Second" << endl;
	else cout << "First" << endl;
	return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g=[[] for _ in range(n)]

for i in range(n-1): # 行列の作成
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

costs = [0]*n # 答えの格納

for i in range(q): # コスト初期値の入力
    p, x = map(int, input().split())
    costs[p-1]+=x

visited = [0]*n # 訪問スタンプ

def dfs(idx):
    visited[idx]=1
    for i in g[idx]:
        if visited[i]==1:
            continue
        costs[i]+=costs[idx] # 累積和をとる
        dfs(i) # 再帰処理
    return

dfs(0)
print(*costs)


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

using namespace std;

int main()
{
    int a , b , k ;
    cin>>a>>b>>k ;
    int cnt = 0 ;
    for(int i = 100 ; i >= 1 ; --i)
    {
        if(a%i == 0 && b % i == 0)
            cnt++ ;
        if(cnt == k)
            return cout<<i<<"\n" , 0 ;
    }
}


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

using namespace std;

int main(){
    vector<int> v(8);
    for(int i=0; i< 8; i++) v[i] = i;
    map<int, int> m;

    queue<pair<vector<int>, int> > que;
    que.push(make_pair(v, 0));
    while(que.size()){
        vector<int> v = que.front().first; int count = que.front().second; que.pop();
        int p = 0;
        for(int i=0; i< 8; i++) p = p*10+v[i];
        if(m[p] == 0 || count+1 < m[p]) m[p] = count+1;
        else continue;

        for(int i=0; i < 8; i++){
            if(v[i] == 0){
                if(i != 0 && i != 4){
                    swap(v[i], v[i-1]);
                    que.push(make_pair(v, count+1));
                    swap(v[i], v[i-1]);
                }
                if(i != 3 && i != 7){
                    swap(v[i], v[i+1]);
                    que.push(make_pair(v, count+1));
                    swap(v[i], v[i+1]);
                }
                if(3 < i){
                    swap(v[i], v[i-4]);
                    que.push(make_pair(v, count+1));
                    swap(v[i], v[i-4]);
                }
                else {
                    swap(v[i], v[i+4]);
                    que.push(make_pair(v, count+1));
                    swap(v[i], v[i+4]);
                }
            }
        }
    }
    int n;
    while(cin >> n){
        for(int i=1; i< 8; i++){
            int t; cin >> t;
            n = n*10+t;
        }
        cout << m[n]-1 << endl;
    }
}

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

typedef long long int ll;
using namespace std;

const ll MOD = 1e9 + 7;

int main()
{
	int n; cin>>n; string s; cin>>s;
	vector<int> c(26,1);

	for(int i=0;i<n;i++){
		c[s[i]-'a']++;
	}

	ll ans = 1;

	for(int i=0;i<26;i++){
		ans *= c[i]; ans %= MOD;
	}

	ans--; ans %= MOD;
	if(ans < 0) ans += MOD; ans %= MOD;
	cout<<ans;
}

Measured memory_bytes: 512
s = input()

if s.count('R') == 3 :
  print(3)
elif s.count('R') == 1:
  print(1)
elif s.count('R') == 0:
  print(0)
elif s.count('R') == 2:
  res = [i for i in range(len(s)) if s.startswith('R', i)]
  if sum(res) == 2:
    print(1)
  else:
    print(2)
  

Measured memory_bytes: 8916
int main(){
  int n,i,j,a[100],swap=0,x;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	x=a[j];
	a[j]=a[j-1];
	a[j-1]=x;
	swap++;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
  printf("%d\n",swap);
  return 0;
}



Measured memory_bytes: 2072
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a<b&&a<c&&b<c){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int func(int n) {
    if(n == 1) { return 300000; }
    else if(n == 2) { return 200000; }
    else if(n == 3) { return 100000; }
    return 0;
}

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

    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1 && Y == 1) {
        ans += 400000;
    }
    ans += func(X);
    ans += func(Y);

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

    return 0;
}

Measured memory_bytes: 256
// sort間に合うんですかね？

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (a[num-1] == 0)
                cnt++;
            a[num-1]++;
        }

        int ans = 0;
        if (cnt > k) {
            Arrays.sort(a);
            ans = n;

            for (int i = 1; i <= k; i++) {
                ans -= a[a.length-i];
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 83060
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

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


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m; cin >> n >> m;
    vi height(n+1);
    FOR(i,n) cin >> height[i+1];
    vector<bool> good(n+1,1);
    int goodv = n;
    FOR(i,m){
        int a,b; cin >> a >> b;
        if(height[a] <= height[b] && good[a]){goodv--; good[a] = 0;}
        if(height[b] <= height[a] && good[b]){ goodv--; good[b] = 0;}
    }
    cout << goodv << endl;
    return 0;
}


Measured memory_bytes: 3728