akhauriyash/Code-Regression huggingface dataset:
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll n, t; cin >> n >> t;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> max_a(n);
	rep(i, n-1){
		int num = n - i - 1;
		max_a[num - 1] = max(max_a[num], a[num]);
	}
	// print(max_a);
	vector<ll> res;
	rep(i, n){
		res.push_back(max_a[i] - a[i]);
	}

	sort(ALL(res), greater<ll>());
	ll ans = 0;
	rep(i, res.size()) ans += res[i] == res[0];
	// print(res);

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 5868
// =====================================================================================
// 
//       Filename:  C.cpp
//        Created:  2017년 09월 30일 20시 45분 28초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
int main(){
	scanf("%d", &n);
	for(ll i=1;i<=3500;i++)
		for(ll j=1;j<=3500;j++){
			ll now=4*i*j-n*(i+j);
			if(now>0&&(n*i*j)%now==0)
				return !printf("%lld %lld %lld\n", i, j, n*i*j/now);
		}
	return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())

dic = {}
for i in range(1, n+1):
    dic[i] = 0

a = 0
b = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == 'AC' and dic[p] != 'AC':
        b += dic[p]
        dic[p] = 'AC'
    elif dic[p] != 'AC':
        dic[p] += 1
    
for i in range(1, n+1):
    if dic[i] == 'AC':
        a += 1
    
print(a, b)

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//printfを使うときはこれでエラーになるので注意,下を削除

//printfを使うときは上を削除
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//宣言だけしとく
int n,m,h,w,k,a,b;
string s;
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	ll M , A , B;
    cin>>M;
    ll sum = 0, keta = 0;
    rep(i,M){
        cin>>A>>B;
        sum += A*B;
        keta += B;
    }
    cout<<(sum - 1)/9 + (keta - 1)<<endl;
}
//写経 正直あんま分かってない


Measured memory_bytes: 256
//ABC103C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		ans += x-1;
	}
	cout << ans << endl;
	return 0;
}

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;

int dp[10005][100][2];
string s;
int n, d;

int digitSum(int pos, int mo, bool tight) {
	if (pos == n) return !mo;
	int &ans = dp[pos][mo][tight];
	if (ans != -1) return ans;

	ans = 0;
	int lim = tight ? s[pos] - '0' : 9;
	for (int i = 0; i <= lim; i++) {
		ans += digitSum(pos + 1, (mo + i) % d, tight and (i == lim));
		ans %= mod;
	}

	return ans;
}

void solve() {
	cin >> s >> d;
	n = s.length();
	memset(dp, -1, sizeof(dp));
	cout << (digitSum(0, 0, 1) - 1 + mod) % mod << endl;
}
// Remember to clear the global containers

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 20072
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>


using namespace std;

typedef unsigned uint;
typedef long long lint;

#define rep(i, n) for(int i=0; i<(n); i++)
#define rrep(i, n) for(int i=(n)-1; i>=0; i--)
#define forr(i, a, b) for(int i=(a); i<(b); i++)
#define rforr(i, a, b) for(int i=(a)-1; i>=(b); i++)

int N;
lint A[100010];

int main() {
    cin >> N;
    
    lint a;
    map<lint, lint> count;
    
    rep(i, N) {
        scanf("%ld", &a);
        count[a]++;
    }
    
    lint ans = 0, d;
    for(auto iter = count.begin(); iter != count.end(); iter++) {
        d = iter->second - iter->first;
        if(d < 0)
            ans += iter->second;
        else
            ans += d;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6272
#include <stdio.h>
#include <stdlib.h>

int main(){
    char a;
    scanf("%c",&a);
    switch(a){
        case 'A':
            printf("T\n");
            break;
        case 'T':
            printf("A\n");
            break;
        case 'C':
            printf("G\n");
            break;
        case 'G':
            printf("C\n");
            break;
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];\
void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}\
void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 1234567
int n,X,Y,c[SZ],w[SZ]; pii ps[SZ];
vector<int> vs[SZ]; Edg
bool vis[SZ];
map<int,int> sz;
void dfs(int x)
{
	vis[x]=1; ++sz[c[x]];
	for esb(x,e,b) if(!vis[b]) dfs(b);
}
const int MOD=1e9+7;
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
	ll x=1; a%=MOD;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
ll C(int a,int b)
{
	return fac[a]*rfac[a-b]%MOD*rfac[b]%MOD;
}
int main()
{
	fac[0]=rfac[0]=1;
	for(int i=1;i<SZ;++i) fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i)
		rfac[i-1]=rfac[i]*i%MOD;
	memset(ps,120,sizeof ps);
	scanf("%d%d%d",&n,&X,&Y);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",c+i,w+i); vs[c[i]].pb(i);
		ps[c[i]]=min(ps[c[i]],pii(w[i],i));
	}
	for(int i=1;i<=n;++i)
	{
		int x=ps[i].se,y=ps[i].fi;
		for(auto g:vs[i])
			if(y+w[g]<=X) adde(g,x);
	}
	sort(ps+1,ps+1+n);
	int a=ps[1].se,b=ps[2].se;
	for(int i=1;i<=n;++i)
	{
		if(1<=a&&a<=n)
		{
			if(c[i]!=c[a]&&w[i]+w[a]<=Y) adde(i,a);
		}
		if(1<=b&&b<=n)
		{
			if(c[i]!=c[b]&&w[i]+w[b]<=Y) adde(i,b);
		}
	}
	ll cp=1;
	for(int i=1;i<=n;++i) if(!vis[i])
	{
		sz.clear(); dfs(i);
		int s=0;
		for(auto g:sz)
		{
			int p=g.se;
			cp=cp*C(s+=p,p)%MOD;
		}
	}
	printf("%d\n",int(cp));
}

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

