akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const int MOD = 1000000007;

ll modadd(ll x, ll y) {
	ll xp = x % MOD;
	if (x < 0) x += MOD;
	ll yp = y % MOD;
	if (y < 0) y += MOD;
	return (x + y) % MOD;
}

ll modsub(ll x, ll y) {
	return modadd(x, -y);
}

ll modmul(ll x, ll y) {
	return x * y % MOD;
}

// power(mod) x^n
ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = modmul(res, x);
		x = modmul(x, x);
		n >>= 1;
	}
	return res;
}

// inverse(mod) x^(-1)
ll inv(ll x) {
	return modpow(x, MOD - 2);
}

ll moddiv(ll x, ll y) {
	return modmul(x, inv(y));
}

// factorial(mod) n!
ll fact(ll n) {
	ll res = 1;
	while (n > 1) {
		res = modmul(res, n);
		n--;
	}
	return res;
}

// permutation(mod) nPr
ll permu(ll n, ll r) {
	if (r < 0 || n < r) return 0;
	else {
		ll res = fact(n);
		res = moddiv(res, fact(n - r));
		return res;
	}
}

// nPr(mod) (O(r))
ll mypermu(ll n, ll r) {
	if (r < 0 || n < r) return 0;
	else {
		ll res = 1;
		for (ll i = 0; i < r; i++) {
			res = modmul(res, n - i);
		}
		return res;
	}
}

// combination(mod) nCr
ll combi(ll n, ll r) {
	ll res = permu(n, r);
	res = moddiv(res, fact(r));
	return res;	
}

// nCr(mod) (O(r))
ll mycombi(ll n, ll r) {
	ll res = moddiv(permu(n, r), permu(r, r));
	return res;
}

int main() {
	int X, Y; cin >> X >> Y;
	int ans = 0;
	if ((X + Y) % 3 == 0) {
		int n = (X + Y) / 3;
		int r = (2 * X - Y) / 3;
		ans = mycombi(n, r);
	}
	cout << ans << endl;
}

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

