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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

vector<int> G[200];
int color[200] = {};
int N;



bool dfs(int v, int c) {
  color[v] = c;
  rep0(i, G[v].size()) {
    if (color[G[v][i]] == c) return false;
    if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
  }
  return true;
}



int main() {
  cin >> N;

  rep0(i, N) {
    string S; cin >> S;
    rep0(j, N) {
      if (S[j] == '1') {
        G[i].push_back(j);
      }
    }
  }

  // 二部チェック
  if (!dfs(0, 1)) {
    cout << "-1" << BR;
    return 0;
  }

  ll INF = 1e9;
  int di = 0;

  rep0(i, N) {
    vector<int> d(N, INF);
    queue<int> q;

    d[i] = 1;
    q.push(i);

    while(!q.empty()) {
      int t = q.front();
      q.pop();
      rep0(i, G[t].size()) {
        if (d[G[t][i]] > d[t] + 1) {
          d[G[t][i]] = d[t] + 1;
          q.push(G[t][i]);
          di = max(di, d[t] + 1);
        }
      }
    }
  }

  cout << di << BR;
  return 0;
}

Measured memory_bytes: 436
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    LL n,k;
    cin >> n >> k;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VI cnt(62);
    REP(i,0,n) REP(j,0,62) if (a[i] & (1LL<<j)) cnt[j]++;
    LL x = 0;
    RREP(i,0,62) {
        if (k == 0) break;
        if (cnt[i] * 2 >= n) continue;
        if ((1LL << i) <= k) {
            x += (1LL << i);
            k -= (1LL << i);
        }
    }
    dump(x);
    LL ans = 0;
    REP(i,0,n) ans += (x ^ a[i]);
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mx 100000
#define md 1000000007ll
#define prMX 10000000
ll prime[prMX+2];
bool vis[prMX+2];
#define MX 10000000000000ll

int main(){
    int a,b;
    cin>>a>>b;
    if(a<=5)cout<<0<<endl;
    else if(a<=12)cout<<(b/2)<<endl;
    else cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
/*idea ïÌ®SÍ¶ÝµÈ¢@ßèÌÅ¬ÍPQÅßèÌ{ÍßèiïÌßèÅÅà¬³¢ÌÍXSTj@
®SÍ@UAQWCSXUCWPQWCRRTTORRUµ©È¢i±ÌâèÌÍÍàÅÍj

ûjF@®SÍª·­È¢ÌÅ ç©¶ßpÓµÄ¨­iüÍÌn_Å±êçÉÄÍÜÁ½êÍ®Sj
@@@@lÌñðå«¢É¾µÄ¢«A«µ±¯éi©gÍÜÜÈ¢j
@@@@aªlÌQ{æèå«­ÈÁ½n_Åßèmè
@@@@
@@@@s«Ì»è@ªÝÂ©çÈ¢BBB
@@@@lÌ¼ªÜÅÌñð¨¨«¢É«µÄ¢«»Ìaªlæèà¬³¯êÎs«mèÆ©H
@@@@±êðì¬µÄàÊçÈ¢æ¤ÈçlÌ¼ªÜÅÌaÅÍÈ­1/3ÜÅÌaÅâÁÄÝæ¤
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std; 


int main(){
  int i,j,k,flag=0;
  long long sum,n,PN[5];
  PN[0]=6;
  PN[1]=28;
  PN[2]=496;
  PN[3]=8128;
  PN[4]=33550336;
  
  while(1){
    flag=0;
    sum=0;
    cin >> n;
    if(n == 0)break;
    if(n == 6 || n ==28 || n == 496 || n == 8128 || n == 33550336){
      cout << "perfect number" << endl;
      continue;
    } 

if(n == 1){
  cout << "deficient number" << endl;
  continue;
    }



    sum++;
    
    for(i=2;i<=(int)sqrt(n);i++){
      if((n%i) == 0){
	if(i == n/i){
	  sum+=i;
	}
	else{
	sum+=i+(n/i);
	//cout << "i=" << i<< endl;
	} 
	}
      
      /*
      if(i == (int)n/2 && sum < n/2){
	cout << "deficient number" << endl;
	flag = 1;
	break;
      }
      else if (sum >= n){
	cout << "abundant number" << endl;
	flag = 1;
	break;
      }
      */
      
    }

    

    //   cout << "sum=" << sum << endl;
    if(sum > n && flag==0){
      cout << "abundant number" << endl;
    }
    else if(sum < n && flag == 0){
      cout << "deficient number" << endl;
    }
    else if(sum == n && flag == 0) {
      cout << "arienai" << endl;
    }



  }


}

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

