akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int s[500000*4+1];
string tar;
void build (int id, int l, int r){
    if (l==r){
        s[id]|=(1<<(tar[l]-'a'));
        return;
    }
    int mid=l+(r-l)/2;
    build (id*2, l, mid);
    build (id*2+1, mid+1, r);
    s[id]=(s[id*2]|s[id*2+1]);
}
void update (int id, int l, int r, int pos, char val){ // REMEMBER: update only to follow one chain
    if (l==r){ //the bottomost nodes of the segment tree
        s[id]=0;
        s[id]|=(1<<(val-'a'));
        return;
    }
    int mid=l+(r-l)/2;
    if (pos<=mid) update (id*2, l, mid, pos, val);
    else update (id*2+1, mid+1, r, pos, val);
    s[id]=(s[id*2]|s[id*2+1]);
}
int query (int id, int l, int r, int L, int R){
    if (L<=l && r<=R) return s[id];
    // above is completely in range case. REMEMBER: query is dividing segment trees parts into different queries
    if (R<l || r<L) return 0;
    //above is completely out of range case. REMEMBER: return something not affecting the result
    int mid=l+(r-l)/2;
    return query (id*2, l, mid, L, R) | query (id*2+1, mid+1, r, L, R);
    //above is partially in range case.
}
int main(){
    int a, q, val, pos, ql, qr;
    char change;
    cin>>a>>tar>>q;
    build (1, 0, a-1);
    for (int t=0; t<q; t++){
        cin>>val;
        if (val==1){
            cin>>pos>>change;
            update(1, 0, a-1, pos-1, change);
        }
        else {
            cin>>ql>>qr;
            cout<<__builtin_popcount(query(1, 0, a-1, ql-1, qr-1))<<endl;
        }
    }
}


Measured memory_bytes: 7044
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
  while(1){
    int t;
    string num;
    cin >> t >> num;
    if(t==0 && num=="0") break;

    int now=0;
    int same_ct=0;
    int small=1000000;
    vector<int> ans;

    //???????????????????????°????????°
    int len = num.size();
    //?????????????????????????????????????????§bitloop
    for(int i=0; i<(1<<(len-1)); ++i){

      int cut=0;
      for(int j=0; j<len-1; ++j){
        if(i>>j & 1) cut++;
      }

      vector<int> s;

      int st=0;
      //printf(" %2d:", i);
      for(int j=0; j<len-1; ++j){
        if(i>>j & 1){
          s.push_back(atoi(num.substr(st,j+1-st).c_str()));
          st=j+1;
        }
      }
      s.push_back(atoi(num.substr(st,len+1-st).c_str()));

      int tmp=0;
      for(int j=0; j<s.size(); ++j) tmp+=s[j];
      //printf("%5d\n", tmp);

      small = min(small, tmp);

      if(t<tmp) continue;
      if(now<tmp){
        ans.resize(s.size());
        for(int j=0; j<s.size(); ++j) ans[j]=s[j];
        now=tmp;
        same_ct=1;
      }
      else if(now==tmp) same_ct++;
    }

    //output
    if(small>t) printf("error\n");
    else if(same_ct>1) printf("rejected\n");
    else{
      printf("%d", now);
      for(int i=0; i<ans.size(); ++i) printf(" %d", ans[i]);
      printf("\n");
    }
  }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> A(N,0);
    REP(i,N) cin >> A[i];

    ll num = 0;

    int r = 0;
    ll ans = 0;
    REP(l,N){
        while(r<N){
            if(num+A[r] == (num^A[r])){
                num += A[r];
                r++;
                ans++;
            }else{
                break;
            }
        }
        num -= A[l];
        ans += r-l;
    }
    ans -= N;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4836
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
 
 
 
using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))
 
 
#define MOD 1000000007
 
typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

ll n,a,b;
ll v[55];

ll dp[55][55];

ll comb(ll n, ll k){//llは実はいらない
	if(dp[n][k]>=1)
		return dp[n][k];
	if(n==k)
		return 1;
	if(k==0)
		return 1;
	return dp[n][k] =  comb(n-1,k-1)+comb(n-1,k);
}

int main() {
	scanf("%lld %lld %lld ",&n,&a,&b);
	rep(i,n){
		rep(j,n){
			dp[i][j]=-1LL;
		}
	}
	rep(i,n){
		scanf("%lld ",&v[i]);
	}
	sort(v,v+n,greater<ll>());

	ll ans=0LL;

	ll sum=0;
	rep(i,a){
		sum+=v[i];
	}
	ll x=0,y=0;
	rep(i,n){
		if(v[i]==v[a-1]){
			x++;
			if(i<a)
				y++;
		}
	}

	cout.precision(7);//
	cout << fixed << (double)sum/(double)a << endl;
	if(v[0]==v[a-1]){
		for(ll i=a; i<= min(b,x); i++)
			ans+=comb(x, i);
		cout << ans << endl;
	}
	else{
		cout << comb(x,y) << endl;
	}
	
	return 0;
}