using namespace std;
const int maxn=2e5+10;
typedef long long ll;
struct Edge
{
    ll v,cost,nxt;
};
Edge edge[maxn];
ll head[maxn];
ll dis[maxn];
int flag[maxn];
int ok[maxn];
ll cnt;
ll tp[maxn];
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
    memset(flag,0,sizeof(flag));
    memset(edge,0,sizeof(edge));
    for(ll i=2;i<maxn;i++)
    {
        dis[i]=-1000000000000000;
    }
    dis[1]=0;
}
void add(ll u,ll v,ll w)
{
    edge[cnt].v=v;
    edge[cnt].cost=w;
    edge[cnt].nxt=head[u];
    head[u]=cnt;
    cnt++;
}
int flag2[maxn];
void dfs(ll x,int st,int en)
{
    flag[x]=1;
    if(x==en&&flag2[st])
    {
        ok[st]=1;
        return ;
    }
    if(ok[st])
        return ;
    for(ll i=head[x];i!=-1;i=edge[i].nxt)
    {
        if(!flag[edge[i].v])
            dfs(edge[i].v,st,en);
    }
}

void dfs2(ll x)
{
    flag2[x]=1;
    for(ll i=head[x];i!=-1;i=edge[i].nxt)
    {
        if(!flag2[edge[i].v])
            dfs2(edge[i].v);
    }
}
int main()
{
    ll n,m,p,u,v,w;
    init();
    scanf("%lld%lld%lld",&n,&m,&p);
    for(int i=0;i<m;i++)
    {
        scanf("%lld%lld%lld",&u,&v,&w);
        add(u,v,w-p);
    }
    dfs2(1);
    for(int i=1;i<=n;i++)
    {
        memset(flag,0,sizeof(flag));
        dfs(i,i,(int)n);
    }

    for(ll i=1;i<=n;i++)
    {
        for(ll k=1;k<=n;k++)
        {
            if(ok[k])
                for(ll j=head[k];j!=-1;j=edge[j].nxt)
                {
                    if(dis[edge[j].v]<dis[k]+edge[j].cost)
                    {
                        dis[edge[j].v]=dis[k]+edge[j].cost;
                    }
                }
        }
    }
    for(int i=1;i<=n;i++)
    {
        tp[i]=dis[i];
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll k=1;k<=n;k++)
        {
            if(ok[k])
                for(ll j=head[k];j!=-1;j=edge[j].nxt)
                {
                    if(dis[edge[j].v]<dis[k]+edge[j].cost)
                    {
                        dis[edge[j].v]=dis[k]+edge[j].cost;
                    }
                }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(ok[i]&&tp[i]!=dis[i])
        {
            printf("-1");
            return 0;
        }
    }
    if(dis[n]>0)
    {
        printf("%lld\n",dis[n]);
    }
    else
    {
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 10112
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod=1e9+7;
ll inf=1e18;


int main(void){
	ll n,x[110],y[110],h[110];
	vector<ll> x2,y2;
	cin>>n;
	rep(i,n){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]==0){
			x2.push_back(x[i]);
			y2.push_back(y[i]);
		}
	}
	reg(X,0,100){
		reg(Y,0,100){
			ll H=-1;
			bool ok=true;
			rep(i,n){//全て0という場合は発生しない
				if(h[i]!=0){
					if(H==-1){
						H=abs(x[i]-X)+abs(y[i]-Y)+h[i];
					}else{
						if(h[i] != max(H-abs(x[i]-X)-abs(y[i]-Y),(ll)0)){
							ok=false;
							break;
						}
					}
				}
			}
			rep(i,x2.size()){
				if(0 != max(H-abs(x2[i]-X)-abs(y2[i]-Y),(ll)0)){
					ok=false;
					break;
				}
			}
			if(ok){
				printf("%d %d %lld\n",X,Y,H);
				return 0;
			}
		}
	}
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

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

int main(){
  cout << setprecision(10);

  int H,W;
  cin >> H >> W;
  vector<string> v(H);
  int INF = 100000;
  vector<vector<int>> check(H, vector<int>(W,INF));

  queue<pii> q;
  for(int i = 0; i < H; i++){
    cin >> v.at(i);
    for(int j = 0; j < W; j++){
      if(v.at(i).at(j) == '#'){
        q.push(make_pair(i,j));
        check[i][j] = 0;
      }
    }
  }
  int ans = 0;
  while(!q.empty()){
    pii now = q.front();
    int now_x = now.first;
    int now_y = now.second;
    q.pop();

    for(int k = 0; k < 4; k++){
      int next_x = now_x + dx[k];
      int next_y = now_y + dy[k];
      if(next_x >= 0 && next_x < H){
        if(next_y >= 0 && next_y < W){
          if(check[next_x][next_y] == INF){
            check[next_x][next_y] = check[now_x][now_y] + 1;
            q.push(make_pair(next_x,next_y));
            ans = max(ans, check[next_x][next_y]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}


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

vector<vector<int>> mapint;
vector<string> mapstr;
ll H, W, Ch, Cw, Dh, Dw;

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

void dfs(int y, int x, int seg)
{
    mapint[y][x] = seg;
    for (ll i = 0; i < 4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (0 <= nx and nx < W and 0 <= ny and ny < H)
        {
            if (mapint[ny][nx] == -1 and mapstr[ny][nx] == '.')
            {
                dfs(ny, nx, seg);
            }
        }
    }
}

int bfs(int s, int g, vector<vector<ll>> &graph)
{
    queue<int> nodes;
    vector<int> reached(graph.size(), -1);

    nodes.push(s);
    reached[s] = 0;
    while (nodes.size())
    {
        int u = nodes.front();
        nodes.pop();
        if (u == g)
        {
            return reached[g];
        }
        for (auto &&e : graph[u])
        {
            if (reached[e] == -1)
            {
                nodes.push(e);
                reached[e] = reached[u] + 1;
            }
        }
    }
    return -1;
}

signed main()
{

    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    for (ll i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        mapstr.push_back(s);
    }
    mapint = vector<vector<int>>(H, vector<int>(W, -1));

    ll seg = 0;
    for (ll i = 0; i < H; i++)
    {
        for (ll j = 0; j < W; j++)
        {
            if (mapstr[i][j] == '.' and mapint[i][j] == -1)
            {
                dfs(i, j, seg);
                seg++;
            }
        }
    }

    vector<vector<ll>> graph(seg + 1);
    for (ll i = 0; i < H; i++)
    {
        for (ll j = 0; j < W; j++)
        {
            if (mapint[i][j] == -1)
                continue;

            for (ll di = -2; di <= 2; di++)
            {
                for (ll dj = -2; dj <= 2; dj++)
                {
                    int nx = j + dj;
                    int ny = i + di;

                    if (0 <= nx and nx < W and 0 <= ny and ny < H)
                    {
                        if (mapint[ny][nx] != -1 and mapint[ny][nx] != mapint[i][j])
                        {
                            graph[mapint[i][j]].push_back(mapint[ny][nx]);
                            graph[mapint[ny][nx]].push_back(mapint[i][j]);
                        }
                    }
                }
            }
        }
    }
    for (ll i = 0; i < seg + 1; i++)
    {
        sort(graph[i].begin(), graph[i].end());
        unique(graph[i].begin(), graph[i].end());
        graph[i].erase(unique(graph[i].begin(), graph[i].end()), graph[i].end());
    }

    int start = mapint[Ch - 1][Cw - 1];
    int goal = mapint[Dh - 1][Dw - 1];

    ll ans = bfs(start, goal, graph);

    cout << ans << endl;

    return 0;
}


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

int main() {
  long long n;
  cin >> n;
  long long a[n], b[n]={0};
  for(int i=0; i<n; i++) {
    cin >> a[i];
    b[0]=a[0];
    if(0<i) {
      b[i]+=b[i-1]+a[i];
      b[i]%=1000000007;
    }
  }
  long long ans=0;
  for(int i=1; i<n; i++) {
    ans+=a[i]*b[i-1];
    ans%=1000000007;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int hoge[114514];
string s;
int it;
int cnt=0;
//int a[1000];
int ri[3000],le[3000],ans[3000],a[3000],oya[3000];
int use[3000]={0};
int winner(){
	cnt++;
int r=cnt;
//cout<<it<<s[it]<<endl;
	if(s[it]>='a' && s[it]<='z'){
		a[r]=s[it]-'a';
		use[r]=2;
//		cout<<s[it]<<endl;
		it++;
		return r;
	}
	else if(s[it]=='['){
	//	cout<<"it "<<it<<endl;
		it++;
		int z=winner();
		it++;
		int zz=winner();
		it++;
		oya[z]=r;
		oya[zz]=r;
		use[r]=1;
			ri[r]=z,le[r]=zz;
//cout<<r<<" "<<ri[r]<<" "<<le[r]<<endl;

		return r;
	}
	return -1;
}

//int ans[1000];
int mr[1000];
int main() {
   cin>>s;
//   cout<<s<<endl;
   s=s+"*";
   it=0;
   for(int i=0;i<1000;i++) a[i]=-1,ans[i]=-1,mr[i]=-1;
	winner();
//cout<<"ss"<<endl;
//return 0;
	oya[1]=-1;


for(int i=1;i<=10;i++){
//	cout<<a[i]<<" "<<ri[i]<<" "<<le[i]<<endl;
}

	int n=(s.length()+3)/4;
//	cout<<n<<endl;
	for(int i=0;i<n;i++){
		char c;
		int y;
		cin>>c>>y;
		ans[c-'a']=y;
	}


	for(int i=0;i<26;i++){

	//	cout<<ans[i]<<endl;
		if(ans[i]==-1) continue;
int j;
//cout<<i<<endl;
		for(j=0;j<1000;j++){
			if(a[j]==i) break;

		}

		int e=oya[j];
		for(int k=0;k<ans[i];k++){
		//	cout<<"e "<<e<<endl;
			if(e==-1){
				cout<<"No"<<endl;
				return 0;
			}
			if(mr[e]!=-1){
				cout<<"No"<<endl;
				return 0;
			}
			mr[e]=i;
		//	cout<<e<<" "<<i<<endl;
			
			e=oya[e];
		}

	}


	for(int i=0;i<1000;i++){
		if(use[i]!=1) continue;
		if(mr[i]==-1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
using P = pair<int, int>;

int time_to_int(string time) {
    stringstream ss(time);
    string str;
    vector<string> v;
    while(getline(ss, str, ':')) {
        if(str.size() != 0) {
            v.push_back(str);
        }
    }
    return stoi(v[0])*3600 + stoi(v[1])*60 + stoi(v[2]);
}


int main() {
    int n;
    while(cin >> n, n) {
        vector<P> v(n);
        for(int i=0; i<n; ++i) {
            string s, e;
            cin >> s >> e;
            v[i] = make_pair(time_to_int(s), time_to_int(e));
        }
        sort(v.begin(), v.end());

        vector<P> train;
        for(int i=0; i<v.size(); ++i) {
            bool exists = false;
            for(int j=0; j<train.size(); ++j) {
                if(train[j].second <= v[i].first) {
                    train[j] = v[i];
                    exists = true;
                    break;
                }
            }
            if(!exists) {
                train.push_back(v[i]);
            }
        }
        cout << train.size() << endl;
    }
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vec x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    sort(all(x));
    sort(all(y));

    bool f = false;

    for (int z = X+1; z <= Y; z++) {
        bool f2 = true;

        if (!(X < z && z <= Y)) f2 = false;

        if (x[n-1] >= z) f2 = false;

        if (y[0] < z) f2 = false;

        if (f2) f = true;
    }

    if (f) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int const nax = 3e5 + 10;
int const Magic = 32;

/**
Some Math note
Let's the last time visit be t
apply (ax, bx) -> (ay, by)
the waiting time of first round would be
ax(t + 1) + bx -> ends at
t + (ax)(t + 1) + bx + 1
apply again
ay(t) + (ax)(ay)(t + 1) + aybx + ay + by + t + (ax)(t + 1) + bx + 1
ax(t) + (ax)(ay)(t + 1) + axby + ax + bx + t + (ay)(y + 1) + by + 1

cut equal term
aybx + ay(t) + ax(t) + ay + by + bx
axby + ax(t) + ay(t) + ax + bx + by
aybx + ay <= axby + ax
ay / (by + 1) <= (ax) / (bx + 1)
So sorted by this comparator does make sense

*/

struct Item {
    ll a, b;

    Item () : a () ,b () {}
    Item (ll a, ll b) : a (a), b (b) {}

    void read () {
        scanf("%lld %lld", &a, &b);
    }

    friend bool operator < (const Item & x, const Item & y) {
        return y.a * x.b + y.a < x.a * y.b + x.a;
    }
};
vector<Item> it;
vector<int> z;
int n;
int T;
ll dp[Magic + 1];


int main () {
    scanf("%d %d", &n, &T);
    for (int i = 1 ; i <= n ; ++ i) {
        Item I;
        I.read();
        if (I.a == 0) z.push_back(I.b);
        else it.push_back(I);
    }
    sort(it.begin(), it.end());
    sort(z.begin(), z.end());
    ll const inf = 1e18;
    fill(dp + 1 , dp + Magic + 1, inf);
    for (Item &i : it) {
        for (int v = Magic - 1; v >= 0 ; -- v) {
            if (dp[v] > T ) continue;
            ll c = (dp[v] + 1) * i.a + i.b + dp[v] + 1;
            if (c <= T)
            dp[v + 1] = min(dp[v + 1], c);
        }
    }
    int ans = 0;
    for (int v = 0 ; v <= Magic; ++ v) {
        if (dp[v] > T) continue;
        int res = v;
        for (int i : z) {
            if (dp[v] + i + 1 <= T) {
                dp[v] += i + 1;
                ++ res;
            }
        }
        ans = max(ans, res);
    }
    printf("%d\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define inf (long long)(1e18)
using namespace std;

struct dat {
  long long cos;
  bool isr;
  string now;
  bool operator<(const dat& r) const { return cos > r.cos; }
};

using P = pair<string, bool>;

long long n;
vector<string> s, rs;
vector<long long> c;
map<P, long long> mp;
priority_queue<dat> pq;

long long solve();

int main() {
  cin >> n;
  s.resize(n);
  c.resize(n);
  rs.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> c[i];
    rs[i] = s[i];
    reverse(rs[i].begin(), rs[i].end());
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = inf;
  for (int i = 0; i < n; ++i)
    if (s[i] == rs[i])
      res = min(res, c[i]);
    else {
      pq.push({c[i], 0, s[i]});
      if (mp.find(P(s[i], 0)) != mp.end())
        mp[P(s[i], 0)] = min(mp[P(s[i], 0)], c[i]);
      else
        mp[P(s[i], 0)] = c[i];
      pq.push({c[i], 1, rs[i]});
      if (mp.find(P(rs[i], 1)) != mp.end())
        mp[P(rs[i], 1)] = min(mp[P(rs[i], 1)], c[i]);
      else
        mp[P(rs[i], 1)] = c[i];
    }
  while (pq.size()) {
    auto [cos, isr, now] = pq.top();
    pq.pop();
    if (mp[P(now, isr)] != cos) continue;
    for (int i = 0; i < n; ++i) {
      string nxt = isr ? s[i] : rs[i];
      long long nextcost = cos + c[i];
      int mlen = min(nxt.size(), now.size());
      bool nxtch = isr;
      if (nxt.substr(0, mlen) != now.substr(0, mlen)) continue;
      if (abs((int)nxt.size() - (int)now.size()) <= 1) {
        res = min(res, nextcost);
        continue;
      }
      if (nxt.size() > now.size()) {
        nxt = nxt.substr(mlen, nxt.size() - mlen);
        nxtch = !nxtch;
      } else
        nxt = now.substr(mlen, now.size() - mlen);
      {
        string tmp = nxt;
        reverse(tmp.begin(), tmp.end());
        if (tmp == nxt) {
          res = min(res, nextcost);
          continue;
        }
      }
      P np(nxt, nxtch);
      if (mp.find(np) == mp.end() || mp[np] > nextcost) {
        mp[np] = nextcost;
        pq.push({nextcost, nxtch, nxt});
      }
    }
  }
  if (res == inf) return -1;
  return res;
}

Measured memory_bytes: 3676
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
ret = b_list[a_list[0] - 1]
for i in range(1, n):
    if(a_list[i] == a_list[i-1] + 1):
        ret += c_list[a_list[i] - 2]
    ret += b_list[a_list[i] - 1]
print(ret)


Measured memory_bytes: 3064
n, x, m = map(int, input().split())
nn = n

slow = x
fast = x
out = 0

while n:
    if n != nn and slow == fast:
        break
    out += slow
    n -= 1

    slow = (slow * slow) % m
    fast = (fast * fast) % m
    fast = (fast * fast) % m

head = slow
curr_sum = slow
curr_count = 1
slow = (slow * slow) % m
while slow != head:
    curr_count += 1
    curr_sum += slow
    slow = (slow * slow) % m

while n % curr_count:
    out += slow
    n -= 1
    slow = (slow * slow) % m

out += (n // curr_count) * curr_sum
print(out)


Measured memory_bytes: 65224
Q,H,S,D=map(int,input().split())
N=int(input())

Q=4*Q
H=2*H
if N%2==0:
	ans=int(N/2)*min(2*Q,2*H,2*S,D)
else:
	ans=(N//2)*min(2*Q,2*H,2*S,D)+min(Q,H,S)

# ans=(N//2)*min(2*Q,2*H,2*S,D)+(N%2)*min(Q,H,S)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string s;
  cin>>s;
if(s>="a") {
cout<<"a"<<endl;
}
  else {
cout<<"A"<<endl;
  }
}

  


Measured memory_bytes: 3548
#include <stdio.h>
int main(){
	int i, j , k, area;
	scanf("%d %d %d", &i, &j , &k);
	if(i > j && i >> k){
		area = j * k / 2;
	}else if (j > i && j > k){
		area = i * k / 2;
	}else{
		area = i * j /2;
	}
printf("%d", area);
return 0;
}

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

int main() {
	char s[4]; 
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < 4; i++) {
		for (int j = i+1; j < 4; j++) {
			if (s[i] == s[j]) {
				ans++;
			}
		}
	}
	if (ans == 2) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
n, x, m = map(int, input().split())

def solve(n, x, m):
    if n == 1:
        return x
    arr = [x]
    for i in range(1, n):
        x = x*x % m
        if x in arr:
            rem = n-i
            break
        else:
            arr.append(x)
    else:
        rem = 0
    sa = sum(arr)
    argi = arr.index(x)
    roop = arr[argi:]
    nn, r = divmod(rem, len(roop))
    return sa + nn*sum(roop) + sum(roop[:r])

print(solve(n, x, m))

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

int pow(long long x, long long n, int p) {
  if (n == 0) return 1;
  x %= p;
  if (n == 1) return x;
  if (n % 2) return (x * pow(x, n - 1, p) % p);
  long long y = pow(x, n / 2, p);
  return y * y % p;
}

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

  int n;
  cin >> n;
  cout << pow(2, floor(log2(n)), 1e9 + 7) << '\n';
  return 0;
}

Measured memory_bytes: 640
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int L, R;
    cin >> L >> R;
    if (R - L >= 2019) {
        cout << 0 << endl;
    } else {
        int ret = INF;
        for (int i = L; i <= R; i++) {
            for (int j = i + 1; j <= R; j++) {
                ret = min(ret, (i * j) % 2019);
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);
  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<=VMAX;i++)
    C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
      }

    for(i=1;i<=VMAX;i++)
        C[i]=C[i]+C[i-1];

    for(j=1;j<=n;j++){
      B[C[A[j]]]=A[j];
      C[A[j]]--;
    }

    for(i=1;i<=n;i++){
      if(i>1)printf(" ");
      printf("%d",B[i]);
    }

    printf("\n");

    return 0;
  }


Measured memory_bytes: 9592
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3:5]=b[4],b[3]
def f():
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


Measured memory_bytes: 5652
n = int(input())
s = [int(input()) for _ in range(n)]
max_score = sum(s)
if max_score % 10 == 0:
  s = sorted(s)
  i = 0
  while i < n:
    now_score = max_score - s[i]
    if now_score % 10 != 0:
      max_score -= s[i]
      break
    i += 1
  if i == n:
    max_score = 0
print(max_score)
    

Measured memory_bytes: 9172
import numpy as np

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

a = np.array(A, dtype=float)
b = np.array(B, dtype=float)

argmaxA = a.argmax()
a = np.roll(a, -argmaxA)
b = np.roll(b, -argmaxA + 1)
a = np.append(a, a[0])
b = np.append(b, b[0])
bb = np.cumsum(b)
c = 2 * np.cumsum(bb)

# force a_c[0]==a_c[N]==0
c -= c[0]
c -= np.arange(N + 1) * ((c[-1] - c[0]) / (N))
c += a[0]

a_c = a - c


def signed_area(x1, y1, x2, y2, x3, y3):
    x12 = x2 - x1
    y12 = y2 - y1
    x13 = x3 - x1
    y13 = y3 - y1
    return x12 * y13 - x13 * y12


# convex hull O(n)
vertices = [(0, a_c[0]), (1, a_c[1])]
for i in range(2, N + 1):
    while (
        len(vertices) >= 2 and signed_area(*vertices[-2], *vertices[-1], i, a_c[i]) >= 0
    ):
        vertices.pop()

    vertices.append((i, a_c[i]))

ans = 0
for i in range(len(vertices) - 1):
    ans += (vertices[i + 1][0] - vertices[i][0]) * (vertices[i + 1][1] + vertices[i][1])
ans /= N * 2
ans += c[:-1].mean()
print(ans)

Measured memory_bytes: 71888
N, a, b = map(int, input().split())
num = b - a
if num%2 == 0:
    half = num//2
    print(half)
else:
    edge = min(N-a, b-1)
    edge2 = min((b-a-1)//2+a, (b-a-1)//2+N-b+1)
    print(min(edge2, edge))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }

    set<ll> se;
    vector<ll> path;
    ll loopStart = 0;
    se.insert(0);
    path.push_back(0);
    while (true) {
        ll next = A[path.back()];

        if (se.find(next) != se.end()) {
            loopStart = next;
            break;
        }

        se.insert(next);
        path.push_back(next);
    }

    vector<ll> l1, l2;
    bool loop = false;
    for (auto p: path) {
        if (p == loopStart) loop = true;
        if (loop) l2.push_back(p);
        else l1.push_back(p);
    }

    if (K < l1.size()) {
        cout << l1[K] + 1 << endl;
        return 0;
    } else {
        K -= l1.size();
    }

    ll k = K % (ll) l2.size();
    cout << l2[k] + 1 << endl;
}


Measured memory_bytes: 18616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        try
        {
            checked
            {
                int n = int.Parse(Console.ReadLine());
                var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
                var res = a.Contains(0) ? 0 : a.Aggregate(1L, (x, y) => x * y);
                if (res > 1000000000000000000) throw new Exception();
                Console.WriteLine(res);
            }
        }
        catch
        {
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 42408
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  int N = 900000000 / (h * w);
  vector<vector<int>> a(H, vector<int>(W, 1 + N));
  for (int i = h - 1; i < H; i += h){
    for (int j = w - 1; j < W; j += w){
      a[i][j] = -(h * w) - N * (h * w - 1);
    }
  }
  long long sum = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      sum += a[i][j];
    }
  }
  if (sum <= 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        cout << a[i][j];
        if (j < W - 1){
          cout << ' ';
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 4492
import heapq as h

def partions(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d


N,K=map(int,input().split())
A=list(map(int,input().split()))
s=sum(A)
candidate=partions(s)
ans=1
for i in range(0,len(candidate)):
    X=[A[j]%candidate[i] for j in range(0,N)]
    s=sum(X)//candidate[i]
    test=0
    h.heapify(X)
    for j in range(0,N-s):
        test=h.heappop(X)
    test=candidate[i]*s-sum(X)
    if K>=test:
        ans=candidate[i]
print(ans)


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


typedef pair<int, int> p;

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

  vector<p> v(n);
  vector<p> max_num(n + 1);
  REP (i, n + 1) max_num[i] = make_pair(-1, -1);
  int a, b;
  REP (i, n) {
    cin >> a >> b;
    v[i] = make_pair(b, a);
    if (max_num[a].first < b) {
      max_num[a] = make_pair(b, a);
    }
  }

  sort(v.begin(), v.end(), greater<p>());

  LL oisi = 0;
  bool done[n + 1] = {false};
  vector<int> foo;
  REP (i, k) {
    oisi += v[i].first;
    if (max_num[v[i].second].first == v[i].first && !done[v[i].second]) {
      done[v[i].second] = true;
    } else {
      foo.push_back(v[i].first);
    }
  }

  sort(foo.begin(), foo.end());

  LL x = 0;
  REP (i, n + 1) {
    if (done[i]) x++;
  }

  sort(max_num.begin(), max_num.end(), greater<p>());

  LL ans = 0;
  REP (i, n + 1) {
    ans = max(ans, oisi + x * x);
    if (foo.size() <= 0) break;
    if (max_num[i].second > 0 && !done[max_num[i].second]) {
      oisi -= foo[0];
      foo.erase(foo.begin(), foo.begin() + 1);
      oisi += max_num[i].first;
      x++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2304
#include <iostream>


using namespace std;

int main() {

    int yen,coins;
    int remain;

    cin >> yen;
    cin >> coins;

    remain = yen % 500;

    if(remain <= coins) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
int a[1000005];
bool v[1000005];

int main(){
    int n;
    cin >> n;
    bool pair = false;
    int num;
    for(int i = 0; i < n; ++i){
        cin >> num;
        ++a[num];
    }
    for(int i = 2; i <= 1000000; ++i)
        if(!v[i]){
            int t = 0;
            for(int j = 1; j * i <= 1000000; ++j){
                t += a[j * i];
                v[j * i] = true;
            }
            if(t == n){
                cout << "not coprime\n";
                return 0;
            }else if(t >= 2)
                pair = true;
        }

    if(pair)
        cout << "setwise coprime\n";
    else
        cout << "pairwise coprime\n";
    return 0;
}


Measured memory_bytes: 8496
#ifndef _WIN32
#include<iostream>
#endif
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
typedef vector<string> VS;
VS wrap(VS v,char c) {
	int R = v.size(), C = v[0].size();
	VS ret(R + 2, string(C + 2, c));
	REP(i, R)REP(j, C)ret[i + 1][j + 1] = v[i][j];
	return ret;
}
const int dr[] = { 0,0,1,-1 };
const int dc[] = { 1,-1,0,0 };

int main() {
	int N;
	while (cin >> N, N) {
		VS s(N);
		REP(i, N)cin >> s[i];
		vector<int> r(N,0);
		REP(i, N) {
			while (!isalpha(s[i][r[i]]))r[i]++;
		}
		REP(i, N) {
			int now = i;
			while (1) {
				int nxt = -1;
				FOR(j, now + 1, N) {
					if (r[j] <= r[i])break;
					if (r[j] == r[i]+1) { nxt = j; break; }
				}
				if (nxt == -1)break;
				FOR(j, now + 1, nxt)s[j][r[i]] = '|';
				now = nxt;

			}
			if (r[i] > 0)s[i][r[i] - 1] = '+';
			for (auto &it : s[i])if (it == '.')it = ' ';
			cout << s[i] << endl;
		}
	}

}

Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
    ll n ;
    cin >> n;
    ll ans =0;
    for(int i =1 ; i< n; i++) {
        for(int j =1; (i * j) < n ; j++) {
            ans ++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

void Main() {
    long long N;
    cin >> N;
    vector<long long> A(N, 0);
    long long numNeg = 0;
    for (long long i = 0; i < N; ++i) {
        long long a;
        cin >> a;
        if (a < 0) {
            ++numNeg;
        }
        A[i] = abs(a);
    }
    sort(A.begin(), A.end());
    long long ans = 0;
    if (numNeg % 2 > 0) {
        ans -= A[0];
        for (long long i = 1; i < N; ++i) {
            ans += A[i];
        }
    }
    else {
        for (long long i = 0; i < N; ++i) {
            ans += A[i];
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4052
package main

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

var sc *bufio.Scanner

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i, _ := range a {
		a[i] = nextInt()
	}
	ans := -int(math.Pow10(10))
	max := -int(math.Pow10(10))
	for i := n - 1; i >= 0; i-- {
		if ans < max-a[i] {
			ans = max - a[i]
		}
		if max < a[i] {
			max = a[i]
		}

	}

	fmt.Println(ans)
}



Measured memory_bytes: 5368
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    ans = [0 for i in range(n+1)]
    for i in range(1,int(n**0.5)+1):
        for j in range(1,int(n**0.5)+1):
            for k in range(1,int(n**0.5)+1):
                a = i**2+j**2+k**2+i*j+j*k+i*k
                if a<=n:
                    ans[a] += 1
    for i in range(1,n+1):
        print(ans[i])
    return

if __name__=='__main__':
    main()


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

const int MAX = 1e6;
const int MOD = 1e9+7;
long fac[MAX],finv[MAX],inv[MAX];

void combinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; ++i){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD-inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1]*inv[i] % MOD;
    }
}


long com(int n, int k){
    if(n < k) return 0;
    if(n < 0 or k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
  combinit();
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  long ans=0;
  for(int i=K-1; i<N; i++){
    ans = ans + com(i,K-1)*A[i]%MOD;
  }
  for(int i=0; i<N-K+1; i++){
    ans = ans - com(N-i-1, K-1)*A[i]%MOD;
  }
  cout << ans%MOD << endl;
  return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
a.sort(reverse=True)
ans = a[0]
count = 1
for i in range(1, n):
    if n - 1 <= count + 2:
        ans += a[i] * (n-1 - count)
        break
    else:
        ans += a[i] * 2
        count += 2
print(ans)

Measured memory_bytes: 92216
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
wa = Array.new(n+1,0)
c = Hash.new(0)
for i in 0..n-1
  wa[i+1] = (wa[i]+a[i])%m
  c[wa[i+1]] += 1
end
c[0] += 1
ans = 0
c.values.each do |v|
  ans += v*(v-1)/2
end
puts ans

Measured memory_bytes: 13956
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define y0 u9cqu3jioajc

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

int n, a[100111];

bool check() {
    if (n == 1) return 1 - a[1] % 2;

    int cntEven = 0, cntOdd = 0;
    FOR(i,1,n) {
        if (a[i] % 2) ++cntOdd;
        else ++cntEven;
    }

    if (cntEven % 2 == 1) return 1;
    if (cntEven % 2 == 0 && cntOdd >= 2) return 0;

    bool ok = false;
    FOR(i,1,n) if (a[i] % 2 == 1 && a[i] > 1) {
        --a[i];
        ok = true;
        break;
    }

    if (!ok) {
        return cntEven % 2;
    }

    int g = a[1];
    FOR(i,2,n) g = __gcd(g, a[i]);
    FOR(i,1,n) a[i] /= g;

    return 1 - check();
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (GI(n) == 1) {
        FOR(i,1,n) GI(a[i]);

        cout << (check() ? "First" : "Second") << endl;
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    cout << s.substr(0,3);

    return 0;
}


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


int main() {
    int N; cin >> N;
    int u, k, v, c; 
    const int inf = 100000000;
    

    vector<pair<int, int> > G[N];
    for (int i = 0; i < N; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            G[u].push_back(make_pair(c, v));
        }
    }

    int dist[N]; 
    priority_queue<pair<int, int> > que;

    for (int i = 0; i < N; ++i) {
        if (i) dist[i] = inf;
        else dist[i] = 0;
    }
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        pair<int, int> f = que.top(); que.pop();
        int cur_cost = f.first*(-1);
        int cur_vtx = f.second;

        if (dist[cur_vtx] < cur_cost) continue;

        for (int i = 0; i < G[cur_vtx].size(); ++i) {
            int next_cost = G[cur_vtx][i].first;
            int next_vtx = G[cur_vtx][i].second;

            if (dist[next_vtx] > cur_cost + next_cost) {
                dist[next_vtx] = cur_cost + next_cost;
                que.push(make_pair(dist[next_vtx]*(-1), next_vtx));
            }
        }   
    }

    for (int v = 0; v < N; ++v) cout << v<< " " << dist[v] << endl;

    return 0;
}





Measured memory_bytes: 3152