int main() {
  int n,k;
  cin >> n >> k;
  int ans=0;
  for (int i=0; i<n; i++) {
    int x;
    cin >> x;
    ans += min(k-x, x)*2;
  }
  
  cout << ans << '\n';
  return 0; 
}

Measured memory_bytes: 256
let first_some f =
  List.fold_left (fun v e -> match v with None -> f e | _ -> v) None

let nb a b r =
  let f b = if b then 1 else 0 in
  [|'W';'S'|].((f (b = 'S') + f (r = 'o') + f (a = 'S')) mod 2)

let () =
  Scanf.scanf "%d %s" @@ fun n s ->
  [('S','S'); ('S','W'); ('W','S'); ('W','W')]
  |> first_some (fun (h0, h1) ->
      let h = Array.make n '0' in
      h.(0) <- h0; h.(1) <- h1;

      let t = String.init n (fun i ->
        if i < 2 then h.(i)
        else
          let v = nb h.(i-2) h.(i-1) s.[i-1] in
          h.(i) <- v; v)
      in

      if nb h.(n-2) h.(n-1) s.[n-1] = h.(0) && nb h.(n-1) h.(0) s.[0] = h.(1) then
        Some t
      else None)
  |> (function Some x -> x | _ -> "-1") |> print_endline

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

int main(){
    int n,r;
    scanf("%d %d",&n,&r);
    if(n >= 10){
        printf("%d",r);
    }else{
        int ans = r + 100*(10 - n);
        printf("%d",ans);
    }
    return 0;
}


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

int main () {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  double temp = fabs(T - A - 0.006*H.at(0));
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (fabs(T - A - 0.006*H.at(i)) < temp) {
      temp = fabs(T - A - 0.006*H.at(i));
      ans = i;
    }
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : ku.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<iostream>
using namespace std;
#include<cstdio>
int main(){
	double x;
	int i=0;
	for(;;){
		cin>>x;
		if(x == 0){
			break;
		}
		i++;
		cout<<"Case "<<i<<": "<<x<<endl;
	}
	return 0;}

Measured memory_bytes: 1280
package main
import (
  "fmt"
  "math"
       )
func main(){
  var a,b,c,d float64
  fmt.Scanf("%f",&a)
  fmt.Scanf("%f",&b)
  fmt.Scanf("%f",&c)
  fmt.Scanf("%f",&d)
  
  if(d >= math.Abs(a - c)){
    fmt.Println("Yes")
    return
  }
  a = math.Abs(b - a)
  b = math.Abs(c - b)
  
  
  if d >= a && d >= b{
    fmt.Println("Yes")
  }else{
  	fmt.Println("No")
  }
  return
}

Measured memory_bytes: 512
#include <iostream>

int main() {
	int n, k;

	std::cin >> n >> k;

	int cnt[150] = { 0 };
	while (k--) {
		int kcnt;
		std::cin >> kcnt;

		int x;
		for (int i = 0; i < kcnt; ++i) {
			std::cin >> x;
			--x;
			++cnt[x];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i)
		if (cnt[i] == 0)
			++ans;

	std::cout << ans;
}

Measured memory_bytes: 3640
#include <iostream>
int main()
{
    int ss;
    int h,m,s;
    std::cin >> ss;
    h = ss / 3600;
    m = (ss % 3600) / 60;
    s = ss % 60;
    std::cout << h << ":" << m << ":" << s << std::endl;
    return 0;
}


Measured memory_bytes: 3116
#define ENABLE_LL
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
using namespace std;

void init();
void solve();
int main(){
try { 

#ifndef CUSTOM_MAIN
#ifdef MULTIPLE_TEST_CASES_WITH_T

int T; scanf("%d",&T); while(T--) {init(); solve();}

#else
#ifdef MULTIPLE_TEST_CASES_WITHOUT_T

while(1) {try{init(); } catch(bool t){return 0;} solve(); }

#else

init(); solve();

#endif
#endif
#endif

} catch (const char* s) { return 0; }
    return 0;
}

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr; typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; } char nextChar(){ char r; ist>>r; return r;} }; Scanner sc(cin);
void ALERT(bool judgememt, const char* phrase) { if (judgememt) { puts(phrase); throw "ALERT"; } }
bool alert(bool judgememt, const char* phrase) { if (judgememt) puts(phrase); return judgememt; }

const int N = 200005;
int a[N], b[N], n;

void init() {
    scanf(I,&n);
    rep (i,n) scanf(I,&a[i]);
    rep (i,n) scanf(I,&b[i]); 
}

