akhauriyash/Code-Regression huggingface dataset:
def isPalindrome(s): 
    rev = ''.join(reversed(s)) 
    if (s == rev): 
        return True
    return False
s=input()
n=len(s)
if n%2==1:
    if isPalindrome(s):
        k=n//2
        s1=s[:k]
        if isPalindrome(s1):
            v=(n+3)//2-1 
            s2=s[v:]
            if isPalindrome(s2):
                print("Yes")
            else:
                print("No")    
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

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

using namespace std;
using ll = long long;
int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<ll> pq;
  for(int i=0;i<n;i++){
    ll a;
    cin >> a;
    pq.push(a);
  }
  vector<pair<ll,ll>> b(m);
  for(int i=0;i<m;i++){
    cin >> b[i].second >> b[i].first;
  }
  sort(b.rbegin(),b.rend());
  ll now = 0;
  for(ll i=0;i<m;i++){
    for(ll j=0;j<b[i].second;j++){
      pq.push(b[i].first);
      if(++now==n)break;
    }
    if(now==n)break;
  }
  ll ret = 0;
  for(int i=0;i<n;i++){
    ret += pq.top();
    pq.pop();
  }
  cout << ret << endl;
}


Measured memory_bytes: 3956
#include <stdio.h>
#include <math.h>


int main(void){
  
    //int n, i;
    int mat[2][2], c, f;
    double mat2[2][2];
    double deltamat;
    
    while(scanf("%d %d %d %d %d %d", &mat[0][0], &mat[0][1], &c, &mat[1][0], &mat[1][1], &f) == 6){
        deltamat = (double)mat[0][0] * mat[1][1] - (double)mat[0][1] * mat[1][0];
        //printf("%f\n", deltamat);
        mat2[0][0] = (double)mat[1][1] / deltamat;
        mat2[0][1] = mat[0][1] / -deltamat; //printf("%f\n", mat2[0][1]);
        mat2[1][0] = mat[1][0] / -deltamat;
        mat2[1][1] = (double)mat[0][0] / deltamat;
        printf("%.3lf %.3lf\n", mat2[0][0]*(double)c+mat2[0][1]*(double)f, mat2[1][0]*(double)c+mat2[1][1]*(double)f);
    }
    return 0;
    
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  
  long double ans, L, L3;
  
  cin >> L;
  L3 = L/3;
  
  ans = L3*L3*L3;
  cout << fixed << setprecision(15)<< ans;
  
  return 0;
}

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