Measured memory_bytes: 384
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const X = parseInt(arg[0].split(" ")[1]);
    
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    
    for(let i in A) {
        if(A[i] > X) {
            answer += A[i] - X;
            A[i] = X;
        }
    }

    for(let i=0; i<A.length-1; i++) {
        let temp = A[i] + A[parseInt(i) + 1];
        
        if(temp > X) {
            answer += temp - X;
            A[parseInt(i) + 1] -= temp - X;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 33164
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int top,s[1000];
int pop(){
	top--;
	return s[top+1];
}
int push(int a){
	s[++top]=a;
}
int main(){
	int b,a;
	top=0;
	char c[3];
	while(cin>>c){
		if(c[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(c[0]=='-'){
			a=pop();
			b=pop();
			push(b-a);
		}
		else if(c[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}
		else{
			push(atoi(c));
		}
	}
	cout<<pop()<<endl;
	return 0;
}


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

int main(){
    int S;
    cin >> S;
    int h,m,s;
    h=S/3600;
    m=(S-h*3600)/60;
    s=(S-h*3600-m*60);
    cout << h <<":" << m << ":" << s << endl;
}


Measured memory_bytes: 3100
n,w=map(int,input().split())
a=[10**10]*100001
a[0]=0
from copy import copy
c=0
for i in range(n):
    x,y=map(int,input().split())
    b=copy(a)
    c+=y
    for j in range(y,100001):
        if j<=c:
            b[j]=min(a[j-y]+x,a[j])
    a=copy(b)
l=[]
for i in range(len(a)):
    if a[i]<=w:
        l.append(i)
print(l[-1])
        

        


Measured memory_bytes: 76828
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<ll> xy1, xy2;
    for(int i=0; i<N; i++) {
        ll x, y; scanf("%lld%lld", &x, &y);
        xy1.emplace_back(x+y);
        xy2.emplace_back(x-y);
    }
    sort(xy1.begin(), xy1.end());
    sort(xy2.begin(), xy2.end());

    ll d1 = xy1.back() - xy1.front();
    ll d2 = xy2.back() - xy2.front();
    printf("%lld\n", max(d1, d2));
    return 0;
}


Measured memory_bytes: 6660
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    printResult(a, b);
  }

  private static void printResult(int a, int b) {
    if (a == b) {
      System.out.println("a == b");
    } else if (a > b) {
      System.out.println("a > b");
    } else {
      System.out.println("a < b");
    }
  }
}

Measured memory_bytes: 26304
/*
Anki:未済
作成日:①2020/03/14・2020/03/15
*/

#include <stdio.h>

int main(void)
{
    long h, w, result;

    scanf( "%ld %ld", &h, &w );

    if (h == 1 || w == 1)
    {
        printf( "1\n" );
        return 0;
    }
    else if ( h % 2 == 0)
    {
        result = ( h / 2 ) * w;
    }
    else if( w % 2 == 0 )
    {
        result = h * ( w / 2 );
    }
    else
    {
        result = ( h * w ) / 2 + 1;
    }
    
    printf( "%ld\n", result );

    return 0;
}

//たとえば (H, W) = (1, 109) のときを考えてみてください。上の解法では 500000000 が出力されますが、実際は角は全く動けないので答えは 1 となります。このような例外をコーナーケースといいます。

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

int main(){
    string s;
    cin>>s;
    if(s=="SUN"){
        printf("%d",7);
    }else if(s=="MON"){
        printf("%d",6);
    }else if(s=="TUE"){
        printf("%d",5);
    }else if(s=="WED"){
        printf("%d",4);
    }else if(s=="THU"){
        printf("%d",3);
    }else if(s=="FRI"){
        printf("%d",2);
    }else if(s=="SAT"){
        printf("%d",1);
    }
    return 0;
}

Measured memory_bytes: 256
// AOJ Vol3-0392: Party Dress
// 2018.12.25
 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int A, B;

	scanf("%d%d", &A, &B);
	printf("%d\n", 1+(B-1)/A);
	return 0;
}


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

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

	for (int i=0;i<S.size();i++){
		if(int(S.at(i))+N>90){
			cout<<char(S.at(i)+N-26);
		}
		else{
			cout<<char(S.at(i)+N);
		}
	}
	cout<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	s:=nextString()
ans:=700
        for i:=0; i<3; i++ {
    if s[i] =='o'{
ans+=100
}
    }
fmt.Println(ans)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    string s;
    cin >> s;
    rep(i, s.length()){
        // kisuu
        if(i % 2 == 0 && s[i] == 'L'){
            out("No");
            return 0;
        }
        if(i % 2 == 1 && s[i] == 'R'){
            out("No");
            return 0;
        }
    }
    out("Yes");
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int s; cin >> s;
  int sz = 1000000;
  vll a(sz+1);
  REP(i, sz) {
    a[i+1] = a[i] + i + 1;
  }

  vll yaku = {1};
  for(ll i=2;i*i<=s;++i) {
    if(s % i == 0) {
      yaku.push_back(i);
      if(i * i != s) yaku.push_back(s/i);
    }
  }
  yaku.push_back(s);

  map<ll, ll> mp;
  REP(i, SZ(yaku)) {
    ll k = yaku[i];
    ll cnt = 0;
    for(auto it=a.begin();it!=a.end();++it) {
      //if(*it < 100) cout << *it << endl;
      auto it2 = lower_bound(it, a.end(), *it+k);
      if(it2 != a.end() && *it2 == *it + k) {
        cnt++;
      }
    }
    mp[k] = cnt;
  }

  ll ans = 0;
  map<ll, bool> sel;
  for(auto &e: mp) {
    ans += e.second * mp[s/e.first];
  }
  cout << ans << endl;

}


