akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<City> cities = new ArrayList<>();

        for (int i = 1; i <= n; i++) {

            City city = new City(i, sc.next(), sc.nextInt());

            int index = cities.indexOf(city);
            if (index == -1) {
                cities.add(city);
            } else {
                cities.get(index).addRestaurant(i, city.ids.get(0).point);
            }
        }

        cities.sort(Comparator.comparing(aCity -> aCity.name));

        for (City city: cities
             ) {
            city.ids.sort((aID, bID) -> bID.point - aID.point);
            for(ID id : city.ids) {
                // 出力
                System.out.println(id.no);
            }
        }
    }

    private static class City {
        private ArrayList<ID> ids = new ArrayList<>();
        private String name;

        private City(int no, String name, int point) {
            addRestaurant(no, point);
            this.name = name;
        }

        private void addRestaurant(int no, int point) {
            ids.add(new ID(no, point));
        }

        @Override
        public boolean equals(Object obj) {
            City target = (City)obj;
            return name.equals(target.name);
        }
    }

    private static class ID {
        private int no;
        private int point;
        private ID(int no, int point) {
            this.no = no;
            this.point = point;
        }
    }
}

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

int main()
{
  int n;
  cin >> n;
  int sum = 0;
  while (n > 0)
  {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
    n--;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;class Main{public static void main(String[] args){Scanner scanner=new Scanner(System.in);int N=scanner.nextInt();boolean[] a=new boolean[N+2];for(int i=1;i<N+1;i++){a[i]=scanner.nextInt()==i;}int ans=0;for(int i=1;i<N+1;i++){if(a[i]){a[i]=a[i+1]=false;ans++;}}System.out.println(ans);}}

Measured memory_bytes: 50132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N; cin >> N;
    int cnt = 0;
    rep(i,N){
        int A;
        cin >> A;
        if(A%2==1){
            cnt++;
        }
    }
    if(cnt%2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>

using namespace std;
int main() {
	int N;
	cin >> N;
	std::map<std::string, int> Judge;
	Judge["AC"] = 0;
	Judge["WA"] = 0;
	Judge["TLE"] = 0;
	Judge["RE"] = 0;
	
	for(int i = 0;i<N;i++){
		std::string S;
		cin >> S;
		Judge[S]++;
	}
	
	std::cout << "AC x " << Judge["AC"] << endl; 
	std::cout << "WA x " << Judge["WA"] << endl; 
	std::cout << "TLE x " << Judge["TLE"] << endl; 
	std::cout << "RE x " << Judge["RE"] << endl; 
	
	return 0;
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    char map[H+5][W+5];
    for(int i = 0; i < H; ++i) cin >> map[i];

    int L[H+5][W+5],
        R[H+5][W+5],
        U[H+5][W+5],
        D[H+5][W+5];
    
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j){
            //左方向に照らされるマスの数
            if(map[i][j] == '#') L[i][j] = 0;
            else if(j == 0) L[i][j] = 1;
            else L[i][j] = L[i][j-1] + 1;
            //右方向
            int r_j = W-1-j;
            if(map[i][r_j] == '#') R[i][r_j] = 0;
            else if(r_j == W-1) R[i][r_j] = 1;
            else R[i][r_j] = R[i][r_j + 1] + 1;
        }
    }

    for(int j = 0; j < W; ++j) {
        for(int i = 0; i < H; ++i) {
            //上方向
            if(map[i][j] == '#') U[i][j] = 0;
            else if(i==0) U[i][j] = 1;
            else U[i][j] = U[i-1][j] + 1;

            //下方向
            int d_i = H-1-i;
            if(map[d_i][j] == '#') D[d_i][j] = 0;
            else if(d_i == H-1) D[d_i][j] = 1;
            else D[d_i][j] = D[d_i+1][j] + 1;
        }
    }

    int ans = 0;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            ans = max(ans, R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66816
#include<stdio.h>

int main()
{
    int a,b,c;

    scanf("%d %d %d", &a, &b, &c);

    if (a!=b && a!=c) printf("%d",a);
    else if (b!=a && b!=c) printf("%d",b);
    else if (c!=a && c!=a) printf("%d",c);

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, m; cin >> n >> m;
	vector<int> v[100001];
	for (int i=0; i<n; i++) {
		int a, b; cin >> a >> b;
		v[a].push_back(b);
	}

	int ret = 0;
	priority_queue<int> q;
	for (int i=1; i<=m; i++) {
		for (auto p : v[i]) q.push(p);
		if (!q.empty()) {
			ret += q.top();
			q.pop();
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 8992
import java.io.*;
import java.util.*;
 
public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[]in=sc.takearr(n);
		boolean[]seq=new boolean[n+1];
		seq[0]=true;
		for(int i=0;i<n;i++) {
			if(seq[in[i]-1]) {
				seq[in[i]]=true;
			}
		}
		int cnt=0;
		for(int i=1;i<=n;i++) {
			if(seq[i]) {
				cnt++;
			}
			else
				break;
		}
		pw.println(cnt==0?-1:n-cnt);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 47180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	cout<<(n>=30?"Yes":"No")<<endl;

	return 0;
}



Measured memory_bytes: 3596
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
x.sort!
dist = []

last = x[0]
(m-1).times do |i|
  dist << (x[i+1] - last)
  last = x[i+1]
end

dist.sort!

answer = dist[0..(-n)].reduce(0, :+)

p answer


Measured memory_bytes: 9968
class Node():
    def __init__(self):
        self.parent = None
        self.left = None
        self.right = None


def preorder(id):
    print(f" {id}", end="")
    if tree[id].left is not None:
        preorder(tree[id].left)
    if tree[id].right is not None:
        preorder(tree[id].right)

def inorder(id):
    if tree[id].left is not None:
        inorder(tree[id].left)
    print(f" {id}", end="")
    if tree[id].right is not None:
        inorder(tree[id].right)


def postorder(id):
    if tree[id].left is not None:
        postorder(tree[id].left)
    if tree[id].right is not None:
        postorder(tree[id].right)
    print(f" {id}", end="")
    
n = int(input())
tree = []
for _ in range(n):
    tree.append(Node())
for _ in range(n):
    id, left, right = map(int, input().split())
    if left != -1:
        tree[id].left = left
        tree[left].parent = id
    if right != -1:
        tree[id].right = right
        tree[right].parent = id
        
for id in range(n):
    if tree[id].parent is None:
        root_id = id
        break
    
print("Preorder")
preorder(root_id)
print("")
print("Inorder")
inorder(root_id)
print("")
print("Postorder")
postorder(root_id)
print("")


Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
ipair students[100001];
int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        students[i].second = i + 1;
        cin >> students[i].first;
    }
    
    sort(students, students + N);

    for(int i = 0; i < N; ++i) {
        if(i != 0) cout << " ";
        cout << students[i].second;
    }
    cout << endl;
   
}

Measured memory_bytes: 2432
let prime_factors n =
  let rec doit i x acc =
    if i*i > n then
      if x = 1 then acc
      else x :: acc
    else if x mod i = 0 then doit i (x / i) (i :: acc)
    else doit (i + 1) x acc in
  doit 2 n []

let decon lst =
  List.fold_left (fun acc x -> match acc with
    | [] -> [x]
    | y :: _ -> if x = y then acc else x :: acc) [] lst

let phi_func n =
  prime_factors n
  |> decon
  |> List.fold_left (fun acc x -> acc *. (1. -. 1. /. (float x))) (float n)
  |> int_of_float

let () =
  let n = read_int () in
  phi_func n |> Printf.printf "%d\n"

Measured memory_bytes: 2332
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int x = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		if(Math.abs(a-x) > Math.abs(b-x)){
			System.out.println("B");
		}else{
			System.out.println("A");
		}		
	}
}


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

int main() {
  long A, B, K;
  cin >> A >> B >> K;
  if (A >= K) {
    A -= K;
  } else if (A + B >= K) {
    B = B - (K - A);
    A = 0;
  } else {
    A = 0;
    B = 0;
  }
  printf("%ld %ld\n", A, B);
  return 0;
}


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



int main(void){
int a,b,c;
cin >> a>>b>>c;
if(a == b&&a==c){
  cout << 1 << endl;
}
else if(a == b||a==c||b==c){
  cout << 2<<endl;
}
else{
  cout << 3 << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, l;
    cin >> n >> l;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) {
        a[i] = make_pair(v[i], i);
    }
    sort(a.begin(), a.end(), greater<>());
    vector<ll> dp(n+2);
    ll ans = 0;
    for (int q = 0; q < n; ++q) {
        int i = a[q].second;
        dp[i+1] = max(dp[i], dp[i+2])+ l-v[i];
        ans = max(ans, dp[i+1]);
    }
    cout << ans << "\n";
    return 0;
}



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

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

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int H, W;
int cnt[26];

void init()
{
	cin >> H >> W;
	rep(i, H*W) {
		char c;
		cin >> c;
		cnt[c-'a']++;
	}
}

void solve()
{
	int f = 0;
	int t = 0;
	int A = H * W;
	int nt, nf;
	rep(i, 26) {
		f += cnt[i] / 4;
		cnt[i] -= (cnt[i] / 4) * 4;
		t += cnt[i] / 2;
	}
	if (W % 2 && H % 2) {
		nf = (W / 2) * (H / 2);
		nt = (A - nf * 4 - 1) / 2;
	} else if (W % 2 || H % 2) {
		if (W % 2) {
			nf = (W - 1) * H / 4;
			nt = A - nf * 4;
			nt /= 2;
		} else {
			nf = W * (H - 1) / 4;
			nt = A - nf * 4;
			nt /= 2;
		}
	} else {
		nf = A / 4;
		nt = 0;
	}
	if (f < nf) {
		PRINT(0);
		return;
	}
	t += (f - nf) * 2;
	PRINT(t >= nt);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline
ll getint(){
	re ll num=0;
	re char c;
	while(!isdigit(c=gc()));
	while(isdigit(c))num=(num<<1)+(num<<3)+(c^48),c=gc();
	return num;
}

inline
void outint(ll a){
	static char ch[23];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=(a-a/10*10)^48,a/=10;
	while(ch[0])pc(ch[ch[0]--]);
}

set<string> se;
string s,last;
int n;
int main(){
	n=getint();
	for(int re i=1;i<=n;++i){
		cin>>s;
		if(se.find(s)!=se.end()){
			puts("No");
			return 0;
		}
		se.insert(s);
		if(i!=1)
		if(s[0]!=last[last.size()-1]){
			puts("No");
			return 0;
		}
		last=s;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#define LIM 1000000007
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  for (int i = 1; i <= n; i++) {
    ll k = i;
    for (int e = 2; e <= i; e++) {
      while (k % e == 0) {
        k /= e;
        m[e] = m[e] + 1;
      }
    }
  }
  ll ans = 1;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ans *= (itr->second + 1);
    ans %= LIM;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
      Scanner sc=new Scanner(System.in);
      
      int n=sc.nextInt();//何両編成か
      int i=sc.nextInt();//前から何両目か
      int b=0;//後ろから何両目か
      
      b=(n-i)+1;
      
      System.out.println(b);
    }
}

Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	int[] a = new int[8];
	int[] b = new int[8];
	int[] sa = new int[8];
	int nikka ;
	int ww ;
	
	
public void syukei(){
	for (nikka=1;nikka <8;nikka++){

		 a[nikka] = sc.nextInt();

		 b[nikka] = sc.nextInt();
		 sa[nikka] = a[nikka] - b[nikka];
		
	}
	
}
public void hyouji(){
	for(ww=1;ww<8;ww++){
		
	
	System.out.println(sa[ww]);
	}
}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Main wao = new Main();
		wao.syukei();
		wao.hyouji();

	}

}

