akhauriyash/Code-Regression huggingface dataset:
# 2020/05/07
# AtCoder Grand Contest 013 - A

# Input
n = int(input())
a = list(map(int,input().split()))

# Calc
cnt = 1
dr = 0
sav = a[0]
for i in range(1, n):
    # Initial Status
    if dr == 0:
        # Increase
        if sav < a[i]:
            dr = 1
        # Decrease
        elif sav > a[i]:
            dr = -1
    # Case Increase
    elif dr == 1:
        if sav > a[i]:
            cnt = cnt + 1
            dr = 0
    # Case Decrease
    elif dr == -1:
        if sav < a[i]:
            cnt = cnt + 1
            dr = 0
    sav = a[i]

ans = cnt

# Output
print(ans)


Measured memory_bytes: 14252
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF) for _ in range(n+1)]
for i in range(1, n+1):
    for j in range(i//2-1, (i+1)//2+1):
        if j == 1:
            dp[i][j] = max(dp[i-1][j], A[i-1])
        elif 0 <= i-2 and 0 <= j <= m:
            dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+A[i-1])
print(dp[-1][m])

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> x(n), y(n);
  REP(i,n) cin >> x[i] >> y[i];
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  
  map<pair<int, int>, int> mp;
  REP(i,n) FOR(j,i+1,n){ 
    mp[{x[i]-x[j], y[i]-y[j]}]++;
    mp[{x[j]-x[i], y[j]-y[i]}]++;
  }
  
  int ans = 0;
  for(auto p: mp){
    ans = max(ans, p.second);
  }
  ans = n-ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
//WA
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define Stand 8000