Measured memory_bytes: 10752
S = input()
Q = int(input())

num = 0
mae = ""
usi = ""
for i in range(Q):
    tmp = input().split()

    if tmp[0] == "1":
        num += 1

    elif tmp[0] == "2":
        num = num % 2
        dada = num + int(tmp[1])

        if dada == 2:
            usi += tmp[2]
            # S = S + tmp[2]
            # print("usi: "+usi)
        else:
            mae = tmp[2] + mae
            # S = tmp[2] + S
            # print("mae: "+mae)


if num % 2 == 1:
    S = S[::-1]
    S = usi[::-1] + S + mae[::-1]
else:
    S = mae + S + usi
print(S)

Measured memory_bytes: 4384
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100100];
vector<vector<ll> > vv;

ll f(ll p){
  if(dp[p]!=-1)return dp[p];
  ll ret = 0;
  rep(i,0,vv[p].sz){
    ret = max(ret,f(vv[p][i])+1);
  }
  return dp[p] = ret;
}

int main() {
	ll n,m;
  cin>>n>>m;
  vector<vector<ll> > vv_(n,vector<ll>());
  vv = vv_;
  rep(i,0,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    vv[b].pb(a);
  }
  clr(dp,-1);
  rep(i,0,n){
    f(i);
  }
  ll mx = 0;
  rep(i,0,n){
    mx = max(mx,dp[i]);
  }
  cout << mx << endl;
	return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n==22)cout<<"Christmas Eve Eve Eve";
  if(n==23)cout<<"Christmas Eve Eve";
  if(n==24)cout<<"Christmas Eve";
  if(n==25)cout<<"Christmas";
    return 0;
}

Measured memory_bytes: 256
// --------------------------------------------
// ****************  gzhffIThh  ***************
// --------------------------------------------
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)

#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;


int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);  
 
        int a, b, c;
        cin >> a >> b >> c;

        int cnt = 0;
        while (cnt < 100) {
        	if ((a & 1) || (b & 1) || (c & 1)) break;

        	int f = a / 2; 
        	int l = b / 2;
        	int q = c / 2;

        	a = l + q;
        	b = f + q;
        	c = f + l;

        	cnt++;

        }

        cout << ((cnt == 100) ? -1 : cnt);

        return 0; 
}

Measured memory_bytes: 3564
fun main(args: Array<String>) {
  var range: String? = readLine()
  var param = range!!.split(" ")
  var height: Int = param[0].toInt()
  var width: Int = param[1].toInt()
  var row : String? = ""
  var check = '.'
  var count = Array<Int>(width,{height + width})
  var last = 0
  var oldRow = ""
  for(i in 0 until width){
    oldRow += '.'
  }
  for(i in 0 until height){
    row = readLine()
    for(j in 0 until width){
      if(row!![j] == '#'){
        if(oldRow[j] == '.' ){
          count[j]++
        }
        if(check == '.'){
          last++
        }
      }
      if(last < count[j]){
        count[j] = last
      }
      last = count[j]
      check = row!![j]
    }
    last = height + width
    check = '.'
    oldRow = row!!
  }
  println(count[count.lastIndex].toString())
}

Measured memory_bytes: 37840
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const long long mod=1000003;

long long dp[1010][1010][2];
long long sum[1010][1010][2];
int N,K;

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

long long get(int rot){
	//asm K<N
	long long res=0;
	int all=gcd(N,rot);
	for(int l=1;l<=min(all-1,K);l++){
		long long cur=sum[all-l][all-l][0];
		cur*=l;
		cur%=mod;
		res+=cur;
		res%=mod;
	}
	return (res*2)%mod;
}

