akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll pat1 = 0, pat2 = 0;
    if(n%2){
        //pattern1
        rep(i,n/2) pat1 += 2*a[n-i-1];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= (a[n/2-1]+a[n/2]);

        //pattern2
        rep(i,n/2-1) pat2 += 2*a[n-i-1];
        rep(i,n/2) pat2 -= 2*a[i];
        pat2 += (a[n/2] + a[n/2+1]);
    }else{
        rep(i,n/2-1) pat1 += 2*a[n-i-1];
        pat1 += a[n/2];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= a[n/2-1];
        pat2 = pat1;
    }
    cout << max(pat1, pat2) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;

typedef pair<ll, int> P;
const ll INF = 1e15;
struct edge {
  int to;
  ll cost;
};

class Dijk {
public:
  vector<edge> G[100005];
  ll dist[100005];
  int used[100005];

  void dijk(int s, int V) {
    priority_queue<P, vector<P>, greater<P>> Q;
    rep(i, 0, V) dist[i] = INF;
    rep(i, 0, V) used[i] = 0;
    dist[s] = 0;
    Q.push({0, s});

    while (!Q.empty()) {
      P p = Q.top();
      Q.pop();
      int v = p.second;
      if (used[v]) continue;
      used[v] = 1;
      for (auto &e : G[v]) {
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          Q.push({dist[e.to], e.to});
        }
      }
    }
  }
};

int main() {
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  s--, t--;
  Dijk D1, D2;
  rep(i, 0, M) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    D1.G[u].push_back({v, a});
    D1.G[v].push_back({u, a});
    D2.G[u].push_back({v, b});
    D2.G[v].push_back({u, b});
  }
  D1.dijk(s, N);
  D2.dijk(t, N);
  vector<ll> ans(N);
  rep(i, 0, N) ans[i] = D1.dist[i] + D2.dist[i];
  rem(i, N-1, 1) ans[i-1] = min(ans[i], ans[i-1]);
  rep(i, 0, N) printf("%lld\n", (ll)1e15 - ans[i]);
  return 0;
}


