akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //

//深さ優先探索　隣接リスト表現（重みなし）
//何か他に変数を持ちたい場合（ansなど）、グローバルで宣言してしまうこと

ll N, K;

using AdjList_Unweighted = vector<vector<ll>>;
vector<bool> seen;
ll dfs(AdjList_Unweighted &graph, ll node_id){
  seen[node_id]=true;

  //行きがけの処理はここで
  ll ans = 1;
  ll colors;
  if (node_id==0){
    colors = K - 1;
  }
  else {
    colors = K - 2;
  }

  for(auto each_adj : graph[node_id]){
    if(seen[each_adj]){
      continue;
    }
    ans *= colors * dfs(graph, each_adj) % MOD;
    colors--;
    ans %= MOD;
  }

  //帰りがけの処理はここで
  return ans;

}

// ----- library end ----- //



int main() {

  cin >> N >> K;

  //隣接リスト表現
  ll a, b;
  AdjList_Unweighted Adjs(N);
  while(cin >> a >> b){
    a -= 1;
    b -= 1; //0-indexed
    Adjs.at(a).PB(b);
    Adjs.at(b).PB(a);
  }

  seen.assign(N, false);
  cout << K * dfs(Adjs, 0) % MOD << endl; //グラフと、最初に探索するノードIDを渡す


// -- main() end -- //
}