long long solve(){
	memset(dp,0,sizeof(dp));
	memset(sum,0,sizeof(sum));
	dp[1][1][0]=1;
	for(int i=1;i<N;i++){
		for(int j=1;j<=min(i,K);j++) for(int k=0;k<=1;k++){
			if(j+1<=K){
				dp[i+1][j+1][k]+=dp[i][j][k];
				dp[i+1][j+1][k]%=mod;
			}
			dp[i+1][1][k^1]+=dp[i][j][k];
			dp[i+1][1][k^1]%=mod;
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++) for(int k=0;k<=1;k++){
			sum[i][j][k]=sum[i][j-1][k]+dp[i][j][k];
			sum[i][j][k]%=mod;
		}
	}
	long long ans=0;
	for(int l=0;l<N;l++){
		ans+=get(l);
		ans%=mod;
	}
	if(K>=N) ans+=N*2;
	while(true){
		if(ans%N==0){
			ans/=N;
			break;
		}else{
			ans+=mod;
		}
	}
	ans%=mod;
	ans+=mod;
	ans%=mod;
	return ans;
}

int main(){
	while(true){
		scanf("%d%d",&N,&K);
		if(N==0&&K==0) break;
		long long ans=solve();
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 32912
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
	
long int sum=0,sq=0,res=0;
int n,a;
cin>>n;
while(n--)
{
	cin>>a;
	sum=sum+a;
	sq=sq+a*a;

}
res=(sum*sum-sq)/2;
cout<<res;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int k,x;
 cin >> k >> x;
 if(k*500>=x) cout << "Yes";
 else cout << "No";
 return 0;
}

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

#define LL long long

const int CN = 110;

int n,k; LL ans = 0,pf,sf,lpf = 1,lsf = 1;
char ch[CN];

LL f(LL x) {return x / 2;}

int main()
{
    cin>>ch; scanf("%d",&k);
    n = strlen(ch);

    pf = 0; while(ch[pf] == ch[pf + 1] && pf < n) pf++,lpf++;
    sf = n - 1; while(ch[sf] == ch[sf - 1] && sf) sf--,lsf++;

    if(pf == n-1) ans = f(1ll * n * k);
    else if(ch[0] != ch[n-1]){
        for(int i=0;i<n;i++){
            int p = i,l = 1;
            while(ch[p] == ch[p + 1]) p++,l++;
            ans += f(l); i = p;
        }
        ans *= k;
    }
    else{
        LL pt = 0;
        for(int i=pf+1;i<sf;i++){
            int p = i,l = 1;
            while(ch[p] == ch[p + 1]) p++,l++;
            pt += f(l); i = p;
        }
        ans = f(lpf) + f(lsf) + 1ll * (k - 1) * f(lpf + lsf) + 1ll * k * pt;
    }

    printf("%lld",ans);

    return 0;
}

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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    long A, B, C, K;
    long sum = 0;

    cin >> A >> B >> C >> K;

    if ( A >= K) {
        cout << K << endl;
        return 0;
    } else {
        sum += A;
        K -= A;
    }

    if ( B >= K) {
        cout << sum << endl;
        return 0;
    } else {
        K -= B;
    }

    if ( C >= K) {
        sum -= K;
        cout << sum << endl;
        return 0;
    } else {
        sum -= C;
        cout << sum << endl;
    }

    return 0;

}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define ll long long
#define pr pair<ll,ll>
#define prr pair<ll, pr> 
using namespace std;
#define make(a,b,c) prr(a, pr(b,c))
const int N = 55;
int c[N], d[N];
int S;
int n,m,s;
vector< prr > g[N];
const long long INF = 1e18;
long long dp[N][2505];   
priority_queue< prr > pq;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> s;
    for(int i=1;i<=m;++i){
        int u,v,a,b;   cin >> u >> v >> a >> b;
        g[u].push_back(make(v,-a,b));
        g[v].push_back(make(u,-a,b));
    }
    for(int i=1;i<=n;++i) {
        cin >> c[i] >> d[i];
        g[i].push_back(make(i,c[i], d[i]));
    }
    S = 50 * n;
    if (s >= S) s = S;
    up(i,1,n) up(j,0,S) dp[i][j] = INF;
    dp[1][s] = 0;
    pq.push(make(0,1,s));
    while (pq.size()){
        prr cur = pq.top(); pq.pop();
        ll coins = cur.second.second, u = cur.second.first, Time = -cur.first;
        if (dp[u][coins] < Time) continue;
        // cout << u << ' ' << coins <<  ' ' << Time << '\n';
        // cout << u << ' ' << coins << ' ' << mTime << '\n';
        for(auto c : g[u]){
            ll v = c.first, nCoins = c.second.first + coins, nTime = Time + c.second.second;
            if (nCoins < 0 || nCoins > S) continue;
            if (dp[v][nCoins] > nTime){
                dp[v][nCoins] = nTime;
                pq.push(make(-nTime, v, nCoins));
            }
        }
    }
    for(int i=2;i<=n;++i){
        long long ans = INF;
        for(int j=0;j<=S;++j) ans = min(ans, dp[i][j]); 
        cout << ans << '\n';
    }

}

