akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a; i < b; i++)

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

	ll a = s.size();
	ll cnt = 0;
	rep(i, 0, a) {
		if (s[i] != t[i]) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
 
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
 
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main(void){
    ll A,B;
    cin>>A>>B;

    
    if (A!=0) A--; 

    vector<ll> bi(41);
    bi[0] = 1;
    for (int i=1;i<=40;i++) {
        bi[i] = bi[i-1] * 2;
    }

    vector<ll> Abit(41,0),Bbit(41,0);
    vector<ll> ansbit(41,0);
    for (int i=1;i<=40;i++) {
        ll nn = A/bi[i];
        ll mm = A%bi[i];
        Abit[i] = nn*bi[i]/2;
        if (mm >= bi[i]/2) Abit[i] += mm - bi[i]/2 + 1;
        nn = B/bi[i];
        mm = B%bi[i];
        Bbit[i] = nn*bi[i]/2;
        if (mm >= bi[i]/2) Bbit[i] += mm - bi[i]/2 + 1;

        ansbit[i] = (Bbit[i]-Abit[i]);
    }

    ll ans = 0;
    for (int i=1;i<=40;i++) {
        if (ansbit[i]%2!=0) {
            ans += bi[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let n:i64 = read();
    let k:i64 = read();
    if n % k == 0 {
	println!("0");
    }else {
	println!("1");
    }
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    ll a;
    cin >> a;
    cout << (a + a * a + a * a * a) << endl;
}


Measured memory_bytes: 3564
S = input()

sample = ["A", "C", "G", "T"]
result = [0] * len(S)
for i in range(len(S)):
    if S[i] in sample:
        if i == 0:
            result[i] += 1
        else:
            result[i] += 1 + result[i - 1]


print(max(result))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int bekimax = 1;
		    
		    for(int i = 2; i <= Math.sqrt(N); i++) 
		    {
		    	int beki = i * i;
		    	while( beki * i <= N ) 
		    	{
		    		beki = beki * i;
		    	}
		    	if( bekimax < beki ) 
		    	{
		    		bekimax = beki ;
		    	} 
		    }
		    System.out.println(bekimax);
		    
		    scanner.close(); }
		  }

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

signed main(void)
{
	string s;
	cin >> s;
	bool ok = false;
	if (s.substr(0, 4) < "2019")
		ok = true;
	else if (s.substr(0, 4) == "2019")
	{
		if (s.substr(5, 2) < "04")
			ok = true;
		else if (s.substr(5, 2) == "04")
			if (s.substr(8, 2) <= "30")
				ok = true;
	}
	if (ok)
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
	return 0;
}


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

using namespace std;

int main () {
    long long n; cin >> n;
    long long s = 0;
    for (long long i = 1; i <= n; i++) {
        s += i;
        if (s >= n) {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

k = inp[0]
a,b = inp
(a..b).each do |d|
  if(d%k == 0)
    puts "OK"
    exit
  end
end

puts "NG"

Measured memory_bytes: 14484
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

template<typename F>
struct FixPoint : F {
  FixPoint(F&& f) :F(forward<F>(f)) {}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f) {
  return FixPoint<F>{forward<F>(f)};
}

constexpr int MOD = 1e9 + 7; // 1e9 + 7

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<vector<int>> G(N);
  
  F0R(i, N-1) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  // 白のときのパターン数
  // - 黒のときのパターン数は1回しか使わないから、メモする必要はない
  vector<int> dp(N, -1);

  // v: 頂点
  // p: 親の頂点
  // b: 親は黒か
  auto result = MFP([&](auto dfs, int v, int p, bool b)->i64 {

    // 末端？
    if (G[v].size() <= 1) {
      if (G[v].size() == 0 || G[v][0] == p)
        return b ? 1 : 2;
    }

    i64 result = 1;

    // 白のときのパターン数
    if (dp[v] < 0) {
      for (auto c : G[v]) {
        if (c == p) continue;
        result = result * dfs(c, v, false) % MOD;
      }
      dp[v] = result;
    }
    else result = dp[v];

    // 黒のときのパターン数
    if (!b) {
      i64 rb = 1;
      for (auto c : G[v]) {
        if (c == p) continue;
        rb = rb * dfs(c, v, true) % MOD;
      }
      result += rb;
      if (result >= MOD) result -= MOD;
    }

    return result;
  })(0, -1, false);

  cout << result;
}
#endif


Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N + 1);
    vector<int> cnt[N];
    for(int i = 0;i < N + 1;i++) {
        int A;
        cin >> A;
        vec.at(i) = A;
        cnt[A - 1].push_back(i);
    }
    int left,right;
    for(int i = 0;i < N;i++) {
        if(cnt[i].size() == 2) {
            left = cnt[i].at(0);
            right = N - cnt[i].at(1);
        }
    }
    int all = left + right;
    COMinit();
    for(int i = 0;i < N + 1;i++) {
        if(i == 0) {
            cout << N << endl;
        }
        else {
            cout << mod(COM(N + 1,i + 1) - COM(all,i)) << endl;
        }
    }
}

Measured memory_bytes: 30464
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
string S[100010];
map<char,int> H;
map<map<char,int>,int> H2;

signed main(){
	cin>>N;
	REP(i,N){
		cin>>S[i];
	}
	REP(i,N){
		H.clear();
		REP(j,10){
			H[S[i][j]]++;
		}
		H2[H]++;
	}
	int ans=0;
	for(auto x:H2){
		ans+=x.second*(x.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, x, m, logn = 1, ans = 0;
  cin >> n >> x >> m;
  while ((1ll << logn) < n) logn++;
  vector<vector<ll>> nex(logn, vector<ll>(m, -1)), sum(logn, vector<ll>(m, 0));

  for (ll r = 0; r < m; ++r) nex[0][r] = r * r % m, sum[0][r] = r;

  for (int p = 0; p < logn - 1; ++p)
    for (int r = 0; r < m; ++r)
      nex[p + 1][r] = nex[p][nex[p][r]],
              sum[p + 1][r] = sum[p][r] + sum[p][nex[p][r]];

  for (int p = 0; p < logn; ++p)
    if (n & (1LL << p)) ans += sum[p][x], x = nex[p][x];

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 57196
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
Volume0-0027
=end

def wday(y,m,d)
  wd = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
  d = Time.new(y,m,d)
  return wd[d.wday]
end

class Main
  def initialize
    while STDIN.gets do
      m, d = $_.chomp.split.map{|x| x.to_i}
      if m==0 then
        break
      end

      puts wday(2004, m, d)
    end
  end
end

if $0 == __FILE__ then
  Main.new
end

Measured memory_bytes: 8492
n = int(input())
h = [int(x) for x in input().split(" ")]

dp = [0 for x in range(n)]
dp[1] = abs(h[0] - h[1])
for i in range(2,len(h)):
    dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))

print(dp[-1])

Measured memory_bytes: 13780
/*
01背包，超大容量
1维实现 dp[i]表示选出价值总和为i的物品占用的最小重量 
*/
#include<cstdio>
#include<algorithm>
#include<climits>
#define MAXN 105
#define MAXV 100000
#define INF (long long)1E15

int w[MAXN], v[MAXN];
long long dp[MAXV+5];
int n, c, ans;
int main(){
    for(int i = 1; i <= MAXV; i++) dp[i] = INF;
    scanf("%d%d", &n, &c);
    for(int i = 1; i <= n; i++)
        scanf("%d%d", &w[i], &v[i]);
    for(int i = 1; i <= n; i++)
        for(int j = MAXV; j >= v[i]; j--)
            dp[j] = std::min(dp[j], dp[j-v[i]]+w[i]);
    for(int i = MAXV; i >= 0; i--)
        if(dp[i] != INF && dp[i] <= c){
            ans = i;
            break;
        }
    printf("%d\n", ans);
}
 

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <initializer_list>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define repr(i,n) for(int i=int(n-1); i>=0; --i)
#define REP(i,m,n) for(int i=int(m), i##_len=(n); i<i##_len; ++i)
#define VV(T) vector<vector<T>>
#define co(P) cout << P << endl
#define ci(P) cin >> P
#define pb push_back
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
using d = double;

int main(){
  string S;
  cin >> S;
  rep(i,3) cout << S[i];
  cout << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int num[3],i,j;
  for(i=0;i<3;i++){
    scanf("%d",&num[i]);
  }
  for(i=0;i<2;i++){
    for(j=0;j<2-i;j++){
      if(num[j]>num[j+1]){
	int temp=num[j];
	num[j]=num[j+1];
	num[j+1]=temp;
      }
    }
  }
  for(i=0;i<3;i++){
    if(i)printf(" ");
    printf("%d",num[i]);
  }
  printf("\n");
  return(0);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void print_matrix(int mat[][3001],int n){
	from(i,n+1){
		from(j,n+1)cout<<mat[i][j]<<" ";
		cout<<endl;
	}
}
 
int32_t main()
{
    string a,b; cin>>a>>b;
	int n = b.length();
	int m = a.length();
	int mat[3001][3001]={0};
	int flag1=0,flag2=0;
	from(i,m){
		if((b[0]==a[i])||flag1){
			mat[1][i+1]=1;
			flag1=1;
		}
	}
	from(i,n){
		if((a[0]==b[i])||flag2){
			mat[i+1][1]=1;
			flag2=1;
		}
	}
	int ans =0 ;
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(a[j]==b[i]){
				mat[i+1][j+1] = 1+ mat[i][j]; 
			}
			else{
				mat[i+1][j+1] = max(mat[i+1][j],mat[i][j+1]);
			}
			ans = max(ans,mat[i+1][j+1]);
		}
	}
	// print_matrix(mat,n);
	string answer;
	int row = n , column = m ;
	while(row>0 && column>0){
		if(b[row-1]==a[column-1]){
			answer.pb(b[row-1]);
			// cout<<row<<" "<<column<<endl;
			row--; column--;
		}
		else{
			if(mat[row-1][column]>mat[row][column-1])row--;
			else column--;
		}
	}
	reverse(answer.begin(),answer.end());
	cout<<answer;
    return 0;
}

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

int main(){
    char s[4];
    cin >>s;
    sort(s,s+4);
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;

}


Measured memory_bytes: 256
def test():
    card = {"1":14,"13":13,"12":12,"11":11,"10":10,"9":9,"8":8,"7":7,"6":6,"5":5,"4":4,"3":3,"2":2}
    a,b = input().split()
    if card[a] == card[b]:
        print("Draw")
    elif card[a] > card[b]:
        print("Alice")
    elif card[a] < card[b]:
        print("Bob") 


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k>a)
    {
        k-=a;
        if(k>b)
        {
            k-=b;
            cout<<a-k;
        }
        else    
            cout<<a;
    }
    else
        cout<<k;
}


