akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int H, W;
  cin>>H>>W;
  vector<vector<char>> image(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char C;
      cin>>C;
      image.at(i).at(j)=C;
    }
  }
  vector<vector<char>> nibai(2*H, vector<char>(W));
  for(int i=0; i<2*H; i++){
    if(i%2==0){
    for(int j=0; j<W; j++){
      nibai.at(i).at(j)=image.at(i/2).at(j);
      if(j==W-1) cout<<nibai.at(i).at(j)<<endl;
      else cout<<nibai.at(i).at(j);
    }
    } //if
    if(i%2==1){
    for(int j=0; j<W; j++){
      nibai.at(i).at(j)=nibai.at(i-1).at(j);
      if(j==W-1) cout<<nibai.at(i).at(j)<<endl;
      else cout<<nibai.at(i).at(j);
    } //j
    } //if
  } //i
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    //チケットの種類 「　ticketType　」とチケットの販売枚数「　ticketSheet　」置く
    int ticketType, ticketSheet;
    
    for(int i = 0; i < 4; i++){
        //チケットの種類 「　ticketType　」とチケットの販売枚数「　ticketSheet　」置く
        cin >> ticketType >> ticketSheet;
        
        //条件：各チケットの種類から金額をもとめる
        if( ticketType == 1) cout << 6000 * ticketSheet << endl;
        else if( ticketType == 2) cout << 4000 * ticketSheet << endl;
        else if( ticketType == 3) cout << 3000 * ticketSheet << endl;
        else if( ticketType == 4) cout << 2000 * ticketSheet << endl;
        
    }

    return 0;
}



Measured memory_bytes: 3092
=begin
N
v1 ... vn
=end

n = gets.chomp.to_i
vn = gets.chomp.split(" ").map(&:to_i)

vn.sort!

while true do
  if vn.count == 2
    break
  end

  v1 = vn.shift
  v2 = vn.shift

  v = (v1 + v2) / 2.0

  vn << v
  vn.sort!
end

