akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

ll solve(ll a)
{
    if (a == 1)
    {
        return 1;
    }
    return 2 * solve(a / 2) + 1;
}

int main()
{
    ll H;
    cin >> H;
    cout << solve(H);
    return 0;
}

Measured memory_bytes: 256
#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>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(max(a + b, a - b), a * b) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, a;
    int[] xs;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        a = sc.nextInt();
        xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        long[][][] dp = new long[n + 1][n + 1][50 * n + 1];
        dp[0][0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                for (int k = 0; k < 50 * n + 1; k++) {
                    if (j >= 1 && xs[i - 1] <= k) {
                        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - xs[i - 1]];
                    } else {
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                }
            }
        }
        long ans = 0;         
        for (int j = 1; j <= n; j++) {
            ans += dp[n][j][j * a]; 
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 83016
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
    
        List<String> array = new ArrayList<>();
        for (int i=0; i<N; i++) {
            array.add(String.valueOf(S.charAt(i)));
            array.add(String.valueOf(T.charAt(i)));
        }
        
        String result = String.join("", array);
        System.out.println(result);
    
    }
}

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

int main(){

  int N;
  cin >> N;
  
  int x = N / 1000;
  int y = N / 100 - 10 * x;
  int z = N / 10 - 100 * x - 10 * y;
  int w = N - 1000 * x - 100 * y -10 * z;
  
  if (x == y && y == z || y == z && z == w){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 3600
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
std::vector<int> g[1000000];
pii vis[1000000];
int v[1000000];
void solve()
{
	memset(v, -1, sizeof(v));
	vis[0].first = 0;
	rep(i, 1000000)
	vis[i].first = -1, vis[i].second = -1;

	int n, m;
	cin >> n >> m;
	rep(i, m)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	v[0] = 1;
	int cnt = 1;
	queue<int> q;

	for (auto E : g[0])
	{
		v[E] = 1;
		q.push(E);
		vis[E].first=1;
		vis[E].second=0;
	}
	cnt++;
	while (!q.empty())
	{
		int k = q.front();
		q.pop();
		for (auto e : g[k])
		{
			if (v[e] == -1)
			{
				q.push(e);
				v[e] = 1;
				vis[e].second=k;
			}
		}
	}

	for (int i = 1; i < n; i++)
	{
		if (vis[i].second == -1)
		{
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
	for (int i = 1; i < n; i++)
		cout << vis[i].second + 1 << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 42856
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)

using namespace std;

int main(void){
  unsigned long long int N,K,sum=0;
  cin >> N >> K;
  pair<int,int> num[N];
  rep(i,N) cin >> num[i].first >> num[i].second;
  sort(num,num+N);
  rep(i,N){
    sum+=num[i].second;
    if(sum>=K){
      cout << num[i].first << endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define w while
#define loop(i,l,r) for(int i=l;i<r;i++)
#define ci cin>>
#define co cout<<
#define mm 1000000007
#define ll long long
using namespace std;
int main()
 {  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    char a[n][m];
    int dp[n][m];
    loop(i,0,n){
      loop(j,0,m){
        ci a[i][j];
        dp[i][j]=0;
      }
    }
    dp[0][0]=1;
    for(int i=1;i<n;i++){
      if(a[i][0]=='.')
      dp[i][0]=dp[i-1][0];
        }
    loop(j,1,m){
      if(a[0][j]=='.'){
        dp[0][j]=dp[0][j-1];
      }
      }
       loop(i,1,n){
         loop(j,1,m){
           if(a[i][j]=='.'){
             dp[i][j]=(dp[i-1][j]%mm+dp[i][j-1]%mm)%mm;
           }
          }
       }
      cout<<dp[n-1][m-1];
    }


Measured memory_bytes: 5120
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M, P = map(int, input().split())

edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, -c+P])


def bellnabFord(edges, src, N):
    inf = float('inf')
    dist = [inf for i in range(N)]
    dist[src] = 0

    for i in range(2*N):
        for s, d, c in edges:
            if s != inf and dist[d] > dist[s]+c:
                dist[d] = dist[s]+c
                if i >= N:
                    dist[d] = -float('inf')

            if i == N-1:
                prev = dist[-1]
    return (prev, dist[-1])


prev, dist = bellnabFord(edges, 0, N)
if prev != dist:
    ans = -1
else:
    ans = max(0, -dist)
print(ans)


Measured memory_bytes: 46812
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}
function cost(X: number[], p: number): number {
  return X.map(x=>(x-p)*(x-p)).reduce((a,b)=>a+b);
}
function Main({ int, str, strs, ints }: NormalInput) {
  const N = int();
  const X = ints(N);
  let min: number | null = null;
  for (let p = 1; p <= 100; p++) {
    const thisCost = cost(X, p);
    min = min === null ? thisCost : Math.min(thisCost, min);
  }
  console.log(min);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, K; cin >>N>>K;

    map<int,int> counter;
    int A;
    rep(i, N) {
        cin >> A;
        counter[A]++;
    }

    vector<int> keys(counter.size());
    int i = 0;
    for (auto it = counter.begin(); it != counter.end(); it++, i++)
        keys[i] = it->first;
    sort(ALL(keys), [&](int x, int y){ return counter[x]<counter[y];});

    int ans = 0;
    int t = counter.size() - K;
    if (t > 0) {
        rep (i, t) {
            ans += counter[keys[i]];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int a[N];
  int state=0;
  int nam=0;
  for(int i=0;i<N;i++)
  {
    cin>>a[i];
    a[i]--;
  }
  while(state!=1)
  {
    if(nam>=N) break;
    state=a[state];
    nam++;  
  }
  if(nam>=N)
  {
    cout<<-1<<endl;
  } else {
    cout<<nam<<endl;
  }
}

Measured memory_bytes: 640
open Scanf

module MarketPrice = Map.Make (
                   struct
                     type t = string
                     let compare (a : string) b = compare a b
                   end)

module Recipe = MarketPrice

let compute_cheapest_price product market_prices recipes =
  let memo = Hashtbl.create (MarketPrice.cardinal market_prices) in
  let rec compute product =
    try Hashtbl.find memo product
    with Not_found ->
      let cheapest_price =
        let market_price = MarketPrice.find product market_prices in
        if not (Recipe.mem product recipes) then market_price
        else
          List.fold_left
            (fun price material -> price + (compute material))
            0 (Recipe.find product recipes)
          |> min market_price in
      Hashtbl.add memo product cheapest_price;
      cheapest_price in
  compute product

let read_lines n =
  let rec read_lines n acc =
    if n = 0 then List.rev acc
    else read_lines (pred n) ((read_line ())::acc) in
  read_lines n []

let split_list = Str.split (Str.regexp " ")

let rec solve () =
  let n = int_of_string (read_line ()) in
  if n = 0 then ()
  else begin
    let market_prices =
      List.fold_left
        (fun market_prices line ->
         sscanf line "%s %d"
                (fun product price ->
                 MarketPrice.add product price market_prices))
        MarketPrice.empty
        (read_lines n) in
    let m = int_of_string (read_line ()) in
    let recipes =
      List.fold_left
        (fun recipes line ->
         let open List in
         let columns = split_list line in
         let product, materials = hd columns, tl (tl columns) in
         Recipe.add product materials recipes)
        Recipe.empty
        (read_lines m) in
    print_int (compute_cheapest_price (read_line ()) market_prices recipes);
    print_newline ();
    solve()
  end

let () = solve ()

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0){
			sum+=i;
		}
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  set<string> st;
  rep(i, n){
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19064
#include<bits/stdc++.h>
#define N 20010
using namespace std;
int p[N],od[N];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d",&p[i]);
    od[p[i]]=i;
  }
  for(int i=1;i<=n;i++){
    printf("%d ", i*n);
  }
  puts("");
  for(int i=1;i<=n;i++){
    printf("%d ",(n-i+1)*n+od[i]);
  }
  puts("");
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include <string.h>
#include<iostream>
#include <cmath>

using namespace std;
int main(){

  int N;
  cin >>N;
  int a[N];
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum=sum+a[i];
  }
  double ave=(double)sum/(double)N;
  //  cout<<ave<<endl;

  int ans=0;
  double min_sub=101;
  for(int i=0;i<N;i++){
    if(min_sub>abs((double)a[i]-ave)){
      min_sub=abs((double)a[i]-ave);
      //      cout <<"min_sub:"<<min_sub<<endl;
      ans=i;
    }
  }


  cout<<ans<<endl;

  return 0;







}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 6e18;
const int mod = 1e9 + 7;

signed main() {
    int a, b;
    cin >> a >> b;
    string A, B;
    for (int i = 0 ; i < b; i++) A += to_string(a);
    for (int i = 0 ; i < a; i++) B += to_string(b);
    cout << min(A, B) << endl;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

int main(){

    int n;
    cin >> n;

    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for(auto iter = mp.begin(); iter != mp.end(); ++iter){
        ll tmp;
        tmp = iter->second;
        ans += tmp * (tmp - 1) / 2;
    }
    cout << ans << endl;

    return 0;
}

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

ll n, k;
vector<ll> a;
ll INF = (ll)(1e18)+1;

ll judge(ll x) {
  ll cnt = 0;
  rep(i, n) {
    if (a.at(i) < 0) {
      int l = -1;
      int r = n;
      while (r-l>1) {
        int c = (r+l)/2;
        if (a.at(i)*a.at(c)<x) r = c;
        else l = c;
      }
      cnt += n-r;
    }
    else {
      ll l = -1;
      ll r = n;
      while (r-l>1) {
        int c = (r+l)/2;
        if (a.at(i)*a.at(c)<x) l = c;
        else r = c;
      }
      cnt += r;
    }
    if (a.at(i)*a.at(i)<x) cnt--;
  } 
  cnt /= 2;
  return cnt;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());

  ll l = -INF;
  ll r = INF;
  while (r-l>1) {
    ll c = (r+l)/2; 
    if (judge(c)<k) l = c;
    else r = c;
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 1792
n = gets.to_i
a = gets.split.map(&:to_i).sort
if a[1] >= 0
    s = a[0]
    ans = a.inject(:+)-2*a[0]
    puts ans
    (1..(n-2)).each do |i|
        puts "#{s} #{a[i]}"
        s -= a[i]
    end
    puts "#{a[-1]} #{s}"
else
    j = -1
    n.times do |i|
        if a[i] >= 0
            j = i
            break
        end
    end
    if j == -1
        ans = -a.inject(:+)+2*a[-1]
        puts ans
        s = a[-1]
        (0..(n-2)).each do |i|
            puts "#{s} #{a[i]}"
            s -= a[i]
        end
    else
        ans = -a[0...j].inject(:+)+a[j...n].inject(:+)
        puts ans
        s = a[0]
        (j..(n-2)).each do |i|
            puts "#{s} #{a[i]}"
            s -= a[i]
        end
        a[0] = s
        t = a[-1]
        j.times do |i|
            puts "#{t} #{a[i]}"
            t -= a[i]
        end
    end
end

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

int n;

int dp[100010][4];
int mat[100010][4];
bool vis[100010][4];

int func( int pos, int last = 0 ) {
  if ( pos > n ) return 0;
  if (vis[pos][last]) return dp[pos][last];
  vis[pos][last] = 1;
  int mx = 0;
  for (int i = 1; i <= 3; ++i) {
    if (last != i)
      mx = max(mx, mat[pos][i] + func( pos + 1, i ));
  }
  return dp[pos][last] = mx;
}

int main() {

  cin >> n;
  for (int i = 1; i <= n; ++i) 
    for (int j = 1; j <= 3; ++j) 
      cin >> mat[i][j];

  cout << func(1) << endl;
  return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
	ll n,m;
	cin >>n>>m;
	if(n==m)cout <<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static long INF = 1L << 60;
	static long[] h;// = new long [100010];
	static long[] dp;// = new long [100100];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		h = new long [100010];
		dp = new long [100100];
		for(int i=0;i<n;i++)h[i] = Long.parseLong(sc.next());
		sc.close();
		//初期化(INF)
		Arrays.fill(dp,INF);
		dp[0] = 0;

		for(int i=1;i<n;i++) {
			 for (int j = 1; j <= k&&j<=i; j++) {
				 	dp[i]=chmin(dp[i], dp[i-j] + Math.abs(h[i] - h[i - j]));
		        }
		}
		System.out.println(dp[n-1]);

	}
	private static long chmin(long a, long b) {
		if (a > b) { a = b; return a; } return a;
	}

}


Measured memory_bytes: 45600
#include<stdio.h>
#define INF 10000000
static const int N = 100;

int min(int a, int b){
  return a < b ? a : b; 
}

int main(){

  int i, j, k, l, q;
  int n, p[N+1], m[N+1][N+1];

  scanf("%d", &n);
  
  for ( i = 1; i <= n; i++ ){
    scanf("%d %d", &p[i-1], &p[i]);
  }
  
  for ( i = 1; i <= n; i++ ){
    m[i][i] = 0;
  }
  
  for ( l = 2; l <= n; l++ ){
    for ( i = 0; i <= n-l+1; i++ ){
      j = i+l-1;
      m[i][j] = INF;
      for ( k = i; k <= j-1; k++ ){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j], q);
      }
    }
  }
  
  printf("%d\n", m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
#define PI 3.1415927
int main()
{
	long long i,j,n,ans=0;
	cin>>n;
	for(i=sqrt(n);i>=1;i--)
	{
		j = n / i;
		if(i*j==n)
		{
			ans = i + j -2;
			break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
int gcd(int a, int b) {
  if (a == 0) return b; else return gcd(b % a, a);
}
int main() {
  int a, b, m, n;
  while (scanf("%d %d", &a, &b) != EOF) {
    m = gcd(a, b); n = a / m * b;
    printf("%d %d\n", m, n);
  }
  return 0;
}

Measured memory_bytes: 596
#ABC149B
def main():
    import sys, math
    A, B, K = map(int, sys.stdin.readline().split())
    #print(A, B, K)
    if A>=K:
        print(A-K, B)
    else:
        print(0, max(B-(K-A), 0))
   

if __name__=='__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	int s = 100000;
	for(int i = 0 ; i < n ; i++)
		s = (s*105/100+999)/1000*1000;
	cout << s << endl;
}

Measured memory_bytes: 1160
S = input()


# 上2ケタ
if 0 < int(S[:2]) <= 12:
    temp = "both"
else:
    temp = "YY"
    
if 0 < int(S[2:4]) <= 12:
    temp2 = "both"
else:
    temp2 = "YY"
    
if temp == "both" and temp2 == "both":
    print("AMBIGUOUS")
elif temp == "both" and temp2 == "YY":
    print("MMYY")
elif temp == "YY" and temp2 == "both":
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

typedef pair<int,int> P;

int main() {
  int dx[] = {0,1,0,-1};
  int dy[] = {-1,0,1,0};
  
  int n,m;
  while(cin >> n >> m,n||m) {
    char ba[n][m];
    P castle;
    REP(y,m) {
      REP(x,n) {
        cin >> ba[x][y];
        if (ba[x][y] == '&')
          castle = P(x,y);
      }
    }
    int dp[n][m];
    REP(x,n) {
      REP(y,m) {
        if (x == 0 || x == n-1 || y == 0 || y == m-1)
          dp[x][y] = 0;
        else
          dp[x][y] = INF;
      }
    }
    bool update = true;
    while(update) {
      update = false;
      for (int x=1; x<n-1; ++x) {
        for (int y=1; y<m-1; ++y) {
          REP(k,4) {
            int xx = x+dx[k], yy = y+dy[k];
            if (ba[x][y] != '#' && ba[xx][yy] == '#') {
              if (dp[x][y] > dp[xx][yy] + 1) {
                dp[x][y] = dp[xx][yy] + 1;
                update = true;
              }
            } else {
              if (dp[x][y] > dp[xx][yy]) {
                dp[x][y] = dp[xx][yy];
                update = true;
              }
            }
          }
        }
      }
    }
    cout << dp[castle.first][castle.second] << endl;
  }
}

Measured memory_bytes: 916
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		double x1 = Double.parseDouble(std.next());
		double y1 = Double.parseDouble(std.next());
		double x2 = Double.parseDouble(std.next());
		double y2 = Double.parseDouble(std.next());
		double res = Math.pow(Math.pow((x1-x2),2) + Math.pow((y1-y2),2),0.5);
		System.out.println(String.format("%.5f", res));
	}
}

Measured memory_bytes: 26288
#include <stdio.h>
int main(){
  int a,b;
  char op;
  while(1){
scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
      printf("%d\n",a+b);
    }
     else if(op=='-'){
	printf("%d\n",a-b);
      }
     else  if(op=='*'){
	printf("%d\n",a*b);
      }
     else if(op=='/'){
	printf("%d\n",a/b);
      }
     else{
	break;
      }
  }
  return 0;
}

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

a = list(map(int, input().split(' ')))

jun = [i+1 for i in range(n)]

ans = {}    
for i, j in zip(a, jun):
    ans[i] = j

ans = sorted(ans.items())
ans = [str(i[1]) for i in ans]

print(' '.join(ans))


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

string S;
string t[4] = {"maerd",
               "remaerd",
               "esare",
               "resare"};

int main()
{
    cin >> S;

    string s;
    for (int i = S.size()-1; i >=0; i--)
    {
        s += S[i];
        for (int j = 0; j < 4; j++)
        {
            if(s == t[j]) s = "";
        }
        
    }
    if(s == "") cout << "YES" << endl;
    else cout << "NO" << endl;
    
 
    return 0;
}


Measured memory_bytes: 512
H, W = [int(c) for c in input().split()]
a = [[int(c) for c in input().split()] for _ in range(H)]
temp = False
result = []

for h in range(H):
    for w in range(W):
        if h % 2 != 0:
            w = W - w -1

        if not temp:
            if a[h][w] % 2 != 0:
                ans = "{0} {1} ".format(h+1, w+1)
                temp = True
            else:
                continue
        else:
            if a[h][w] % 2 != 0:
                ans += "{0} {1}".format(h+1, w+1)
                temp = False
                result.append(ans)
            else:
                ans += "{0} {1}".format(h+1, w+1)
                result.append(ans)
                ans = "{0} {1} ".format(h+1, w+1)

print(len(result))
for ans in result:
    print(ans)

Measured memory_bytes: 16344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int H, A;
  cin >> H >> A;
  int ans = 0;
  while (H > 0) {
    H -= A;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main
{
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in); 
		int t,i;	
		int n=sc.nextInt();
		int w=sc.nextInt();
		long dp[][]=new long[n+1][w+1];
		int v[][]=new int[n+1][2];
		for(i=1;i<=n;i++)
		{
			v[i][0]=sc.nextInt();
			v[i][1]=sc.nextInt();
		}
		for(i=1;i<=n;i++)
		{
			for(int j=1;j<=w;j++)
			{
				int wc=v[i][0];
				if(wc>j)
					dp[i][j]=dp[i-1][j];
				else
					dp[i][j]=Math.max(dp[i-1][j], dp[i-1][j-wc]+v[i][1]);
			}
		}
		System.out.println(dp[n][w]);
	}
}

Measured memory_bytes: 140520
#include"bits/stdc++.h"
using namespace std;

void Main() {
	string N;
	cin >> N;
	int pos = N.find("7");
	if (pos == string::npos) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;

int D;

int main() {
	cin >> D;
	if (D == 25) cout << "Christmas" << endl;
	if (D == 24) cout << "Christmas Eve" << endl;
	if (D == 23) cout << "Christmas Eve Eve" << endl;
	if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

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

void showVector(std::vector<int> &readVec){
    int length = readVec.size();
    for(int i = 0; i < length; ++i){
        if(length - 1 != i){
            std::cout << readVec.at(i) << " ";
        }else{
            std::cout << readVec.at(i);
        }
    }
    
    std::cout << std::endl;
}

int bubbleSort(std::vector<int> &readVec){
    int n = readVec.size();
    int temp, count = 0;
    bool flg = true;
    while(flg){
        flg = false;
        for(int i = n - 1; 0 < i; --i){
            if(readVec.at(i) < readVec.at(i - 1)){
                temp = readVec.at(i);
                readVec.at(i) = readVec.at(i - 1);
                readVec.at(i - 1) = temp;
                flg = true;
                ++count;
            }
        }
    }

    return count;
}

int main(){
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    int count = bubbleSort(a);
    showVector(a);    
    std::cout << count << std::endl;

    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, X, Y, bypass_distance1, bypass_distance2, bypass_distance;
  cin >> N >> X >> Y;
  vector<vector<int>> table(N, vector<int>(N));
  map<int, int> m;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++) table.at(i).at(j) = j - i;
  }
//  for(int i=0;i<N;i++){
//    for(int j=0;j<N;j++) if(i<j) printf("table.at(%d).at(%d) =  %d\n",i+1,j+1,table.at(i).at(j));
//  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      bypass_distance1 = 2000;
      bypass_distance2 = 2000;
      bypass_distance = 2000;
      bypass_distance1 = abs(j+1-X) + abs(i+1-Y) + 1;
      bypass_distance2 = abs(j+1-Y) + abs(i+1-X) + 1;
      bypass_distance = min(bypass_distance1, bypass_distance2);
      if(i<j) table.at(i).at(j) = min(table.at(i).at(j), bypass_distance);
    }
  }
//  printf("NEW!!\n");
//    for(int i=0;i<N;i++){
//    for(int j=0;j<N;j++) if(i<j) printf("table.at(%d).at(%d) =  %d\n",i+1,j+1,table.at(i).at(j));
//  }
  for(int i=1;i<N;i++) m[i] = 0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      m[table.at(i).at(j)]++;
    }
  }
  for(int i=1;i<N;i++) cout << m[i] << endl;
 
  return 0;
}

