akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, m;
    map<string, int> s;
    map<string, int> t;
    set<string> k;

    cin >> n;
    REP(i, n) {
        string tmp;
        cin >> tmp;
        if (s.find(tmp) == s.end()) {
            s[tmp] = 1;
        } else {
            s[tmp]++;
        }
        k.insert(tmp);
    }

    cin >> m;
    REP(i, m) {
        string tmp;
        cin >> tmp;
        if (t.find(tmp) == t.end()) {
            t[tmp] = 1;
        } else {
            t[tmp]++;
        }
        k.insert(tmp);
    }

    int mx = 0;
    for (string keyword:k) {
        int sc = 0;
        int tc = 0;
        if (s.find(keyword) != s.end()) {
            sc = s[keyword];
        }
        if (t.find(keyword) != t.end()) {
            tc = t[keyword];
        }
        mx = max(mx, sc - tc);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1e9 + 7;
const int MAXN = 5555;
char s[MAXN];
ll f[MAXN][MAXN];

int main(){
	int n;
	scanf("%d%s", &n, s);
	int l  =strlen(s);
	f[0][0] = 1;
	for(int i = 1; i <= n; i++){
		f[i][0] = (f[i-1][0] + f[i-1][1] * 2) % MM;
		for(int j = 1; j <= n; j++)
			f[i][j] = (f[i-1][j-1] + f[i-1][j+1] * 2) % MM;
	}
	cout<<f[n][l]<<endl;
	return 0;
} 

Measured memory_bytes: 215552
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
	int N, M;
	cin >> N >> M;

	vector<int>oks(N + 1, true);
	for (int i = 0; i < M; i++) {
		int a;cin >> a;
		oks[a] = false;
	}

	vector<long long int>dp(N + 1);
	dp[0] = 1;
	for (int now = 0; now < N; now++) {
		for (int next = now + 1; next <= min(N, now + 2); next++) {
			if (oks[next]) {
				dp[next] += dp[now];
				dp[next] %= mod;
			}
		}
	}

	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 1408
from math import sqrt
cx,cy,r = map(int,input().split())
c = [cx, cy]
q = int(input())

class Line:pass

def dot(a, b):
    return sum([i * j for i,j in zip(a, b)])
def add(a,b):
    return [a[0] + b[0],a[1] + b[1]]
def sub(a, b):
    return [a[0] - b[0],a[1] - b[1]]
def multi(k, a):
    return [k*a[0],k*a[1]]
def cross(a, b):
    return  a[0] * b[1] - a[1] * b[0]
def norm(a):
    return sqrt(a[0] ** 2 + a[1] ** 2)    
def proj(p, l):
    base = sub(l.p2, l.p1)
    hypo = sub(p, l.p1)
    t = dot(hypo,base) / norm(base)
    return add(l.p1, multi(t/norm(base), base))
    
for i in range(q):
    x1,y1,x2,y2 = map(int, input().split())
    l = Line()
    l.p1 = [x1,y1]
    l.p2 = [x2,y2]
    pr = proj(c, l)
    e = multi(1/norm(sub(l.p2, l.p1)),sub(l.p2, l.p1))
    e2 = multi(-1, e)
    base = sqrt(r**2 - norm(sub(pr,c))**2)
    a = add(pr, multi(base, e))
    b = add(pr, multi(base, e2))
    ans = [a,b]
    ans = sorted(ans, key=lambda x: (x[0],x[1]))
    print(' '.join([str(round(i,8)) for o in ans for i in o]))

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

using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<ll> res;

void dfs(int v, int p, ll c){
    res[v] = c;
    for(auto e:G[v]){
        if(e.first == p) continue;
        if(e.second%2==0)dfs(e.first,v,c);
        else dfs(e.first,v,1-c);
    }
}


int main(void){
    
    int N;
    cin >> N;
    G.assign(N,vector<Edge>());
    
    int u,v;
    ll w;
    for(int i = 0; i < N-1;i++){
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(Edge(v,w));
        G[v].push_back(Edge(u,w));
    
    }
    res.assign(N,0);
    dfs(0,-1,1);
    for(auto v:res) cout << v <<endl;
}

Measured memory_bytes: 10752
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(A*B, C*D);
}


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

const int N = 5005;
int n, a[N], b[N];
char s[N], t[N];