puts ((vn[0] + vn[1]) / 2.0)


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[10001] = {0};
    int m =  min(n,99);
    for(int i = 1 ; i <= m ; i++)
    {
        for(int j = 1 ; j <= m ;j++)
        {
            for(int z = 1 ; z <= m ;z++)
            {
                if(i*i+j*j+z*z+i*j+i*z+j*z <= 10000)
                    arr[i*i+j*j+z*z+i*j+i*z+j*z]++;
            }
        }
    }
    for(int  i = 1 ; i <= n ; i++)
    {
        cout<<arr[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
        cin>>a[i];
    ll dp[k+1];
    for(ll i=0;i<=k;i++)
        dp[i]=0;
    for(ll i=1;i<=k;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(a[j]>i)
                continue;
            if(dp[i-a[j]]==0)
                dp[i]=1;
        }
    }
    if(dp[k]==1)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



int main () {
  ios::sync_with_stdio(0); srand(time(0));
  cin.tie(0); cout.tie(0);

  int t;
  cin >> t;
  while( t-- ) {
    ll p, q;
    cin >> p >> q;
    ll z = p * q;
    ll lo = 1, hi = max(p, q);
    while( lo < hi ) {
      ll mid = (lo + hi + 1)/ 2;
      if( mid * mid < z ) lo = mid;
      else hi = mid-1;
    }
    ll rt = lo;
    ll a;
    if( rt * rt + rt < z )
      a = 2 * rt;
    else
      a = 2 * rt - 1;
    if( min(p, q) <= rt ) a--;
    cout << a << nl;
  }

  return 0;
}

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


Measured memory_bytes: 256
n,l=map(int,input().split())
a=[]
for i in range(0,n):
  a.append(i+l)
if 0 in a:
  print(sum(a))
else:
  if a[0]>0:
    print(sum(a)-a[0])
  else:
    print(sum(a)-a[n-1])


Measured memory_bytes: 2940
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,t,h,a,b,i,d[3010]={0};
  scanf("%d %d %d",&n,&t,&h);
  while(n--){
    scanf("%d %d",&a,&b);
    for(i=t;i>-1;i--){
      if(i<h&&h<i+b)continue;
      if(i+b>t)continue;
      d[i+b]=MAX(d[i+b],d[i]+a);
    }
    for(i=0;i<t;i++)d[i+1]=MAX(d[i+1],d[i]);
    //for(i=0;i<t;i++)printf("%2d ",d[i]);printf("\n");
  }
  printf("%d\n",d[t]);
  return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; 
	int K; 
	cin >> S >> K; 
	int L = S.size(); 
	int A[100010] = {};
	int nokori = K;  
	for(int i = 0; i < L; i++){
		A[i] = S.at(i) - 'a'; 
	}
	for(int i = 0; i < L-1; i++){
		if(S.at(i) == 'a' || nokori < 26 - A[i]) cout << S.at(i); 
		else{
			cout << 'a'; 
			nokori -= 26 - A[i]; 
		}
	}
	int R = (A[L-1] + nokori) % 26; 
	cout << (char) ('a' + R) << endl; 
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var sum = new int[N];
            var total = 0;
            // T以下とTより大きいグループに分ける
            for (var i = 0; i < N; i++)
            {
                total += array[i];
                sum[i] = total;
            }

            var min = int.MaxValue;
            for (var i = 0; i < N-1; i++)
            {
                min = Math.Min(Math.Abs(sum[i] - Math.Abs(sum[N - 1] - sum[i])), min);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 11348
#define _CRT_SECURE_NO_WARNINGS
#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>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
	int a,b,n[999];
	n[0]=1;
	reps(i,1,999){
		n[i]=n[i-1]+i+1;
	}
	cin>>a>>b;
	rep(i,999){
		if(n[i]-a==n[i+1]-b)	cout<<n[i]-a<<endl;
	}
	return 0;
}

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

int main() {
	long long N;
	double V[50];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> V[i];
	sort(V, V + N);
	for (int i = 0; i < N - 1; i++) {
		V[i + 1] = (V[i] + V[i + 1]) / 2;
	}
	printf("%.9lf\n", V[N - 1]);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
int main (void){
  int n;
  scanf("%d",&n);
  int b[n+1];
  double a[n+1],te,ans;
  for(int i=1;i<=n;i++){
    scanf("%d",&b[i]);
    a[i]=b[i];
  }
  for(int k=1;k<=n;k++){
  for(int i=1;i<=n-k;i++){
    if(a[i]>=a[i+1]){te=a[i];a[i]=a[i+1];a[i+1]=te;}
  }
  }
  for(int i=1;i<=n-1;i++){
    a[i+1]=(a[i]+a[i+1])/2;
  }
  ans=a[n];
  printf("%f",ans);
}

Measured memory_bytes: 256
loop do
    h, w = gets.split(" ").map(&:to_i)

    if h == 0 && w == 0 then
        break;
    end
    
    # #........#
    
    h.times do |i|
        if i == 0 || i == h - 1 then
            print "#" * w, "\n"
        else
            print "#", "." * (w - 2), "#\n"
        end
    end
    
    print "\n"
end


Measured memory_bytes: 6876
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>

//by Skeef79

//НЕ ИСПОЛЬЗУЙ endl, есть свой en!!
//Иногда нужно не просто придумывать решение, а метматически расписать систему уравнений
//для задач с cin/cout в большом кол-ве - gnu , иначе вижуалки. А ваще пробуй два если TL

//для интерактивок - cout<<flush
// cin.tie и sync_with_stdio убирать для интерактивок

typedef long long ll;
typedef long double ld;

#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 1e9 + 1233;
const ll LINF = 1e18 + 1233;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
}

template <typename T> void Input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

bool IsSorted(vector<int>& a)
{
	for (int i = 1; i < a.size(); i++)
	{
		if (a[i] < a[i - 1])
			return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	Input(a);

	if (IsSorted(a))
	{
		cout << "YES";
		return 0;
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			swap(a[i], a[j]);
			if (IsSorted(a))
			{
				cout << "YES";
				return 0;
			}
			swap(a[i], a[j]);
		}
	}

	cout << "NO";

}





Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {

	nextReader = newScanner()

	n, k := nextInt(), nextInt()

	h := nextInts(n)
	sort.Ints(h)

	total := 0
	for i := 0; i < n-k; i++ {
		total += h[i]
	}

	fmt.Println(total)

}

/* --------------------------------------------------------------------------
 *  std.io
 * ------------------------------------------------------------------------- */
var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func mins(t ...int) int {
	if len(t) == 0 {
		return 0
	}

	min := t[0]
	for i := 1; i < len(t); i++ {
		if min > t[i] {
			min = t[i]
		}
	}
	return min
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return 0 - a
	}
}


