akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;




long long int N,M,sum=0,res=0;
string S,str;

int main()
{
    cout << fixed << setprecision(18);
    cin>>str;
    if(str.length()%2==1){cout<<"No"<<endl;return 0;}
    for(int i=0;i<str.length();i+=2){
        if(str[i]!='h'||str[i+1]!='i'){cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  int count = 0;
  int maxv = 0;
  for(int i = 0; i < N; i++){
    maxv = max(maxv, H.at(i));
    if(maxv == H.at(i)){
      count++;
    }
  }
  cout << count << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int N;
  cin >> N;
  int mi = 1e9 + 1;
  int ma = 0;
  for (int i = 0; i < N; i++) {
	  int A;
	  cin >> A;
	  mi = min(mi, A);
	  ma = max(ma, A);
	}
  cout << ma - mi << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n,a[100];
  ll dp[100][21];
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  for(int i=0;i<n-1;i++){
    if(i==0){
      fill(dp[0],dp[0]+21,0);
      dp[0][a[0]] = 1;
    }else{
      for(int j=0;j<=20;j++){
        dp[i][j] = 0;
        if(j+a[i]<=20) dp[i][j] += dp[i-1][j+a[i]];
        if(j-a[i]>=0) dp[i][j] += dp[i-1][j-a[i]];
      }
    }
  }
  printf("%lld\n",dp[n-2][a[n-1]]);
  return 0;
}

Measured memory_bytes: 2688
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()

    mod=10**9+7
    n=len(s)
    dp=[[0]*4 for _ in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        #i文字目を選ばない
        for j in range(4):
            if s[i-1]!="?":
                dp[i][j]+=dp[i-1][j]
            else:
                dp[i][j]+=dp[i-1][j]*3

        #i文字目を選ぶ
        if s[i-1]=="A":
            dp[i][1]+=dp[i-1][0]
        elif s[i-1]=="B":
            dp[i][2]+=dp[i-1][1]
        elif s[i-1]=="C":
            dp[i][3]+=dp[i-1][2]
        elif s[i-1]=="?":
            dp[i][1]+=dp[i-1][0]
            dp[i][2]+=dp[i-1][1]
            dp[i][3]+=dp[i-1][2]

        for j in range(4):
            dp[i][j]%=mod
            
    print(dp[n][3])
if __name__=="__main__":
    main()

Measured memory_bytes: 27596
t,s,i,k[999];main(n){for(;scanf("%d",&n)*n;puts(n?"No":"Yes")){for(i=n;i--;k[s]+=t)scanf("%d%d",&t,&s);for(n=t=0;++i<999;n|=t>i)t+=k[i],k[i]=0;}}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
  
{
  int a,b,A,B,C,Max;
  
  scanf("%d", &a);
  scanf("%d", &b);
  
  A = a + (a-1);
  B = b + (b-1);
  C = a + b;
  
  if(A>B && A>C)
    Max = A;
  
  else if(A==B || A==C)
    Max = A;
  
  if(B>A && B>C)
    Max = B;
  else if(B==A || B==C)
    Max = B;
  
  if(C>A && C>B)
    Max = C;
  else if(C==A || C==B)
    Max =C;
   
  
  printf("%d", Max);
  


  	return 0;
  
}

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


int main(int argc, char const* argv[])
{
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
long long f[55][2];
int main() {
	int n, P;
	scanf("%d%d", &n, &P);
	f[0][0] = 1;
	for (int i = 1; i <= n; ++ i) {
		int x; scanf("%d", &x);
		if (x & 1) {
			f[i][1] = f[i - 1][1] + f[i - 1][0];
			f[i][0] = f[i - 1][0] + f[i - 1][1];
		} else {
			f[i][0] = f[i - 1][0] * 2;
			f[i][1] = f[i - 1][1] * 2;
		}
	}
	printf("%lld\n", f[n][P]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)

struct mint {
	ll x;
	mint(ll x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint c(int n, int k) {
	mint a = 1, b = 1;
	rep(i, k) {
		a *= n - i;
		b *= i + 1;
	}
	return a / b;
}



void solve() {
	int n;
	cin >> n;
	n -= 5;
	mint ans;
	for (int o = 0; o <= 11; o++) {
		int m = n - o;
		if (m < 0 || m % 2 != 0) continue;
		ans += c(m / 2 + 15, 15) * c(11, o);
	}
	cout << ans << endl;
}


int main() {
	int ts;
	cin >> ts;
	rep(ti, ts) solve();
	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;

int main(void){
    int r, D, x;
    cin >> r >> D >> x;
    int x_ = x;
    for(int i=0; i < 10; i++ ){
        x_ = r*x_ - D;
        cout << x_ << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

long long calc(vector<long long>&a, long long b) {
	long long val = 0;
	for (auto x: a) {
		val += abs(x - b);
	}
	return val;
}

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

	vector<long long> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}

	sort(a.begin(), a.end());

	auto x1 = calc(a, a[n / 2]);
	auto x2 = calc(a, a[n / 2 + 1]);

	cout << min(x1, x2) << endl;
	return 0;
}


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

int main() {
    int ans =0 ;
    int M, D; scanf("%d%d",&M,&D);
    for(int i=1; i<=M; i++) {
        for(int j=1; j<=D; j++) {
            int a = j/10, b = j%10;
            if(a >= 2 && b >= 2 && a*b == i) ++ans;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<string>
#include <stack>
#include<queue>
#include<map>
#include <stdlib.h>

using namespace std;

int main() {

	int r,g,b,n,cnt=0;
	cin>>r>>g>>b>>n;
	for(int i=0;i<3001;i++){
		for(int j=0;j<3001;j++){
			if(r*i+g*j+abs(b*((n-r*i-g*j)/b))==n)cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : ABC 117 C
 *      author  : kyomukyomupurin
 *      created : 
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m; cin >> n >> m;
    int64 x[m];
    rep(i, m) cin >> x[i];

    sort(x, x + m);

    int64 diff[m - 1];
    rep(i, m - 1){
        diff[i] = x[i + 1] - x[i];
    }

    sort(diff, diff + m - 1);

    int64 ans = 0;

    for (int i = 0; i < (m - n); ++i){
        ans += diff[i];
    }

    print(ans);
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	long long a[100000], b, i, count = 0;
	cin >> b;
	for (i = 1; i <= b; i++)
		cin >> a[i];
	if (b == 1)
	{
		cout << "Yes";
		return 0;
	}
	for (i = 1; i < b; i++)
	{
		if (a[i] > a[i+1])
			count++;
		else if (a[i] < a[i+1])
			count = 0;
		if (a[i] - a[i+1] > 1)
		{
			cout << "No";
			return 0;
		}
		if (count >= 2)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define mp make_pair
// GCD inbuilt func: __gcd(a,b)
// LCM formula: (a*b)/__gcd(a,b)

int BS(vector<int> &v, int low, int high, int k){
    while(low<=high){
        int mid=(low+high)/2;
        if(v[mid]==k) return mid;
        else if(v[mid]>k) high=mid-1;
        else low=mid+1;
    }
    return -1;
}

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	// CODE goes here
    int k,n;
    cin >> k >> n;
    vector<int> v;
    for(int i=0;i<n;i++){
    	int x;
    	cin >> x;
    	v.push_back(x);
    }
    sort(v.begin(),v.end());
    if(n==0){
    	cout << k;
    	return 0;
    }
    int i=0;
    int ans;
    while(1){
    	int x=BS(v,0,n-1,k-i);
    	int y=BS(v,0,n-1,k+i);
    	if(x==-1){
    		ans=k-i;
    		break;
    	}
    	if(y==-1){
    		ans=k+i;
    		break;
    	} 
    	i++;
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 3636
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,x;
  cin >> n >> a >> b;
  x=n/(a+b)*a;
  cout << x+min(n%(a+b),a) << endl;
}

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

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);


int main(void) {

	int   len,i;
	char  S[51];

	s_cin(S);
	len = (int)strlen(S);

	if (len < 5 || len>9) { s_cout("NO"); return 0; }
	if (!memcmp(S, "AKIHABARA", 9)) { s_cout("YES"); return 0; }
	if (!memcmp(S, "KIHBR", 5)) { s_cout("YES"); return 0; }
	if (!memcmp(S, "AKIH", 4)) i = 4;
	else if (!memcmp(S, "KIH", 3)) i = 3;
	else  { s_cout("NO"); return 0; }
	
	if (!memcmp(&S[i],"AB",2) ) i+=2;
	else {
		if (S[i] != 'B') { s_cout("NO"); return 0; }
		i++;
	}

	if (!memcmp(&S[i], "AR", 2)) { s_cout("YES"); return 0; }
	if (S[i] == 'R')             { s_cout("YES"); return 0; }
	
	s_cout("NO");
	return 0;
}

//降順
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
//
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	rept(i, 0, n) {
		i_cin(*(a + i));
	}
	return 0;
}




Measured memory_bytes: 128
def pin(type=int):
    return map(type,input().split())
    
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
"""

#solution:
#input
a,b=pin()
if a*b<=0:print("Zero")
elif a>0 :print("Positive")
else:
    if (b-a+1)%2==0:print("Positive")
    else:print("Negative")

Measured memory_bytes: 38256
#include <stdio.h>

int main(void)
{
int a,b;

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

if(a<b){
printf("a < b\n");
}else if(a>b){
printf("a > b\n");
}else if(a==b){
printf("a == b\n");
}

return 0;
}

Measured memory_bytes: 580
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int n,m,ok=0,ng=0;
	cin>>n>>m;
	string s;cin>>s;
	rep(i,n-1){
		if(s[i]==s[i+1]) ok++;else ng++;
	}
	cout<<ok+min(m*2,ng)<<endl;
}


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

string c2s( char ch ) {
  if(ch == ' ') return "11010";
  if(ch == '.') return "11011";
  if(ch == ',') return "11100";
  if(ch == '-') return "11101";
  if(ch == '\'') return "11110";
  if(ch == '?') return "11111";

  int n = ch-'A';
  string ret;
  for(int i=4; i>=0; i--) ret += n & (1<<i) ? '1' : '0';
  return ret;
}

map<string, char> sym;

void initsym() {
  sym["101"] = ' ';
  sym["000000"] = '\'';
  sym["000011"] = ',';
  sym["10010001"] = '-';
  sym["010001"] = '.';
  sym["000001"] = '?';
  sym["100101"] = 'A';
  sym["10011010"] = 'B';
  sym["0101"] = 'C';
  sym["0001"] = 'D';
  sym["110"] = 'E';
  sym["01001"] = 'F';
  sym["10011011"] = 'G';
  sym["010000"] = 'H';
  sym["0111"] = 'I';
  sym["10011000"] = 'J';
  sym["0110"] = 'K';
  sym["00100"] = 'L';
  sym["10011001"] = 'M';
  sym["10011110"] = 'N';
  sym["00101"] = 'O';
  sym["111"] = 'P';
  sym["10011111"] = 'Q';
  sym["1000"] = 'R';
  sym["00110"] = 'S';
  sym["00111"] = 'T';
  sym["10011100"] = 'U';
  sym["10011101"] = 'V';
  sym["000010"] = 'W';
  sym["10010010"] = 'X';
  sym["10010011"] = 'Y';
  sym["10010000"] = 'Z';
}

int main() {
  initsym();
  
  string s, str, res, temp;
  while(getline(cin, s)) {
    str = res = temp = "";
    for(unsigned i=0; i<s.size(); i++) str += c2s(s[i]);
    for(unsigned i=0; i<str.size(); i++) {
      temp += str[i];
      if(sym.count(temp)) res+=sym[temp], temp="";
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int graph[1001][1001];
int from[1001][1001];
int coun[1001][1001];
int level[1001][1001];
bool fin[1001][1001];
queue<pair<int, int> > que;
int ans, n, hage;
bool flg;

bool is_loop(){
	for (int i = 1; i <= n; i++){
		for (int j = i+1; j <= n; j++){
			if (from[i][j] == 0){
				que.push(make_pair(i, j));
			}
			if (graph[i][j] == 0 && graph[j][i] == 0){
				fin[i][j] = true;
			}
		}
	}
	if (que.empty()) return true;
	return false;
}

int dfs(int now1, int now2){
	hage++;
	if (hage >= n*n){
		flg = true;
		return 0;
	}
	if (level[now1][now2] != 0) return level[now1][now2];
	if (fin[now1][now2]) return 0;
	if (graph[now1][now2] && graph[now2][now1]){
		int a = dfs(min(now1, graph[now1][now2]), max(now1, graph[now1][now2])) + 1;
		int b = dfs(min(now2, graph[now2][now1]), max(now2, graph[now2][now1])) + 1;
		level[now1][now2] = max(a, b);
		return level[now1][now2]; 
	}
	if (graph[now1][now2]){
		return level[now1][now2] = dfs(min(now1, graph[now1][now2]), max(now1, graph[now1][now2])) + 1;
	}
	if (graph[now2][now1]){
		return level[now1][now2] = dfs(min(now2, graph[now2][now1]), max(now2, graph[now2][now1])) + 1;
	}
}

int main(){
	cin >> n;
	for (int i = 1; i <= n; i++){
		int hoge;
		cin >> hoge;
		for (int j = 0; j < n-2; j++){
			cin >> graph[i][hoge];
			hoge = graph[i][hoge];
		}
	}

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (i != j){
				from[min(i, graph[i][j])][max(i, graph[i][j])]++;
			}
		}
	}
	if (is_loop()){
		cout << -1 << endl;
		return 0;
	}

	while(!que.empty()){
		pair<int, int> p = que.front();
		que.pop();
		dfs(p.first, p.second);
	}

	if (flg){
		cout << -1 << endl;
		return 0;		
	}

	int ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			ans = max(ans, level[i][j]);
		}
	}
	cout << ans+1 << endl;
	return 0;
}

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

int main()
{
  //int n;
  int a;
  int b;
  int c;
  int cnt = 0;
  cin >> a >> b >> c;
  for(int i = a; i <= b ; i++)
  {
      if((c % i) == 0)cnt = cnt + 1;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3116
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,m=MI()
    a = LI()
    s = sum(a)
    if s>n:
        print(-1)
    else:
        print(n-s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 10244
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int d,s,t;
	cin >> d >> s >> t;
	if(d <= s * t) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int x=a/1000,y=a/100%10,z=a/10%10,qiutianyidalao=a%10;
	if(y==z&&(x==y||z==qiutianyidalao))
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main() {
	int H, W;
	scanf("%d %d", &H, &W)+1;

	char** A = new char* [H+2];
	A[0] = new char[W + 2];
	memset(A[0], '*', W + 2);
	A[H+1] = new char[W + 2];
	memset(A[H+1], '*', W + 2);
	for (int i = 1; i < H + 1; i++) {
		A[i] = new char[W+2];
		scanf("%s", &(A[i][1])) + 1;
		A[i][0] = A[i][W + 1] = '*';
	}

	vector<pair<int, int>>* memori = new vector<pair<int, int>>;
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			if (A[i][j] == '.' && (A[i - 1][j] == '#' || A[i + 1][j] == '#' || A[i][j - 1] == '#' || A[i][j + 1] == '#')) {
				A[i][j] = '*';
				memori->push_back(make_pair(i, j));
			}
		}
	}

	int count = 0;
	while (memori->size() != 0) {
		count++;
		auto before = memori;
		memori = new vector<pair<int, int>>;
		auto beg = before->begin();
		auto end = before->end();
		for (auto itr = beg; itr != end; itr++) {
			int i = itr->first;
			int j = itr->second;
			if (A[i-1][j] == '.') {
				A[i-1][j] = '*';
				memori->push_back(make_pair(i-1, j));
			}
			if (A[i+1][j] == '.') {
				A[i+1][j] = '*';
				memori->push_back(make_pair(i+1, j));
			}
			if (A[i][j-1] == '.') {
				A[i][j-1] = '*';
				memori->push_back(make_pair(i, j-1));
			}
			if (A[i][j+1] == '.') {
				A[i][j+1] = '*';
				memori->push_back(make_pair(i, j+1));
			}
		}
		delete before;
	}

	printf("%d", count);

	return 0;
}


Measured memory_bytes: 12400
mod=10**9+7
n=input()
D=int(input())
N=len(n)+1
dp=[[[0 for i in range(2)] for j in range(D)] for k in range(len(n)+1)]
dp[0][0][0]=1
for a in range(N-1):
  x=int(n[a])
  for b in range(D):
    for d in range(10):
      if d<x:
        dp[a+1][(b+d)%D][1]+=dp[a][b][0]+dp[a][b][1]
      elif d==x:
        dp[a+1][(b+d)%D][0]+=dp[a][b][0]
        dp[a+1][(b+d)%D][1]+=dp[a][b][1]
      else:
        dp[a+1][(b+d)%D][1]+=dp[a][b][1]
      dp[a+1][(b+d)%D][1]%=mod
      dp[a+1][(b+d)%D][0]%=mod
ans=sum(dp[-1][0])
print((ans-1)%mod)

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

const int MAXN = 100005;
const long double eps = 1e-8;

inline int read()
{
	int a = 0, c;
	do c = getchar(); while (!isdigit(c));
	while (isdigit(c)) {
		a = a*10+c-'0';
		c = getchar();
	}
	return a;
}

int n, mod, T;
int x[MAXN], w[MAXN];
int a[MAXN];
pair<int,int> p[MAXN];

int main()
{
	n = read(), mod = read(), T = read();
	int pox = -1, poy = -1, c = 0;
	for (int i = 0; i < n; i++) {
		x[i] = read(), w[i] = read();
		if (w[i] == 1) pox = i, c++;
		else poy = i;
	}
	if (pox == -1) {
		for (int i = 0; i < n; i++)
			printf("%d\n", ((x[i]-T)%mod+mod)%mod);
	} else if (poy == -1) {
		for (int i = 0; i < n; i++)
			printf("%d\n", ((x[i]+T)%mod+mod)%mod);
	} else {
		int cnt = pox;
		for (int i = 0; i < n; i++)
			if (w[i] == 2) {
				int T_first = i > pox ? (x[i]-x[pox]) : mod-(x[pox]-x[i]);
			        if (T_first > T*2) continue;
				cnt = (cnt+1ll+(2*T-T_first)/mod)%n;
			}
		for (int i = 0; i < n; i++) {
			if (w[i] == 1)
				p[i] = make_pair((x[i]+T)%mod, i);
			else p[i] = make_pair(((x[i]-T)%mod+mod)%mod, i);
		}
		// cerr << pox << " " << cnt << endl;
		sort(p, p+n);
		int pp = 0;
		for (int i = 0; i < n; i++) {
			// cerr << p[i].first << " ";
			if (p[i].second == pox)
				pp = i;
		}
		// cerr << endl;
		for (int i = pp, c = cnt; i < pp+n; i++, c = (c+1)%n)
			a[c%n] = p[i%n].first;
		for (int i = 0; i < n; i++)
			printf("%d\n", a[i]);
	}
	return 0;
}


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

int main()
{
  	std::string line;
  	std::getline(std::cin, line);
  
  	int n = 0, m = 0;
  	for (auto c : line)
    {
      	switch (c)
        {
          case 'A':
          case 'C':
          case 'T':
          case 'G':
            ++n;
            break;
          default:
            m = std::max(n, m);
            n = 0;
            break;
        }
    }
  	m = std::max(n, m);

  	std::cout << m << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll  long long 
const ll INF=1LL<<60;
const ll MOD=1000000007;
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
ll dp[2001];
int main(){
    ll a;cin>>a;
    dp[1]=0;
    dp[2]=0;
    dp[3]=1;
    dp[4]=1;
    if(a<=4)cout<<dp[a];
    else{for(ll i=5;i<=a;i++){
        dp[i]=dp[i-2]+dp[i-3]+dp[i-4];
        dp[i]%=MOD;
    }
    cout<<dp[a];
}}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  if(a<b){
   System.out.println("a < b");
  }
  else if(a>b){
   System.out.println("a > b");
  }
  else{
   System.out.println("a == b");
  }
 }
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    vll a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << a[k-1] << endl;
    // cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;

int N;
P ps[3000];

int f(int i,int j){
    int dx=ps[i].first-ps[j].first;
    int dy=ps[i].second-ps[j].second;

    if(!binary_search(ps,ps+N,P(ps[i].first+dy,ps[i].second-dx)))return 0;
    if(!binary_search(ps,ps+N,P(ps[j].first+dy,ps[j].second-dx)))return 0;
    return dx*dx+dy*dy;
}
void solve(){
    for(int i=0;i<N;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        ps[i]=P(x,y);
    }
    sort(ps,ps+N);
    int ma=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j)continue;
            ma=max(ma,f(i,j));
        }
    }
    printf("%d\n",ma);
}

int main(){
    while(scanf("%d",&N),N)solve();
    return 0;
}

Measured memory_bytes: 1212
import sys
#from typing import *


def main(argv):
    # type: (List[str]) -> int
    a, b, *_ = map(int, argv) # type: Tuple[int, int, Any]
    if a % 2 == 0 or b % 2 == 0:
        print("Even")
    else:
        print("Odd")
    return 0

if __name__ == '__main__':
    # main(sys.argv[1:])
    main(input().split())


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

struct node{
	int data;
	node *l, *r;
};

node *new_node(int in){
	node *ret = new node;
	ret->data = in;
	ret->l = NULL;
	ret->r = NULL;
	return ret;
}

void insert_node(node **root, int in){
	node *add = new_node(in);
	if(*root == NULL){
		*root = add;
		return ;
	}
	node *p = *root, *pp = NULL;
	while(p != NULL){
		pp = p;
		if(add->data < p->data) p = p->l;
		else p = p->r;
	}
	if(add->data < pp->data) pp->l = add;
	else pp->r = add;
	return ;
}

void print_n(node *root, bool mode){
	if(mode == true) cout << " " << root->data;
	if(root->l != NULL) print_n(root->l, mode);
	if(mode == false) cout << " " << root->data;
	if(root->r != NULL) print_n(root->r, mode);
}

void print_node(node *root){
	print_n(root, false);
	cout << endl;
	print_n(root, true);
	cout << endl;
}

void find_node(node *root, int in){
	bool ans = false;
	while(root != NULL){
		if(in == root->data){
			ans = true;
			break;
		}else if(in < root->data){
			root = root->l;
		}else{
			root = root->r;
		}
	}
	if(ans == false) cout << "no" << endl;
	else cout << "yes" << endl;
}

int main(){
	int n;
	cin >> n;
	node *root = NULL;
	rep(i, n){
		string s;
		cin >> s;
		if(s == "print"){
			print_node(root);
		}else if(s == "find"){
			int in;
			cin >> in;
			find_node(root, in);
		}else{
			int in;
			cin >> in;
			insert_node(&root, in);
		}
	}
	return 0;
}


Measured memory_bytes: 15656
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n,int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}

void yes() {
	cout << "Yes" << endl;
}

void no() {
	cout << "No" << endl;
}

bool is_palindrome(string s) {
	string t(s.rbegin(), s.rend());
	return s == t;
}

int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) && is_palindrome(s.substr((n + 1) / 2))) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
int ans;

const int mod = 1000000007;
int cost[101][2];
int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n;
    cin >> n;

    

    for(int i = 1; i <= n; i++)
    {
      cin >> cost[i][0];
      cost[i][0] += cost[i-1][0];
    }

    for(int i = 1; i <= n; i++)
    {
      cin >> cost[i][1];
      cost[i][1] += max(cost[i-1][1],cost[i][0]);
    }

    cout << cost[n][1];











    return 0; 
}


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


int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)return 0;
		ivec A;
		for (int i = 0; i < n; i++)
		{
			int s;
			scanf("%d", &s);
			A.push_back(s);
		}
		sort(A.begin(), A.end());
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			if (i == 0 || i == n - 1)continue;
			sum += A[i];
		}
		printf("%d\n", sum / (n - 2));
		
	}
	return 0;
}

Measured memory_bytes: 3136
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N, K;
    int h[100001];
    cin >> N >> K;
    rep(i, 0, N) cin >> h[i];    
    int dp[100001];
    dp[0] = 0;
    for(int i=1; i<N; i++){
        int minCost = dp[i-1] + abs(h[i] - h[i-1]);
        for(int k=1; k<=K; k++){
            if(i-k >= 0){
                minCost = min(minCost, dp[i-k] + abs(h[i] - h[i-k])); 
            }
        } 
        dp[i] = minCost;
    }
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>
#include <cassert>

// aliases
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

// graph
using Graph = Vvec<int>;
class Edge{
public:
    int to;
    long long cost;
    Edge(int v, long long c = 1): to(v), cost(c){}
    ~Edge(){}
    bool operator<(const Edge& e) const{return cost < e.cost;}
};
using WeightedGraph = Vvec<Edge>;

// for debug
template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

// answer

// basisの要素を2元体上のベクトルとみなす
// span{basis}がaを含むかどうか
// 含まない場合basisを更新
bool isIncluded(vector<ll>& basis, ll a){
    for(auto& b: basis){
        if(b & (-b) & a) a ^= b;
    }
    if(a == 0) return true;
    for(auto& b: basis){
        if(a & (-a) & b) b ^= a;
    }
    basis.emplace_back(a);
    return false;
}

int solve(const int N, const vector<ll>& A, const string& S){
    vector<ll> basis;
    for(int i=N-1; i>=0; i--){
        bool flag = isIncluded(basis, A[i]);
        if(flag) continue;
        if(S[i]=='1') return 1;
    }
    return 0;
}

int main()
{
    int T;
    cin >> T;
    vector<int> ans(T);
    for(int t=0; t<T; t++){
        int N;
        cin >> N;
        vector<ll> A(N);
        for(auto& e: A) cin >> e;
        string S;
        cin >> S;

        ans[t] = solve(N, A, S);
    }
    for(auto& e: ans) cout << e << "\n";
}

Measured memory_bytes: 3020
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool used[105];
vector<int> edge[105];
int n, a, b;

int dfs(int x){
    if(edge[x].empty())return 0;
    if(used[x])return 0;
    int res = 0;
    used[x] = true;
    for(int i = 0;i < edge[x].size();i++){
	res = max(res, dfs(edge[x][i]));
    }
    used[x] = false;
    return res + 1;
}

int main(){
    while(true){
	cin >> n;
	if(n == 0)return 0;
	for(int i = 0;i < 100;i++){
	    edge[i].clear();
	}
	for(int i = 0;i < n;i++){
	    cin >> a >> b;
	    a--,b--;
	    edge[a].push_back(b);
	    edge[b].push_back(a);
	}
	int res = 0;
	for(int i = 0;i < 100;i++){
	    res = max(res, dfs(i));
	}
	cout << res << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> vec;
vector<vector<int>> now;
bool dfs(int i){
    int ii=now.at(i).at(0);
    if(ii==-1){return false;}
    if(now.at(ii).at(0)==i){return true;}
    else{return false;}
}
int main(){
    int N;
    cin>>N;
    vec.resize(N,vector<int>(N-1));
    now.resize(N,vector<int>(0));
    vector<int> enemy(N);
    for(int i=0;i<N;i++){//O(N^2)
        for(int j=0;j<N-1;j++){
            int a;
            cin>>a;
            vec.at(i).at(j)=a-1;
            if(j==0){
                now.at(i).push_back(a-1);
            }
        }
        enemy.at(i)=0;
    }
    long long count=0;
    long long day=0;
    //countはN(N-1)/2まで
    while(count<N*(N-1)/2){//O(N^3)
        unordered_map<int,int> mp;
        int memo=count;
        day++;
        for(int i=0;i<N;i++){
            //cout<<count<<" "<<i<<endl;
            if(dfs(i) && mp[i]==0 && mp[now.at(i).at(0)]==0 && now.at(i).at(0)!=-1){
                count++;
                int a=i;
                int b=now.at(i).at(0);
                enemy.at(a)++;
                enemy.at(b)++;
                mp[a]=1;
                mp[b]=1;
                //cout<<a<<" "<<b<<"   "<<enemy.at(a)<<" "<<enemy.at(b)<<endl;
                if(enemy.at(a)<N-1){
                    //cout<<a<<" "<<b<<" "<<enemy.at(a)<<endl;
                    now.at(a).at(0)=vec.at(a).at(enemy.at(a));
                }
                else{
                    now.at(a).at(0)=-1;
                }
                if(enemy.at(b)!=N-1){
                    //cout<<" "<<a<<" "<<b<<" "<<enemy.at(b)<<endl;
                    now.at(b).at(0)=vec.at(b).at(enemy.at(b));
                }
                else{
                    now.at(b).at(0)=-1;
                }
            }
        }
        if(memo==count){
            cout<<-1<<endl;
            return 0;
        }
        mp.clear();
    }
    cout<<day<<endl;
}


Measured memory_bytes: 7616
import sys
readline = sys.stdin.readline


def st(line):
    tmp = ''
    for l in line:
        if l == '\n':
            yield tmp
        elif l == ' ':
            yield tmp
            tmp = ''
        else:
            tmp += l


def solve():
    N = int(input())
    As = st(readline())

    d = dict()
    total = 0
    for a in As:
        a = int(a)

        if a in d:
            d[a] += 1
        else:
            d[a] = 1
        total += a

    Q = int(input())
    queries = (map(int, readline().strip().split()) for _ in range(Q))

    for que in queries:
        b, c = que

        if b not in d:
            print(total)
            continue

        n_b = d[b]
        d[b] = 0

        if c not in d:
            d[c] = 0

        d[c] += n_b
        total += (c - b) * n_b

        print(total)


def main():
    solve()


if __name__ == "__main__":
    main()

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

int main(void){
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll p=n/i;
        ans+=i*(1+p)*p/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3568
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
from heapq import heappop,heappush
h=[]
heappush(h,-a[0])
ans=0
for i in a[1:]:
  ans-=heappop(h)
  heappush(h,-i)
  heappush(h,-i)
print(ans)

Measured memory_bytes: 31752
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int MOD = (int)1e9 + 7;
const int MX = (int)2e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

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

vector<int> read(int n, int k){
	vector<int> vec(n);
	for(int i = 0; i < k; ++i) cin >> vec[i];
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = k; i < n; ++i)
		vec[i] = (a * 1ll * vec[i - 2] + b * 1ll * vec[i - 1] + c) % d;
	return vec;
}

int eval(const set<int>& st, int mid){
	assert(!st.empty());
	auto it = st.lower_bound(mid);
	auto prv = prev(it);
	assert(prv != st.end());
	int fs = *prv - *st.begin(); // first half
	int sc = *st.rbegin() - *it; // second half
	assert(sc >= 0);
	assert(fs >= 0);
	return fs + sc;
}

int calc (const set<int>& st){
	// assert(!st.empty());
	if(st.size() <= 2) return 0;
	int l = *st.begin(), r = *st.rbegin();
	int best = r - l;
	while(r - l >= 2){
		int third = (r - l + 1) / 3;
		int fs = l + third;
		int sc = r - third;
		int fs_ev = eval(st, fs);
		int sc_ev = eval(st, sc);
		best = min(fs_ev, sc_ev);
		if(fs_ev < sc_ev) r = sc;
		else l = fs;
	}
	return best;
}

void solve(){
	string s;
	cin >> s;
	if(s.back() == 's') s += "es";
	else s += "s";
	cout << s << "\n";
	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3624