akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
string S;
int dp[4040][4][20];

void solve() {
    dp[0][0][0] = 1;
    FOR (x, 1, N + 1) {
        FOR (i, 0, 4) {
            FOR (s, 0, 8) {
                dp[x][i][s] = dp[x - 1][i][s];
                if (i > 0 && s - S[x - 1] >= 0)
                    dp[x][i][s] += dp[x - 1][i - 1][s - S[x - 1]];
                //cout << x << " " << i << " " << s << " : " << dp[x][i][s] << endl;
            }
        }
    }
    int ans = dp[N][3][7];
    FOR (i, N) {
        FOR (j, i + 1, N) {
            if ((j - i) % 2 == 0) {
                int k = (j + i) / 2;
                if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k])
                    ans--;
            }
        }
    }
    cout << ans << endl;
}

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

    cin >> N >> S;
    for (auto& c : S) {
        if (c == 'R')
            c = 1;
        if (c == 'G')
            c = 2;
        if (c == 'B')
            c = 4;
    }

    solve();
    return 0;
}


Measured memory_bytes: 6100
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
for i in range(h):
    if '#' not in a[i]:
        a[i]=['n']*w
for i in range(w):
    l=[a[j][i] for j in range(len(a))]
    if '#' not in l:
        for k in range(len(a)):
           a[k][i]='n'
for i in a:
    l=[x for x in i if x!='n']
    if l:
        print(''.join(l))

