akhauriyash/Code-Regression huggingface dataset:
#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>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);

    sort(A.begin(), A.end());
    int ans = A.at(N - 1) - A.at(0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
fun main(array: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    for(i in 1..1009) {
        if(a == (i * 0.08).toInt() && b == (i * 0.1).toInt()) {
            print(i)
            return
        }
    }
    print(-1)
}

Measured memory_bytes: 37872
import java.util.Scanner;

public class Main {

    static int N, A, B, C;
	static int[] l;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[N];
        for(int i = 0; i < N; i++) {
            l[i] = sc.nextInt();
            // System.out.println("input sc >> " + l[i]);
        }
        System.out.println(cost(0,0,0,0));
        sc.close();
    }

    static int cost(int depth, int a, int b, int c){
        int INF = (int) 10e8;
        int pattern0, pattern1, pattern2, pattern3;
        if(depth == N){
            if(a>0 && b>0 && c>0){
                return Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C) - 30;
            } else {
                return INF;
            }
        }
        pattern0 = cost(depth+1, a, b, c);
        pattern1 = cost(depth+1, a+l[depth], b, c) + 10;
        pattern2 = cost(depth+1, a, b+l[depth], c) + 10;
        pattern3 = cost(depth+1, a, b, c+l[depth]) + 10;

        return Math.min(Math.min(pattern0, pattern1), Math.min(pattern2, pattern3));
    }

    Main() {

    }
}

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

#define INF 10000000

int t[101][101], s[101][101];

int main(void){
	int n,m;

	while(cin>>n>>m, n){
		for(int i=0;i<=m;i++) for(int j=0;j<=m;j++) t[i][j] = s[i][j] = INF;
		for(int i=0;i<n;i++){
			int a,b,cost,time;
			cin>>a>>b>>cost>>time;
			t[a][b] = t[b][a] = cost;
			s[a][b] = s[b][a] = time;
		}

		for(int k=1;k<=m;k++){
			for(int i=1;i<=m;i++){
				for(int j=1;j<=m;j++){
					t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
					s[i][j] = min(s[i][j],s[i][k]+s[k][j]);
				}
			}
		}

		cin>>n;
		while(n--){
			int a,b,flg;
			cin>>a>>b>>flg;
			cout<<(flg?s[a][b]:t[a][b])<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7 
#define LINF 1e15+7 
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll>a(x),b(y),c(z);
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    
    vector<ll>ab;
    rep(i,x)rep(j,y){
        ab.push_back(a[i]+b[j]);
    }
    vector<ll>abc;
    sort(ab.rbegin(),ab.rend());
    rep(i,min(k,x*y))rep(j,z){
        abc.push_back(ab[i]+c[j]);
    }
    sort(abc.rbegin(),abc.rend());
    rep(i,k){
        cout<<abc[i]<<endl;
    }
    
    return 0;
}

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

namespace ABC148D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ainput = Console.ReadLine().Split(' ');
            int[] a = new int[N];
            int search = 1;
            int num = 0;
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(ainput[i]);
                if (a[i] == search)
                {
                    num += 1;
                    search += 1;
                }
            }
            if (num == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(N - num);
            }
            
        }
    }
}


Measured memory_bytes: 43116
main :: IO ()
main = do
    input <- getLine
    if solve input then
        putStrLn "Yes"
    else
        putStrLn "No"

solve :: String -> Bool
solve input =
    case input of
        _:_:c3:c4:c5:c6:_ ->
            c3 == c4 && c5 == c6
        _ -> error "unexpected input"


Measured memory_bytes: 380
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

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

