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

const int lim = 2000006;

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

    int k;
    cin>>k;
    cout<<(k/2)*((k+1)/2); 

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,sse4.1,sse4.2,popcnt,abm,mmx,avx")
#pragma comment(linker,"/STACK:102400000,102400000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
inline int read()
{
	int ret=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return w*ret;
}
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.length()/2;i++)
	if(s[i]!=s[s.length()-i-1]) ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <string>
#include <cmath>

using namespace std;

using s64 = long long int;

s64 N, K;
s64 v[50];

s64 dp_l[51][100];
s64 dp_r[51][100];

const s64 INF = 1000000000;

int main(){
    cin >> N >> K;
    for(s64 i=0;i<N;i++){
        cin >> v[i];
    }

    {
        dp_l[0][0] = 0;
        for(s64 l = 0; l < N; l++){
            dp_l[l+1][0] = dp_l[l+1-1][0] + v[l];
        }
        std::vector<s64> tmp;
        for(s64 l=0;l<N;l++){
            tmp.push_back(v[l]);
            sort(tmp.begin(), tmp.end());
            
            s64 sum = dp_l[l+1][0];
            for(s64 k=1;k<K;k++){
                //if(tmp.size() <= k || 0 <= tmp[k-1]){
                //    dp_l[l+1][k] = -INF;
                //}else{
                    sum -= tmp[k-1];
                    dp_l[l+1][k] = sum;
                //}
            }
        }

        tmp.clear();
        dp_r[N][0] = 0;
        for(s64 r=N-1;0<=r;r--){
            dp_r[r][0] = dp_r[r+1][0] + v[r];
        }
        for(s64 r=N-1;0<=r;r--){
            tmp.push_back(v[r]);
            sort(tmp.begin(), tmp.end());
            
            s64 sum = dp_r[r][0];
            for(s64 k=1;k<K;k++){
                if(tmp.size() <= k || 0 <= tmp[k-1]){
                    dp_r[1][k] = -INF;
                }else{
                    sum -= tmp[k-1];
                    dp_r[r][k] = sum;
                }
            }
        }
    }


    const bool debug = false;

    if(debug){
        cout << "==dp_l==" << endl;
        for(s64 k=0;k<K;k++){
            for(s64 i=0;i<N+1;i++){
                if(dp_l[i][k] != -INF){
                    cout << dp_l[i][k] << ", ";
                }else{
                    cout << "INF" << ", ";
                }
            }
            cout << endl;
        }
        cout << "==dp_r==" << endl;
        for(s64 k=0;k<K;k++){
            for(s64 i=0;i<N+1;i++){
                if(dp_r[i][k] != -INF){
                    cout << dp_r[i][k] << ", ";
                }else{
                    cout << "INF" << ", ";
                }
            }
            cout << endl;
        }
    }

    s64 ans = 0;
    for(int l=0;l<=N;l++){
        for(int lk=0;lk<K;lk++){
            for(int r=0;r<=N;r++){
                for(int rk=0;rk<=K;rk++){
                    if(r+1 <= l)
                        continue;
                    int count = (l) + (N-r) + lk + rk;
                    s64 value = dp_l[l][lk] + dp_r[r][rk];

                    if(K < count)
                        continue;

                    if(debug)
                        cout << "l[" << l << "][" << lk << "] + r[" << r << "][" << rk << "] : " << value << endl;

                    ans = max(ans, value);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long p = sc.nextLong();
		if (n == 1) {
			System.out.println(p);
			return;
		}
		int ans = 1;
		for (int i = 2; Math.pow(i, n) <= p; i++) {
			if (p % Math.pow(i, n) == 0) {
				ans = i;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23508
/*
dp[i][j][k] 第i个字符到第j个字符最多修改k个字符的最大长度

dp[i][j][k] = max(
                  dp[i+1][j][k],dp[i][j-1][k],
                  if s[i]==s[j] : dp[i+1][j-1][k]+2
                else :

abcabcabc
cbacbacba


*/

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int n,m;
char s[305];
int dp[305][305][305];

int main(){
    int i,j,k;
    while(~scanf("%s%d",s,&m)){
        n = strlen(s);
        memset(dp,0,sizeof(dp));
        for(i = 0;i < n;i++){
            for(j = 0;j <= m;j++)
                dp[i][i][j] = 1;
        }
        for(i = n-1;i >= 0;i--){
            for(j = i+1;j < n;j++){
                for(k = 0;k <= m;k++){
                    dp[i][j][k] = max(dp[i+1][j][k],dp[i][j-1][k]);
                    //if(i+1 <= j-1){
                        if(s[i] == s[j]){
                            dp[i][j][k] = max(dp[i][j][k],dp[i+1][j-1][k]+2);
                        }else if(k > 0){
                            dp[i][j][k] = max(dp[i][j][k],dp[i+1][j-1][k-1]+2);
                        }
                    //}
                }
            }
        }
        printf("%d\n",dp[0][n-1][m]);

    }

    return 0;
}


Measured memory_bytes: 110976
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{ 
  int i,j,k,a,b,ans;
  string s;
  cin>>s;
  i=0;
  while(s[i]!='A'){i++;}
  k=s.size();
  k--;
  while(s[k]!='Z'){k--;}
  cout<<k-i+1;
  return 0;
}

Measured memory_bytes: 3724
#include<iostream>

using namespace std;


bool ch(string s){
	int k = s.length();
	for(int i = 0;i < k/2;i++){
		if(s[i] != s[k-1-i]){
			return false;
		}
	}
	return true;
}

int main(){
	string s;
	cin >> s;
	int l = s.length();
	// cout << s.substr((l+3)/2) ;
	if(ch(s) && ch(s.substr(0,(l-1)/2)) && ch(s.substr((l+3)/2 - 1))){
		cout << "Yes" << "\n";
	}
	else{
		cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)

int main(void) {
	int n; cin >> n;
	vector<ll> v(n-1);
	for (int i = 0; i < n - 1; i++) {
		cin >> v[i];
	}
	ll sum = 0;
	sum += v[0]+v[n-2];
	for (int i = 1; i < n - 1; i++) {
		sum += min(v[i - 1],v[i]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <string>
    using namespace std;
     
    int main(){
        string a, b, c;
        cin >> a >> b >> c;
        int ia=0, ib=0, ic=0;
        char next = 'a';
        char ans;
        while (true){
            if (next == 'a'){
                if (ia == a.length()){
                    ans = 'A';
                    break;
                }
                next = a[ia];
                ia += 1;
            }
            else if (next == 'b'){
                if (ib == b.length()){
                    ans = 'B';
                    break;
                }
                next = b[ib];
                ib += 1;
            }
            else{
                if (ic == c.length()){
                    ans = 'C';
                    break;
                }
                next = c[ic];
                ic += 1;
            }
        }
        
        cout << ans << endl;
    }

Measured memory_bytes: 256
MOD = 1000000007
N = gets.chomp.to_i

group = Hash.new(0)
worst_iwashi_count = 0

N.times do |i|
  a, b = gets.chomp.split.map(&:to_i)

  if a == 0 && b == 0
    worst_iwashi_count += 1
    next
  end

  if a == 0
    group[[0, -1]] += 1
    next
  end

  if b == 0
    group[[1, 0]] += 1
    next
  end

  gcd = a.gcd(b)
  a /= gcd
  b /= gcd

  if a < 0
    a *= -1
    b *= -1
  end

  group[[a, b]] += 1
end

ans = 1

group.each do |a_and_b, count|
  a, b = a_and_b

  if b < 0
    pair_count = group[[-b, a]]
    group.delete([-b, a])
  else
    pair_count = group[[b, -a]]
    group.delete([b, -a])
  end

  ans *= (2 ** count - 1) + (2 ** pair_count - 1) + 1
  ans %= MOD
end

p (ans + worst_iwashi_count - 1) % MOD


Measured memory_bytes: 35148
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		while(stdin.hasNext()) {
			int n = stdin.nextInt();
			List<Integer> scores = new ArrayList<Integer>();
			if (n == 0) break;
			for (int i = 0; i < n; i++) {
				scores.add(stdin.nextInt());
			}
			Collections.sort(scores);
			int sum = 0;
			for (int i = 1; i < n - 1; i++) {
				sum += scores.get(i);
			}
			System.out.println(sum / (n - 2));
		}
		System.exit(0);
	}
}

Measured memory_bytes: 20980
// schedule lectures codechef
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string imp="Impossible\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
// const int N=10;
const int N=2e4+5;
ll MOD=1e9+7;
ll m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
	cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    while(tests--){
        int x;  cin>>x;
        int k=0;
        if(x>=400&&x<=599) k=8;
        else if(x>=600&&x<=799) k=7;
        else if(x>=800&&x<=999) k=6;
        else if(x>=1000&&x<=1199)   k=5;
        else if(x>=1200&&x<=1399)   k=4;
        else if(x>=1400&&x<=1599)   k=3;
        else if(x>=1600&&x<=1799)   k=2;
        else k=1;
        cout<<k<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count1 = 0;
		int count2 = 0;
		int count3 = 0;
		int count4 = 0;
		for(int i = 0; i < 6; i++) {
			int n = sc.nextInt();
			if(n == 1) {
				count1++;
			} else if(n == 2) {
				count2++;
			} else if(n == 3) {
				count3++;
			} else {
				count4++;
			}
		}
		if(count1 == 0 || count2 == 0 || count3 == 0 || count4 == 0) {
			System.out.println("NO");
		} else if(count1 == 3 || count2 == 3 || count3 == 3 || count4 == 3) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl
#define MOD 1000000007ULL
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll N;
  	cin>>N;
    ll x1=1,x2=1,x3=1;
  	rep(i,N){
     	x1=x1*10%MOD;
      	x2=x2*9%MOD;
      	x3=x3*8%MOD;
    }
  	ll ans=x1-x2*2+x3;
  	
  	ans=(ans+MOD*10)%MOD;
  
  	cout<<ans<<endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
using namespace std;
const int N=205;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,l[N],ans;
int main(){
	n=read();
	inc(i,1,2*n) l[i]=read();
	sort(l+1,l+1+2*n);
	inc(i,1,n) ans+=l[2*i-1];
	printf("%d",ans); 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int k;cin>>k;
  ll a=7%k;ll b=7%k;if(!b){cout<<1<<endl;return 0;}
  for(int i=2;i<1e8;i++){
     b=(b*10)%k;
     a=(a+b)%k;
    if(!a){cout<<i<<endl;
    return 0;}
  }
cout<<-1<<endl;
  
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    int N;
    cin >> N;
    vector<ll> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    int sum_max = 0;
    for(int i = 0; i < N; i++){
        int sum = 0;
        for(int j = i; i < N - 1; i++){
            if(H[i] >= H[i + 1]) sum++;
            else break;
        }
        sum_max = max(sum, sum_max);
    }
    cout << sum_max << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int jj = 0,ii = 0;
		string a;
		cin >> a;
		long y = 0;
		y = a.size();

		for (long i = 0; i < y - 2; i++)
		{
			if (a.substr(i,3) == "JOI")
			{
				jj++;
			}
			else if (a.substr(i,3) == "IOI")
			{
				ii++;
			}
		}
		cout << jj << endl << ii << endl;
	}
}


Measured memory_bytes: 3152
from sys import stdin
data = stdin.readline().split()
N, M = int(data[0]), int(data[1])
left = [None] * M
right = [None] * M
for itr in range(M):
    gate = stdin.readline().split()
    left[itr] = int(gate[0])
    right[itr] = int(gate[1])
if (min(right)-max(left) + 1) < 0:
    print(0)
else:
    print(min(right)-max(left) + 1)

Measured memory_bytes: 10888
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int sep[200000], grd[200000];
typedef long long ll;
ll mod = 1000000007;
int idx[200000], ig[200000];
ll rdp[200002];
vector<int>dat[200000];
int m1[200000], m2[200000];
ll get(vector<int>v)
{
	int maxi = -1;
	for (int i = 0; i < v.size(); i++)maxi = max(maxi, v[i]), m1[i] = maxi;
	int mini = v.size();
	for (int i = int(v.size()) - 1; i >= 0; i--)mini = min(mini, v[i]), m2[i] = mini;
	for (int i = 0; i < v.size(); i++)dat[i].clear();
	for (int i = 0; i < v.size(); i++)dat[m1[i]].push_back(m2[i]);
	for (int i = 0; i < v.size() + 2; i++)rdp[i] = 0;
	rdp[1] = 1;
	for (int i = 0; i < v.size(); i++)
	{
		rdp[i + 2] = rdp[i + 1];
		for (int j = 0; j < dat[i].size(); j++)
		{
			rdp[i + 2] += (rdp[i + 2] + mod - rdp[dat[i][j]]);
			rdp[i + 2] %= mod;
		}
	}
	return (rdp[v.size() + 1] + mod - rdp[v.size()]) % mod;
}
int ff[200000];
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>zax, zav;
	for (int i = 0; i < num; i++)scanf("%d%d", &sep[i], &grd[i]), zax.push_back(sep[i]), zav.push_back(grd[i]);
	sort(zax.begin(), zax.end());
	sort(zav.begin(), zav.end());
	for (int i = 0; i < num; i++)sep[i] = lower_bound(zax.begin(), zax.end(), sep[i]) - zax.begin(), grd[i] = lower_bound(zav.begin(), zav.end(), grd[i]) - zav.begin();
	for (int i = 0; i < num; i++)idx[sep[i]] = i, ig[sep[i]] = grd[i];
	for (int i = 0; i < num; i++)dat[i].clear();
	int za, zb;
	za = 0, zb = num - 1;
	fill(ff, ff + num, 0);
	for (int i = 0; i < num; i++)if (za <= idx[i] && idx[i] <= zb)ff[ig[i]] = 1;
	for (int i = 0; i < num - 1; i++)ff[i + 1] += ff[i];
	vector<int>v;
	for (int i = 0; i < num; i++)if (za <= idx[i] && idx[i] <= zb)v.push_back(ff[ig[i]] - 1);
	printf("%lld\n", get(v));
}

Measured memory_bytes: 21356
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

struct MaxFlow{
    struct edge{ int to, cap, rev; };

    int V;
    vector<vector<edge>> G;
    vector<bool> used;

    MaxFlow(int _V){
        V = _V;
        G.resize(V);
        used.resize(V);
    }

    void add(int from, int to, int cap){
        G[from].push_back({ to, cap, (int)G[to].size() });
        G[to].push_back({ from, 0, (int)G[from].size()-1 });
    }

    int dfs(int v, int t, int f){
        if(v == t) return f;
        used[v] = true;
        for(int i=0; i<G[v].size(); i++){
            edge& e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int calculate(int s, int t){
        int ret = 0;
        while(true){
            used.assign(V, false);
            int f = dfs(s, t, INT_MAX);
            if(f == 0) break;
            ret += f;
        }
        return ret;
    }
};

int H, W;
string S[100];
int si, sj, ti, tj;
MaxFlow flow(100*100*2);

signed main(){
    cin >> H >> W;
    rep(i, H) cin >> S[i];

    rep(i, H){
        rep(j, W){
            if(S[i][j] == 'S'){
                si = i;
                sj = j;
            }
            if(S[i][j] == 'T'){
                ti = i;
                tj = j;
            }
        }
    }

    if(si == ti || sj == tj){
        cout << -1 << endl;
        return 0;
    }

    rep(i, H){
        rep(j, W){
            if(S[i][j] == '.') continue;
            flow.add((100*i+j)*2, (100*i+j)*2+1, 1);
        }
    }
    rep(i, H){
        rep(j, W){
            if(S[i][j] == '.') continue;
            rep(k, W){
                if(j == k) continue;
                if(S[i][k] == '.') continue;
                flow.add((100*i+j)*2+1, (100*i+k)*2, 1);
            }
        }
    }
    rep(i, W){
        rep(j, H){
            if(S[j][i] == '.') continue;
            rep(k, H){
                if(j == k) continue;
                if(S[k][i] == '.') continue;
                flow.add((100*j+i)*2+1, (100*k+i)*2, 1);
            }
        }
    }
    cout << flow.calculate((100*si+sj)*2+1, (100*ti+tj)*2) << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

int main() {
  int A, B;
  cin >> A >> B;


  cout << (B + A - 3) / (A - 1) << endl;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000001;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

ll RepeatSquaring(ll N, ll P, ll M){
    if(P < 0) {
        return 0;
    }
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

int main() {
    string S;
    cin >> S;
    int N = S.size();
    vector<ll> q(N + 1);
    for(int i = 0;i < N;i++) {
        if(S.at(i) == '?') {
            q.at(i + 1) = q.at(i) + 1;
        }
        else {
            q.at(i + 1) = q.at(i);
        }
    }
    vector<ll> A(N + 1);
    for(int i = 0;i < N;i++) {
        if(S.at(i) == 'A') {
            A.at(i + 1) = A.at(i) + 1;
        }
        else {
            A.at(i + 1) = A.at(i);
        }
    }
    vector<ll> C(N + 1);
    for(int i = N;i >= 1;i--) {
        if(S.at(i - 1) == 'C') {
            C.at(i - 1) = C.at(i) + 1;
        }
        else {
            C.at(i - 1) = C.at(i);
        }
    }
    ll ret = 0;
    for(int i = 0;i < N;i++) {
        if(S.at(i) == 'B' || S.at(i) == '?') {
            ll cnt = 0;
            cnt += A.at(i) * RepeatSquaring(3ll,q.at(i),MOD);
            cnt %= MOD;
            cnt += q.at(i) * RepeatSquaring(3ll,q.at(i) - 1,MOD);
            cnt %= MOD;
            ll cnt2 = 0;
            cnt2 += C.at(i + 1) * RepeatSquaring(3ll,q.at(N) - q.at(i + 1),MOD);
            cnt2 %= MOD;
            cnt2 += (q.at(N) - q.at(i + 1)) * RepeatSquaring(3ll,q.at(N) - q.at(i + 1) - 1,MOD);
            cnt2 %= MOD;
            ret += cnt * cnt2;
            ret %= MOD;
        }
    }
    cout << ret << endl;
}

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

const int N = 100005;

int n, A;
vector<int> e[N];

int g(vector<int> &v, int z){
    for(int i = -(v.size() & 1), j = int(v.size()) - 1; i < j; i++, j--){
        int t = v[j];
        if(i >= 0) t += v[i];
        if(t > z) return -1;
    }
    return 0;
}

int h(vector<int> &v, int m, int z){
    if((m >= 0 ? v[m] : 0) + 1 > z) return -1;
    vector<int> w;
    for(int i = 0; i < v.size(); i++) if(i != m) w.push_back(v[i]);
    return g(w, z);
}

int f(int x, int y, int z){
    vector<int> v;
    for(int i : e[x]){
        if(i == y) continue;
        v.push_back(f(i, x, z));
        if(v.back() < 0) return -1;
    }
    if(v.empty()) return 1;
    sort(v.begin(), v.end());
    if(!y) return g(v, z);
    int l = -(~v.size() & 1), r = v.size() - 1;
    while(l < r){
        int m = (l + r + 2) / 2 -1;
        if(h(v, m, z) >= 0) r = m;
        else l = m + 1;
    }
    if(h(v, l, z) < 0) return -1;
    return (l >= 0 ? v[l] : 0) + 1;
}

int main(){
    scanf("%d", &n);
    for(int i = 0, x, y; i < n - 1; i++){
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    A = n - 1;
    for(int i = 1; i <= n; i++) A -= int(e[i].size()) / 2;
    printf("%d ", A);
    int l = 1, r = n;
    while(l < r){
        int m = (l + r) / 2;
        if(f(1, 0, m) >= 0) r = m;
        else l = m + 1;
    }
    printf("%d\n", l);
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,B;
	string S,T,U;
	cin>>S>>T>>A>>B>>U;
	if(S==U){
		cout<<A-1<<" "<<B;
	}
	else{
		cout<<A<<' '<<B-1;
	}
	return 0;
 } 

Measured memory_bytes: 3592
from collections import*
n,*a=map(int,open(0).read().split())
d=defaultdict(int)
l=[]
for i in a:
    if d[i]%2:l.append(i)
    d[i]+=1
if len(l)>1:
    *_,a,b=sorted(l)
    print(a*b)
else:
    print(0)

Measured memory_bytes: 69792
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n;
  cin>>n;
  if(n==22)
  {
      cout<<"Christmas Eve Eve Eve"<<endl;
  }
  else if(n==23)
  {
      cout<<"Christmas Eve Eve"<<endl;
  }
  else if(n==24)
  {
      cout<<"Christmas Eve"<<endl;
  }
  else if(n==25)
  {
    cout<<"Christmas"<<endl;
  }

}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int big = 0;
		int small = 0;
		int tyuou = 0;
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A > B) {
			big = A;
			small = B;
		}else {
			big = B;
			small = A;
		}
		while(big != 0) {
			big--;
			small++;
			if(big == small) {
				tyuou = big;
				break;
			}
		}
		if(tyuou == 0) {
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println(tyuou);
		}
	}
}

Measured memory_bytes: 21972
# coding: utf-8
N, K = map(int, input().split())
mod = 10**9 + 7
A = list(map(int, input().split()))
l = []
for i in range(N):
    tmp = [0, 0]
    for j in range(N):
        if j < i:
            if A[i] < A[j]:
                tmp[0] += 1
        else:
            if A[i] < A[j]:
                tmp[1] += 1
    l.append(tmp[:])
ans = 0
for i in range(N):
    ans += K * ((l[i][0] * (K+1)) + (l[i][1]*(K-1))) // 2
    ans %= mod
print(ans % mod)

Measured memory_bytes: 42092
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

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

//sub-EOF


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

char st[210];
int k;

int main()
{
    scanf("%s",st);
    scanf("%d",&k);
    int len=0;
    while (st[len]) ++len;
    if (len==1){
        printf("%d",k/2);
        return 0;
    }
    long long ans=0;
    if (k==1 || st[0]!=st[len-1])
    {
        for (int i=1;i<len;)
        {
            if (st[i]==st[i-1])
            {
                ans++;
                i+=2;
            }
            else
                ++i;
        }
        printf("%lld\n",1LL*ans*k);
        return 0;
    }
    //the first
    ans=0;
    for (int i=len;i<len*2;++i)
        st[i]=st[i-len];
    long long ans1=0;
    int flag1=0,flag2=0;
    for (int i=1;i<len*2;)
    {
        if (st[i]==st[i-1])
        {
            if (i==len-1) flag1=1;
            if (i==2*len-1) flag2=1;
            ++ans;
            if (i>=len)
                ++ans1;
            i+=2;
        }
        else
            ++i;
    }
    if (flag1) printf("%lld\n", 1LL*(ans-ans1)*k );
    else if ((!flag1) && flag2){
        printf("%lld\n",1LL*ans*(k/2)+1LL*(ans-ans1));
    }
    else printf("%lld\n",ans+1LL*ans1*(k-2));
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

pair<ll, ll> DP1[1000000], DP2[1000000];

int main() {
  ll N;
  cin>>N;
  ll A[(1<<N)];
  for(ll i=0;i<(1<<N);++i) {
    cin>>A[i];
  }
  DP1[0] = mp(A[0], 0);
  bool ok1;
  for(ll i=1;i<(1<<N);++i) {
    DP1[i] = mp(A[i], i);
    for(ll j=0;j<20;++j) {
      if((i&(1<<j))!=0) {
        vector<pair<ll, ll> > tmparr(4);
        tmparr[0] = mp(DP1[i].fi, DP1[i].se);
        tmparr[1] = mp(DP2[i].fi, DP2[i].se);
        tmparr[2] = mp(DP1[i-(1<<j)].fi, DP1[i-(1<<j)].se);
        tmparr[3] = mp(DP2[i-(1<<j)].fi, DP2[i-(1<<j)].se);
        sort(tmparr.begin(), tmparr.end(), greater<pair<ll, ll> >());
        map<ll, ll> amap;
        ok1 = false;
        for(ll k=0;k<4;++k) {
          if(amap[tmparr[k].se]>0) continue;
          if(!ok1) {
            DP1[i] = tmparr[k];
            amap[tmparr[k].se]++;
            ok1 = true;
          }
          else {
            DP2[i] = tmparr[k];
            break;
          }
        }
      }
    }
  }
  ll ans[(1<<N)];
  //for(int i=1;i<(1<<N);++i) cout<<i<<" "<<DP1[i]<<" "<<DP2[i]<<endl;
  for(ll i=0;i<(1<<N);++i) ans[i] = 0;
  for(ll i=1;i<(1<<N);++i) {
    ans[i] = max(ans[i-1], DP1[i].fi+DP2[i].fi);
  }
  for(ll i=1;i<(1<<N);++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 15908
#include<iostream>
using namespace std;
int main(){
  int n;
  int a,b;
  cin>>n>>a>>b;
  
  int ans=0;
  for(int i=1;i<=n;i++){
    int temp=i;
    int sum=0;
    while(temp>0){
      sum+=temp%10;
      temp/=10;
    }
    if(a<=sum&&sum<=b){
      ans+=i;
    }
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#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; 
#define ll long long
#define MOD 1000000007
#define ull unsigned long long int
#define db double
#define fi first
#define se second
#define pb push_back
#define vec vector<ll>
#define pr pair<ll,ll>
#define pq priority_queue<ll,vector<ll>, compare_queue >
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define GS(s)   string s; getline(cin,s);
#define lll __int128_t
#define endl "\n"
#define Next cout.flush()

struct compare_queue
{
    bool operator()(const ll& a, const ll& b)
    {
        return a>b;
    }
};

ll gcd(ll u,ll v)
{
	if(v==0)
	return u;
	
	else
	return gcd(v,u%v);
}

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2)%MOD; 
    p = ((p%MOD) * (p%MOD))%MOD; 

    return (y%2 == 0)? p%MOD : ((x%MOD) * (p%MOD))%MOD; 
} 

    // ll power(ll x,ll y){
    //     ll i;
    //     ll ans=1;
    //     for(i=0;i<y;i++){
    //         ans=ans*x;
    //     }
    //     return ans;
    // }


// ll modInverse(int a, int m) 
// { 
//     if(a==1){return 1;}
//     return power(a, m-2, m); 
// } 
  



// // // #define MAX 1000000
// int primes[100009],cnt=0;
// // vector<int> factors[1000009];
// char str[1000009];
// void pre()
// {
//     // calcualting primes
//     int n=100000;
//     for(int i=2; i*i<=n; i++)
//         if(str[i]==0)
//             for(int j=i; j*i<=n; j++)
//                 str[i*j]=1;
//     for(int i=2; i<=n; i++)
//         if(str[i]==0)primes[cnt]=i,cnt++;
// }


// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
// vector<ll> getFactorization(ll x) 
// { 
//     vector<ll> ret; 
//     while (x != 1) 
//     { 
//         ret.push_back(spf[x]); 
//         x = x / spf[x]; 
//     } 
//     return ret; 
// } 

// C:\Users\A\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\lambda


// ll getPow(ll n,ll k){
//     double f=log((double)n);
//     double g=log((double)k);
//     f=f/g;
//     return (ll)f;
// }

void Function(){
ll n;
cin >> n;
if(n<=1){cout << 0 << endl; return;}
ll ans=power(10,n)%MOD;
ans=((ans%MOD) + (power(8,n)%MOD))%MOD;
ans=((ans%MOD) - (power(9,n)%MOD) + MOD)%MOD;
ans=((ans%MOD) - (power(9,n)%MOD) + MOD)%MOD;
cout << ans << endl;
}


int main(){ 
fast;
ll t=1,i=0,j=0,k,h;
 //pre();
// cin >> t;
for(h=1;h<=t;h++){

Function();

}


return 0;

}

Measured memory_bytes: 3568
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map


int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n, k; cin >> n >> k;
	vi A = vi();
	rep(i, n){
		int x; cin >> x;
		A.pb(x);
	}
	// dp[i] = can Taro (first player) win if there are i stones remaining
	vi dp = vi(k+1, 0); 
	for(int i = 1; i <= k; i++){
		for(const auto& stones : A){
			if (i - stones < 0) continue;
			if (dp[i-stones] == 0){
				dp[i] = 1;
				break;
			}
		}
	}
	cout << (dp[k] == 1 ? "First" : "Second");
}


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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	//final lentgh of string differ, but the evenness isn't chaning
	cin >> s;
	n = sz(s);
	bool ans = 0;
	if (s[0] != s[n-1]) ans ^= (n%2);
	if (s[0] == s[n-1]) ans ^= !(n%2);
	cout << (ans ? "First" : "Second") << '\n';
   	return Accepted;
}

// B...a

Measured memory_bytes: 18944
def solve(N, As):
    Ss = [0]
    total = 0
    for a in As:
        Ss.append(Ss[-1] + a)
    for i in range(N - 1):
        total += As[i] * (Ss[-1] - Ss[i + 1])
    ans = total % (10 ** 9 + 7)
    print(ans)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split()))
    solve(N, As)


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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
ll dp[100001][4];

int main() {
  string s;
  cin>>s;
  dp[s.size()][3] = 1;
  for (int i = s.size() - 1; i >= 0; i--) {
    for (int j = 3; j >= 0; j--) {
      dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3LL : 1LL);
      if (j < 3 && (s[i] == '?' || s[i] == "ABC"[j])) {
        dp[i][j] += dp[i + 1][j + 1];
      }
      dp[i][j] %= mod;
    }
  }
  cout<<dp[0][0]<<endl;
  return 0;
}

Measured memory_bytes: 3584
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[100009],dp[100009];
ll DP(ll n)
{
    if(dp[n]!=-1)
    {
        return dp[n];
    }
    if(n==0)
    {
        return dp[n] = 0;
    }
    if(n==1)
    {
        return dp[n] = DP(n-1)+abs(a[n]-a[n-1]);
    }
    return dp[n] = min(DP(n-1)+abs(a[n]-a[n-1]),DP(n-2)+abs(a[n]-a[n-2]));
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    sf(n);
    memset(dp,-1,sizeof dp);
    rep0(i,n)
    {
        sf(a[i]);

    }
    cout<<DP(n-1)<<endl;
    return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll test[12345678];
signed main() {
    ll n, m, a = 0, ok = 1, ans = 1; cin >> n;
    for (int h = 0; h < n; h++) {
        cin >> test[h];
    }
    for (int h = 0; h < n; h++) {
        a++;
        if (test[h] >= ok) { ok += 2; }
        else { ans *= a; ans %= mod; a--; }
    }
    for (int h = 1; h <= a; h++) { ans *= h; ans %= mod; }
    while (ans < 0) { ans += mod; }
    cout << ans % mod << endl;
    return 0;
}

Measured memory_bytes: 4388
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,aris,bob;
	aris = 0;
	bob = 0;
	cin >> n;
	vector<int> card(n);
	rep(i, 0, n) {
		cin >> card[i];
	}
	sort(card.begin(), card.end(),greater<int>());
	rep(i, 0, n) {
		if (i % 2 == 0)aris += card[i];
		else bob += card[i];
	}

	cout << aris -bob << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
no_x = s.replace('x','')

l = 0
r = len(s)-1
ans = 0
while l<r :
  if s[l] != s[r]:
    ans += 1
    if s[l] == 'x':
      l += 1
    else:
      r -= 1  
  else:
    l += 1
    r -= 1  

for i in range(len(no_x)//2):
  if no_x[i] != no_x[-i-1]:
    ans = -1

print(ans)    

Measured memory_bytes: 3316
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

ll power_without_mod(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

vector<vector<ll>> graph;
vector<bool> visited;
vector<ll> dist;
map<ll,ll> mymap;
ll max_dist = 1;

void bfs(int u1){
    visited[u1] = 1;
    dist[u1] = 1;
    mymap[1] = u1;
    queue<ll> q;
    q.push({u1});
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto i=graph[u].begin();i!=graph[u].end();i++){
            if(!visited[*i]){
                dist[*i] = dist[u] + 1;
                visited[*i] = 1;
                max_dist = max(dist[*i],max_dist);
                mymap[dist[*i]] = *i;
                q.push({*i});
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll n,k;
        cin>>n>>k;
        n %= k;
        cout<<min(n,k-n);
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
vector<vector<char>> G;
vector<vector<int>> dist;

int solve(int sx, int sy) {
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) dist[i][j] = -1;
    }
    dist[sx][sy] = 0;
    queue<pair<int, int>> Q;
    Q.emplace(sx, sy);
    while(!Q.empty()) {
        auto cur = Q.front(); Q.pop();
        int x = cur.first, y = cur.second;
        for(int i=0; i<4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && G[nx][ny] == '.' && dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                Q.emplace(nx, ny);
            }
        }
    }

    int ret = 0;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) ret = max(ret, dist[i][j]);
    }
    return ret;
}

int main() {
    cin >> H >> W;
    G.assign(H, vector<char>(W));
    dist.assign(H, vector<int>(W));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) cin >> G[i][j];
    }

    int res = 0;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(G[i][j] == '#') continue;
            res = max(res, solve(i, j));
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256