Measured memory_bytes: 5120
(* O(m α(n)) *)
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let ab_s = Array.init m (fun i -> ab_s.(m - 1 - i))
let ps = Array.make n @@ -1
let rec find x =
  if ps.(x) < 0 then x
  else let y = find ps.(x) in ps.(x) <- y; y
let unite x y =
  let x = find x in
  let y = find y in
  if x = y then false
  else
    (if ps.(x) < ps.(y) then (ps.(x) <- ps.(x) + ps.(y); ps.(y) <- x)
    else (ps.(y) <- ps.(y) + ps.(x); ps.(x) <- y);
    true)
let size x = -ps.(find x)
let v = ref @@ n * (n - 1) / 2
let vs = ref []
let _ =
  let f (a, b) =
    vs := !v :: !vs;
    let x, y = size a, size b in
    if unite a b then v := !v - x * y in
  Array.iter f ab_s;
  List.iter (fun v -> Printf.printf "%d\n" v) !vs

Measured memory_bytes: 11392
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 4001;
ll DP[N+50][N+50], n, ma, mb, a, b, c;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Fill(DP, linf);
  DP[0][0] = 0;
  cin >> n >> ma >> mb;
  FOR(i, 0, n){
    cin >> a >> b >> c;
    FORR(j, N-1, 0)FORR(k, N-1, 0) mins(DP[j+a][k+b], DP[j][k] + c);
  }
  ll sma = 0, smb = 0, ans = linf;
  while(sma < N && smb < N){
    sma += ma;
    smb += mb;
    mins(ans, DP[sma][smb]);
  }
  cout << (ans < linf ? ans : -1) << endl;
  return 0;
}

Measured memory_bytes: 128512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// UnionFind高速
type UnionFind struct {
	d []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.d = make([]int, N)
	for i := 0; i < N; i++ {
		u.d[i] = -1
	}
	return u
}

func (p *UnionFind) root(x int) int {
	if p.d[x] < 0 {
		return x
	}
	p.d[x] = p.root(p.d[x])
	return p.d[x]
}

func (p *UnionFind) unite(x, y int) bool {
	x = p.root(x)
	y = p.root(y)
	if x == y {
		return false
	}
	if p.d[x] > p.d[y] {
		x, y = y, x
	}
	p.d[x] += p.d[y]
	p.d[y] = x
	return true
}

func (p *UnionFind) same(x, y int) bool {
	return p.root(x) == p.root(y)
}

func (p *UnionFind) size(x int) int {
	return -p.d[p.root(x)]
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	p := make([]int, N)
	for i := 0; i < N; i++ {
		p[i] = getInt() - 1
	}
	u := newUnionFind(N)
	for i := 0; i < M; i++ {
		x, y := getInt()-1, getInt()-1
		u.unite(x, y)
	}

	ans := 0

	for i := 0; i < N; i++ {
		f := u.same(p[i], i)
		if f {
			ans++
		}
	}
	out(ans)
}


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


#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a%b, y, x);
  y -= a/b * x;
  return d;
}

class BSumIsMultiple {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n; cin >> n;
      vector<ll> divisors;
      ll n2 = 2*n;

      ll ret = n2-1;
      for(ll i=1; i*i<=n2; i++) {
        if (n2%i==0) {
          ll a = i;
          ll b = n2/i;

          // extgcd
          if (gcd(a, b) != 1) continue;

          b = -b;

          ll x, y;
          ll p = extGCD(a, b, x, y);
          debug(x, y, a*x, b*y, p);

          __uint128_t k = abs(a*x);
          if (k!=0 && (k*(k+1)/2)%n == 0) {
            chmin(ret, (ll)k);
          }
          k = abs(b*y);
          if (k!=0 && (k*(k+1)/2)%n == 0) {
            chmin(ret, (ll)k);
          }
        }
      }
      cout << ret << endl;


    }
};