int main() {
    int a[3][3];
    bool b[3][3];
    int n;
    REP(i, 3) {
        REP(j, 3) {
            cin >> a[i][j];
            b[i][j] = false;
        }
    }
    cin >> n;
    REP(k, n) {
        int tmp;
        cin >> tmp;
        REP(i, 3) {
            REP(j, 3) {
                if (a[i][j] == tmp) {
                    b[i][j] = true;
                }
            }
        }
    }
    // yoko
    REP(i, 3) {
        bool all = true;
        REP(j, 3) {
            if (!b[i][j]) {
                all = false;
            }
        }
        if (all) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    // tate
    REP(j, 3) {
        bool all = true;
        REP(i, 3) {
            if (!b[i][j]) {
                all = false;
            }
        }
        if (all) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    // naname
    if ((b[0][0] && b[1][1] && b[2][2]) || (b[0][2] && b[1][1] && b[2][0])) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    ta = a[0]
    res = 0
    while ta % 2 == 0:
        res += 1
        ta //= 2
    for sa in a:
        tres = 0
        while sa % 2 == 0:
            tres += 1
            sa //= 2
        if res != tres:
            return 0
    hc = 1
    m2 = m*2
    for i in range(n):
        hc = (hc*a[i])//gcd(hc,a[i])
        if hc > m2:
            return 0
    hc //= 2
    ret = m // hc
    return (ret+1)//2

print(main())

Measured memory_bytes: 89580
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,G; cin>>N>>G;
    vint p(N),c(N);
    REP(i,N) cin>>p[i]>>c[i];

    int ans=1e9;
    REP(S,1<<N){
        int sum=0,cnt=0;
        REP(i,N) if(S>>i&1){
            sum+=100*(i+1)*p[i]+c[i];
            cnt+=p[i];
        }
        for(int i=N-1;i>=0;i--){
            if(S>>i&1) continue;
            if(sum<G){
                int x=G-sum;
                int y=100*(i+1);
                int z=min(p[i]-1,(x+y-1)/y);
                sum+=y*z;
                cnt+=z;
            }
        }
        if(sum>=G) ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		List<String> ss = new ArrayList<String>();

		try {
			ss.add(sc.next());
			ss.add(sc.next());
			ss.add(sc.next());
			Collections.sort(ss);

			for (int i = 0; i < 3; i++) {
				if ((i == 0 || i == 1) && !"5".equals(ss.get(i))) {
					System.out.println("NO");
					throw new Exception();
				} else if (i == 3 && !"7".equals(ss.get(i))) {
					System.out.println("NO");
					throw new Exception();
				}
			}
			System.out.println("YES");
		} catch (Exception e) {

		} finally {
			sc.close();
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>


using namespace std;

long long modexp(long long x, long long n, long long mod)
{
    if (n == 0) {
        return 1;
    }

    if (n % 2 == 0) {
        return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod)) % mod;
    }
    return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod) * x) % mod;
}



int main()
{
    int k, s;
    cin >> k >> s;
    int x, y, z;
    int i, j,l,count=0;
    for (i = 0; i <= k; ++i) {
        for (j = 0; j <= k; ++j) {
            if (i + j <= s && i+j>=s-k) {
                count++;
            }
        }
    }
    cout << count;

}

    




        


Measured memory_bytes: 256
N, M = map(int, input().split())
AC = [0] * N
WA = [0] * N
for _ in range(M):
  p, s = input().split()
  p = int(p) - 1
  if s == 'AC':
    AC[p] = 1
  elif AC[p] < 1:
    WA[p] += 1
WA = [w if AC[p] else 0 for p, w in enumerate(WA)]
print(sum(AC), sum(WA))

Measured memory_bytes: 5424
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static String[] x;
    static String[] y;
    static String temp;
	public static void main(String[] args)throws IOException{
		Scanner sc = new Scanner(System.in);
		x = sc.nextLine().split(" ");
		y = sc.nextLine().split(" ");
		char[] c = { 'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S' };

		boolean flag = false;
		for(int i=0;i<3;i++){
			for(char d:c){
				roll(d);
				if(Arrays.equals(x, y)){
					flag=true;
					break;
				}
			}
		}
		if(flag){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	public static void roll(char c) {
        switch (c) {
            case 'E':
                    temp = x[0];
                x[0] = x[3];
                x[3] = x[5];
                x[5] = x[2];
                x[2] = temp;
                break;
            case 'N':
                temp = x[0];
                x[0] = x[1];
                x[1] = x[5];
                x[5] = x[4];
                x[4] = temp;
                break;
            case 'W':
                temp = x[0];
                x[0] = x[2];
                x[2] = x[5];
                x[5] = x[3];
                x[3] = temp;
                break;
            default:
                temp = x[0];
                x[0] = x[4];
                x[4] = x[5];
                x[5] = x[1];
                x[1] = temp;
                break;
        }
    }
}

Measured memory_bytes: 26228
#include <stdio.h>
int main(void) {
	int a, b;
	char s[11], t[11], u[11];
	scanf("%s", s);
	scanf("%s", t);
	scanf("%d%d", &a, &b);
	scanf("%s", u);
	int i = 0;
	while (u[i] != 0) {
		if (u[i] != s[i]) {
			printf("%d %d\n", a, b - 1);
			return 0;
		}
		i++;
	}
	printf("%d %d\n", a - 1, b);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll s(vector<int>A)
{
	ll res=0;
	queue<int> q;
	map<int,bool>m;
	int l=0,r=A.size()-1;
	q.push(l);
	q.push(l);
	l++;
	while(!q.empty())
	{
		if(r<l)
		{
			break;
		}
		int np=q.front();q.pop();
		if(abs(r-np)>abs(l-np))
		{
			res+=abs(A[r]-A[np]);
			if(!m[r])
			{
				m[r]=true;
				q.push(r--);
			}
		}
		else
		{
			res+=abs(A[l]-A[np]);
			if(!m[l])
			{
				m[l]=true;
				q.push(l++);
			}

		}
	}
	return res;
}

ll s2(vector<int>A)
{
	ll res=0;
	queue<int> q;
	map<int,bool>m;
	map<int,bool>f;
	int l=0,r=A.size()-1;
	q.push(r);
	q.push(r);
	r--;
	while(!q.empty())
	{
		if(r<l)
		{
			break;
		}
		int np=q.front();q.pop();
		if(abs(r-np)>abs(l-np))
		{
			res+=abs(A[r]-A[np]);
			if(!m[r])
			{
				m[r]=true;
				q.push(r--);
			}
		}
		else
		{
			res+=abs(A[l]-A[np]);
			if(!m[l])
			{
				m[l]=true;
				q.push(l++);
			}
		}
	}
	return res;
}


int main()
{
	int N;
	cin>>N;
	vector<int>A;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		A.push_back(a);
	}
	sort(A.begin(),A.end());
	cout<<max(s(A),s2(A))<<endl;
	
}

Measured memory_bytes: 6192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 10000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
void allcout(auto V) {
    for(auto x : V) cout << x << ' ';
    cout << endl;
}
vector<int> Ans;
void dfs(int n, int s) {
    int m = n % 10;
    Ans.push_back(n);
    if(s < 10) {
        dfs(n * 10 + m, s + 1);
        if(m > 0) dfs(n * 10 + m - 1, s + 1);
        if(m < 9) dfs(n * 10 + m + 1, s + 1);
    }
}
int judge(int n, int k) {
    while(n % k == 0) n /= k;
    if(n % k == 1) return true;
    return false;
}
signed main() {
    int ans = 0;
    int N;
    cin >> N;
    for(int i = 1; i * i <= N - 1; i++) {
        if((N - 1) % i == 0) {
            if(i * i == N - 1)
                ans++;
            else
                ans += 2;
        }
    }
    ans--;
    for(int i = 2; i * i <= N; i++) {
        if(N % i == 0) {
            if(i * i == N) {
                ans++;
            } else {
                if(judge(N, i)) ans++;
                if(judge(N, N / i)) ans++;
            }
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int linerSearch(int A[], int n, int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)
    i++;
  return i;
}

int main(){
  int i=0, n, A[10000], q, key, sum=0;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if((linerSearch(A,n,key))!=n)
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2052
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

main :: IO ()
main = do
  [x,t] <- getIntList
  print $ (x - t) `max` 0


Measured memory_bytes: 508
n = int(input())
a = [input() for i in range(n)]
ans = 'Yes'
for i in range(n):
    if a.count(a[i])!=1:
        ans = 'No'
        break
for i in range(n-1):
    if a[i][-1] != a[i+1][0]:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  ans += n / 500 * 1000;
  ans += n % 500 / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
a = [int(input()) for _ in range(N)]
b = [a[-1]]
for i in range(2, N+1):
    x = a[-i]
    index = bisect.bisect_right(b, x)
    if index == len(b):
        b.append(x)
    else:
        b[index] = x
print(len(b))    
    

Measured memory_bytes: 84420
#include<vector>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
	char s[15];
	scanf("%s",s);
	if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

using i64 = long long;
using pll = pair<i64, i64>;

const int N = 128;

set<int> g[N], og[N];
int far[N], lvl[N], sons[N];

vector<int> dchain;
int n;

static void get_diameter() {
	int slut, diam;

	function<void(int, int, int)> dfs1 = [&](int u, int pap, int tdist) {
		if (tdist > diam) {
			diam = tdist;
			slut = u; }
		for (auto v: g[u]) if (v != pap)
			dfs1(v, u, tdist + 1); };

	function<void(int, int, int)> dfs2 = [&](int u, int pap, int tdist) {
		if (tdist > diam) {
			diam = tdist;
			slut = u; }
		far[u] = pap;
		for (auto v: g[u]) if (v != pap)
			dfs2(v, u, tdist + 1); };

	diam = -1;
	dfs1(1, 0, 1);
	diam = -1;
	dfs2(slut, 0, 1);

	dchain.clear();
	while (slut) {
		dchain.push_back(slut);
		slut = far[slut]; } }

static void bfs(int a, int b) {
	deque<int> dq;
	int u;

	for (int i = 1; i <= n; ++i)
		lvl[i] = 0;

	dq.push_back(a);
	if (a != b)
		dq.push_back(b);
	lvl[a] = lvl[b] = 1;

	while (!dq.empty()) {
		u = dq.front();
		dq.pop_front();
		for (auto v: g[u]) if (!lvl[v]) {
			lvl[v] = lvl[u] + 1;
			dq.push_back(v); } } }


static pll solve0(int a = 0, int b = 0) {
	pll ant;

	if (n == 2)
		return {1, 2};

	get_diameter();
	if (!a && !b) {
		a = dchain[dchain.size() / 2];
		b = dchain[dchain.size() / 2 - (1 - dchain.size() % 2)]; }

	bfs(a, b);
	for (int i = 0; i <= n; ++i)
		sons[i] = 0;
	for (int i = 1; i <= n; ++i)
		sons[lvl[i]] = max(sons[lvl[i]], int(g[i].size() - 1));

	ant.first = (1 + dchain.size()) / 2;
	ant.second = 1;
	for (int i = 2; i <= n; ++i)
		ant.second*= max(1, sons[i]);

	if (a != b)
		ant.second*= (max(g[a].size(), g[b].size()) - 1) * 2;
	else
		ant.second*= g[a].size();

	return ant; }

static pll solve1() {
	pll ant = solve0();
	int mid = dchain[dchain.size() / 2];

	for (auto v: g[mid])
		ant = min(ant, solve0(mid, v));

	return ant; }

int main() {
#ifdef HOME
	freopen("agc24d.in", "r", stdin);
	freopen("agc24d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	pll ant;

	cin >> n;
	for (int a, b, i = 1; i < n; ++i) {
		cin >> a >> b;
		g[a].insert(b);
		g[b].insert(a); }

	get_diameter();
	if (dchain.size() % 2)
		ant = solve1();
	else
		ant = solve0();

	cout << ant.first << ' ' << ant.second << '\n';

	return 0; }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
int a[110];
signed main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }

    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }

    cout<<"APPROVED"<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

itn X;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> X;
    int ans = 0;
    ans += (X / 500) * 1000;
    X %= 500;
    ans += (X / 5) * 5;
    cout << ans << endl;


    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int N,S;
    cin>>N>>S;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    ll mod=998244353;
    vector<vector<ll>> dp(N+1,vector<ll>(S+1,0));
    dp[0][0]=1;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=S;j++){
            dp[i][j]=(dp[i-1][j]*2)%mod;
            if(j>=A[i-1]){
                dp[i][j]+=dp[i-1][j-A[i-1]];
                dp[i][j]%=mod;
            }
        }
    }
/*
    for(int i=0;i<=N;i++){
        for(int j=0;j<=S;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    //*/

    cout<<dp[N][S]<<endl;

    return 0;
}

Measured memory_bytes: 73736
N,K=map(int,input().split())
S=input()
a=[0]
for i in range(1,N):
  if S[i-1]!=S[i]:
    a.append(i)
a.append(N)
l=len(a)
ans=[]
for i in range(l-1):
  if S[a[i]]=='0':
    ans.append(a[min(i+2*K,l-1)]-a[i])
  else:
    ans.append(a[min(i+2*K+1,l-1)]-a[i])
print(max(ans))


Measured memory_bytes: 16944
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    i64 H, W, K;
    cin >> H >> W >> K;

    bool able = false;

    reps(h, 0, H) reps(w, 0, W) {
        able |= (H*w + h*W - 2*h*w == K);
    }

    print((able) ? "Yes" : "No");

    return 0;
}


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

