akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
	#include <vector>
	#include <set>
	#include <algorithm>

	#define mp make_pair
	#define pb push_back
	#define ppb pop_back

	using namespace std;

	typedef pair<int, int> pii;
	typedef vector<int> vi;
	typedef vector<pii> vpi;
	typedef vector<vi> vvi;
	typedef long long ll;
	typedef pair<ll, ll> pll;
	typedef vector<ll> vl;
	typedef vector<pll> vpl;
	typedef vector<vl> vvl;

	#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
	#define fors(i, n, s) for (int i = 0; i < (int)(n); i += s)
	#define forn1(i, n) for (int i = 1; i <= (int)(n); ++i)
	#define forn11(i, n) for (int i = 1; i < (int)(n); ++i)
	#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

	#define prOk(ok) cout << ((ok) ? "Yes" : "No")
	#define in insert
	#define rem remove

	int main()
	{

		ll n, k;
		cin >> n >> k;


		ll sum = 0;

		vl a(26, 0);

		forn(i, n)
		{
			string tmp;
			cin >> tmp;
			a[tmp[0] - 'A']++;
		}

		while(true)
		{
			ll amount = 0;
			sort(a.begin(), a.end());
			for(int i = 25; i >=0 ; i--)
			{
				if(a[i] <= 0)
					break;
				amount++;
				a[i]--;
				if(amount == k)
					break;
			}
			if(amount != k)
				break;
			else
				sum++;
		}

		cout << sum << endl;

		return 0;
	}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	sc = NewScanner(os.Stdin)
)

func main() {
	lines := sc.ReadLines(2)
	K, S := lines[0].Int(), lines[1].String()

	if len(S) <= K {
		fmt.Println(S)
	} else {
		fmt.Println(S[:K] + "...")
	}
}

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{scanner: bufio.NewScanner(r)}
}

func (sc *Scanner) ReadLine() Value {
	if sc.scanner.Scan() {
		return Value(sc.scanner.Text())
	}
	panic(sc.scanner.Err())
}

func (sc *Scanner) ReadLines(n int) Values {
	a := make(Values, n)
	for i := range a {
		a[i] = sc.ReadLine()
	}
	return a
}

type Value string

func (v Value) String() string {
	return string(v)
}

func (v Value) Strings() []string {
	return strings.Split(string(v), " ")
}

func (v Value) Int() int {
	n, err := strconv.Atoi(v.String())
	if err != nil {
		panic(err)
	}
	return n
}

func (v Value) Ints() []int {
	strings := v.Strings()
	ints := make([]int, len(strings))

	for i, s := range strings {
		n, err := strconv.Atoi(s)
		if err != nil {
			panic(err)
		}
		ints[i] = n
	}
	return ints
}