Measured memory_bytes: 3636
/* Author rumoisen */
/* created 2018/10/20 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    int a,b;
    cin>>a>>b;
    int ans=max(a+b,a*b);
    ans=max(ans,a-b);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

int candy(int i, int j, vector<vector<int>> field, int n) {//そこからゴールまでに獲得する最大の飴
    if (i == 1 && j == n - 1) { return field[1][n - 1]; }
    if (i == 1) { return field[i][j] + candy(i, j + 1, field, n); }
    if (j == n - 1) { return field[0][n - 1] + field[1][n - 1]; }
    return max(candy(i, j + 1, field, n), candy(i + 1, j, field, n)) + field[i][j];
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> field(2, vector<int>(n));
    REP(i, n) { cin >> field[0][i]; }
    REP(i, n) { cin >> field[1][i]; }
    cout << candy(0, 0, field, n) << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;

const greater <int> gt;
vvi vex;
vi lis;
int A[2000000];
int H[2000000];

void dfs(int i, int p) {
    vi::iterator indx = lower_bound(lis.begin(), lis.end(), A[i]);
    bool lst = indx == lis.end();
    int ind = indx - lis.begin();
    
    if(lst) lis.push_back(A[i]);
    else swap(A[i], lis[ind]);
    
    H[i] = lis.size();
    
    for(int r : vex[i])
        if(r != p)
            dfs(r, i);
    
    if(lst) lis.pop_back();
    else swap(A[i], lis[ind]);
    
    return ;
}

int main() {
    cin.tie(NULL) -> sync_with_stdio(false);
    int n; cin >> n;
    vex.resize(n);
    for(int i = 0; i < n; ++i)
        cin >> A[i];
        
    int u, v;
    for(int i = 1; i < n; ++i) {
        cin >> u >> v;
        vex[--v].push_back(--u);
        vex[u].push_back(v);
    }
    
    dfs(0, 0);
    for(int i = 0; i < n; ++i)
        cout << H[i] << '\n';
    
    return 0;
}

Measured memory_bytes: 33000
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 7;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

int n;
vector <int> g[N];
vector <int> nums[2];
int used[N], ans[N];

void dfs(int v, int pr = -1, int c = 0){
    nums[c].pb(v);
    for(int i = 0;i < g[v].size();i ++){
        int to = g[v][i];
        if(to == pr){
            continue;
        }
        dfs(to, v, !c);
    }
}

int main(){
    Speedforce
    //fop("", "")
    cin >> n;
    for(int i = 1;i < n;i ++){
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    int len1 = n / 3, len2 = n / 3;
    if(n % 3 == 1){
        len1 ++;
    }
    if(n % 3 == 2){
        len1++;
        len2 ++;
    }
    /*for(int i = 0;i < nums[0].size();i ++){
        cout << nums[0][i] << " ";
    }
    cout << endl;*/
    if(nums[0].size() > nums[1].size()){
        swap(nums[0], nums[1]);
    }
    if(len1 <= nums[0].size() && len2 <= nums[1].size()){
        for(int i = 0;i < len1;i ++){
            used[nums[0][i]] = 1;
        }
        for(int i = 0;i < len2;i ++){
            used[nums[1][i]] = 2;
        }
    }
    else{
        for (int i = 0; i < len1;i ++){
            used[nums[1][i]] = 1;
        }
        for (int i = len1; i < len1 + len2;i ++){
            used[nums[1][i]] = 2;
        }
    }
    int ans1 = 1, ans2 = 2, ans3 = 3;
    for(int i = 1;i <= n;i ++){
        if(!used[i]){
            ans[i] += ans3;
            ans3 += 3;
        }
        if(used[i] == 1){
            ans[i] += ans1;
            ans1 += 3;
        }
        if(used[i] == 2){
            ans[i] += ans2;
            ans2 += 3;
        }
    }
    for(int i = 1;i <= n;i ++){
        cout << ans[i] << " ";
    }
}


