akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int nmax = 2e3 + 10;
const int inf = 0x3f3f3f3;

int n, k;
vector < int > g[nmax];

int dfs(int node, int dad, int lvl, int lmax) {
    int res = 0;

    if (lvl > lmax) res++;
    for (auto &it : g[node]) {
        if (it == dad) continue;
        res += dfs(it, node, lvl + 1, lmax);
    }
    return res;
}

int main()
{
    //freopen("input","r",stdin);
    //freopen("output","w",stdout);

    scanf("%d %d", &n, &k);
    for (int i = 1; i < n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);

        g[x].push_back(y);
        g[y].push_back(x);
    }

    int ans = inf;
    if (k & 1) {
        for (int i = 1; i <= n; ++i)
            for (auto &it : g[i]) {
                if (it < i) continue;
                ans = min(ans, dfs(i, it, 0, k / 2) + dfs(it, i, 0, k / 2));
            }
    }
    else
        for (int i = 1; i <= n; ++i)
            ans = min(ans, dfs(i, 0, 0, k / 2));

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 512
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()

flag = True

l = []
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(h):
    l.append(list(input()))

for i in range(h):
    for j in range(w):
        if l[i][j] == '#':
            check = False
            for k in range(4):
                if i+dx[k] < 0 or i+dx[k] >= h:
                    continue
                if j+dy[k] < 0 or j+dy[k] >= w:
                    continue
                if l[i+dx[k]][j+dy[k]] == '#':
                    check = True
            if not check:
                flag = False

print('Yes' if flag else 'No')

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

const int N = 200005;
int n , a[N] , L[N] , R[N] , s[N] , top;

