akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 112000000012345L

template<typename T>
class MaximumFlow{
private:
  struct edge{int to; T cap; int rev;};
  vector<vector<edge> > Graph;
  vector<int> level, iter; //sからの距離,どこまで調べたか
  void bfs(int s){
    fill(all(level), -1);
    queue<int> q;
    level[s]=0;
    q.push(s);
    while(!q.empty()){
      int v=q.front(); q.pop();
      for(auto e : Graph[v]){
        if(e.cap>0 && level[e.to]<0){
          level[e.to] = level[v]+1;
          q.push(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)Graph[v].size(); i++){
      auto &e = Graph[v][i];
      if(e.cap>0 && level[v]<level[e.to]){
        T d = dfs(e.to, t, min(f, e.cap));
        if(d>0){
          e.cap -= d;
          Graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
public:
  MaximumFlow(int n){
    Graph = vector<vector<edge> >(n, vector<edge>());
    level = vector<int>(n);
    iter = vector<int>(n);
  }
  T max_flow(int s, int t){
    T flow=0;
    while(true){
      bfs(s);
      if(level[t] < 0) break;
      fill(all(iter), 0);
      T f;
      while( (f=dfs(s,t,INF)) > 0){
        flow += f;
      }
    }
    return flow;
  }
  void add_edge(int from, int to, T cap){
    int tos = Graph[to].size(), froms = Graph[from].size();
    Graph[from].pb(((edge){to, cap, tos}));
    Graph[to].pb(((edge){from, 0, froms}));
  }
};

int main(){
  int n;
  cin>>n;
  vector<long> v(n);
  rep(i,n) cin>>v[i];

  MaximumFlow<long> flow(n+2);
  int s = 0, t = n+1;
  long acc = 0;
  rep(i,n){
    flow.add_edge(s, i+1, max(0L, -v[i]));
    flow.add_edge(i+1, t, max(0L, v[i]));
    for(int x = i; x>0; x--) if((i+1)%x==0) flow.add_edge(x, i+1, INF);
    acc += max(0L, v[i]);
  }

  cout << acc - flow.max_flow(s,t) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 4e6+5;
int s[N],n;char tmple[N];
int cnt[3];
int p[3]={0,1,2};
 
inline void _swap(int x,int y){
	swap(p[x],p[y]);
	for(int i=1;i<=n;i++){
		if(s[i]==x)s[i]=y;
		else if(s[i]==y)s[i]=x;
	}
}
 
int b1,b2,c1,c2;
vector<int> pc2;bool ban[N];
 
void get(int l,int r){
	if(l>r)return ;
	int cntt[3]={0,0,0};
	for(int i=l;i<=r;i++){
		cntt[s[i]]++;
	}
	if(cntt[2]==0||cntt[1]==0){
		if(cntt[2]&&l>1&&r<n)c2++,pc2.push_back(l-1);
		if(cntt[1]&&l>1&&r<n)b2++;
	}
	if(cntt[2])c1++;
	if(cntt[1])b1++;
}
 
void Sol(int l,int r){
	if(l>r)return ;
	if(l==r){
		if(l==1||l==n){
			if(s[l]==2&&cnt[2]>cnt[1])cnt[2]--,ban[l]=1;
		}
	}
	if(l==r)return ;
	if(s[l]==2&&cnt[2]>cnt[1])cnt[2]--,ban[l]=1;
	if(s[r]==2&&cnt[2]>cnt[1])cnt[2]--,ban[r]=1;
}
 
int now,tar;
void Sol2(int l,int r){
	if(l>r)return ;
	while(l<r&&now>tar){
		if(l+1>=r && l!=1 && r!=n)break;
		now--;ban[l]=ban[l+1]=1;l+=2;
	}
}
 
int main()
{
	scanf("%s",tmple+1);int lll=strlen(tmple+1);
	for(int i=1;i<=lll;i++)if(i==1||tmple[i]!=tmple[i-1])s[++n]=tmple[i]-'A';
	for(int i=1;i<=n;i++)cnt[s[i]]++;
	for(int i=0;i<3;i++)for(int j=i+1;j<3;j++)if(i!=j){
		if(cnt[i]>cnt[j]){
			_swap(i,j);
			swap(cnt[i],cnt[j]);
		}
	}
	// for(int i=1;i<=n;i++)printf("%c",'A'+s[i]);puts("");
	// cout << " " << cnt[0] << ":" << cnt[1] << ":" << cnt[2] << endl;
	int lst=0;
	for(int i=1;i<=n;i++)
		if(s[i]==0){get(lst+1,i-1);lst=i;}
	get(lst+1,n);
	// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
	if(b1<c2){
		int ct=c2-b1;
		for(int i=0;i<ct;i++){
			//  cout << pc2[i] << "-";
			ban[pc2[i]]=1,cnt[0]--;
		}
	}
	// puts("");
	/*  */
	lst=-1;int nn=0;
	for(int i=1;i<=n;i++)if(!ban[i]){
		if(lst!=s[i])lst=s[i], s[++nn]=s[i];
	}n=nn;
	cnt[0]=cnt[1]=cnt[2]=0;
	for(int i=1;i<=n;i++)cnt[s[i]]++;
	memset(ban,0,sizeof(ban));
	
	// for(int i=1;i<=n;i++)printf("%c",'A'+s[i]);puts("");
	// cout << " " << cnt[0] << ":" << cnt[1] << ":" << cnt[2] << endl;
	/*  */
	lst=0;
	for(int i=1;i<=n;i++)
		if(s[i]==0){Sol(lst+1,i-1);lst=i;}
	Sol(lst+1,n);
	/*  */
	lst=-1,nn=0;
	for(int i=1;i<=n;i++)if(!ban[i]){
		if(lst!=s[i])lst=s[i], s[++nn]=s[i];
	}n=nn;
	cnt[0]=cnt[1]=cnt[2]=0;
	for(int i=1;i<=n;i++)cnt[s[i]]++;
	memset(ban,0,sizeof(ban));
 
	// for(int i=1;i<=n;i++)printf("%c",'A'+s[i]);puts("");
	// cout << " " << cnt[0] << ":" << cnt[1] << ":" << cnt[2] << endl;
	/*  */
	now=cnt[1],tar=cnt[0];
	lst=0;
	for(int i=1;i<=n;i++)
		if(s[i]==0){Sol2(lst+1,i-1);lst=i;}
	Sol2(lst+1,n);
	for(int i=1;i<=n;i++){
		if(!ban[i])printf("%c",'A'+p[s[i]]);
	}
}

Measured memory_bytes: 13944
using System;
using System.Linq;
class A{
    static void Main(){
        while(true){
            int n=int.Parse(Console.ReadLine());
            if(n==0){break;}
         int ans=0;
         for(int i=0;i<n;i++){
             int []s=Console.ReadLine().Split().Select(int.Parse).ToArray();
             int w=s[3];
             int cm=s[0]+s[1]+s[2];
             if(cm<=60&&w<=2){ans+=600;}
             else if(cm<=80&&w<=5){ans+=800;}
             else if(cm<=100&&w<=10){ans+=1000;}
             else if(cm<=120&&w<=15){ans+=1200;}
             else if(cm<=140&&w<=20){ans+=1400;}
             else if(cm<=160&&w<=25){ans+=1600;}
             
             
         }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void *a, const void *b) {
	return ((int*)a)[2] - ((int*)b)[2];
}

int solve(int num_node, int num_edge) {
	int i, k, answer, node1, node2;
	int S[num_edge][3];
	char forest[num_node][num_node];

	for (i = 0; i < num_edge; i++) {
		scanf("%d,%d,%d ", S[i]+0, S[i]+1, S[i]+2);
	}
	qsort(S, num_edge, sizeof(S[0]), compare);

	memset(forest, 0, sizeof(forest[0]) * num_node);
	for (i = 0; i < num_node; i++) {
		forest[i][i] = 1;
	}

	answer = 0;
	for (i = 0; i < num_edge; i++) {
		node1 = node2 = 0;
		for (k = 0; k < num_node; k++) {
			if (forest[k][S[i][0]]) {
				node1 = k;
			}
			if (forest[k][S[i][1]]) {
				node2 = k;
			}
		}
		if (node1 != node2) {
			for (k = 0; k < num_node; k++) {
				forest[node1][k] |= forest[node2][k];
				forest[node2][k] = 0;
			}
			answer += (S[i][2] / 100) - 1;
		}
	}
	return answer;
}

int main(void) {
	int num_node, num_edge;

	while (1) {
		scanf("%d ", &num_node);
		if (!num_node)
			break;

		scanf("%d ", &num_edge);
		printf("%d\n", solve(num_node, num_edge));
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int val;
int p;
bool f(string s){
  if(isdigit(s[p])){
    return s[p++]=='1';
  }
  if(isalpha(s[p])){
    char c=s[p]; p++;
    return ((val>>(c-'a'))&1);
  }
  if(s[p]=='-'){
    p++;
    return !f(s);
  }
  if(s[p]=='('){
    p++;
    bool vl=f(s);
    char op=s[p];
    p++;
    bool vr=f(s);
    p++;
    if(op=='^')return vl^vr;
    else return vl&vr;
  }
  assert(0);
}

struct state{
  string s;
};

bool operator<(const state& a,const state& b){
  return a.s.size() > b.s.size();
}

int calc(string s){
  int S=0;
  rep(i,16){
    p=0;
    val=i;
    S|=(f(s)<<i);
  }
  return S;
}

string cs[18]={"0","1","a","b","c","d","(a*b)","(a*c)","(a*d)","(b*c)","(b*d)","(c*d)","(a^b)","(a^c)","(a^d)","(b^c)","(b^d)","(c^d)"}; 
vector<string> ss;
int dp[1<<16];

int main(){
  priority_queue<state> que;

  rep(i,18)que.push((state){cs[i]});
  rep(S,1<<16)dp[S]=INF;
  while(que.size()){
    string s=que.top().s; que.pop();
    int S=calc(s);
    if(dp[S]!=INF)continue;
    dp[S]=s.size();
    string nxt="-"+s;
    if(nxt.size()<=16)que.push((state){nxt});
    rep(k,18){
      nxt="("+cs[k]+"*"+s+")";
      if(nxt.size()<=16)que.push((state){nxt});
      nxt="(-"+cs[k]+"*"+s+")";
      if(nxt.size()<=16)que.push((state){nxt});
      nxt="("+cs[k]+"^"+s+")";
      if(nxt.size()<=16)que.push((state){nxt});
      nxt="(-"+cs[k]+"^"+s+")";
      if(nxt.size()<=16)que.push((state){nxt});
    }
  }
  while(1){
    string s;
    cin>>s;
    if(s==".")break;
    int S=0;
    rep(i,16){
      val=i;
      p=0;
      S|=(f(s)<<i);
    }
    cout<<dp[S]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3992
import itertools

N = list(input().strip())

for p in itertools.product(['+', '-'], repeat=3):
    s = N[0] + p[0] + N[1] + p[1] + N[2] + p[2] + N[3]
    if eval(s) == 7:
        print(s + '=7')
        exit()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  int k,n;
  cin>>k>>n;
  int a[2*n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=n;i<2*n;i++)
  {
    a[i]=a[i-n]+k;
  }
  int sum=0,minm=INT_MAX;
  for(int i=1;i<n;i++)
    sum+=(a[i]-a[i-1]);
  minm=sum;
  for(int i=1;i<=n;i++)
  {
    sum=sum-(a[i]-a[i-1]);
    sum=sum+(a[i+n-1]-a[i+n-2]);
    minm=min(minm,sum);
  }
  cout<<minm<<endl;
}

Measured memory_bytes: 1792
package main

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

type task struct {
	cost     int
	deadline int
}

type tasks []task

func (t tasks) Len() int {
	return len(t)
}

func (t tasks) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

func (t tasks) Less(i, j int) bool {
	return t[i].deadline < t[j].deadline
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var N int
	fmt.Scan(&N)

	ts := make(tasks, N)
	for i := 0; i < N; i++ {
		cd := strings.Split(readLine(), " ")
		c, _ := strconv.Atoi(cd[0])
		d, _ := strconv.Atoi(cd[1])
		ts[i] = task{c, d}
	}
	sort.Sort(ts)

	tc := 0
	for i := range ts {
		tc += ts[i].cost
		if tc > ts[i].deadline {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  int n;
  cin >> n;
  vector<ll> t(n), a(n), t_confirm(n, 0), a_confirm(n, 0);
  for(int i = 0; i < n; i++){
    cin >> t[i];
  }
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  if(t[n - 1] != a[0]){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  for(int i = 1; i < n - 1; i++){
    if(t[i] == t[i - 1] && a[i] == a[i + 1]){
      ans *= min(t[i],a[i]);
      ans %= mod;
    }else if(t[i] == t[i - 1] && a[i] > a[i + 1] && t[i] < a[i]){
      ans = 0;
    }else if(a[i] == a[i + 1] && t[i] > t[i - 1] && a[i] < t[i]){
      ans = 0;
    }else if(a[i] > a[i + 1] && t[i] > t[i - 1] && a[i] != t[i]){
      ans = 0;
    }
  }

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 300005
#define lg 18
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    int arr[n];
    int hs[space]={0};
    rep(i,0,n)
    {
        cin>>arr[i];
        hs[arr[i]]=i;
    }
    sort(arr,arr+n);
    if(arr[n-1]==arr[n-2])
    {
        rep(i,0,n)
        {
            cout<<arr[n-1]<<"\n";
        }
    }
    else
    {
        rep(i,0,n)
        {
            if(i==hs[arr[n-1]]) cout<<arr[n-2]<<'\n';
            else cout<<arr[n-1]<<'\n';
        }
    }
    return 0;
}



Measured memory_bytes: 3584
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	map<int, int> m;


	for (int i = 0; i < n; i++) {
		int x; cin >> x;

		m[x]++;
	}

	LL ans = 0;

	for (auto i : m) {
		if (i.second % 2 == 1) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
cin>>x;
}
void solve() { print(10-x/200); }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    ll n;
    cin >> n;
    ll arr[n + 5];
    for(int i = 0; i < n; i++) cin >> arr[i];
    ll l[n + 5] = {}, r[n + 5] = {}, ans = 0;
    for(int i = n - 1; i >= 0; i--) r[i] = __gcd(r[i + 1], arr[i]);
    for(int i = 0; i < n; i++) l[i + 1] = __gcd(l[i], arr[i]);
    for(int i = 0; i < n; i++)
        ans = max(ans, __gcd(l[i], r[i + 1]));
    cout << ans;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  LL a, b, c, k;

  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);

  if (k % 2 == 0 && a - b < pow(10, 18)) {
    printf("%lld\n", a - b);
  } else if (k % 2 == 1 && b - a < pow(10, 18)) {
    printf("%lld\n", b - a);
  } else {
    printf("Unfair\n");
  }
}


Measured memory_bytes: 256
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <cassert>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=(a%10/5)+(a%5), a/=10; return res;}

int main() {
  int n,k; cin>>n>>k;
  int h[n]; for(int i=0;i<n;i++) cin>>h[i];
  int dp[n]; fill(dp,dp+n,1e9); dp[0]=0;
  for(int i=0;i<n;i++) {
    for(int j=1;j<=k;j++) {
      if (i+j>=n) break;
      chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<dp[n-1]<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest

Measured memory_bytes: 4324
use std::io;
use std::cmp;
use std::collections::VecDeque;

fn main() {
    let n = read_one::<usize>();
    let mut g = Vec::new();
    for _ in 0..n {
        let vs = read::<usize>()[2..].iter()
            .map(|v| v - 1)
            .collect::<Vec<_>>();
        g.push(vs);
    }

    let mut cost = vec![!0; n];
    let mut arrived = vec![false; n];
    let mut q = VecDeque::new();
    q.push_back((0, 0));

    while let Some((v, p)) = q.pop_front() {
        arrived[v] = true;
        cost[v] = cmp::min(cost[v], 1usize.wrapping_add(cost[p]));

        for &u in &g[v] {
            if u == p || arrived[u] { continue; }
            q.push_back((u, v));
        }
    }

    for (i, &c) in cost.iter().enumerate() {
        print!("{} ", i + 1);
        println!("{}", if arrived[i] { c as isize } else { -1 });
    }
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

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

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] + n > 90)
        {
            s[i] = s[i] + n - 26;
        }
        else
        {
            s[i] = s[i] + n;
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    ll n,y,i,j,k,to=0,ten=-1,five=-1,thou=-1;

    cin>>n>>y;

    for(i=0; i<=n; i++)
    {
        for(j=0; i+j<=n; j++)
        {
            k=n-i-j;
            to=10000*i+5000*j+1000*k;

            if(to==y)
            {
                ten=i;
                five=j;
                thou=k;
            }
        }
    }
    cout<<ten<<" "<<five<<" "<<thou<<endl;
}


Measured memory_bytes: 256
//
// Created by 永徳泰明 on 2019-01-12.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

int main() {
    readFromInputFile();
    int N, A, B;
    cin >> N >> A >> B;
    int x = 0, y = 0, z = 0;
    rep(i, N) {
        int t;
        cin >> t;
        if (t <= A) {
            x++;
        } else if (t > A && t <= B) {
            y++;
        } else {
            z++;
        }
    }

    cout << min(min(x, y), z) << endl;

    return 0;
}


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

int main(){
  int n; cin >> n;
  string s,t; cin >> s >> t;
  string res = "";
  for(int i = 0; i < n; i++){ 
    res += s[i];
    res += t[i];
  }
  
  cout << res << endl;
  
  return 0;
}
    

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define N 4

int main(void){
    int n[N];
    int a=0,b=0,c=0,d=0;

    for(int i=0;i<N;i++){
        cin>>n[i];
        switch(n[i]){
            case 1:a+=1;break;
            case 9:b+=1;break;
            case 7:c+=1;break;
            case 4:d+=1;break;
        }
    }

    if(a==1&&b==1&&c==1&&d==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int a[5], k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  rep(i,5){
    rep(j,5){
      if(abs(a[i]-a[j])>k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  V<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  VV<lint> dp; assign(dp, 2, n + 1);
  for (int i = 1; i < k + 1; i++) {
    deque<int> dq;
    for (int j = max(i - m, 0); j < i; j++) {
      while(!dq.empty() and dp[i - 1 & 1][dq.back()] <= dp[i - 1 & 1][j]) dq.pop_back();
      dq.push_back(j);
    }
    for (int j = i; j < n + 1; j++) {
      dp[i & 1][j] = i * a[j - 1] + dp[i - 1 & 1][dq.front()];
      if (dq.front() == j - m) dq.pop_front();
      while (!dq.empty() and dp[i - 1 & 1][dq.back()] <= dp[i - 1 & 1][j]) dq.pop_back();
      dq.push_back(j);
    }
  }
  cout << *max_element(dp[k & 1].begin(), dp[k & 1].end()) << '\n';
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}



signed main() {
	makev(v, 5);
	makei(k);
	sort(all(v));
	Yay(v.back() - v.front() <= k);
};


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

using namespace std;

typedef long long ll;


ll largemod(ll m,string s)
{
    ll mod=0;

    for(int i=0; i<s.size(); i++)
    {
        mod = (mod*10 + s[i]-'0')%m;
    }
    return mod;


}

ll SOD[10000000+100]={};
void sod(ll n)
{
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
        {
            SOD[j]++;
        }
    }


}
int main(void)
{

    ll N;
    cin>>N;
    sod(N);
    ll ans=0;
    for(ll k=1;k<=N;k++)
    {
        ans+= k*SOD[k];
    }
    cout<<ans<<endl;


}


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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			while (n-- != 0)
			{
				var e = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
				Array.Sort(e);
				Console.WriteLine(((e[0] * e[0]) + (e[1] * e[1]) == (e[2] * e[2])) ? "YES" : "NO");
			}
		}
	}
}

Measured memory_bytes: 5880
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <limits>
#include <climits>
#include <functional>
#include <numeric>

using namespace std;

#define alloc(type,n) (type*)calloc(sizeof(type),(n));
typedef long long lli;

vector<vector<int> >g;
int n,m;
int res = 0;
vector<bool> vis;


void dfs(int p){
	static int dps = 1;
	if(dps == n){
		res++;
		return;
	}
	dps++;
	vis[p] = true;
	for(int i = 0;i < g[p].size();i++){
		if(!vis[g[p][i]]) dfs(g[p][i]);
	}
	vis[p] = false;
	dps--;
	return;
}


int main(){
	cin >> n >> m;
	g = vector<vector<int> >(n+1);
	vis = vector<bool>(n+1);
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a,b,c,d,x,y,max1;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	max1=max(max(a*c,a*d),max(b*c,b*d));
	printf("%lld",max1);
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll tMOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

ll inverse_element(ll t){
	return mod_pow(t,MOD-2);
}
ll n;
ll d[100100];
ll co[100100];
ll ans=1;
int main(){
	cin>>n;
	REP(i,n){
		cin>>d[i];
		co[d[i]]++;
	}
	if(d[0]!=0||co[0]!=1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<100100;i++){
		if(co[i]==0&&co[i+1]>=1){
			cout<<0<<endl;
			return 0;
		}
	}
	for(int i=1;i<100100;i++){
		if(co[i]==0)break;
		for(int j=0;j<co[i];j++){
			ans*=co[i-1];
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int h, w;
string ma[51];
int res[51][51];

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

bool bound(int y, int x) {
    return (y >= 0 && y < h && x >= 0 && x < w);
}

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> ma[i];
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (ma[i][j] == '#') {
                res[i][j] = -1;
                continue;
            }

            for (int k = 0; k < 8; k++) {
                int ny = i + dy[k];
                int nx = j + dx[k];
                if (bound(ny, nx) && ma[ny][nx] == '#') {
                    res[i][j]++;
                }
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (res[i][j] == -1) cout << '#';
            else cout << res[i][j];

        }
        cout << '\n';
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
string s;
long long k;
int main()
{
	cin>>s>>k;
	long long tmp=-1;
	for(long long i=0;i<s.size()-1;i++)
		if(s[i]!=s[i+1])
		{
			v.push_back(i-tmp);
			tmp=i;
		}
	v.push_back(s.size()-1-tmp);/*
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	cout<<endl;*/
	if(v.size()==1)
		cout<<(long long)s.size()*k/2<<endl;
	else if(s[0]==s[s.size()-1])
	{
		long long ans=0;
		for(long long i=1;i<v.size()-1;i++)
			ans+=v[i]/2;
		ans+=(v[0]+v.back())/2;
		ans*=k;
		ans-=(v[0]+v.back())/2;
		ans+=v[0]/2;
		ans+=v.back()/2;
		cout<<ans<<endl;
	}
	else
	{
		long long ans=0;
		for(long long i=0;i<v.size();i++)
		{
			ans+=v[i]/2;
			//cout<<v[i]<<" ";
		}
		//cout<<endl;
		cout<<ans*k<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,x;
	while(scanf("%d %d %d",&a,&b,&c)!=EOF) {
		if((a==1868 && b==9 && c<=7)||(a==1868 && b<9 && c<=31)||(a<1868 && b<=12 && c<=31)) {
			printf("pre-meiji\n");
		}
		else if((a==1912 && b==7 && c<=29)||(a==1912 && b<7 && c<=31)||(a<1912 && b<=12 && c<=31)) {
			x=a-1867;
			printf("meiji %d %d %d\n",x,b,c);
		}
		else if((a==1926 && b<=12 && c<=24)||(a==1926 && b<12 && c<=31)||(a<1926 && b<=12 && c<=31)) {
			x=a-1911;
			printf("taisho %d %d %d\n",x,b,c);
		}
		else if((a==1989 && b<=1 && c<=7)||(a<1989 && b<=12 && c<=31)) {
			x=a-1925;
			printf("showa %d %d %d\n",x,b,c);
		}
		else {
			x=a-1988;
			printf("heisei %d %d %d\n",x,b,c);
		}
	}
	return 0;
}

Measured memory_bytes: 604
using System;

class AOJ
{
  static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());

    for (int i = 0; i < n; i++)
    {
      int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

      Array.Sort(x);

      if(x[2]*x[2] == x[0]*x[0] + x[1]*x[1])
        Console.WriteLine("YES");

      else
        Console.WriteLine("NO");
    }
  }
}

Measured memory_bytes: 9120
#include<iostream>

using namespace std;

int main()
{
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if(A1+A2+A3 >= 22)
    cout<<"bust"<< "\n";
  else
    cout << "win"<<"\n";
  return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

int main(){
    double d;
    cin >> d;
    
    double output;
    if(pow(d, 2) - pow(floor(d), 2) <= 2){
        output = max(sqrt(2) * d, floor(d)+1);
    } else {
        output = sqrt(2) * d;
    }

    cout << fixed << setprecision(10) << output << endl;
}

Measured memory_bytes: 3280
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int arr[100001];
int main(){
  int n;cin>>n;
  int mx = 0;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    arr[tmp]++;
    mx = max(mx,tmp);
  }
  int kes = 0;
  int kind = 0;
  for(int i = 0; mx >= i; i++){
    if(arr[i] == 0)continue;
    kind++;
    if(arr[i]%2==0)kes++;
  }
  if(kes % 2 == 0)cout << kind << endl;
  else cout << kind-1 << endl;
}

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


int main() {
  string s, t;
  cin >> s >> t;
  vector<char> a;
  vector<char> b;
  for (int i = 0; i < s.length(); i++) a.push_back(s[i]);
  for (int i = 0; i < t.length(); i++) b.push_back(t[i]);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  for (int i = 0; i < a.size(); i++) s[i] = a[i];
  for (int i = 0; i < b.size(); i++) t[i] = b[i];
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int s[1000], d[1000], y[1000], a, b;
P p[100000];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n)scanf("%d", &s[i]);
		rep(i, m)scanf("%d%d", &a, &b), p[i] = { b,a };
		sort(p, p + m); iota(d, d + n, 0);
		rep(i, m) {
			swap(d[p[i].t - 1], d[p[i].t]);
			p[i] = { d[p[i].t - 1],d[p[i].t] };
			if (p[i].first > p[i].t)swap(p[i].first, p[i].t);
		}
		rep(i, n)y[d[i]] = s[i];
		int M = accumulate(y, y + k, 0); int S = M;
		rep(i, m)if (p[i].first < k&&p[i].second >= k)M = min(M, S + y[p[i].second] - y[p[i].first]);
		printf("%d\n", M);
	}
}

Measured memory_bytes: 3988
n = int(raw_input())

while n > 0:
  d = map(int, raw_input().split())
  d.sort()
  a = d[0]
  b = d[1]
  c = d[2]

  if (c*c) == (a*a + b*b):
    print "YES"
  else:
    print "NO"

  n = n-1

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

using namespace std;

int main()
{
    int n;
    long long int t[100010], a[100010];
    long long int wa[100010];
    long long int ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> t[i] >> a[i];
        wa[i] = t[i]+a[i];
    }

    sort(wa, wa+n);
    reverse(wa, wa+n);

    for (int i = 0; i < n; i++) {
        if (!(i%2)) {
            ans += wa[i];
        }
        ans -= a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()

if k > (n-1)*(n-2)//2:
    print(-1)
    quit()
res = []
for i in range(n-1):
    res.append([1,2+i])
l = (n-1)*(n-2)//2 - k

ind = 2

def p():
    m = len(res)
    print(m)
    for i in range(m):
        print(*res[i])
if l == 0 :
    p(); quit()
for i in range(ind,n):
    for j in range(i+1,n+1):
        res.append([i,j])
        l -= 1
        if l == 0:
            p()
            quit()
    ind += 1


Measured memory_bytes: 68332
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
void dict(char *word, int current, int cm, int n){
    int i;
    for(i=0; i<=cm;i++){
        word[current] = 'a' + i;
        if(current == n - 1){
            int j;
            for(j=0;j<n;j++) cout << word[j];
            cout << endl;
        }else{
            dict(word, current+1, max(i+1, cm), n);
        }
    }
}
int main(){
    int N;
    cin >> N;
    char w[N];
    dict(w, 0, 0, N);
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
  int A,B;
  cin>>A>>B;
  if((A*B)%2!=0)
    cout << "Yes" <<endl;
  else if((A*B)%2==0)
    cout << "No" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> a(N); rep(i, N) cin >> a[i];
  vector<int> que;
  for (int i = 0; i < N; ++i){
    int length = 1;
    while (a[i] == a[i + 1] && i + 1 < N) i++, length++;
    que.emplace_back(length);
  }
  ll ans = 0;
  rep(i, que.size()){
    ans += que[i] / 2;
  }
  cout << ans << endl;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    vector<string> S;
    vector<int> T;
    int N;
    cin >> N;
    REP(i,N){
        string s;
        int t;
        cin >> s >> t;
        S.push_back(s);
        T.push_back(t);
    }
    string X; cin >> X;
    int ans = 0;

    REP(i,N){
        if (X == S[i]){
            for (size_t k = i + 1; k < N; k++) {
                ans += T[k];
            }
        }        
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	ans := (N - 1) * N / 2
	out(ans)
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();

    for (int i = n - 1; i >= 0; i--) {
        if (s.substr(i, 7) == "dreamer")
            s.erase(s.begin() + i, s.begin() + i + 7);
        if (s.substr(i, 6) == "eraser")
            s.erase(s.begin() + i, s.begin() + i + 6);
        if (s.substr(i, 5) == "dream")
            s.erase(s.begin() + i, s.begin() + i + 5);
        if (s.substr(i, 5) == "erase")
            s.erase(s.begin() + i, s.begin() + i + 5);
    }

    if (s.empty())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


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

int main(){
	long long int n, num[101], ans, dp[21][101] = {0};
	cin >>n;
	for(int i = 0; i < n; i++){
		cin >>num[i];
	}
	dp[num[0]][0] = 1;
	for(int i = 1; i < (n - 1); i++){
		for(int j = 0; j <= 20; j++){
			if(dp[j][i - 1] != 0){
				int p = j + num[i], m = j - num[i];
				if(p >= 0 && p <= 20) dp[p][i] += dp[j][i - 1];
				if(m >= 0 && m <= 20) dp[m][i] += dp[j][i - 1];
			}
		}
	}
	printf("%lld\n", dp[num[n - 1]][n - 2]);
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double total =0;
    for (int i=0; i<N; i++) {
      double x = sc.nextDouble();
      String u = sc.next();
      if (u.equals("BTC")) {
        total += x * 380000;
      } else {
        total += x;
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int P[5050];
ll C[5050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) cin>>P[i], P[i]--;
	FOR(i,N) cin>>C[i];
	
	ll ret=-1LL<<60;
	FOR(i,N) {
		vector<ll> V;
		j=i;
		ll sum=0;
		while(1) {
			j=P[j];
			V.push_back(C[j]);
			sum+=C[j];
			if(j==i) break;
		}
		ll csum=0;
		for(j=1;j<=V.size();j++) {
			csum+=V[j-1];
			if(j<=K) {
				ll lef=(K-j)/V.size();
				ret=max(ret,csum+lef*max(sum,0LL));
			}
		}
		
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3816
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		
		String s = sc.next();
        long ans = 0;
        int r = 0;
        int g = 0;
        int b = 0;
        for(int i=0;i<a;i++){if(s.charAt(i)=='R'){r++;}
                             if(s.charAt(i)=='G'){g++;}
                             if(s.charAt(i)=='B'){b++;}
                            }
        int dr = r;
        int dg = g;
        int db = b;
        if(a>3){for(int i=0;i<a-3;i++){if(s.charAt(i)=='R'){r--;}if(s.charAt(i)=='G'){g--;}if(s.charAt(i)=='B'){b--;}
                                       dr = r;dg = g; db = b;
               for(int j=i+1;j<a-1;j++){if(s.charAt(i)=='R'){
                 if(s.charAt(j)=='G'){ans+=db;if(2*j-i<a && s.charAt(2*j-i)=='B'){ans--;}dg--;}
               if(s.charAt(j)=='B'){ans+=dg;if(2*j-i<a && s.charAt(2*j-i)=='G'){ans--;}db--;}
               if(s.charAt(j)=='R'){dr--;}                                             
                                                            }
                                        if(s.charAt(i)=='G'){
                 if(s.charAt(j)=='R'){ans+=db;if(2*j-i<a && s.charAt(2*j-i)=='B'){ans--;}dr--;}
               if(s.charAt(j)=='B'){ans+=dr;if(2*j-i<a && s.charAt(2*j-i)=='R'){ans--;}db--;}
               if(s.charAt(j)=='G'){dg--;}                           
                                                            } 
                              
                                       if(s.charAt(i)=='B'){
                 if(s.charAt(j)=='G'){ans+=dr;if(2*j-i<a && s.charAt(2*j-i)=='R'){ans--;}dg--;}
               if(s.charAt(j)=='R'){ans+=dg;if(2*j-i<a && s.charAt(2*j-i)=='G'){ans--;}dr--;}
               if(s.charAt(j)=='B'){db--;}                                                    
                                                           } 
                                       }                               
                                      }                           
              }
       
		System.out.println(ans);
	}
}


Measured memory_bytes: 41072