int main(){
    long a,b,c;
    cin >> a >> b >> c;
    int ans;
    if (a+b >= c){
        ans = b + c;
    }
    else{
        ans = a + 2*b + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: i64,
        a: [i64; n],
    }
    let mut b = a.clone();

    if b[0] > x {
        b[0] = x;
    }
    for i in 1..n {
        let acc = b[i-1] + b[i];
        if acc > x {
            b[i] -= acc - x;
        }
    }

    let mut cnt = 0;
    for i in 0..n {
        cnt += a[i] - b[i];
    }
    println!("{}", cnt);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
lli x(lli i, lli j, lli a[], lli b[], lli c[])
{
	if(j == 0)
      	return a[i];
 	else if(j == 1)	
      	return b[i];
  	else
      	return c[i];
}

int main(){
  lli n;
  cin >> n;
  lli a[n], b[n], c[n];
  for(lli i = 0; i<n;i++)
    {
    cin >> a[i] >> b[i] >> c[i];
  }
  lli dp[n][3];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  
  for(lli i = 1; i<n; i++)
    {
        for(lli j = 0; j < 3; j++)
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + x(i,j, a, b, c);
                   
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  }


Measured memory_bytes: 4992
N = int(input())
b = list(map(int, input().split()))

ans = []

for i in range(N):
    L = -1
    for j in range(len(b)):
        if j+1 == b[j]:
            L = j

    if L != -1:
        ansi = b.pop(L)
        ans.append(ansi)

if len(ans) != N:
    print(-1)
else:
    ans = list(reversed(ans))
    for a in ans:
        print(a)


Measured memory_bytes: 9208
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int[] inp = IntLine();
        int N = inp[0], W = inp[1];
        long[] w = new long[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++)
        {
            long[] box = LongLine();
            w[i] = box[0];
            v[i] = box[1];
        }
        long[] dp = new long[1000100];
        for (int i = 0; i < 1000100; i++) dp[i] = INF;
        dp[0] = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 1000000; j >= 0; j--)
            {
                if (dp[j] != INF)
                {
                    dp[j+v[i]] = Math.Min(dp[j+v[i]], dp[j] + w[i]);
                }
            }
        }
        for (int i = 1000000; i != 0; i--)
        {
            if (dp[i] <= W && dp[i] != INF)
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}