Measured memory_bytes: 43764
import sys
L,R = map(int,input().split())
mod = 2019
cnt = 0
ans = float('inf')
List = [False for i in range(2019)]
for i in range(L,R):
    for j in range(i+1,R+1):
        tmp = (i*j)%mod
        List[tmp] = True
        ans = min(tmp,L*R,ans)
        if cnt>=10**6 or all(List)==True:
            print(ans)
            sys.exit()
        cnt +=1
print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;


int main(){
    cout << fixed << setprecision(10);
    
    double R;
    cin >> R;
    
    cout << 2 * R * 3.14159265359;

    return 0;
}


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

int main() {
    int K;
    cin >> K;
    int Even;
    int Odd;
    if(K % 2 == 0 ) {
        Even = K / 2;
        cout << Even * Even << endl;
    }
    else if(K % 2 == 1) {
        Even = (K-1) / 2;
        Odd = (K+1) / 2;
        cout << Even * Odd << endl;
    }
    
}

Measured memory_bytes: 256
public class Main {

    static java.util.Scanner scan = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        String a = getLine()[0];
        String[] b = new String[]{
                "AAB","ABA","BAA","BBA","BAB","ABB"
        };
        boolean f = false;
        for(int i = 0;i<6;i++){
            if(b[i].equalsIgnoreCase(a)){
                f = true;
            }
        }
        System.out.println(f?"Yes":"No");
    }




    public static int[] getLineInts(){
        return java.util.stream.Stream.of(getLine()).mapToInt(Integer::parseInt).toArray();
    }

    public static String[] getLine(){
        return scan.nextLine().split(" ");
    }
}