int main() {
    scanf("%d" , &n);
    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d" , &a[i]);
    }
    for (int i = 1 ; i <= n ; ++ i) {
        while (top && a[s[top]] >= a[i]) {
            R[s[top --]] = i;
        }
        s[++ top] = i;
    }
    while (top) {
        R[s[top --]] = n + 1;
    }
    for (int i = n ; i > 0 ; -- i) {
        while (top && a[s[top]] >= a[i]) {
            L[s[top --]] = i;
        }
        s[++ top] = i;
    }
    while (top) {
        L[s[top --]] = 0;
    }
    long long res = 0;
    for (int i = 1 ; i <= n ; ++ i) {
        res += (long long)a[i] * (i - L[i]) * (R[i] - i);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>

int main(void){
  int A,B;
  std::cin >> A;
  std::cin >> B;
  if((A > 0 && A < 10) && (B > 0 && B < 10)){
  	std::cout << A * B << std::endl;
  }
  else {
  	std::cout << -1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=2e5+100 , M=1e4+100 , SQ=710 , LG=23 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll k,now=1;
set<ll>s;
/*==========================================================================*/
ll get(ll x)
{   ll ans=0;
	while(x)   ans+=x%10   ,   x/=10;
	return ans;
}
/*==========================================================================*/
void proses()
{
    for(int i=0;i<=15;++i,now*=10)
    {
		for(ll j=0;;++j)
		{   ll x=now*j+now-1;
			if(x<=get(x)*now)   s.I(x);
			else                break;
		}
	}
	s.E(0);
}
/*==========================================================================*/
int main()
{
    IOS;
	proses();
	cin>>k;
	for(auto x:s)
    {
		cout<<x<<"\n";
		k--;
		if(k==0)   break;
	}
	return 0;
}


Measured memory_bytes: 384
while true
    r, a = gets.chomp.split()
    break if [r, a] == ["0", "0"]
    hit = 0
    4.times{|i| hit += 1 if r[i] == a[i]}
    hazure = (r.split("") - a.split("")).length
    puts "#{hit} #{4 - hazure - hit}"
end


Measured memory_bytes: 7204
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int k,t,i,mx=0,sum=0;
    int a[1005];
    scanf("%d%d",&k,&t);
    for(i=0;i<t;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
        if(a[i]>mx){
            mx=a[i];
        }
    }
    if(mx-1<sum-mx){
        printf("0\n");
    }
    else{
        printf("%d\n",mx-sum+mx-1);
    }
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
int n;
vector<int>G[N];
ll dp[N], ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[max(u, v)].push_back(min(u, v));
	}
	ans = dp[1] = 1ll;
	for (int i = 2; i <= n; i++) {
		sort(G[i].begin(), G[i].end(), greater<int>());
		int mx = 0;
		if (!G[i].empty())mx = G[i][0];
		dp[i] = i - mx + dp[i - 1];
		for (int j = 1; j < (int)G[i].size(); j++) {
			int v = G[i][j];
			dp[i] -= v;
		}
		ans += dp[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 35012
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 
ll n[100010]={0};
int main()
{
	ll N,q,i,s=0,t,b,c;
	cin>>N;
	for(i=0;i<N;i++)
	{
		scanf("%lld",&t);
		n[t]++;s+=t;
	}
	cin>>q;
	for(i=0;i<q;i++)
	{
		scanf("%lld%lld",&b,&c);
		t=c-b;
		s+=t*n[b];
		n[c]+=n[b];
		n[b]=0;
		printf("%lld\n",s);
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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



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

    ll N,M;
    string S;
    cin >> N>>M;
    vector<ll> k(M);
    vector<vector<ll>> s(M);

    REP(i,M){
        cin >> k.at(i);
        for (ll j = 0; j < k.at(i); j++) {
            ll tmp;
            cin >> tmp;
            s.at(i).push_back(tmp);
        }

        
    }
    vector<ll> p(M);
    REP(i,M){
        cin >> p.at(i);
    }
    ll count = 0;
    bool flag = true;
    ll ans = 0;

    for (int bit = 0; bit < (1 << N); ++bit)
    {
        bitset<10> bit1(bit);
        REP(j, M)
        {
            REP(a, k.at(j))
            {
                if (bit1.test(s.at(j).at(a) -1) == true)
                {
                    count++;
                }
            }
            if (count % 2 == p.at(j))
            {
                count = 0;
            }
            else
            {
                count = 0;
                flag = flase;
                break;
            }
        }
        if (flag)
        {
            //cout << bit1 << endl;
            ans++;
        }
        flag = true;
    }

    cout << ans << endl;
}


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

const int LOOP = 10000; //?????????[???v????????????
const double EPS = 1e-6; //?????????????????????p(???C??????????????????????????)
int L;
int N; //?????????[?????????P???[???L????????

//?????????[?????????P???[???L?????????u???????????????????????n???????????A???S?????????????????????????v???Z????????????
double Evaluate(int r[12]) {
	double val = r[0] + r[N-1];
	for (int i = 0; i < N - 1; i++)
	{
		int a = abs(r[i] - r[i+1]), c = r[i] + r[i+1];
		val += sqrt(c*c - a*a);
	}
	return val;
}

//???????????????????[???v?????????????n???????????A?????????????????????????????J????????????????????????????
//(???J??????????????????????true)
bool Changes(int cnt) {
	return cnt < rand()%LOOP;
}

//?????????????????????@??????????????????????????
//???????????×????????????????????????????????????????????????????????????
//int r[12] : ?????????[?????????P???[???L??????0????????????N-1???????????????????t?????????A???z???????????u???????????????????????????i???[????????????
double Solve(int r[12]) {
	double score = Evaluate(r); //??????????????????????r[]???????????????????????i???[????????????????????
	double mi = score; //?????????????????????????????????????????????????????l?????????i???[????????????????????
	for (int cnt = 0; cnt < LOOP; cnt++)
	{
		//===============================================
		swap(r[rand()%N],r[rand()%N]);
		for(int i = 0 ;i < N ; i++){
			score = Evaluate(r);
		}
		if(score < mi){
			mi = score;
		}
		else {
			if(Changes(cnt)){
				if(mi > score){
					mi = score;
				}
			}
			else {
				swap(r[rand()%N],r[rand()%N]);
			}
		}
		
		//===============================================
	}
	return mi; //???????????l??????????????
}

//???????????`?????????????????????????????????|????????????????????????????????????????????????
int main() {
	while (cin >> L)
	{
		N = 0;
		int r[12];
		string S;
		getline(cin, S);
		stringstream SS(S);
		while (!SS.eof()) SS >> r[N++];

		double ans;
		if (N == 1) ans = r[0]*2;
		else ans = Solve(r);

		if (L - ans + EPS > 0) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int X; cin >> X;
  bool ans = 0;
  for(int cnt = 1; cnt <= X/100; cnt++){
    int p = X - 100*cnt;
    ans |= (p <= 5*cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> ans(33);

    if(n == 0){
        cout << 0 << endl;
        return 0;
    }

    int pow2 = 2,powm2 = 1;

    for(int i = 0;i < 33;i ++){
        if(n % pow2 != 0){
            ans.at(i) = 1;
            n -= powm2;
        }

        pow2 *= 2;
        powm2 *= -2;
    }

    while(ans.at(ans.size()-1) == 0){
        ans.pop_back();
    }

    for(int i = ans.size()-1;i >= 0;i --){
        cout << ans.at(i);
    }
    cout << endl;

}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        
        long B = sc.nextLong();
        
        long C = sc.nextLong();
        
        long D = sc.nextLong();

        long a = 0;

        long m = 0, n = 0, mn = 0;

            m = B/C-(A-1)/C;
            n = B/D-(A-1)/D;
            mn = B/lcm(C,D)-(A-1)/lcm(C,D);
            
            a = (B-A+1)-(m+n-mn);

        System.out.println(a);
        
    }

    //最小公倍数lcm・コピペ
    static long lcm (long a, long b) {
	    long temp;
        long c = a;
        
	    c *= b;
        
        while((temp = a%b)!=0) {
		    a = b;
		    b = temp;
	    }
	    return (c/b);
    }

}

Measured memory_bytes: 22612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N, A, B;

void print(vector<int>&ans) {
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i];
		if (i + 1 == ans.size()) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
}

int main(void)
{
	cin >> N >> A >> B;
	/*if (N + 1 == A + B) {
		vector<int>ans;
		for (int i = 0; i < B - 1; ++i) {
			ans.push_back(N - i);
		}
		for (int j = B - 1; j < N; ++j) {
			ans.push_back(j - (B - 1) + 1);
		}
		print(ans);
		return 0;
	}*/
	if (A * B >= N && A + B <= N + 1) {
		vector<vector<int>>pack;
		pack.push_back(vector<int>());
		for (int i = 0; i < N; ++i) {
			pack.back().push_back(i + 1);
			if (pack.back().size() == A) {
				pack.push_back(vector<int>());
			}
		}
		if (pack.back().empty())
			pack.pop_back();
		int chomp = B - (int)pack.size();
		if (chomp < 0) {
			cout << -1 << endl;
			return 0;
		}
		vector<vector<int>>rev;
		while (pack.size()) {
			vector<int>vec = pack.back();
			while (vec.size() >= 2 && chomp > 0) {
				rev.push_back(vector<int>(1, vec.back()));
				vec.pop_back();
				--chomp;
			}
			if (vec.size()) {
				rev.push_back(vec);
			}
			pack.pop_back();
		}
		assert(chomp == 0);
		vector<int>ans;
		for (auto& elm : rev) {
			for (int x : elm) {
				ans.push_back(x);
			}
		}
		print(ans);
		return 0;
	}
	cout << "-1" << endl;
	return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0, bmin = 1000000000;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        flag &= (a == b);
        ans += a;
        if (a > b) bmin = min(bmin, b);
    }
    ans -= bmin;
    if (flag) ans = 0;
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll h,w;cin>>h>>w;
    if(h%3==0 || w%3==0){
        cout<<0<<endl;
    }
    else{
        ll ans = h*w;
        rep(i,h-1){
            ll ws=w/2;
            ll tmp=max((h-i-1)*w-abs(i+1)*ws,abs((h-i-1)*w-(i+1)*(w-ws)));
            ans=min(tmp,ans);
        }
        rep(i,w){
            ll hs=h/2;
            ll tmp=max((w-i-1)*h-abs(i+1)*hs,abs((w-i-1)*h-(i+1)*(h-hs)));
            ans=min(tmp,ans);            
        }
        ans=min(ans,h);
        ans=min(ans,w);
        cout<<ans<<endl;
    }
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

ll sum(ll x) {
    ll ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    vector<ll> nums;
    forn(i, 1, 1000) nums.eb(i);
    fore(i, 0, 12) {
        ll pw = 1;
        forn(j, 0, i) pw *= 10;
        fore(j, 1, 1000) if (j > 1 || i > 0) nums.eb(j * pw - 1);
    }
    //cerr << nums.back() << '\n';
    vector<ll> ans;
    for (ll x : nums) {
        bool ok = true;
        for (ll y : nums)
            if (y > x) {
                ok &= x * sum(y) <= y * sum(x);
                if (!ok) break;
            }
        if (ok) ans.eb(x);
    }
    sort(all(ans));
    ans.resize(unique(all(ans)) - ans.begin());
    int k;
    cin >> k;
    forn(i, 0, k) cout << ans[i] << ' ';
    //cerr << ans.back() << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h,n;
	int a[100010];
	int ans=0;
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans+=a[i];
	}
	if(ans>=h){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }


int main(){
    ll X; cin>>X;
    ll L = pow(10,4);
    bool fin = false;
    for(ll a=0;a<=L;++a){
        for(ll b=-L;b<=L;++b){
            if(pow(a,5)-pow(b,5)==X){
                cout << a << " " << b <<"\n";
                fin = true;
            }
            if(fin){break;}
        }
        if(fin){break;}
    }

}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p1=1000000007;
int n;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--) {
        int n;cin>>n;
        map<int,int> m;
        int f=0;
        rep(i,n){
            int x;cin>>x;
            if(m.find(x)!=m.end())f=1;
            m[x]=1;
        }
        if(f)cout<<"NO";
        else cout<<"YES";
    }   
    return 0;   
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string L; cin >> L;
  mint ans = 0;
  ll num = 0;
  REP(i,L.size()){
    int len = int(L.size()) - i - 1;
    if(L[i]=='1'){
      ans += mint(2).pow(num) * mint(3).pow(len);
      num++;
    }    
  }
  ans += mint(2).pow(num);
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n,k,s=0,i,x;
	cin>>n>>k;
	map<int,int> a;
	for(i=1;i<=n;i++){ 
		cin>>x;
		if (a[x]==0)
			a[x]=1;
		else
			a[x]++;
	}
	if (a.size() <= k)
		cout<<0;
	else {
		int b[a.size()];
		int i=0;
		for(map<int,int>::iterator it=a.begin();it!=a.end();it++,i++){
			b[i]=it->second;
		}
		sort(b,b+a.size());
		for(int i=0;i<a.size()-k;i++){
			s+=b[i];
		}
		cout<<s;
	}
	return 0;
}

Measured memory_bytes: 10368
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {

		int n = in.nextInt();

		int[] cnt = new int[2001];
		for (int i=0; i<=1000; i++) {
			for (int j=0; j<=1000; j++) {
				cnt[i+j]++;
			}
		}

		int ans = 0;

		for (int i=0; i<=2000; i++) {
			for (int j=0; j<=2000; j++) {
				if (i + j == n) {
					ans += cnt[i] * cnt[j];
				}
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  vector<int> buf;
  vector<int>::iterator itr;
  bool flag=true,exist=false;
  cin>>s>>t;
  
  for(int i=0;i!=s.size();i++){
    flag=true;
    if(i+t.size()-1<s.size()){
      for(int j=0;j<t.size();j++){
        if(s[i+j]!='?'&&s[i+j]!=t[j]){
          flag=false;
          break;
        }
      }
      if(flag){       
        buf.push_back(i);
        exist=true;
      }
    }
  }
  if(exist){
    itr=buf.end();
    itr--;
    for(int j=0;j<t.size();j++){
          s[*itr+j]=t[j];
        }
    for(int i=0;i<s.size();i++){
      if(s[i]=='?'){
        s[i]='a';
      }
    }
    cout<<s<<endl;
  }else{
    cout<<"UNRESTORABLE"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using vc=vector<char>;

int dr[4]={-1,0,0,1};
int dc[4]={0,-1,1,0};

int main(){
    int n,m;
    cin >> n >> m;
    vector<vi> graph(n,vi());
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vi road(n);
    rep(i,n) road[i]=i;
    int ans=0;
    do{
        bool flag=true;
        for(int i=0;i<n-1;i++){
            if(find(graph[road[i]].begin(),graph[road[i]].end(),road[i+1])==graph[road[i]].end()) flag=false;
        }
        if(flag){
            //rep(i,n) cout << road[i] << " ";
            //cout << endl;
            ans++;
        }
    }while(next_permutation(road.begin()+1,road.end()));

    cout << ans << endl;
}

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

int main() {
  double A,B,H,M;
  double Ac;
  double Bc;
  long double Cc;
  long double Ans;
  cin >> A >> B >> H >> M;
  
  Bc = (360/60)*M;
  Ac = 0.5* (H * 60 + M);
  
/*
  if(Ac == Bc)
  {
    cout << 0 << endl;
    return 0;
  }
    */
  Cc = min(max(Ac,Bc)-min(Ac,Bc) , 360-max(Ac,Bc)+min(Ac,Bc));
  Cc = (Cc * 3.141592653589793 / 180);
  Ans = sqrt(pow(A,2) + pow(B,2) -(2*A*B*cos(Cc)));

  cout << setprecision(15)<<  Ans << endl;
}


Measured memory_bytes: 4160
#include<iostream>

using namespace std;

int main()
{
	int ans;
	int a,i;
	
	for(;;)
	{
		cin >> ans ;
		if(ans==0)
			break;
		
		for(i=0;i<9;i++)
		{
			cin >> a ;
			ans-=a;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int sod(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}


int main(){
    int n;
    cin>>n;
    int min_sum=INF;
    for(int i=1; i<n/2+1; i++){
        min_sum=min(min_sum, sod(i)+sod(n-i));
    }
    cout<<min_sum<<endl;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> a(N+1, 0);
    FOR(i, 1, N+1) cin >> a[i];

    // 累積和
    FOR(i, 1, N+1) a[i] += a[i-1];
    
    vector<long long> all_comb;
    FOR(l, 1, N+1){
        FOR(r, l, N+1){
            all_comb.push_back(a[r]-a[l-1]);
        }
    }

    long long ans = 0;
    // 上の桁から決めていく
    for(int i = 40; i >= 0; --i){
        vector<long long> tmp;
        for(auto v: all_comb){
            if(v & ((long long)1 << i)) tmp.push_back(v);
        }
        if(tmp.size() >= K){
            ans += ((long long)1 << i);
            all_comb = tmp;
            //cout << i << " " << ans << endl;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi 3.1415926535897
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double dif = abs(h*5+m/12-m);
    dif = dif/60;
    dif=dif*pi*2;
  //  double ans=cos((2*pi)/4);
    double ans= a*a + b*b  - 2*a*b*cos(dif);
   printf("%.9f",sqrt(ans));

}

Measured memory_bytes: 4216
#include <cstdio>
#include <algorithm>

using namespace std;

struct req {
    int l, r, val, idx;
    bool t;
};

bool operator <( req a, req b ) {
    if ( a.r == b.r ) {
        return a.t < b.t;
    }
    return a.r < b.r;
}

int bit[ 500001 ];

void add( int y, int val ) {
    while ( y <= 500000 ) {
        bit[ y ] += val;
        y += ( y & -y );
    }
}

int sum( int y ) {
    int res = 0;
    while ( y > 0 ) {
        res += bit[ y ];
        y -= ( y & -y );
    }
    return res;
}

bool visited[ 2000001 ];
req arr[ 1000005 ];
int main() {
    int N, Q, i;
    int *prev = new int[ 2000001 ];
    for ( i = 0; i <= 2000000; ++i ) {
        visited[ i ] = false;
        prev[ i ] = 0;
    }
    scanf( "%d", &N );
    scanf( "%d", &Q );
    for ( i = 1; i <= N; ++i ) {
        add( i, 1 );
    }
    for ( i = 0; i < N; ++i ) {
        scanf( "%d", &arr[ i ].val );
        arr[ i ].idx = i + 1;
        arr[ i ].t = 0;
        arr[ i ].r = i + 1;
    }
    for ( i = N; i < N + Q; ++i ) {
        scanf( "%d%d", &arr[ i ].l, &arr[ i ].r );
        arr[ i ].idx = i - N;
        arr[ i ].t = 1;
    }
    sort( arr, arr + N + Q );
    int ans[ Q ];
    for ( i = 0; i < N + Q; ++i ) {
        if ( arr[ i ].t ) {
            ans[ arr[ i ].idx ] = sum( arr[ i ].r ) - sum( arr[ i ].l - 1 );
        }
        else {
            if ( visited[ arr[ i ].val ] ) {
                if ( prev[ arr[ i ].val ] != 0 ) {
                    add( prev[ arr[ i ].val ], -1 );
                }
            }
            visited[ arr[ i ].val ] = true;
            prev[ arr[ i ].val ] = arr[ i ].idx;
        }
    }
    for ( i = 0; i < Q; ++i ) {
        printf( "%d\n", ans[ i ] );
    }
    return 0;
}

Measured memory_bytes: 36980
N,K=map(int, input().split())
X,Y=map(list,zip(*[list(map(int,input().split())) for i in range(N)]))
x=sorted(X)
y=sorted(Y)
c=[[0]*(N+1) for i in range(N+1)]
for i in range(N):
    c[x.index(X[i])+1][y.index(Y[i])+1]=1
for i in range(N):
    for j in range(N):
        c[i+1][j+1]+=c[i][j+1]+c[i+1][j]-c[i][j]
ans=5*10**18
for t in range(1,N):
    for b in range(t+1,N+1):
        for l in range(1,N):
            for r in range(l+1,N+1):
                count=c[b][r]-c[b][l-1]-c[t-1][r]+c[t-1][l-1]
                if count>=K:
                    ans=min(ans,(y[r-1]-y[l-1])*(x[b-1]-x[t-1]))
                    break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

struct edge { int to, cost; };
typedef pair<int, int> P;

const int N = 3000;
const int INF = (1<<28);

int n, m, k;
vector<edge> G[N];
int d[N];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  d[s] = 0;
  que.push(P(0, s));
                      
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e= G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

main(){
  cin >> n >> m >> k;
  for(int i=0;i<m;i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back((edge){b, c});
    G[b].push_back((edge){a, c});
  }
  fill(d, d+n, INF);
  for(int i=0;i<k;i++){
    int in;
    cin >> in;
    dijkstra(in-1);
  }

  double ans = 0.0;
  for(int i=0;i<n;i++) ans = max(ans, (double)d[i]);
  for(int i=0;i<n;i++){
    for(int j=0;j<G[i].size();j++){
      int a = i, b = G[i][j].to;
      int tmp = abs(d[a] - d[b]);
      ans = max(ans, max(d[a], d[b]) + (double)(G[i][j].cost - tmp) / 2.0);
    }
  }
  cout << ((int)(ans * 10) + 5) / 10 << endl;
}

Measured memory_bytes: 4204
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
constexpr ll MOD=1e9+7;
constexpr ll nmax=1e5+10;//1e9+10;
ll dp[110][nmax];
//constexpr ll nmax=1e2+10;//1e9+10;
//ll dp[5][nmax];
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-3.in");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N,K; cin>>N>>K;
    unordered_map<ll,ll> tbl; //N/jが何種類か
    vector<ll> lim;
    //lim.reserve(N+1); //出てくる数
#if LOCAL&0
    for(ll i=1;i<=N;++i){
         ++tbl[N/i];
    //     lim.push_back(N/i);
    }
#endif
    for(ll i=1;i*i<=N;++i){
        lim.push_back(i);
        lim.push_back(N/i);
    }
    sort(lim.begin(),lim.end(), greater<ll>());
    lim.erase(std::unique(lim.begin(), lim.end()), lim.end()); //重複除く
    lim.insert(lim.begin(), 0);
    for(int i=1;i<lim.size();++i){
        ll l=N/lim[i];
        ll r=lim[i-1]==0?0:N/lim[i-1];
        tbl[lim[i]]=l-r;
    }

    dp[0][1]=1;
    for(ll k=1;k<=K;++k){
		//vector<ll> sum(N + 1,0); //累積和
        vector<ll> sum(lim.size()+10,0);
		//for(ll si = 1; si <= N; ++si) {
        //    sum[si]=sum[si-1]+dp[k-1][si];
		//}
        //unordered_map<ll,ll> sum; //累積和
        for(ll si=1;si<=lim.size();++si){
            sum[si]=sum[si-1]+dp[k-1][si];
        }
        for(ll si=1;si<=lim.size();++si){
            ll sum_range=lim.size()-si;
            ll multip=tbl[lim[si]];
            dp[k][si]=sum[sum_range]*multip%MOD;
        }
		//for(ll m=1;m<=N;++m){
            // for(ll a=1;a<=N/m;++a){
            //     dp[k][a]+=dp[k-1][m];
            // }
        //    dp[k][m]=sum[N/m];
        //}
    }
    // for(ll k=1;k<=K;++k){
    //     for(ll m=1;m<=N;++m){
    //         for(ll a=1;a<=N/m;++a){
    //             ll val=m*a;
    //             dp[k][val]+=dp[k-1][m];
    //         }
    //     }
    // }
    ll ans=0;
    for(auto&& v:dp[K]){
        ans += v;
        ans %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 82976
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b == 0 ? a : gcd(b, a % b);}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    //pairwise coprime
    bool p = true;
    sort(a.begin(), a.end());
    //A_i = 1 (1 <= i <= n)
    if(a[n - 1] == 1){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    set<int> prime;
    for(int i = 0; i < n; i++){
        if(a[i] == 1)
            continue;
        int j = 2;
        if(prime.find(a[i]) != prime.end()){
            p = false;
            goto END_REP;
        }
        prime.insert(a[i]);
        while(j * j <= a[i]){
            if(a[i] % j == 0){
                int q = a[i] / j;
                if(prime.find(j) != prime.end() || prime.find(q) != prime.end()){
                    p = false;
                    goto END_REP;
                }
                else{
                    prime.insert(j);
                    prime.insert(q);
                }
            }
            j++;
        }
    }
    END_REP: ;
    // for(int i : prime)
    //     cout << i << endl;

    if(p)
        cout << "pairwise coprime" << endl;
    else{
        //setwise coprime
        int g = a[0];
        for(int i = 1; i < n; i++)
            g = gcd(g, a[i]);
        if(g == 1)
            cout << "setwise coprime" << endl;
        else
            cout << "not coprime" << endl;
    }
    return 0;
}

Measured memory_bytes: 7292
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

ll t[111111];
ll a[111111];
ll r[111111];

int main(void){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>t[i];
  for(int i=1;i<=n;i++) cin>>a[i];

  ll res=1;
  for(int i=1;i<=n;i++){
    if(t[i-1]!=t[i]){
      if(t[i]!=min(t[i],a[i])){
	cout<<0<<endl;
	return 0;
      }
    }
  }
  for(int i=n;i>=1;i--){
    if(a[i+1]!=a[i]){
      if(a[i]!=min(t[i],a[i])){
	cout<<0<<endl;
	return 0;
      }
    }
  }

  ll tm=0;
  for(int i=1;i<=n;i++) {
    r[i]=min(t[i],a[i]);
    tm=max(tm,r[i]);
  }
  map<ll,ll> mp;
  for(int i=1;i<=n;i++){
    if(r[i]==tm) break;
    if(mp.find(r[i])==mp.end()) mp[r[i]]=1;
    else{
      res*=r[i];
      res%=mod;
    }
  }

  map<ll,ll> mp2;
  for(int i=n;i>=1;i--){
    if(r[i]==tm) break;
    if(mp2.find(r[i])==mp2.end()) mp2[r[i]]=1;
    else{
      res*=r[i];
      res%=mod;
    }
  }
  int counttm=0;
  for(int i=1;i<=n;i++) if(r[i]==tm) counttm++;
  for(int i=0;i<counttm-2;i++){
    res*=tm;
    res%=mod;
  }
  cout<<res<<endl;
  
  return 0;
}


Measured memory_bytes: 8832
"""
異なる数の足し算で
行ける最大の距離を一秒ずつ算出し，こした時がその値
つまり，そこまでの内で一つを除けば辿りつくはず

数列の和を求めていく
"""

X = int(input())
count = 0
ans = 0
for i in range(1,X+1):
    count += i
    ans += 1
    if count >= X:
        print(ans)
        exit()

Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 500005
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
lli dp[S];
void solve()
{
    lli n;
    cin>>n;
    lli arr[n+100]={0};
    for(lli i=1;i<=n;i++)
    {
        cin>>arr[i];

    }

    for(lli i=n;i>=1;i--)
    {
        dp[i]=(dp[i+1]%M+arr[i+1]%M)%M;
    }
    lli ans=0;
    for(lli i=1;i<=n;i++)
    {
        // print2(i,dp[i])
        ans=ans%M+((arr[i]%M)*(dp[i]%M))%M;
        ans=ans%M;
    }

    cout<<ans;




}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";

Measured memory_bytes: 6724
import std.stdio, std.range, std.algorithm, std.conv, std.string, std.array, std.typecons, std.format;

void main() {
    long n;
    long bs = 0;
    long ae = 0;
    long bsae = 0;
    bool nonbsa = false;
    long cnt = 0;
    readf("%d\n", &n);
    foreach (_; 0..n) {
        auto s = readln.strip;
        cnt += s.count("AB");

        if(s[0] == 'B' && s[$-1] == 'A' ) {
            bsae = 1;
            bs++;
            ae++;
        } else if (s[0] == 'B') {
            nonbsa = true;
            bs++;
        } else if (s[$-1] == 'A') {
            nonbsa = true;
            ae++;
        }
    }


    if (nonbsa) {
        bsae = 0;
    }

    writeln(cnt + min(bs, ae) - bsae);
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;

template <typename T> T digsum(T a) {
    T res = 0;
    while (a > 0) {
        res += a%10;
        a /= 10;
    }
    return res;
}




int main()
{
    ll N;
    cin >> N;
    
    string s = to_string(N);
    int n = int(s.length());
    ll ans = ll(9*(n-1)+int(s[0]-'1'));
    ans = max(ans,digsum(N));
    
    cout << ans << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
import numpy as np
import copy
c = [0]*3
for i in range(3):
  c[i] = [int(x) for x in input().split()]

ans = False
while c[0][0] >= 0 and c[0][1] >= 0 and c[0][2] >= 0:
  a = copy.deepcopy(c[1])
  b = copy.deepcopy(c[2])
  for i in range(3):
    a[i] -= c[0][i]
    b[i] -= c[0][i]
  if a[0] == a[1] == a[2] and b[0] == b[1] == b[2]:
    ans = True
    break
  for i in range(3):
    c[0][i] -= 1

if ans:
  print("Yes")
else:
  print("No")

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

const int INF = 1e9;

struct Node {
    int dist;
    vector<int> to, cost;

    bool operator <(Node that) const {return dist > that.dist;} // 小さい方から出てくるようにする
};

int main() {
    int K; cin >> K;
    vector<Node> node(K);
    for (int i = 0; i < K; i++) {
        node[i].dist = INF;

        node[i].to.push_back((i + 1) %K);
        node[i].cost.push_back(1);

        node[i].to.push_back((i*10) %K);
        node[i].cost.push_back(0);
    }

    // ダイクストラ法
    priority_queue<Node> que;
    node[1].dist = 0; que.push(node[1]);

    while (que.size() > 0) {
        Node n = que.top(); que.pop();

        for (int i = 0; i < n.to.size(); i++) {
            if (n.dist + n.cost[i] < node[n.to[i]].dist) {
                node[n.to[i]].dist = n.dist + n.cost[i];
                que.push(node[n.to[i]]);
            }
        }
    }

    cout << node[0].dist + 1 << endl;
    return 0;
}

Measured memory_bytes: 19156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if(N % 2 == 0)
            {
                Console.WriteLine(N / 2);
            }
            else
            {
                Console.WriteLine(N / 2 + 1);
            }

        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
const int N=4005;
char c[N];
int a[N],tree[2][N],cntb[N][N],cntw[N][N],ind[2][N];
int dp[N][N];
int prev(int x)
{
    return (x&(x-1));
}
int next(int x)
{
    return 2*x-prev(x);
}
void update(int type, int ind, int diff)
{
    while(ind<=N)
    {
        tree[type][ind]+=diff;
        ind=next(ind);
    }
}
int get(int type, int ind1, int ind2)
{
    int ans=0;
    while(ind2)
    {
        ans+=tree[type][ind2];
        ind2=prev(ind2);
    }
    ind1--;
    while(ind1)
    {
        ans-=tree[type][ind1];
        ind1=prev(ind1);
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=2*n;i++)
    {
        cin>>c[i]>>a[i];
        ind[c[i]=='W'][a[i]]=i;
    }
    for(int i=0;i<n;i++)
    {
        cntb[i][0]=get(0,ind[0][i+1]+1,2*n);
        for(int j=1;j<=n;j++)
        {
            update(1,ind[1][j],1);
            cntb[i][j]=get(1,ind[0][i+1]+1,2*n)+cntb[i][0];
        }
        for(int j=1;j<=n;j++)
            update(1,ind[1][j],-1);
        update(0,ind[0][i+1],1);
    }
    for(int i=0;i<n;i++)
        update(0,ind[0][i+1],-1);
    for(int i=0;i<n;i++)
    {
        cntw[i][0]=get(1,ind[1][i+1]+1,2*n);
        for(int j=1;j<=n;j++)
        {
            update(0,ind[0][j],1);
            cntw[i][j]=get(0,ind[1][i+1]+1,2*n)+cntw[i][0];
        }
        for(int j=1;j<=n;j++)
            update(0,ind[0][j],-1);
        update(1,ind[1][i+1],1);
    }
    for(int i=0;i<n;i++)
        update(1,ind[1][i+1],-1);
    bool ans=true;
    for(int i=1;i<=2*n;i++)
        if(get(0,i,i)!=0 || get(1,i,i)!=0)
            ans=false;
    if(ans==false)
    {
        cout<<"What the fuck!"<<endl;
        return 0;
    }
    /*cout<<"Cntb: "<<endl;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=n;j++)
            cout<<i<<" "<<j<<" "<<cntb[i][j]<<endl;
        cout<<endl;
    }
    cout<<endl;
    cout<<"Cntw: "<<endl;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=n;j++)
            cout<<i<<" "<<j<<" "<<cntw[i][j]<<endl;
        cout<<endl;
    }
    cout<<endl;*/
    dp[0][0]=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==0 && j==0) continue;
            if(i==0)
                dp[i][j]=dp[i][j-1]+cntw[j-1][i];
            else if(j==0)
                dp[i][j]=dp[i-1][j]+cntb[i-1][j];
            else
                dp[i][j]=min(dp[i-1][j]+cntb[i-1][j],dp[i][j-1]+cntw[j-1][i]);
        }
    }
    /*cout<<"Dp:"<<endl;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
            cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        cout<<endl;
    }
    cout<<endl;*/
    cout<<dp[n][n]<<endl;
    return 0;
}


Measured memory_bytes: 98048