int main() {
	scanf("%d%s%s", &n, s + 1, t + 1);
	for (int i = 1; i < n; ++i) if (s[i] != s[i + 1]) a[++a[0]] = i;
	for (int i = 1; i < n; ++i) if (t[i] != t[i + 1]) b[++b[0]] = i;
	int ans = 1 << 30;
	for (int i = -a[0] - 1; i <= b[0] + 1; ++i)
		if ((i & 1) ^ (s[1] == t[1])) {
			int s = 0;
			for (int j = min(1, 1 - i); j <= max(a[0], b[0] - i); ++j)
				s += abs((j <= 0 ? 0 : j > a[0] ? n : a[j]) - (j + i <= 0 ? 0 : j + i > b[0] ? n : b[i + j]));
			ans = min(ans, s);
		}
	printf("%d\n", ans);
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, tmp;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        while (tmp % 2 == 0)
        {
            ans++, tmp /= 2;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,t,x,s;
    scanf("%d %d",&n,&q);
    stack<int>v[n];
    for(int i=0;i<q;i++)
    {
        cin>>s;
        if(s==0)
        {
            cin>>t;
            cin>>x;
            v[t].push(x);
        }
        else if(s==1)
        {
            cin>>t;
            if(v[t].size()!=0){
            cout<<v[t].top()<<endl;}
        }
        else if(s==2)
        {
            cin>>t;
            if(v[t].size()!=0){
            v[t].pop();}
        }
    }
    return 0;
}



Measured memory_bytes: 4404
#include <stdio.h>

int main(void) {
	int num,i;

	scanf("%d", &num);

	int member[num];

	for (i = 0; i < num; i++) {
		scanf("%d", &member[i]);
	}

	i = i - 1;
	for (i; i > -1; i--) {
		if (i != (num-1))printf(" ");
		printf("%d", member[i]);
	}

	printf("\n");
	return 0;
}


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

using int64 = long long;

using vint = vector<int>;

constexpr int INF = (1 << 30) - 1;
constexpr int64 INF64 = (1ll << 60) - 1;

#define rep(i, N) for(int i=0;i<(int)(N);++i)
#define fs first
#define sc second
#define e_b emplace_back
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& m) {
	os << "{" << endl;
	for (auto& e : m) os << "(" << e.first << ", " << e.second << ")" << endl;
	return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
	os << "{" << endl;
	for (auto& e : s) os << ", " << e << endl;
	return os << "}";
}

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int64 gcd(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	int64 r;
	while ((r = y % x) != 0) {
		y = x;
		x = r;
	}
	return x;
}
int64 lcm(int64 x, int64 y) {
	if (x == 0 || y == 0) return 0;
	return x / gcd(x, y) * y;
}

// int dx[] = { -1, 0, 1, 0 };
// int dy[] = { 0, 1, 0, -1 };

void Main();
signed main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	Main();
}


/*----------------------------Insert from here!----------------------------*/



/*----------------------------Insert above here----------------------------*/


void Main() {
	int H, W; cin >> H >> W;
	vector<string> c(H);
	rep(i, H) cin >> c[i];

	using P = pair<int64, int64>;
	vector<P> v(W, P(INF, -INF));
	rep(j, W) rep(i, H) {
		if (c[i][j] == 'B') {
			v[j].fs = min(v[j].fs, (int64)i);
			v[j].sc = max(v[j].sc, (int64)i);
		}
	}
	int64 ans = 0;
	for(int64 j=0; j<W; ++j) {
		if (v[j].fs == INF || v[j].sc == -INF) continue;
		int64 n1 = 0, n2 = 0;
		for (int64 k = j; k < W; ++k) {
			if (v[k].fs == INF || v[k].sc == -INF) continue;
			else {
				n1 = max(n1, (k - j) + max(abs(v[k].fs - v[j].fs), abs(v[k].sc - v[j].fs)));
				n2 = max(n2, (k - j) + max(abs(v[k].fs - v[j].sc), abs(v[k].sc - v[j].sc)));
			}
		}
		ans = max({ ans, n1, n2 });
	}

	cout << ans << endl;
}



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

int main() {
    int i, n, k, rewrite, a=0, c=0, b[210000], d[210000];
    cin >> n >> k;
    while(cin >> i) {
        if(b[i] == 0) {
            c++;
            d[1]++;
        } else {
            d[b[i]]--;
            d[b[i]+1]++;
        }
        b[i]++;
    }

    /*
    for(i=0; i<=n; i++) cout << b[i] << " ";
    cout << endl;
    for(i=0; i<=n; i++) cout << d[i] << " ";
    cout << endl;
    */
    
    rewrite = c-k;
    for(i=1; i<=n; i++) {
        while(d[i]!=0) {
            if(rewrite<=0) {
                cout << a << endl;
                return 0;
            }
            a+=i;
            d[i]--;
            rewrite--;
        }
    }
}