signed main() {
  BSumIsMultiple solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

typedef int integer;
typedef pair<long long,long long> pr;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lw lower_bound
#define fst first 
#define snd second 
#define mp make_pair    

#define fore(i,a,b) for(int i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())

#define infll (long long)1e7
#define INF (long long)1e15
#define inf  (int)2e9
#define int long long
#define endl '\n'

const ld pi = acos(-1);
const ll MOD = 1e9+7;
const ld EPS = 1e-9;
const int MAX_N = 2e5;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll fpow(ll b, ll e, ll m = MOD){if(!e)return 1;ll q=fpow(b,e/2,m);q=(q*q)%m;return e&1?(b*q)%m:q;}


integer main(){FIN;
	int n; cin>>n;
	int res=0;
	while(1){
		res++;
		n/=2;
		if(n==0)break;
	}
	int c=1; int p=2;
	fore(i,0,res-1){
		c+=p;
		p*=2;
	}
	cout<<c<<endl;
    return 0; 
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define vi vector<int>
int main(){
    int k,x;
    cin>>k>>x;
    for(int i=k-1;i>0;i--){
        cout<<x-i;
        cout<<" ";
    }
    for(int i=0;i<k;i++){
        cout<<i+x;
        if(i!=k-1)cout<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define sd(x) scanf("%d", &x)
#define sf(x)  scanf("%lf",&x)
#define rep(i,n) for(i=0;i<(n);++i)
#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))       //2つの変数の内容を入れ替える
#define max(a, b) ((a) > (b) ? (a) : (b))           //指定された2つの引数のうち,最大のものを返す
#define min(a, b) ((a) < (b) ? (a) : (b))           //指定された2つの引数のうち,最小のものを返す

int i,j,k;          //forループ用

int main() {
    int r,d;
    int x[100];
    sd(r);
    sd(d);
    sd(x[0]);
    rep(i,11) {
        x[i+1]=r*x[i]-d;
    }

    for(i=1;i<11;i++) {
        printf("%d\n",x[i]);
    }

 return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        long a = long.Parse(s[0]);
        long b = long.Parse(s[1]);

        //Console.WriteLine(f0(b));
        //Console.WriteLine(f0(a-1));
        Console.WriteLine(f0(b) ^ f0(a - 1));
    }

    static ulong f0(long k)
    {
        ulong r = 0;
        if (k % 4 == 1 || k % 4 == 2) r = 1;
        for (int i = 1; i <= 40; i++)
        {
            long m = (long)Pow(2, i + 1);
            long k_ = k % m;
            if (k_ < m / 2) continue;
            if ((k_ - m / 2 + 1) % 2 == 0) continue;
            r = r | ((ulong)1 << i);
        }
        return r;
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<stdio.h>
#include<math.h>

int main()
{
	double x = 0, y = 0;
	double pace, angle;
	double theta = 0;
	
	while( 1 ){
		scanf( "%lf,%lf", &pace, &angle );
		if( !pace && !angle ) break;
		
		x += cos( ( 90 - theta ) * 3.1415926535 / 180 ) * pace;
		y += sin( ( 90 - theta ) * 3.1415926535 / 180 ) * pace;
		theta += angle;
	}
	
	printf( "%d\n%d\n", (int)x, (int)y );
	                      
 	return 0;
}

Measured memory_bytes: 1216
#include<string.h>
#include<iostream>
int main()
{
	char str[1001];
	std::cin >> str;
	int q;
	std::cin >> q;
	char**result = new char*[q];
	for(int i = 0; i < q; i++)
	{
		result[i] = new char[1001];
		char order[8];
		std::cin >> order;
		if(strcmp(order, "print") == 0)
		{
			int a, b;
			std::cin >> a >> b;
			for(int j = a; j <= b; j++)
			{
				result[i][j - a] = str[j];
			}
			result[i][b - a + 1] = '\0';
		}
		else if(strcmp(order, "reverse") == 0)
		{
			int a, b;
			std::cin >> a >> b;
			int step = (b - a + 1) / 2;
			for(int j = 0; j < step; j++)
			{
				char tmp = str[a + j];
				str[a + j] = str[b - j];
				str[b - j] = tmp;
			}
			result[i][0] = '\0';
		}
		else if(strcmp(order, "replace") == 0)
		{
			int a, b;
			std::cin >> a >> b;
			char*p = new char[b - a + 2];
			std::cin >> p;
			for(int j = a; j <= b; j++)
			{
				str[j] = p[j - a];
			}
			result[i][0] = '\0';
		}
	}
	for(int i = 0; i < q; i++)
	{
		if(result[i][0] != '\0')
		{
			std::cout << result[i] << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
 
using namespace std;
 
int main() {
	int n,a,b;
	int sums = 0;
	cin >> n >> a >> b;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			for(int k=0; k<10; k++){
				for(int l=0; l<10; l++) {
					int sum = i*1000+j*100+k*10+l;
					if(sum > n) {cout << sums << endl; return 0;}
					if(i+j+k+l <a || i+j+k+l > b) {continue;}
					sums += sum;
				}}}}
	if(n == 10000) sums += 10000;
	cout << sums << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main(){
  ll N; cin >> N;
  Sieve sieve(1000005);
  ll ans = 0;
  for(int i = 1; i < N; i ++){
    ll tmp = 1;
    vector<pair<ll, ll> > m = sieve.factor(i);
    for(auto p : m){
      tmp *= p.sc + 1;
    }
    ans += tmp;
  }
  cout << ans << endl;
}


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

int main() {
  int ans = 0, mini = 10;
  
  for (int i = 0; i < 5; i++) {
    int N;
    cin >> N;
    if (N % 10 != 0) mini = min(mini, N % 10);
    ans += (N + 9) / 10 * 10;
  }

  cout << ((mini == 10) ? ans : ans + mini - 10) << "\n";
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  const obj = { A: true, C: true }
  input = input.split('\n').map(v => v.split(' '))
  const n = ~~input[0][0]
  const qn = ~~input[0][1]
  let str = input[1][0].split('')
  let Q = input.slice(2, -1)
  Q = Q.map(v => v.map(v2 => ~~v2))

  let count = [0]
  let tmp = 0
  for (let i = 1; i < n; i++) {
    if (str[i - 1] == 'A' && str[i] == 'C') {
      tmp += 1
    }
    count[i] = tmp
  }

  let ans = ''
  let xxx = 0
  for (let i = 0; i < qn; i++) {
    let l = Q[i][0]
    let r = Q[i][1]
    xxx = count[r - 1] - count[l - 1]
    ans += xxx + '\n'
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 70684
#include <stdio.h>
#include <string.h>
int main(void){
	int dataset,ining;
	int i;
	int runner[3],point,out;
	char str[8];

	scanf("%d",&dataset);
	for(ining=0;ining<dataset;ining++){

		//init state variable
		for(i=0;i<3;i++){
			runner[i]=0;
		}
		point=0;
		out=0;

		//start	ining
		while(out<3){
			scanf("%s",&str[0]);

			if(strcmp(str,"HOMERUN")==0){
		                for(i=0;i<3;i++){
					point+=runner[i];
		                        runner[i]=0;
		                }
				point++;
			}

			else if(strcmp(str,"HIT")==0){
				if(runner[2]==1){
					runner[2]=0;
					point++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[0]=0;
					runner[1]=1;
				}
				runner[0]=1;
			}

			else if(strcmp(str,"OUT")==0){
				out++;
			}
		}

		//finish ining
		printf("%d\n",point);
	}
}

Measured memory_bytes: 1024
n = int(input())
H = [0] + list(map(int, input().split())) + [0]
T = [0 for _ in range(n+2)]
c = 0
while True:
	s0 = 0; t1 = 0
	for i in range(0, n+2):
		if H[i] > 0 and s0 == 1:
			H[i] -= 1
			t1 = 1
		elif H[i] == 0 and t1 == 1:
			c += 1
			t1 = 0
		elif H[i] == 0:
			s0 = 1
	if H == T: break
print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n);
    Cinm(int, n, m);
    vector<int> res {0, 0};
    for(auto e : m){
        if(e.second >= 2) res.push_back(e.first);
        if(e.second >= 4) res.push_back(e.first);
    }
    DeSort(res);
    Cout((ll)res[0] * res[1]);
}


Measured memory_bytes: 4388
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int N, A;
	cin >> N >> A;

	int tmp = N % 500;
	
	string ans = "Yes";
	if (tmp > A)
	{
		ans = "No";
	}

	cout << ans << endl;

	return 0;
 
}

Measured memory_bytes: 256
#include <stdio.h>

#define A_MAX 1000000

int a[A_MAX + 1];

int main() {
    int min_factor[A_MAX + 1];
    int q[A_MAX + 1];
    int primes[A_MAX + 1];
    int primes_size = 0;
    for (int i = 2; i <= A_MAX; ++i) {
        min_factor[i] = i;
    }
    for (int i = 2; i <= A_MAX; ++i) {
        if (min_factor[i] == i) {
            primes[primes_size++] = i;
        }
        for (int j = 0; j < primes_size; ++j) {
            int p = primes[j];
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor[i]) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }

    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        int A;
        scanf("%d", &A);
        ++a[A];
    }

    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        if (a[n] > 1) {
            if (a[n] == N) {
                printf("not coprime\n");
                return 0;
            }
            is_pairwise_coprime = 0;
        }
        a[min_factor[n]] += a[n];
        a[q[n]] += a[n];
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }

    return 0;
}


Measured memory_bytes: 13692
import sys
from collections import Counter
from collections import deque
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
s=list(input())
ans=0
for i in range(1,n):
    ans=max(ans,len(list(set(s[:i]) & set(s[i:]))))
print(ans)

Measured memory_bytes: 5324
using System;
using System.Linq;

public static class Program
{
    
    public static int Main(string[] args)
    {
        
        int[] n = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        
        if(n[0] > n[1])
        {
            Console.WriteLine("a > b");
        }
        else if(n[0] < n[1])
        {
            Console.WriteLine("a < b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
        
        return 0;
        
    }
}


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

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

    int x = n;
    int s = 0;
    while (x != 0) {
        s += x % 10;
        x /= 10;
    }
    if (n % s == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int a, b;
	bool c = false;
	while (cin >> a >> b&&(a||b)) {
		if (c)cout << endl;
		c = true;
		int count = 0;
		for (int i = a; i <= b; i++) {
			if (i % 4 == 0) {
				if (i % 100 != 0) {
					cout << i << endl;
					count++;
				}
				else {
					if (i % 400 == 0) {
						cout << i << endl;
						count++;
					}
				}
			}
		}
		if (count == 0) {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3056
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer k = Integer.parseInt(scanner.next());
        Integer da[][] = new Integer[k][];
        Boolean[] total = new Boolean[n];

        for(int i= 0; i < n; i++) {
            total[i] = false;
        }

        for(int i = 0; i < k; i++) {
            int tmp = Integer.parseInt(scanner.next());
            ArrayList list = new ArrayList();
            for(int j = 0; j < tmp; j++) {
               list.add(Integer.parseInt(scanner.next()));
            }
            da[i] = (Integer[])list.toArray(new Integer[tmp]);
        }

        for(int i = 0; i < da.length; i++) {
            for(int j = 0; j < da[i].length; j++) {
                total[da[i][j] -1] = true;
            }
        }
        int count = 0;
        for(int i =0; i < total.length; i++){
            if(total[i] == false) count++;
        }

        System.out.println(count);
    }
}


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

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

    int n;
    cin >> n;
    set<string> st;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << (int)st.size() << endl;

    return 0;
}

Measured memory_bytes: 19196
n=int(input())
ii,jj=[0]*n,[0]*n
b=0
for i in range(n):
  s=input()
  for j in range(n):
    k=1if"#"==s[j] else 0
    ii[i]+=k
    jj[j]+=k
    b+=k
if b==0:print(-1);exit()
c=n-jj.count(n)
mi=10000
for i in range(n):
  x=n-ii[i]
  if jj[i]==0:x+=1
  mi=min(x,mi)
print(mi+c)


Measured memory_bytes: 3064
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

int N, T;
int c[1010], t[1010];
int minCost = INF;

int main() {
	cin >> N >> T;
	REP(i, N) {
		cin >> c[i] >> t[i];
		if (t[i] <= T) minCost = min(minCost, c[i]);
	}
	if (minCost == INF) cout << "TLE" << endl;
	else cout << minCost << endl;
}

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

int main(){
  int x, a, b, A, B;
  cin >> x >> a >> b;
  
  if(a - x < 0){
    A = x - a; 
  }else{
    A = a - x;
  }
  
  if(b - x < 0){
    B = x - b; 
  }else{
    B = b - x;
  }
  
  if(A < B){
    cout << 'A' << endl;
  }else{
    cout << 'B' << endl;   
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	int a,b;

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


	if (a < b)
		cout << "0" << endl;
	else
		cout << "10" << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    h, w, m = MI()
    targets = [[] for i in range(h)]
    tate = [[] for i in range(w)]
    tate_length = [0] * w
    original = []
    lengths = [0] * h
    for i in range(m):
        target = LI()
        original.append(target)
        targets[target[0] - 1].append(target[1] - 1)
        tate[target[1] - 1].append(target[0] - 1)
        lengths[target[0] - 1] += 1
        tate_length[target[1] - 1] += 1

    max_length = max(lengths)
    max_length_tate = max(tate_length)

    max_w_indexes = [i for i, x in enumerate(
        tate_length) if x == max_length_tate]

    max_h_indexes = [i for i, x in enumerate(
        lengths) if x == max_length]

    max_h_indexes = set(max_h_indexes)
    max_w_indexes = set(max_w_indexes)

    ttl = len(max_h_indexes) * len(max_w_indexes)

    for target in original:
        if target[0] - 1 in max_h_indexes and target[1] - 1 in max_w_indexes:
            ttl -= 1

    if ttl > 0:
        print(max_length + max_length_tate)
    else:
        print(max_length+max_length_tate - 1)


main()


Measured memory_bytes: 236700
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var b = check(s);
        Console.WriteLine(b? "Yes":"No");
    }
    static bool check(string s)
    {
        while (true)
        {
            if (s.IndexOf("ABC") < 0) return false;
            if (s == "ABC") return true;
            if (s.Length > 3 && s.Substring(0, 3) == "ABC")
            {
                var w = s.Replace("ABC", "A");
                s = w;
            }
            else if (s.Length > 3 && s.Substring(s.Length - 3) == "ABC")
            {
                var w = s.Replace("ABC", "C");
                s = w;
            }
            else if (s.Length > 3)
            {
                var t = s.Replace("ABC", "");
                if (t.IndexOf("ABA") >= 0 | t.IndexOf("CBC") >= 0) return false;
                var w = s.Replace("ABC", "B");
                s = w;
            }
        }
    }
}



Measured memory_bytes: 32452
S = input()
T = input()
lS = len(S)
lT = len(T)
C = []
for i in range(lS-lT+1):
    count = 0
    for j in range(lT):
        if S[i+j]!=T[j]:
            count += 1
    C.append(count)
print(min(C))           

Measured memory_bytes: 73136
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int r, D; cin>>r>>D;
  int X[11];
  cin>>X[0];
  for(int i=1; i<=10; i++){
    X[i]=r*X[i-1]-D;
    cout<<X[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int r;
    cin >> r;
    double ans = double(r * 2 * 3.141592653589);
    printf("%.3f\n", ans);
}

Measured memory_bytes: 3728
//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[100001];
    ll dp[100001];
    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i = 2; i < n; i++)
    {
        ll ans = 1000000000;
        for(int j = i-1; j >= 0; j--)
        {
            if(i-j > k)
            {
                break;
            }
            ans = min(ans, dp[j]+abs(a[i]-a[j]));
        }
        dp[i] = ans;
    }
    
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 5168
import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
	Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int max = 0, cnt = 0;
    while (n --> 0)
    {
      int h = in.nextInt();
      if (h >= max)
      {
		max = h;
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
int main(){
	int n;
	cin>>n;
	ll out=1;
	rep(i,n){
		ll a;cin>>a;
		out=lcm(out,a);
	}
	cout<<out<<endl;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}*/
 
int main(){
  int x;
  cin>>x;
  int finished =3;
  
  for(;finished==3;x++){
    bool prime=true;
    for(int i=2;i<=316;i++){
      
      if(i*i<x && x%i ==0)prime=false;
      
    }
    if(prime){
      cout<<x<<endl;
      finished=4;
    
  }
  }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.length()<=k)
    cout<<s;
  else
  {
    string t=s.substr(0,k);
    t.push_back('.');
    t.push_back('.');
    t.push_back('.');
    cout<<t;
  }
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <time.h>
struct bc
{
    int b;
    int c;
};
void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
void swap2(struct bc * a, struct bc * b)
{
    struct bc t = *a;
    *a = *b;
    *b = t;
}
 
void print_int(int n)
{
    printf("%d\n",n);
    
}
 
void sort(struct bc a[], int n)
{
    int h, i, j;
 
    for(h = 1; h < n / 9; h = h * 3 + 1)
        continue;
 
    for(; h > 0; h /= 3)
    {
        for(i = h; i < n; i++)
        {
            j = i;
            while(j >= h && a[j].c < a[j-h].c)
            {
                swap2(&a[j], &a[j-h]);
                j -= h;
            }
        }
    }
}
 
void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
}
 
void intcpy(int a[], const int b[], int count)
{
    for(int i = 0; i < count; i++)
    {
        a[i] = b[i];
    }
}
 
int list_sum(int a[], int n)
{
    int sum = 0;
 
    for(int i = 0; i < n; i++)
    {
        sum += a[i];
    }
 
    return sum;
}
 
 
void permutate(int s[], int count, int n)
{
    if(n == count)
        return;
 
    for(int i = n; i < count; i++)
    {
        swap(&s[i], &s[n]);
 
        if(i != n)
        {
            //intcpy(result[j++], s, count);
        }
        
        permutate(s, count, n+1);
        swap(&s[i], &s[n]);
    }
}
int segmentation(int a[], int s, int e)
{
    int i, j, m, pivot;
 
    i = s - 1;
    j = e;
 
    //m = median(a, s, (s+e)/2, e);
    //swap(&a[j], &a[m]);
    pivot = a[j];
 
    while(1)
    {
        while(a[++i] < pivot)
            continue;
        
        while(i < j-- && pivot < a[j])
            continue;
        
        if(i >= j)
            break;
        else
            swap(&a[i], &a[j]);
        
    }
    swap(&a[i], &a[e]);
    return i;
}
void quick_routine(int a[], int s, int e)
{
    int c;
 
    if(s >= e)
        return;
 
    c = segmentation(a, s, e);
    quick_routine(a, s, c-1);
 
    quick_routine(a, c+1, e);
 
}
void quick_sort(int a[], int n)
{
    quick_routine(a, 0, n - 1);
}
 

 
 
int main(void)
{
 
    int n, m;
    scanf("%d %d", &n, &m);
    int card[n];
    int i = 0, j = 0, k = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &card[i]);
    }
    
    
    quick_sort(card, n);
    struct bc tuple[m];
    
    long long ans = 0;

    for (i = 0; i < m; i++)
    {
        scanf("%d %d", &tuple[i].b, &tuple[i].c);
    }

    sort(tuple, m);

    
    for (i = 0; i < m; i++)
    {
        for (j = 0; j < tuple[m-1-i].b && k < n; j++)
        {
            if(card[k] < tuple[m-1-i].c)
            {
                card[k] = tuple[m-1-i].c;
                k++;
            }
            else
            {
                goto jump;
            }   
        }
    }
    jump:
 
    for (int i = 0; i < n; i++)
    {
        ans += card[i];
    }
    printf("%lld\n", ans);
    
    
    
 
 
    
    
    
    
 
    return 0;
}

Measured memory_bytes: 1280
a, b, m = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
cost = []
for i in range(m):
  x, y, c = map(int, input().split())
  cost.append(arr_a[x - 1] + arr_b[y - 1] - c)
cost.append(min(arr_a) + min(arr_b))
ans = min(cost)
print(ans)

Measured memory_bytes: 24776
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,x,ok;
int main(){
    scanf("%d",&n);
    while(n--){
        scanf("%d",&x);
        ok^=x;
    }
    puts((ok&1)?"NO":"YES");
    //system("pause");
    return 0;
}


Measured memory_bytes: 256