inline int p(int u){ return (u+n-1)%n; }
inline int s(int u){ return (u+1  )%n; }
inline bool check(int u) { return b[u]>b[p(u)] && b[u]>b[s(u)]; }
void solve() {
    queue <int> que;
    rep (i,n) if (check(i)) que.push(i);
    int ans=0;
    while (!que.empty()) {
        int u=que.front(); que.pop();
        if (b[u]==a[u]) { continue; } ALERT(b[u]<a[u],"-1");
        int sub=b[p(u)]+b[s(u)];
        int del=b[u]-a[u];
        ans+=del/sub; b[u]-= del/sub*sub;
        if (check(p(u))) { que.push(p(u)); } 
        if (del>=sub && check(u)) { que.push(u); } 
        if (check(s(u))) { que.push(s(u)); } }
    rep (i,n) ALERT(b[i]!=a[i],"-1");
    printf(IN,ans);
}



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

int main() {
  ll h, w;
  cin >> h >> w;

  if (h == 1 || w == 1) {
    cout << 1 << endl;
  } else if (h%2 == 0 && w%2 == 0) {
    cout << w * h/2 << endl;
  } else if (h%2 == 1 && w%2 == 1) {
    cout << (w/2+1)*(h/2+1) + (w/2) * (h/2) << endl;
  } else {
    cout << (w*h)/2 << endl;
  }

  return 0;
}


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