int main() {
  char s[8005];
  int x, y;
  scanf("%s%d%d", s, &x, &y);
  int v[2][16001] = {}, h[2][16001] = {}, len = strlen(s), k = 0, cntT = 0, cntF = 0, stv = 0, sth = 0;
  s[len] = 'T';
  while (s[k] == 'F')
    k++;
  v[0][Stand+k] = 1;
  h[0][Stand] = 1;
  for (; k<=len; k++) {
    if (s[k] == 'T') {
      if (cntT%2) {
        for (int i=0; i<16001; i++) {
          if (i >= cntF && h[sth][i - cntF])
            h[(sth + 1) % 2][i] = 1;
          else if (i < 16001 - cntF && h[sth][i + cntF])
            h[(sth + 1) % 2][i] = 1;
          else
            h[(sth + 1) % 2][i] = 0;
        }
        sth++;
        sth %= 2;
      } else {
        for (int i=0; i<16001; i++) {
          if (i >= cntF && v[stv][i - cntF])
            v[(stv + 1) % 2][i] = 1;
          else if (i < 16001 - cntF && v[stv][i + cntF])
            v[(stv + 1) % 2][i] = 1;
          else
            v[(stv + 1) % 2][i] = 0;
        }
        stv++;
        stv %= 2;
      }
      cntT++;
      cntF = 0;
    } else {
      cntF++;
    }
  }
  if (h[sth][Stand+y] && v[stv][Stand+x])
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
int n;
priority_queue<double,vector<double>,greater<double> > q;
int main( ){
	double x,y,z,k;
	n=read( );
	for(register int i=1;i<=n;++i){
		scanf("%lf",&x);
		q.push(x);
	}
	while(q.size( )>1){
		x=q.top( );q.pop( );
		y=q.top( );q.pop( );
		q.push((x+y)/2.0);
	}
	printf("%.7lf\n",q.top( ));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
 
ll mod = 1e9+7;
 
ll max(ll a, ll b ) {
	if(a>b)
		return a;
	else return b;
}
ll min(ll a, ll b ) {
	if(a<b)
		return a;
	else return b;
}
ll MAXN = 1e6+10;
vector<ll> spf;
void sieve() 
{ 
    spf[1] = 1; 
    for (int i = 2; i < MAXN; i++) spf[i] = i; 
  
        // Marking smallest prime factor for every 
        // number to be itself 
         
  
    // Separately marking spf for every even 
    // number as 2 
    for (int i = 4; i < MAXN; i += 2) spf[i] = 2;  
        
  
    // Checking if i is prime 
    for (int i = 3; i * i < MAXN; i++) { 
  
        // Marking SPF for all numbers divisible by i 
        if (spf[i] == i) { 
            for (int j = i * i; j < MAXN; j += i) {
  
                // Marking spf[j] if it is not 
                // previously marked 
                if (spf[j] == j) spf[j] = i; 
			}
        } 
    } 
} 

int main() {
	ll ttt;
	//cin>>ttt;
	ttt = 1;
	while(ttt--) {
		ll n; cin>>n;
		ll a[n]; for(int i=0; i<n; i++) cin>>a[i];
		spf.assign(MAXN+1,0);
		map<ll,ll> m;
		//ll ct = 0;
		sieve();
		for(int i=0; i<n; i++) {
			ll x = a[i];
			ll temp;
			map<ll,ll> vis;
			while (x != 1) { 
				temp = spf[x]; 
				if (x % temp == 0) { 
		
					if(vis[spf[x]]==0) { m[spf[x]]++; vis[spf[x]] = 1;} 
					x = x / spf[x]; 
				} 
				while (x % temp == 0) 
					x = x / temp; 
			} 
		}
		int flag = 0;
		for(auto it = m.begin(); it!=m.end(); it++) {
			if(it->se>1) flag = 1;
		}
		if(flag==0) cout<<"pairwise coprime";
		else {
			ll x = a[0];
			for(int i=1; i<n; i++) {
				x = __gcd(x,a[i]);
			}
			if(x==1) cout<<"setwise coprime";
			else cout<<"not coprime";
		}

	}
	return 0;
}


Measured memory_bytes: 23660
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL;
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){ 
    int n;cin>>n;
    int odd=0,even=0;
    rep(i,0,n){
        int x;cin>>x;
        (x%2)?odd++:even++;
    }
    if(odd%2==1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

    return 0;
}


/*
3 3 3 4 4
3 3 4 4 4
3 3 3 3 3

*/


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

string s;
int main() {
	cin >> s;
	for(int i=0; i<s.size()-1; i++) {
		if(s[i]=='A' && s[i+1]=='C') return puts("Yes"), 0;
	}
	puts("No");
	return 0;
}


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

int sort(string &text){
  bool isend = true;

  while(isend){
    bool swap = false;
    for (int i = 0; i < text.size() -1 ; i++){
      char a0 = text.at(i);
      char a1 = text.at(i + 1); 
  
      if (a0 > a1){
        text.at(i) = a1;
        text.at(i + 1) = a0;
        swap = true;
      }
    }
    if (swap){
      isend = true;
    }
    else{
      isend = false;
    }
  }
}

int sortr(string &text){
  bool isend = true;

  while(isend){
    bool swap = false;
    for (int i = 0; i < text.size() -1 ; i++){
      char a0 = text.at(i);
      char a1 = text.at(i + 1); 
  
      if (a0 < a1){
        text.at(i) = a1;
        text.at(i + 1) = a0;
        swap = true;
      }
    }
    if (swap){
      isend = true;
    }
    else{
      isend = false;
    }
  }
}


bool cond1(string s, string t){
  bool james = false;
  
  if(s.size() < t.size()){
    james = true;
  }
  else{
    return james;
  }
 
  for (int i = 0; i < s.size(); i++){
    if (s.at(i) == t.at(i)){
      james = true;
    }
    else{
      james = false;
    }
  }
  return james; 
}


bool cond2(string s, string t){
  bool james = false;
  int a;
  for (int i = 0; i < min(s.size(), t.size()); i++){
    if(s.at(i) != t.at(i)){
      a = i;
      break;
    }
  }
  if(s.at(a) < t.at(a)){
    james = true;
    return james;
  }
  else{
    return james;
  }
}


int main() {
  string x, y;
  cin >> x >> y;
  sort(x);
  sortr(y);
  
  if (cond1(x, y) || cond2(x, y)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int t1,n1,t2,n2,t3,n3,t4,n4;
  int s1,s2,s3,s4;
  scanf("%d %d %d %d %d %d %d %d",&t1,&n1,&t2,&n2,&t3,&n3,&t4,&n4);

  if(t1==1) s1=n1*6000;
  else if(t1==2) s1=n1*4000;
  else if(t1==3) s1=n1*3000;
  else if(t1==4) s1=n1*2000;
  if(t2==1) s2=n2*6000;
 else if(t2==2) s2=n2*4000;
 else if(t2==3) s2=n2*3000;
 else if(t2==4) s2=n2*2000;
  
  if(t3==1) s3=n3*6000;
 else if(t3==2) s3=n3*4000;
 else if(t3==3) s3=n3*3000;
 else if(t3==4) s3=n3*2000;
  
  if(t4==1) s4=n4*6000;
 else if(t4==2) s4=n4*4000;
 else if(t4==3) s4=n4*3000;
 else if(t4==4) s4=n4*2000;


  printf("%d\n",s1);
  printf("%d\n",s2);
  printf("%d\n",s3);
  printf("%d\n",s4);

  return 0;
}

Measured memory_bytes: 600
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private long sum(int m, List<long[]> l) {
		long x1 = 0, y1 = 0, z1 = 0;
		long x2 = 0, y2 = 0, z2 = 0;
		for (int i = 0; i < m; i++) {
			long[] a1 = l.get(i);
			x1 += a1[0];
			y1 += a1[1];
			z1 += a1[2];

			long[] a2 = l.get(l.size() - i - 1);
			x2 += a2[0];
			y2 += a2[1];
			z2 += a2[2];

		}
		return Math.max(
				Math.abs(x1) + Math.abs(y1) + Math.abs(z1),
				Math.abs(x2) + Math.abs(y2) + Math.abs(z2));
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		List<long[]> l = new ArrayList<>();

		for (int i = 0; i < N; i++) {
			l.add(new long[] { sc.nextLong(), sc.nextLong(), sc.nextLong() });
		}

		// 正, 正, 正
		// 負, 負, 負
		l.sort((a, b) -> Long.compare(a[0] + a[1] + a[2], b[0] + b[1] + b[2]));
		long ans1 = sum(M, l);

		// 正, 正, 負
		// 負, 負, 正
		l.sort((a, b) -> Long.compare(a[0] + a[1] - a[2], b[0] + b[1] - b[2]));
		long ans2 = sum(M, l);

		// 正, 負, 正
		// 負, 正, 負
		l.sort((a, b) -> Long.compare(a[0] - a[1] + a[2], b[0] - b[1] + b[2]));
		long ans3 = sum(M, l);

		// 正, 負, 負
		// 負, 正, 正
		l.sort((a, b) -> Long.compare(a[0] - a[1] - a[2], b[0] - b[1] - b[2]));
		long ans4 = sum(M, l);

		long ans = Math.max(Math.max(ans1, ans2), Math.max(ans3, ans4));

		out.println(ans);

		sc.close();

	}

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

}


Measured memory_bytes: 29404
#!/usr/bin/env python3
import sys
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
A, B = map(int, input().split())
if em: sys.stdin = open('/dev/tty')
if A < 10 and B < 10:
  print(A*B)
else:
  print("-1")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define N 1000000
using namespace std;

int main(){
	int n,k,s=0,d=0;
	scanf(" %d %d", &n , &k);
	int a[N],h1,h2,h3,h4,h5,h6,h7,h8,h9,h10;
	int i=0;
	for(;n-i>11; i+=10){
		scanf(" %d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8,&h9,&h10);
		a[i]=h1; a[i+1]=h2; a[i+2]=h3; a[i+3]=h4; a[i+4]=h5;
		a[i+5]=h6;a[i+6]=h7; a[i+7]=h8; a[i+8]=h9; a[i+9]=h10;
		s +=(h1+h2+h3+h4+h5+h6+h7+h8+h9+h10)/k;
		d = max(max( max(h1, max(h2, h3)), max(h4, max(h5, d))),max( max(h6, max(h7, h8)), max(h9, h10)));
	}
	for(;i<n;i++){
		scanf(" %d", &h1);
		s += h1/k;
		d = max(d, h1);
		a[i] = h1;
	}
	
	int low=s-1,high,mid;
	high = min(1000000000,(d*n)/k);
	while(1){
		if(high-low <= 1) break;
		mid = (low+high)/2;
		int count=0, bef=0,bag,p;
		bool f = true;
		while(1){
			if(bef == n) break;
			if(count >= k){
				f = false;
				break;
			}
			bag = mid;
			for(p=bef;p<n;p++){
				if(bag >= a[p]) bag-=a[p];
				else break;
			}
			bef = p;
			count++;
		}
		if(f) high = mid;
		else low = mid;
	}
	
	printf("%d\n", high);	
	return 0;
}

Measured memory_bytes: 3624
# ITP_11_B
dice = input().split()
top_list =  [
    (-1, 2, 4, 1, 3, -1),
    (3, -1, 0, 5, -1, 2),
    (1, 5, -1, -1, 0, 4),
    (4, 0, -1, -1, 5, 1),
    (2, -1, 5, 0, -1, -3),
    (-1, 3, 1, 4, 2, -1)
]

for q in range(int(input())):
    top, front = [dice.index(s) for s in input().split()]
    print(dice[top_list[top][front]])
    


Measured memory_bytes: 5596
#include<stdio.h>
#define MAX 100
void Graph(int **);
void Clear();
void Jugde(int);

int A[MAX][MAX],JDGE[MAX],DWN[MAX],FLT[MAX];
int *B[MAX];
int N;
int time = 0;
int i,j;


//Aの初期化、出力
int main(){

  scanf("%d",&N);

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < N; i++){
    B[i] = A[i];
  }

  Graph(B);
  Clear();

  for(i = 0; i < N; i++){
    printf("%d %d %d\n",i+1,DWN[i],FLT[i]);
  }

  return 0;
}


//グラフ構築
void Graph(int **A){
  int u,k,v;

  for(i = 0; i < N; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j< k; j++){
      scanf("%d",&v);
      v--;
      A[u][v] = 1;
    }
  }
}


//訪問判定配列の初期化
void Clear(){
  int a;
  for(a = 0; a < N; a++){
    JDGE[a] = 0;
  }

  for(a = 0; a < N; a++){
    if(JDGE[a] == 0) Judge(a);
  }

}


//探索、再帰
void Judge(int a){
  int b;
  JDGE[a] = 1;
  DWN[a] = ++time;
  for(b = 0; b < N; b++){
    if(A[a][b] == 0) continue;
    if(JDGE[b] == 0) Judge(b);
  }
  JDGE[a] = 2;
  FLT[a] = ++time;
}

Measured memory_bytes: 636
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) ((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) ((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;


int main() {
	int A, B;
	cin >> A >> B;
	double C = (A + B) / 2.;
	int D = (int)(C + 0.5);
	cout << D << endl;

	
	return 0;
}

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

public class Main {
    
    public static boolean solve(String s){
    	int a=0,b=0,c=0;
    	for(int i=0;i<s.length();i++){
    	    char l = s.charAt(i);
    	    if(l=='a') a++;
    	    else if(l=='b') b++;
    	    else c++;
    	}
    	
    	
    	if(a==b) return -1<=a-c && a-c<=1;
    	if(a-b==1||b-a==1) return c==a || c==b;
    	return false;
    	
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String given = sc.next();
        
        System.out.println(solve(given) ? "YES" : "NO");
        
    }
}

Measured memory_bytes: 24228
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-10000000,min=2020202021,ans=0,sum=0;
    string s,t;
    cin >> n;
    VI a(n);
    rep(i,n){
        cin >> a[i];
	}
    rep(i,n){
        if(i+1==a[i]){
            ans++;
            if(i+2==a[i+1]){
                i+=1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        String a = sc.next();
        String b = sc.next();
        String result = "";
        if(a.equals("H")){
            if(b.equals("H")) result = "H";
            else if(b.equals("D")) result = "D";
        }else if(a.equals("D")){
            if(b.equals("H")) result = "D";
            else if(b.equals("D")) result = "H";
        }
        System.out.println(result);

    }

    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: 21204
#include <bits/stdc++.h>
using namespace std;
bool acgt(char c){
	return c=='A'||c=='G'||c=='C'||c=='T';
}
int main() {
	string s; cin >> s; s += ' ';
	int ans = 0, curr = 0; 
	for(int i = 0; i < s.length(); i++){
		if (acgt(s[i])) curr++, ans = max(ans, curr);
		else curr = 0;
	}
	cout << ans;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
now = 1
c = 0
p = set([1])
while True:
    if A[now-1] in p:
        print(-1)
        exit()
    p.add(A[now-1])
    c += 1
    if A[now-1] == 2:
        break
    now = A[now-1]
print(c)


Measured memory_bytes: 19124
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,k;
	cin>>a>>b>>k;
	if(a>k)
	cout<<a-k<<" "<<b;
	else if(a+b>k){
		cout<<0<<" "<<b+a-k;
		}
	else{
		cout<<0<<" "<<0;
		}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

#define X real()
#define Y imag()

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


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

const int N = 1e5 + 50;
const double EPS = 1e-8;
const long long mod = 1e9 + 7;

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




int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n , h[N];
    cin >> n;
    for(int i = 0; i < n; ++i)
            cin >> h[i];
    // state : pos
    // trans : dp[pos] = min(dp[pos - 1] , dp[pos - 2] )
    // base  : dp[0] = 0 , dp[1] = abs(h[1]-h[0]);
    int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int pos = 2; pos < n; ++pos)
            dp[pos] = min(dp[pos - 1] + abs(h[pos] - h[pos - 1])
                    , dp[pos - 2] + abs(h[pos] - h[pos - 2]));
    cout << dp[n - 1] << '\n';
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	char c = s[0];
	int cnt = 0;
	for (auto sc : s) {
		if (c != sc) {
			cnt++;
			c = sc;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3704
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  string S; int Q; cin >> S >> Q; int cnt=0;
  rep(i, Q){
    int T; cin >> T;
    if(T==1){
      cnt++; continue;
    }
    int F; string C; cin >> F >> C;
    if((F+cnt)%2){
      S.insert(0, C);
    }
    else S+=C;
  }
  if(cnt%2){
    reverse(S.begin(), S.end());
  }
 cout << S << endl; 
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int sz=1e5+9;
int n,m;
pair<int,int> p[sz];
long long ans;
vector<int> v[sz];


int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d %d",&p[i].x,&p[i].y);
        if(p[i].x>m) continue;
        v[m-p[i].x].push_back(p[i].y);
    }
    priority_queue<int> q;
    for(int i=m-1;i>=0;i--){
        while(!v[i].empty()){
            q.push(v[i].back());
            v[i].pop_back();
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/


signed main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0)cout << "Zero" << endl;
	else if (a > 0 || (b - a) % 2)cout << "Positive" << endl;
	else cout << "Negative" << endl;
	endre;
}

Measured memory_bytes: 256
R, C, K = map(int, input().split())
points_dict = dict()
for _ in range(K):
    r, c, v = map(int, input().split())
    points_dict[r * 30000 + c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] # dp[4][R+1][C+1]
index = 0
for i in range(1, R+1):
    for j in range(1, C+1):
        #移動
        for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
        if i * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v
"""
for i in range(4):
    print(i)
    print(*dp[i], sep = '\n')
"""
print(max((dp[i][R][C] for i in range(4))))


Measured memory_bytes: 368172
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin>>n;
    map<ll, ll> m;
    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin>>a;
        m[a]++;
    }
    ll ans = 0;
    for (auto k : m)
    {
        if (k.second % 2 != 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
static const int MAX_N = 10005;

struct UF {
  int par[MAX_N], rank[MAX_N];

  void init(int n) {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }

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

  int same(int x, int y) {
    return find(x) == find(y);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
};

struct edge {
  int from, to, c;
  edge(){}
  edge(int p1, int p2, int p3) {
    from = p1;
    to = p2;
    c = p3;
  }

  const bool operator<(const edge &r) const {
    return c < r.c;
  }
};

UF uf;
edge E[100005];

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

  int v, e;
  cin >> v >> e;
  uf.init(v);

  for (int i = 0; i < e; ++i) {
    int s, t, w;
    cin >> s >> t >> w;
    E[i] = edge(s, t, w);
  }
  sort(E, E + e);

  int ans = 0;
  for (int i = 0; i < e; ++i) {
    if (uf.same(E[i].from, E[i].to)) continue;
    uf.unite(E[i].from, E[i].to);
    ans += E[i].c;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3700
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


N, X, Y = MI()
cnt = [0] * N

for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        idx = min(j - i, abs(X - i) + abs(Y - j) + 1)
        cnt[idx] += 1

for c in cnt[1:]:
    print(c)


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

namespace ConsoleApp4 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int A = X[0];
            int B = X[1];

            if(A >= B * 2) {
                Console.WriteLine(A - B * 2);
            } else {
                Console.WriteLine(0);
            }

        }
    }
}


Measured memory_bytes: 13396
n=int(input())
p=n
yakusu=[]
for i in range(1,int(n**0.5)+1):
	if n%i==0:
		yakusu.append(i)
		if i!=n//i:
			yakusu.append(n//i)
p-=1
yakusu_1=[]
for i in range(1,int(p**0.5)+1):
	if p%i==0:
		yakusu_1.append(i)
		if i!=p//i:
			yakusu_1.append(p//i)
ans=len(yakusu_1)-1
for x in yakusu:
	r=n
	if x!=1:
		while r%x==0:
			r//=x
		if (r-1)%x==0:
			ans+=1
print(ans)

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

using namespace std;

int main()
{
	int num[100];
	int i, j;
	int min;
	int n;
	int ans = 0;
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> num[i];
	}
	
	for (i = 0; i < n; i++){
		min = i;
		for (j = i; j < n; j++){
			if (num[j] < num[min]){
				min = j;
			}
		}
		if (num[i] != num[min]){
			swap(num[i],num[min]);
			ans++;
		}
	}
	
	for (i = 0; i < n; i++){
		cout << num[i];
		if (i == n - 1){
			cout << "\n";
			cout << ans << "\n";
		}
		else cout << " ";
	}
	
	return (0);
}



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

namespace ABC148
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }
        
        public static void c()
        {
            long[] ab = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            long a = ab[0], b = ab[1];
            long ans = 1;
            bool flg = true;
            if(a == b)
            {
                Console.WriteLine(a);
                return;
            }
            var list = new List<long>();
            long a1 = a, b1 = b;
            while(flg)
            {
                if(a1 < b1)
                {
                    if(b1 % a1 == 0)
                    {
                        list.Add(a1);
                        flg = false;
                    }
                    else
                    {
                        b1 %= a1;
                        //Console.WriteLine("b1==" + b1);
                    }
                }
                else if(a1 > b1)
                {
                    if(a1 % b1 == 0)
                    {
                        list.Add(b1);
                        flg = false;
                    }
                    else
                    {
                        a1 %= b1;
                        //Console.WriteLine("a1==" + a1);
                    }
                }
            }
            
            long v = list[0];
            list.Add(a / v);
            list.Add(b / v); 
            foreach(var x in list)
            {
                ans *= x;
            }
            Console.WriteLine(ans);
            
        }
    }
}


Measured memory_bytes: 13396
n,m = input().split(' ')
n = int(n)
m = int(m)
dp = [float('inf')]*2**n
dp[0] = 0
for i in range(m):
    a,b = input().split(' ')
    a = int(a)
    b = int(b)
    ngo = 0
    for j in input().split(' '):
        ngo += 2**(int(j)-1)
    for j in range(2**n):
        if dp[j|ngo] > dp[j]+a:
            dp[j|ngo] = dp[j]+a
    
if dp[2**n-1] == float('inf'):
    print(-1)
    exit(0)
print(dp[2**n-1])

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<ll> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll mod;
typedef vector<vi> M;
inline M operator*(const M & a, const M &b){
	M c(a.size(), vi(b[0].size()));
	rep(i, c.size()) rep(j, c[0].size()){
		ll s = 0;
		rep(k, a[0].size()) s += (ll)a[i][k] * b[k][j] % mod;
		c[i][j] = s % mod;
	}
	return c;
}
inline M pow(M a, ll m){
	M res(a.size(), vi(a.size()));
	rep(i, a.size()) res[i][i] = 1;
	for(; m; m /= 2){
		if(m & 1) res = res * a;
		a = a * a;
	}
	return res;
}
void calc(ll &prev, ll a, ll b, ll n){
	ll ten = 1;
	for(ll i = a; i; i /= 10) ten = ten * 10 % mod;
	M m =
	{
		{1, 0, 0},
		{b, 1, 0},
		{0, 1, ten}
	};
	m = pow(m, n) * M({{1}, {a % mod}, {prev}});
	prev = m[2][0];
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	ll l, a, b; cin >> l >> a >> b >> mod;
	ll ans = 0;
	while(l){
		ll ten = 1;
		for(ll i = a; i; i /= 10) ten = ten * 10;
		ll m = min((ten - 1 - a) / b, l - 1) + 1;
		
		//dbg(a, b, l, m);
		
		calc(ans, a, b, m);
		a = a + b * m;
		l -= m;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  vector<string> v = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int q; cin >> q;
  while(q > 0) {
    q--;
    string s; cin >> s;
    vector<pair<int, int>> p;
    char now = s[0];
    int cnt = 1;
    for(int i=1;i<(int)(s.size());++i) {
      if(s[i] == now) {
        cnt++;
      } else {
        p.push_back({now-'0', cnt});
        now = s[i];
        cnt = 1;
      }
    }
    p.push_back({now-'0', cnt});
    string ans = "";
    for(int i=0;i<(int)(p.size())-1;++i) {
      if(p[i].first != 0 && p[i+1].first == 0) {
        ans.push_back(v[p[i].first][(p[i].second-1) % (int)(v[p[i].first].size())]);
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3160
n, k = map(int, input().split())

d = []
a = []
res = [0] * n

for i in range(k):
    d_tmp = int(input())
    a_tmp = list(map(int, input().split()))
    d.append(d_tmp)
    a.append(a_tmp)

for aa in a:
    for aaa in aa:
        res[aaa - 1] += 1

count = 0

for i in range(n):
    if res[i] == 0:
        count += 1

print(count)


Measured memory_bytes: 67852
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

void main() {
    string s;
    while ((s = readln.chomp) != null) {
        auto ab = s.split.map!(to!int).array;
        int a = ab[0], b = ab[1];

        writeln(gcd(a, b));
    }
}

Measured memory_bytes: 2332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp

#define MAXN 10005
#define MAXQ 505

int N;
int A[MAXN];

static bool lin(int x) {
    A[N] = x;
    int i = 0;
    while(A[i] != x) i++;
    return i != N;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    int q; cin >> q;
    int ans = 0;
    REP(i, q) {
        int a; cin >> a;
        if (lin(a)) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = 1000000000;
  rep(i, n-k+1){
    ans = min(ans, h[i+k-1] - h[i]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = (ll)1e9 + 7;
  string L;
  cin >> L;
  vector<ll> dp = {1, 0};
  for (ll i = 0; i < L.size(); ++i) {
    vector<ll> temp = {0, 0};
    if (L.at(i) == '1') {
      temp.at(0) = (dp.at(0) * 2) % mod;
      temp.at(1) = (dp.at(1) * 3 + dp.at(0)) % mod;
    }
    else {
      temp.at(0) = dp.at(0) % mod;
      temp.at(1) = (dp.at(1) * 3) % mod;
    }
    dp = temp;
  }
  ll ans = dp.at(0) + dp.at(1);
  ans %= mod;
  cout << ans << "\n";
}


Measured memory_bytes: 3764
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let blst = Array.to_list
      (Array.init (n-1) @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d) in
  let (_,ans) = List.fold_left
      (fun (bfr,ans) x -> (x,ans + (min bfr x)))
      (List.hd blst, 0) blst in
  Printf.printf "%d\n" (ans + (List.hd (List.rev blst)))

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    std::sort(a.begin(),a.end());
    lint ans=0;
    for(lint i=0;i<n;i++){
        for(lint j=i+1,k=j;j<n-1;j++){
            for(;k<n&&a.at(k)<a.at(i)+a.at(j);k++);
            ans+=k-j-1;
        }
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <cstddef>
#include <queue>
#include <math.h>
#include <cstdlib>
using namespace std;

int main()
{
    int N, K, k = 0;
    cin >> N >> K;
    vector<int> h(N);
    vector<long long> dp(N);
    const long long INF = 1LL << 60;
    for(int i = 0; i < N; i++)
    {
        cin >> h.at(i); 
        dp.at(i) = INF;
    }
    dp.at(0) = 0;
    for(int i = 1; i < N; i++)
    {
        k = min(K, i);
        for(int j = 1; j < (k + 1); j++)
        {
            dp.at(i) = min((dp.at(i - j) + abs(h.at(i) - h.at(i - j))), dp.at(i));
        }
    }
    cout << dp.at(N - 1) << endl; 
    return 0;
}

Measured memory_bytes: 1408
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[]args){
	Scanner sc = new Scanner(System.in);
    int K= sc.nextInt();
    int L=0;
    int ans=-1;
    if(K%7==0){
        L=9*K/7;
    }else{
        L=9*K;
    }

    int R=1;
    for(int i=1; i<L; i++){
        R =(R*10)%L;
        if(R==1){
            ans =i;
            break;
        }
      }
    System.out.println(ans);
    }
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2*(1e5 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int has[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}

bool ispalin(string s)
{
	string k = s;
	reverse(k.begin(),k.end());
	if(k == s)
	{
		return true;
	}

	return false;
}


signed main()
{
	speedrap
	int t;
	//cin>>t;
	t = 1;
	while(t--)
	{
		int x;
		cin>>x;
		int k1 = x/500;
		k1 *= 1000;
		x%=500;
		int k2 = (x/5)*5;
		cout<<k1+k2;
	}
}

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

int main()
  {
  string s;
  cin>>s;
  int len,c=0;
  len=s.length();
  for(int i=0;i<len/2;i++)
    {
    if(s[i]!=s[len-1-i])
      c++;
    }
  cout<<c;
  return 0;
  }
    
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int l1,l2;
int ans (int i,int j)
{
	if(i==l1 || j==l2)
	return 0;
	if(s[i]==t[j])
	return 1+ans(i+1,j+1);
	return max(ans(i+1,j),ans(i,j+1));
}
int dp[3005][3005];
int main()
{
	cin>>s>>t;
	l1 = s.size();
	l2 = t.size();
	for(int i=0;i<l1;i++)
	{
		for(int j=0;j<l2;j++)
		{
			if(s[i]==t[j])
			dp[i+1][j+1] = 1+dp[i][j];
			else
			dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
		}
	}
	string ans = "";
	int i=l1,j=l2;
	while(i!=0 && j!=0)
		{
			if(s[i-1]==t[j-1]){
				ans+=s[i-1];
				i--;
				j--;
			}
			else
			{
				if(dp[i][j-1] > dp[i-1][j])
				j--;
				else
				i--;
			}
		}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 38868
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;
int main() {
    cin >> n >> m;
    vector<int> x(m, 0);
    for(int i = 0; i < m; ++i) cin >> x.at(i);
    sort(x.begin(), x.end());
    vector<int> xx;
    for(int i = 0; i < m-1; ++i) {
        int cxx = x.at(i+1) - x.at(i);
        xx.push_back(cxx);
    }

    int xxlen = xx.size();
    sort(xx.begin(), xx.end(), greater<int>());
    long long sum = 0;
    for(int i = (n-1); i < xxlen; ++i) {
        sum += xx.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
  int H, n;
  cin >> H >> n;
  vector<int> dp(H + 1, INF); // dp[H]
  // dp[x] - minimum total cost to get value x
  dp[0] = 0;
  while(n--) {
    int value, cost;
    cin >> value >> cost;
    for(int i = 0; i <= H; i++) { // O(N*H)
      // dp[i] -> dp[i+value]
      int j = min(H, i + value);
      dp[j] = min(dp[j], dp[i] + cost);
    }
  }
  cout << dp[H] << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, LIM; scanf("%d %d", &N, &LIM);
  vector<ll> W(N), V(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &W[i], &V[i]);
  }
  vector<vector<ll>> dp(N + 5, vector<ll>(305, 0));
  ll diff_sum = 0;
  for (int i = 0; i < N; ++i) {
    ll diff = W[i] - W[0];
    for (int num = i; num >= 0; --num) {
      for (int j = diff_sum; j >= 0; --j) {
        dp[num + 1][j + diff] = max(dp[num + 1][j + diff],
                                    dp[num][j] + V[i]);
      }
    }
    diff_sum += diff;
  }

  ll ans = 0;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= diff_sum; ++j) {
      if (W[0] * i + j <= LIM) {
        ans = max(ans, dp[i][j]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
int n;
while(cin>>n){
int res=0;
for(int n1=0;n1<=9;n1++)
for(int n2=0;n2<=9;n2++)
for(int n3=0;n3<=9;n3++)
for(int n4=0;n4<=9;n4++)
if(n1+n2+n3+n4==n) res++;
cout<<res<<endl;
}
}

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

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

    if(n > 1){
        res += n * (n - 1) / 2;
    }

    if(m > 1){
        res += m * (m - 1) / 2;
    }

    cout << res << endl;
}

Measured memory_bytes: 256