int main()
{
	ll x,y;
	cin >> x >> y;
	int ans = 0;
	for(ll i = x;i<=y;i*=2)
	{
		ans ++;
		//cout<<i<<';'<<y<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		if(n>=9000) ans = 10000-n;
		else if(n>=8000) ans = 9000-n;
		else if(n>=7000) ans = 8000-n;
		else if(n>=6000) ans = 7000-n;
		else if(n>=5000) ans = 6000-n;
		else if(n>=4000) ans = 5000-n;
		else if(n>=3000) ans = 4000-n;
		else if(n>=2000) ans = 3000-n;
		else if(n>=1000) ans = 2000-n;
		else ans = 1000-n;

		if(ans == 1000) System.out.println(0);
		else System.out.println(ans);

	}
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;

int was[100000];
vi v[100000];
ii val[100000];
int cnt[100000];
int col[100000];

int go (int x, int r) {
	if (was[x]) re 0;
	was[x] = 1;
	col[x] = r;
	for (int i = 0; i < sz (v[x]); i++) {
		int y = v[x][i];
		go (y, r);
	}
	re 0;
}

int main () {
	scanf ("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf ("%d", &val[i].fi);
		val[i].se = i;
	}	
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf ("%d%d", &a, &b);
		v[a].pb (b);
		v[b].pb (a);
	}
	int r = 0;
	for (int i = 0; i < n; i++)
		if (!was[i]) {
			go (i, r);
			r++;
		}
	if (r == 1) {
		cout << 0 << endl;
		re 0;
	}
	sort (val, val + n);
	ll ans = 0;
	int rem = 2 * (r - 1);
	memset (was, 0, sizeof (was));
	for (int i = 0; i < n; i++)
		if (cnt[col[val[i].se]] == 0) {
			cnt[col[val[i].se]]++;
			ans += val[i].fi;
			was[val[i].se] = 1;
			rem--;
		}
	for (int i = 0; i < n && rem > 0; i++)
		if (!was[val[i].se] && cnt[col[val[i].se]] < r - 1) {
			cnt[col[val[i].se]]++;
			ans += val[i].fi;
			was[val[i].se] = 1;
			rem--;
		}
	if (rem > 0) {
		cout << "Impossible" << endl;
		re 0;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	string in,lon = "",mor = "";
	map<string,int> aa;
	while(cin >> in)
	{
		if(in.size() > lon.size())
			lon = in;
		aa[in]++;
		if(aa[mor] < aa[in])
			mor = in;
	}
	cout << mor << " " << lon << endl;
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int mod=1e9+7;
const int N=4010,maxn=8000,M=200010;
int a[M],b[M];
int dp[N][N];
int cj[N*2],inv[N*2];
int ans;
int n,ma,mb;

int power(int x,int y){
	int ret=1;
	for(;y;y>>=1,x=1ll*x*x%mod){
		if(y&1)	ret=1ll*ret*x%mod;
	}
	return ret;
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i,j;
	scanf("%d",&n);
	rep(i,1,n)	scanf("%d%d",&a[i],&b[i]),ma=max(ma,a[i]),mb=max(mb,b[i]);
	rep(i,1,n)	dp[ma-a[i]][mb-b[i]]++;
	rep(i,0,2*ma){
		rep(j,0,2*mb){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod;
		}
	}
	rep(i,1,n)	ans=(ans+dp[ma+a[i]][mb+b[i]])%mod;
	cj[0]=1;rep(i,1,maxn)	cj[i]=1ll*cj[i-1]*i%mod;
	inv[0]=1;inv[maxn]=power(cj[maxn],mod-2);
	for(i=maxn-1;i;i--)	inv[i]=1ll*inv[i+1]*(i+1)%mod;
	rep(i,1,n)	ans=(ans-1ll*cj[2*a[i]+2*b[i]]*inv[2*a[i]]%mod*inv[2*b[i]])%mod;
	ans=(ans+mod)%mod;
	ans=1ll*ans*power(2,mod-2)%mod;
	printf("%d",ans);
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 10, 0);
  int input;
  int i;
  for (i = 0; i < n; i++) {
    cin >> input;
    a[input]++;
  }
  sort(a.begin(), a.end(), greater<int>());
  int result = n;
  for (i = 0; i < k; i++) {
    result -= a[i];
    if (a[i] == 0) {
      break;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1024
h, w = map(int,input().split())
if h == 1 or w == 1:
    print(1)
else:
    h1 = (h+1) // 2
    h2 = h // 2
    w1 = (w+1) //2
    w2 = w // 2
    print(h1*w1 + h2*w2)

Measured memory_bytes: 2940
import sys

n, *csf = map(int, sys.stdin.read().split())
csf = list(zip(*[iter(csf)] * 3))

def main():
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t <= s: t = s + c
            else: t = s + ((t - s + f - 1) // f) * f + c
        print(t)
    print(0)

if __name__ ==  '__main__':
    main()

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;


template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

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

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> vec;
  for(int i = 0; i < n; ++i) {
    ll add = 0;
    for(int j = i; j < n; ++j) {
      add += a[j];
      vec.push_back(add);
    }
  }

  ll ans = 0;
  for(int t = 40; t > 0; --t) {
    ll q = 0;
    for(auto x : vec) {
      ll tmp = ans + (ll)pow(2, t-1);
      tmp &= x;
      if(tmp == ans + (ll)pow(2, t-1)) ++q;
    }
    if(q >= k) ans += pow(2, t-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6260
n, k = map(int, input().split())
x = list(map(int, input().split()))
t = []
for i in range(n - k + 1):
    if x[i] * x[i + k -1] >= 0:
        t.append(max(abs(x[i]), abs(x[i + k - 1])))
    else:
        t.append(x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i])))
print(min(t))

Measured memory_bytes: 15020
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007


int main()
{   
    ll n,k;cin>>n>>k;
    if(n%2==0)
    {
        if(k>n/2)
        cout<<"NO"<<"\n";
        else
        cout<<"YES"<<"\n";
    }
    else
    {
        if(k>(n/2+1))
        cout<<"NO"<<"\n";
        else
        cout<<"YES"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3580
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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


Measured memory_bytes: 35784
#include <bits/stdc++.h>
using namespace std;
inline int rf()
{
	int r;int s=0,c;
	for(;!isdigit(c=getchar());s=c);
	for(r=c^48;isdigit(c=getchar());
	(r*=10)+=c^48);
	return s^45?r:-r;
}
//#define int long long
#define N
int n;
//int head[N<<1],nxt[N<<1],ver[N<<1],top=0;
//int val[N<<1];
/*
void add(int x,int y)
{
	 nxt[++top]=head[x];
	 head[x]=top;
	 ver[top]=y;
	 //val[top]=v;
}
*/
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int a,b;
    cin>>a>>b;
  	cout<<max(0,a-2*b);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b) ) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var cnt = new long[N + 1];
		for(long x = 1; x * x <= N; x++)
		{
			for(long y = 1; y * y <= N; y++)
			{
				for(long z = 1; z * z <= N; z++)
				{
					long f = x * x + y * y + z * z + x * y + y * z + z * x;
					if(f <= N)
						cnt[f]++;
				}
			}
		}
		WriteLine(string.Join("\n", cnt.Skip(1)));
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

int main() {

    string s;
    cin >> s;

    rep(i, s.size()) s[i] = 'x';

    cout << s << endl;

    return 0;
}

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

int main(){
    int n;
    string s,t;
    cin >> n >> s;

    bool flag = true;
    if(n%2 == 1) flag = false;
    else{
        rep(i, n / 2) if (s[i] != s[n / 2 + i]) flag = false;
    }
    if(flag)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;

        return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[200005],b[200005]; 
int main(){
	cin>>n>>k;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	if(k>50){
		for(int i=0;i<n;++i){
			cout<<n<<' ';
		}
		cout<<'\n';
		return 0;
	}
	for(int i=0;i<k;++i){
		memset(b,0,sizeof(b));
		for(int i=0;i<n;++i){
			int l=max(0,i-a[i]);
			int r=min(n-1,i+a[i]);
			b[l]++;
			if(r+1<n){
				b[r+1]--;
			} 
		}
		for(int i=1;i<n;++i){
			b[i]+=b[i-1];
		}
		for(int i=0;i<n;++i){
			a[i]=b[i];
		}
	}
	for(int i=0;i<n;++i){
		cout<<a[i]<<' ';
	}
	cout<<'\n';
	return 0;
} 

Measured memory_bytes: 5180
N, M = map(int, input().split())
i = 0
li = []
while i < N:
    try:
        li.append(list(map(int, input().split())))
    except:
        break
    i += 1

if 1 == len(li):
    del(li[0][0])
    print(len(li[0]))
else:
    temp = []
    for i in range(N):
        del(li[i][0])
        if i == 0:
            temp = list(set(li[i]) & set(li[i+1]))
        else:
            temp = list(set(li[i]) & set(temp))

    if temp:
        print(len(temp))
    else:
        print(0)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, Ans, i, j, k, a[200000], sub = 0;
cc judge[200000][35], kai[35], A = 0;

string S;


int main() {
	
	cin >> N;
	Ans = 3 * N*N;
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 256
N,K,Q = map(int, input().split())
P = [K-Q]*N
# print(P)
for i in range(Q):
    A = int(input())
    P[A-1] += 1

for i in range(N):
    if P[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 6596
import Foundation

main()

func main() {
    guard let s = readLine() else {
        return
    }
    var ans = 0, cnt = 0
    for c in s {
        if (c == "R") {
            cnt += 1
        } else {
            cnt = 0
        }
        ans = max(ans, cnt)
    }
    print(ans)
}


Measured memory_bytes: 13096
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll mod = 1000000007;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define srep(i,s) rep(i,(ll)s.size())
#define vin(n,v) rep(i,n)cin>>v[i]
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
void YN(bool b) { cout << (b ? "YES" : "NO") << endl; }
void yn(bool b) { cout << (b ? "Yes" : "No") << endl; }
ll n, num = 0;
int main(){
	cin >> n;
	rep(i, 100000000) {
		num += i;
		if (num >= n){ cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a, b, c, d,both;

int main()
{
	cin>>a>> b>> c>> d;
	if (b <= c||a>=d)
	{
		both =0;
	}
	else if (b >= d && a <= c)
	{
		both = d - c;
	}
	else if (b <= d && a <= c)
	{
		both = b - c;
	}
	else if (a>=c&&b>=d)
	{
		both = d - a;
	}
	else
		both = b - a;
	cout << both;
	return 0;
}

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

int main() {

	char a[2][3];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	if (a[0][0] == a[1][2] && a[0][1] == a[1][1] && a[0][2] == a[1][0])
		cout << "YES" << endl;
	else
	cout<< "NO" <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m,num=-1;
char s[30];
bool used[30];
bool tuke=false;
bool ok=false;
ll ikeru=0;
 
int main(){
	cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		used[s[i]-96]=true;
	}
	for(i=1;i<=26;i++){
		if(!used[i]){
			tuke=true;
			break;
		}
	}
	if(tuke){
		char a[1];
		a[0]='a'-1+i;
		cout<<s<<a[0]<<endl;
	}else{
		for(i=1;i<=26;i++){
			used[i]=false;
		}
		for(i=0;i<n;i++){
			used[s[i]-96]=true;
			for(j=s[i]-95;j<=26;j++){
				if(!used[j]){
					ikeru=j;
					num=i;
					break;
				}
			}
		}
		s[num]=('a'-1+ikeru);
		
		if(num==-1)cout<<-1<<endl;
		else{
			for(j=0;j<num+1;j++){
			cout<<s[j];
		}
		cout<<endl;
		}
	}
 
	return 0;
}

Measured memory_bytes: 4992
n=int(input())
lst=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    lst.append([c,s,f])

for i in range(n-1):
    time=0
    for j in range(i,n-1):
        if time<=lst[j][1]:
            time=lst[j][1]+lst[j][0]
            continue
        if time%lst[j][2]==0:
            time+=lst[j][0]
            continue
        time+=(lst[j][2]-time%lst[j][2])+lst[j][0]
    print(time)
print(0)

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

int main(){
    using namespace std;
    using tuplis = array<int, 3>;
    const int sq = 800;
    
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    for(int& i : c){
        cin >> i;
        i--;
    }
    vector<tuplis> query(q);
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        l--;
        query[i] = {l, r, i};
    }
    sort(query.begin(), query.end(), [&](const tuplis& a, const tuplis& b){ if(a[0] / sq == b[0] / sq) return a[1] < b[1]; return a[0] < b[0]; });
    vector<int> ans(q);
    vector<int> cnt(n);
    int types = 0, L = 0, R = 0;
    for(auto [l, r, i] : query){
        while(L < l){
            cnt[c[L]]--;
            types -= !cnt[c[L]];
            L++;
        }
        while(L > l){
            L--;
            types += !cnt[c[L]];
            cnt[c[L]]++;
        }
        while(R > r){
            R--;
            cnt[c[R]]--;
            types -= !cnt[c[R]];
        }
        while(R < r){
            types += !cnt[c[R]];
            cnt[c[R]]++;
            R++;
        }
        ans[i] = types;
    }
    for(int i : ans) cout << i << ' ';
}

Measured memory_bytes: 15460
#include <cstdio>
#define maxn 200005
using namespace std;

int cnt[maxn], a[maxn];

int main(int argc, char** argv)
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		scanf("%d", a + i);
		cnt[a[i]] ++;
	}
	long long s = 0;
	for(int i=1; i<=n; i++)
		if(cnt[i] != 0)
			s += cnt[i] * (long long)(cnt[i] - 1) >> 1;
	for(int i=0; i<n; i++)
		printf("%lld\n", s - (cnt[a[i]] - 1));
	return 0;
}

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

int arr[3];
int main(){
  for (int i=0;i<3;i++){
    cin >> arr[i];
  }
  sort(arr,arr+3);
  if (arr[0]+arr[1] == arr[2]){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, k, q;
  cin >> n >> k >> q;

  vi a(q);
  rep(i,q) {
    cin >> a[i];
    a[i]--;
  }

  vi score(n,k-q);
  rep(i,q) {
    score[a[i]]++;
  }

  rep(i,n) {
    printf("%s\n", score[i]>=1?"Yes":"No");
  }
 }

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7;
int n, m;
int mul(int a, int b)
{
	return (1ll * a * b) % MOD;
}

int fact(int num)
{
	int res = 1;
	for(int i = 2; i <= num; ++i)
		res = mul(res, i);
	return res;
}
int numWays()
{
	if(abs(n - m) > 1)
		return 0;
	if(n == m)
		return mul(2ll, mul(fact(n), fact(m)));
	return mul(fact(n), fact(m));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> m;

	cout << numWays() << endl;

	return 0;
}

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


def solve(n, m, a):

    ans = 0
    s = [(a[0], 0)]
    for i in range(1, n):
        ans += (a[i] - a[i - 1]) % m
        s.append((a[i], i))
    s.sort()


    r = [0] * (m + 1)
    c = 0
    t = 0
    active = [0] * n
    j = 0
    while j < n:
        aj, _ = s[j]
        r[aj] += (aj * c - t - c)
        while j < n:
            ai, i = s[j]
            if ai != aj:
                break
            if 0 < i:
                if active[i - 1]:
                    active[i - 1] = 0
                    c -= 1
                    t -= a[i - 1]
            if i < n - 1:
                active[i] = 1
                c += 1
                t += a[i]
            j += 1

    if 0 < c:
        t -= m * c
        j = 0
        while j < n:
            aj, _ = s[j]
            r[aj] += (aj * c - t - c)
            while j < n:
                ai, i = s[j]
                if ai != aj:
                    break
                if 0 < i:
                    if active[i - 1]:
                        active[i - 1] = 0
                        c -= 1
                        t -= a[i - 1] - m
                j += 1
            if c == 0:
                break

    ans -= max(r)

    return ans


def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    a = list(map(int, input().split()))

    print(solve(n, m, a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 22384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		long[] s=sc.La;
		long ans=1;
		if(s[1]>=s[2]-2||s[0]<=s[1]){
			ans+=s[0];
		}
		else{
			s[0]-=s[1]-1;
			ans+=s[1]-1;
			ans+=(s[0]/2)*(s[2]-s[1]);
			ans+=s[0]%2;
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 13268
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
SA=sum(A)
SB=sum(B)
if SA<SB:
    print(-1)
    exit()
ans=0
p=[]
m=[]
for i in range(N):
    a=A[i]-B[i]
    if a>=0:
        p.append(a)
    else:
        m.append(a)
if len(m)==0:
    print(0)
    exit()
M=sum(m)
M=abs(M)
p.sort(reverse=True)
for i in range(len(p)):
    if M<=0:
        break
    ans+=1
    M=M-p[i]
ans+=len(m)
print(ans)

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

int main(){
  int N; cin >> N;
  string S; cin >> S;
  int count=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      count++;
    }
    else count--;
  }
  if(count>0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N=int(input())
AC=0
WA=0
TLE=0
RE=0

for i in range(N):
  S=input()
  if(S=='AC'):
    AC+=1
  elif(S=='WA'):
    WA+=1
  elif(S=='TLE'):
    TLE+=1
  elif(S=='RE'):
    RE+=1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int a[20005];
int main()
{
	int num=0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j])
				{
					num++;
				 } 
			}
		}
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
(defun get-max (n)
  (cond
    ((< n 1) -10000000000)
    (t (let ((x (read)))
	 (max x (get-max (- n 1)))))))
(defun get-min (n)
  (cond
    ((< n 1) 10000000000)
    (t (let ((x (read)))
	 (min x (get-min (- n 1)))))))
(let*
    ((n (read))
     (m (read))
     (x (read))
     (y (read))
     (xmax (max (get-max n) x))
     (ymin (min (get-min m) y)))
  (if (>= xmax ymin)
      (princ "War")
      (princ "No War")))

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

int main(){
  int n,m; cin >> n >> m;
  int p[m];
  char s[m],S[m];
  rep(i,m) cin >> p[i] >> s[i] >> S[i];
  int ans[n+1];
  int neoans[n+1];
  rep(i,n+1){
    ans[i] = 0;
    neoans[i] = 0;
  }
  int cor = 0,wro = 0;
  rep(i,m){
    if(ans[p[i]] == 0 && s[i] == 'A'){
      ans[p[i]] = 1;
    }
  }
  rep(i,m){
    if(neoans[p[i]] == 0 && s[i] == 'A'){
      cor++;
      neoans[p[i]] = 1;
    }
    else if(neoans[p[i]] == 0 && ans[p[i]] == 1 && s[i] == 'W'){
      wro++;
    }
  } 
  cout << cor << " " << wro << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[500005];
ll dp[500006];
int main()
{
    ll n,i,j,k,l,m;
    scanf("%lld%lld",&n,&k);
    for(i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
    	dp[i]=1e9;
	}
	dp[1]=0;
	for(i=2;i<=n;i++){
	   for(j=1;j<=k&&i-j>=1;j++)
	   dp[i]=min(abs(a[i]-a[i-j])+dp[i-j],dp[i]);
	}
	cout<<dp[n];
    return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<algorithm>
#define md 1000000007
#define C(x,y)(1ll*jc[y]*ny[x]%md*ny[(y)-(x)]%md)
using namespace std;
int jc[1000001],ny[1000001];
int pw(int x,int y){
	int ans=1;
	for(int i=1;y;i<<=1,x=1ll*x*x%md)
		if(y&i)ans=1ll*x*ans%md,y-=i;
	return ans;
}
int main(){
	int n,m,k,z;scanf("%d%d%d",&n,&m,&k);z=n+m+k;
	for(int i=jc[0]=1;i<=z;i++)jc[i]=1ll*i*jc[i-1]%md;
	ny[z]=pw(jc[z],md-2);
	for(int i=z;i;i--)ny[i-1]=1ll*i*ny[i]%md;
	int ans=0,o=1;
	for(int i=n;i<=z;i++){
		ans=(ans+C(n-1,i-1)*o%md*pw(3,z-i))%md;
		o=(o+o)%md;
		if(i>=n+m)o=(o-C(m,i-n)+md)%md;
		if(i>=n+k)o=(o-C(i-n-k,i-n)+md)%md;
	}
	printf("%d",ans);
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+2*1e5;
const LL INF=1<<30;
int P[SIZE];
bool solve(){
	int N;
	cin.tie(0);
	VI ans[2];
	cin >> N;
	int def=5*1e8,x;
	int A=def,B=def;
	REP(i,N) {
		cin >> x;
		P[x-1]=i;
	}
	REP(i,N){
		int tar=def*2+P[i];
		if(A+B<tar) A+=tar-B-A;
		else B-=A+B-tar;
		ans[0].PB(A);
		ans[1].PB(B);
		A++;
		B--;

	}
	REP(j,2)
		REP(i,N){
			cout << ans[j][i];
			if(i==N-1) cout << endl;
			else cout << " ";
 
		}
 
}
int main(){
	solve();
	
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  map<int, int> cnt;
  for (int i = 0; i < n; i += 2) {
    cnt[a[i]]++;
  }
  vector<ii> A, B;
  for (auto& it : cnt) {
    A.emplace_back(it.second, it.first);
  }
  sort(A.begin(), A.end(), greater<ii>());
  cnt.clear();
  for (int i = 1; i < n; i += 2) {
    cnt[a[i]]++;
  }
  for (auto& it : cnt) {
    B.emplace_back(it.second, it.first);
  }
  sort(B.begin(), B.end(), greater<ii>());
  int ret = INF;
  if (A[0].second != B[0].second) {
    ret = n - A[0].first - B[0].first;
  } else {
    if (A.size() > 1) {
      ret = min(ret, n - A[1].first - B[0].first);
    } else {
      ret = min(ret, n - B[0].first);
    }
    if (B.size() > 1) {
      ret = min(ret, n - A[0].first - B[1].first);
    } else {
      ret = min(ret, n - A[0].first);
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 4088
#include<bits/stdc++.h>
#define st first
#define nd second


using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 2e3 + 10;
int ans[N] ;

int main(){
	int n, x, y;
	scanf("%d %d %d",&n, &x, &y);
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			if(i <= x){
				if(j <= x) ans[j - i]++;
				else if(j <= y){
					int mi = min(j - i, x - i + y - j + 1);
					ans[mi]++;
				}
				else {
					ans[x - i + j - y + 1]++;
				}
			}
			else if(i <= y){
				if(j <= y){
					int mi = min(i - x + y - j + 1, j - i);
					ans[mi]++;
				}
				else{
					int mi = min(j - i, i - x + j - y + 1);
					ans[mi]++;
				}
			}
			else ans[j - i]++;
		}
	}
	for(int i = 1; i < n; i++){
		printf("%d\n",ans[i]);
	}

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a[10],s[10],d,f,g,z;
	for(g=1;g<=10;g++){
		scanf("%d",&a[g]);
	}
	for(g=1;g<=10;g++){
		scanf("%d",&s[g]);
	}
	for(g=1;g<=10;g++){
		for(f=g+1;f<=10;f++){
			if(a[g]<a[f]){
				d=a[g];
				a[g]=a[f];
				a[f]=d;
			}
			if(s[g]<s[f]){
				z=s[g];
				s[g]=s[f];
				s[f]=z;
			}
		}
	}
	printf("%d %d\n",a[1]+a[2]+a[3],s[1]+s[2]+s[3]);
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

vector<int64_t> get_divisor_list(int64_t n)
{
    vector<int64_t> ret;

    for (int64_t i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

    auto divisor_list = get_divisor_list(n);
    int64_t ret = std::numeric_limits<int64_t>::max();
    for (auto d : divisor_list)
    {
        ret = min(ret, d + n / d - 2);
    }
    cout << ret << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        long res = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] != (i + n % 2) / 2 * 2 + (1 - n % 2)) {
                out.println(0);
                return;
            }
            if (i > 0 && a[i] == a[i - 1]) {
                res = (res * 2) % ((long) (1e9 + 7));
            }
        }
        out.println(res);
    }


    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 22024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(int, N);

    vector<int> index(N + 1);
    vector<int> p(N);

    rep(i, N) {
        input(p[i]);
        index[p[i]] = i;
    }

    multiset<int> S { -1, -1, N, N };
    sort(all(p), greater<>());

    i64 ans = 0;
    for (const int e : p) {
        const auto cur = S.insert(index[e]);
        const i64 leftR = *prev(cur);
        const i64 leftL = *prev(cur, 2);
        const i64 rightL = *next(cur);
        const i64 rightR = *next(cur, 2);
        const i64 l = e * (leftR - leftL) * (rightL - index[e]);
        const i64 r = e * (rightR - rightL) * (index[e] - leftR);
        ans += l + r;
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 5760
def dfs(n):
    table =[]
    i = 2
    while n >= i**2:
        while n % i == 0:
            if i not in table:
                table.append(i)
            n /= i
        i += 1
    if n > 1:
        table.append(int(n))
    return table

A,B = map(int, input().split())

yaku_A = dfs(A)
yaku_B = dfs(B)
count = 1

for i in yaku_A:
  if i in yaku_B:
    count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mp make_pair
#define ss second
#define ff first
#define ll long long int
#define tcase ll t;cin>>t;while(t--)
#define sz(a) int((a).size())
#define pb push_back
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define yes cout<<"yes\n";
#define no cout<<"no\n";
#define f(i,a,b) for(int i=a;i<b;i++)
#define in insert
#define matrix vector<vector<ll> >
#define E cout<<"\n";
#define I(x) cin>>x;
#define O(x) cout<<x;
#define all(a) a.begin(),a.end()
#define vi vector<int>
const ll M=1000000007;
const double pi=3.1415926;

using namespace std;

//ll modexpo(ll a,ll b,ll p)
//{
//    ll ans=1;
//      a=a%p;  // update a if(a>=p)
//
//        if(a==0)
//            return 0;
//
//                while(b!=0)
//                {
//                    if(b%2==1)
//                        ans=(ans*a)%p;
//
//                    a=(a*a)%M;
//                    b=b/2;
//
//                }
//                return ans;
//
//}

//ll countbit(ll n)
//{
//    ll x=0;
//    while(n!=0)
//    {
//        n=n&(n-1);
//
//        x++;
//    }
//    return x;
//}



//  vector<int> prime1;
//  int prime[10000001];
//
//void sieve(int n)
//{
//       for(long long i=2;i<=n;i++)
//       {
//         if(prime[i]==0)
//         {  prime[i]=i;
//            prime1.pb(i);
//         }
//
//            for(long long j=0;j<sz(prime1) && prime1[j]<=prime[i] && i*prime1[j]<=n;j++)
//            {
//
//                   prime[i*prime1[j]]=prime1[j];
//
//
//            }
//
//
//      }
//
// return ;
//}

//ll gcd(ll a,ll b)
//{
//    if(a==0)
//        return b;
//    else
//        return gcd(b%a,a);
//}
//ll lcm(ll a,ll b)
//{
//    return (a*b)/gcd(a,b);
//}

void fastio()
{
       ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

}


int main()
{

     fastio();
         int n;
         cin>>n;
         vi v(n+1);
         for(int i=1;i<=n;i++)
         {
             for(int j=i;j<=n;j+=i)
                v[j]++;
         }

         ll sum=0;
         for(int i=1;i<=n;i++)
         {
             sum+=v[n-i];
         }

          cout<<sum;

    return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n),b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    priority_queue<pair<ll,ll>> pq;
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
        if(b[i]<a[i]){
            std::cout << -1 << std::endl;
            return 0;
        }
        if(b[i]>a[i]){
            pq.push({b[i],i});
        }
    }
    
    ll ans = 0;
    
    while(pq.size()){
        auto [v,i] = pq.top();pq.pop();

        auto sum = b[(i+n-1)%n]+b[(i+n+1)%n];

        if(v > sum){
            if(v%sum>a[i]){
                ans += v/sum;
                v %= sum;
                b[i] = v;
                if(a[i]==b[i])continue;
                pq.push({v,i});
            }else{
                ans += (v-a[i])/sum;
                v -= (v-a[i])/sum*sum;
                b[i] = v;
                if(a[i]==b[i])continue;
                pq.push({v, i});
            }
        }else{
            if(a[i]==b[i])continue;
            std::cout << -1 << std::endl;
            return 0;
        }
    }
    std::cout << ans << std::endl;
}

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

int main(){
  int N;
  cin >> N;
  string S = to_string(N);
  if (S.at(0) == '9' || S.at(1) == '9'){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

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

int main() {
  int H, W;
  scanf("%d %d", &H, &W);
  H *= W;

  int c[10][10];
  for (int i=0; i<10; ++i)
    for (int j=0; j<10; ++j)
      scanf("%d", &c[i][j]);

  for (int k=0; k<10; ++k)
    for (int i=0; i<10; ++i)
      for (int j=0; j<10; ++j)
        c[i][j] = std::min(c[i][j], c[i][k]+c[k][j]);

  int res=0;
  for (int i=0; i<H; ++i) {
    int d;
    scanf("%d", &d);
    if (d == 1 || d == -1)
      continue;

    res += c[d][1];
  }

  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

void solve() {
  static const int MAXN = 2e5 + 3;
  static int a[MAXN];

  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x;
    cin >> x;
    ++a[x];
  }
  for (int i = 1; i <= n; ++i)
    cout << a[i] << "\n";
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int o_o = 1;
  if (!o_o)
    cin >> o_o;
  for (; o_o; --o_o)
    solve();
  return 0;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>inline T read()
{
	T f=1,ans=0;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>inline void write(T x,char y)
{
	if(x==0)
	{
		putchar('0');putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
	#ifndef ONLINE_JUDGE
		freopen("c.in","r",stdin);
		freopen("c.out","w",stdout);
	#endif
}
const int N=1e5+5;
int t[N],x[N],y[N],n;
void input()
{
	int sum,num;
	n=read<int>();
	For(i,1,n)
	{
		t[i]=read<int>();x[i]=read<int>();y[i]=read<int>();
		num=t[i]-t[i-1];
		sum=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		//cout<<sum<<' '<<num<<endl;
		if(num<sum||num%2!=sum%2){puts("No");return;}
	}
	puts("Yes");
}
int main()
{
	//file();
	input();
	return 0;
}

Measured memory_bytes: 1408