Measured memory_bytes: 10368
#include<iostream>
using namespace std;
int main()
{
    int a;
    int b;
    int anss=1;
    cin>>a>>b;
    if(b==1) cout<<0;
    else{
    for(int ans=1;a*ans+1-ans<b;ans++)
       {
         anss=ans+1;
       }
    cout<<anss;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*  T_T0210 */
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int D = B % 2;
  int E = B / 2;
  if ( D == 1 ) {
    cout << "No" <<endl;
  }
  else if ( A > E ) {
    cout << "No" <<endl;
  }
  else if ( A * 4 >= B ) {
    cout << "Yes" <<endl;
  }
  
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
vector<int> G[50];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N>>M;
  rep(i, M){
    int a,b;
    cin>>a>>b;a--,b--;G[a].pb(b);G[b].pb(a);
  }
  rep(i,N) {
    cout<<G[i].size()<<"\n";
  }
  return 0;
}


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

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

	map<string, bool> gift_map;

	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		gift_map[s] = true;
	}
	int count = 0;
	for (auto itr = gift_map.begin(); itr != gift_map.end(); itr++) {
		count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 19280
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll N = 4000005;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll dx[4] = {1,0,-1,0};
const ll dy[4] = {0,1,0,-1};
 
ll pi[N];
bool done[500005];
ll f[500005];
bool vis[500005];
 
string s,t,k,r;
ll m,n;
 
ll dfs(ll i){
    if(f[i]==-1){
        return M;
    }
    if(vis[i]){
        return f[i];
    }
    vis[i]=1;
    if(done[i]){
        f[i]=-1;
        return f[i] = dfs((i+m)%n) + 1;
    }
}
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>s>>t;
    n=s.length();
    m=t.length();
    ll l=0;
    while(l<m){
        l+=n;k+=s;
    }
    r = t+k+s;
    l = r.length();
    rep(i,1,l){
        ll j=pi[i-1];
        while(j>0 and r[i]!=r[j])   j=pi[j-1];
        if(j>=m){
            j=pi[j-1];
            while(j>0 and r[i]!=r[j])   j=pi[j-1];
        }
        if(r[i]==r[j])  j++;
        pi[i]=j;
    }
    rep(i,l-n,l){
        if(pi[i]==m)    done[i-(l-n)]=1;
    }    
    rep(i,0,n){
        if(!vis[i]){
            ll j=dfs(i);
        }
    }
    ll ans=0;
    rep(i,0,n)  ans=max(ans,f[i]);
    if(ans>=n){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 35040
n=int(input())
A=list(map(int, input().split()))
def f(i):
  if A[i]>=A[i-1]:
    return 0
  else:
    d=A[i-1]-A[i]
    A[i]=A[i-1]
    return d
  	
ans=0
for i in range(1,n):
  ans+=f(i)
print(ans)

Measured memory_bytes: 32296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    queue<ll> q;
    rep(i, k) q.push(a[i]);
    for (int i = k; i < n; ++i) {
        ll f = q.front(); q.pop();
        q.push(a[i]);
        if (f < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 6328
#include<iostream>
using namespace std;
int main () {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b == c) {
    if (a == b || d == c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int SZ=100005;

vector<pint> v[SZ];
pint id[SZ];

signed main()
{
    int N,M;
    cin>>N>>M;

    REP(i,M){
        int p,y; cin>>p>>y;
        v[p-1].push_back(pint(y,i));
    }
    
    REP(i,N){
        if(v[i].empty()) continue;
        sort(ALL(v[i]));
        REP(j,v[i].size()){
            int idx=v[i][j].second;
            id[idx]=pint(i+1,j+1);
        }
    }
    
    REP(i,M){
        printf("%06lld%06lld\n",id[i].first,id[i].second);
    }

}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int W, H, x, y;

// 2分探索のテンプレ
int bin() {
   auto check = [&](int mid) -> bool {
      // 判定処理を書く
      // 閉区間の方を >=, <= にする
   };

   int l = -1; // 条件を満たさないと分かっている数を適当に
   int r = W; // 条件を満たすと分かっている数を適当に

   // [l, r) か (l, r] か気をつける
   while (r - l > 1) { // 答えの整数範囲が1つになるまで繰り返し
      int mid = (l + r) / 2;
      if (check(mid)) {
         r = mid; // 場合によって異なる
      } else {
         l = mid; // 場合によって異なる
      }
   }

   return r; // 場合によって異なる
}

signed main() {
	cin >> W >> H >> x >> y;
	double ans = 1.0 * W * H / 2;
	int more = 0;
	if (H%2 == 0 and y == H/2 and W%2 == 0 and x == W/2) {
		more = 1;
	}

	printf("%.10lf %lld\n", ans, more);

	// if (x > 0 and x < W and y > 0 and y < H) {
	// }

	/*
	double ans = 2e18;
	int more = 0;
	if (x > 0 and x < W and y > 0 and y < H) {
		double a = min(y*W, (H-y)*W);
		double b = min(x*H, (W-x)*H);
		ans = max(a, b);
	} else {
		ans = min(y * W, (H-y)*W);
	}


	*/

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int, n)
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		m[a]++
	}

	b := []int{}
	for k, v := range m {
		if v >= 2 {
			b = append(b, k)
			v -= 2
		}
		if v >= 2 {
			b = append(b, k)
		}
	}
	sort.Ints(b)

	if len(b) >= 2 {
		fmt.Println(b[len(b)-1] * b[len(b)-2])
	} else {
		fmt.Println(0)
	}
}


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

namespace AtCoderABC115
{
    class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> l = new List<int>();
            for (int i = 0; i < N; i++)
            {
                l.Add(int.Parse(Console.ReadLine()));
            }
            l = l.OrderByDescending(x => x).ToList();
            int res = l[0] / 2;
            for (int i = 1; i < N; i++)
            {
                res += l[i];
            }
            Console.WriteLine(res);
        }
    }
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

int main(){
    fcin;
    int h, w, k;
    cin >> h >> w >> k;

    vector<string> line(h);
    for(int i = 0; i < h; i++){
        cin >> line[i];
    }

    int ans = INF;
    for(int i = 0; i < (1 << (h - 1)); i++){
        vector<int> hcut(h, 0);
        int hans = __builtin_popcount(i);
        for(int j = 0; j < h; j++) hcut[j] = (i >> j) & 1;
        hcut[h-1] = 1;

        vector<vector<int>> cell(hans+1, vector<int>(w, 0));
        bool bad = false;
        for(int j = 0; j < w; j++){
            int cnt = 0;
            int c = 0;
            for(int r = 0; r < h; r++){
                cnt += line[r][j] == '1';
                if(cnt > k) bad = true;
                if(hcut[r]) cell[c++][j] = cnt, cnt = 0;
            }
        }

        vector<int> sum(hans+1, 0);

        int cc = cell.size();
        int vans = 0;
        for(int j = 0; j < w; j++){
            bool cut = false;
            for(int c = 0; c < cc; c++){
                if(sum[c] + cell[c][j] > k) cut = true;
            }

            if(cut) vans++;
            for(int c = 0; c < cc; c++){
                if(!cut) sum[c] += cell[c][j];
                else sum[c] = cell[c][j];
            }
        }

        if(bad) continue;
        
        ans = min(ans, vans + hans);
    }

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



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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

int n, q;
vi v;

int root(int x)
{
    if(v[x] == x) return x;
    return v[x] = root(v[x]);
}

void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    v[rx] = ry;
}

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> n >> q;
    v.resize(n); REP(i, n) v[i] = i;
    REP(i, q)
    {
        int com, x, y; cin >> com >> x >> y;
        if(com == 0)
        {
            unite(x, y);
        }
        else
        {
            cout << same(x, y) << endl;
        }
    }
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%d",&a)
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>bool is_palindrome(T s){T s1=s;reverse(s1.begin(),s1.end());if(s==s1)return true;return false;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    ll t,mx=0,ans=0;
    scanf("%lld",&t);
    for(int i=0; i<t; i++){
        ll x;
        scl(x);
        ans+=x;
        mx=max(mx,x);
    }
    cout<<ans-mx+(mx/2)<<endl;
    return 0;
}


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

using namespace std;

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

    int ans = 0;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += x-1;
    }

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


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

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = tokens[0]
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = tokens[0]

    s = lines[1]


    return (n, s)


def solve(n, s):



    sum_r = len([1 for c in s if c == "R"])

    result = "No"
    if sum_r > int(n) - sum_r:
        result = "Yes"

    return result

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


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

int main() {
  string A, B;
  cin >> A >> B;
  
  if (A.size() > B.size()) {
    cout << "GREATER" << endl;
  } else if (A.size() < B.size()){ 
    cout << "LESS" << endl;
  } else {
    if (A > B) {
      cout << "GREATER" << endl;
    } else if (A < B) {
      cout << "LESS" << endl;
    } else {
      cout << "EQUAL" << endl;
    }
  }
  
}

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

using namespace std;
int n, m, ans, h[100005], a[100005], b[100005], c[100005];
int main()
{
    cin>> n>> m;
    for(int i=1; i<=n; i++) cin>> h[i];
    for(int i=1; i<=m; i++){
        cin>> a[i]>> b[i];
        if(h[a[i]] == h[b[i]]){
            c[a[i]]=-1;
            c[b[i]]=-1;
        }
        else if(h[a[i]] < h[b[i]]) c[a[i]]=-1;
        else c[b[i]]=-1;
    }
    for(int i=1; i<=n; i++)
        if(c[i]!=-1)
            ans++;
    cout<< ans;
    return 0;
}


Measured memory_bytes: 5132
#include <iostream>
#include <string>
#include <cctype>

int main() {

	std::string a, b;
	std::getline(std::cin, a);
	for (int i = 0; i < a.size(); i++) {
		if (islower(a[i])) {
			a[i] = toupper(a[i]);
		}
		else if (isupper(a[i])) {
			a[i] = tolower(a[i]);
		}
		std::cout << a[i];
	}
	std::cout << std::endl;
	
}



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

int main(void)
{
    int A,B; cin >> A >> B;
    int tasu = A+B;
    int hiku = A-B;
    int kakeru = A*B;

    int tmp = tasu;
    if(tmp < hiku) tmp = hiku;
    if(tmp < kakeru) tmp = kakeru;
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	char[][] abacus = {
			{'*','*','*','*','*',' ',' ',' ',' ',' '},
			{' ',' ',' ',' ',' ','*','*','*','*','*'},
			{'=','=','=','=','=','=','=','=','=','='},
			{' ','*','*','*','*',' ','*','*','*','*'},
			{'*',' ','*','*','*','*',' ','*','*','*'},
			{'*','*',' ','*','*','*','*',' ','*','*'},
			{'*','*','*',' ','*','*','*','*',' ','*'},
			{'*','*','*','*',' ','*','*','*','*',' '}
	};
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(true){
			String str = scan.nextLine();
			int[] num = new int[5];
			for(int i = 5-str.length(),j = 0;j < str.length();i++,j++){
				num[i] = (int)(str.charAt(j) - '0');
			}
			for(int i = 0;i < 8;i++){
				for(int j = 0;j < 5;j++){
					System.out.print(abacus[i][num[j]]);
				}
				System.out.println();
			}
			if(!scan.hasNext()){
				break;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 32084
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

vector<pii> adj[300];

int main() {
	fastio;
	int N, M, L;
	cin >> N >> M >> L;

	for (int a, b, c, i = 0; i < M; ++i) {
		cin >> a >> b >> c;
		adj[--a].push_back({ --b, c });
		adj[b].push_back({ a, c });
	}

	int dist[300][300], len[300][300]{};
	ini(dist, 0x3f);

	for (int i = 0; i < N; ++i) {
		using T = tuple<int, int, int>;
		priority_queue<T, vector<T>, greater<T>> PQ;
		bool vis[300]{};

		PQ.push(T{ 0, 0, i });
		dist[i][i] = 0;

		while (!PQ.empty()) {
			int cnt, val, now;
			tie(cnt, val, now) = PQ.top(); PQ.pop();

			if (vis[now]) continue;
			vis[now] = 1;
			dist[i][now] = cnt;

			for (auto &nxt : adj[now]) {
				int v = nxt.X, d = nxt.Y;
				if (L < d) continue;

				if (val + d > L) {
					if (dist[i][v] < cnt + 1 ||
						dist[i][v] == cnt + 1 && len[i][v] < d) continue;

					dist[i][v] = cnt + 1;
					len[i][v] = d;
					PQ.push(T{ cnt + 1, d, v });
				}
				else {
					if (dist[i][v] < cnt ||
						dist[i][v] == cnt && len[i][v] < val + d) continue;

					dist[i][v] = cnt;
					len[i][v] = val + d;
					PQ.push(T{ cnt, val + d, v });
				}
			}
		}
	}

	int Q;
	cin >> Q;

	for (int s, t; Q--; ) {
		cin >> s >> t;
		cout << (dist[--s][--t] == 0x3f3f3f3f ? -1 : dist[s][t]) << endl;
	}

	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

int main() {
	fastio;
	int r; cin >> r;
	double ans = 2 * 3.14159 * r;
	cout << setprecision(6) << ans << endl;
	return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,s[100000],t[100000],ans;
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++)cin>>s[i];
    sort(s,s+m);
    for(int i=0;i<m-1;i++)t[i]=s[i+1]-s[i];
    //for(int i=0;i<m-1;i++)cout<<t[i]<<endl;
    sort(t,t+m-1);
    reverse(t,t+m-1);
    for(int i=0;i<m-1;i++){
        if(n>1){
            n--;
        }
        else ans+=t[i];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main(){
    int h, w;

    while(1){
        cin >> h >> w;
        if (h == 0 && w == 0) return 0;
        for (int i = 0; i < h; i++ ){
            for (int j = 0; j < w; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

const int maxn = 1e4 + 5;
int inf = 1e9 + 7;

vector<int> G[maxn],cost[maxn];
queue<int> seq;
int n,m,dis[maxn],vis[maxn];

void spfa(int x){
	for(int i = 0;i <= 9;i++) dis[i] = inf;
	dis[x] = 0;
	seq.push(x),vis[x] = 1;
	while(!seq.empty()){
		int u = seq.front();
		for(int i = 0;i < G[u].size();i++){
			int v = G[u][i];
			if(dis[u] + cost[u][i] < dis[v]){
				dis[v] = dis[u] + cost[u][i];
				if(!vis[v]){
					seq.push(v);
					vis[v] = 1;
				}
			}
		}
		if(!seq.empty()) seq.pop(),vis[u] = 0;
	}
}

int main(){
	long long sum = 0;
	scanf("%d %d\n",&n,&m);
	for(int i = 0;i <= 9;i++){
		for(int j = 0;j <= 9;j++){
			long long w;
			scanf("%lld",&w);
			G[j].push_back(i);
			cost[j].push_back(w);
		}
	}
	spfa(1);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			int x;
			scanf("%d",&x);
			if(x != -1) sum += dis[x];
		}
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 768
// AOJ 0118

import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

    private static char[][] orchard;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt(), W = sc.nextInt();
            if (H == 0 && W == 0) return;

            orchard = new char[H][];
            for (int i = 0; i < H; i++) {
                orchard[i] = sc.next().toCharArray();
            }

            int count = 0;
            ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
            int[][] direction = {
                {0, 1}, {0, -1}, {1, 0}, {-1, 0}
            };
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (orchard[i][j] != '.') {
                        count++;
                        queue.add(new int[] {i, j});
                        char fruit = orchard[i][j];
                        orchard[i][j] = '.';
                        while (!queue.isEmpty()) {
                            int[] loc = queue.poll();
                            int x = loc[0], y = loc[1];
                            for (int[] d: direction) {
                                int dx = d[0], dy = d[1];
                                if (0 <= x + dx && x + dx < H &&
                                    0 <= y + dy && y + dy < W &&
                                    orchard[x+dx][y+dy] == fruit) {
                                    queue.add(new int[] {x+dx, y+dy});
                                    orchard[x+dx][y+dy] = '.';
                                }
                            }
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 29408
open System
let input =stdin.ReadLine().Split()|> Array.map int
let A =input.[0]
let B =input.[1]
[<EntryPoint>]
let sf argv = 
    let minus x = x-1
    let rec tap cur a b = if cur >= b then 0 else (tap (cur+minus a) a b)+1 
    tap 1 A B|>stdout.WriteLine
    0


Measured memory_bytes: 11220
#include<stdio.h>

int main(void){

  int N;
  int L[10] = {0};
  int max = 0;
  int max_num = 0;
  scanf("%d", &N);
  
  for(int i = 0 ; i < N ; i++){
    scanf("%d" , &L[i]);
    
    if(L[i] > max){              //最大値とその場所を記憶
      max = L[i];
      max_num = i;
    }
    
  }


  int sum = 0;
  for(int i = 0 ; i < N ; i++){
    if(i == max_num) continue;   //最大数の場所なら足さなくていい

    sum += L[i];
  }

  if(sum > max){
    puts("Yes");
  }else{
    puts("No");
  }    
  
  return 0;
}

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

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

	if((abs(b-a)<=d&&abs(c-b)<=d)||abs(a-c)<=d)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}



Measured memory_bytes: 256
from collections import deque



R, C = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())

sy, sx, gy, gx = sy-1, sx-1, gy-1, gx-1
maze = [list(input()) for i in range(R)]
d = deque()
ds = deque()
maze[sy][sx] = 0
d.append([sy, sx])
ds.append([sy, sx])
while(d or ds):
  while(d):
    [y, x] = d.popleft()
    ds.append([y, x])
    if (y, x) == (gy, gx):
      print(maze[gy][gx])
      exit()
    for [dy, dx] in [[1,0], [-1,0], [0,1], [0,-1]]:
      ny = y + dy
      nx = x + dx
      if  R > ny and ny >= 0 and C > nx and nx >= 0 and maze[ny][nx] == ".":
        maze[ny][nx] = maze[y][x]
        d.append([ny, nx])
        ds.append([ny, nx])

  while(ds):   
    [y, x] = ds.popleft()
    for [dy, dx] in [[2,2], [2,1], [2,0], [2,-1], [2,-2],
                     [1,2], [1,1], [1,-1], [1,-2], [0,-2], 
                     [0,2], [-1,2], [-1,1], [-1,-1], [-1,-2],
                     [-2,2], [-2,1], [-2,0], [-2,-1], [-2, -2]]:
      ny = y + dy
      nx = x + dx
      if  R > ny and ny >= 0 and C > nx and nx >= 0 and maze[ny][nx] == ".":
        maze[ny][nx] = maze[y][x]+1
        d.append([ny,nx])
        
        
print(-1)
      
  

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, X, T;
    cin >> N >> X >> T;
    PR((N+X-1)/X*T);

    return 0;
}

/*



*/

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int main(void){
    int n, k, h[100010];
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h, h + n);
    
    int ans = 1e9;
    for (int i = 0; i + k - 1 < n; i++) {
        if (ans > h[i + k - 1] - h[i]) ans = h[i + k - 1] - h[i];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 640
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll per(ll a){
  ll res = 1;
  for(int i = 1;i <= a;i++){
    res *= i;
  }
  return res;
}

int main(){
  ll N;
  cin >> N;
  vector<long double> x(N),y(N);
  rep(i,N)cin >> x[i] >> y[i];
  vector<vector<int>> kumi;
  vector<int> v;
  for(int i = 1;i <= N;i++)v.push_back(i);
  do{
    kumi.push_back(v);
  }while(next_permutation(v.begin(), v.end()));
  long double ans = 0;
  for(auto a : kumi){
    rep(i,a.size()-1){
      long double t = (x[a[i]-1]-x[a[i+1]-1])*(x[a[i]-1]-x[a[i+1]-1]);
      t += (y[a[i]-1]-y[a[i+1]-1])*(y[a[i]-1]-y[a[i+1]-1]);
      ans += sqrt(t);
    }
  }
  long double all = kumi.size();
  ans /= all;
  cout << fixed << setprecision(8) << ans << endl;

  return 0;
}


Measured memory_bytes: 6524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    private static List<List<int>> comb = new List<List<int>>();

    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var N = int.Parse(input[0]);
        var M = int.Parse(input[1]);
        var Q = int.Parse(input[2]);

        var a = new List<int>();
        var b = new List<int>();
        var c = new List<int>();
        var d = new List<int>();
        for (int i = 0; i < Q; i++)
        {
            var line = Console.ReadLine().Split(" ");
            a.Add(int.Parse(line[0]));
            b.Add(int.Parse(line[1]));
            c.Add(int.Parse(line[2]));
            d.Add(int.Parse(line[3]));
        }

        var A = new List<int>();
        DFS(A, N, M);

        var max = 0;
        foreach (var item in comb)
        {
            var sum = 0;
            for (int i = 0; i < Q; i++)
            {
                var num1 = item[b[i] - 1];
                var num2 = item[a[i] - 1];
                if (num1 - num2 == c[i]) sum += d[i];
            }

            max = Math.Max(sum, max);
        }

        Console.WriteLine(max);
    }

    private static void DFS(List<int> list, int size, int maxValue)
    {
        if(list.Count == size)
        {
            comb.Add(new List<int>(list));
            return;
        }

        int last = (list.Count == 0 ? 1 : list[list.Count - 1]);
        for (int i = last; i <= maxValue; i++)
        {
            list.Add(i);
            DFS(list, size, maxValue);
            list.Remove(i);
        }
    }
}


Measured memory_bytes: 38028
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        DecimalFormat df = new DecimalFormat("0.000000");
        double r = sc.nextDouble();
        double area = r * r * Math.PI;
        double circumference = r * 2.0 * Math.PI;
        System.out.print(df.format(area) + " ");
        System.out.println(df.format(circumference));
    }
}


Measured memory_bytes: 27984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<ll>> Matrix;
const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};
 
vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

// firstに素数, secondに何乗かが入る
vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i, 0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if ( n != 1) res.emplace_back(n, 1);
  return res;
} 

long long fastpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  vector<P> fact = factorize(n);
  map<ll, ll> mp;
  vector<ll> candidates;
  set<ll> s;
  for(auto f: fact) {
    rep1(i, f.second) {
      s.insert(fastpow(f.first, i));
    }
  }
  ll ans = 0;
  for(auto z: s) {
    if (n % z) continue;
    n /= z;
    ans++;
    if (n < z) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3656
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

int main(){
	fastIO;
	int n;
	string bun;
	string before = "Hoshino", after = "Hoshina";
	// cinに続きgetlineする場合は改行読み捨てを行う.
	// 参考：http://wikiwiki.jp/kyopro/?%A5%D7%A5%ED%A5%B0%A5%E9%A5%DF%A5%F3%A5%B0%A4%CE%A5%C6%A5%AF%A5%CB%A5%C3%A5%AF%2F%C6%FE%CE%CF%A4%CE%BD%E8%CD%FD%28C%2CC%2B%2B%29
	
	// 文字列操作 参考：http://minus9d.hatenablog.com/entry/20120519/1337412307

	cin >> n; cin.ignore();
	while (n--){
		getline(cin, bun);
		
		int pos = bun.find(before);
		while (pos != string::npos){
			bun.replace(pos, before.size(), after);
			pos = bun.find(before, pos + after.size());
		}

		cout << bun << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    ans = sum(a)

    a[n], b[n-1] = fight(a[n], b[n-1])

    for i in range(n-1, 0, -1):
        a[i], b[i] = fight(a[i], b[i])
        a[i], b[i-1] = fight(a[i], b[i-1])

    a[0], b[0] = fight(a[0], b[0])
    print(ans-sum(a))


def fight(m, h):
    if m <= h:
        return 0, h-m
    else:
        return m-h, 0


if __name__ == "__main__":
    main()


Measured memory_bytes: 76416
#include <stdio.h>

int main(void)
{

  char s[105];
  int n=0;

  fgets(s, sizeof(s), stdin);

  for (int i=0; s[i] != '\n'; i++) {
    ++n;
  }

  printf("%c%d%c\n", s[0], n-2, s[n-1]);
  
  return 0;
}


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

int main() {
  ll a, b;
  cin >> a >> b;
  if(a%2!=b%2) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	int n, k;
	string s;
	cin >> n >> k >> s;

	if (s.at(k - 1) == 'A')
	{
		s.at(k - 1) = 'a';
	}
	else if (s.at(k - 1) == 'B')
	{
		s.at(k - 1) = 'b';
	}
	else
	{
		s.at(k - 1) = 'c';
	}
	
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N,x;
  cin>>N>>x;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int64_t sum=0;
  for(int i=0;i<N;i++){
    if(a[i]>x){sum+=(a[i]-x);a[i]=x;}  
  }
  for(int i=0;i<N-1;i++){
    if(a[i]+a[i+1]>x){
      int64_t c=a[i]+a[i+1]-x;
      if(c>=a[i+1]){a[i+1]=0;a[i]-=(c-a[i+1]);}
      else if(c<a[i+1]&&c>=0){a[i+1]-=c;}
      sum+=c;
    }
  }
  cout<<sum<<endl;
  return 0;
}

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

int minCost(int a[], int n, int k){
	int dp[n];
  	dp[0]=0;
  	for(int i=1;i<n;i++)
      dp[i]=INT_MAX;
  	for(int i=0;i<n;i++){
    	for(int j=i+1;j<=i+k;j++){
          if(j<n){
        	dp[j]=min(dp[j],dp[i] + abs(a[j]-a[i]));
          }
        }
    }
  return dp[n-1];
}

int main(){
	int n,k;
  	cin>>n;
  	cin>>k;
  	int a[n];
  	for(int i=0;i<n;i++){
    	cin>>a[i];
    }
  	cout<<minCost(a,n,k);
}

Measured memory_bytes: 4360
N,M = map(int, input().split())
L = []
ans = []
for i in range(M):
	L.append(list(map(int, input().split())))
	ans.append(False)

for i in range(10**N):
    num = str(i)
    if len(num) == N:
        for j,l in enumerate(L):
            if num[l[0]-1] == str(l[1]):
                ans[j] = True 
                continue
            else:
                break
        if all(ans):
            print(i)
            break
if not all(ans):
  print(-1)

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define      TEST    ll t ; cin >> t ; while( t -- )


//------------------------------------------------------------------------//

#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)

//------------------------------------------------------------------------//


const ll big = 10e10 + 11 ;


int  main (  ) {

    FASTIO ;

    int k, a, b ;
    cin >> k >> a >> b ;

    int f = 0 , x = k ;

    for( int i = 1 ;  ; i++ ){
        x = i *k  ;

        //cout << x << "\n" ;
        if( x >= a && x <= b ) {
            f = 1 ;
            break ;
        }
        else if( x > b ) break ;
    }

    if( f ) cout << "OK" ;
    else  cout << "NG";


    return  0 ;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(){
	int n,pa,pb,a,b;
	while(cin>>n){
		if(n==0){break;}
		pa=pb=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			if(a>b){
				pa+=a+b;
			}else if(b>a){
				pb+=a+b;
			}else{
				pa+=a;
				pb+=b;
			}
		}
		cout<<pa<<" "<<pb<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a, b, c;
  cin >> a >> b >> c;

  ll t = c - a - b;

  string ans;
  if (t > 0 && 4 * a * b < t * t) {
    ans = "Yes";
  } else {
    ans = "No";
  }

  cout << ans << ln;

  return 0;
}

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

const int N = 105;
int ara[N];
int n;

int main( )
{
    int i, j, k, s, mn = 1e9;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
    }
    for (i = -101; i <= 101; i++) {
        s = 0;
        for (j = 1; j <= n; j++) {
            s += ((ara[j] - i) * (ara[j] - i));
        }
        mn = min(s, mn);
    }
    cout << mn << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,n,a,x[50],j;
  long long int dp[51][5001]={};
  scanf("%d %d",&n,&a);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    x[i]-=a;
  }
  dp[0][n*50]=1;
  for(i=0;i<n;i++){
    for(j=0;j<=2*n*50;j++){
      if((j-x[i])<=n*100&&(j-x[i])>=0)
        dp[i+1][j]=dp[i][j]+dp[i][j-x[i]];
      else
        dp[i+1][j]=dp[i][j];
    }
  }
  printf("%ld\n",dp[n][50*n]-1);
}


Measured memory_bytes: 2176
import itertools

N = int(input())
P = [int(i) for i in input().split()]
# P = "".join([i for i in input().split()])
Q = [int(i) for i in input().split()]

# def factorial(n):
#     if n == 1:
#         return 1
#     else:
#         return n * factorial(n-1)


n = sorted(list(itertools.permutations(P)))
# q = sorted(list(itertools.permutations(Q)))
p = n.index(tuple(P))+1
q = n.index(tuple(Q))+1
print(abs((p - q)))


Measured memory_bytes: 8308
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, T[10], x;
	while (cin >> n && n) {
		for (int i = 0; i < 10; i++)
			T[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> x;
			T[x]++;
		}
		for (int i = 0; i < 10; i++) {
			if (T[i] == 0)
				cout << "-" << endl;
			else {
				for (int j = 0; j < T[i]; j++)
					cout << "*";
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */

ull pow(ull x,ull n) {
  ull res = 1;
  while(n > 0) {
    if(n&1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14])
{
  int j;
  int f = 1;
  int g = 0;
  for(j = 0;;j++) {
    if(str[j] == 'A')
      g += f * 1;
    else if(str[j] == 'C')
      g += f * 2;
    else if(str[j] == 'G')
      g += f * 3;
    else if(str[j] == 'T')
      g += f * 4;
    else break;
    f *= 5;
  }
  return g; 
}

int main()
{
  static long i,j,k,l;
  long n;
  long cnt = 0;
  int f,g;
  long left,right,mid;
  long ans = 0;
  static int dic[200000000];
  char opstr[14];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s",opstr,str);
    if(opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    }
    else if(opstr[0] == 'f') {
      if(dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}

Measured memory_bytes: 39172
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

bool get (char c) {
	return ((c == 'A') ? 1 : 0);
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	string s, res;
	cin >> n >> k >> s;
	int num = 0;
	bool f = 0;
	for (int i = 0; i < n; i++) {
		if (get(s[i]) ^ f)
			num++;
		if (num == k) {
			res = "B";
			for (int t = i + 1; t < n; t++)
				if (f)
					res += ((s[t] == 'A') ? "B" : "A");
				else
					res += s[t];
			for (int t = 0; t < i; t++)
				res += (((i - t) % 2) ? "A" : "B");
			cout << res << "\n";
			return 0;
		}
		f = 1 - f;
		num++;
		if (num == k) {
			for (int t = i + 1; t < n; t++)
				if (f)
					res += ((s[t] == 'A') ? "B" : "A");
				else
					res += s[t];
			for (int t = 0; t < i + 1; t++)
				res += (((i - t) % 2) ? "B" : "A");
			cout << res << "\n";
			return 0;
		}
	}
	if (n == 1) {
		if (k % 2)
			cout << ((s[0] == 'A') ? "B" : "A") << "\n";
		else
			cout << s[0] << "\n";
		return 0;
	}
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++)
			cout << ((i % 2) ? "A" : "B");
		cout << "\n";
		return 0;
	}
	k -= num;
	if (k % 2 == 1)
		cout << "BB";
	else
		cout << "AB";
	for (int i = 2; i < n; i++)
		cout << ((i % 2) ? "B" : "A");
	cout << "\n";
}



Measured memory_bytes: 1044
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
using namespace std;

int n;

vector<int> uf;

void initialize(int n)
{
  uf = vector<int>(n);
  for (int i = 0; i < n; i++)
    uf[i] = i;
}

int root(int i)
{
  if (uf[i] == i) return i;
  return uf[i] = root(uf[i]);
}

void unite(int i, int j)
{
  int ri = root(i);
  int rj = root(j);
  if (ri != rj)
    uf[rj] = ri;
}

bool same(int i, int j)
{
  return root(i) == root(j);
}

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

  initialize(n);
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    unite(u, v);
  }

  cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v; cin >> u >> v;
    cout << (same(u, v)?"yes":"no") << endl;
  }

  return EXIT_SUCCESS;
}


Measured memory_bytes: 3624