template<class T>
T gcd(T a, T b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

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

    ll K; cin >> K;
    ll ans = 0LL;
    for(ll i = 1LL; i <= K; ++i){
        for(ll j = 1LL; j <= K; ++j){
            for(ll k = 1LL; k <= K; ++k){
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3612
import java.math.BigDecimal;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
      	//BigDecimalで入力
      	BigDecimal A = sc.nextBigDecimal();
		BigDecimal B= sc.nextBigDecimal();
      
      	//sekiにAとBをかけたものを代入する
		BigDecimal seki = B.multiply(A);
      
      	//long型に変えて出力する
		long C = seki.longValue();
		System.out.println(C);
	}
}

Measured memory_bytes: 37544
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,m,M) for(int i = m;i<M;i++)
int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	int M = max(N, Q);
	vector<int> A(M);   //i番目に正解した人
	vector<int> num(M); //i番目の人がnum[i]回正解
	FOR(i, 0, Q)
	{
		cin >> A[i];
		num[A[i] - 1]++;
	}

	FOR(i, 0, N)
	{
		if (num[i] + K - Q  <= 0)
			cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1408
char s[9999];
main(){
	char*p,*n;
	for(;scanf("%[^\n]\n",s),strcmp(s,"END OF INPUT");){
		strcat(s," ");
		for(p=s;n=strchr(p,' ');p=n+1){
			printf("%d",n-p);
		}
		puts("");
	}
	exit(0);
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

const int MaxN = 2e5;
using namespace std;
int a[MaxN + 5]; 
int n ;
int main()
{
	while(~scanf("%d" , &n)){
		int tot = 1;
		if(n & 1) tot++;
		for(int i = 1;i <= n;i++) scanf("%d" , &a[i]);
		for(int i = n;i >= 1;i -= 2) printf("%d " , a[i]);
		for(int i = tot;i <= n;i += 2) printf("%d " , a[i]);
		printf("\n");
	}
}

Measured memory_bytes: 2816
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define MP make_pair
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STRING(x) string x;cin>>x;
# define STR(x) STRING(x);
# define DOUBLE(x) double x;cin>>x;
# define DBL(x) DOUBLE(x); 
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl
# define INIT(a) memset(a,-1,sizeof a)
# define CLR(a) memset(a,0,sizeof a)
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
//const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const int M = 1000000007;
template<class T> void debug(T a) { for ( auto i : a )cout << i << endl; }

#define int long long

multimap<int, pii> ms;

int compute_hash(vs A, vs B, multimap<int, pii> &m)
{
	vvi hashes;
	int B1 = 9973, B2 = 100000007;

	FOR(i, A.size())
	{
		int t1 = 1;
		FOR(j, B[0].size())t1 *= B1;
		int ah = 0;
		FOR(j, B[0].size())ah = ah*B1 + A[i][j];
		vi h;
		for ( int j = 0; j + B[0].size() <= A[i].size(); j++ )
		{
			h.push_back(ah);
			if ( j + B[0].size() < A[i].size() )ah = ah*B1 + A[i][j + B[0].size()] - A[i][j] * t1;
		}
		hashes.push_back(h);
	}
	FOR(j, hashes[0].size())
	{
		int t2 = 1;
		FOR(i, B.size())t2 *= B2;
		int ah = 0;
		FOR(i, B.size())ah = ah*B2 + hashes[i][j];
		for ( int i = 0; i + B.size() <= hashes.size(); i++ )
		{
			m.insert(MP(ah, pii(j, i)));
			if ( j + B.size() < hashes.size() )ah = ah*B2 + hashes[i][j + B.size()] - hashes[i][j] * t2;
		}
	}

	vi b;
	FOR(i, B.size())
	{
		int t1 = 1;
		int bh = 0;
		FOR(j, B[i].size())bh = bh*B1 + B[i][j];
		b.push_back(bh);
	}
	int ans = 0;
	FOR(i, b.size())
		ans = ans*B2 + b[i];
	return ans;
}

signed main()
{
	string a, b;
	cin >> a >> b;
	vs A(1, a), B(1, b);
	int h=compute_hash(A, B, ms);
	auto i = ms.lower_bound(h), j = ms.upper_bound(h);
	for ( ; i != j; i++ )
	{
		cout << i->second.first << endl;
	}

}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
signed main() {
    int n;
    cin>>n;
    int h[n];
    int dp[n];
    for(int i=0 ; i<n ; i++) cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2 ; i<n ; i++) {
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout<<dp[n-1];
}


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

int main() {
  int N,a;
  cin >> N;
  int A[N]={};
  int B[N]={};

  for(int i=0;i<N-1;i++){
     cin >> A[i];
     a = A[i];
     B[a-1] +=1;
}

for(int i=0;i<N;i++){
     cout << B[i] << endl;
}
return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, res;
	cin >> a >> b;

	if (a == b)
		res = a * 2;
	else
		res = max(a, b) * 2 - 1;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+5;
int hs[100100];
int dp[100100];
int N, K;

int rec(int i) {
    if (dp[i] < INF) return dp[i];
    if (i == 1) return 0;
    if (i == 2) return abs(hs[2] - hs[1]);
    int m = INF;
    int h = hs[i];
    for (int k = 1; k <= K; ++k) {
        if (0 < i - k) {
            m = min(m, rec(i - k) + abs(h - hs[i - k]));
        }
    }
    dp[i] = m;
    return dp[i];
}

void solve() {
    cin >> N >> K;
    for (int i = 1; i <= N; ++i) cin >> hs[i];
    for (int i = 1; i <= N; ++i) dp[i] = INF;
    cout << rec(N) << endl;
}

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


Measured memory_bytes: 5760
# coding: utf-8

list_r = []
line = int(input())
line_a = list(map(int, [line/100, (line%100)/10, line%10]))
for i in range(3):
    #print(i)
    list_r.append(10-line_a[i])
print(''.join(map(str, list_r)))

Measured memory_bytes: 2940
#include <stdio.h>

const long long mod = 1000000007;

struct mat {
	int a[3][3];

	mat operator -(mat t) {
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = (a[i][j] + mod - t.a[i][j]) % mod;
		}
		return r;
	}

	mat operator *(mat t){
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = 0;
			for (int k = 0; k < 3; k++) {
				r.a[i][j] = (r.a[i][j] + (long long)a[i][k] * t.a[k][j]) % mod;
			}
		}
		return r;
	}

	int get(){
		return (a[2][0] * 5ll + a[2][1]) % mod;
	}
};

int N, M, X[100100],D[100100];

int main()
{
	mat base[32];
	base[0] = mat{ 4,mod - 2,1,1,0,0,0,1,0 };
	for (int i=1;i<32;i++) base[i] = base[i-1] * base[i-1];

	scanf("%d %d", &N, &M);
	for (int t = 1; t <= M; t++) scanf("%d", &X[t]);
	X[M + 1] = N;

	mat sum = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	mat idt = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
	mat all = idt;

	for (int i = 1; i <= M + 1; i++) {
		mat now = idt;
		for (int j=0,x=X[i]-X[i-1];x;j++,x/=2) if (x & 1) now = now * base[j];
		sum = sum * now;
		all = all * now;
		D[i] = (all - sum).get();
		for (int k = 0; k < 3; k++) sum.a[k][k] = (sum.a[k][k] + D[i]) % mod;
	}

	printf("%d\n", D[M+1]);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int res=a[0];
    rep(i,n-1){
        if(a[i+1]>a[i]){
            res+=a[i+1]-a[i];
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#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];
    }
  }
  int flag = 0;
  bool can = false;
  int deltaX[4] = {1,0,-1,0};
  int deltaY[4] = {0,1,0,-1};
  for (int i=0; i < H; ++i) {
    for (int j=0; j < W; ++j) {
      if (s[i][j] == '#') {
        flag = 1;
        for (int k=0; k < 4; ++k) {
          int dy = i + deltaY[k];
          int dx = j + deltaX[k];
          if ((dy < 0)||(dx < 0)||(dy > H - 1)||(dx > W - 1)) {
            continue;
          }
          if (s[dy][dx] == '#') {
            can = true;
            break;
          }
        }
      }
      if ((flag == 1) && (can == false)) {
        cout << "No\n";
        return 0;
      }
      flag = 0;
      can = false;
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  int ans=0;
  for(int i=0;i<L;i++){
    if(S[i]!='.') continue;

    char lt='.',rt='.';
    for(int j=i-1;j>=0;j--){
      if(S[j]=='W') continue;
      lt=S[j];
      break;
    }
    for(int j=i+1;j<L;j++){
      if(S[j]=='W') continue;
      rt=S[j];
      break;
    }

    if(lt=='B'&&rt=='B') continue;
    if(lt=='.'&&rt=='.') continue;

    if(lt=='B'){
      int res=0;
      for(int j=i-1;j>=0;j--){
        if(S[j]=='W'){
          res=i-j-1;
          break;
        }else if(S[j]=='.') break;
      }
      ans=max(ans,res);
    }else{
      int res=0;
      for(int j=i+1;j<L;j++){
        if(S[j]=='W'){
          res=j-i-1;
          break;
        }else if(S[j]=='.') break;
      }
      ans=max(ans,res);
    }
  }

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
#define maxn 105
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	Point operator - (){
		return Point(-x,-y);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){ return a.x * b.x + a.y * b.y; }
double det(Vector a,Vector b){ return a.x * b.y - a.y * b.x; }
Vector rot(Vector a,double theta){//rotate.
	double x1 = cos(theta) * a.x - sin(theta) * a.y;
	double y1 = sin(theta) * a.x + cos(theta) * a.y;
	return Point(x1,y1);
}
struct Crossing{
	double r;
	int up;
	Crossing(double r = 0.0,int up = 0): r(r),up(up) {}
	bool operator < (const Crossing &b)const
	{
		return r < b.r;
	}
};
vector <Crossing> lis;
int ccw(Point p,Segment l){
	if(det(l.p2 - l.p1,p - l.p1) > EPS) return 1;
	if(det(l.p2 - l.p1,p - l.p1) < -EPS) return -1;
	if(dot(l.p2 - l.p1,p - l.p1) < -EPS) return 2;
	if((l.p2 - l.p1).norm() < (p - l.p1).norm()) return -2;
	return 0;
}
bool cross(Segment s1,Segment s2){
	return ccw(s1.p1,s2) * ccw(s1.p2,s2) <= 0 && ccw(s2.p1,s1) * ccw(s2.p2,s1) <= 0;
}
double crossPoint(Segment a,Segment b){
	return det(b.p2 - b.p1,a.p1 - b.p1) / det(a.p2 - a.p1,b.p2 - b.p1);
}
int T,n;
Segment nl,s;
int o,l;
int main(){
	scanf("%d",&T);
	while(T--){
		lis.clear();
		scanf("%lf%lf%lf%lf",&nl.p1.x,&nl.p1.y,&nl.p2.x,&nl.p2.y);
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%lf%lf%lf%lf",&s.p1.x,&s.p1.y,&s.p2.x,&s.p2.y);
			scanf("%d%d",&o,&l);
			l ^= o ^ 1;
			if(cross(s,nl)){
				lis.push_back(Crossing(crossPoint(nl,s),l));
			}
		}
		sort(lis.begin(),lis.end());
		int ans = 0;
		for(int i=1;i<(int)lis.size();i++){
			ans += (lis[i].up ^ lis[i - 1].up);
		}
		printf("%d\n",ans);
	}
	return 0;
}



Measured memory_bytes: 3144
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int n, K;
vector<vector<int> > g;   // to
vector<int> vvv;

int dfs(int par, int curr)
{
    int max = 0;
    int i;
    for (i = 0; i < (int)g[curr].size(); i++) {
        int next = g[curr][i];
        if (par == next) continue;
        int ret = dfs(curr, next);
        max = MAX(max, ret);
    }
    assert(curr==0 || max <= K - 1);
    if (max == K - 1 && curr!=0 && par!=0) {
        vvv.push_back(curr);
        return 0;
    }

    return max+1;
}

void solve()
{
    scanf("%d%d", &n, &K);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]); a[i]--;
    }

    int cnt = 0;
    if (a[0] != 0) {
        a[0] = 0;
        cnt++;
    }

    g.resize(n);
    for (i = 1; i < n; i++) {
        g[a[i]].push_back(i);
        g[i].push_back(a[i]);
    }
    dfs(-1, 0);


    cnt += (int)vvv.size();

    printf("%d\n", cnt);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 11388
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr int INF = 1ll<<30;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string s;
int dp[200010];
int memo[1ll<<26];

ll rev( ll bit, ll b ) {
  return bit^(1ll<<b);
}

int main() {
  std::cin >> s;

  ll n = s.size();
  ll par = 0;

  rep( i, n+5 )
    dp[i] = INF;
  rep( i, 1ll<<26 )
    memo[i] = INF;

  dp[0] = 0;
  memo[0] = 0;

  rep( i, n ) {
    par = rev( par, s[i]-'a' );
    chmin( dp[i+1], memo[par]+1 );
    
    rep( c, 26 ) {
      par = rev( par, c );
      chmin( dp[i+1], memo[par]+1 );
      par = rev( par, c );
    }

    chmin( memo[par], dp[i+1] );
  }

  std::cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 266692
#include"bits/stdc++.h"

using namespace std;

int main() {
	string s;
	cin >> s;
	int cnt = 0;

	for (int i = 1; i < s.length() - 1; i++) {
		cnt++;
	}

	cout << s[0] << cnt << s.back() << endl;

	return 0;
}

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

int main() {
    int n, temp, ans=0;
    cin >> n;
    int v[n];

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

    for (int i = 0 ; i < n ; ++i) {
        cin >> temp;
        v[i] -= temp;
        if (v[i] > 0) ans += v[i];
    }

    cout << ans; 

    return 0;
}


Measured memory_bytes: 3620
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())


int main() {

	std::cin.tie(0);
    
	int a,b,i;
	int tmpa, tmpb;
	cin >> a >> b;

	for(i=10;i<10001;i++){

		tmpa =  (i * 0.08);
		tmpb =  (i * 0.1);

		if(a==tmpa && b == tmpb ){
			cout << i << endl;
			return 0;
		}

	}

	cout << "-1" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int MAX = 1001;

int main() {
	int N, M;
	long long x[MAX], y[MAX], z[MAX];
	long long ans = 0;
	vector<long long> v[8];

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < N; j++) {
			long long sum = 0;
			sum += i & (1 << 0) ? x[j] : -x[j];
			sum += i & (1 << 1) ? y[j] : -y[j];
			sum += i & (1 << 2) ? z[j] : -z[j];
			v[i].push_back(sum);
		}
	}

	for (int i = 0; i < 8; i++) {
		sort(v[i].begin(), v[i].end());

		long long sum1 = 0;
		long long sum2 = 0;

		for (int j = 0; j < M; j++) {
			sum1 += v[i][j];
			sum2 += v[i][M - j - 1];
		}
		ans = max(ans, max(abs(sum1), abs(sum2)));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228
#define complex complex228

ghost main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	int S;
	cin >> S;
	if (S == 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL) {
		cout << 0 << " " << 0 << " " << 1000000000 << " " << 0 << " " <<  0 << " " << 1000000000 << '\n';
		return 0;
	}
	int sq = (int)sqrt(S) + 1;
	int x1 = sq, y2 = sq, x2 = 0, y1 = 0;
	int rest = sq * sq - S;
	x2 = 1, y1 = rest;
	for (int i = 2; i * i <= rest; ++i) {
		if (rest % i == 0) {
			x2 = i;
			y1 = rest / i;
		}
	}
	cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << '\n';
	return 0;
} // kek ;
// Ого! Кажетсья это $#@!










Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.algorithm, std.string, std.math;

void main() {
    string s;
    while ((s = readln()).length != 0) {
        int[] nx;
        if (to!uint(s.chomp) == 0) {break;}
        for (uint i = 0; i < to!uint(s.chomp); ++i) {
            nx ~= to!int(readln().chomp);   
        }
        writeln(solve(nx));
    }
}

int solve(int[] tx) {
    if (negative_all(tx)) {
        int max = -100000;
        foreach(n ; tx) {
            if (n > max) {
                max = n;   
            }
        }
        return max;
    }
    
    int[] nx = reduce_by_sign(tx);
    
    if (nx.length == 1)      { return nx[0]; }
    
    if (nx[0] < 0)           { nx = nx[1..(nx.length)]; }
    if (nx[nx.length-1] < 0) { nx = nx[0..(nx.length-1)]; }

    /*for (uint i = 0; i < nx.length; ++i) {
        if (nx[i] < 0) {
            if (nx[i-1] >= abs(nx[i]) && nx[i+1] >= abs(nx[i])) {
                int t = nx[i-1] + nx[i] + nx[i+1];
                if (i+2 < nx.length) {
                    nx = nx[0..i-1] ~ [t] ~ nx[i+2..nx.length];
                } else {
                    nx = nx[0..i-1] ~ [t];
                }
            }
        }
    }

    int max = 0;
    foreach(n ; nx) {
        if (max < n) {
           max = n;   
        }
    }*/
    int max = nx[0];
    for (uint i = 0; i < nx.length; ++i) {
        int max_ = nx[i];
        int acc = max_;
        for (uint j = i+1; j < nx.length; ++j) {
            acc = acc + nx[j];
            if (acc > max_) { max_ = acc; }
        }
        if (max_ > max) { max = max_; }
    }
    
    return max;
}

bool negative_all(int[] nx) {
    foreach(n ; nx) {
        if (n > 0) {
            return false;
        }
    }
    return true;
}

int[] reduce_by_sign(int[] nx) {
    bool sign = (nx[0] >= 0);
    uint index = 0;
    int[] ret = [nx[0]];
    
    for (uint i = 1; i < nx.length; ++i) {
        if (sign != (0 <= nx[i])) {
            sign = !sign;
            ret ~= 0;
            ++index;
        }
            
        ret[index] += nx[i];
    }
    return ret;
}

Measured memory_bytes: 1136
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int s, w;
    cin >> s >> w;
    cout << (s <= w ? "unsafe" : "safe") << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadLongArray(N);
        var B = sc.ReadLongArray(N);

        long m = 0;
        var mcount = 0;
        var X = new long[N];
        for (int i = 0; i < N; i++)
        {
            if (A[i] < B[i])
            {
                m += B[i] - A[i];
                mcount++;
            }
            else X[i] = A[i] - B[i];
        }
        Array.Sort(X);
        Array.Reverse(X);

        if (A.Sum() < B.Sum())
        {
            Console.WriteLine(-1);
            return;
        }
        if (mcount == 0)
        {
            Console.WriteLine(0);
            return;
        }

        var ans = mcount;
        for (int i = 0; i < N; i++)
        {
            ans++;
            m -= X[i];
            if (m <= 0) break;
        }
        Console.WriteLine(ans);
    }

    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 31120
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[305];
ll dp[2][45002];
ll dp2[2][45002];
ll tp[305];
ll tp2[305];

ll extgcd(ll a,ll b,ll& x,ll& y){
    ll d=a;
    if(b!=0LL){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }else{
        x=1;
        y=0;
    }
    return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}


int main(void){
    tp[0]=1;
    tp2[0]=1;
    ll inv=mod_inverse(2,MOD);
    for(int i=0;i<=300;i++){
        tp[i+1]=tp[i]*2LL%MOD;
        tp2[i+1]=tp2[i]*3LL%MOD;
    }
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int su=0;
    dp[0][0]=tp[n]*3LL%MOD;
    dp2[0][0]=3LL;
    int cur=0,nxt=1;
    for(int i=0;i<n;i++){
        for(int k=0;k<=min(su,sum/2+1);k++){
            //printf("%d %d %lld\n",i,k,dp2[cur][k]);
            dp[nxt][k]+=dp[cur][k]%MOD;
            if(dp[nxt][k]>=MOD){
                dp[nxt][k]-=MOD;
            }
            dp2[nxt][k]+=dp2[cur][k]%MOD;
            if(dp2[nxt][k]>=MOD){
                dp2[nxt][k]-=MOD;
            }
            dp[nxt][min(k+a[i],sum/2+1)]+=dp[cur][k]*inv%MOD;
            if(dp[nxt][min(k+a[i],sum/2+1)]>=MOD){
                dp[nxt][min(k+a[i],sum/2+1)]-=MOD;
            }
            dp2[nxt][min(k+a[i],sum/2+1)]+=dp2[cur][k]%MOD;
            if(dp2[nxt][min(k+a[i],sum/2+1)]>=MOD){
                dp2[nxt][min(k+a[i],sum/2+1)]-=MOD;
            }
        }
        su+=a[i];
        swap(cur,nxt);
        memset(dp[nxt],0,sizeof(dp[nxt]));
        memset(dp2[nxt],0,sizeof(dp2[nxt]));
    }
    ll ans=tp2[n];
    //printf("%lld\n",ans);
    //printf("%d %lld %lld\n",i,dp[cur][i][sum/2+1],dp[cur][i][sum/2]);
    {
        ll val=dp[cur][sum/2+1]%MOD;
        ans-=val;
        if(ans<0LL)ans+=MOD;
    }
    if(sum%2==0){
        ll val=dp[cur][sum/2]%MOD;
        //ll tpa=(tp[n-i]-2LL+MOD)%MOD;
        //val=val*tpa%MOD;
        ans-=val;
        if(ans<0LL)ans+=MOD;
        ans+=dp2[cur][sum/2];
        ans%=MOD;
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main (void){

    int N,T=0,i,j;
    cin >> N;
    int t[N],x[N][2];
    for(i = 0; i < N; i++){
        cin >> t[i];
        for(j = 0; j < 2; j++){
            cin >> x[i][j];
        }
    }
    for(i = 0; i < N; i++){
        if(( t[i] - T ) >= x[i][0] + x[i][1]){
            if( ( ( t[i] - T ) - ( x[i][0] + x[i][1]) ) % 2 == 0 ){
                continue;
            }else{
                cout << "No" << endl;
                return 0;
            }
        } else{
            cout << "No" << endl;
            return 0;
        }
        T = t[i];
    }

        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
package main

import (
	"fmt"
)

func main() {
	var n,m,c int
	fmt.Scan(&n,&m,&c)

	bs := make([]int,m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scan(&b)
		bs[i] = b
	}

	count := 0
	for i := 0; i < n; i++ {
		sum := c
		for j := 0; j < m; j++ {
			var a int
			fmt.Scan(&a)
			sum += bs[j] * a
		}
		if sum > 0 {
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
#include <stdio.h>
#define N 2000000
int n,A[N],B[N],i;
void CountingSort(int*,int*,int);
int main(){
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
    }
  CountingSort(A,B,n);
  return 0;
}
void CountingSort(int *A,int *B,int n){
  int i,j,C[N];
  for(i = 0;i < N;i++){
    C[i] = 0;
    }
  for(j = 0;j < n;j++){
    C[A[j]]++;
    }
  for(i = 1;i <= N;i++){
    C[i] = C[i] + C[i - 1];
    }
  for(j = n;j >= 0;j--){
    B[C[A[j]]] = A[j];
    (C[A[j]])--;
  }
  for(i = 1;i <= n;i++){
    if(i-1)printf(" ");
    printf("%d",B[i]);
    }
  printf("\n");
}



Measured memory_bytes: 25168
#include<stdio.h>
int main()
{
    long long s,c;
    while(scanf("%lld%lld",&s,&c)!=EOF){
    if(s>c/2)
        printf("%lld\n",c/2);
    else
    {
        printf("%lld\n",s+(c-(s*2))/4);
    }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,x;
  cin>>n>>x;
  int a[n];
  for(int i = 0; i < n; i++) cin>>a[i];
  ll cnt = 0;
  for(int i = 0; i < n-1; i++){
    if(a[i]>x){
      cnt+=a[i]-x;
      a[i]=x;
    }
    if(a[i]+a[i+1]>x){
      cnt+=a[i+1]-(x-a[i]);
      a[i+1]=x-a[i];
    }
  }
  // for(int i = 0; i < n; i++) cout<<a[i]<<" ";
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<VI> bulb(m);
  FOR(b,bulb) {
    int k;
    cin >> k;
    REP(i,0,k) {
      int s;
      cin >> s;
      b.push_back(s);
    }
  }
  VI ps(m);
  FOR(p,ps) {
    cin >> p;
  }
  ll ans = 0;
  REP(i,0,1<<n) {
    bool ok = true;
    REP(j,0,m) {
      bool on = ps[j] == 0;
      FOR(s,bulb[j]) {
        if ((i >> (s - 1) & 1) != 0) {
          on = !on;
        }
      }
      if (!on) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main ()
{
    long n, c, k;
    cin >> n >> c >> k;
    long t[n];
    rep(i, n) cin >> t[i];

    sort(t, t+n);

    long passenger_n = 1;
    long endure_t = t[0];
    long res = 1;
    for (int i = 1; i < n; i++) {
        passenger_n++;
        if (passenger_n > c || t[i] > endure_t + k) {
            res++;
            endure_t = t[i];
            passenger_n = 1;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
K,A,B=map(int,input().split())
ans=1
if K==1:
  ans+=1
elif A>=B-1 or K-A+1<=0:
  ans+=K
else:
  if (K-(A-1))%2==0:
    ans=A+(B-A)*( (K-A+1)//2 )
  else:
     ans=A+(B-A)*( (K-A+1)//2 )+1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll x[MAX],y[MAX],cs_x[MAX],cs_y[MAX];
ll dist(ll x,ll y)
{
    if(x<=0 && y<=0)
        return abs(abs(x)-abs(y));
    else if(x<=0 && y>=0)
        return abs(x)+y;
    else
        return y-x;
}
ll sum(int n)
{
    ll res=0;
    for(int i=0; i<n; i++)
    {
        res+=(((x[i]*(i+1))%MOD)*(n-i))%MOD;
        res%=MOD;
    }
    return res;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,m,mx_y=0,mn_y=INT_MAX;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        cin>>x[i];
        if(i)
            x[i-1]=dist(x[i-1],x[i]);
    }
    for(int i=0; i<m; i++)
    {
        cin>>y[i];
        if(i)
            y[i-1]=dist(y[i-1],y[i]);
    }
    ll X=sum(n-1),res=0;
    m--;
    for(int i=0; i<m;i++)
    {
        ll t=(((y[i]*(i+1))%MOD)*(m-i))%MOD;
        t=(t*X)%MOD;
        res+=t;
        res%=MOD;
    }
    cout<<res<<endl;





    return 0;
}


Measured memory_bytes: 5196
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int X[12];

char D[12][13];
int N, M;
int ans = 0;

void solve(){
//	for(int i = 0; i < M; i++) printf("%d ", X[i]); printf("\n");
	int dp[1<<12] = {};
	int pos[12][12] = {};
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			pos[i][j] = 1;
			for(int k = 0; k < M; k++){
				if(D[i][k] != D[j][X[k]]) pos[i][j] = 0;
			}
//			printf("%d ", pos[i][j]);
		}
//		printf("\n");
	}
	dp[0] = 1;
	if(N%2 == 1){
		for(int i = 0; i < N; i++){
			if(pos[i][i]) dp[1<<i] = 1;
		}
	}
	for(int i = 0; i+1 < 1<<N; i++){
		if(dp[i] == 0) continue;
		int v = 0;
		for(v = 0; i&1<<v; v++);
		for(int u = 0; u < N; u++){
			if(u == v || (1<<u&i) || !pos[u][v]) continue;
			dp[1<<u | 1<<v | i] = 1;
		}
	}
	int mx = (1<<N) - 1;
	if(dp[mx]) ans = 1;
}

void dfs(int x, int ch){
	if(x == M) return solve();
	if(X[x] != -1){
		dfs(x+1, ch);
		return;
	}
	if(ch){ X[x] = x; dfs(x+1, 0); X[x] = -1; }
	for(int i = x+1; i < M; i++){
		if(X[i] != -1) continue;
		X[x] = i; X[i] = x;
		dfs(x+1, ch);
		X[x] = X[i] = -1;
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++) scanf("%s", D[i]);
	for(int i = 0; i < M; i++) X[i] = -1;
	dfs(0, M%2);
	printf("%s\n", ans?"YES":"NO");
}


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

using namespace std;

int main()
{
    string s; cin >> s;
    bool isPalindrome = true;
    
    int n = s.size();
    for (int i = 1; i <= n; i++) {
        if (s[i-1] != s[n-i]) {
            isPalindrome = false;
        }
        int mid1 = ((n-1)/2)-i;
        if (i-1 <= mid1) {
            if (s[i-1] != s[mid1]) {
                isPalindrome = false;
            }
        }
        int mid2 = (n+3)/2+i-2;
        if (mid2 <= n-i) {
            if (s[mid2] != s[n-i]) {
                isPalindrome = false;
            }
        }
    }
    
    cout << (isPalindrome ? "Yes" : "No") << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string S; int N, cnt;
 
int main() {
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		int c[3] = {i / 100, (i / 10) % 10, i % 10};
		int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == ('0' + c[f])) f++;
			if (f == 3) break;
		}
		if (f == 3) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3652
void main() {
  problem();
}

void problem() {
  const K = scan!long;

  long solve() {
    auto queue = DList!long(1,2,3,4,5,6,7,8,9);

    long count;
    while(true) {
      count++;
      auto n = queue.front;
      if (count == K) return n;
      queue.removeFront();

      const tail = n % 10;
      const next = n * 10 + tail;
      if (tail != 0) queue.insertBack(next - 1);
      queue.insertBack(next);
      if (tail != 9) queue.insertBack(next + 1);
    }
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.functional;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 11644
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int n, m, ans, a[maxn];
string s;

void solve(){
	cin >> n >> m >> s;

	if (m == 2 || m == 5){
		for (int i = 0; i < n; i++)
			if ((s[i] - '0') % m == 0)
				ans += (i + 1);
	    cout << ans;
	    return;
	}

	/*for (int i = 0; i < n; i++){
		for (int j = i; j < n; j++){
			int x = 0;
			for (int k = i; k <= j; k++){
				x = (x * 10 + (s[k] - '0'));
				x %= m;
			}
			if (x == 0){
				cout << i + 1 << " " << j + 1 << endl;
				ans++;
			}
		}
	}

	cout << ans;
	return;   */

	int x = 0, p = 1;
	a[x] = 1;

	for (int i = n - 1; i >= 0; i--){
		x = (x + (s[i] - '0') * p) % m;
		ans += a[x];
		a[x]++;
		p *= 10;
		p %= m;
	}

	cout << ans;
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

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

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

int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<string, int>> S(N);
  int AC = 0, WA = 0;
  for (int i = 0; i < M; i++) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (s == "WA") {
      if (S.at(p).first == "AC") continue;
      else S.at(p).first = "WA", S.at(p).second++, WA++;
    }
    if (s == "AC") {
      if (S.at(p).first == "AC") continue;
      else S.at(p).first = "AC", AC++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (S.at(i).first == "WA" && S.at(i).second) WA -= S.at(i).second;
  }

  cout << AC << " " << WA << "\n";
}

Measured memory_bytes: 6528
#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;

int main(void) {
    int a, b, c;cin >> a>>b>>c;
    cout << (a == c && a != b || a == b && a != c || b == c && b != a ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N, C, K = map(int, input().split())
    T = sorted([int(input()) for i in range(N)])
    cnt = 0
    past_time = 0
    ans = 0
    for i in range(len(T)):
        if cnt != 0 and past_time != 0 and past_time + K < T[i]:
            ans += 1
            cnt = 1
            past_time = T[i]
        else:
            cnt += 1
            if cnt == 1:
                past_time = T[i]
            if cnt == C:
                ans += 1
                cnt = 0
    if cnt > 0:
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14160
s=input()
t=list(s)
u=list(s)
a=[]
for i in range(26):
    a.append(chr(i+97))
if len(t)!=26:
    flag=True
    for i in range(len(a)):
        if a[i] not in t:
            b=a[i]
            flag=False
            break

    if flag:
        print(-1)
    else:
        print(s+a[i])
else:
    flag2=True
    r=[t[-1]]
    t.remove(t[-1])
    while len(t):

        if r[-1]>t[-1]:
            k=t[-1]
            t.remove(t[-1])
            for i in range(len(r)):
                if r[i]>k:
                    ans=r[i]
                    break

            print("".join(t)+ans)
            flag2=False
            break
        if len(t)==0: break
        r.append(t[-1])
        t.remove(t[-1])

        r=sorted(r)
    if flag2: print(-1)

Measured memory_bytes: 3064