Measured memory_bytes: 1024
#include <iostream>

int main(){
  int A, B;
  std::cin>>A>>B;
  if((A % 2 == 1) && (B % 2 == 1)){
    std::cout<<"Yes"<<std::endl;
  }else{
    std::cout<<"No"<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
DP=[0]*N
DP[1] = abs(H[1]-H[0])
for i in range(2,N):
    DP[i] = min(DP[i-1]+abs(H[i]-H[i-1]), DP[i-2]+abs(H[i]-H[i-2]))
print(DP[N-1])
    


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

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

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);

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

int IT_MAX = 1 << 18;
const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 1234567890123456789ll;
const db PI = acos(-1);
const db EPS = 1e-8;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)

int in[100005];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		if (t % 4 == 0) in[i] = 2;
		else if (t % 2 == 0) in[i] = 1;
	}
	int c[3] = { 0,0,0 };
	for (i = 1; i <= N; i++) c[in[i]]++;

	if (c[0] <= c[2]) printf("Yes\n");
	else if (c[0] >= c[2] + 2) printf("No\n");
	else if (c[1] == 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define F first
#define S second
int main(){

    ll N ;
    cin >>N ;
    ll a[N] ;
    for(int i=0;i<N;i++) cin >>a[i] ;
    sort(a,a+N) ;
    cout<<a[N-1]-a[0]<<endl;
    return 0 ;

}


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

int main()
{
	priority_queue< int,vector<int>,less<int> > que;
	int in;

	for(int i = 0; i < 10; i++){
		cin >> in;
		que.push(in);
	}


	for(int j = 0; j < 3; j++){
		cout << que.top() << '\n';
		que.pop();
	}

	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,res=0,waru=2,kake=1,tmp;
string S;

int main(){
    cin>>N;
    if(N==0){
        out("0");
        return 0;
    }
    while(N!=0){
        if(N%waru<0)tmp=N%waru+waru;
        else tmp=N%waru;
        if(tmp==0){
            S+="0";
            kake*=-2;
        }
        else{
            S+="1";
            res+=abs(kake);
            N-=kake;
            kake*=-2;
        }
        waru*=2;
    }
    reverse(S.begin(),S.end());
    out(S);
}


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

typedef long long ll;

int main() {
  int A,B; cin >> A >> B;
  if ( A >= 13 ) {
    cout << B << endl;
  } else if ( A >= 6 && A <= 12 ) {
    cout << B/2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e5 + 10;
const int  maxm = 300;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//next_permutation
int main()
{
        //freopen("in.txt", "r", stdin);
        ll now;
        ll n, m;
        cin >> n >> m;
        ll ans = m * 1900 + (n - m) * 100;
        for (ll i = 1; i <= m; i++)
        {
                ans *= 2;
        }
        cout << ans << endl;
}


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

int main() {
  ll l = 0 ;
  ll r = 0 ;

  constexpr ll waru = 2019 ;

  cin >> l >> r ;

  ll minValue = 10e10 ;
  for ( ll i = l ; i < r ; ++i ) {
    for ( ll j = i+1 ; j <= r ; ++j ) {
      ll current = ( ( i%waru ) * (j%waru) ) %waru ;
      if ( minValue == 0 ) {
        cout << minValue ;
        return 0;
      }
      if ( current < minValue ) minValue = current ;
    }
  }
  cout << minValue ;

  return 0 ;
}



Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

abcd = raw_input()
abcd = abcd.split()
abcd = map(int,abcd)

if abcd[0] >= abcd[3]:
    print 0
elif abcd[2] >= abcd[1]:
    print 0
elif abcd[0] < abcd[2]:
    if abcd[1] < abcd[3]:
        print abcd[1] - abcd[2]
    else:
        print abcd[3] - abcd[2]
else:
    if abcd[1] > abcd[3]:
        print abcd[3] - abcd[0]
    else:
        print abcd[1] - abcd[0]


Measured memory_bytes: 2568
def main():
    MinNum, MaxNum, Scale = map(int, input().split())
    PrintList = []
    for i in range(Scale):
        if((MinNum + i) > MaxNum):
            break
        PrintList.append(MinNum + i)
        
    for i in range(Scale-1, -1, -1):
        if((MaxNum - i) < MinNum):
            break
        PrintList.append(MaxNum - i)
    
    PrintList_uniq = sorted(list(set(PrintList)))
    for num in PrintList_uniq:
        print(num)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

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

    li n, k;
    cin >> n >> k;

    li sqrtn;
    for (li i = 0; i * i <= n; ++i) {
        sqrtn = i;
    }

    vector<li> ub, upperub;
    for (int i = 0; i < sqrtn; ++i) {
        ub.push_back(i + 1);
        upperub.push_back(n / (i + 1));
    }
    sort(upperub.begin(), upperub.end());
    ub.insert(ub.end(), upperub.begin(), upperub.end());

    const li m = ub.size();
    vector<vector<li>> dp(k + 1, vector<li>(m));
    dp[0][0] = 1;
    for (int i = 0; i < k; ++i) {
        li accum = 0;
        for (int j = 0; j < m; ++j) {
            accum += dp[i][j];
            accum %= mod;
            li revj = m - 1 - j;
            li size = revj ? ub[revj] - ub[revj - 1] : ub[revj];
            dp[i + 1][revj] = accum * size % mod;
        }
    }

    li ans = 0;
    for (int i = 0; i < m; ++i) {
        ans += dp[k][i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51844
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

struct Edge {
	int from, to;
	ll cost;
	Edge(int a, int b, ll c) { from = a, to = b, cost = c; }
};

int N, M;
vector<Edge> E;

ll d[1000];

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		E.push_back(Edge(a, b, c));
	}

	d[0] = 0;
	for (int i = 1; i < N; i++)d[i] = -1e18;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < E.size(); j++) {
			Edge e = E[j];
			if (d[e.from] + e.cost > d[e.to]){
				d[e.to] = d[e.from] + e.cost;
				if (i == N - 1 && e.to == N - 1) {
					cout << "inf" << endl;
					return 0;
				}
			}
		}
	}
	ll ans = 0;
	cout << d[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i != 0)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

// 入力されたint配列を昇順にソートする
void InsertationSort(int A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        int tg = A[i];
        int j = i - 1;
        // 配列の左側はソートされているので、tgをソート済みの右側から調べる
        while (j >= 0 && tg < A[j])
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = tg;
        trace(A, N);
    }
}

int main()
{
    int N;
    int A[100];
    // 入力を第一位引数のフォーマットとして受け取る
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    InsertationSort(A, N);
    return 0;
}



Measured memory_bytes: 2712
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0;
    cin>>n;
    string s;
    map<string,ll>mp;
    for(ll i=0;i<n;++i){
        cin>>s;
        sort(s.begin(),s.end());
        ++mp[s];
    }
    ll ans=0;
    for(auto i:mp){
        if(i.S>1){
            ll a=i.S;
            ans+=a*(a-1)/2;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 11416
#include<iostream>
#include<algorithm>
using namespace std;
// aaa
void trace(int A[],int N){

    for(int i=0; i < N; i++){
        if( i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl ;

}

void insertionSort(int A[],int N){
    int v,j,i;
    for(int i = 1; i < N; i++){
        v = A[i];
        j = i-1;

        while( j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
            
        }
        A[j+1] = v;
        trace(A,N);
    }

}
int main(){
    int A[100],N;

    cin >> N;
    for(int i=0; i < N; i++) cin >> A[i];
    trace(A,N);
    insertionSort(A,N);

    return 0;

}





Measured memory_bytes: 3100
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
      	String s = scanner.next();
 	    char c = s.charAt(0);
        System.out.println(Character.isUpperCase(c) ? 'A' : 'a');
    }
}

Measured memory_bytes: 35740
import sys
sys.setrecursionlimit(100000)

N = int(input())
a = [int(input()) for _ in range(N)]
c = [0] * N

def f(i, n):
  if a[n] == 2: return i
  if c[n] == 1: return -1
  c[n] = 1
  return f(i + 1, a[n] - 1)

print(f(1, 0))


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k, n;
    cin >> k >> n;

    vector<int> a(n * 2);
    for (int i = 0; i < n; i++){
        cin >> a[i];
        a[i + n] = k + a[i];
    }

    int ans = INT_MAX;
    for (int i = 0; i < n; i++)
        ans = min(ans, a[i + n - 1] - a[i]);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1792
s = input()
s=s[::-1]
i=0
ans="YES"
while True:
    if len(s)==i:
        break
    elif s[i:i+5]=="maerd":
        i+=5
    elif s[i:i+7]=="remaerd":
        i+=7
    elif s[i:i+5]=='esare':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    else:
        ans="NO"
        break
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	bool series = false;
	rep(i, n) {
		if(s[i] == s[0]) {
			series = false;
		}
		else if(!series && k >= 1) {
			series = true;
			k--;
			s[i] = s[0];
		}
		else if(series) {
			s[i] = s[0];
		}
	}
	int ans = 0;
	rep(i, n) {
		if(i < n - 1 && s[i] == 'R' && s[i + 1] == 'R') ans++;
		if(i > 0 && s[i - 1] == 'L' && s[i] == 'L') ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MAXN=105,INF=1e15;
struct Maxflow{
	struct edge{
		int to;ll cap,flow;int rev;
	};
	vector<edge> G[MAXN];
	int dis[MAXN],cur[MAXN],s,t;
	ll dfs(int u,ll cap){
		if(u==t||!cap) return cap;
		for(int &i=cur[u];i<G[u].size();++i){
			edge &e=G[u][i];
			if(dis[e.to]==dis[u]+1&&e.cap!=e.flow){
				ll df=dfs(e.to,min(cap,e.cap-e.flow));
				if(df){
					e.flow+=df,G[e.to][e.rev].flow-=df;
					return df;
				}
			}
		} 
		dis[u]=-1;
		return 0;
	}
	bool bfs(){
		MEM(dis,-1);
		queue<int> q;
		q.push(s),dis[s]=0;
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(auto e:G[u])
				if(!~dis[e.to]&&e.flow!=e.cap)
					q.push(e.to),dis[e.to]=dis[u]+1;
		}
		return dis[t]!=-1;
	}
	ll maxflow(int _s,int _t){
		s=_s,t=_t;
		ll flow=0,df;
		while(bfs()){
			MEM(cur,0);
			while(df=dfs(s,INF)) flow+=df;
		}
		return flow;
	}
	void init(int n){
		for(int i=0;i<n;++i) G[i].clear();
	}
	void add_edge(int a,int b,ll cap){
		G[a].pb(edge{b,cap,0,G[b].size()});
		G[b].pb(edge{a,0,0,G[a].size()-1});
	}
}Dinic;

int main()
{jizz
	int n;
	ll x,s=0;
	cin >> n,Dinic.init(n+2);
	for(int i=1;i<=n;++i)
		if(cin >> x,x<=0) Dinic.add_edge(0,i,-x);
		else Dinic.add_edge(i,n+1,x),s+=x;
	for(int i=1;i<=n;++i)
		for(int j=i+i;j<=n;j+=i)
			Dinic.add_edge(i,j,INF);
	cout << s-Dinic.maxflow(0,n+1) << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ls x<<1
#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+100;
map<string,int>mp;
int cnt;
void solve(){
	int s,w;
	scdd(s,w);
	if(w>=s)printf("unsafe");
	else printf("safe");
}
int main(){
    //IOS;
    //freopen("fenwick.in","r",stdin);
    //freopen("fenwick.out","w",stdout);
    solve();
    
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;                                             ;;
	;;         ;;            ;;;;;;;;;       ;;    ;;
	;;        ;; ;;        ;;                ;;    ;;
	;;       ;;   ;;       ;;                ;;    ;;
	;;      ;;;;;;;;;      ;;                ;;    ;;
	;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    return 0;
}

Measured memory_bytes: 3228
def judge(As):
    print('?', *[A + 1 for A in As])
    res = input()
    if res == '-1':
        exit()
    return res[0]
N = int(input())
N2 = N + N
L, R = 0, N
fL = judge(range(L, L + N))
fR = 'B' if fL == 'R' else 'R'
while R - L > 1:
    mid = (L + R) // 2
    fM = judge(range(mid, mid + N))
    if fM == fL:
        L = mid
    else:
        R = mid
res = [''] * N2
res[L] = fL
res[L + N] = fR
T1s = set(range(L + 1, L + N))
T2s = set(range(L)) | set(range(L + N + 1, N2))
for i in range(N2):
    if i == L or i == L + N:
        continue
    if i in T1s:
        res[i] = judge(T2s | {i})
    else:
        res[i] = judge(T1s | {i})
print('!', ''.join(res))

Measured memory_bytes: 3532
// A - Grouping
#include <bits/stdc++.h>
using namespace std;

int main(){
	int x,y; cin>>x>>y;

	int x_group = 0;
	int y_group = 0;

	if(x%2) x_group = x<9? 1: 2;
	else{
		x_group = x<8? 2:1;
		if(x==2) x_group++;
	}

	if(y%2) y_group = y<9? 1: 2;
	else{
		y_group = y<8? 2:1;
		if(y==2) y_group++;
	}
	puts(x_group == y_group? "Yes":"No");

}

Measured memory_bytes: 256
/*input
60 3
5 8
1 3
10 15
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll dp[maxn];
ll pref[maxn];
int l[maxn],r[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,k;
    cin>>n>>k;
    REP(i,k) cin>>l[i]>>r[i];
    dp[1]=1;
    pref[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=0;
        REP(j,k){
            if(i-l[j]<=0) continue;
            dp[i]+=pref[i-l[j]]-pref[max(i-r[j]-1,0)];
            dp[i]%=MOD;
            dp[i]+=MOD;
            dp[i]%=MOD;
        }
        pref[i]=pref[i-1]+dp[i];
        pref[i]%=MOD;
    }
    cout<<dp[n]<<'\n';
}  


Measured memory_bytes: 6792
#include <iostream>
#include <queue>
#include <set>
using namespace std;

class Node {
public:
  int tx, ty;
  int kx, ky;
  int time;
  Node(int tx = 0, int ty = 0, int kx = 0, int ky = 0, int time = 0):
    tx(tx), ty(ty), kx(kx), ky(ky), time(time) {}

  bool operator <(const Node &n) const {
    if(tx != n.tx) return tx < n.tx;
    if(ty != n.ty) return ty < n.ty;
    if(kx != n.kx) return kx < n.kx;
    if(ky != n.ky) return ky < n.ky;
    return false;
  }
};

int main() {
  while(1) {
    int X, Y;
    cin >> X >> Y;
    if(X == 0 && Y == 0) break;
    int tx, ty;
    cin >> tx >> ty;
    int kx, ky;
    cin >> kx >> ky;
    int data[Y][X];
    for(int i = 0; i < Y; i++) {
      for(int j = 0; j < X; j++) {
	cin >> data[i][j];
      }
    }
    queue<Node> Q;
    set<Node> visited;
    Q.push(Node(tx-1, ty-1, kx-1, ky-1, 0));
    int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
    int ans = -1;
    while(!Q.empty()) {
      Node n = Q.front();
      Q.pop();
      if(visited.find(n) != visited.end()) continue;
      visited.insert(n);
      if(n.tx == n.kx && n.ty == n.ky) {
	ans = n.time;
	break;
      }
      for(int i = 0; i < 4; i++) {
	int ntx = n.tx + d[i][0];
	int nty = n.ty + d[i][1];
	if(ntx < 0 || ntx >= X) ntx = n.tx;
	if(nty < 0 || nty >= Y) nty = n.ty;
	if(data[nty][ntx] == 1) {
	  ntx = n.tx;
	  nty = n.ty;
	}
	int nkx = n.kx - d[i][0];
	int nky = n.ky - d[i][1];
	if(nkx < 0 || nkx >= X) nkx = n.kx;
	if(nky < 0 || nky >= Y) nky = n.ky;
	if(data[nky][nkx] == 1) {
	  nkx = n.kx;
	  nky = n.ky;
	}
	if(visited.find(Node(ntx, nty, nkx, nky, n.time+1)) == visited.end())
	  Q.push(Node(ntx, nty, nkx, nky, n.time+1));
      }
    }
    if(ans == -1) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;
const ll mod = 1e9+7;

int n,m,k;
set<int> s[3], se[maxn], mid;

int xx[maxn], yy[maxn], len=0, cnt[maxn];
int main()
{
    cin>>n;
    cout<<n*n*3<<"\n";
    return 0;
}


Measured memory_bytes: 9984
import sys

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, K = mi()
    ans = 0
    for b in range(K+1, N+1):
        q = 0
        while K+b*q <= N:
            ans += min((q+1)*b, N+1)-(K+b*q)
            q += 1
    if K == 0:
        ans -= N
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71020
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5;
LL a[maxn+3]={0}, b[maxn+3]={0}, c[maxn+3]={0};
int main()
{
    LL sum = 0;
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    for(int i=2; i<=n; ++i)
    {
        if(a[i] > a[i-1])
        {
            sum += a[i]-a[i-1];
            b[a[i-1]+1] += a[i-1]+1;
            b[a[i]+1] -= a[i-1]+1;
            ++c[a[i-1]+1];
            --c[a[i]+1];
        }
        else
        {
            sum += m-a[i-1]+a[i];
            b[a[i-1]+1] += a[i-1]+1;
            ++c[a[i-1]+1];
            b[1] -= m-a[i-1]-1;
            ++c[1];
            b[a[i]+1] += m-a[i-1]-1;
            --c[a[i]+1];
        }
    }
    for(int i=1; i<=m; ++i)
        b[i] += b[i-1], c[i] += c[i-1];
    /*for(int i=1; i<=m; ++i)
    {
        printf("%d ",b[i]);
    }
    puts("");
    for(int i=1; i<=m; ++i)
    {
        printf("%d ",c[i]);
    }
    puts("");*/
    LL ans = 0, pos = 0;
    for(int i=1; i<=m; ++i)
    {
        LL tmp = i*1LL*c[i]-b[i];
        ans = max(ans, tmp);
    }
    //printf("%lld\n",sum);
    printf("%lld\n",sum-ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll res = 0;
  rep(i, n) {
    ll tmp = i+1;
    if (v.at(i) == tmp) {
      res++;
      if (i == n-1) break;
      if (v.at(i+1) == tmp+1) i++;
    }
  } 
  cout << res << endl;
}

Measured memory_bytes: 1024
// A - Double Helix
#include <bits/stdc++.h>
using namespace std;

int main(){
	char b; cin>>b;
	if(b=='A') cout<<'T'<<endl;
	if(b=='T') cout<<'A'<<endl;
	if(b=='C') cout<<'G'<<endl;
	if(b=='G') cout<<'C'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
}

int main() {
  ll n;
  cin >> n;
  for (ll i = -1000; i <= 1000; i++) {
    ll tmp = n + (ll)pow(i, 5);
    if (tmp == (ll)pow((ll)pow(tmp, 0.2), 5)) {
      cout << (ll)pow(tmp, 0.2) << ' ' << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 4080
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	string S, T;
	cin >> S >> T;
	for(int i = 0; i < S.size(); i++){
		if(S[i] != T[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
ll MOD = 1e9 + 7;

using vc = vector<char>;
using vi = vector<int>;
using vll = vector<ll>;

vll fact, inv, invfact;

ll choose(ll n, ll k) {
    return fact[n] * invfact[k] % MOD * invfact[n-k] % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll N, K;
    cin >> N >> K;

    fact = vll (N+1);
    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = fact[i-1] * i % MOD;

    inv = vll (N+1);
    inv[1] = 1;
    FOR(i, 2, N+1) inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

    invfact = vll (N+1);
    invfact[0] = 1;
    FOR(i, 1, N+1) invfact[i] = invfact[i-1] * inv[i] % MOD;

    vll arr (N);
    F0R(i, N) {
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());
    
    ll BM = 0;
    FOR(i, K-1, N) {
        BM += arr[i] * choose(i, K-1);
        BM %= MOD;        
    }

    ll BS = 0;
    FOR(i, 0, N-K+1) {
        BS += arr[i] * choose(N-i-1, K-1);
        BS %= MOD;
    }
    cout << (BM - BS + MOD) % MOD << endl;
}

Measured memory_bytes: 3456
// Ballazt
//0a..brute force
//0b..greedy
//1..memorizatton of some sort	remember something cleverly
//2..sort
//3..binary search	keep check a particular solution
//4..dp				repeating strucutre,limited choices
//5..dfs/bfs		matrix with obstacles
//6..correlate to graph in some way		each state is a point
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"


int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int k,a,b;

	cin>>k>>a>>b;

	
for(int i=a;i<=b;i++)
{
	if(i%k==0)
	{
		cout<<"OK";
		return 0;
	}


}

cout<<"NG";



	
}

Measured memory_bytes: 3612
#ABC078 A - HEX
def HEX(s):
    if s == 'A':
        n = 10
    elif s == 'B':
        n = 11
    elif s == 'C':
        n = 12
    elif s == 'D':
        n = 13
    elif s == 'E':
        n = 14
    elif s == 'F':
        n = 15
    return n

x,y = map(str,input().split())
x = HEX(x)
y = HEX(y)

if x < y:
    ans = '<'
elif x == y:
    ans = '=' 
elif x > y:
    ans = '>'

print(ans)


Measured memory_bytes: 3188
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())

uf = UnionFind(n+1)
for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))

print(ans)

Measured memory_bytes: 14808
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int nowmod = 0;
        boolean flg = false;
        for(int i = 1; i <= n; i++){
            nowmod *= 10;
            nowmod += 7;
            nowmod %= n;
            if(nowmod == 0){
                pw.println(i);
                flg = true;
                break;
            }
        }
        if(!flg){
            pw.println(-1);
        }
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25920
import qualified Data.IntSet as IS

main :: IO ()
main = readLn >>= print . solve

solve :: Int -> Int
solve n = go 0 IS.empty $ IS.singleton 0
  where
    go depth used vs
        | IS.member n vs = depth
        | otherwise = go (depth + 1) (IS.union used nexts) $ nexts IS.\\ used
      where
        nexts = IS.unions . map next $ IS.toList vs
    next x = IS.unions
        [ IS.singleton $ x + 1
        , IS.fromList . takeWhile (<=n) . map (+x) $ iterate (*6) 6
        , IS.fromList . takeWhile (<=n) . map (+x) $ iterate (*9) 9
        ]

Measured memory_bytes: 2428
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
using namespace std;

class osa_k{
private:
    vector<int> prime_sieve;
    vector<int> set_prime;
    int N;
    void eratosthenes(){
        for(int i=2;i*i<N;i++) {
            if(prime_sieve[i]<i) continue;
            for(int j=i*i;j<N;j+=i){
                if(prime_sieve[j]==j) prime_sieve[j] = i;
            }
        }                
    }

    void setPrimeSet(){
        for(int i=2;i<N;i++){
            if(prime_sieve[i]==i){
                set_prime.emplace_back(i);
            }
        }        
    }
public:    
    osa_k(const int n):N(n){
        prime_sieve.resize(n);
        iota(prime_sieve.begin(),prime_sieve.end(),0);
        eratosthenes();
        setPrimeSet();
    }

    //例えばi=8の時、{2,2,2}
    vector<int> getFactor(int i) {
        vector<int> res;
        while(i>1){
            res.emplace_back(prime_sieve[i]);
            i/=prime_sieve[i];
        }
        return res;
    }
    //例えばi=8の時、{2}
    vector<int> getFactorSet(int i){
        vector<int> res;
        while(i>1){
            res.emplace_back(prime_sieve[i]);
            i/=prime_sieve[i];
        }
        //重複を省く
        sort(res.begin(),res.end());
        decltype(res)::iterator result = unique(res.begin(), res.end());
        res.erase(result, res.end());
        return res;
    }
    //素数の集合を得る {2,3,5,7,11,...}
    vector<int> getPrimeSet(){
        return set_prime;
    }
    //iが素数:true
    bool isPrime(const int i){
        if((i==0)||(i==1)){
            return false;
        }
        if(prime_sieve[i]==i){
            return true;
        }
        return false;
    }
};



int main(){
    int n;cin>>n;
    osa_k o(55555);
    auto x=o.getPrimeSet();
    vector<int> ans;
    for(int i=0;i<x.size();i++){
        if(x[i]%5==3){
            ans.emplace_back(x[i]);
        }
    }
    cout<<ans[0];
    for(int i=1;i<n;i++){
        cout<<" "<<ans[i];
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 3716
import sys
def input():
  return sys.stdin.readline().rstrip()

S=input()
K=int(input())

vec=[]
for i in range(len(S)):
  for j in range(i+1,K+i+1):
    tmp=S[i:j]
    if not tmp in vec:
      vec.append(tmp)
vec.sort()

print(vec[K-1])


Measured memory_bytes: 69544
N, M, C = input().split(' ')
N = int(N)
M = int(M)
C = int(C)
B = []
B = input().split(' ')
B = [int(i) for i in B]
A = []
R = 0
for i in range(N):
  A = input().split(' ')
  A = [int(i) for i in A]
  combine = [x * y for (x, y) in zip(A, B)]
  if sum(combine) + C > 0:
    R += 1
print(R)

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

using namespace std;

int main(){
	long long sum = 0,Z = 0,z;
	string s; cin >> s;
	int m = int(s.size());
	for(int i = 0; i < m; i++){
		if(s[i] == 'A'){
			break;
		}
		sum++;
	}
	for(int i = m - 1; i >= 0; i--){
		if(s[i] == 'Z'){
			break;
		}
		Z++;
	}
	cout << m - (sum + Z);
	return 0;
}



Measured memory_bytes: 640