func (v Value) Float64() float64 {
	f, err := strconv.ParseFloat(v.String(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func (v Value) Float64s() []float64 {
	strings := v.Strings()
	float64s := make([]float64, len(strings))

	for i, s := range strings {
		f, err := strconv.ParseFloat(s, 64)
		if err != nil {
			panic(err)
		}
		float64s[i] = f
	}
	return float64s
}

type Values []Value

func (v Values) Strings() [][]string {
	a := make([][]string, len(v))
	for i, value := range v {
		a[i] = value.Strings()
	}
	return a
}

func (v Values) Ints() [][]int {
	a := make([][]int, len(v))
	for i, value := range v {
		a[i] = value.Ints()
	}
	return a
}

func (v Values) Float64s() [][]float64 {
	a := make([][]float64, len(v))
	for i, value := range v {
		a[i] = value.Float64s()
	}
	return a
}


Measured memory_bytes: 1756
N = int(input())
a = input().split()

D = {}
ans = 0

for i in range(N):
	if a[i] in D.keys():
		D[a[i]] += 1
	else:
		D[a[i]] = 1

for i in D.keys():
	if D[i] > int(i):
		ans += D[i] - int(i)
	elif D[i] < int(i):
		ans += D[i]

print(ans)

Measured memory_bytes: 20596
m,k = map(int, input().split())

if k == 0:
    ans = []
    for i in range(1<<m):
        ans.append(i)
        ans.append(i)
elif 1<<m <= k or m==1:
    ans = [-1]
else:
    ans = [i for i in range(1<<m) if i!=k]
    ans = ans + [k] + ans[::-1] + [k]

print(*ans)

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  while (true) {
    C -= B;
    if (C <=0) {
      cout <<"Yes"<< endl;
      break;
    }
    A -= D;
    if (A<=0) {
      cout <<"No"<< endl;
      break;
    }
  }
}


Measured memory_bytes: 3636
def judge(w, h, x, y, r):
    within_range = (0 <= x - r and x + r <= w) and (0 <= y - r and y + r <= h)
    return 'Yes' if within_range else 'No'

if __name__ == '__main__':
    w, h, x, y, r = map(int, input().split(' '))
    print(judge(w, h, x, y, r))



Measured memory_bytes: 5600
def readinput():
    n=int(input())
    a=[]
    b=[]
    c=[]
    for _ in range(n):
        aa,bb,cc=list(map(int,input().split()))
        a.append(aa)
        b.append(bb)
        c.append(cc)
    return n,a,b,c

def main(n,a,b,c):
    dp=[]
    dp.append([0]*n)
    dp.append([0]*n)
    dp.append([0]*n)

    dp[0][0]=a[0]
    dp[1][0]=b[0]
    dp[2][0]=c[0]

    for i in range(1,n):
        dp[0][i]=max(dp[0][i],dp[1][i-1]+a[i])
        dp[0][i]=max(dp[0][i],dp[2][i-1]+a[i])
        dp[1][i]=max(dp[1][i],dp[2][i-1]+b[i])
        dp[1][i]=max(dp[1][i],dp[0][i-1]+b[i])
        dp[2][i]=max(dp[2][i],dp[0][i-1]+c[i])
        dp[2][i]=max(dp[2][i],dp[1][i-1]+c[i])
    ans=max(dp[0][n-1], dp[1][n-1])
    ans=max(ans,dp[2][n-1])
    return ans

if __name__=='__main__':
    n,a,b,c=readinput()
    ans=main(n,a,b,c)
    print(ans)


Measured memory_bytes: 32604
N = int(input())
A = list(map(int, input().split()))

even = []
approved = 0

for i in A:
    if i % 2 == 0:
        even.append(i)

for x in even:
    if x % 3 == 0 or x % 5 == 0:
        approved += 1

if approved == len(even):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 9112
a, b = map(int, input().split())
s = input()
if s[a] != '-':
    print('No')
else:
    flag = True
    for i in range(len(s)):
        if i == a:
            continue
        elif not s[i].isdigit():
            print('No')
            flag = False
            break
    if flag:
        print('Yes')


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  string s;
  while(1){
    cin>>n;
    cin.ignore();
    if(n==0)break;
    map<string,int> mp;
    rep(i,n){
      string s;
      getline(cin,s);
      string tmp;
      rep(j,s.size()){
        if(s[j]!=' '&&s[j]!='\0')
          tmp.push_back(s[j]);
        else{
          mp[tmp]++;
          tmp.clear();
        }
      }
      mp[tmp]++;
    }
    char k;
    cin>>k;
    pair<int,string> p[20];
    int m=0;
    for(std::map<string,int>::const_iterator itr=mp.begin();itr!=mp.end();++itr)
      if(itr->first[0]==k){
        p[m].first=-(itr->second);
        p[m].second=itr->first;
        m++;
      }
    if(m==0){
      cout<<"NA"<<endl;
    }else{
      sort(p,p+m);
      rep(i,min(5,m)){
        cout<<p[i].second;
        if(i<min(5,m)-1)cout<<" ";
      }
      cout<<endl;

    }
  }
}

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

int main(){

    int N;
    cin>>N;

    int O = N%10;
    switch(O){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout<<"hon";
            return 0;
    }
    switch(O){
        case 0:
        case 1:
        case 6:
        case 8:
            cout<<"pon";
            return 0;
    }
    switch(O){
        case 3:
            cout<<"bon";
            return 0;
    }    
    return 0;
}

Measured memory_bytes: 3632
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n[5];
  rep(i, 5) cin >> n[i];
  rep(i, 5) if (n[i] == 0) {
    cout << (i + 1) << endl;
    return 0;
  }
}


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