public class Atcoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int GCD(int a, int b)
    {
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(int a, int b)
    {
        return (long)a * b / GCD(a, b);
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static long Combination(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r + 1), r).ToList().Aggregate((now, next) => now * next) /
            Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next);
    }
    public static long Permutation(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r), r).ToList().Aggregate((now, next) => now * next);
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


Measured memory_bytes: 20960
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;
typedef pair<int,bool> Pair;

int main(){

  int ans = 0;
  string S,T;
	
  cin >> S;
  cin >> T;
	
  for(int i =0;i < 3;++i){
    if(S[i] == T[i]){
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll ans,mn,mx;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<n; i++){
		mx=max(mx,a[i]);
		if(a[i] >= mx) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int A,B,C,D,st,en;
  cin>>A>>B>>C>>D;
  st=max(A,C);
  en=min(B,D);
  if(en-st<0) cout<<"0"<<endl;
  else cout<<en-st<<endl;
}


Measured memory_bytes: 256
import heapq



N = int(input())
xy = [None] * N
yx = [None] * N

for i in range(N):
    x,y = map(int, input().split())
    xy[i] = (x, y, i)
    yx[i] = (y, x, i)


xy.sort()
yx.sort()


es = [[] for _ in range(N)]
for i in range(N-1):
    heapq.heappush(es[xy[i][2]], (abs(xy[i][0] - xy[i+1][0]), xy[i+1][2]))
    heapq.heappush(es[xy[i+1][2]], (abs(xy[i][0] - xy[i+1][0]), xy[i][2]))

    heapq.heappush(es[yx[i][2]], (abs(yx[i][0] - yx[i+1][0]), yx[i+1][2]))
    heapq.heappush(es[yx[i+1][2]], (abs(yx[i][0] - yx[i+1][0]), yx[i][2]))


used = [False] * N
used[0] = True
ans = 0

q = []
for c,nxt in es[0]:
    heapq.heappush(q, (c, nxt))

while q:
    c, curr = heapq.heappop(q)
    
    if used[curr]:
        continue

    used[curr] = True
    for nc, nxt in es[curr]:
        if not used[nxt]:
            heapq.heappush(q, (nc, nxt))
    ans += c

print(ans)

Measured memory_bytes: 86224
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];


int a[105];
int n,k,d,x;

void input() {
  cin >> n >> k;
  for (int i = 1; i<=k; i++) {
    cin >> d; // d=3 x=2,3,4
    while(d--){ // d=3 の時（最初の一回目）→dがなくなるまで
      cin >> x; // x=2
      a[x]++; // a[0しかない]　→　a[2]=0 →　aの２番目が1つあった。
    }
  }
}

void calc() {
  int ans =0;
  for (int i=1; i<=n;i++) {
    if (a[i]==0) ans++;
  }
  cout << ans << endl;
}

int main() {
  input();
  calc();
  return 0;
}


Measured memory_bytes: 3592
from copy import deepcopy 
h,w,k=map(int,input().split())
c=[list(input()) for i in range(h)]

tate=[]
yoko=[]
for i in range(1<<h):
  t=[]
  for j in range(h):
    if i&(1<<j):
      t.append(1)
    else:
      t.append(0)
  tate.append(t)
for i in range(1<<w):
  t=[]
  for j in range(w):
    if i&(1<<j):
      t.append(1)
    else:
      t.append(0)
  yoko.append(t)
ans=0
# print(tate)
# print(yoko)
for i in range(len(tate)):
  for j in range(len(yoko)):
    tt=[]
    tt=deepcopy(c)
    t_cnt=0
    t_tate=tate[i]
    t_yoko=yoko[j]
    # print(t_tate)
    # print(t_yoko)
    for a in range(len(t_tate)):
      if t_tate[a]==1:
        for b in range(w):
          tt[a][b]="@"
    for a in range(len(t_yoko)):
      if t_yoko[a]==1:
        for b in range(h):
          tt[b][a]="@"
    for a in range(h):
      for b in range(w):
        if tt[a][b]=="#":
          t_cnt+=1
    # print(tt)  
    if t_cnt==k:
      ans+=1
print(ans)


# h,w,k=map(int,input().split())
# c=[list(input()) for i in range(h)]
# ans=0
# tt=c[:]
# for i in range(1<<h):
#   t=tt
#   t_cnt=0
#   for a in range(h):
#     if i%(1<<a):
#       for b in range(w):
#         t[a][b]="@"
#   for j in range(1<<w):
#     for a in range(w):
#       if j%(1<<a):
#         for b in range(h):
#           t[b][a]="@"
#   for c in range(h):
#     for d in range(w):
#       if t[c][d]=="#":
#         t_cnt+=1
#   if t_cnt==k:
#     ans+=1
# print(ans)



Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int h, n; cin >> h >> n;
    vector<int> as(n), bs(n);
    for(int i=0; i<n; ++i){
        cin >> as[i] >> bs[i];
    }
    vector<int> dp(h+1);
    for(int i=1; i<=h; ++i){
        int x=numeric_limits<int>::max();
        for(int j=0; j<n; ++j){
            if(as[j]>=i){
                x=min(x, bs[j]);
            } else{
                x=min(x, bs[j]+dp[i-as[j]]);
            }
        }
        dp[i]=x;
    }
    cout << dp[h] << endl;
    return 0;
}


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