Measured memory_bytes: 19908
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define inf 1000000000
#define mod 1000000007
using namespace std;
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	str A, B = "YAKI";
	cin >> A;
	if (A.length() < 4) {
		printf("No\n");
		return 0;
	}
	for (i = 0; i < 4; i++) {
		if (A[i] != B[i]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
int a,b,c;
int i, num, count = 0;

scanf("%d %d %d", &a, &b, &c);

for (i = a; i <= b; i++) {
num = c / i;
if((num*i) == c) {
count += 1;
}
}
printf("%d\n", count);
return (0);
}

Measured memory_bytes: 596
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void dfs(bool[][] dp, bool[] visited, int v) {
  visited[v] = true;

  foreach (int i, e; dp[v]) {
    if (e) {
      if (!visited[i]) {
        dfs(dp, visited, i);
      }
    }
  }
}

void main() {
  int[] NM = readln.chomp.split.to!(int[]);
  int N = NM[0],
      M = NM[1];
  bool[][] dp;
  dp.length = N;
  foreach (ref e; dp) {
    e.length = N;
  }
  int[][] vs;
  int ans;

  foreach (_; 0..M) {
    int[] ab = readln.chomp.split.to!(int[]);
    int a = ab[0],
        b = ab[1];
    a--;
    b--;
    vs ~= [a, b];
    dp[a][b] = dp[b][a] = true;
  }

  foreach (v; vs) {
    int a = v[0],
        b = v[1];
    bool[] visited;
    visited.length = N;

    dp[a][b] = dp[b][a] = false;

    dfs(dp, visited, 0);

    if (!visited.all!(e => e)) {
      ans++;
    }

    dp[a][b] = dp[b][a] = true;
  }

  writeln(ans);
}


Measured memory_bytes: 256
#include<iostream>
#define N 100001
using namespace std;

struct Node{
  int p,l,r,sib;
};
Node t[N];

void preparse(int u){
  if(u<0) return;
  cout<<" "<<u;
  preparse(t[u].l);
  preparse(t[u].r);
}

void inparse(int u){
  if(u<0) return;
  inparse(t[u].l);
  cout<<" "<<u;
  inparse(t[u].r);
}

void postparse(int u){
  if(u<0) return;
  postparse(t[u].l);
  postparse(t[u].r);
  cout<<" "<<u;
}

int main(){
  int n,id,c;
  cin>>n;
  for(int i=0;i<n;i++)t[i].l=-1,t[i].p=-1,t[i].r=-1,t[i].sib=-1;
for(int i=0;i<n;i++){
    cin>>id;
    for(int j=0;j<2;j++){
      cin>>c;
      if(c>=0)t[c].p=id;
      if(j==0) t[id].l=c;
      else t[id].r=c;
    }
  }

  int root;
  for(int i=0;i<n;i++) if(t[i].p==-1) root=i;

  cout<<"Preorder"<<endl;
  preparse(root);
  cout<<endl;
  cout<<"Inorder"<<endl;
  inparse(root);
  cout<<endl;
  cout<<"Postorder"<<endl;
  postparse(root);
  cout<<endl;

  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[20][1100000];
vector<int> y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=1,g=0;
  cin >>a;
  cout <<a*a*a<<'\n';
  return (0);
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n=1):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
        self.number = [1] * n
    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.parent[y] = x
            res = self.number[x] * self.number[y]
            self.number[x] += self.number[y]
            return res
        else:
            return 0


N, M = map(int, input().split())
uf = UnionFind(N)
AB = []
for i in range(M):
  AB.append(list(map(int, input().split())))

ans = [N*(N-1)//2]
while AB:
  a, b = AB.pop()
  decrease = uf.union(a-1, b-1)
  _ans = ans[-1] - decrease
  ans.append(_ans)
  if _ans == 0:
    break

ans += [0] * (M - len(ans))
ans = ans[::-1]
ans = ans[-M:]
print(*ans, sep='\n')

Measured memory_bytes: 102816
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<cmath>
#include<math.h>
#include<cstdlib>
#include<assert.h>
#include<string>
#include<sstream>
#include<algorithm>
#include<ctime>
#include<iostream>
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define BP(n) __builtin_popcount(n)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=1;j<=n;j++)
#define unique(v) vector<ll>::iterator it; sort(v.begin(),v.end()); it= unique(v.begin(),v.begin()+v.size()); v.resize(distance(v.begin(),it))
#define PI 3.14159265358979323846
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<ll>& v,ll n){ ll i,io; rep(i,n) { cin>>io; v.pb(io);} }
/*void output(vector<ll> v) { ll i; rep(i,v.size()) cout<<v.at(i)<<" "; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(ll n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }*/
int main()
{
	fastio;
	ll a;
	cin>>a;
	cout<<a + a*a + a*a*a<<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	int a,b;
	int sum = 0;
	double aver = 0;
	char d;
	double ave;
	int avek;
	double avem;
	double counter = 0;

	while (cin >> a >> d >> b) {
		sum += a * b;
		aver += b;
		counter++;
	}

	avek = aver / counter;
	ave = aver / counter;
	avem = (ave - avek) * 10;

	if (avem >= 5) {
		avek++;
	}

	cout << sum <<endl << avek << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	lli n,m,v,p;
	cin >> n >> m >> v >> p;
	vector<lli> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	auto csum = a;
	for(int i=0; i<n-1; i++){
		csum[i+1] += csum[i];
	}

	lli ans = 0;
	for(int i=0; i<n; i++){
		//cerr << "i = " << i << endl;
		lli ubidx = upper_bound(a.begin(), a.end(), a[i]+m) -a.begin();
		if(n -ubidx >= p){
			continue;
		}
		lli sidx = upper_bound(a.begin(), a.end(), a[i]) -a.begin();
		if(n -sidx < p){
			ans++;
			continue;
		}
		lli unbeatable = n -ubidx;
		if(p-unbeatable-1 > 0){
			ubidx -= p-unbeatable-1;
		}
		lli rem = v -(n-ubidx) -sidx;
		//cerr << ubidx << " " << sidx << " " << rem << endl;
		if(rem <= 0){
			ans++;
			continue;
		}
		lli remnum = ubidx - sidx;
		lli remcap = remnum*(a[i]+m) -(csum[ubidx-1] -csum[sidx-1]);
		if(remcap >= rem*m){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        vi a;
        rep(i,n)
        {
            vp(a,x);
        }
        s=0;
        c=1;
        rep(i,n)
        {
            if(a[i]==c)
            {
                c++;
            }
            else s++;
        }
        if(s==n) cout<<-1<<en;
        else
        cout<<s<<en;
    }
}



Measured memory_bytes: 2548
#include <iostream>
using namespace std;
void digitNumber()
{
	int a, b;
	while (cin >> a)
	{
		cin >> b;
		int sum = a + b;
		int count = 0;
		while(sum > 0)
		{
			sum /= 10;
			count++;
		}

		cout << count << endl;
	}
}


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

Measured memory_bytes: 1160
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
long long grid[2][4000][4000] = {};
int pepe[2][2000][2000] = {};
int main() {
#define int long long
	int n,k;
	cin >> n >> k;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		string s;
		cin >> s;
		if (s == "W") {
			if (((long long)(a / k) + (long long)(b / k)) % 2LL == 0LL) {
				grid[0][a%k][b%k]++;
				pepe[0][a%k][b%k]++;
			}
			else {
				grid[1][a%k][b%k]++;
				pepe[1][a%k][b%k]++;
			}
		}
		else {
			if (((long long)(a / k) + (long long)(b / k)) % 2LL == 0LL) {
				grid[1][a%k][b%k]++;
				pepe[1][a%k][b%k]++;
			}
			else {
				pepe[0][a%k][b%k]++;
				grid[0][a%k][b%k]++;
			}
		}
	}
	for (int i = 0;i < 2;++i) {
		for (int q = 0;q <= k;++q) {
			for (int j = 1;j <= k;++j) {
				grid[i][q][j] += grid[i][q][j - 1];
			}
		}
		for (int q = 1;q <= k;++q) {
			for (int j = 0;j <= k;++j) {
				grid[i][q][j] += grid[i][q - 1][j];
			}
		}
	}
	long long ans = 0;
	for (int t = 0;t < 2;++t) {
		for (int i = 0;i <= k;++i) {
			for (int q = 0;q <= k;++q) {
				long long pre_ans = grid[t][k - 1][k - 1];
				if (i != 0) {
					pre_ans -= grid[t][i - 1][k - 1];
				}
				if (q != 0) {
					pre_ans -= grid[t][k - 1][q - 1];
				}
				if (i != 0 && q != 0) {
					pre_ans += 2LL * grid[t][i - 1][q - 1];
				}
				//white clear
				long long black = 0;
				if (i != 0) {
					black += grid[(t+1)%2][i - 1][k - 1];
				}
				if (q != 0) {
					black += grid[(t+1)%2][k - 1][q - 1];
				}
				if (i != 0 && q != 0) {
					black -= 2LL * grid[(t+1)%2][i - 1][q - 1];
				}
				ans = max(ans, black + pre_ans);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

int bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
int bit(lli _mask,int _i){return (_mask&(1ll<<_i))==0?0:1;}
int powermod(lli _a,lli _b,int _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
int add(int a,int b,int m=MOD){int x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
int sub(int a,int b,int m=MOD){int x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
int mul(int a,int b,int m=MOD){lli x=a*1ll*b;x%=m;while(x<0)x+=m;return (int)x;}
int ldtoint(ld x){return (int)(x+0.5);}lli ldtolli(ld x){return (lli)(x+0.5);}

template<class T1,class 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){os << "[";bool first=true;for (T it:v){if (!first)os<<", ";first = false;os<<it;}os<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,set<T>&v){os<<"[";bool first=true;for (T it:v){if(!first)os<<", ";first=false;os<<it;}os<<"]";return os;}
template<class T1,class T2>ostream&operator<<(ostream& os,map<T1,T2>&v){os<<"[";bool first=true;for(pair<T1,T2> it:v){if(!first)os<<", ";first=false;os<<"("<<it.F<<","<<it.S<<")";}os<<"]";return os;}

int N;
int A[100010];
vector<int> G[100010];
int ans[100010];

void dfs(int u){
    int cnt = 0;
    vector<int> szs;
    for(int v : G[u]){
        cnt ++;
        dfs(v);
        szs.pb(ans[v]);
    }
    if(cnt == 0)
        return;

    sort(all(szs));
    reverse(all(szs));

    int ret = 0;
    for(int i=0;i<szs.size();i++)
        ret = max(ret,szs[i]+i+1);
    ans[u] = ret;
}

int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));

    cin>>N;
    for(int i=2;i<=N;i++){
        cin>>A[i];
        G[A[i]].pb(i);
    }
    dfs(1);
    cout<<ans[1];

    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    string s;
    int q;
    cin >> s >> q;
    list<char> li;
    rep(i,s.size()) li.push_back(s[i]);
    bool rev = false;
    rep(qi,q){
        int t;
        cin >> t;
        if(t==1) rev = !rev;
        else{
            int f;
            char c;
            cin >> f >> c;
            if((f==1 && rev==false) || (f==2 && rev==true)){
                li.push_front(c);
            }else{
                li.push_back(c);
            }
        }
    }
    if(rev){
        while(!li.empty()){
            cout << li.back();
            li.pop_back();
        }
    }else{
        while(!li.empty()){
            cout << li.front();
            li.pop_front();
        }
    }
    return 0;
}

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

/// Constant:
#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9

#define         lli         long long int
#define         PB          push_back
#define         pb          pop_back
#define         mk          make_pair
#define         I           insert
/// Loop:
#define         f1(a,b)     for (int i=a; i<=b; i++)
#define         f2(a,b)     for (int j=a; j<=b; j++)
#define         f-1(a,b)     for (int i=b; i>=a; i--)
#define         f-2(a,b)     for (int j=b; j>=a; j--)
///Print:
#define         pY          cout<<"YES"<<endl;
#define         pN          cout<<"NO"<<endl;
#define         py          cout<<"Yes"<<endl;
#define         pn          cout<<"No"<<endl;

using namespace std;
///ISNNJB

/// Functions:
//lli bigmod(lli b, lli p, lli m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ lli res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//lli mod_inverse(lli a, lli mod) { return bigmod(a,mod-2,mod); }
//lli LCM(lli a, lli b){ return a*b/ __gcd(a,b);}

///Global Variable:
int ara[400005],brr[400004];

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {

    /**freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a,b,c,d,k,t,n,m,x,y,q,ctn=0,l1,l2,total=0,l,r;

    cin>>l>>r>>d;
    f1(l,r) {
        if(i%d==0)
            ctn++;
    }

    cout<<ctn<<endl;

    return 0;
}




Measured memory_bytes: 3564
#include <cstdio>
#include <queue>
#include <vector>

#define INF (long)1e15
#define MAX_N 100000

using namespace std;

int main() {
    int N, a;
    scanf("%d", &N);
    priority_queue<int, vector<int>, greater<int>> first;
    int second[N];
    priority_queue<int> third;
    long sum1 = 0, sum3 = 0;
    for (int i=0; i<3*N; i++) {
        scanf("%d", &a);
        if (i < N) {
            first.push(a);
            sum1+=a;
        } else if (i < 2*N) {
            second[i-N] = a;
        } else {
            third.push(a);
            sum3+=a;
        }
    }
    long score[MAX_N+1] = {0};
    score[0] = sum1; score[N] = -sum3;
    for (int i=1; i<=N; i++) {
        int a1 = second[i-1],   a3 = second[N-i];
        first.push(a1);       third.push(a3);
        int b1 = first.top(), b3 = third.top();
        first.pop();          third.pop();
        sum1 += a1 - b1;      sum3 += a3 - b3;
        score[i] += sum1;     score[N-i] -= sum3;
    }
    long best = -INF;
    for (int i=0; i<=N; i++) best = max(best, score[i]);
    printf("%ld\n", best);
    return 0;
}

Measured memory_bytes: 2296
#include<stdio.h>
int main(){
  int n = -1, x = -1, ans = 0;
  int a, b, c;
  while (1) {
    scanf("%d %d", &n, &x);
    if (n == 0 && x == 0) {
      break;
    }
    for (a = 1; a <= n; a++) {
      for (b = a + 1; b <= n; b++) {
        c = x - a - b;
        if (b < c && c <= n) {
          ans++;
        }
      }
    }
    printf("%d\n", ans);
    ans = 0;
  }
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

struct point{double x, y;};

void koch(int d, point p1, point p2){
    if(d == 0) return;
    point s, u, t;
    double th = M_PI * 60.0 / 180.0;
    s.x = (2.0*p1.x + p2.x) / 3;
    s.y = (2.0*p1.y + p2.y) / 3;
    t.x = (p1.x + 2.0*p2.x) / 3;
    t.y = (p1.y + 2.0*p2.y) / 3;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    koch(d-1, p1, s);
    cout << s.x << " " << s.y << endl;
    koch(d-1, s, u);
    cout << u.x << " " << u.y << endl;
    koch(d-1, u, t);
    cout << t.x << " " << t.y << endl;
    koch(d-1, t, p2);
}

int main(){
    point a, b;
    int n;
    cin >> n;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    cout << a.x << " " << a.y << endl;
    koch(n, a, b);
    cout << b.x << " " << b.y << endl;
}


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

int dp[3030][3030] ;

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

	for(int i = 1 ;i <= s.size() ; ++i) {
    	    for(int j = 1; j<= t.size() ; ++j) {
        	    if ( s[i-1] == t[j-1]) 
        	    	dp[i][j] = dp[i-1][j-1]+1;
            	else
            		dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
	
	vector<char>ans ; 
	int i = s.size() , j = t.size();
    while(i>0 && j>0) {
        if( s[i-1] == t[j-1] ) {
            ans.push_back(s[i-1]) ; 
            --i;--j;
        }
        else {
        	
            if (dp[i][j-1]>dp[i-1][j]) --j;
            else --i;
        }
    }
	
	for(int i =ans.size()-1 ; i>=0 ; --i)
		printf("%c" , ans[i]) ; 
		
	puts("") ; 
//	printf("%d" , dp[s.size()][t.size()]) ; 
	return 0;
}

Measured memory_bytes: 35840
import numpy as np

a, b, c, k = map(int, input().strip().split())


def mono(a, b, c):
    return b + c, c + a, a + b


# ダブリング
def doubling(a, b, c, coeff):
    vec = np.array([a, b, c])
    result = np.dot(coeff, vec)
    return result


def doubling_n_times(a, b, c, n):
    coeff = np.array([
        [0, 1, 1],
        [1, 0, 1],
        [1, 1, 0],
    ], dtype=np.int)
    for i in range(n - 1):
        coeff = np.dot(coeff, coeff)

    a, b, c = doubling(a, b, c, coeff)

    return a, b, c


def solve(a, b, c, k):
    pow = 0
    while k > 0:
        bit = k % 2
        k //= 2
        pow += 1
        if bit == 0:
            continue

        a, b, c = doubling_n_times(a, b, c, pow)

    return a, b, c


def solve_naively(a, b, c, k):
    for i in range(k):
        a, b, c = mono(a, b, c)
        if i + 1 in (1, 2, 4, 8, 16, 32):
            print("a, b, c, i + 1 = ", a, b, c, i + 1)

    return a, b, c


a, b, c = solve(a, b, c, k)

ans = a - b
if abs(ans) > 1e18:
    print('Unfair')
else:
    print(ans)


Measured memory_bytes: 22620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; }
    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) { ans += (A[i] + ans + B[i] - 1) / B[i] * B[i] - (A[i] + ans); }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int a = ipar();
        int b = ipar();
        int c = ipar();
        int m1 = Math.min(c, b);
        long total = m1 * 2;
        c -= m1;
        b -= m1;
        int m2 = Math.min(c, a);
        total += m2;
        c -= m2;
        a -= m2;
        total += b;
        total += Math.min(1, c);
        out.println(total);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 21716
#include <iostream>
#include <array>
#include <utility>
using namespace std;

int main()
{
    array<int, 6> d;
    array<int, 3> r = {0, 1, 2};
    auto rot = [&](int b, int x){swap(r[0], r[b]);r[x] = 5 - r[x];};

    for (int &x: d)
        cin >> x;

    for (char c; cin >> c;)
        switch (c) {
        case 'N': rot(1, 1); break;
        case 'S': rot(1, 0); break;
        case 'E': rot(2, 0); break;
        case 'W': rot(2, 2); break;
        }

    cout << d[r[0]] << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long w, h;
	cin >> w >> h;
 
	vector<long long> p(w);
	vector<long long> q(h);
	for (int i = 0; i < w; i++) scanf("%lld", &p[i]);
	for (int i = 0; i < h; i++) scanf("%lld", &q[i]);
 
	vector<pair<long long, int>> c;
	for (int i = 0; i < w; i++) c.emplace_back(p[i], 0);
	for (int i = 0; i < h; i++) c.emplace_back(q[i], 1);
	sort(c.begin(), c.end());
 
	long long ans = 0;
	int row = 0, col = 0;
	for (int i = 0; i < c.size(); i++) {
		long long a = c[i].first;
		int t = c[i].second;
		if (t == 0) {
			ans += (h - col + 1) * a;
			row++;
		} else {
			ans += (w - row + 1) * a;
			col++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6000
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
#define MAXN 0x3f3f3f3f
vector<int>v[100005];
int n;
int c[100005];
int vis[100005];
bool cmp(int x,int y)
{
    return x>y;
}
int cnt=0;
int ans[100005];
/*void init(int a)
{
    cout<<a<<endl;
    if(a==n+1) return ;
    for(int i=0;i<v[a].size();i++)
    {
        if(vis[v[a][i]==0]) ans[v[a][i]]=c[cnt++];
        vis[v[a][i]]=1;
    }
    for(int i=0;i<v[a].size();i++)
    {
        init(v[a][i]);
    }
}*/
void init()
{
    queue<int>p;
    ans[1]=c[1];
    cnt=1;
    p.push(1);
    vis[1]=1;
    while(!p.empty())
    {
        int t=p.front();
        p.pop();
        for(int i=0;i<v[t].size();++i)
        {
            if(!vis[v[t][i]])
            {
                ans[v[t][i]]=c[++cnt];
                vis[v[t][i]]=1;
                p.push(v[t][i]);
            }
        }
    }

}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int maxx=0;
    int maxi;
    for(int i=1;i<=n;i++)
    {
        if(v[i].size()>maxx)
        {
            maxx=v[i].size();
            maxi=i;
        }
    }
    int sum=0;
    int maxmax=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
        if(c[i]>maxmax)
        {
            maxmax=c[i];
        }
        sum+=c[i];
    }
    sort(c+1,c+n+1,cmp);
    cout<<sum-maxmax<<endl;
    init();
    cout<<ans[1]<<' ';
    for(int i=2;i<=n;i++)
    {
        cout<<' '<<ans[i];
    }

}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main(){
  vector < pair < int, int > > v;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ; i < n ;  i++){
    int x, y;
    cin >> x >> y;
    v.push_back({y, x});
  }
  sort(v.rbegin(),v.rend());
  set < int > st;
  for(int i = 1 ; i <= m ; i++)
    st.insert(i);
  long long ans = 0;
  for(int i = 0; i < v.size() ; i++){
    auto it = st.lower_bound(v[i].second);
    if (it != st.end()){
      st.erase(it);
      ans += v[i].first;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5748
loop do
  n = gets.to_i
  break if n==0
  ia = n.times.map{ gets.to_i }
  count = 0

  n.times do |i|
    0.upto(n-i-2) do |j|
      if ia[j] > ia[j+1]
        ia[j],ia[j+1]=ia[j+1],ia[j]
        count+=1
      end
    end
  end
  puts count
end

Measured memory_bytes: 6112
n = int(input())
a = list(map(int, input().split()))

b = [0] * (n + 1)
for i in range(n):
    b[i+1] = b[i] + a[i]

c = {}
for i in range(n + 1 ):
    count = c.get(b[i], 0)
    c[b[i]] = count + 1

ret = 0
for k, v in c.items():
    ret += v * (v - 1) // 2

print(ret)

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


using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

typedef long long ll;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


// * Dinic法による最大流
template<typename T> struct MaxFlow {
	const T INF =  1LL<<59; //1 <<29;
	const int V;
	struct Edge { int to, rev; T cap; };
	vector<vector<Edge>> g;
	vector<int>  iter, level;
	
	/// 初期化
	void init() { for(int i = 0; i < V; i++) g[i].clear(); }
	MaxFlow(int su) : V(su), g(V) { };
	/// 有向辺の追加
	void add(int from, int to, T cap) {
		g[from].push_back(Edge{to, (int)g[to].size(), cap});
		g[to].push_back(Edge{from, (int)g[from].size()-1, 0});
	}
	/// 無向辺の追加
	void add_multi(int from, int to, T cap) {
		g[from].push_back(Edge{to, (int)g[to].size(), cap});
		g[to].push_back(Edge{from, (int)g[from].size()-1, cap});
	}

	void bfs(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		for(;!que.empty();) {
			int v = que.front(); que.pop();
			for(const Edge& e: g[v]) if(e.cap > 0){
				if (level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	T dfs(int v, int t, T f) {
		if (v == t) return f;
		for(int &i = iter[v]; i < (int)g[v].size(); i++) {
			Edge &e = g[v][i];
			if (e.cap <= 0) continue;
			if (level[v] < level[e.to]) {
				T d = dfs(e.to, t, min(f, e.cap));
				if (d <= 0) continue;
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}

	// sからtへの最大流を返す
	T exec(int s, int t) {
		level.assign(V, -1);
		iter.assign(V, 0);
		T flow = 0;
		for(;;) {
			bfs(s);
			if (level[t] < 0) return flow;
			fill(iter.begin(), iter.end(), 0);
			T f;
			for(;(f = dfs(s, t, INF)) > 0;) flow += f;
		}
	}
};



int main() {

	int n; cin >>n;
	vector<ll> a(n);
	rep(i,n) cin >>a[i];
	
	MaxFlow<ll> mf(n+5);
	int S=n, T=n+1;
	ll psm=0;
	
	rep(i,n){
		if(a[i]>0){
			mf.add(i, T, a[i]);
			psm += a[i];
		}else{
			mf.add(S, i, -a[i]);
		
		}
	}
	rep(i,n) rep2(j, i+1,n){
		if((j+1)%(i+1)==0) mf.add(i, j, mf.INF);
	}
	ll res = mf.exec(S, T);
	cout << psm - res <<"\n";
	return 0;
}

Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
else:
    xn = int((x + y) / 6 + (x - y) / 2)
    yn = int((x + y) / 6 + (y - x) / 2)
    # print(xn, yn)
    if xn * yn < 0:
        print(0)
    else:
        n = cmb((xn + yn), xn)
        s = pow(int(n), 1, 1000000007)
        print(s)

Measured memory_bytes: 45392
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int p[20010]={};
	
	int a[20010]={};
	int b[20010]={};

	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> p[i];
	
	int maxdiff=N+1;
	for(int i=1;i<N;i++)
		maxdiff=max(maxdiff,abs(p[i]-p[i+1]));
	
	a[1]=1;
	for(int i=2;i<=N;i++)
		a[i]=a[i-1]+maxdiff+1;
	
	int x=1e9+1;
	for(int i=N,cnt=0;i>=1;i--,cnt++)
		b[p[i]]=(x-cnt)-a[p[i]];
	
	int xx=b[N];
	if(xx<1)xx=abs(xx)+1;
	else xx=0;
	for(int i=N;i>=1;i--)
		b[i]+=xx;

	for(int i=1;i<=N;i++)
	{
		cout << a[i];
		if(i==N)cout << endl;
		else cout << " ";
	}
	for(int i=1;i<=N;i++)
	{
		cout << b[i];
		if(i==N)cout << endl;
		else cout << " ";
	}
	

	return 0;
}



Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

double sqr(double x){
  return x*x;
}

int main(){
  for(int n,c=1;cin>>n,n;c++){
    double x[14][2],y[14][2];
    double ll=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
	cin>>x[i][j]>>y[i][j];
      }
      ll+=sqrt(sqr(x[i][0]-x[i][1])+sqr(y[i][0]-y[i][1]));
    }
    double dp[1<<14][14][2];
    fill(dp[0][0],dp[1<<14][0],1e99);
    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
	dp[1<<i][i][j]=0;
      }
    }
    double ans=1e99;
    for(int i=0;i<1<<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<2;k++){
	  if(i+1==1<<n){
	    ans=min(ans,dp[i][j][k]);
	  }
	  for(int l=0;l<n;l++){
	    if(i>>l&1)continue;
	    for(int m=0;m<2;m++){
	      dp[i|1<<l][l][m]=min(dp[i|1<<l][l][m],dp[i][j][k]+sqrt(sqr(x[j][k]-x[l][m^1])+sqr(y[j][k]-y[l][m^1])));
	    }
	  }
	}
      }
    }
    cout.precision(5);
    cout<<"Case "<<c<<": "<<fixed<<ans+ll<<endl;
  }
}

Measured memory_bytes: 4880
from bisect import bisect_left as bl
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    bb = LI()
    cc = LI()
    aa.sort()
    bb.sort()
    #print(aa)
    #print(bb)
    ans=0
    bi_to_a_cnt=[0]
    for b in bb:
        bi_to_a_cnt.append(bl(aa,b)+bi_to_a_cnt[-1])
    for c in cc:
        bi=bl(bb,c)
        ans+=bi_to_a_cnt[bi]
    print(ans)

main()

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    if(N < 1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define INF 2147483647
using namespace std;
struct Edge {
	int to, cost;
	Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > P;
P graph;
vector<int> dist;
bool bellman_ford(int n, int s) {
	dist = vector<int>(n, INF);dist[s] = 0;
	for (int i = 0; i < n; i++) {
		for (int v = 0; v < n; v++) {
			for (int k = 0; k < graph[v].size(); k++) {
				Edge e = graph[v][k];
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					if (i == n - 1) return true;
				}
			}
		}
	}
	return false;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int V, E;cin >> V >> E;
	graph = P(V);
	for (int i = 0; i < E; i++) {
		int from, to, cost;cin >> from >> to >> cost;
		graph[from].push_back(Edge(to, cost));
	}
	for (int j = 0; j < V;j++) {
		if (bellman_ford(V, j)) { cout << "NEGATIVE CYCLE" << endl; return 0; }
		for (int i = 0; i < V; i++) {
			if (dist[i] != INF) { cout << dist[i]; }
			else { cout << "INF"; }
			if (i != V - 1) { cout << ' '; }
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){

  int stac[101];
  char r[7];
  int top=0;
  int log;
  int i;

  for(i=0;i<101;i++)stac[i]=0;
  while(1){
    
    if(scanf("%s",&r[0])==EOF)break;
    
    if(r[0]=='+'){
      stac[top-1]=stac[top-1]+stac[top];
      stac[top]=0;
      top--;
    }
    else if(r[0]=='*'){
      stac[top-1]=stac[top]*stac[top-1];
      stac[top]=0;
      top--;
    }
    else if(r[0]=='-'){
      stac[top-1]=stac[top-1]-stac[top];
      stac[top]=0;
      top--;
      
    }
    else{
      log=strlen(r);
      top++;
      for(i=0;i<log;i++){
	stac[top]*=10;
	stac[top]+=r[i]-'0';
      }
    }
  }
  printf("%d\n",stac[top]);
  return 0;
}



      



Measured memory_bytes: 2048
n = int(input())

m = {}
for i in range(0,26):
  m[i] = chr(97+i)

ans = ''
while 1:

  n -= 1

  x = n // 26
  y = n % 26

  ans = m[y] + ans

  n = x
  if n == 0:
    break

print(ans)


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

int main()
{
	int64_t a, b;
	cin >> a >> b;

	auto lcm = [](int64_t a, int64_t b) {
		auto gcd = [](int64_t a, int64_t b) {
			while (b)
			{
				int64_t tmp = b;
				b = a % b;
				a = tmp;
			}
			return a;
		};

		return a / gcd(a, b) * b;
	};

	cout << lcm(a, b) << endl;

	return 0;
}

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

bool betemp(string sleft, string sright, long long left, long long right){
    if(sleft == sright) return (right - left) % 2 == 1;
    else return (right - left) % 2 == 0;
}

void solve(long long n){
    string vac = "Vacant";

    string sleft;
    string sright;
    string str;

    long long left = 0;
    long long right = n/2;

    cout << left << endl;
    cin >> sleft;
    if(sleft == vac) return;

    cout << right << endl;
    cin >> sright;
    if(sright == vac) return;

    if(betemp(sleft, sright, left, right) == false){
        swap(sleft, sright);
        left = right;
        right = n;
    }

    while(right - left > 1){
        long long mid = (left + right)/2;
        cout << mid << endl;
        cin >> str;
        if(str == vac) return;
        if(betemp(sleft, str, left, mid) == true) sright = str, right = mid;
        else sleft = str, left = mid;
    } 
}

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

    solve(n);
    return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

const ll N = 2e6 + 10;
ll fact[N];

void prefact() {
    fact[0] = 1;
    for(ll i = 1; i < N; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
    }
}

ll powmod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if(p & 1) {res = (res * a) % mod;}
        p /= 2;
        a = (a * a) % mod;
    }
    return res;
}

ll modinv(ll a) {
    return powmod(a, mod - 2);
}

ll ncr(ll n, ll r) {
    return (fact[n] * (modinv((fact[r] * fact[n - r]) % mod) % mod)) % mod;
}

void solve() {
    prefact();
    ll k;
    string s;
    cin >> k;
    cin >> s;
    ll ans = 0, n = s.size();
    for(ll i = 0; i <= k; i++) {
        ans = (ans + (ncr(n + i - 1, n - 1) * ((powmod(25, i) * powmod(26, k - i)) % mod) % mod)) % mod;
    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 19848
'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => parseInt(v, 10)))
  const n = input[0][0]
  const k = input[0][1]

  const nums = input.slice(1, input.length)
  let counts = Array.apply(null, { length: 1e5 + 1 }).map(v => 0)
  for (let i = 0; i < n; i++) {
    counts[nums[i][0]] += nums[i][1]
  }
  // console.log(counts)

  let tmp = 0
  for (let i = 1; i <= 1e5 + 1; i++) {
    tmp += counts[i]

    if (tmp >= k) {
      console.log(i)
      return
    }
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 51372
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,u,v,m = LI()
    ud = {}
    for i in range(n):
        t = LI()
        for j in range(n):
            ud[t[j]] = (i,j)
    vd = {}
    for i in range(n):
        t = LI()
        for j in range(n):
            vd[t[j]] = (i,j)

    ma = [I() for _ in range(m)]
    ut = collections.defaultdict(bool)
    vt = collections.defaultdict(bool)
    un = 0
    vn = 0
    for t in ma:
        if t in ud:
            ut[ud[t]] = True
            ui,uj = ud[t]
            for di,dj in ddn[:4]:
                k = 1
                for i in range(1, n):
                    if not ut[(ui+di*i, uj+dj*i)]:
                        break
                    k += 1
                for i in range(-1, -n, -1):
                    if not ut[(ui+di*i, uj+dj*i)]:
                        break
                    k += 1
                if k >= n:
                    un += 1
                    if k == 1:
                        un = 1

        if t in vd:
            vt[vd[t]] = True
            vi,vj = vd[t]
            for di,dj in ddn[:4]:
                k = 1
                for i in range(1, n):
                    if not vt[(vi+di*i, vj+dj*i)]:
                        break
                    k += 1
                for i in range(-1, -n, -1):
                    if not vt[(vi+di*i, vj+dj*i)]:
                        break
                    k += 1
                if k >= n:
                    vn += 1
                    if k == 1:
                        vn = 1

        if un >= u and vn < v:
            return 'USAGI'
        if vn >= v and un < u:
            return 'NEKO'
        if un >= u and vn >= v:
            break

    return 'DRAW'



print(main())



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

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 <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	// int rn = uniform_int_distribution<int>(0, MAXN)(rng);

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

    int n,m;
    cin>>n>>m;
    vi v;
    FOR(i,1,ceil(sqrt((double)m))+1) {
        if(m%i == 0) {
            if(m/i != i) {
                v.PB(i); v.PB(m/i);
            } else v.PB(i);
        }
    }

    int res = 1;
    REP(i,v.size()) {
        int p = m/v[i];
        if(p >= n) res = max(res, v[i]);
    }
    cout<<res;

	
	
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back

int main(){
    string str;
    cin>>str;
    if(str[0]==str[2]){
        cout<<"Yes"<<endl;
    }else{
         cout<<"No"<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int X=stdIn.nextInt();
		int A=X%100;
		int B=X/100;
		if(X%100==0)
			System.out.println(1);
		else{
			for(int i=0;i<5;i++){
				for(int j=0;j<B;j++){
					if(A>0)
						A--;
					if(A<=0){
						System.out.println(1);
						System.exit(0);
					}
				}
			}
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23636
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repA(i,a,n) for(ll i=a;i<=(n);++i)
#define repD(i,a,n) for(ll i=a;i>=(n);--i)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define PI       3.14159265358979323846
#define fastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
const ll MAX=1e5+5;
const ll INF=2e18;

#define INPUT_OUTPUT {\
	freopen("input.txt","r",stdin);\
	freopen("output.txt","w",stdout);\
}

// logical code of program starts here.
void solve()
{
    int n,w;
    cin>>n>>w;
    vi wt(n+1,0),val(n+1,0);
    rep(i,n)cin>>wt[i+1]>>val[i+1];
    ll dp[n+1][w+1];
    ms(dp,0);
    //cout<<dp[0][0]<<endl;
    rep(i,n+1)
    {
        rep(j,w+1)
        {
            if(i==0 or j==0)continue;
            dp[i][j]=dp[i-1][j];
            if(wt[i]<=j){
                dp[i][j]=max(dp[i][j],dp[i-1][j-wt[i]]+val[i]);
                //cout<<dp[i-1][j-wt[i]]<<endl;
                //cout<<i<<endl;
            }
        }
    }
    cout<<dp[n][w]<<endl;
}


// mian function 
int main()
{
    //INPUT_OUTPUT;//file handling
    fastIO;// fast input output
    clock_t start, end; 
    start = clock();
    int t;
    t=1;
    //cin>>t;
    w(t) solve();
    end = clock();   
    double time_taken = double(end - start)/double(CLOCKS_PER_SEC); 
    clog << "Time taken by program is : " << fixed 
    << time_taken << setprecision(5); 
    clog << " sec " << endl;
    return 0;
}

Measured memory_bytes: 82604
#include<bits/stdc++.h>
using namespace std;
#define int long long
main(){
    int n,x;
    cin>>n>>x;
    int ans=0;
    ans+=n;
    int res=n-x;
    while(res){
        if(res%x==0){
            ans+=(2*res/x-1)*x;
            break;
        }
        else {
            ans+=(2*(res/x))*x;
            int tmp=res;
            res=x;
            x=tmp%x;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(i,j,n) for(int i=j;i<n;i++)
#define pb        push_back
#define rf(i,j,n) for(i=n;i>=j;i--)
#define vi        vector<int>
#define hmm        "\n"
#define sp        " "
using namespace std;
int main()
{
    string p ;
    cin >> p;
    long long  ac = 0,ans=0;
    fr(i,0,p.size())
    {
        if(p[i]=='A'){ac++;}
        else if(i+1<p.size() && p[i]=='B' && p[i+1]=='C'){
            ans+=ac; i++;
        }
        else {ac=0;}
    }
    cout<<ans<<hmm;
}


Measured memory_bytes: 640