int main() {
float x1,x2,x3,x4,y1,y2,y3,y4;
int n;
cin>>n;
for(int jjj=1;jjj<=n;jjj++){
	cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
	if(x1==x2||x3==x4){
		if(x3==x4&&x1==x2){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}}
	else{
		double k=(y2-y1)/(x2-x1),l=(y4-y3)/(x4-x3);
		if(k==l){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}	
	}

	return 0;
}

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

#define ll long long
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define MAX 1000000

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a=(a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    for(ll i = 2;i < MAX; i++)
    {
        if(prime[i-1])
        {
            for(ll j = i*i; j < MAX; j += i)
                prime[j-1] = false;
        }
    }
}

void getfact(vector<ll>&fact, vector<ll>&factinv)
{
    fact[0] = 1;
    factinv[0] = 1;
    
    for(ll i = 1; i < MAX; i++)
        fact[i] = (fact[i-1] * i)%MOD;
    
    for(ll i = 1; i < MAX; i++)
        factinv[i] = (factinv[i-1] * fastpower(i, MOD -2) )%MOD;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string a,b;
    cin>>a>>b;
    ll n=a.size();
    ll m=b.size();
    if(m-n == 1)
    {
        bool f=true;
        for(ll i=0;i<n;i++)
        {
            if(a[i]!=b[i])
            {
                f=false;
                break;
            }
        }
        if(f)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    else
    {
        cout<<"No\n";
    }
    

    return 0;
}

Measured memory_bytes: 3640
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = (ll)1e9+7;
// const ll MAXN = (ll)1e5+10;

set<ll> GetYakusu(ll a) {
   set<ll> ret;
   ll max = ceil(sqrt(a));
   for (ll i = 1; i <= max;i++) {
      if (a%i==0) {
         ret.insert(i);
         ret.insert(abs(a/i));
      }
   }
   return ret;
}

int main(void) {
   int N,M;
   cin>>N>>M;
   set<ll> yaku = GetYakusu(M);
   auto itr = yaku.end();
   while (itr!= yaku.begin()) {
      itr--;
      if (*itr *N <= M) break;
   }
   cout<<*itr<<endl;


   return 0;
}



Measured memory_bytes: 256
import sys
N = int(input())

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

ans = 0
v = 1

maxv = []

for i in range(N+1):

    if v <= 0:
        print (-1)
        sys.exit()
    
    maxv.append(v)

    v -= A[i]
    v *= 2

if v < 0:
    print (-1)
    sys.exit()

#print (maxv)

now = 0
for i in range(N,-1,-1):

    now = min(now + A[i] , maxv[i])
    #print (now)
    ans += now

print (ans)

    

Measured memory_bytes: 702072
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
ans, num = 1, []

if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

for _ in range(k):
    if len(mia) > 0 and len(pla) > 0:
        if abs(mia[-1]) <= pla[-1]:
            tmp = pla.pop()
        elif abs(mia[-1]) > pla[-1]:
            tmp = mia.pop()
    elif len(mia) == 0:
        tmp = pla.pop()
    elif len(pla) == 0:
        tmp = mia.pop()
    num.append(tmp)

cnt = sum(i < 0 for i in num)
for i in num:
    ans = ans * i % mod

if cnt % 2 == 1:
    p, q, r, s = 1, 0, -1, 0
    if len(mia) > 0 and cnt != k:
        for i in num[::-1]:
            if i >= 0:
                p, q = i, mia[-1]
                break
    if len(pla) > 0:
        for i in num[::-1]:
            if i < 0:
                r, s = i, pla[-1]
                break
    if len(mia) > 0 or (len(pla) > 0 and cnt != k):
        if q * r >= p * s:
            ans *= q * pow(p, mod - 2, mod)
        if q * r < p * s:
            ans *= s * pow(r, mod - 2, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 31828
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = tuple(map(int, sys.stdin.readlines()))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
            if use > K:
                return False
    return True
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)



Measured memory_bytes: 15892
n=int(input())
t,a=map(int,input().split())
hs=list(map(int,input().split()))
n=0
m=float('inf')
for i,h in enumerate(hs, start=1):
    x=abs(a-(t-h*0.006))
    if m>x:
        m=x
        n=i
print(n)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
// #define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    ll ans = 0;
    rep(i, 0, n) {
        int la = lower_bound(a, a + n, b[i]) - a;
        int lb = (c + n) - upper_bound(c, c + n, b[i]);
        ll sum = (ll)la * lb;
        ans += sum;
    }
    cout << ans << "\n";
}

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

int main() {
  
  int n;
  string k,s;
  
  cin >> n >>k;
  
  if(k.size()>n){
    for(int i = 0;i<n;i++){
      s = s + k.at(i);
    }
    cout << s << "..." << endl;
  }else{
    cout << k << endl;
  }
}


Measured memory_bytes: 3644
N, M = map(int, input().split())

AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort()

ans = 0
need = M
for a, b in AB:
    buy = min(need, b)
    need -= buy
    ans += buy * a

print(ans)


Measured memory_bytes: 20072
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	rep(i, y) res = res * x % mod;
	return res;
}