int main(){
  string s; cin >> s;
  int k; cin >> k; 

  for(int i=0; i<s.length(); i++){
    if(s[i] == 'a') continue;
    int ch = 26 - (s[i] - 'a');
    if(ch <= k){
      s[i] = 'a';
      k -= ch;
    }
  }

  s[s.size()-1] = (s[s.size()-1] - 'a' + k) % 26 + 'a';

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 512
local mod = 998244353
local mma, mmi = math.max, math.min
local mfl = math.floor

local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local n = io.read("*n")
local a = {}
local tot = 0
for i = 1, n do
  a[i] = io.read("*n")
  tot = tot + a[i]
end
local htot = mfl(tot / 2)
local dp = {}
local single = {}
local curmax = 0
for i = 1, htot do
  dp[i] = 0
  single[i] = 0
end
for i = 1, n do
  local ai = a[i]
  local lim = mmi(curmax, htot - ai)
  for j = lim, 1, -1 do
    dp[j + ai] = badd(dp[j + ai], bmul(2, dp[j]))
    single[j + ai] = badd(single[j + ai], single[j])
  end
  if ai <= htot then
    dp[ai] = badd(dp[ai], 2)
    single[ai] = badd(single[ai], 1)
  end
  curmax = curmax + ai
end
local ret = modpow(3, n)
if tot % 2 == 0 then
  local rmsum = 1
  for i = 1, htot do
    rmsum = badd(rmsum, dp[i])
  end
  rmsum = bsub(rmsum, single[htot])
  rmsum = bmul(rmsum, 3)
  ret = bsub(ret, rmsum)
else
  local rmsum = 1
  for i = 1, htot do
    rmsum = badd(rmsum, dp[i])
  end
  rmsum = bmul(rmsum, 3)
  ret = bsub(ret, rmsum)
end
print(ret)


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int a,b;
    int m,c;
    while(scanf("%d %d",&a,&b)!=EOF){
        m=a+b;
        c=0;
        for(;;){
            c++;
            if((m/=10)==0)break;
        }
        printf("%d\n",c);
    }
    return 0;
}