Measured memory_bytes: 23252
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
MOD = 10 ** 9 + 7

if n == 1:
    print(0)
    sys.exit(0)

print((pow(10, n, MOD) - (pow(9, n, MOD) * 2) + pow(8, n, MOD)) % MOD)


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

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

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb push_back
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", " ;
	return out << "}" << endl;
}
template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}
int main(){
	ll k;
	cin >> k;
	int n=50;
	cout << n << endl;
	if(k<50){
		cout << n-1 + k * n;
		rep(i,n-1) cout << " 0";
		cout << endl;
		return 0;
	}

	ll base = k / n;
	k %= n;

	rep(i,n){
		if(i) cout << " ";
		if(i>2) cout << n - 1 + base - k;
		else{
			ll t = (k + i) / 3;
			cout << n - 1 + base + t * n -(k-t);
		}
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 256
n = int(input())
dp = [[0]*10 for i in range(10)]
su = 0
for i in range(1,n+1):
  a,b = str(i)[0],str(i)[-1]
  dp[int(a)-1][int(b)-1] += 1
for i in range(10):
  for j in range(10):
    su += dp[i][j]*dp[j][i]
print(su)

Measured memory_bytes: 9100
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int A[100100];
int B[100100];
int S[100100];

struct BIT {
    //1-indexed
    static const int MAX_N = 200200;
    int bit[MAX_N], n;

    void init(int N) {
        n = N;
        rep(i, MAX_N) {
            bit[i] = 0;
        }
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int N;

int inversion() {
    BIT bit;
    bit.init(200200);
    int res = 0;
    rep(i, N + 1) {
        res += i - bit.sum(S[i] + 100100);
        bit.add(S[i] + 100100, 1);
    }
    return res;
}

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    //ai>=canとなるiの個数>=N/2
    int can = 0;
    int cannot = 1100000000;
    while (cannot - can > 1) {
        int m = (can + cannot) / 2;
        rep(i, N) {
            if (A[i] >= m)B[i] = 1;
            else B[i] = -1;
        }
        S[0] = 0;
        rep(i, N) {
            S[i + 1] = S[i] + B[i];
        }
        if (inversion() <= (N * N + N) / 2 / 2)can = m;
        else cannot = m;
    }
    cout << can << endl;
}


Measured memory_bytes: 4096
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i in range(h):
    l = ' '
    for j in range(w):
        if s[i][j] == '#':
            l = '#'
        else:
            total = 0
            for l in range(max(0, i-1), min(h, i+2)):
                for m in range(max(0, j-1), min(w, j+2)):
                    total += s[l][m].count("#")
                l = str(total)
        print(l,end = '')
    print('')

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    int k;

    std::cin >> k;

    rep(i, k)
            std::cout
        << "ACL";
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
 
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


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

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class ASecurity {
public:

void solve(std::istream& cin, std::ostream& cout) {
    string s;
    cin >> s;
    _for(i,3)if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return;
    }
    cout << "Good"<<endl;

}
};


#undef int
int main() {
	ASecurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


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

long long int abs(long long int n, long long int k){
    if(n >= k){
        return n-k;
    } else{
        return k-n;
    }
}
int main(){
    long long int N, K;
    cin >> N >> K;

    if(N == K){
        cout << 0;
    }
    else if(N > K){
        long long int tmp = N%K;
        long long int tmp1 = abs(tmp, K);
        if(tmp > tmp1){
            cout << tmp1;
        } else{
            cout << tmp;
        }
    } else{
        long long int tmp = abs(N, K);
        if(tmp > N){
            cout << N;
        } else{
            cout << tmp;
        }
    }

}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
ans = 1
for i in a:
    if i % 2 == 0:
        if not(i % 3 == 0 or i % 5 == 0):
            ans = 0
if ans == 1:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl


template<class Integer>
class BinaryIndexedTree
{
private:
	ull maxSize_;
	vector<Integer> values_;
public:
	BinaryIndexedTree(ull maxSize) : maxSize_(maxSize), values_(maxSize_, 0) {}

	void update(ll index, Integer increment)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		while (index <= maxSize_)
		{
			values_[index - 1] += increment;
			index += index & -index;
		}
	}

	Integer query(ll index)
	{
		if (maxSize_ <= index)
		{
			throw invalid_argument("Index should be less than maxSize.");
		}
		++index;

		Integer res = 0;
		while (index > 0)
		{
			res += values_[index - 1];
			index -= index & -index;
		}
		return res;
	}
};
using bit = BinaryIndexedTree<ll>;

int solve() {
	ll n;
	cin >> n;
	vector<ll> as(n + 1);
	for (ll i = 0; i <= n; ++i) {
		cin >> as[i];
	}

	if (n == 0) {
		if (as[0] == 1) {
			cout << 1 << endl;
			return 0;
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	bit usable_counts(n * 2 + 1);
	usable_counts.update(0, 2);
	usable_counts.update(1, -2);

	ll curr_using_idx = 0;
	ll res = 1;
	for (ll i = 0; i <= n; ++i) {
		if (as[i] == 0) continue;

		ll a = as[i];
		while (a > 0) {
			if (curr_using_idx >= i) {
				cout << -1 << endl;
				return 0;
			}
			ll using_count = min(a, usable_counts.query(curr_using_idx));

			a -= using_count;
			res += (i - curr_using_idx) * using_count;

			usable_counts.update(curr_using_idx, -using_count);
			usable_counts.update(curr_using_idx + 1, using_count * 2LL);
			usable_counts.update(i, -using_count);
			while (curr_using_idx <= n && usable_counts.query(curr_using_idx) == 0) {
				++curr_using_idx;
			}
		}
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 5576
#include<stdio.h>
int main(){
  char c[2][3];
  scanf("%s",c[0]);
  scanf("%*c%s",c[1]);
  if(c[0][0]==c[1][2] && c[0][1]==c[1][1] && c[0][2]==c[1][0])
    puts("YES");
  else
    puts("NO");
  return 0;
}


Measured memory_bytes: 128
//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e6 + 5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi (2.0*acos(0))
#define M ((int)1e6 + 7)
#define MOD ((int)1e9 + 7)
#define NN ((int)1e6 + 7)
#define N ((int)2e5 + 7)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 29
#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/




typedef tree < pair < ll, pair < ll, ll > >,  null_type,  less < pair < ll, pair < ll, ll > > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).



int main()
{
    fastio;

    int n;

    cin>>n;

    int cnt = 0;

    for(int i = 1 ; i<=n ; i++){
        int a;
        cin>>a;
        cnt += a&1;
    }

    if(cnt&1) cout<<"NO\n";
    else cout<<"YES\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b, c; cin >> a >>b;
	//string s,t; cin >> s>>t;
	if (a == 1 || b == 1) {
		if (a == b)cout << "Draw";
		else {
			if (a == 1)cout << "Alice";
			else cout << "Bob";
		}
		return 0;
	}
	if (a<b)cout<< "Bob";
	else if (a>b)cout<< "Alice";
	else cout << "Draw";


	cout << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input().strip())
a = list(map(int, input().strip().split()))
na = [0]*1024
for x in a:
	na[x] += 1
sa = [0] * 1024
for i in range(1023):
	sa[i+1] = sa[i] + na[i]

ans = 0
for i in range(1, 1024):
	for j in range(i, 1024):
		mink = max(j, j-i+1)
		maxk = min(1022, i+j-1)
		if maxk < mink:
			continue

		if sa[maxk+1] == sa[mink]:
			continue

		if i != j:
			if mink != j:
				ans += na[i]*na[j]*(sa[maxk+1] - sa[mink])
			else:
				ans += na[i]*na[j]*(sa[maxk+1] - sa[mink+1]) + na[i]*na[j]*(na[j]-1)//2
		else:
			if mink != j:
				ans += na[i]*(na[j]-1)//2*(sa[maxk+1] - sa[mink])
			else:
				ans += na[i]*(na[j]-1)//2*(sa[maxk+1] - sa[mink+1]) + na[i]*(na[j]-1)*(na[j]-2)//6
print(ans)


Measured memory_bytes: 42480
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	vector<long long> a;
	long long i, j, k, l, m, n;

	cin >> n;
	a.resize(n);

	rep(i, n) {
		cin >> j;
		a[i] = j - 1 - i;
	}

	sort(a.begin(), a.end());

	if (n % 2 == 0) {
		l = 0;
		m = 0;
		rep(i, n) {
			l += abs(a[i] - a[n / 2]);
			m += abs(a[i] - a[n / 2 - 1]);
		}
		cout << min(l,m);
	}
	else {
		l = 0;
		rep(i, n) {
			l += abs(a[i] - a[n / 2]);
		}
		cout << l;
	}

	return 0;
}

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

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N, K;
	int h[123456];

	cin >> N >> K;
	for (int i = 0; i<N; i++) cin >> h[i];

	int dp[123456] = { 0 };

	dp[0] = 0;
	for (int i = 1; i < N; i++){
		dp[i] = INF;
		for (int k = 1; k <= K; k++)
			if (i-k>=0)
				dp[i] = min(dp[i], dp[i - k] + abs(h[i - k] - h[i]));
	}
	cout << dp[N - 1] << endl;

	return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <string.h>


int main(void) {

	// 1_8-D Ring
	// ????????°??¶???????????? s ???????????????????????????????¨????????????£?¶????????????????????????????????????§???
	// ????????? p ??????????????????????????????????????°??????
	
	char s[100];
	char s2[200];
	char p[100];

	// ????????? s ????????? p ???????????????
	gets(s);
	gets(p);

	strncpy(s2,s,100);
	strncat(s2,s,100);

	// ????????¨???
	if(strstr(s2,p)!=NULL && strlen(s)<=100 && strlen(p)<=strlen(s)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 524
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] array = sc.next().split("");
    int start =0;
    int first_A=0;
    int end =0;
    for(int i=0; i<array.length; i++){
    	if(array[i].equals("A") && first_A==0){
        	start=i;
            first_A=1;
        }
        if(array[i].equals("Z") && first_A !=0 ){
        	end =i;
        }
    }
    System.out.println(end - start + 1);
  }
}

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

 int main()
     {
    int n,c=0,m=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
       if(s[i]=='I')
        c++;
       else if(s[i]=='D')
        c--;
        m=max(c,m);
    }
    cout<<m;


   return 0;
     }


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>
#include <deque>

#define INF_LL 1e18
#define INF 1e9

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

typedef long long ll;

using namespace std;


int main() {
  string a, b, c;
  cin >> a >> b >> c;

  string ans;
  ans += a[0]; ans += b[0]; ans += c[0];
  transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
  cout << ans;

  return 0;
}



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

using i64 = int64_t;

class UnionFindTree {
  private:
    std::vector<int> par;   // 親
    std::vector<int> depth; // 木の深さ

  public:
    // n要素で初期化
    UnionFindTree(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
            depth.push_back(0);
        }
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

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

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) { return find(x) == find(y); }
};

int main(){
    i64 n, m;
    cin >> n >> m;
    vector<pair<i64, int>> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.emplace_back(a, i);
    }
    UnionFindTree uft(n);
    for(int i=0;i<m;++i){
        i64 x, y;
        cin >> x >> y;
        uft.unite(x, y);
    }
    set<int> st;
    for(int i=0;i<n;++i)st.insert(uft.find(i));
    if(n < 2*(st.size()-1)){
        cout << "Impossible" << endl;
        return 0;
    }

    if(st.size() == 1){
        cout << 0 << endl;
        return 0;
    }

    int num_connected = st.size();
    i64 ans = 0;

    map<int, i64> mp, mp2;
    for(int i=0;i<n;++i){
        int par = uft.find(i);
        if(mp.count(par) == 0 || mp[par] > v[i].first){
            mp[par] = v[i].first;
            mp2[par] = i;
        }
    }
    st.clear();
    for(auto e: mp2)st.insert(e.second);
    for(auto e: mp)ans += e.second;

    sort(v.begin(), v.end());
    for(auto e: v){
        if(st.size() >= 2*(num_connected-1))break;
        if(st.count(e.second))continue;
        st.insert(e.second);
        ans += e.first;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13680
// ※※※ 解答不能 ※※※
// https://img.atcoder.jp/panasonic2020/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _abs(x) ((x) > 0 ? (x) : -(x))

// 二点間を妨害するような黒マスの連結成分があるかを計算？
// @param x:  x座標(スタート地点).
// @param y1: y座標(スタート地点).
// @param y2: y座標(ゴール地点).
// @return : 妨害する黒マスの連結成分があるかどうか.
bool between(LL x, LL y1, LL y2){
    if(y1 > y2) swap(y1, y2);
    y1++, y2--;
    if(!(y1 <= y2)) return false;
    while(x > 0){
        if(x % 3 == 1){
            if(y2 - y1 > 3) return true;
            for(LL y = y1; y <= y2; y++) if(y % 3 == 1) return true;
        }
        x /= 3;
        y1 /= 3;
        y2 /= 3;
    }
    return false;
}

// 迂回する距離？を計算.
// @param x1: x座標(スタート地点).
// @param y1: y座標(スタート地点).
// @param x2: x座標(ゴール地点).
// @param y2: y座標(ゴール地点).
// @return : スタート地点からゴール地点までの迂回する距離を返却.
LL get_extra(LL x1, LL y1, LL x2, LL y2){
    LL ans = 0, three = 1;
    int i;
    rep(i, 35){
        if(x1 / three == x2 / three && between(x1 / three, y1 / three, y2 / three)){
            LL tmp = min(min(x1 % three, x2 % three) + 1, three - max(x1 % three, x2 % three));
            ans = max(ans, tmp);
        }
        three *= 3;
    }
    return ans;
}

// 二点間の距離を求める.
// @param x1: x座標(スタート地点).
// @param y1: y座標(スタート地点).
// @param x2: x座標(ゴール地点).
// @param y2: y座標(ゴール地点).
// @return : スタート地点からゴール地点までの距離を返却.
LL get_dist(LL x1, LL y1, LL x2, LL y2){
    return _abs(x1 - x2) + _abs(y1 - y2) + 2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}

int main(){
    
    // 1. 入力情報.
    int Q;
    scanf("%d", &Q);
    
    // 2. クエリに回答.
    rep(i, Q){
        LL a, b, c, d;
        scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
        a--, b--, c--, d--;
        printf("%lld\n", get_dist(a, b, c, d));
    }
    return 0;
    
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
   public static void main(String[]args){
      Scanner sc = new Scanner(System.in);
      final int x = sc.nextInt();//4
      int a = sc.nextInt();//5
      int b = sc.nextInt();//6
      int xa,xb;
      if(x>a){
         xa = x-a;
      }else{
         xa = a-x;//1

      }
      if(x>b){
         xb = x-b;
      }else{
         xb = b-x;//2
      }
      if(xa>xb){
         System.out.println("B");
      }else{
         System.out.println("A");
      }
   }
}

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())

    for i in range(1, 11):
        if i * 1000 >= n:
            return i * 1000 - n

    return


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9180