int main() {
	ll x;
	cin >> x;
	for (int a = -120; a < 120; a++) {
		for (int b = a - 1000; b < a; b++) {
			if (pow(a, 5) - pow(b, 5) == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve(int tc)
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<v64> arr(3, v64());
	arr[0].assign(x, 0);
	arr[1].assign(y, 0);
	arr[2].assign(z, 0);
	for (int i = 0; i < x; i++)
		cin >> arr[0][i];
	for (int i = 0; i < y; i++)
		cin >> arr[1][i];
	for (int i = 0; i < z; i++)
		cin >> arr[2][i];
	for (int i = 0; i < 3; i++)
		sort(arr[i].begin(), arr[i].end());
	set<pair<ll, v32>> Q;
	v32 temp = {x - 1, y - 1, z - 1};
	Q.insert({arr[0][x - 1] + arr[1][y - 1] + arr[2][z - 1], temp});
	while (k--)
	{
		pair<ll, v32> p = *(Q.rbegin());
		db(p.fi, p.se);
		cout << p.fi << ln;
		Q.erase(p);
		int idx[3];
		idx[0] = p.se[0], idx[1] = p.se[1], idx[2] = p.se[2];
		for (int j = 0; j < 3; j++)
		{
			ll res = p.fi;
			int z = idx[j];
			z--;
			if (z < 0)
				continue;
			res -= arr[j][z + 1];
			res += arr[j][z];
			p.se[j]--;
			Q.insert({res, p.se});
			p.se[j]++;
		}
	}
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int solve(int l, int r, vector<long long int>&v, vector<vector<long long int>>&dp){
    if(l==r)
        return v[l];
    else{
        if(dp[l][r]!=-1)
            return dp[l][r];

        return dp[l][r]=max((v[l]-solve(l+1, r, v, dp)), (v[r]-solve(l, r-1, v, dp)));
    }
}

int main() {
    int n;
    cin>>n;
    vector<long long int>v(n);
    vector<vector<long long int>>dp(n, vector<long long int>(n, -1));
    for(int i=0;i<n;i++)
        cin>>v[i];
    
    cout<<solve(0, n-1, v, dp);
    return 0;
}


Measured memory_bytes: 72960
#include<iostream>
#define ll long long
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
#include <iomanip>
using namespace std;
ll ans = 0;



int main()
{
    ll n;
    cin>>n;
    ll dp[n][n];
    ll elements[n];
    for(ll i=0; i< n; ++i){
        cin>>elements[i];
    }
    for(int  i=n-1; i>=0; --i)
    {
        for(int j=i; j<n; ++j)
        {
            if(i==j)
            {
                dp[i][j] = elements[i];
            }
            else
            {
                dp[i][j] = max( (elements[i] - dp[i+1][j]) ,(elements[j] - dp[i][j-1]) );
            }

        }
    }

    cout<<dp[0][n-1];
    return 0;
}


Measured memory_bytes: 70400
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <numeric>
#include <utility>
#include <queue>
#include <memory>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <iterator>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/
// #define ONLINE_JUDGE
#define maxn 1010
#define maxm 40010
#define inf 0x3f3f3f3f3f3f3f3f
struct Edge {
	int u, v;
	ll cost;
	Edge(int u = 0, int v = 0, ll c = 0) : u(u), v(v), cost(c) {}
};
vector<Edge> e;
ll d[maxn];
int n;
bool bellman(int s) {
	memset(d, 0x3f, sizeof d);
	d[s] = 0;
	for (int i = 1; i < n; i++) {
		bool fg = false;
		for (int j = 0; j < e.size(); j++) {
			int u = e[j].u;
			int v = e[j].v;
			ll cost = e[j].cost;
			if (d[v] > d[u] + cost) {
				d[v] = d[u] + cost;
				fg = true;
			}
		}
		if (!fg) {		// 无法再更新 
			return true;
		}
	}
	ll tmp = d[n];
	for (int j = 0; j < e.size(); j++) {
		int u = e[j].u;
		int v = e[j].v;
		ll cost = e[j].cost;
		if (d[v] > d[u] + cost) {
			d[v] = d[u] + cost;
		}
	}
	return d[n] == tmp;
}
int main()
{/*
	#ifdef ONLINE_JUDGE
    	freopen("aplusb.in", "r", stdin);
    	freopen("aplusb.out", "w", stdout);
	#endif*/
	int m, x, y;
	ll z;
	
	scanf("%d%d", &n, &m);
	while (m--) {
		scanf("%d%d%lld", &x, &y, &z);
		e.push_back(Edge(x, y, -z));
	}
	int ans = bellman(1);
	if (ans == 0) {
		puts("inf");
	} else {
		cout << -d[n] << endl;
	}
}


Measured memory_bytes: 256
w,h,x,y,r=input().split()
w=int(w)
h=int(h)
x=int(x)
y=int(y)
r=int(r)
if w-x>=r and x-r>=0 and h-y>=r and y-r>=0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,K;
    cin>>N>>K;

    int H[N];
    int sum=0;
    rep(i,N){
        cin>>H[i];
        sum+=H[i];
    }
    sort(H,H+N);
    reverse(H,H+N);
    rep(i,min(K,N)){
        sum-=H[i];
    }
    cout << sum << endl;

    



}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>	
#include<limits>
#include<ctime>
#include<stack>	
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
	
typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}

int main() {
	ll n;
	cin>>n;
	ll a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	bool y=false;
	for(int i=0;i<n-2;i++){
		if(a[i]==b[i] and a[i+1]==b[i+1] and a[i+2]==b[i+2]){
			y=true;
			break;
		}
	}
	if(y){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N), o(1000001);
  long flag = 1;
  for(int i = 0; i < N; i++)cin >> data.at(i);
  long a;
  for(int i = 0; i < N; i++){
    a = data.at(i);
    for(int j = 2; j <= sqrt(data.at(i)); j++){
      if(a % j == 0){
        o.at(j)++;
        if(o.at(j) >= 2)flag = 0;
        while(a % j == 0)a /= j;
      }
    }
    if(a != 1)o.at(a)++;
    if(o.at(a) >= 2)flag = 0;
    if(flag == 0)break;
  }
  for(int i = 1; i <= 1000000; i++){
    if(o.at(i) >= 2)flag = 0;
  }
  if(flag == 1){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  long g = data.at(0);
  for(int i = 1; i < N; i++){
    g = __gcd(g, data.at(i));
  }
  if(g == 1){
    cout << "setwise coprime" << endl;
  } else cout << "not coprime" << endl;
  return 0;
}


Measured memory_bytes: 18772
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n;
  cin >> n;
  
  rep(i,50000){
    if(i*108/100==n){
    cout << i << endl;
    return 0;
    }
    if(i==49999) cout << ":(" << endl;
  }
  
}


Measured memory_bytes: 256
import java.util.Scanner;

//Pi is Three
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		double EPS = 1e-10;
		for(;;){
			double R = sc.nextDouble();
			if(R==0)break;
			int n = 1, d = 1;
			double min = 1<<29;
			int an = 0, ad = 1<<29;
			while(d<=ad){
				double r = Math.PI-n*1.0/d;
				double e = Math.abs(r);
				if(e<R+EPS&&e<min){
					min = e; an = n; ad = d;
				}
				if(r<0)d++;
				else n++;
			}
			System.out.println(an+"/"+ad);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

bool test(int A,int B,int m,int cnt){
	if(cnt>A)return false;
	if(m==0){
		if(B==0){
			return true;
		}else{
			return false;
		}
	}else{
		for(int i=0;m*i<=B;i++){
			if(test(A,B-m*i,m-1,cnt+i)){
				return true;
			}
		}
		return false;
	}
}

int main(){
	int X;
	cin >> X;

	int A=X/100;
	int B=X%100;

	//a+2b+3c+4d+5e=B (a+b+c+d+e<=A)
	if(test(A,B,5,0)){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    sl = list(S)

    sl[K-1] = sl[K-1].lower()

    print(''.join(sl))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    char c[3];
    int ans = 700;
    cin >> c;

    for (int i = 0; i < 3; i++) {
        if (c[i] == 'o')
            ans = ans+100;
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
  ll a,b,c;
  cin >>a>>b>>c;
  ll cnt=abs(a)/c;
  ll ans;
  if(a<=0){
    a+=cnt*c;
    if((b-cnt)%2==0){
      ans=abs(a);
    }
    else{
      ans=abs(a+c);
    }
    if(cnt>b){
      ans=abs(a-(cnt-b)*c);
    }
  }
  else{
    a-=cnt*c;
    if((b-cnt)%2==0){
      ans=abs(a);
    }
    else{
      ans=abs(a-c);
    }
    if(cnt>b){
      ans=abs(a+(cnt-b)*c);
    }
  }
  
  cout << ans <<endl;
}


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

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; ++i) cin >> A[i];
    for (int i = 0; i < Y; ++i) cin >> B[i];
    for (int i = 0; i < Z; ++i) cin >> C[i];
    
    // A + B の上位 K 個
    vector<long long> AB;
    for (int i = 0; i < X; ++i) for (int j = 0; j < Y; ++j) AB.push_back(A[i] + B[j]);
    sort(AB.begin(), AB.end(), greater<long long>());
    AB.resize(K);
    
    // AB と C
    vector<long long> ABC;
    for (int i = 0; i < AB.size(); ++i) for (int j = 0; j < Z; ++j) ABC.push_back(AB[i] + C[j]);
    sort(ABC.begin(), ABC.end(), greater<long long>());
    
    // 出力
    for (int k = 0; k < K; ++k) cout << ABC[k] << endl;
}

Measured memory_bytes: 43112
n, k = map(int, input().split(" "))
l = []
a_l = []
for i in range(n):
  a, b = map(int, input().split(" "))
  l.append((a, b))
  
l = sorted(l)
for n in l:
  if k > n[1]:
    k = k - n[1]
    continue
  else:
    ans = n[0]
    break
    
print(ans)
    

Measured memory_bytes: 17804
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <map>
#include <array>
#include <vector>
#include <set>
#include <cmath>
#include <cstdlib>

using namespace std;

int main()
{
    long long a, b, c, k;

    cin >> a >> b >> c >> k;

    if (k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
//#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}





int main() {
	int n,a=0,b=0;
	string s;
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'R') {
			a++;
		}
		else {
			b++;
		}
	}
	a > b ? cout << "Yes" << endl : cout << "No" << endl;
}



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

int main() {
  ll h,w,n,sx,sy;
  cin >> h >> w >> n >> sy >> sx;
  string s,t;
  cin >> s >> t;
  ll u=sy,l=sx,r=w-sx+1,d=h-sy+1;
  for(ll i=0;i<n;i++) {
    if(s[i]=='U') {
      u--;
    }
    if(s[i]=='L') {
      l--;
    }
    if(s[i]=='R') {
      r--;
    }
    if(s[i]=='D') {
      d--;
    }
    if(u<1||l<1||d<1||r<1) {
      cout << "NO" << endl;
      return 0;
    }
    if(t[i]=='U') {
      d=min(h,d+1);
    }
    if(t[i]=='L') {
      r=min(w,r+1);
    }
    if(t[i]=='R') {
      l=min(w,l+1);
    }
    if(t[i]=='D') {
      u=min(h,u+1);
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;

    int res = B - A;
    if(B % A == 0){
        res = A + B;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>

std::vector<long> to[200005];
std::vector<long long> ans;

void dfs(int a, int p=-1){
  //printf("a=%d\n",a);
  //printf("to[%d].size()=%ld\n",a,to[a].size());
  for (int i=0; i<to[a].size(); i++){
    if (to[a][i] == p){
      continue;
    }
    ans[to[a][i]] += ans[a];
    //printf("ans[%ld] += %ld\n",to[a][i], ans[a]);
    dfs(to[a][i], a);
  }
  return;
}

int main(){

  long N, Q;
  scanf("%ld %ld",&N, &Q);
  //printf("N=%ld, Q=%ld\n",N,Q);
  ans.resize(200005);
  int temp1, temp2;

  for (int i=0; i<N-1; i++){
    scanf("%d",&temp1);
    scanf("%d",&temp2);
    temp1--;
    temp2--;
    //printf("tp[%d].push_back(%d)\n",temp1,temp2);
    to[temp1].push_back(temp2);
    to[temp2].push_back(temp1);
  }
  //printf("to[0][0]=%ld\n",to[0][0]);
  for (int i=0; i<Q; i++){
    scanf("%d",&temp1);
    scanf("%d",&temp2);
    temp1--;
    ans[temp1] += temp2;
  }
  dfs(0);

  //printf("============\n");
  printf("%llu", ans[0]);
  for (int i=1; i<N; i++){
    printf(" %llu",ans[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
const int mod=1000003;
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int mulv[mod+100];
int main()
{
	for(int i=mulv[0]=1;i<mod;i++) mulv[i]=1ll*mulv[i-1]*i%mod;
	int T;cin>>T;
	while(T--)
	{
		int x,d,n;scanf("%d%d%d",&x,&d,&n);
		int k=1ll*x*ksm(d,mod-2)%mod;
		if(d==0){printf("%d\n",ksm(x,n));continue;}
		if(k+n-1>=mod||k==0) {puts("0");continue;}
		printf("%lld\n",1ll*ksm(d,n)*mulv[k+n-1]%mod*ksm(mulv[k-1],mod-2)%mod);
	}
}

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

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    int lowerStayDays = 0;
    int normalStayDays = 0;

    if (N >= K) {
        lowerStayDays = K;
        normalStayDays = N - K;
    } else {
        lowerStayDays = N;
    }

    int total = X * lowerStayDays + Y * normalStayDays;

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;

namespace hello_world
{
	class Program
	{
		static void Main(string[] args)
		{
			int K = int.Parse(Console.ReadLine());
			string S = Console.ReadLine();
			int s = S.Length;
			if (s <= K)
				Console.WriteLine(S);
			else
			{
				string a = S.Substring(0, K);
				Console.WriteLine(a + "...");
			}


			

		}
	}

}


Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 401;
const ll INF = 1e18;
ll dp[N][N];
ll acum[N];

ll f(int i, int j) {
    if (i == j) return 0;
    ll &r = dp[i][j];
    if (r != -1) return r;
    r = INF;
    forn(k, i, j) {
        ll a = f(i, k);
        ll b = f(k+1, j);
        ll cost = acum[j+1]-acum[i];
        r = min(r, a+b+cost);
    }
    return r;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n;
    cin >> n;
    
    forn(i, 1, n+1) {
        cin >> acum[i];
        acum[i] += acum[i-1];
    }
    
    memset(dp, -1, sizeof dp);
    cout << f(0, n-1) << endl;
}


Measured memory_bytes: 4960
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e8;

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];
    VI d(n);
    priority_queue<P, vector<P>, greater<P> > q;
    REP(i,n){
        if (a[i] == 0){
            d[i] = -INF;
            q.push(P(-INF,i));
        }
    }
    while (!q.empty()){
        P p = q.top();
        q.pop();
        int now = p.second;
        if(d[now] < p.first) continue;
        FOR(i,-1,1){
            int next = now + i;
            if (next < 0 || next >= n) continue;
            int cost = d[now] + 1;
            if (a[next] < 0) cost = max(cost, a[next]);
            if (d[next] > cost){
                d[next] = cost;
                q.push(P(d[next], next));
            }
        }
    }
    int ans = 0;
    REP(i,n){
        if (a[i] > 0){
            ans += min(a[i], -d[i]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4592
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(const pair<A,B> &p,const pair<C,D> &q){ p.X+=p.X; q.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(const pair<A,B> &p,const pair<C,D> &q){ p.X-=p.X; q.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T> T read(){ T re; cin>>re; return re;}
template<class T> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return re;}
template<class T> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return re;}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return g;}
vv<int> readG(const int &n){ return readG(n,n-1);}

const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read<int>();
	cauto g=readG(n);
	ll re=0;
	reps(i,1,n+1) re+=i*(n+1ll-i);
  rep(a,n)for(auto b:g[a])if(a<b) re-=(a+1ll)*(n-b);
	cout<<re NL;
  return 0;
}


Measured memory_bytes: 15032
#include <iostream>
using namespace std;
int N,P,cur,t=1,cnt[10010],i;char S[200010];int64_t ans;
int main()
{
    scanf("%d%d%s",&N,&P,S);
    if(P==2||P==5){
        for(i=0;i<N;i++)if((S[i]-'0')%P==0)ans+=i+1;
    }else{
        cnt[0]=1;
        for(i=N-1;i>=0;i--){
            (cur+=(S[i]-'0')*t)%=P;
            ans+=cnt[cur]++;
            t=t*10%P;
        }
    }
    printf("%lld",ans);
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}


Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
 
using namespace std;
 
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % hell;
        x=(x*x) % hell;
        n=n/2;
    }
    return result % hell;
}
 
class dsu{
    vi p,rank;
    vi set_count;
  
  public:
    dsu(int n){
        p.assign(n,0); 
        rank.assign(n,0);
        set_count.assign(n,1);
        for(int i=0;i<n;i++) p[i] = i;
    }
    int findSet(int x){
        return (p[x] == x) ? x:(p[x] = findSet(p[x]));
    }
    bool isSame(int i, int j){
        return (findSet(i) == findSet(j));
    }
    void unionSet(int i, int j){
        if(!isSame(i,j)){
            int x = findSet(i), y = findSet(j);
            if(rank[x] > rank[y]) {p[y] = x; set_count[x]+=set_count[y];}
            else{
                p[x] = y;
                set_count[y]+=set_count[x];
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
    }
    int count(int x){
        return set_count[findSet(x)];
    }
};

int S[105][105];
int T[105][105];

// code copied from god_arham
int mod_inv(int a,int m){
    a=a%m;
    return power(a,m-2)%hell;
}
int fact[200005];
void count_fact(){
    int i,x=1;
    fact[0]=1;
    for(int i=1;i<200002;i++){
        
        x=(x*i)%hell;
      //  cout<<x<<" ";
        fact[i]=x;
        
    }
}
 
int ncr(int n,int r){
    int a=fact[n],b=fact[r],c=fact[n-r];
    
    return (a*mod_inv(b*c,hell))%hell;
} 
//copied code ends here
 
signed main()
{
    tezz
 
    int a,b;
    cin>>a>>b;

    int gc = __gcd(a, b);
    cout<<(a*b)/gc;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int N, T;
	int res = INF;
	cin >> N >> T;
	REP(i, N){
		int c, t;
		cin >> c >> t;
		if(t <= T){
			chmin(res, c);
		}
	}
	if(res == INF){
		cout << "TLE" << endl;
	}else{
		cout << res << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){	if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return x*f;
}
inline void print(int x){
	if(x<0) x=-x,putchar('-');
	if(x>=10) print(x/10);
	putchar(x%10+48);
}
int n;
int a[1000010];
int pre[1000010];
int tm[1000010];
int main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=2;i<=1000000;++i){
		if(!pre[i]){
			for(int j=1;j*i<=1000000;++j) pre[i*j]=i;
		}
	}
	for(int i=1;i<=n;++i){
		int x=a[i];
		while(x!=1){
			int p=pre[x];
			while(x%p==0) x/=p;
			++tm[p];
		}
	}
	bool flag1=1,flag2=1;
	for(int i=1;i<=1000000;++i){
		if(tm[i]>1) flag1=0;
		if(tm[i]==n) flag2=0;
	}
	if(flag1) printf("pairwise coprime\n");
	else if(flag2) printf("setwise coprime\n");
	else printf("not coprime\n");
	return 0;
}

Measured memory_bytes: 15152
/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   19.04.2020
  *  Time:   17:40:16
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define debug(...) 1729
#endif

#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

int seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T, typename U>inline istream& operator >>(istream& in, pair<T, U> &a){in >> a.ff >> a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in, vector<T> &a){for(auto &x : a)in >> x;return in;}

int32_t main(int32_t argc, char **argv)
{
    #ifdef DHRUV_GHEEWALA
        std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
        start_time = std::chrono::high_resolution_clock::now();

        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m;
    cin >> n >> m;
    vi a(m);
    cin >> a;

    int sum = 0;
    for(int i = 0 ; i < m ; i++)
    	sum += a[i];

    cout << (sum > n ? -1 : n - sum) << endl;

    #ifdef DHRUV_GHEEWALA
        end_time = std::chrono::high_resolution_clock::now();
        int elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
        cerr << endl << endl;
        cerr << "Elapsed Time: " << elapsed_time << " ms" << endl;
    #endif

    return 0;
}

Measured memory_bytes: 3688