Measured memory_bytes: 2716
import math
a, b , h, m = map(int, input().split())
xa = a * math.sin((h+(m/60))/6*math.pi)
ya = a * math.cos((h+(m/60))/6*math.pi)
xb = b * math.sin(m/30*math.pi)
yb = b * math.cos(m/30*math.pi)
print(math.sqrt((xa-xb)**2 + (ya-yb)**2))

Measured memory_bytes: 9576
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int n, right_low[200005];
ll DP[200005], arr[200005];


int main(){

    ios_base::sync_with_stdio(0);

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>arr[i];

    stack<int> st;
    right_low[n] = n+1;
    st.push(n);
    for(int i=n-1;i>=1;i--){
        while(!st.empty() && arr[st.top()] >= arr[i])
            st.pop();
        if(st.empty())  right_low[i] = n+1;
        else    right_low[i] = st.top();
        st.push(i);
    }

// for(int i=1;i<=n;i++)   cout<<right_low[i]<<" ";cout<<endl;

    DP[n] = arr[n];
    for(int i=n-1;i>=1;i--){
        DP[i] = (right_low[i]-i)*arr[i] + DP[right_low[i]];
    }

    ll ans = 0;
    ans = accumulate(DP+1, DP+n+1, 0LL);
    cout<<ans;
    return 0;
}






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