Measured memory_bytes: 3064
#include <stdio.h>
int main() {
	while (1) {
		int n, k, j, sum = 0,f=0;
		scanf("%d", &n);
		if (n == 0)
			break;
		for (j = 0; j < n; j++) {
			scanf("%d", &k);
			if (k>0)
				sum++;
			if (k >= 2)
				f++;
		}
		if (f==0)
			printf("NA\n");
		else
			printf("%d\n", sum + 1);
	}
	return 0;
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	int n = nxt(), k = nxt();
	if (k == 1 || k == 2 * n - 1) {
		puts("No");
	} else {
		cout << "Yes\n";
		if (n == 2) {
			cout << "1\n2\n3\n";
			return 0;
		}
		int cur = 1;
		int l1 = k + 1, r1 = k - 1, r2 = k - 2;
		if (k == 2) {
			l1 = k - 1;
			r1 = k + 1;
			r2 = k + 2;
		}
		for (int i = 0; i < 2 * n - 1; i++) {
			if (i == n - 3) {
				cout << r1 << "\n";
			} else if (i == n - 2) {
				cout << l1 << "\n";
			} else if (i == n - 1) {
				cout << k << "\n";
			} else if (i == n) {
				cout << r2 << "\n";
			} else {
				while (cur == l1 || cur == r1 || cur == r2 || cur == k) {
					cur += 1;
				}
				cout << cur++ << "\n";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = 998244353;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    Factorial[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}


//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll k = 0;
    rep0(i, n){
        cin >> a[i];
        k ^= a[i];
    }
    cout << ll(a[0] ^ k);
    rep1(i, n - 1)cout << " " << ll(a[i] ^ k);
    cout << endl;
    return 0;
}


Measured memory_bytes: 4772
#include<iostream>
#include<string>

int main()
{
	int a,b,c,d,ans=0;
	
	std::cin >> a >> b >> c >> d;
	
	if(a>b) ans+=b;
	else ans+=a;
	if(c>d) ans+=d;
	else ans+=c;
	std::cout << ans << std::endl;
}

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

using namespace std;

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

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

    function<long long (long long, long long)> gcd = [&](long long x, long long y) {
        return (y == 0 ? x : gcd(y, x % y));
    };

    auto lcm = [&](long long x, long long y) {
        return (x * y) / gcd(x, y);
    };

    long long l =  a[0] / 2;
    long long lcmDiff = a[0];
    for (int i = 1; i < n; ++i) {
        l = lcm(l, a[i] / 2);
        lcmDiff = lcm(lcmDiff, a[i]);
    }

    auto ok = [&](long long target) {
        for (long long val : a) {
            long long d = target - val / 2;
            if (d < 0 || d % val) {
                return false;
            }
        }
        return true;
    };

    if (l > right || !ok(l)) {
        cout << "0\n";
        return 0;
    }
    cout << 1 + (right - l) / lcmDiff << '\n';

    return 0;
}


Measured memory_bytes: 3952
#include<stdio.h>
#include<string.h>
int main(void){
  char str1[101],str2[101],tmp;
  int i,j;
  scanf("%s",str1);
  scanf("%s",str2);
  for(i=1;i<=strlen(str1);i++){
    if(strcmp(str1,str2)==0){
      printf("Yes");
      return 0;
    }
    for(j=(strlen(str1)-1);j>=-1;j--){
      if(j==(strlen(str1)-1)){
        tmp=str1[j];
      }else if(j==-1){
        str1[j+1]=tmp;
      }else{
        str1[j+1]=str1[j];
      }
    }
  }
  printf("No");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n;
    cin>>n;
    int ctr=log2(n);
    if ((1<<ctr)>n)
        ctr--;
    cout<<(1<<ctr)<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<climits>

int max(int a, int b){
	return (a > b)? a : b;
}

int maxRange(int* a, int start, int end){
	int max = INT_MIN;
	for(int i = start; i <= end; i++){
		if(a[i] > max) max = a[i];
	}
	return max;
}

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

	int max_range = INT_MIN;
	int min = R[0];
	int max_v = maxRange(R, 1, N-1);
	for(int i = 0; i < N-1; i++){
		if(R[i] < min) min = R[i];
		if(R[i] == max_v) max_v = maxRange(R, i+1, N-1);
		max_range = max( max_range , max_v - min );
	}
	printf("%d\n", max_range);
	return 0;

}

Measured memory_bytes: 1804
s = str(input())

is_yymm = False
is_mmyy = False

if 0 < int(s[:2]) < 13:
    is_mmyy = True
if 0 < int(s[2:4]) < 13:
    is_yymm = True

ans = ""
if is_yymm and not is_mmyy:
    ans = "YYMM"
elif is_mmyy and not is_yymm:
    ans = "MMYY"
elif is_yymm and is_mmyy:
    ans = "AMBIGUOUS"
else:
    ans = "NA"
print(ans)

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

int main(){
    int N;
    cin >> N;
    ll abs_sum=0;
    ll min_num=1'000'000'000;
    
    int count_negative=1;
    rep(i,N){
        ll x;
        cin >> x;
        if(x<0){
            count_negative *=-1;
        }
        
        abs_sum += abs(x);
        min_num = min(min_num, abs(x));
    }
    
    if(count_negative == -1){
        abs_sum -= min_num*2;
    }
   
   cout << abs_sum << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    atmp,btmp = (int(num) for num in input().split())
    a[i] = atmp
    b[i] = btmp
    
a.sort()
b.sort()
minval = 0
maxval = 0
ans = 0
if n % 2 == 0:
    minval = (a[n//2-1] + a[n//2]) / 2
    maxval = (b[n//2-1] + b[n//2]) / 2
    ans = int((maxval - minval) * 2 + 0.00001) + 1
else:
    minval = a[n//2]
    maxval = b[n//2]
    ans = maxval - minval + 1
    
print(ans)

Measured memory_bytes: 25516
H, W = map(int, raw_input().split())
ans = H*W 

for loop in xrange(2):
    ans = min(ans, (((H - H/3) + 1)/2 - H/3)*W)
    for w in xrange(1, W):
        h = H/2
        mx = max(w*H, (W - w)*(H - h))
        mn = min(w*H, (W - w)*h)
        ans = min(ans, mx - mn)
    H, W = W, H

print ans


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60) {
        ll x = 0;
        rep(j,n) if (a[j]>>i & 1) x++;
        ll now = x*(n-x)%mod; //今考えてる桁から生じる和
        rep(k,i) now = now*2%mod;
        ans += now;
        ans %= mod;
    }
   cout << ans << endl; 
}

Measured memory_bytes: 5624
#include <iostream>
#include <vector>

int main() {
    int64_t n, k;
    std::cin >> n >> k;
    std::vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    int64_t in = 0, out = 0;
    for (int i = 0; i < n; i++) {
        // A の中での転倒数
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                in++;
            }
        }
        // その数字より小さな数
        for (int j = 0; j < n; j++) {
            if (i != j and a[i] > a[j]) {
                out++;
            }
        }
    }

    const int64_t mod = 1e9 + 7;
    int64_t ans = (in * k % mod + out * (k * (k - 1) / 2 % mod) % mod) % mod;

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct po{
  int I,U,A,P,sum;
};

int main (){
  int n;

  while(1) {
  cin >> n;
  if (n == 0) break;
  vector <po> D;
  D.resize(n);
  for(int i=0;i<n;i++) cin >> D[i].I >> D[i].U >> D[i].A >> D[i].P;

  po t;
  for(int i=0;i<n;i++) {
    for(int j=n-1;j>i;j--){
      if(D[j].A > D[j-1].A){
	t = D[j];
	D[j] = D[j-1];
	D[j-1] = t;
      }
      if(D[j].A == D[j-1].A) {
	if(D[j].P < D[j-1].P) {
	  t = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
	if(D[j].P == D[j-1].P && D[j].U <= D[j-1].U) {
	  t  = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
      }
    }
  }

  int goukei = 0;
  int flg[1001] = {};

  for(int i=0;i<n;i++) {
    if(goukei < 10 && flg[D[i].U] < 3) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 20 && flg[D[i].U]< 2) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 26 && flg[D[i].U] == 0) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
  }

  }

  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

map <int,int> mp;

int a[200005];
bool f[200005];
int res[200005];

int main()
{
	int k,n;
	cin>>k>>n;
	for(int i=0;i<k;i++)
	{
		cin>>a[i];
		f[a[i]]=1;
		mp[a[i]]++;
	}
	
	int num=0;
	for(int i=0;i<k;i++)
	{
		if(f[a[i]])
		{
			res[num++]=mp[a[i]];
			f[a[i]]=false;
		}
	}
	
	sort(res,res+num);
	int x=num-n;
	int ans=0;
	for(int i=0;i<x;i++)
	{
		ans+=res[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11392
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;

int binarySearch(vector<int> vec, int key) {
    // key: 検索対象の値
    int left = 0, right = vec.size(), mid;

    while (left < right) {
        mid = (left + right)/2;
        if (vec[mid] == key) {
            return mid;
        } else if (key < vec[mid]) {
            // 半分より下
            right = mid;
        } else if (vec[mid] < key) {
            // 半分より上
            // 必要ないが，分かりやすいように条件を記述してある．
            left = mid + 1;
        }
    }
    // key が配列の中に見つからない場合
    return -1;
}


int main()
{   
    int x, n;
    cin >> x >> n;
    
    vector<int> p(n, 0);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    
    sort(p.begin(), p.end());
    
    int index = binarySearch(p, x);
    
    if(index==-1){
        cout << x << endl;
        return 0;
    }
    
    int left_key = x-1;
    int right_key = x+1;
    
    while(true){
        //小さい方を探す
        index = binarySearch(p, left_key);
        if(index==-1){
            cout << left_key << endl;
            return 0;
        }
        //大きい方を探す
        index = binarySearch(p, right_key);
        if(index==-1){
            cout << right_key << endl;
            return 0;
        }
        
        //次の探索値
        left_key--;
        right_key++;
    }
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 1000000007;
const int inf = 100000005;
const int N = 200005, M = N;
int i,j,n,m;

ll cnt , idx;
vi temp;

void solve() {
   ll n,k;
   cin>>k>>n;

   unordered_map<int,int>mp;
   ll x,ans = 0;

   fo(i,0,n) cin>>x , mp[x] = 1;
   fo(i,0,1000) {

    if(mp[k-i] == 0) {
        ans = k - i;
        break;
    }

    if(mp[k+i] == 0) {
        ans = k + i;
        break;
    }
   }
   cout<<ans<<"\n";
}

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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 3620
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, k;
  char s[55];
  scanf("%d%d%s", &n, &k, s);
  s[k - 1] = s[k - 1] - ('A' - 'a');
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
aBfore = sum(A)
for i in range(N):
    if A[i] <= B[i]:
        B[i] -= A[i]
        A[i] = 0
        A[i+1] = max(A[i+1] - B[i], 0)
    else:
        A[i] -= B[i]
aAfter = sum(A)
print(aBfore - aAfter)

Measured memory_bytes: 18476
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))


(defmacro while (test &body body)
  `(do ()
	 ((not ,test))
	 ,@body))

(let* ((n (read))
	   (d (* 2 (read)))
	   (a (read))
	   (damage-sum 0)
	   (ans 0)
	   (monster (sort (loop repeat n collect (cons (read) (read)))
					  (lambda (a b) (< (car a) (car b)))))
	   (rp monster))
  (mapc (lambda (target)
		  (while (and rp (<= (caar rp) (+ (car target) d)))
				 (incf (cdar rp) damage-sum)
				 (setf rp (cdr rp)))
		  (when (> (- (cdr target) damage-sum) 0)
			(let ((attack-time (ceiling (- (cdr target) damage-sum) a)))
			  (incf ans attack-time)
			  (incf damage-sum (* a attack-time)))))
		monster)
  (princ ans))


Measured memory_bytes: 68600
def main():
    s = input()
    max_ = 0
    min_ = 0
    cnt = 0
    l=[0]
    for i in range(len(s)):
        if s[i] == "<":
            cnt += 1
        else:
            cnt = 0
        l.append(cnt)
    cnt = 0
    for i in range(len(s),0,-1):
        if s[i-1] == ">":
            cnt += 1
        else:
            cnt = 0
        l[i-1]=max(l[i-1],cnt)
    print(sum(l))
main()

Measured memory_bytes: 24092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);



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

    vector<ll> vec(n);
    for (int i = 0; i < vec.size(); i++) cin >> vec[i];
    ll q;
    cin >> q;

    map<ll, ll> cnt;
    ll s = 0;
    for (int i = 0; i < n; i++) {
        s += vec[i];
        cnt[vec[i]]++;
    }
    
    while (q--) {
        ll b, c;
        cin >> b >> c;
        ll cn = cnt[b];
        cnt[b] -= cn;
        s -= b * cn;
        cnt[c] += cn;
        s += c * cn;
        cout << s << "\n";
    }
    return 0;
}

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

int main() {
    string S; cin >> S;
    string T; cin >> T;
    int s = S.size();
    int t = T.size();
    if(s < t){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for (int i = s-1; i >= t-1; i--){
        bool ch = true;
        for (int j = 0; j < t; j++){
            if(S[i-j] == T[t-1-j] || S[i-j] == '?'){
                continue;
            } else {
                ch = false;
                break;
            }
        }
        if(ch){
            for (int j = 0; j < t; j++){
                S[i-j] = T[t-1-j];
            }
            break;
        }
        if(i == t-1){
            cout << "UNRESTORABLE" << endl;
            return 0;
        }
    }

    for (int i = 0; i < s; i++){
        if(S[i] == '?'){
            S[i] = 'a';
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
    class MainClass {
        public static void Main(string[] args) { new MainClass().solve(); }
        Scanner cin;

        int N;
        int[] A;
        void solve() {
            cin = new Scanner();

            N = cin.nextInt();
            A = new int[N];
            long sumS = 0;
            long sumA = 0;
            for(int i = 0; i < N; i++) {
                A[i] = cin.nextInt();
                sumS += A[i];
            }

            sumA += A[0];
            sumS -= A[0];
            long min = Math.Abs(sumS-sumA);


            for(int i = 1; i < N-1; i++) {
                sumA += A[i];
                sumS -= A[i];
                //Console.WriteLine("bef:" + min);
                min = Math.Min(min, Math.Abs(sumS - sumA));
                //Console.WriteLine("aft:" + min);
            }

            Console.WriteLine(min);


        }
    }

    class Scanner {
        string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' };
        public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; }
        public string next() {
            if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            BufferCnt = 0;
            return nextBuffer[BufferCnt++];
        }
        public int nextInt() { return int.Parse(next()); }
        public long nextLong() { return long.Parse(next()); }
        public double nextDouble() { return double.Parse(next()); }
    }
}

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

int main(){
	int H, W;
	cin >> H >> W;
	char S[H][W];
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cin >> S[i][j];
		}
	}
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j]=='#'){
				cout << '#';
			} else if(S[i][j]=='.'){
				int c=0;
				if(i==0&&i==H-1&&j==0&&j==W-1){
					c=0;
				} else if(i==0&&i==H-1&&j==0&&j!=W-1){
					if(S[ i ][j+1]=='#')c++;
				} else if(i==0&&i==H-1&&j!=0&&j==W-1){
					if(S[ i ][j-1]=='#')c++;
				} else if(i==0&&i==H-1&&j!=0&&j!=W-1){
					if(S[ i ][j-1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
				} else if(i==0&&i!=H-1&&j==0&&j==W-1){
					if(S[i+1][ j ]=='#')c++;
				} else if(i==0&&i!=H-1&&j==0&&j!=W-1){
					if(S[ i ][j+1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
					if(S[i+1][j+1]=='#')c++;
				} else if(i==0&&i!=H-1&&j!=0&&j==W-1){
					if(S[ i ][j-1]=='#')c++;
					if(S[i+1][j-1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
				} else if(i==0&&i!=H-1&&j!=0&&j!=W-1){
					if(S[ i ][j-1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
					if(S[i+1][j-1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
					if(S[i+1][j+1]=='#')c++;
				} else if(i!=0&&i==H-1&&j==0&&j==W-1){
					if(S[i-1][ j ]=='#')c++;
				} else if(i!=0&&i==H-1&&j==0&&j!=W-1){
					if(S[i-1][ j ]=='#')c++;
					if(S[i-1][j+1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
				} else if(i!=0&&i==H-1&&j!=0&&j==W-1){
					if(S[i-1][j-1]=='#')c++;
					if(S[i-1][ j ]=='#')c++;
					if(S[ i ][j-1]=='#')c++;
				} else if(i!=0&&i==H-1&&j!=0&&j!=W-1){
					if(S[i-1][j-1]=='#')c++;
					if(S[i-1][ j ]=='#')c++;
					if(S[i-1][j+1]=='#')c++;
					if(S[ i ][j-1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
				} else if(i!=0&&i!=H-1&&j==0&&j==W-1){
					if(S[i-1][ j ]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
				} else if(i!=0&&i!=H-1&&j==0&&j!=W-1){
					if(S[i-1][ j ]=='#')c++;
					if(S[i-1][j+1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
					if(S[i+1][j+1]=='#')c++;
				} else if(i!=0&&i!=H-1&&j!=0&&j==W-1){
					if(S[i-1][j-1]=='#')c++;
					if(S[i-1][ j ]=='#')c++;
					if(S[ i ][j-1]=='#')c++;
					if(S[i+1][j-1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
				} else if(i!=0&&i!=H-1&&j!=0&&j!=W-1){
					if(S[i-1][j-1]=='#')c++;
					if(S[i-1][ j ]=='#')c++;
					if(S[i-1][j+1]=='#')c++;
					if(S[ i ][j-1]=='#')c++;
					if(S[ i ][j+1]=='#')c++;
					if(S[i+1][j-1]=='#')c++;
					if(S[i+1][ j ]=='#')c++;
					if(S[i+1][j+1]=='#')c++;
				}
				cout << c;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,m,i;
	cin>>n>>m;
	string s[n];
	for(i=0;i<n;i++)
	   cin>>s[i];
	sort(s,s+n);
	for(i=0;i<n;i++)
	   cout<<s[i];
    cout<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int n;cin>>n;
    vector<pair<pair<string, int>,int>> a(n);
    rep(i, n) {
        a[i].second = i+1;
        cin >> a[i].first.first;
        int t;
        cin >> t;
        t *= -1;
        a[i].first.second = t;
    }
    sort(all(a));
    rep(i, n) cout << a[i].second<< endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int K, N; cin >> K >> N;
    vec A(N); cin >> A;
    int d = 0;
    REP(i, N){
        Max(d, (A[(i + 1) % N] - A[i] + K) % K);
    }
    Out(K - d);

    return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

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

    bool isExist = false;
    for(int i = 0; i <= N/4; i++)
    {
        for(int j = 0; j <= N/7; j++)
        {
            if(4 * i + 7 * j == N)
                isExist = true;
        }
    }
    if(isExist)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    
}


Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    x = nl()

    for i in range(n):
        x[i] = [x[i], i]

    x.sort(key=lambda x: x[0])

    left = n//2 - 1
    right = left + 1

    for i, arr in enumerate(x):
        arr.append(x[right][0] if i <= left else x[left][0])

    x.sort(key=lambda x: x[1])
    
    for arr in x:
        print(arr[2])


if __name__ == '__main__':
    main()

Measured memory_bytes: 48940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e8;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pi acos(-1)
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SIZE 5000 + 1

ll expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

void solve()
{
  ll n,m;
  cin>>n>>m;
  cout<<min(m-(n%m),n%m)<<endl;

}

int main()
{
  boost;
  ll t=1;
  //cin>>t;
  //sieve();
  //int ca=0;
  while(t--)
  {
     // ca++;
     // cout<<"Case #"<<ca<<":"<<" ";
      solve();
  }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    edge[s].append(t)

dp = [-1]*N

def dfs(s):
    if dp[s] != -1:
        return dp[s]
    if len(edge[s]) == 0:
        dp[s] = 0
        return 0
    res = 0
    for t in edge[s]:
        res = max(res, dfs(t)+1)
    dp[s] = res
    return res

for i in range(N):
    dfs(i)
print(max(dp))
    

Measured memory_bytes: 61220
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll x;
    cin >> x;
    vector<ll> ans;
    ll ok = 0, ng = 100000;
    while(ng-ok > 1){
        ll mid = (ok+ng)/2;
        if(mid*(mid-1)/2 < x) ok = mid;
        else ng = mid;
    }
    string s = string(ok, ')')+string(ok, '(');
    x = ok*(ok+1)/2-x;
    int cur = ok;
    for (int i = 0; i < x; ++i) {
        swap(s[cur-1], s[cur]);
        cur--;
    }
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 3336
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

size_t get_largest_square(vector<vector<int>> &g) {
    size_t h=g.size(), w=g[0].size();

    vector<vector<size_t>> dp(h, vector<size_t>(w));
    size_t max_len=0;
    for (size_t i=0; i<h; ++i)
        for (size_t j=0; j<w; ++j) {
            dp[i][j] = !g[i][j];
            max_len |= dp[i][j];
        }

    for (size_t i=1; i<h; ++i)
        for (size_t j=1; j<w; ++j) {
            if (g[i][j]) {
                dp[i][j] = 0;
            } else {
                dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1;
                max_len = max(max_len, dp[i][j]);
            }
        }

    return max_len*max_len;
}

int main() {
    size_t h, w;
    scanf("%zu %zu", &h, &w);

    vector<vector<int>> g(h, vector<int>(w));
    for (size_t i=0; i<h; ++i)
        for (size_t j=0; j<w; ++j)
            scanf("%d", &g[i][j]);

    printf("%zu\n", get_largest_square(g));
    return 0;
}

Measured memory_bytes: 25408
#include <iostream>
#include <string>
#include <cmath> 
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric> 
#include <iomanip>
#include <map> 
#include <stack>
#include <sstream>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
/*const int MAX = 1e6;
long long max(long long a, long long b) { if (a > b)return a; else return b; }
long long min(long long a, long long b) { if (a < b)return a; else return b; }
const int MAXN = 1000000 + 30;
int a[MAXN];*/


  		     	/*ll n, k;
		std::cin >> k >> n;
		std::vector <int> v(n);
		for (ll i = 0; i < n; i++)
		{
				std::cin >> v[i];
		}
		std::sort(v.begin(), v.end());*/

int main()
{
	
		ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
		ll n, k;
		ll cnt = 0;
		std::cin  >> n;
		std::vector <int> v(n);
		
		
			for (ll i = 0; i < n; i++)
			{
				std::cin >> v[i];
			}
			std::sort(v.begin(), v.end());
			if (n <= 2)
			{
				cout << 0 << endl;
				return 0;
			}
			
			for (ll i = 0; i < n; i++)
			{
				for (ll j = i + 1; j < n; j++)
				{
					for (ll k = j + 1; k < n; k++)
					{
						if (v[i] + v[j] > v[k] && v[i] != v[j] && v[i] != v[k] && v[k] != v[j])
						{
							cnt++;
						}
					}
				}
			}
		
		cout << cnt;
		


		
 return 0;

}




	

  



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> b(n + 1, 0);
  for (int i = n; 0 < i; i--) {
    int c = 0;
    for (int j = 2 * i; j <= n; j += i) {
      if (b[j]) c ^= 1;
    }
    if (a[i] != c) b[i] = 1;
  }

  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << (i != (int)ans.size() - 1 ? " " : "");
  }
  cout << endl;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner stdin = new Scanner(System.in)) {
            String numText = stdin.next();
            long num = Long.parseLong(numText);
            long sum = numText.chars().mapToLong(c -> c - '0').sum();
            System.out.println((num % sum == 0) ? "Yes" : "No");
        }
    }
}


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

int main(){
    ll n,p;
    cin>>n>>p;
    ll a[n];
    ll odd=0;
    ll even=0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        if(a[i]%2==1){
            odd++;
        }else{
            even++;
        }
    }
    ll ans;
    if(p==1 and odd==0){
        ans = 0;
    }else if(p==0 and odd==0){
        ans = pow(2, even);
    }else{
        ans = pow(2, even) * pow(2, odd-1);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String res = "";
		int n = str.length();
		for(int i=0;i<n;i++) {
			res+="x";

		}
		System.out.println(res);
		


	}

}


Measured memory_bytes: 23252
package main

import (
	"fmt"
)

// 以下の問題
// https://atcoder.jp/contests/abc054/tasks/abc054_a

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	switch {
	case a == b:
		fmt.Println("Draw")
	case a == 1:
		fmt.Println("Alice")
	case b == 1:
		fmt.Println("Bob")
	case a > b:
		fmt.Println("Alice")
	default:
		fmt.Println("Bob")

	}
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>

int main()
{
    char s[10];
    int lng = strlen(s);
    bool b = false;

    scanf("%s", s);

    for (int i = 0; i < lng - 1; i++)
        if (s[0 + i] == 'A' && s[1 + i] == 'C')
            b = true;

    if (b) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

const int INF = 1e9 + 7;
vector<int> dp(100005, INF);

int main(void) {
  int n, k;
  cin >> n >> k;
  int h[n + 1];
  rep (i, n) cin >> h[i + 1];

  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);

  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i - j <= 0) break;
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }  

  cout << dp[n] << endl;
  //printa(dp, n + 1);
  return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>


int main(void) {
  FILE* fp;
  fp = stdin;
  char line[15];
  if(!fgets(line, 15, fp)) return 0;
  int coin_1, given;
  sscanf(line, "%d", &given);
  if(!fgets(line, 15, fp)) return 0;
  sscanf(line, "%d", &coin_1);
  int rem = given % 500;
  int flag = 0;
  if(coin_1 >= rem) {
    flag = 1;
  }
  printf("%s\n", flag ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <array>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(),x.end())

using int64 = ll;

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vint a(m);
	int b[101][101] = {};
	rep(i, 0, m)
		cin >> a[i];
	rep(i, 0, m){
		rep(j, 0, n)
			cin >> b[i][j];
	}
	vint ans(n);
	rep(i, 0, m){
		rep(j, 0, n){
			if (b[i][j] == a[i]){
				ans[j]++;
			}
			else{
				ans[a[i]-1]++;
			}
		}
	}
	rep(i, 0, n)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main(){
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e>>k;
	if ((e - a) <= k){
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	vector<int> t[11];
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++)
	{
		int r,type;
		cin >> r >> type;
		t[type].pb(r);
	}
	for(int i=1;i<=10;i++)
	{
		sort(t[i].begin(),t[i].end(),greater<int>());
		for(int j=1;j<t[i].size();j++)
		{
			t[i][j]+=t[i][j-1];
		}
		for(int j=1;j<t[i].size();j++)
		{
			t[i][j]+=j*(j+1);
		}
	}
	int dp[11][2002];
	for(int i=0;i<11;i++)
	{
		for(int j=0;j<2002;j++)
		{
			dp[i][j]=-INF;
		}
	}
	dp[0][0]=0;
	int ans=0;
	for(int i=1;i<=10;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			for(int l=1;l<=j&&l<=t[i].size();l++)
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j-l]+t[i][l-1]);
			}
		}
	}
	cout << dp[10][k] << endl;
	return 0;
}

Measured memory_bytes: 1320
#include <stdio.h>
int main(){
char a,b,c,d,e,f;
scanf("%c%c%c%c%c%c",&a,&b,&c,&d,&e,&f);

if((c == d && e == f)&&(a != b))
{ printf("Yes");
}
else{
printf("No");
}

return 0;
}

Measured memory_bytes: 1652
//# pragma GCC optimize ("O2")
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<climits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<iomanip>
#include<sstream>
#define out(i,a,now) for(int i=a.be[now],to=a.v[i];i;i=a.ne[i],to=a.v[i])
#define fo(i,a,b) for(i=a;i<=b;i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define mp(a,b) make_pair(a,b)
#define qk(x) memset(x,0,sizeof(x))
#define RG register
#define gs(x) (tr[tr[x].f].son[1]==x)
#define lb(x) (x&(-x))
#define mid ((l+r)>>1)
#ifdef Mogician
#endif
using namespace std;
typedef long long LL;
typedef double DB;
template <class T> void cmax(T &a,T b)
{
    a=max(a,b);
}
template <class T> void cmin(T &a,T b)
{
    a=min(a,b);
}
template <class T> void swp(T &a,T &b)
{
	T temp=a; a=b; b=temp;
}
struct data
{
	LL a,b;
	bool operator <(const data x) const
	{
		return b-a>x.b-x.a;
	}
}a[210000];
LL n;
int main()
{
	scanf("%lld",&n);
	LL i;
	LL flag=0;
	fo(i,1,n)
	{
		scanf("%lld%lld",&a[i].a,&a[i].b);
		if (a[i].a>a[i].b) flag=1;
	}
	sort(a+1,a+n+1);
	LL ans=0;
	if (!flag)
	{
		puts("0");
		return 0;
	}
	LL mib=INT_MAX;
	fo(i,1,n)
	{
		ans+=a[i].b;
		if (a[i].a>a[i].b) cmin(mib,a[i].b);
	}
	printf("%lld",ans-mib);
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long n,l[2100000];
int main()
{
	scanf("%lld",&n);
	l[0]=2;l[1]=1;
	for(long long i=2;i<=n;i++)
	{
		l[i]=l[i-1]+l[i-2];
	}
	printf("%lld\n",l[n]);
	return 0;
}


Measured memory_bytes: 384
dict = {}
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':	dict[ki] = int(a[2])
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	else:
		if ki in dict: dict[ki] = 0


Measured memory_bytes: 37504
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> pp;
typedef pair<pp,int> P;
char t[2500001],p[1001];
int a[2500001],d[1000001],i;
P b[1000001];

void mk(){
  for(i=0;t[i]!=0;i++)
    b[i].f.f=t[i],b[i].s=i;
  b[i].f.f=0,b[i].s=i;

  for(int j=1;j<=i;j*=2){
    sort(b,b+i+1);
    a[b[0].s]=0;
    for(int k=1,l=0;k<=i;k++)
      if(b[k-1].f==b[k].f)a[b[k].s]=l;
      else a[b[k].s]=++l;
    for(int k=0,o=b[0].s;k<=i;k++,o=b[k].s)
      b[k]=P(pp(a[o],a[o+j]),o);
  }
  sort(b,b+i+1);
  a[b[0].s]=0;
  for(int k=1,l=0;k<=i;k++)
    if(b[k-1].f==b[k].f)a[b[k].s]=l;
    else a[b[k].s]=++l;
  for(int j=0;j<=i;j++)d[a[j]]=j;
}

void bs(int n){
  int l=0,r=i,m;
  while(l<r){
    m=(l+r)/2;
    if(strncmp(t+d[m],p,n)<0)l=m+1;
    else r=m;
  }
  if(strncmp(t+d[l],p,n) ==0 )printf("1\n");
  else printf("0\n");
}


int main(){
  int q;
  scanf("%s",t);
  mk();
  cin>>q;
  while(q--&&scanf("%s",p))bs(strlen(p));
  return 0;
}

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

int main()
{
        int N;
        int A[205];

        cin >> N;

        for ( int i = 0; i < 2 * N; i++ ) {
                cin >> A[i];
        }

        sort(A, A + N * 2);
        
        int sum = 0;
        for ( int i = 0; i < N; i++ ) {
                sum += min(A[i * 2], A[i * 2 + 1]);
        }

        cout << sum << endl;
        return ( 0 );
}


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

MOD = 10**9+7
N, M = map(int, readline().split())
S = list(map(int, readline().strip()))
Query = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]

PP = S.count(1)

Li = [None]*PP
Ri = [None]*PP

T1 = S[:]
for l, r in Query:
    cnt = 0
    for i in range(l, r+1):
        cnt += T1[i]
    for i in range(l, l+cnt):
        T1[i] = 1
    for i in range(l+cnt, r+1):
        T1[i] = 0
T2 = S[:]
for l, r in Query:
    cnt = 0
    for i in range(l, r+1):
        cnt += 1 - T2[i]
    for i in range(l, l+cnt):
        T2[i] = 0
    for i in range(l+cnt, r+1):
        T2[i] = 1

cnt = 0
for i in range(N):
    if T1[i]:
        Li[cnt] = i
        cnt += 1
cnt = 0
for i in range(N):
    if T2[i]:
        Ri[cnt] = i+1
        cnt += 1

dp = [0]*N
for i in range(Li[0], Ri[0]):
    dp[i] = 1

for j in range(1, PP):
    dp2 = [0] + dp[:-1]
    for i in range(1, N):
        dp2[i] = (dp2[i]+dp2[i-1])%MOD
    for i in range(Li[j]):
        dp2[i] = 0
    for i in range(Ri[j], N):
        dp2[i] = 0
    dp = dp2[:]
res = 0
for d in dp:
    res = (res+d)%MOD
print(res)
    


Measured memory_bytes: 51804