akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

void solve (int N, int line[]){
    unsigned long long int tally = 0;
    int tallest = 0;
    for (int i = 0; i < N; ++i){
        tallest = max(tallest, line[i]);
        tally += max((tallest - line[i]), 0);
    }
    cout << tally << "\n";
}

int main(){
    int N;
    cin >> N;
    int line[N];
    for (int i = 0; i < N; ++i){
        cin >> line[i];
    }
    solve(N, line);
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


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

    int len=s.size();
    string ss="",s1="";
    ss+=s[0];
    int cnt=1;
    for(int i=1; i<len; i++){
        s1+=s[i];
        if(ss!=s1){
          cnt++;
          ss=s1;
          s1="";
        }
    }
    pf("%d\n",cnt);


    return 0;
}


Measured memory_bytes: 640
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

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


    t += "$";
    p += "$";

    vector<bool> exists(p.size());
    bool duplicated = false;
    int i = 0;
    char tmp = '!';
    // P: aab, T: aaab ??????????????´???, ????????? a ??? OK ??????, 2????????? a ???????????????
    for (char j : t) {
        // ?????¨??????????????????????????¨?????´??????, ????????????????????????????????£????????????
        if (p[i] == j && !exists[i]) {
            exists[i] = true;
            // ?????????????´¢?????????????????????
            tmp = p[i];
            i += 1;
        }
        // ???????????????
        else if (tmp == j) {
            duplicated = true;
        }
        else if (exists[i]) {
            i += 1;
            cout << "aa" << endl;
        }
    }

    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}

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