int main() {
	int N, S; cin >> N >> S;
	vector<int>as(N);
	for (int i = 0; i < N; ++i)cin >> as[i];
	auto it = as.begin();auto jt = as.begin();
	int sum = 0;
	int ans = int(1e6);
	while (jt != as.end()) {
		sum += *jt;
		jt++;
		while (sum >= S) {
			ans = min(ans, int(jt - it));
			sum -= *it;
			it++;
		}
		 
	}
	if (ans == int(1e6))ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3132
# coding: utf-8
import sys
import numpy as np
from itertools import permutations

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, C = lr()
feeling = np.array([lr() for _ in range(C)])
Cij = [lr() for _ in range(N)]
three = [[0] * C for _ in range(3)]
for i in range(N):
    for j in range(N):
        remain = (i+j) % 3
        num = Cij[i][j] - 1
        three[remain][num] += 1

three = np.array(three)
answer = 10 ** 10
for X in permutations(range(C), 3):
    temp = 0
    for i in range(3):
        # X[i]の色にする
        x = X[i]
        y = feeling[:, x]
        temp += (three[i] * y).sum()
    if temp < answer:
        answer = temp

print(answer)
# 13

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b=LI()
  c=1
  ans=0
  while True:
    if c>=b:
      return ans
    ans+=1
    c-=1
    c+=a

# main()
print(main())


Measured memory_bytes: 6828
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int k,x; 
  cin >> k >> x;
  
  if(500 * k >= x) cout << "Yes" << endl;
  else cout << "No" << endl;

  
}