Measured memory_bytes: 7364
import sys
sys.setrecursionlimit(500000)

import sys
def input():
    return sys.stdin.readline()[:-1]

H, W = map(int, input().split())
CH, CW = map(int, input().split())
DH, DW = map(int, input().split())
S = [list(input()) for i in range(H)]
 
from collections import deque
 
q = deque([(CH-1, CW-1)])
 
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
warp = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
        (0, -2), (0, -1), (0, 1), (0, 2), 
        (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i][j] = 10**7
S[CH-1][CW-1] = 0

while q:
    h, w = q.popleft()
    for wh, ww in warp:
        if 0 <= h+wh < H and 0 <= w+ww < W and S[h+wh][w+ww] != "#":
            if (wh, ww) in directions:
                if S[h+wh][w+ww] > S[h][w]:
                    S[h+wh][w+ww] = S[h][w]
                    q.appendleft((h+wh, w+ww))
            else:
                if S[h+wh][w+ww] > S[h][w] + 1:
                    S[h+wh][w+ww] = S[h][w] + 1
                    q.append((h+wh, w+ww))

if S[DH-1][DW-1] == 10**7:
    print(-1)
else:
    print(S[DH-1][DW-1])

Measured memory_bytes: 151312
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long  ll;
int main(){
    ll N; cin>>N;
    bool flag=false;
    for(ll i=1;i<=3500;i++){
        for(ll j=1;j<=3500;j++){
            ll A=4*i*j - N*(i+j);
            ll B=N*i*j;
            if(A>0 && B%A==0){
                ll n = B/A;
                cout<<i<<' '<<j<<' '<<n<<endl;
                flag=true;
                break;
            }
        }
        if(flag) break;
    }
    
    return 0;
}


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

using namespace std;

int main() 
{
  int n, ans = 0, d[100];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> d[i];
  
  for(int i = 0; i < n; i++)
  {
    for(int j = i+1; j < n; j++)
      if(d[i] == d[j]) d[j] = 0;
  }
  for(int i = 0; i < n; i++)
    if(d[i] != 0) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

	int n;
	cin >> n;

	vector<vector<int>> values(n, vector<int>(3));

	for(auto &vec : values) {
		for(auto &e : vec) {
			cin >> e;
		}
	}

	vector<int> score(n, 0);
	for(int i = 0; i < 3; ++i) {
		vector<int> cnt(101, 0);
		for(int j = 0; j < n; ++j) {
			++cnt[values[j][i]];
		}

		for(int j = 0; j < n; ++j) {
			if(cnt[values[j][i]] == 1) score[j] += values[j][i];
		}
	}

	for(const auto &e : score) {
		cout << e << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
#include<stdio.h>
int main(){
    int n,i;
    int h[101];
    int ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&h[i]);
    ans+=h[0];
    for(i=1;i<n;i++){
        if(h[i]>h[i-1])ans+=(h[i]-h[i-1]);
    }
    printf("%d\n",ans);
    return 0;
}

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


int n,r,c;
struct Point{
	int x,y,idx;
	int where(void)const{
		if(x==0)
			return 1;
		if(x==r)
			return 3;
		if(y==c)
			return 2;
		if(y==0)
			return 4;
		return 0;
	}
	bool operator<(const Point& rhs)const{
		if(where()!=rhs.where())
			return where()<rhs.where();
		if(where()==1)
			return y<rhs.y;
		if(where()==2)
			return x<rhs.x;
		if(where()==3)
			return y>rhs.y;
		return x>rhs.x;
	}
}p1,p2;
vector<Point> v;
stack<int> st;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>r>>c>>n;
	for(int i=1;i<=n;i++){
		cin>>p1.x>>p1.y>>p2.x>>p2.y;
		p1.idx=p2.idx=i;
		if(p1.where()&&p2.where()){
			v.emplace_back(p1);
			v.emplace_back(p2);
		}
	}
	sort(v.begin(),v.end());
	for(auto it:v){
		if(st.empty())
			st.push(it.idx);
		else if(it.idx==st.top())
			st.pop();
		else st.push(it.idx);
	}
	if(st.empty())
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}
//

Measured memory_bytes: 4340
#include "bits/stdc++.h"
using namespace std;

int mod = 1e9 + 7;