int main(){
    int x,a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https[i]://blog.cs[i]dn.net/Pig_cfbs[i]l 
	> Created Time: 2020/5/2 20:44:09
 ************************************************************************/
#include<map>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int cnt=0;
char s[100010][10],ans[100010];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int n=read(),a=read(),b=read(),c=read();
	For(i,1,n) scanf("%s",s[i]);
	For(i,1,n){
		if(s[i][0]=='A'){
			if(s[i][1]=='B'){
				if(a>b ||(a==b && s[i+1][0]=='B')){
					a--;
					b++;
					ans[++cnt]='B';
				}
				else{
					a++;
					b--;
					ans[++cnt]='A';
				}
			}
			else{
				if(s[i][1]=='C'){
					if(a>c || (a==c && s[i+1][1]=='C')){
						a--;
						c++;
						ans[++cnt]='C';
					}
					else{
						a++;
						c--;
						ans[++cnt]='A';
					}
				}
			}
		}
		else{
			if(b>c || (b==c && s[i+1][1]=='C')){
				b--;
				c++;
				ans[++cnt]='C';

			}
			else{
				b++;
				c--;
				ans[++cnt]='B';
			}
		}
		if(a<0 || b<0 || c<0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	For(i,1,cnt)
		printf("%c\n",ans[i]);
	return 0;
}


Measured memory_bytes: 4852
package main

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

func main() {
	N := nextInt()
	A := nextInt64()
	B := nextInt64()

	X := make([]int64, N)
	for i := 0; i < N; i++ {
		X[i] = nextInt64()
	}

	s := int64(0)

	for i := 1; i < N; i++ {
		s += min((X[i]-X[i-1])*A, B)
	}

	fmt.Println(s)
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 5212
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>

int main() {
	int k, n; std::cin >> k >> n;
	std::vector<int> position(n); for (auto& p : position) std::cin >> p;
	position.push_back(k + position.front());
	int max = 0;
	for (auto i = 1; i < position.size(); ++i) {
		max = std::max(max, position[i] - position[i - 1]);
	}
	std::cout << k - max << std::endl;
}


Measured memory_bytes: 2424
using System;

class Program {
  static void Main(){
    int[] a = new int[5];
    int ave=0;
    for(int i=0;i<a.Length;i++){
      a[i] = int.Parse(Console.ReadLine());
      if(a[i] < 40){
        ave += 40;
      }
      else{
        ave += a[i];
      }
    }
    ave /= a.Length;
    Console.WriteLine("{0}",ave);
  }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

namespace mp = boost::multiprecision;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 405;

int H, W;
char field[MAX_N][MAX_N];

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

bool isInField(int x, int y) {
  return 0 <= x && x < W && 0 <= y && y < H;
}

int ans[MAX_N][MAX_N];

void bfs(int x, int y) 
{
  using II = pair<int, int>;
  using TT = pair<II, int>;

  queue<TT> que;
  que.push(TT(II(x, y), 1));
  used[y][x] = true;

  int ret = 0;
  vector<II> vec;
  vec.push_back(II(x, y));

  while(que.size()) {
    TT p = que.front(); que.pop();
    x = p.first.first; y = p.first.second;
    int turn = p.second;
    int nextTurn = (turn+1)%2;

    for(int d = 0; d < 4; d++) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      if(isInField(nx, ny)) {
        if(nextTurn == 0) {
          if(!used[ny][nx] && field[ny][nx] == '.') {
            used[ny][nx] = true;
            que.push(TT(II(nx, ny), nextTurn));
            ret++;
          }
        }
        if(nextTurn == 1) {
          if(!used[ny][nx] && field[ny][nx] == '#') {
            used[ny][nx] = true;
            que.push(TT(II(nx, ny), nextTurn));
            vec.push_back(II(nx, ny));
          }
        }
      }
    }
  }

  for(II v : vec) {
    ans[v.second][v.first] = ret;
  }
}

signed main()
{
  cin >> H >> W;
  REP(h,H) {
    REP(w,W) {
      cin >> field[h][w];
    }
  }

  int ret = 0;
  REP(h,H) {
    REP(w,W) {
      if(!used[h][w] && field[h][w] == '#') {
        bfs(w,h);
      }
      if(field[h][w] == '#') {
        // cerr << h << " " << w << " " << ans[h][w] << endl;
        ret += ans[h][w];
      }
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long li;

const int maxn = 1e5;

int n;
char s[maxn + 1];

int main(void) {
  scanf("%s", s);
  n = strlen(s);

  int ans = n;
  for (int c = 0; c < 26; ++c) {
    if (count(s, s + n, c + 'a') == 0) continue;
    int max_len = 0;
    for (int i = 0; i < n; ) {
      if (s[i] == c + 'a') {
        ++i;
        continue;
      }

      int j = i;
      while (j < n && s[j] != c + 'a') ++j;
      max_len = max(max_len, j - i);
      i = j;
    }
    ans = min(ans, max_len);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
ans = 1

Flag = False

if 0 in A:
  Flag = True
else:
  for i in A:
    if ans <= 10**18:
      ans *= i
    else:
      break

if Flag:
  print(0)
elif ans <= 10**18:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 21700
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/



  int x;

  cin>>x;

  if(x>=1200){
    cout<<"ARC"<<endl;
  }else{

    cout<<"ABC"<<endl;

  }
  return 0;

}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long int N,K;
    cin>>N>>K;
    long long int min=N;
    long long int s=N/K;
    if(min>=N-s*K){
        min=N-s*K;
    }
    long long int t=abs((N-s*K)-K);
    if(min>=t){
        min=t;
    }
    cout<<min<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long int a,b,k;
    
    scanf("%ld%ld%ld",&a,&b,&k);
    a-=k;
    if(a<=0){
        b+=a; a=0;
    }
    if(b<0)
        b=0;
    printf("%ld %ld\n",a,b);
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = readLine.split(" ").map(_.toInt)
        println(mergeSort(arr, 0, len - 1))
    }
    def mergeSort(arr: Array[Int], left: Int, right: Int): Long = {
        if (left < right) {
            val mid = (right + left) / 2
            val r1 = mergeSort(arr, left, mid)
            val r2 = mergeSort(arr, mid + 1, right)
            val r3 = merge(arr, left, mid, right)
            r1 + r2 + r3
        } else {
            0
        }
    }
    def merge(arr: Array[Int], left: Int, mid: Int, right: Int): Long = {
        var reverse = 0L
        val tmp = arr.slice(left, mid + 1) // 左側を一時配列にコピー
        var leftPtr = 0
        var rightPtr = mid + 1
        for (i <- (left to right)) {
            if (leftPtr >= tmp.length) {
                // 左側を使い切った場合 : 交換の必要なし
                rightPtr += 1
            } else if (rightPtr  > right) {
                // 右側を使い切った場合
                arr(i) = tmp(leftPtr)
                leftPtr += 1
            } else {
                if (arr(rightPtr) < tmp(leftPtr)){
                    arr(i) = arr(rightPtr)
                    rightPtr += 1
                    reverse += tmp.length.toLong - leftPtr.toLong
                } else {
                    arr(i) = tmp(leftPtr)
                    leftPtr += 1
                }
            }
        }
        reverse
    }
}


Measured memory_bytes: 153324
from math import factorial
def tempcalc(lst, N):
    templst = [i for i in range(1, N + 1)]
    ord = (lst[0] - 1) * factorial(N - 1) + 1
    templst.remove(lst[0])

    for i in range(N - 1):
        ord += (templst.index(lst[i + 1]) - 1) * factorial(N - i - 2)
        templst.remove(lst[i + 1])
    return ord

def CountOrder():
    N = int(input())
    P = []
    Q = []
    for _ in range(1):
        P = list(map(int, input().split()))
        Q = list(map(int, input().split()))


    ord = abs(tempcalc(P, N) - tempcalc(Q, N))

    print(ord)

CountOrder()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      	int i,j;
        int c[][] = new int[3][3];
      	int check = 0;
        int a[] = new int[3];
        int b[] = new int[3];      
        for(i = 0;i<3;i++){
         for(j=0;j<3;j++){
           c[i][j] = sc.nextInt();
         }
        }
      
        if(c[0][0] == 0){
          a[0] = 0;
          b[0] = c[0][0];
          a[1] = c[1][0] - b[0];
          a[2] = c[2][0] - b[0];
			for(j = 0;j< 3;j++){
                if(c[0][j] - a[0] != c[1][j] - a[1] || c[1][j] - a[1] != c[2][j] - a[2]){
                       System.out.println("No"); 
               		System.exit(0);
                  }
                }
                 System.out.println("Yes"); 
                 System.exit(0);
              
          }else{
		  for(i = 0;i <= c[0][0]; i++){
            a[0] = i;
            b[0] = c[0][0] - a[0];
            a[1] = c[1][0] - b[0];
            a[2] = c[2][0] - b[0];
            b[1] = c[1][1] - a[1];
            b[2] = c[2][2] - a[2];
             if(a[1] >=0 && a[2] >=0 && b[1] >= 0 && b[2] >= 0){
				for(j = 0;j< 3;j++){
                  if(c[0][j] - a[0] != c[1][j] - a[1] || c[1][j] - a[1] != c[2][j] - a[2]){
                         System.out.println("No"); 
               			 System.exit(0);
                  }
                }
                 System.out.println("Yes"); 
                 System.exit(0);
              }


            
          }
        }
        System.out.println("No"); 
    }
}

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

int main(void){
	int A[3][3];
	rep(i,3)rep(j,3) cin >> A[i][j];
	int N;
	cin >> N;
	int b[N];
	rep(i,N) cin >> b[i];

	int h[3][3] = {0};
	rep(i,N)rep(j,3)rep(k,3){
		if (b[i] == A[j][k]) h[j][k] = 1;
	}

	int bingo = 0;
	rep(i,3) {
		if (h[i][0]*h[i][1]*h[i][2] == 1) {
			bingo = 1;
			break;
		}
	}
	rep(i,3) {
		if (h[0][i]*h[1][i]*h[2][i] == 1) {
			bingo = 1;
			break;
		}
	}
	if (h[0][0]*h[1][1]*h[2][2] == 1) bingo = 1;
	if (h[0][2]*h[1][1]*h[2][0] == 1) bingo = 1;

	if (bingo) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;
class Main {
	public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.printf("%d %d\n",(int)(a * b), (int)(a*2 + b*2));
	}

}


Measured memory_bytes: 26084
#include <stdio.h>
int A[100000],n;

int binarySearch(int key){
  int left=0;
  int right=n;
  int mid;

  //  while(1){                                                                 
  // if(left<right)break;                                                       
    while(left<right){
    mid=(left+right)/2;
    if(key==A[mid])return 1;
    if(key>A[mid])left=mid+1;
    else if(key<A[mid])right=mid;
  }
  return 0;
}
int same(int *array,int last){
  int cnt,ncnt,same,nsame=0;
  for(cnt=0;cnt<last-1;cnt++){
    same=*(array+cnt);
    for(ncnt=cnt+1;ncnt<last;ncnt++){
      if(*(array+ncnt)==same){
        nsame++;
        //      return 1;//nsame++;                                            \
                                                                                
        //return nsame;                                                        \
                                                                                
      }

    }
    // if(nsame>0)                                                             \
                                                                                
    return nsame;
    // else return 0;                                                          \
                                                                                
  }
}
int main(){
  int i,q,k,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",&k);
    if(binarySearch(k))sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2184
#include <stdio.h>
#include <string.h>
int main(){
char a[101],b[101],c[101],m,n,o;
scanf ("%s %s %s",&a,&b,&c);
m=strlen(a);
n=strlen(b);
if(a[m-1]==b[0]&&b[n-1]==c[0]){
	printf("YES");
}
else{
	printf("NO");
}
return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   string s;
   cin>>s;
   int n=s.size();

   int cnt=0;
   rep(i, n/2) if(s[i]!=s[n-1-i]) cnt++;

   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 3616
x,y,z = map(int,input().split())
if x == y:
  if x == z:
    print("No")
  else:
    print("Yes")
elif x == z:
  if x == y:
    print("No")
  else:
    print("Yes")
elif y == z:
  if x == y:
    print("No")
  else:
    print("Yes")
else:
  print("No")

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll ll_pow(ll a, ll n){
    ll ans = 1;
    FOR(i, 0, n){
        ans *= a;
    }
    return ans;
}

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

    // input
    ll M, K;
    cin >> M >> K;

    if(K==0){
        // ペアにするだけ
        vector<ll> A;
        FOR(i, 0, ll_pow(2, M)){
            A.push_back(i);
            A.push_back(i);
        }
        // ans
        FOR(i, 0, A.size()){
            if(i){
                cout << ' ';
            }
            cout << A[i];
        }
        cout << endl;
        return 0;
    }

    ll XOR = 0;
    FOR(i, 0, ll_pow(2, M)){
        if(i!=K){
            XOR ^= i;
        }
    }

    // pn(XOR);

    if(XOR!=K){
        p(-1);
        return 0;
    }

    // 以降、作れる
    deque<ll> que;
    que.push_front(K);
    FOR(i, 0, ll_pow(2, M)){
        if(i!=K){
            que.push_back(i);
            que.push_front(i);
        }
    }
    que.push_front(K);

    vector<ll> A;
    for(ll a : que){
        A.push_back(a);
    }
    FOR(i, 0, A.size()){
        if(i){
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 6132
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> id;
    vector<vector<pair<int, int>>> province(n + 1);
    int p, y;
    for (int i = 0; i < m; i++) {
        cin >> p >> y;
        id.push_back({p, y});
        province[p].push_back({y, i});
    }
    for (auto& v : province) {
        sort(v.begin(), v.end());
        for (int j = 0; j < v.size(); j++) { id[v[j].second].second = j + 1; };
    }
    for (auto& x : id) {
        cout << setw(6) << setfill('0') << x.first << setw(6) << x.second
             << endl;
    }
    return 0;
}

Measured memory_bytes: 7796
MOD = 10**9+7
def comb(n, k):
  res = 1
  for i in range(k):
    res *= n-i
    res %= MOD
    res *= pow(i+1, MOD-2, MOD)
  return res

n, a, b = map(int, input().split())
ans = pow(2, n, MOD) - comb(n, a) - comb(n, b) - 1
ans %= MOD
print(ans)

Measured memory_bytes: 3188
N = int(input())
dp = []
dp.append([0] * N)
dp.append([0] * N)
dp.append([0] * N)
a, b, c = [int(x) for x in input().strip().split()]
dp[0][0] = a
dp[1][0] = b
dp[2][0] = c

for i in range(1, N):
    a, b, c = [int(x) for x in input().strip().split()]
    dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a
    dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b
    dp[2][i] = max(dp[1][i-1], dp[0][i-1]) + c


print(max(dp[0][N-1], dp[1][N-1], dp[2][N-1]))


Measured memory_bytes: 52056
#include <iostream>
#include <vector>

using namespace std;

void solve() {
  string S;
  cin >> S;

  vector<int> cnt(40, 0);

  for (char c:S) {
    cnt[c-'a']++;
  }

  for (int c:cnt) {
    if (c%2 == 1) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys

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

n=II()
ans=0
for a in range(1,n+1):
    ans+=a*(n+1-a)
for _ in range(n-1):
    u,v=MI()
    if u>v:u,v=v,u
    ans-=u*(n+1-v)
print(ans)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
int main(void){
    ll n;
    cin>>n;
    while(n>0){
        ll l=0,r=100000000;
        while(r-l>1){
            ll m=(l+r)/2;
            if(m+(m-1)*m/2>=n){
                r=m;
            }else{
                l=m;
            }
        }
        cout<<r<<endl;
        n=n-r;
    }
    
}


Measured memory_bytes: 3524
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int c = A + B;
    int d = A + (A - 1);
    int e = B + (B - 1);
    int max = 0;
    max = Math.max(c,d);
    max = Math.max(max,e);
    System.out.println(max);
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    ll ans = 0;
    rep(i,n){
        if( (k|a[i]) == k) ans += b[i];
    }
    int c = 0;
    ll k_ = k;
    while(k_>0) k_/=2,++c;

    for(int i=c-1;i>=0;i--){
        if(k>>i&1){
            ll p = (k ^ (1LL<<i)) | ((1LL<<i) - 1LL);
            ll res = 0;
            rep(i,n){
                if( (p|a[i]) == p) res += b[i];
            }
            ans = max(ans,res);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4848
def main():
    strn = input()
    n = int(strn)
    if n < 10:
        print(n)
        return
    m = [0] * 81

    for i in range(1, n + 1):
        a = int(str(i)[0])
        b = int(str(i)[-1])
        # print(a, b)
        if b == 0:
            continue
        else:
            key = 9 * (a - 1) + b - 1
            # print(key)
            m[key] += 1
    ans = 0
    # print(m)
    for i in range(1, 10):
        for j in range(1, 10):
            key = 9 * (i - 1) + j - 1
            oppose = 9 * (j - 1) + i - 1
            ans += m[key] * m[oppose]
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 40556
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-9;//-14
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}



signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c;
    scanf("%lld %lld.%lld",&a,&b,&c);
    printf("%lld",a * (b * 100LL + c) / 100LL);
    return 0;
}

Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {
	private static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int X = scanner.nextInt();
		int Y = scanner.nextInt();
		int a = (N - K) * (X - Y);
		if (a < 0) a = 0;
		System.out.println(N * X - a);
	}
}


Measured memory_bytes: 10068
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] arg) throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strToke;
        String line;
        // ax + by = c
        // dx + ey = f
        while ((line = in.readLine()) != null) {
            strToke = new StringTokenizer(line);
            double a = Double.parseDouble(strToke.nextToken());
            double b = Double.parseDouble(strToke.nextToken());
            double c = Double.parseDouble(strToke.nextToken());
            double d = Double.parseDouble(strToke.nextToken());
            double e = Double.parseDouble(strToke.nextToken());
            double f = Double.parseDouble(strToke.nextToken());
            BigDecimal y = new BigDecimal((a * f - d * c) / (a * e - d * b)).setScale(3, BigDecimal.ROUND_HALF_UP);
            BigDecimal x = new BigDecimal((c * e - f * b) / (a * e - b * d)).setScale(3, BigDecimal.ROUND_HALF_UP);
            System.out.println(x + " " + y);
        }
    }
}

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

int main() {
    long long int n,k;
    cin>>n>>k;
    long long int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int sum =0;
    for(int i=0;i<k;i++)
    {
        sum = sum+arr[i];
    }
    cout<<sum;
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  bool dp[1000005]; dp[0] = true;
  for(int i=1; i<=99; i++){
    dp[i] = false;
  }
  dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = true;
  for(int i=106; i<=1000000; i++){
    if(dp[i-100]|| dp[i-101] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105]){
      dp[i] = true;
    }
  }
  int N; cin >> N;
  if(dp[N]) cout << 1 << endl;
  else cout << 0 << endl;
  
    
}

Measured memory_bytes: 1280
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define MAXN 100010

typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    pair<ll, ll> shops[N];
    for (ll i = 0; i < N; i++) {
        cin >> shops[i].first >> shops[i].second;
    }
    sort(shops, shops + N);
    ll ans = 0;
    for (auto shop : shops) {
        if (M - shop.second > 0) {
            ans += shop.second * shop.first;
            M -= shop.second;
        } else {
            ans += M * shop.first;
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using ll = int_fast64_t;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repr(i,n) for(int i{n};i-->0;)
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  string s;
  int d;
  cin>>s>>d;
  int n = size(s);

  vector<int> a(n);
  rep(i,n)a[i] = s[i]-'0';

  auto dp = vec<ll>(2,n+1,d);
  dp[0][0][0] = 1;
  constexpr ll mod = 1e9+7;
  rep(i,n){
    rep(m,d){
      dp[0][i][m] %= mod;
      dp[1][i][m] %= mod;
      rep(dig,10){
        int nd = (dig+m)%d;
        dp[1][i+1][nd] += dp[1][i][m];
        if(dig==a[i])dp[0][i+1][nd] += dp[0][i][m];
        if(dig<a[i])dp[1][i+1][nd] += dp[0][i][m];
      }
    }
  }
  ll ans = dp[0][n][0]+dp[1][n][0]-1;
  ans %= mod;
  cout<<(ans)<<endl;

}

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

#define SIZE 200005

int n,m;
string str;
char mo[SIZE],dr[SIZE];
int ch[SIZE],d[SIZE];
int i,j,k;

bool left(int p){
  for(i=0;i<m;i++){
    if(str[p]-'A'==ch[i]){
      p+=d[i];
      if(p<0) return true;
      if(p>=n) return false;
    }
  }
  return false;
}

bool right(int p){
  for(i=0;i<m;i++){
    if(str[p]-'A'==ch[i]){
      p+=d[i];
      if(p>=n) return true;
      if(p<0) return false;
    }
  }
  return false;
}

int main(){
  cin>>n>>m;
  cin>>str;
  for(i=0;i<m;i++){
    cin>>mo[i]>>dr[i];
    ch[i]=mo[i]-'A';
    if(dr[i]=='R') d[i]=1;
    else d[i]=-1;
  }

  int ret=n;
  int l=-1,r=n;

  while(r-l>1){
    int d=(r+l)/2;
    if(left(d)) l=d;
    else r=d;
  }

  ret-=r;
  //cout<<ret<<endl;
  l=-1,r=n;

  while(r-l>1){
    int d=(r+l)/2;
    if(right(d)) r=d;
    else l=d;
  }

  ret-=n-r;

  cout<<ret<<endl;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
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 solve(int a,int b){
    if(a>b)swap(a,b);
    if(b%a==0)return (b/a*2-1)*a;
    return b/a*a*2+solve(a,b%a);
}

signed main(){
    int N,X;
    cin>>N>>X;

    cout<<N+solve(X,N-X)<<endl;
    return 0;
}


Measured memory_bytes: 256
### constant

UN = 5
TN = 10

INF = 1 << 30

### subroutines

def conflict_tt?(att, tt, k)
  for u in (0...UN)
    for i in (0...$n)
      return true if att[u][k + i] && tt[u][i]
    end
  end
  false
end

def c_rec(i, k)
  #p ["c_rec", i, k]
  if i >= TN
    return k - 1
  end

  min_c = INF
  bcfls = []
  
  for dk in (0...$n)
    k0 = k + dk
    break if k0 > min_c

    if $acfls[k0].nil?
      for j in (0...$n)
        bcfls[j] = $acfls[k0 + j]
        $acfls[k0 + j] = 1 if $ucfls[j]
      end

      c = c_rec(i + 1, k0 + 1)
      min_c = c if min_c > c

      for j in (0...$n)
        $acfls[k0 + j] = bcfls[j]
      end
    end
  end

  min_c
end

### main

loop do
  $n = gets.to_i
  break if $n == 0

  utt = UN.times.map{gets.strip.split('').map{|ch| ch == 'X'}}
  #p utt

  $ucfls = [1] + (1...$n).map{|k| conflict_tt?(utt, utt, k) ? 1 : nil}
  #p $ucfls

  $acfls = $ucfls.clone
  #p $acfls

  min_c = c_rec(1, 1)

  puts min_c + $n
end

Measured memory_bytes: 6148
#include <stdio.h>
int main(void){
    
    double r,pi,a,b;
    pi=3.14159265359;
    
    scanf("%lf",&r);
    a=2*pi*r;
    b=r*r*pi;
    
    printf("%lf %lf\n",b,a);
    return 0;
}

Measured memory_bytes: 1808
#include <stdio.h>

int main(void){
	int A,B;
	scanf("%d %d",&A,&B);
	int ans = 0;
	for(;A<=B;A++){
		int i,j,k,l,m;
		i = A%10;
		j = (A%100-i)/10;
		k = (A%1000-i-j*10)/100;
		l = (A%10000-i-j*10-k*100)/1000;
		m = (A%100000-i-j*10-k*100-l*1000)/10000;
		if(m==i && l==j) ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll N, ans = 0;
    cin >> N;
    N %= 10;
    switch (N) {
        case 0:
            cout << "pon" << endl;
            break;
        case 1:
            cout << "pon" << endl;
            break;
        case 2:
            cout << "hon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
        case 4:
            cout << "hon" << endl;
            break;
        case 5:
            cout << "hon" << endl;
            break;
        case 6:
            cout << "pon" << endl;
            break;
        case 7:
            cout << "hon" << endl;
            break;
        case 8:
            cout << "pon" << endl;
            break;
        case 9:
            cout << "hon" << endl;
            break;

        default:
            break;
    }
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

struct card{
	int num;
	char suit;

	bool operator == (const card& a) const{
		return (num == a.num) && (suit == a.suit);
	}
};

void bubblesort(card a[], int n){
	int flag = true;
	while (flag){
		flag = false;
		for (int j = n - 1; j >= 1; j--){
			if (a[j].num < a[j - 1].num){
				swap(a[j], a[j - 1]);
				flag = true;
			}
		}
	}
}

void selectionsort(card a[], int n){
	for (int i = 0; i < n; i++){
		int minj = i;
		for (int j = i; j < n; j++){
			if (a[j].num < a[minj].num)
				minj = j;
		}
		swap(a[i], a[minj]);
	}
}

bool stablecheck(card sorted[], card in[], int n){
	for (int i = 0; i < n; i++)
	for (int j = i+1; j < n; j++)
	for (int a = 0; a < n; a++)
	for (int b = a+1; b < n; b++){
		// 初期の数字が同じすべてのペアについて、
		// 逆転しているかどうか
		if (in[i].num == in[j].num &&
			in[i] == sorted[b] && in[j] == sorted[a])
			return false;
	}
	return true;
}

signed main(){

	int n;
	card a[36], copy[36];

	cin >> n;
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		a[i].suit = s[0];
		a[i].num = s[1] - '0';
	}

	{
		memcpy(copy, a, sizeof(a));

		bubblesort(copy, n);
		bool f = stablecheck(copy, a, n);
		for (int i = 0; i < n; i++){
			cout << copy[i].suit << copy[i].num;
			if (i < n - 1) cout << " ";
			else cout << endl;
		}
		if (f) cout << "Stable" << endl;
		else cout << "Not stable" << endl;
	}
	{
		memcpy(copy, a, sizeof(a));

		selectionsort(copy, n);
		bool f = stablecheck(copy, a, n);
		for (int i = 0; i < n; i++){
			cout << copy[i].suit << copy[i].num;
			if (i < n - 1) cout << " ";
			else cout << endl;
		}
		if (f) cout << "Stable" << endl;
		else cout << "Not stable" << endl;
	}

	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=300;
ll a[N];
ll b[N];
int32_t main(){
    ll n;
    cin >> n;
    ll l=0,r=n;
    cout << flush << l << endl;
    string t;
    cin >> t;
    ll p1=0;
    if (t=="Female"){
        p1=1;
    }
    while(r-l>1){
        ll mid=(r+l)/2;
        cout << flush << mid << endl;
        string s;
        cin >> s;
        ll p2=0;
        if (s=="Vacant"){
            return 0;
        }
        if (s=="Female"){
            p2=1;
        }
        if ((mid-l)%2==1 && p2==p1){
            r=mid;
            continue;
        }
        if ((mid-l)%2==0 && p2!=p1){
            r=mid;
            continue;
        }
        l=mid;
        p1=p2;
    }

}


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

bool calc(const string &s) {
    set<char> dif;

    for(size_t i = 0; i < s.size(); i++) {
        dif.insert(s[i]);
    }

    if(dif.size() == 2)
        return true;

    return false;
}

int main() {
    string s;

    cin >> s;

    auto r = calc(s);

    cout << (r ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        double a,b,c,S,L,h;
        a=sc.nextDouble();
        b=sc.nextDouble();
        c=sc.nextDouble()*(Math.PI/180);
        S=(a*b*Math.sin(c))/2;
        L=a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(c));
        h=b*Math.sin(c);
        System.out.printf("%f\n%f\n%f\n",S,L,h);
    }
}


Measured memory_bytes: 28456
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  bool ok=false;
  for(int i=1;i<=9;i++){
    if(n%i==0 && n/i<=9)ok=true;
  }
  if(ok)cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline int read() {
    int res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int a, b;

int main() {
    std::cin >> a >> b;
    std::cout << std::max(a - b * 2, 0) << std::endl;
    return 0;
}

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

int main() {
  int64_t X;
  cin >> X;
  for (int i = -129; i < 129; i++) {
    for (int j = -128; j < 130; j++) {
      if (pow(i, 5) - pow(j, 5) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


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

int main() {
 long int k,n,ans;
  cin >>k>>n;
  vector<long int>a(n);
  for(long int i=0;i<n;i++){
  cin >>a[i];}
    vector<long int>memo(n);
  
  for(long int i=0;i<n-1;i++){
  	memo[i]=a[i+1]-a[i];    
  }
  memo[n-1]=k+a[0]-a[n-1];
  sort(memo.begin(),memo.end());
  ans=k-memo[n-1];
  cout <<ans<<endl;
}

Measured memory_bytes: 3328
import numpy as np
 
N, K = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))
indexes = np.arange(0, N)
 
dp = np.zeros(shape=N + 1, dtype=np.int64)
 
for k in range(K):
    np.add.at(dp, np.maximum(0, indexes - A), 1)
    np.add.at(dp, np.minimum(N, indexes + A + 1), -1)
    A = dp.cumsum()[:-1]
    if np.all(A == N):
        break
    dp *= 0
 
print(' '.join(map(str, A)))

Measured memory_bytes: 51568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)

/*
・グラフ
  > Dijkstra
  > BellmanFord
  > WarshallFloyd
  > Kruskal
[応用] 単一終点最短路問題は, すべての有向辺を逆向きに張り替えると, 単一始点最短路問題に帰着できる.
[使用例]
Graph<int> g(N);              // 頂点数N, 重さの型がintのグラフを宣言
add_edge(g,a,b,c);            // グラフgに, aからbへの重さcの無向辺を追加
add_arc(g,a,b,c);             // グラフgに, aからbへの重さcの有向辺を追加
add_to_edges(edges,a,b,c);    // 辺集合edgesに, 始点a, 終点b, 重さcの辺を追加
*/

template<typename T> struct Edge {
  int from, to;
  T weight;
  Edge() : from(0), to(0), weight(0) {}
  Edge(int f, int t, T w) : from(f), to(t), weight(w) {}
};
template<typename T> using Edges = vector< Edge< T > >;
template<typename T> using Graph = vector< Edges< T > >;
template<typename T> void     add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); g[to].emplace_back(to,from,w); }
template<typename T> void      add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); }
template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from,to,w); }

/*
・ダイクストラ法
  > O(ElogV) [E:辺の数, V:頂点の数]
[備考] 負辺の存在しないグラフに対する単一始点全点間最短路を求めるアルゴリズム
[注意] 結果を足し合わせる際, INFの大きさに注意
[使用例]
auto dij = Dijkstra(g,s);     // グラフgにおける, 始点sからの最短路
*/

template<typename T> vector< T > Dijkstra(Graph<T> &g, int from) {
  const auto INF = numeric_limits< T >::max()/10;
  vector< T > dist(g.size(), INF);
  dist[from] = 0;
  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.emplace(dist[from], from);
  while ( !que.empty() ) {
    T weight; int idx;
    tie(weight, idx) = que.top(); que.pop();
    if (dist[idx] < weight) continue;
    for (auto &e : g[idx]) {
      auto next_weight = weight + e.weight;
      if (dist[e.to] <= next_weight) continue;
      dist[e.to] = next_weight;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int K;

signed main() {

  cin >> K;

  Graph<int> g(K);

  // a -> a + 1
  REP(i, K) add_arc(g, i, (i + 1) % K, 1);

  // a -> 10 * a
  REP(i, K) add_arc(g, i, (10 * i) % K, 0);

  // 1から始めて, Kになるまでの最短距離
  cout << Dijkstra(g, 1)[0] + 1 << endl;

}


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

int main(){
    string S; cin >> S;
    int ans=0;
    int cnt=0;
    
    rep(i,S.size()){
        if (S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T') cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    
    cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<long long> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  long long ans = 0;
  while (a.back() >= n) {
    long long tmp = a.back() / n;
    ans += tmp;
    REP(i, n - 1) a[i] += tmp;
    a.back() -= tmp * n;
    sort(ALL(a));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
p = [0, 0]
q = [W, H]
for _ in [0]*N:
    x, y, a = map(int, input().split())
    if a == 1:
        p[0] = max(p[0], x)
    elif a == 2:
        q[0] = min(q[0], x)
    elif a == 3:
        p[1] = max(p[1], y)
    elif a == 4:
        q[1] = min(q[1], y)

if q[0] - p[0] < 0 or q[1] - p[1] < 0:
    print(0)
else:
    print((q[0] - p[0])*(q[1] - p[1]))

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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> ii;
typedef pair <ll, ll> dl;
typedef vector <ii> vii;
typedef vector <dl> vil;
typedef vector <vi> graph;

graph grafo;
int n, m;
int indegree[200010];
int dp[200010];

int dag(int u) {
  if (dp[u] != -1) return dp[u];
  int total = grafo[u].size(), v;
  int temp, mayor = 1;
  for (int i = 0; i < total; i++) {
    v = grafo[u][i];
    temp = 1 + dag(v);
    mayor = temp > mayor ? temp : mayor;
  }
  return dp[u] = mayor;
}

int main() {
  cin >> n >> m;
  int in1, in2;
  vi empty;
  grafo.assign(n + 10, empty);
  for (int i = 0; i < m; i++) {
    cin >> in1 >> in2;
    grafo[in1].push_back(in2);
  }
  for (int i = 0; i < 200010; i++) {
    dp[i] = -1;
  }
  int temp;
  int mayor = -1;
  for (int i = 1; i <= n; i++) {
    if (!indegree[i]) {
      temp = dag(i);
      mayor = temp > mayor ? temp : mayor;
    }
  }
  cout << mayor - 1 << "\n";
  return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    auto S = accumulate(v.begin(),v.end(), 0LL);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if(v[i]*4*m >= S) cnt++;
    }
    puts(cnt >= m ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
def main():


   N , M= map(int,input().split())
   tmpList = [ list(map(int,input().split())) for _ in range(M)]
   roadList = [ j for i in tmpList for j in i]

   for i in range(1,N+1):
      print(roadList.count(i))







if __name__== "__main__":
    main() 



Measured memory_bytes: 2940
A,B=map(int,input().split())
ansA=A//(0.08)
ansB=B//(0.1)
a=[]
b=[]
while True:
    if int(ansA*1.08-ansA)==A:
        a.append(int(ansA))
        ansA+=1
    elif int(ansA*1.08-ansA)>A:
        break
    else:
        ansA+=1

while True:
    if int(ansB*1.1-ansB)==B:
        b.append(int(ansB))
        ansB+=1
    elif int(ansB*1.1-ansB)>B:
        break
    else:
        ansB+=1
c=[]
c+=set(a)&set(b)


if c==[]:
    print("-1")
else:
    print(int(min(c)))





Measured memory_bytes: 3064