Measured memory_bytes: 3592
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);*/
        string temp = ReadLine();
        int a = 0;
        for(int i=0;i<4;i++){
            if(temp[i] == '+'){
                a++;
            }else{
                a--;
            }
        }
        WriteLine(a);
    }
}

Measured memory_bytes: 11220
from collections import Counter

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

count = [0]*(N+1)

for a in A:
    count[a] += 1

sum_ = sum(map(lambda x: int(x*(x-1)/2), count))

ans = []

for a in A:
    temp = sum_ - (count[a] - 1)
    ans.append(temp)

print(*ans, sep='\n')


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const int mod = 1000000007;

struct UnionFind {
    vector<int> par;

    UnionFind(int n)
        : par(n, -1)
    {
    }
    void init(int n) { par.assign(n, -1); }

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    int N, K, L;
    cin >> N >> K >> L;
    UnionFind uf1(N), uf2(N);
    for (int i = 0; i < K; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf1.merge(a, b);
    }
    for (int i = 0; i < L; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf2.merge(a, b);
    }

    using pint = pair<int, int>;
    map<pint, int> ma;
    for (int v = 0; v < N; v++) {
        pint p(uf1.root(v), uf2.root(v));
        ma[p]++;
    }
    for (int v = 0; v < N; v++) {
        pint p(uf1.root(v), uf2.root(v));
        cout << ma[p] << " ";
    }

    return 0;
}


Measured memory_bytes: 15972
#include <stdio.h>
#include <stdlib.h>//atoi 文字列の数字をint型の数値にする
#include <string.h>
int top,S[1000];

int push(int x){
  S[++top]=x;
  //notS[top++] sがゼロの時に処理してしまうから

}
int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top = 0;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    } else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#define ll long long
using namespace std;
const int N=2e5+10;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int main(int argc, char const *argv[])
{
	io();
	int n;
	cin>>n;
	if(n%1000==0)cout<<0<<endl;
	else cout<<1000-n%1000<<endl;
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i) 
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int R = 1000000000;
	int L = 0;
	int a = 0;
	int b = 0;
	int n;
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		L = max(L, a);
		R = min(R, b);
    }
	ll ans = max(R - L + 1,0);
	cout << ((ans > n) ? n : ans) << endl;
	return 0;
}

Measured memory_bytes: 888