long long exp(long long a, int b) {
	int res{1};
	while (b) {
		if (b&1) res = (res*a)%mod;
		a = (a*a)%mod;
		b /= 2;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	long long ans = (exp(10, n) - 2*exp(9, n) + exp(8, n))%mod;
	cout << (ans + mod)%mod;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/

int main()
{
  ll n;cin>>n;
  ll a[3]={n%10,(n/10)%10,n/100};
  string ans= a[0]==7 || a[1]==7 || a[2]==7 ? "Yes":"No";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    int count = 0;
    for (int i = 0; i < M; ++i)
    {
        int tmp;
        cin >> tmp;
        count += tmp;
    }
    if (N < count)
        cout << "-1\n";
    else
        cout << N - count << "\n";
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
int main(void){
   
   int n;
   string s[55];
   vector<char> ss;
   cin>>n;
   int ans=2374823;
   for(int i=0;i<n;i++)cin>>s[i];
   for(int i=0;i<26;i++){
       char c='a';
       c+=i;
       for(int j=0;j<n;j++){
           int count=0;
           for(int k=0;k<s[j].size();k++){
               if(s[j][k]==c)count++;
           }
           ans=min(ans,count);
       }
       for(int j=0;j<ans;j++)ss.push_back(c);
       ans=2374823;
   }
   for(auto x:ss)cout<<x;
   
   
}


Measured memory_bytes: 256
n = int(input())
a,b = map(int,input().split())
dif = list(map(int,input().split()))
x = 0
y = 0
z = 0
for i in range(n):
  if dif[i]<=a:
    x += 1
  elif dif[i]<=b:
    y += 1
  else:
    z += 1
print(min(x,y,z))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
	IOS;
	int n,m;
	double s=0;
	cin>>n>>m;
	int a[n];
	rep(i,0,n){
	cin>>a[i];s+=a[i];
	}
	s=s/(double)(4*m);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=s)
		ans++;
	}
	if(ans>=m)
	cout<<"Yes";
	else
	cout<<"No";
}


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

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);

      int N, M;
      cin >> N >> M;
      for(int i = M/N;;i--){
          if(M%i==0){
              cout << i << endl;
              ED
          }
      }
}


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

typedef long long lint;

int main(){
    string s;
    lint K;
    cin >> s >> K;
    for(int i=0;i<s.size();i++){
        if(s[i]=='a') continue;
        if('z'-s[i]+1<=K){
            K-='z'-s[i]+1;
            s[i]='a';
        }
    }
    K%=26;
    for(;K>0;K--){
        if(s[s.size()-1]=='z') s[s.size()-1]='a';
        else s[s.size()-1]++;
    }

    cout << s << endl;
    return 0;
}//

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;
const int MN = 1000010;

int N;
ll fac[MN], ifac[MN];
ll inv[MN];

ll nck(int n, int k) {
	if (n < 0 || k < 0 || k > n) {
		return 0;
	}
	return fac[n] * ifac[n-k] % MOD * ifac[k] % MOD;
}