Measured memory_bytes: 16128
'use strict';
var NS = {};
function addProps(ns) {
    var isBrowser = function() {
        return typeof window !== 'undefined';
    }
    ns.isBrowser = isBrowser;
    
    var isNodejs = function() {
        return ! isBrowser();
    }
    ns.isNodejs = isNodejs;
    
    if (isBrowser()) {
        var getHtmlEncoded = function(string0) {
            return String(string0)
                    .replace(/&/g, '&amp;')
                    .replace(/"/g, '&quot;')
                    .replace(/'/g, '&#39;')
                    .replace(/</g, '&lt;')
                    .replace(/>/g, '&gt;');
        }
        ns.getHtmlEncoded = getHtmlEncoded;
        
        var outputCode = function() {
            document.getElementById('code').innerHTML = '<pre><code>' + getHtmlEncoded(addProps) + '</code></pre>';
        }
        ns.outputCode = outputCode;
    }
    
    var getInput = function() {
        var inputLines = [];
        if (isBrowser()) {
            var html = document.getElementById('input').innerHTML;
            inputLines = html.split('<br>');
        }
        if (isNodejs()) {
            inputLines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
        }
        return inputLines;
    }
    
    var doOutput = function(outputLines) {
        if (isBrowser()) {
            document.getElementById('output').innerHTML = outputLines.map(getHtmlEncoded).join('<br>\n');
        }
        if (isNodejs()) {
            for (var i = 0; i < outputLines.length; i++) {
                console.log(outputLines[i]);
            }
        }
    }
    ns.doOutput = doOutput;
    
    var getHMS = function(s) {
        var result = {};
        result.seconds = s % 60;
        s = Math.floor(s / 60);
        result.minutes = s % 60;
        s = Math.floor(s / 60);
        result.hours = s;
        return result;
    }
    
    var main = function() {
        var inputLines = getInput();
        var s = Number(inputLines[0]);
        var result = getHMS(s);
        var string0 = result.hours + ':' + result.minutes + ':' + result.seconds;
        doOutput([string0]);
    }
    ns.main = main;
}
addProps(NS);
if (NS.isBrowser()) {
    window.onload = function() {
        NS.outputCode();
    }
}
NS.main();

Measured memory_bytes: 7644
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N;
LL A, B;
vector<LL> hp;

bool check(LL c){
    LL res = 0;
    LL s = A-B;
    REP(i, N){
        LL h = hp[i] - c*B;
        if(h<=0)continue;
        res += h / s + (h%s==0 ? 0 : 1);
    }
    return res <= c;
}

int main(){
    cin >> N >> A >> B;
    hp.resize(N);
    REP(i, N)cin >> hp[i];
    LL lb = 0;
    LL ub = 1000000000;
    while(ub-lb>1){
        LL mid = (lb+ub)>>1;
        if(check(mid)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    cout << ub << endl;
    return 0;
}


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

int n, z, w, a[2005];

int main ()
{
	cin >> n >> z >> w;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	int ans = abs (a[n] - w);
	if (n > 1)
		ans = max (ans, abs (a[n] - a[n-1]));
	cout << ans;
}

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

#define ll long long
#define ld long double
#define F first
#define S second

#define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9+7;

void solve(){
	int n,m;
	cin >> n >> m;
	int s = 0;
	for(int i = 0; i < m; i++){
		int x; cin >> x;
		s+=x;
	}
	n-=s;
	if(n < 0) n = -1;
	cout << n << "\n";
}

int main(){
	#ifndef ONLINE_JUDGE	
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);		
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

char h;

string s[4][13];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	map<char,int> mp;
	for(int i=2;i<10;i++){
		mp[(char)(i+'0')]=i;
	}
	mp['T']=10;
	mp['J']=11;
	mp['Q']=12;
	mp['K']=13;
	mp['A']=14;
	while(cin >> h,h!='#'){
		int win[2]={};
		for(int i=0;i<4;i++){
			for(int j=0;j<13;j++){
				cin >> s[i][j];
			}
		}
		int fi=0;
		for(int i=0;i<13;i++){
			int wi=0,mx=0;
			bool f=0;
			char c=s[fi][i][1];
			for(int j=0;j<4;j++){
				int r=mp[s[j][i][0]];
				char ss=s[j][i][1];
				if(f){
					if(ss==h&&r>mx){
						mx=r;
						wi=j;
					}
				}
				else{
					if(ss==h){
						f=1;
						mx=r;
						wi=j;
					}
					else{
						if(ss==c&&r>mx){
							mx=r;
							wi=j;
						}
					}
				}
			}
			fi=wi;
			win[wi%2]++;
		}
		if(win[0]>win[1]){
			printf("NS %d\n",win[0]-6);
		}
		else{
			printf("EW %d\n",win[1]-6);
		}
	}
}



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

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int, int>> data; //{市番号,県,年,内部順序}
    for(size_t i = 0; i < m; i++)
    {
        int p, y;
        scanf("%d %d", &p, &y);
        data.push_back(make_tuple(i + 1, p, y, -1));
    }
    int cnt[n+1] = {};

    sort(data.begin(), data.end(),
        [](tuple<int, int, int, int> l, tuple<int, int, int, int> r) {
            return get<2>(l) < get<2>(r);
        });
    
    for(size_t i = 0; i < m; i++)
    {
        cnt[get<1>(data[i])]++;
        data[i] = make_tuple(get<0>(data[i]), get<1>(data[i]), get<2>(data[i]), cnt[get<1>(data[i])]);
    }

    sort(data.begin(), data.end(),
         [](tuple<int, int, int, int> l, tuple<int, int, int, int> r) {
             return get<0>(l) < get<0>(r);
         });
    
    
    for(size_t i = 0; i < m; i++)
    {
        cout << setw(6) << setfill('0') << get<1>(data[i]) << setw(6) << setfill('0') << get<3>(data[i]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  lol a;
  priority_queue<lol> ans;
  rep(i, n){
    cin >> a;
    ans.push(a);
  }
  rep(i, m){
    a = ans.top();
    ans.pop();
    a /= 2;
    ans.push(a);
  }
  lol nasu = 0;
  while(!ans.empty()){
    nasu += ans.top();
    ans.pop();
  }
  cout << nasu << '\n';
  return 0;
}


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

using namespace std;

long long n , m  , Max=0;

vector<long long> a[100010];

long long dp[100005];

void dfs(long long x , long long root , long long i)
{
    if(dp[x]!=0){return;}
    for(auto v: a[x])
    {
        if(v!=root&&v!=i)
        {
            dfs(v , x , i);
            dp[x]=max(dp[v]+1 , dp[x]);
           // dp[v]=0;
        }
    }
}

int main()
{
    cin >> n >> m ;
    for(long long i=1 ; i<=n ; i++){
        dp[i]=0;
    }
    for(long long i=1 ; i<=m ; i++){
        long long u , v;
        cin >> u >> v;
        a[u].push_back(v);
    }
    for(long long i=1 ; i<=n ; i++)
    {
        dfs(i , -1 , i);
        Max=max(dp[i] , Max);
    }
    cout << Max<<endl;
    
}



Measured memory_bytes: 12556
#[allow(unused_imports)]
use std::io::*;

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

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

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

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

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

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

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

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

fn main(){
    input!{
        n: i32,
        d: [u32; n],
    }
    let mut m1 = 0;
    let mut m2 = 0;
    for i in &d{
        if m1 < *i{
            m2 = m1;
            m1 = *i;
        }else if m2 < *i{
            m2 = *i;
        }
    }
    for i in &d{
        let ans = if *i != m1 { m1 } else { m2 };
        println!("{}", ans);
    }
}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n, k;
  string s;
  cin >> n >> k >> s;

  k--;
  if(s[k] == 'A') s[k] = 'a';
  else if(s[k] == 'B') s[k] = 'b';
  else s[k] = 'c';
  cout << s << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string[] placeInput=Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int x = int.Parse(input[1]);

            int[] distances = new int[n];
            for (int i = 0; i < n;i++){
                distances[i] = Math.Abs(int.Parse(placeInput[i]) - x); 
            }
             
            int tmp=distances[0];
            
            for (int i = 0; i < n ;i++){
                tmp= gcd(tmp,distances[i] );
            }

            Console.WriteLine(tmp);
         }



        public static int gcd(int a,int b){
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;

        }
     }
}




Measured memory_bytes: 18400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int sz=s.size();
    int c=0;
    for(int i=0;i<sz/2;i++)
    {
        if(s[i]!=s[sz-1-i])
            c++;
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

using namespace std;

main(){
    int d, n;
    int sum;
    while ( scanf("%d", &d) != EOF ){
	sum = 0;
	int lim = 600 - d;
	for ( int x = d; x <= lim; x += d){
	    sum += x*x * d;
	}
	
	printf("%d\n", sum);
    }
}

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

long long A, B, C;
int solve(){
    for(int i = 0;i< 1000000; ++i){
        if(A&1||B&1 ||C&1) return i;
        long long tA = (B+C)/2;
        long long tB = (A+C)/2;
        long long tC = (A+B)/2;
        
        A=tA,B=tB,C=tC;
    }
    return -1;
    
}
int main(void){
    cin>>A>>B>>C;
    cout<<solve()<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 200000000
#define N 51




int32_t main()
{
    IOS;
   
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> v(n);
    for(int i = 0;i < n;i++)
        v[i] = (s[i] == 'R');
    int ans1 = 0;
    int ans2 = 0;
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        if(v[i] == 0)
        {
            if(i - 1 >= 0 and v[i-1] == 0)
                ans++;
        }
        else
        {
            if(i + 1 < n and v[i + 1] == 1)
                ans++;
        }
    }

    for(int i = 0;i < n;i++)
    {
        if(v[i] == 0)
        {
            if(i -1 >= 0 and v[i-1] == 0)
                ;
            else
                ans1++;
        }
        if(v[i] == 1)
        {
            if(i - 1 >= 0 and v[i-1] == 1)
                ;
            else
                ans2++;
        }
    }
    // cerr << ans << " " << ans1 << " " << ans2 << endl;
    cout << min(n - 1,ans + 2 * min(k,min(ans1,ans2)));
}   
 
 


Measured memory_bytes: 1232
import math

N = int(input())
k = int(math.log10(N))
s = 0
for i in range(1, k + 1):
    if i % 2 == 0:
        continue
    s += 10 ** i - 10 ** (i - 1)
if k % 2 == 0:
    s += N - 10**k + 1
print(s)

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

using namespace std;

vector<int> factorize(int x) {
  vector<int> factors;
  for (int a = 1; a * a <= x; a++) {
    if (x % a == 0) {
      factors.push_back(a);
      if (a * a != x) {
        factors.push_back(x / a);
      }
    }
  }
  sort(factors.begin(), factors.end());
  return factors;
}

int main() {
  int N;
  cin >> N;
  int answer = 0;
  for (int i = 1; i <= N; i += 2) {
    vector<int> factors = factorize(i);
    if (factors.size() == 8) {
      answer++;
    }
  }
  cout << answer;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1!=m2)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
/*AOJ No.5067 Best Pizza*/
/*g++ -std=c++0x 0567.cpp*/

#include <iostream>
#include <algorithm>

using namespace std;

int main(){

  int A,B,C,N; 
  int i;
  int rate;
  int nrate;
  int price;
  int kcal;

  cin >> N;
  cin >> A >> B; 
  cin >> C;
  
  price=A;
  kcal=C;
  rate=kcal/price;

  int T[N];

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

  sort(T,T+N);

  for(i=N-1;i>=0;i--){
    kcal+=T[i];
    price+=B;
    nrate=kcal/price;
   
    if(nrate>=rate){
      rate=nrate;
    }
      
    else{
      break;
    }
  }
  
  cout << rate << endl;

  return 0;
}

Measured memory_bytes: 1176