int main (){
	int h;
	while(cin>>h && h){
		vector<vector<int>> v(h,vector<int>(5));
		for(int i=0;i<h;i++)for(int j=0;j<5;j++)cin>>v[i][j];//入力
		int ans=0;
		while(1){
			int flag=true; //消す石があったらtrueのまま
			//３個以上並ぶところを消す処理
			for(int i=0;i<h;i++){
				int chain; //同じ数字が並ぶ数
				for(int j=0;j<5;j++){
					chain=1;
					while(j+1<5 && v[i][j]!=-1 && v[i][j]==v[i][j+1]){
						chain++;
						j++;
					}
					if(chain>=3){ //3つ以上並んでいたら
						flag=false;
						ans+=chain*v[i][j];
						for(int k=0;k<chain;k++){ //その部分を-1に変える
							v[i][j-chain+k+1]=-1;
						}
						break;
					}
				}
			}
			if(flag)break; //消す石が無かったなら終了

			//石の落下処理。配列を縦に回す
			for(int p=0;p<h;p++){
				for(int i=0;i<5;i++){
					for(int j=h-1;j>=1;j--){
						if(v[j][i]==-1){
							for(int k=j;k>=1;k--)swap(v[k][i],v[k-1][i]);
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3052
#include<iostream>
#include<algorithm>
using namespace std;
static const int N =100001;
int n;
int A[N], L[N], P[N];

// slow implementation
void lis(){
    L[0]=0;
    A[0]=0;
    P[0]=-1;
    int i,j,k;
    for(i=1;i<=n;i++){
	k=0;
	for(j=0;j<i;j++){
	    if(A[j]<A[i] && L[j]>L[k]) k=j;
	}
	L[i]=L[k]+1;
	P[i]=k;
	
    }
}

int MAX(){
    int m=-1,i;
    for(i=1;i<=n;i++){
	if (m<=L[i])m=L[i];
    }
    return m;
}

// quick implementation using DP and binary search
int lis2(){
    L[0]=A[0];
    int len=1;
    
    int i;
    for(i=1;i<n;i++){
	if(L[len-1]<A[i]) L[len++]=A[i];
	
	else *lower_bound(L,L+len,A[i])=A[i];
    }
    return len;
}
	
    


int main(){
    int i;
    cin>>n;
    for(i=0;i<n;i++){
	cin >>A[i];
    }
    /*
    lis();
    
    cout <<MAX() << endl;
    */
    cout << lis2() << endl;
    
    return 0;
}

Measured memory_bytes: 1948
#include<bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
const int lim = 1000001;

vi prime_fact(int x, const vi &table){
  vi res;
  while(x>1){
    res.push_back(table[x]);
    x /= table[x];
  }
  sort(all(res));
  res.erase(unique(all(res)),res.end());
  return res;
}

int main(){
  vi table(lim,1);
  for(int i=2;i<=lim;i++){
    if(table[i] == 1){
      for(int j=i;j<=lim;j+=i)table[j] = i;
    }
  }

  int a,b;
  while(cin >> a >> b, a){
    vi va = prime_fact(a,table), vb = prime_fact(b,table);
    a = 2*va.back() - accumulate(all(va),0);
    b = 2*vb.back() - accumulate(all(vb),0);
    cout << (a>b?"a":"b") << endl;
  } 
}

Measured memory_bytes: 4900
n=int(input())
li=[None]*n
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    li[i]=(x+l, x-l)
li=sorted(li)
count=1
x,y=li[0]
for i in range(1,n):
    x2,y2=li[i]
    if y2 < x:
        continue
    count=count+1
    x=x2
print(count)

Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  int ans = (H-h)*(W-w);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#include<unordered_map>
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double PI = 3.1415926536;

using namespace std;

int n;
ll a[maxn];
vector<int> v[maxn];
ll b[maxn];
ll x[maxn], y[maxn];

int main()
{
	io;
	cin >> n;
	for (int i = 1, x; i <= n; ++i) {
		cin >> x;
		++a[x];
		v[x].push_back(i);
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		x[i] = (a[i] * (a[i] - 1)) / 2;
		ans += x[i];
	}
	for (int i = 1; i <= n; ++i) {
		for (auto j : v[i])
			b[j] = ans - a[i] + 1;
	}
	for (int i = 1; i <= n; ++i)
		cout << b[i] << "\n";
	return 0;
}


Measured memory_bytes: 14976
s=input()
n=len(s)
ans=0
a=[]
for i in range(n):
  if s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T':
    ans+=1
    a.append(ans)
  else:
    ans=0
    a.append(ans)
print(max(a))


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
const int MAX=5e5+10;
//const int INF=1e9+15;



int main(){
	int N;
	ll D;
	cin>>N>>D;
	ll d[MAX];
	rep1(i,N)scanf("%lld", &d[i]);
	int Q;
	cin>>Q;
	
	ll now[MAX];
	now[0]=D;
	rep1(i,N)now[i]=min(now[i-1], abs(now[i-1]-d[i]));
	if(now[N]!=0){
		rep(_,Q)cout<<"YES"<<endl;
		return 0;
	}
	int ur[MAX];
	ur[N]=1;
	for(int i=N-1; i>=0; i--){
		if(d[i+1]>=2*ur[i+1]) ur[i]=ur[i+1];
		else ur[i]=ur[i+1]+d[i+1];
	}
	rep(_,Q){
		int q;
		scanf("%d", &q);;
		q--;
		if(now[q]>=ur[q+1])printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 11648
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N - i + 1):
        if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y):
            print(str(i) + " " + str(j) + " " + str(N-i-j))
            exit()
print(str(-1) + " " + str(-1) + " " +str(-1))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;



int MOD=1000000007;
int main(void){
	int ans=0;
	string S;
	cin >> S;
	for(int i=0; i<S.size()/2; i++){
		if(S[i]!=S[S.size()-1-i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def pf(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

num = int(input())
ls = pf(num)
if len(ls) % 2 == 0:
  print(ls[len(ls)//2-1]+ls[len(ls)//2]-2)
else:
	print(ls[len(ls)//2]*2 -2)


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

int main() {
  string S;
  int K;
  cin >> S >> K;

  auto pos = find_if(S.begin(), S.end(), [](auto c) { return c != '1'; });
  if(pos == S.end()) {
    cout << 1 << endl;
    return 0;
  } else {
    auto n = pos - S.begin();
    if(K <= n) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << S[n] << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using lint=long long;
int main(){
    lint q;std::cin>>q;
    while(q--){
        lint L=1;for(lint i=0;i<30;i++)L*=3;
        lint i0,j0,i1,j1;std::cin>>i0>>j0>>i1>>j1;
        i0--,j0--,i1--,j1--;
        for(;i0/L==i1/L&&j0/L==j1/L;L/=3);
        if(j0/L==j1/L)std::swap(i0,j0),std::swap(i1,j1);
        lint d=0;
        for(;L;L/=3){
            lint I0=i0/L,I1=i1/L,J0=j0/L,J1=j1/L;
            if(I0!=I1)break;
            if(I0%3==1&&1<std::abs(J0-J1)){
                lint r0=i0%L,r1=i1%L;
                d=std::min({r0+1,r1+1,L-r0,L-r1});
                break;
            }
        }
        std::cout<<std::abs(i0-i1)+std::abs(j0-j1)+2*d<<'\n';
    }
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }


int main(){ 
    string s, t, u; int a, b; cin >> s >> t >> a >> b >> u;
    if(s==u)a--; else b--;
    cout << a << " " << b << ln;
}

Measured memory_bytes: 256
s = gets.chomp.chars
size = s.size
if size == 1
  puts s[0]
  exit
end
i = 0
ans = 0
while i < 2**(size -1)
  pattern = "0"*(size - 1 - i.to_s(2).size) + i.to_s(2)
  sigs = pattern.chars.map! {|digit| "+" * digit.to_i }
  formula = s[0]
  sigs.each.with_index do |sig,id|
    formula += sig + s[id+1]
  end
  ans += eval(formula)
  i += 1
end
puts ans


Measured memory_bytes: 14328
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

ll dp[2000][2010];

int main(){
    ll s;
    cin >> s;
    rep(i, s)rep(j, s){
        dp[i][j] = 0;
    }
    dp[0][0] = 1;
    for (ll  i = 1; 3 * i <= s; i++){
        for (int j = i * 3; j <= s; j++){
            for (int k = (i-1) * 3; k <= j - 3; k++){
                dp[i][j] += dp[i-1][k];
                dp[i][j] %= mod;
            }
        }
    }
    // rep(i, s){
    //     rep(j, s){
    //         cout << dp[i][j] << " ";
    //     }cout << endl;
    // }
    ll ans = 0;
    rep(i, s){
        ans += dp[i][s];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 35020
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,d,n,q;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c>>d;
		q=(a*c+b*d);
		if(c>4&&d>1)cout<<q*8/10<<endl;
		else{
			if(d<2)d=2;
			if(c<5)c=5;
			if(q>(a*c+b*d)*8/10)cout<<(a*c+b*d)*8/10<<endl;
				else cout<<q<<endl;
		}
	}return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using ll=long long;
using namespace std;
int main(){
  int x,n,p;
  vector<int> d(102);//あるかないかの配列 0~101までの102個
 cin>>x>>n;
  rep(i,n){
  cin>>p;
d[p]=1;//p[i]に含まれている数字にたいしては1を格納
  }
  int ans=102;//絶対値を格納
  int ans1=0;//数字を格納
  for(int i=0;i<102;i++){//d[p]の要素数の分だけループを回す
 /*if(p[i]<x){//何もしない
 
  } */ 
    if (d[i]==1) continue;//入っていたらcontinue
    else if(ans==abs(x-i)){//ansと今の絶対値が一緒だったら、前のやつが答え
    
      break;
    }
    else if(ans>abs(x-i)){//更新される場合
   ans=min(ans,abs(x-i));//小さい方をansに
   ans1=i;//答えを更新
   
    }

}
 cout<<ans1<<endl; 
}
  
  

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL
 
struct node{
  struct node *l;
  struct node *r;
  struct node *p;
  int key;
};
 
typedef struct node * Node;
 
Node root;

void insert(int);
Node Search(Node ,int );
void Preorder(Node );
void Inorder(Node );

main(){
  int n, i, x;
  char str[20];
  Node s;
  scanf("%d",&n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s",str);
 
    if (str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } 
    else if(str[0]=='f'){
      scanf("%d",&x);
      s=Search(root,x);
      if (s!= NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if (str[0]=='p'){
      Inorder(root);
      printf("\n");
       
      Preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;
   
  while(x!=NIL){
    y=x;
 
    if(z->key<x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;
   
  if(y==NIL) root=z;
  else if(z->key<y->key) y->l=z;
  else y->r=z;
}

 
Node Search(Node t,int k){
  if(t==NIL || k==t->key) return t;
  if(k<t->key) return Search(t->l,k);
  else return Search(t->r,k);
}

void Preorder(Node t){
  printf(" %d",t->key);
  if(t!=NIL){
    if(t->l!=NIL)Preorder(t->l);
    if(t->r!=NIL)Preorder(t->r);
  }
}
 
void Inorder(Node t){
   
  if(t!=NIL){
    if(t->l!=NIL){
      Inorder(t->l);
      }
    printf(" %d",t->key);
     
    if(t->r!=NIL){
      Inorder(t->r);
      }
  }
}

Measured memory_bytes: 19360
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <queue>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10,18);
const int MOD = pow(10,9) + 7;
/* contest template */
int A,B;
int h=100;
int w=100;
std::vector<string> v1(50,"####################################################################################################");
std::vector<string> v2(50,"....................................................................................................");
int a=1;
int b=1;

int main()
{
    cin>>A>>B;
    int i=1;
    int j=1;
    while(a<A){
      v1[i][j]='.';
      a++;
      j+=2;
      if(j==101){
        i+=2;
        j=1;
      }
    }
    i=1;
    j=1;
    while(b<B){
      v2[i][j]='#';
      b++;
      j+=2;
      if(j==101){
        i+=2;
        j=1;
      }
    }
    cout<<100<<" "<<100<<endl;
    for(int i=0;i<50;i++){
      cout<<v1[i]<<endl;
    }
    for(int i=0;i<50;i++){
      cout<<v2[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,X=map(int,input().split())
*A,=map(int,input().split())

B=[0]*N
for i in range(N):
    B[i] = A[i] if A[i]<=X else X

cnt=sum(A)-sum(B)    
for i in range(N-1):
    if X < B[i]+B[i+1]:
        d=B[i]+B[i+1]-X
        B[i+1]-=d
        cnt+=d
print(cnt)

Measured memory_bytes: 19992
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
  int N, X;
  cin >> N >> X;
  int ret = 1;
  int pos = 0;
  int L;
  rep(i, N) {
    cin >> L;
    pos += L;
    if(pos <= X)
      ++ret;
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from numpy import cumsum


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
abc = [LIST() for _ in range(n)]


dp = []
for i in range(n + 1):
    dp.append([0,0,0])

for i in range(n):
    dp[i + 1][0] = max(dp[i][1] + abc[i][0], dp[i][2] + abc[i][0])
    dp[i + 1][1] = max(dp[i][0] + abc[i][1], dp[i][2] + abc[i][1])
    dp[i + 1][2] = max(dp[i][0] + abc[i][2], dp[i][1] + abc[i][2])
    #print(dp[i+1])

print(max(dp[-1]))
"""for i in range(n + 1):
    print(dp[i])"""
      

Measured memory_bytes: 59836
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		String input = sc.next();
		char[] charArray = input.toCharArray();
		Arrays.sort(charArray);
		String sortedString = new String(charArray);
		int N = sortedString.length();
		int cnt = 0;
		char tmpVal = sortedString.charAt(0);
		
		if (N <= 1) {
			System.out.println("No");
			return;
		}
		for (int i = 0; i < N; i++) {
			char val = sortedString.charAt(i);
			if (val==tmpVal) {
				cnt++;
			} else {
				if (cnt % 2!=0) {
					System.out.println("No");
					return;
				}
				cnt = 1;
				tmpVal = val;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    string s; cin >> s;
    int ans = 0;
    rep(i,s.length()/2) {
        if (s[i] != s[s.length()-1-i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
n, d = gets.chomp.split(' ').map(&:to_i)
input = Array.new(n) { gets.chomp.split(' ').map(&:to_i) }
ans = 0
input.combination(2) do |a, b|
  y_square = 0
  d.times do |dimention|
    y_square += (a[dimention] - b[dimention]) ** 2
  end
  ans += 1 if (1..y_square).any? { |k| k ** 2 == y_square }
end
puts ans


Measured memory_bytes: 1788
def combmod(n,k,mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod
  
num,A,B = list(map(int, input().split()))
print((pow(2,num,10**9+7) - 1 - combmod(num,A,10**9+7) - combmod(num,B,10**9+7)) % (10**9+7))

Measured memory_bytes: 38512
r,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(r)]

for i in range(r):
    l[i].append(sum(l[i]))

m=[0]*(c+1)
for i in range(r):
    for j in range(c+1):
        m[j]+=l[i][j]

for i in range(r):
    print(' '.join(map(str, l[i])))
print(*m)


Measured memory_bytes: 5712
# abc150_c.py
'''
全パターン作ってソートで順番みる
'''
import itertools
N = int(input())
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))

l = [i+1 for i in range(N)]
target =  itertools.permutations(l)
cnt=0
pcnt = 0
qcnt = 0
for i in target:
    cnt += 1
    if i == P:
        pcnt=cnt
    if i == Q:
        qcnt=cnt

print(abs(pcnt-qcnt))


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

int main() {
 char x;
 cin >> x;
  if (x == 'A')
    cout << 'T';
  if (x == 'T')
    cout << 'A';
  if (x == 'G')
    cout << 'C';
  if (x == 'C')
    cout << 'G';
}


Measured memory_bytes: 256
import heapq
import sys

input = sys.stdin.readline

def dijlstra_heap(N,s,edge):
    d = [float('inf')] * N
    used = [True] * N
    d[s] = 0
    edgelist = []
    for a, b in edge[s]:
        heapq.heappush(edgelist, a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge%(10**6)]:
            continue
        v = minedge % (10 ** 6)
        d[v] = minedge // (10 ** 6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

def main():
    N = int(input())
    edge = [[] for i in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append([1,b])
        edge[b].append([1,a])
    d0 = dijlstra_heap(N,0,edge)
    dn = dijlstra_heap(N,N-1,edge)

    f_cnt = 0
    s_cnt = 0
    for i in range(N):
        if d0[i] <= dn[i]:
            f_cnt += 1
        else:
            s_cnt += 1

    if f_cnt > s_cnt:
        print('Fennec')
    else:
        print('Snuke')


if __name__ == "__main__":
    main()

Measured memory_bytes: 88384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=1e5+10;
const int maxm=1e2+10;
const int mod=1e9+7;
int A,B,C;
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %d %d",&A,&B,&C))
    {
        int flag=1;
        int ans=0;
        while(1)
        {
            if(A%2==1||B%2==1||C%2==1)
                break;
            if(A==B||B==C) {flag=0;break;}
            int tA=(B+C)/2;
            int tB=(A+C)/2;
            int tC=(A+B)/2;
            A=tA;B=tB;C=tC;
            ans++;
        }
        if(flag==0) printf("-1\n");
        else printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[4];
		for (int i = 0; i < 3; i++) {
			arr[sc.nextInt() - 1]++;
			arr[sc.nextInt() - 1]++;
		}
		int one = 0;
		int two = 0;
		for (int x : arr) {
			if (x == 1) {
				one++;
			} else if (x == 2) {
				two++;
			}
		}
		if (one == 2 && two == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21716
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key)
    cur = cur->next;
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while ( 1 ) {
    if ( cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ) {
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) insert(key);
    else if ( strlen(com) == 6 ) deleteKey(key);
    else if ( com[6] == 'F' ) deleteFirst();
    else deleteLast();
  }

  printList();

  return 0;
}


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

#define int long long

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

int N, A, B, C, D;

signed main() {
    cin >> N >> A >> B >> C >> D;
    int target = B - A;
    for (int i = 0; i < N; i++) {
        int can = C * N - C - 2 * C * i;
        if (target > can) {
            if ((N - 1 - i) * (D - C) >= target - can) {
                cout << "YES" << endl;
                return 0;
            }
        } else {
            if (i * (D - C) >= can - target) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 1e17 , MOD=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int32_t main(){
    boost;
    
    string s1,s2;
    cin>>s1>>s2;
    s2 = s2.substr(0,s2.size()-1);
    if(s1 == s2){
        cout<<"Yes\n";
    }else
    cout<<"No\n";
    
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> prefs(n);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    p--;
    prefs[p].push_back({y, i});
  }

  auto gen_id = [](int pref, int order) {
    stringstream ss;
    ss << setfill('0') << right << setw(6) << pref;
    ss << setfill('0') << right << setw(6) << order;
    return ss.str();
  };

  vector<string> ids(m);
  for (int i = 0; i < prefs.size(); i++) {
    sort(prefs[i].begin(), prefs[i].end());
    for (int j = 0; j < prefs[i].size(); j++) {
      ids[prefs[i][j].second] = gen_id(i + 1, j + 1);
    }
  }

  for (string &id : ids) {
    cout << id << '\n';
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> p(n);
  for(int i = 0; i < n; i++){
    int k;
    string l;
    cin >> l >> k;
    p.at(i) = make_pair(make_pair(l, -k), i);
  }
  
  sort(p.begin(), p.end());
  
  for(int i = 0; i < n; i++) cout << p.at(i).second + 1 << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let h: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut max = 0;
    let mut ans = 0;
    for x in h {
        if max < x {
            max = x;
        }
        if x == max {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <limits>
#include <algorithm>


int main() {
	int N;
	int K;
	std::cin >> N >> K;
	int h[N];
	for (int i = 0; i < N; ++i) {
		std::cin >> h[i];
	}
	
	int dp[N];
	for (int i = 0; i < N; ++i) {
		dp[i] = std::numeric_limits<int>::max();
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < N; ++i) {
		for (int j = 1; j <= K; ++j) {
			if (i - j >= 0) {
				dp[i] = std::min(dp[i], dp[i - j] + std::abs(h[i] - h[i - j]));
			}
		}
	}
	std::cout << dp[N - 1];
	
	return 0;	
}


Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main(){
  int n,m;
  cin>>n>>m;
  int a[m];
  for(int i=0;i<m;i++)cin>>a[i];
  int b[n+1];
  for(int i=0;i<=n;i++)b[i]=0;
  for(int i=0;i<m;i++)b[a[i]]=1;
  int dp[n+2];
  for(int i=0;i<n+2;i++)dp[i]=0;
  dp[0]=1;
  for(int i=0;i<n;i++){
    if(b[i+1]!=1){
      dp[i+1]+=dp[i];
      dp[i+1]%=MOD;
    }
    if(b[i+2]!=1){
      dp[i+2]+=dp[i];
      dp[i+2]%=MOD;
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	ans := 0
	l, r := 0, len(s)-1
	for l < r {
		if s[l] == s[r] {
			l++
			r--
			continue
		}

		if s[l] != 'x' && s[r] != 'x' {
			fmt.Println(-1)
			return
		}

		if s[l] != 'x' {
			r--
		} else {
			l++
		}
		ans++
	}
	fmt.Println(ans)
}


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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
        string s,t;
        cin >> s >> t;
       	int a,b;
       	cin >> a >> b;
       	string u;
       	cin >> u;
       	if(s == u)
       		a--;
       	else
       		b--;
       	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    class Combination:
        """
        階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う
        https://atcoder.jp/contests/abc167/submissions/13071653
        """
    
        def __init__(self, n, MOD):
            self.fact = [1]
            for i in range(1, n + 1):
                self.fact.append(self.fact[-1] * i % MOD)
            self.inv_fact = [0] * (n + 1)
            self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
            for i in reversed(range(n)):
                self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
            self.MOD = MOD
    
        def factorial(self, k):
            """k!を求める O(1)"""
            return self.fact[k]
    
        def inverse_factorial(self, k):
            """k!の逆元を求める O(1)"""
            return self.inv_fact[k]
    
        def permutation(self, k, r):
            """kPrを求める O(1)"""
            if k < r:
                return 0
            return (self.fact[k] * self.inv_fact[k - r]) % self.MOD
    
        def combination(self, k, r):
            """kCrを求める O(1)"""
            if k < r:
                return 0
            return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD
    
        def combination2(self, k, r):
            """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
            if k < r:
                return 0
            res = 1
            for l in range(r):
                res *= (k - l)
                res %= self.MOD
            return (res * self.inv_fact[r]) % self.MOD
    
    
    MOD = 10**9+7
    # 第１引数は制約より大きめ
    comb = Combination(10 ** 6, MOD)
    
    """
    comb.combination(n,r)　のようにつかう
    powは組み込みでpow(n,r,MOD)でOK
    """
    
    n,k=map(int,input().split())
    A=sorted(list(map(int,input().split())))
    M=0
    m=0

    for i in range(k-1,n):
        M+=A[i]*comb.combination(i,k-1)
        M%=MOD
    
    A.reverse()

    for i in range(k-1,n):
        m+=A[i]*comb.combination(i,k-1)
        m%=MOD
    
    print((M-m)%MOD)




    
resolve()

Measured memory_bytes: 156940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[330];
int N, K;

i64 dp[2][330][330]; // 0, 1, required K
vector<int> ones;
vector<int> acc;

void clr(int t)
{
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= K; ++j) dp[t][i][j] = 0;
	}
}

int main()
{
	scanf("%s%d", S, &K);

	N = strlen(S);
	S[N++] = '0';
	S[N] = 0;
	int n0 = 0, n1 = 0, n1d = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '0') {
			++n0;
			ones.push_back(n1d);
			acc.push_back(n1);
			n1d = 0;
		} else {
			++n1;
			++n1d;
		}
	}
	K = min(K, N);

	int t = 0;
	clr(t);
	dp[t][0][0] = 1;
	for (int i = 0; i < n0; ++i) {
		for (int j = 0; j <= n1; ++j) {
			for (int k = 0; k <= K; ++k) {
				dp[1 - t][j][k] = dp[t][j][k];
				if (j > 0) ADD(dp[1 - t][j][k], dp[1 - t][j - 1][k]);
			}
		}
		for (int j = 0; j <= n1; ++j) {
			for (int k = 0; k <= K; ++k) {
				for (int l = 0; l < ones[i]; ++l) {
					if (j + l > n1) break;
					ADD(dp[1 - t][j + l][k], MOD - dp[t][j][k]);
					if (k + ones[i] - l <= K) ADD(dp[1 - t][j + l][k + (ones[i] - l)], dp[t][j][k]);
				}
			}
		}
		for (int j = 0; j < acc[i]; ++j) {
			for (int k = 0; k <= K; ++k) {
				dp[1 - t][j][k] = 0;
			}
		}
		t = 1 - t;
	}
	i64 ret = 0;
	for (int i = 0; i <= n1; ++i) for (int j = 0; j <= K; ++j) ADD(ret, dp[t][i][j]);
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 4768
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = sum(a) % mod

ans = 0

for i in range(n):
    po -= a[i]
    po %= mod
    ans += (po * a[i])
    ans %= mod
print(ans)

Measured memory_bytes: 92108
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
using namespace std;

int main() {
	int N;
	cin >> N;
	unordered_map<string, int> order;
	vector<int> times(N,0);
	for (int i = 0; i < N; i++) {
		string title;
		int time;
		cin >> title >> time;
		times[i] = time;
		order[title] = i;
	}

	string X;
	cin >> X;
	int sleep_first = order[X] + 1;
	int ans = 0;
	for (int i = sleep_first; i < N; i++) ans += times[i];
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
  char str[100];
  int i;

  gets(str);
  for (i = 0; i < strlen(str); i++){
    str[i] = toupper(str[i]);
  }
  
  printf("%s\n", str);
  return (0);
}

Measured memory_bytes: 524
N=gets.to_i
A=gets.split.map(&:to_i)
a=[0,*A,0]
sum=0
(N+1).times{|i|
    sum+=(a[i]-a[i+1]).abs
}
warn sum
(1..N).each{|n|
    x=(a[n-1]-a[n]).abs
    y=(a[n]-a[n+1]).abs
    z=(a[n-1]-a[n+1]).abs
    puts sum-x-y+z
}


Measured memory_bytes: 23024