Measured memory_bytes: 17236
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cmath>
using namespace std;
 
 
int main() {
    int N;
    cin >> N;
    vector<string> W(N);

    for (int i = 0; i < N; i++) cin >> W[i];
    
    string ans = "Yes";
    for (int i = 0; i < N; i++) {
        if (i != 0 && W[i-1].back() != W[i].front()) {
            ans = "No";
            break;
        }
        for (int j = 0; j < i; j++) {
            if (W[i] == W[j]) {
                ans = "No";
                break;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
typedef long long LL;

int main(){
    LL n;
    scanf("%lld",&n);
    /*LL ans1 = 0;*/
    /*for(LL i = 1; i <= n; i++){
        if(n/i==n%i) ans1 += i;
    }*/   
    LL ans2 = 0;
    for(LL i = 1; i*i <= n; i++){
        if(n%i==0){
            LL a = i;
            LL b = n/i;
            LL k1 = a; LL m1 = b-1;
            LL k2 = b; LL m2 = a-1;
            if(m1>k1) ans2 += m1;
            if(m2>k2) ans2 += m2;
        }
    }
    printf("%lld\n",ans2);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;
//import org.apache.commons.lang3.StringUtils;
 
 
/**
 *
 * @author aj
 */
public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            String[] HW = in.readLine().split(" ");
            String[] hw = in.readLine().split(" ");
            int H = Integer.parseInt(HW[0]);
            int W = Integer.parseInt(HW[1]);
            int h = Integer.parseInt(hw[0]);
            int w = Integer.parseInt(hw[1]);
            int r = H*W - ( h*(W-w) + h*w + w*(H-h));
            out.write((r+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        
    }
    
    
    
}

Measured memory_bytes: 22612
N = int(input())
A = list(map(int,input().split()))
min = 0
for i in range(N):
    if i == 0:
        max = A[i]
    else :
        if max > A[i] :
            min = min + max - A[i]
        else :
            max = A[i]   
print(min)

Measured memory_bytes: 94144
#include <iostream>
#include <algorithm>

using namespace std;

const char mark[4] = {'R', 'D', 'L', 'U'};
const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int main(void) {
    bool w[5][9];
    for (int i = 0; i < 9; i++) {
        int x = 4 + i % 2;
        for (int j = 0; j < x; j++) {
            char c;
            cin >> c;
            w[j][i] = (c == '1');
        }
    }
    int x = 0, y = 0, d = 0;
    do {
        int dx, dy, _x, _y;
        d--;
        if (d < 0) d += 4;
        for (int i = 0; i < 4; i++) {
            dx = dir[d][0];
            dy = dir[d][1];
            _x = x + dx;
            _y = y + dy;
            if (_x >= 0 && _x <= 4 && _y >= 0 && _y <= 4) {
                if (d % 2 == 0 && w[min(x, _x)][y * 2]) break;
                if (d % 2 == 1 && w[x][min(y, _y) * 2 + 1]) break;
            }
            d++;
            d %= 4;
        }
        x = _x;
        y = _y;
        cout << mark[d];
    } while (!(x == 0 && y == 0));

    cout << endl;

    return 0;
}

Measured memory_bytes: 1132
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  ll a[n];
  ll ma = 0;
  ll mi = INF;
  rep(i,n){
    cin >> a[i];
    chmax(ma,a[i]);
    chmin(mi,a[i]);
  }
  pri(ma-mi);

  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,m = inpm()
    print(n*(n-1)//2+m*(m-1)//2)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 63980
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);
    boolean union[];
    char[][] str;
    int n;

    void run() {
        for (;;) {
            n = sc.nextInt();
            if (n == 0)
                break;
            int[] in = new int[256];
            int[] out = new int[256];
            str = new char[n][2];
            for (int i = 0; i < n; i++) {
                char[] tmp = sc.next().toCharArray();
                str[i][0] = tmp[0];
                str[i][1] = tmp[tmp.length - 1];
                in[str[i][0]]++;
                out[str[i][1]]++;
            }
            union = new boolean[256];
            dfs(str[0][0]);
            boolean flag = true;
            for (int i = 'a'; i <= 'z'; i++) {
                if (!union[i] && in[i] + out[i] != 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                boolean ok = true;
                for (int i = 'a'; i <= 'z'; i++) {
                    if (Math.abs(in[i] - out[i]) != 0) {
                        ok = false;
                        break;
                    }
                }
                System.out.println(ok ? "OK" : "NG");
            } else {
                System.out.println("NG");
            }
        }
    }

    void dfs(char c) {
        for (int i = 0; i < n; i++) {
            if (str[i][0] == c) {
                if (!union[str[i][1]]) {
                    union[str[i][1]] = true;
                    dfs(str[i][1]);
                }
            }
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

}

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

using namespace std;

typedef long long ll;

ll dp[100][21];

int n;
int a[100];

ll rec(int i, int j)
{
	if (j < 0 || j > 20) return 0;

	if (dp[i][j] >= 0) return dp[i][j];

	ll res;

	if (i == n - 2) {
		res = j == a[n - 1];
	} else {
		res = rec(i + 1, j + a[i + 1]) + rec(i + 1, j - a[i + 1]);
	}

	return dp[i][j] = res;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; ++i) cin >> a[i];

	memset(dp, -1, sizeof(dp));

	printf("%lld\n", rec(0, a[0]));
}

Measured memory_bytes: 1176
N=int(input())
A=list(map(int,input().split()))

mini=float("inf")
summ=0
minus=0

for i in range(N):
  if A[i]<0:
    minus += 1
  mini = min(mini,abs(A[i]))
  summ += abs(A[i])

if minus%2==0:
  print(summ)
else:
  print(summ-2*mini)

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

using namespace std;


int main()
{
    long long n,res=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0)res+=i;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll a = 0, bc = 0;
    ll ans = 0;
    int state = 0; // 1:a, 2:bc
    for ( int i = 0; i < n - 1; i++ ) {
        if ( s[i] == 'A' ) {
            if ( state == 0 ) {
                state = 1;
                a++;
            } else if (state == 1 ) {
                a++;
            } else {
                state = 1;
                ans += a * bc;
                a++;
                bc = 0;
            }
        } else if ( s[i] == 'B' && s[i+1] == 'C') {
            if ( state == 0 ) {
            } else if ( state == 1 ) {
                state = 2;
                bc = 1;
            } else {
                bc++;
            }
            i++;
        } else {
            state = 0;
            ans += a * bc;
            a = 0;
            bc = 0;
        }
    }
    ans += a * bc;

    cout << ans << '\n';
    return 0;
}

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

using namespace std;

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

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


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int3(a, b, h);
    pri((a + b) * h / 2);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n, m;
  cin >> n >> m;
  Yes(n==m);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<bool> check(8,false);
  int b=0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    if(a>=1&&a<=399) check.at(0)=true;
    if(a>=400&&a<=799) check.at(1)=true;
    if(a>=800&&a<=1199) check.at(2)=true;    
    if(a>=1200&&a<=1599) check.at(3)=true;
    if(a>=1600&&a<=1999) check.at(4)=true;
    if(a>=2000&&a<=2399) check.at(5)=true;
    if(a>=2400&&a<=2799) check.at(6)=true;    
    if(a>=2800&&a<=3199) check.at(7)=true; 
    if(a>=3200) b++;     
  }
  int ans1=0;
  for(int i=0; i<8; i++){
    if(check.at(i)) ans1++;
  }
  int ans2=ans1+b;
  ans1=max(1,ans1);  
  cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for _ in range(Q):
    B.append(list(map(int,input().split())))
s=sum(A)
from collections import Counter
a=Counter(A)
b=list(a.keys())
c=list(a.values())
for i in range(Q):
    s-=B[i][0]*a[B[i][0]]
    s+=B[i][1]*a[B[i][0]]
    a[B[i][1]]+=a[B[i][0]]
    a[B[i][0]]=0
    print(s)

Measured memory_bytes: 39980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    auto dist = make_v<ll>(N, N);
    fill_v(dist, INT_MAX);
    map<ll, ll> cnt;
    rep(i, N)
    {
        rep(j, N)
        {
            if (i <= X and Y <= j)
            {
                chmin(dist[i][j], abs(i - j) - abs(Y - X) + 1);
                chmin(dist[j][i], dist[i][j]);
            }
            else
            {
                chmin(dist[i][j], (ll)min((ll)abs(i - j), abs(i - X) + abs(Y - j) + 1));
                chmin(dist[j][i], (ll)min((ll)abs(i - j), abs(i - X) + abs(Y - j) + 1));
            }
        }
    }
    rep(i, N)
    {
        rep2(j, i + 1, N)
        {
            cnt[dist[i][j]]++;
        }
    }
    rep2(k, 1, N)
    {
        cout << cnt[k] << "\n";
    }
    return 0;
}

Measured memory_bytes: 31744
import Control.Monad.State
import Control.Arrow

getInts = map read . words <$> getLine :: IO [Int]

data Coins = Coins {_a::Int,_b::Int,_c::Int}

sumStr = map (\x -> read [x]) >>> foldr1 (+)

main = do
    (n:a:b:_) <- getInts
    putStrLn . show $ take n >>> filter (show >>> sumStr >>> between a b) >>> foldr1 (+) $ [1..]
    where between a b x =  a <= x && x <= b


Measured memory_bytes: 1276
N = int(input())

A = [int(input()) for i in [0]*N]

m = max(A)
ind = A.index(m)
A_ = A[:ind]+A[ind+1:]
m_ = max(A_)

for i in range(N):
	if i != ind:
		print(m)
	else:
		print(m_)


Measured memory_bytes: 15424
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
inline int read(){
	int ret=0,p=1;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') p=-1;
	for (;isdigit(ch);ch=getchar()) ret=ret*10+ch-'0';
	return ret*p;
}
int n,p;
int a[100000+3];
LL f[50+3][2];
int main(){
	n=read();p=read();
	for (int i=1;i<=n;i++) a[i]=read()&1;
	f[0][0]=1;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=1;j++){
			f[i][j]=0;
			for (int k=0;k<i;k++){
				f[i][j]+=f[k][j^a[i]];
			}
		}
	}
	LL ans=0;
	for (int i=0;i<=n;i++) ans+=f[i][p];
	cout << ans << endl;
	return 0;
}

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


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

  int x,y;
  cin >> x >> y;
  rep(i,x+1){
    if(i*2+(x-i)*4==y){
      cout <<"Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
    

}


Measured memory_bytes: 3652
n = int(input())

c = {
    "AC": 0,
    "WA": 0,
    "TLE": 0,
    "RE": 0
}

for i in range(n):
    s = input()
    c[s] += 1

print("AC x", c["AC"])
print("WA x", c["WA"])
print("TLE x", c["TLE"])
print("RE x", c["RE"])

Measured memory_bytes: 9192
N, X = map(int, input().split())
ans = N
a, b = sorted((X, N - X))
while a != 0:
    if b % a == 0:
        ans += 2 * (b // a - 1) * a
        break
    else:
        ans += 2 * (b // a) * a
        a, b = sorted((a, b % a))
print(ans + a)

Measured memory_bytes: 3060
#include<stdio.h>

int SelectionSort ( int *A, int N) {
	int C = 0;
	for( int i = 0; i < N; i++) {
		int minj = i;
		for( int j = i + 1; j < N; j++) {
			if(A[j] < A[minj]) {
				minj = j;
			}
		}
		if( minj != i){
			int temp = A[i];
		    A[i] = A[minj];
		    A[minj] = temp;
		    C++;
		}
	}
	return C;
}

int main() {
	int N;
	int A[100+10];
	scanf("%d", &N);
	for( int i = 0; i < N; i++) {
		scanf("%d",&A[i]);
	}
	int c = SelectionSort(A,N);
	for(int i = 0; i < N; i++) {
		printf("%d", A[i]);
		if(i != N - 1) printf(" ");
		else printf("\n");
	}
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 2720
n = gets.to_i
ff = []
n.times do
  ff << gets.split.map(&:to_i)
end

pp = []
n.times do
  pp << gets.split.map(&:to_i)
end

ans = -Float::INFINITY
(0..1023).each do |i|
  cnt = 0
  flg = false
  ff.each.with_index do |f,j|
    f = f.join.to_i(2)
    tmp = (i & f).to_s(2).count("1")
    cnt += pp[j][tmp]
    flg = true if tmp != 0
  end
  ans = [ans, cnt].max if flg
end

puts ans


Measured memory_bytes: 1916
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> s)
{
    if (s.size()> N)
    {
        
        int now = 0;
        for (int m = 0; m < Q; m++)
        {
            if (s[b[m]] - s[a[m]] == c[m])now += d[m];
        }
        ans = max(now, ans);
        //
        //for(int f=0;f<s.size();f++){
        //cout << s[f]<< " ";
        //}
        //cout <<ans<<endl;
        //
        return;
    }
    ////
    //for(int f=0;f<s.size();f++){
    //    cout << s[f]<< " ";
    //}
    //cout << endl;
    //
    s.push_back(s.back());
    while(s.back()<=M){
        dfs(s);
        s.back()++;
    }
}

int main(void)
{
    cin >> N >> M >> Q;
    b=vector<int>(Q);
    a=vector<int>(Q);
    c=vector<int>(Q);
    d=vector<int>(Q);
    for (int k = 0; k < Q; k++)
    {
        int n, l, p;
        cin >> n >> l >> c[k] >> d[k];
        a[k] = n;
        b[k] = l;
    }
    vector<int> ax(1,1);
    dfs(ax);
    cout <<ans <<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int n, x;
	scanf("%d%d", &n, &x);
	int count = 1;
	int sum = 0;
	rep(i, n)
	{
		int temp;
		scanf("%d", &temp);
		sum += temp;
		if (sum <= x)
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 3776
def main():
    A, B, C, D = map(int, input().split())

    attack_count_A = C // B
    if C % B > 0:
        attack_count_A += 1
    
    attack_count_B = A // D
    if A % D > 0:
        attack_count_B += 1

    if attack_count_B >= attack_count_A:
        print('{}'.format('Yes'))
    else:
        print('{}'.format('No'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
import java.util.*;

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

        int N = sc.nextInt();
        int A = sc.nextInt();

        if(N % 500 <= A){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<double>data(n);
  for(int i = 0;i < n;i++){
    double p;
    cin >> p;
    if(i != 0) data[i] = data[i-1]+(p+1)/2;
    else data[i] = (p+1)/2;
  }
  double max = data[k-1];
  for(int i = k;i < n;i++){
    if(data[i]-data[i-k] > max) max = data[i]-data[i-k];
  }
  cout << fixed;
  cout << setprecision(8) << max << endl;;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;

int main(void) {
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL);
  //freopen("in.txt", "r", stdin);
  int n;
  cin >> n;
  bool isOdd = false;
  if(n%2) {
    isOdd = true;
    n--;
  }
  vector<pair<int, int>> ret;
  vector<pair<int, int>> v;
  rep(i,1,n/2 + 1) {
    v.pb(mp(i, n - i + 1));
  }
  rep(i,0,sz(v)) {
    rep(j,i+1,sz(v)) {
      ret.pb(mp(v[i].F, v[j].F));
      ret.pb(mp(v[i].F, v[j].S));
      ret.pb(mp(v[i].S, v[j].F));
      ret.pb(mp(v[i].S, v[j].S));
    }
  }
  if(isOdd) {
    rep(i,1,n+1) {
      ret.pb(mp(i, n+1));
    }
  }
  cout << sz(ret) << endl;
  rep(i,0,sz(ret)) {
    cout << ret[i].F << ' ' << ret[i].S << endl;
  }

  return 0;
}

Measured memory_bytes: 384
s=input()
n=len(s)
list=["A","C","G","T"]
new=[]
a=0
for i in range(n):
  if s[i] in list:
    a+=1
    if i == n-1:
      new.append(a)
  if s[i] not in list:
    new.append(a)
    a=0
print(max(new))


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

long op(long x,long y) {
  x=max(x,y);
  return x;
}
long e() {
  return 0;
}

int main() {
  long n,k,ans=0;
  cin >> n >> k;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  segtree<long,op,e> seg(300001);
  cin >> a[0];
  for(long i=0;i<n;i++) {
    seg.set(a[i],1+seg.prod(max(0L,a[i]-k),min(300001L,a[i]+k+1)));
    ans=max(ans,seg.get(a[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 16236
n=int(input())
dp=[[0]*3 for _ in range(n)]
dp[0]=list(map(int,input().split()))
for i in range(1,n):
  a,b,c=map(int,input().split())
  dp[i][0]=a+max(dp[i-1][1],dp[i-1][2])
  dp[i][1]=b+max(dp[i-1][0],dp[i-1][2])
  dp[i][2]=c+max(dp[i-1][0],dp[i-1][1])
print(max(dp[n-1]))

Measured memory_bytes: 22772
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

void Main() {
    // input
    u_int32_t N, K;
    cin >> N >> K;
    vector<u_int32_t> monsters(N);

    for (u_int32_t i = 0; i < N; i++) {
        cin >> monsters[i];
    }

    u_int64_t count = 0;
    sort(monsters.begin(), monsters.end());
    
    // process
    while (!monsters.empty()) {
        if (K > 0) {
            K--;
            monsters.pop_back();
        } else {
            count += monsters.back();
            monsters.pop_back();
        }
    }


    // output
    cout << count << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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


    #define s scanf
    #define p printf
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define tmax(a, b, c) max(max(a, b), c)

    using namespace std;

    const int INF = 1e9;
    const long long LINF = 1e18+5;
    const double eps = 0.0000001;
    fstream fin, fout;
    typedef pair<int, int> ii;
    typedef vector<ii> vii;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<char> vc;
    typedef vector<vector<int> > vvi;
    typedef vector<ll> vll;

    int main(){
    int n; cin >> n;
    vll q(n); for(ll &i : q) cin >> i;
    sort(all(q));
    vll d, t;
    ll suma = 0, sumb = 0;
    int i = 0, j = n - 1;
    while(i < j){
        d.pb(q[i]); d.pb(q[j]);
        t.pb(q[j--]); t.pb(q[i++]);
    }
    if(n % 2){
        d.pb(q[i]); t.pb(q[i]);
    }
    for(int i = 1; i < n; i++)
    {
        suma+= abs(d[i] - d[i-1]);
        sumb+= abs(t[i] - t[i-1]);
    }
        suma = max(suma - abs(d[n-1] - d[n-2]) + abs(d[n-1] - d[0]), suma);
        sumb = max(sumb - abs(t[n-1] - t[n-2]) + abs(t[n-1] - t[0]), sumb);
    cout << max(suma, sumb);
    }


Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const long long INF=1e18;

template <class A, class B> ostream& operator<<(ostream& os, const pair<A,B> p) {return os << "(" << p.first << "," << p.second << ")";} 

void dprint(string s) { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0,w) << ": " << t << "] "; dprint(s.substr(w+1, (int)s.size()-w), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e6+5; // Don't forget to CHANGE this value ACC. TO Q.

int32_t main()
{
    IOS;
    int n,W; cin>>n>>W;
    int wt[n+1], val[n+1];
    for(int i=1;i<=n;i++)
        cin>>wt[i]>>val[i];
    int dp[n+1][W+1]={};
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(j-wt[i]>=0)
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-wt[i]]+val[i]);
            else 
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W];
    return 0;
}

Measured memory_bytes: 82548
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	listV := make([]int, n)
	listC := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listV[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&listC[i])
	}
	x := 0
	y := 0
	for i := 0; i < n; i++ {
		if listV[i] > listC[i] {
			x += listV[i]
			y += listC[i]
		}
	}
	fmt.Println(x - y)

}


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

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<int> nums;
    if (S[0] == '0')
        nums.push_back(0);
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i])
            j++;
        nums.push_back(j - i);
        i = j;
    }

    if (S.back() == '0')
        nums.push_back(0);
    vector<int> sum(nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); i++) {
        sum[i + 1] = sum[i] + nums[i];
    }

    int res = 0;
    for (int left = 0; left < sum.size(); left += 2) {
        int right = left + 2 * K + 1;
        if (right >= sum.size())
            right = sum.size() - 1;
        res = max(res, sum[right] - sum[left]);
    }

    cout << res << endl;
}

Measured memory_bytes: 1272
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int a[200010];
signed main() {
    int n, t; cin >> n >> t;
    rep(i,0,n) cin >> a[i];
    a[n] = 1e15;
    int ans = 0;
    repq(i,1,n) ans += min(t, a[i] - a[i-1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792