int main() {
	inv[1] = 1;

	for (int i = 2; i < MN; ++i) {
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;	
	}

	fac[0] = ifac[0] = 1;
	for (int i = 1; i < MN; ++i) {
		fac[i] = fac[i-1] * i % MOD;
		ifac[i] = ifac[i-1] * inv[i] % MOD;
	}

	cin >> N;

	ll ret = 0;

	ll la = 0;

	for (int k = 1; k <= N-1; ++k) {
		ll way = nck(k-1, N-1-k) * fac[k] % MOD * fac[N-1-k] % MOD;
		ret = (ret + (way - la + MOD) * k) % MOD;
		la = way;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 23680
def make_path(l,y1,x1,y2,x2):
    current_x = x1
    current_y = y1
    if x2 == x1:
        for i in range(y2-y1):
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
    elif x2 > x1:
        if y1 % 2 == 1:
            for i in range(x2-x1):
                l.append((current_y,current_x,current_y,current_x+1))
                current_x += 1
            for i in range(y2-y1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
        else:
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
            for i in range(x2-x1):
                l.append((current_y,current_x,current_y,current_x+1))
                current_x += 1
            for i in range(y2-y1-1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
    else:
        if y1 % 2 == 1:
            l.append((current_y,current_x,current_y+1,current_x))
            current_y += 1
            for i in range(x1-x2):
                l.append((current_y,current_x,current_y,current_x-1))
                current_x -= 1
            for i in range(y2-y1-1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
        else:
            for i in range(x1-x2):
                l.append((current_y,current_x,current_y,current_x-1))
                current_x -= 1
            for i in range(y2-y1):
                l.append((current_y,current_x,current_y+1,current_x))
                current_y += 1
                
import numpy as np

H,W,*af = map(int, open(0).read().split())
a = np.array(af).reshape(H,W).tolist()
ab = [[x % 2 for x in y] for y in a]
rev = False
found_first = False
ans = []
temp = [0] * 4
x_count = 0
y_count = 0
for y in ab:
    y_count += 1
    if rev == False:
        x_count += 1
        for x in y:
            if x == 1:
                if found_first == False:
                    temp[0] = y_count
                    temp[1] = x_count
                    found_first = True
                else:
                    temp[2] = y_count
                    temp[3] = x_count
                    make_path(ans,*temp)
                    found_first = False
            x_count += 1
        rev = True
    else:
        x_count -= 1
        for x in reversed(y):
            if x == 1:
                if found_first == False:
                    temp[0] = y_count
                    temp[1] = x_count
                    found_first = True
                else:
                    temp[2] = y_count
                    temp[3] = x_count
                    make_path(ans,*temp)
                    found_first = False
            x_count -= 1
        rev = False
print(len(ans))
for x in ans:
    print(*x)

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){

    double A,B,V,W,T;
    cin>>A>>V;
    cin>>B>>W;
    cin>>T;
    if(V<=W){
        cout<<"NO"<<endl;
        return 0;
    }
    if(T < (fabs(B-A))/(V-W)){
        cout<<"NO"<<endl;
        return 0;
    }
        cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll a, b;
        cin >> a >> b;
        char ca = '0' + a;
        char cb = '0' + b;
        string s1(b, ca);
        string s2(a, cb);
        if (s1 < s2) {
                cout << s1 << endl;
        } else {
                cout << s2 << endl;
        }
}

Measured memory_bytes: 3624
//ΔAGC023C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1e6+16;
const int mod = 1e9+7;
int fpow(int x,int y=mod-2){
	if(!y)
		return 1;
	LL z=fpow(x,y>>1);
	z=z*z%mod;
	if(y&1)
		z=z*x%mod;
	return z;
}
int fac[N],inv[N];
int n,f[N];
int main()
{
	int i,x,ans=0;
	cin>>n;
	if(n==2){
		cout<<1;
		return 0;
	}
	if(n==3){
		cout<<4;
		return 0;
	}
	fac[0]=1;
	for(i=1;i<=n;i=i+1)
		fac[i]=(LL)fac[i-1]*i%mod;
	inv[n]=fpow(fac[n]);
	for(i=n;i;i=i-1)
		inv[i-1]=(LL)inv[i]*i%mod;
	n--;
	f[0]=fac[n];
	for(i=1;i<=n-i+1;i=i+1){
		if(i>n-i-1)
			f[i]=0;
		else
			f[i]=(LL)fac[n-i-1]*inv[n-i-i-1]%mod*fac[n-i]%mod;
		x=(f[i-1]-f[i]+mod)%mod;
		ans+=(LL)x*(n-i+1)%mod;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11904
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    string s,t;
    cin>> s>> t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3920
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int num[4], a;

int main() {
    rep(i, 6) {
        cin >> a;
        num[a-1]++;
    }
    string ans = "YES";
    rep(i, 4) if (num[i] > 2) ans = "NO";
    cout << ans << endl;
}

Measured memory_bytes: 256
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc140a(N int){
	fmt.Println(N*N*N)
}
 
func main(){
	x := 0
	fmt.Scan(&x)
	abc140a(x)
}

Measured memory_bytes: 640
/* 

	CODE TEMPLATE APRATIM

*/

#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define veci vector<ll>
#define it map<string, vv>::iterator
#define MOD 1000000007
#define N (ll)3e+5
#define test int T;cin>>T;while(T--)
#define nl "\n"
#define FULL(iii) iii.begin(),iii.end()
#define setbit(_) __builtin_popcount(_)
#define INF 9223372036854775807 
#define TOUPR(str) transform(str.begin(), str.end(),str.begin(), ::toupper)
#define TOLWR(str) transform(str.begin(), str.end(),str.begin(), ::tolower)
#define pb push_back
#define len(s) s.length()
#define pb push_back
#define eb emplace_back
#define S second
#define F first
#define len(s) s.length()
#define coutp cout<<setprecision(15)
#define pow(a,b) (ll)(pow(a,b)+0.5)
#define bin(x) stoull(x,0,2)
#define lld long double
#define yy cout<<"Yes"<<nl;
#define nn cout<<"No"<<nl;
class Graph
{
	private:
	map<ll,veci>m;
	public:
	void edges(ll source, ll destination)
	{
		m[source].pb(destination);
		m[destination].pb(source);
	}
	vector<ll> BFS(ll s)
	{
		queue<ll> q;
		map<ll,ll>vis;
		veci x;
		vis[s]=1;
		q.push(s);
		while(!q.empty())
		{
			s=q.front();x.pb(s);
			q.pop();
			for(auto node:m[s])
			{
				if(!vis[node])
				vis[node]=1,q.push(node);
			}
		}
		return x;
		
	}
	
};
ll powi(ll a,ll b)
{
	if(b==0) return (ll)1;
	if(b==1) return a;
	else if(b%2) return a*powi(a,b-1);
	else return powi(a*a,b/2);
}
ll b(vector<ll>a,ll n)
{
	ll l=0,r=n-1;
	while(l<=r)
	{
		int m = r-(r-l)/2;
		if(a[m]==0)
			l = m+1;
		else{
			if(a[m-1]==0 || m==0) return m;
			else r = m-1;
		}
	}
	return -1;
}
int main() {	
	fio;
	
	//test
	int x;cin>>x;
	cout<<(!x);
	
}
	
/*

4
1 2 4 7

7
1 2 4 8 10 12 6


7
1 2 3 4 5 6 8

*/




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

const double PI = 3.141592653589;

void solve_abc_a() {
	ll s, w;
	//float ans;
	string ans = "No";

	cin >> s >> w;
	if (w >= s) {
		ans = "unsafe";
	}
	else {
		ans = "safe";
	}

	cout << ans;

	return;
}

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

	solve_abc_a();

	return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	long long int a, b,k;
	cin >> a >> b >> k;
	if (a >= k)
	{
		a = a - k;
		k = 0;
	}
	else
	{
		k = k - a;
		a = 0;
		
	}
	b = b - k;
	if (b <= 0)
		b = 0;
	cout << a <<" "<< b<<endl;
}

Measured memory_bytes: 3580
def parm(a):
    return(int(a*(a-1)/2))

n=int(input())
a=list(input().split())
dic={}
ans=[0]*n
sumans=0
for i in range(n):
    if a[i] in dic.keys():
        dic[a[i]]+=1
    else:
        dic[a[i]]=1
for i in dic.values():
    sumans+=parm(i)
for i in range(n):
    print(sumans-parm(dic[a[i]])+parm(dic[a[i]]-1))

Measured memory_bytes: 28196
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        List<Integer> list = new ArrayList<>();

        for (int i = 1; i <= Math.max(a, b); i++) {
            if (a % i == 0 && b % i == 0) {
                list.add(i);
            }
        }
        System.out.println(list.get(list.size() - k));
    }
}


Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
const ll M =1000000007;
const int N = 10000003;
using namespace std;
const int mod = 1000000007;

ll prime[N];
unordered_map<ll, ll> max_map;
ll power(ll a, ll n)
{
	if (n == 0)
		return 1;
	ll p = power(a, n / 2) % mod;
	p = (p * p) % mod;
	if (n & 1)
		p = (p * a) % mod;
	return p;
}
void sieve()
{
	prime[0] = prime[1] = 1;
	for (ll i = 2; i < N; i++) {
		if (prime[i] == 0) {
			for (ll j = i * 2; j < N; j += i) {
				if (prime[j] == 0) {
					prime[j] = i;
				}
			}
			prime[i] = i;
		}
	}
}
ll lcmModuloM(vector<ll>ar, ll n)
{
	for (ll i = 0; i < n; i++) {
		ll num = ar[i];
		unordered_map<ll, ll> temp;
		while (num > 1) {
			ll factor = prime[num];
			temp[factor]++;
			num /= factor;
		}
		for (auto it : temp) {
			max_map[it.first] = max(max_map[it.first], it.second);
		}
	}
	ll ans = 1;
	for (auto it : max_map) {
		ans = (ans * power(it.first, it.second)) % mod;
	}
	return ans;
}

int main()
{
	Amr_Abdelazim
		ll n;
	cin >> n;
	sieve();
	vector<ll>v(n);
	for (int i = 0;i < n; i++)cin >> v[i];
	ll lcm = v[0];
	lcm = lcmModuloM(v, n);
	ll ans = 0;
	for (auto i : v){
		ll a = (lcm *power(i, M-2))%M;
		ans = (ans%M + a%M) % M;
	}
	cout << ans<< "\n";
		return 0;
}

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

int main( void )
{
  int N;
  int befor = 0;
  int count = 0;
  
  cin >> N;

  vector<int> d( N );
  
  for( int i = 0; i < N; i++ )
    cin >> d.at( i );

  sort( d.begin(), d.end(), greater<int>() );

  for( int i = 0; i < N; i++ ) {
    if( d.at( i ) != befor ) {
      count++;
    }
    befor = d.at( i );
  }
  if( count == 0 )
    count++;
  
  cout << count << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[100];
	bool gg = false;
	int manji, nk[26] = {false};
	cin >> a>>b>>c;
	f = a %b;
	g = f;
	for (int i = 0; i<100; i++) {
		g += f;
		if (g >= b) {
			g -= b;
		}
		if (g == c) {
			cout << "YES" << endl;
			return 0;
		}
		if (g == f) {
			cout << "NO" << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256