akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define int long
using namespace std;
main()
{
	int n,a,b;cin>>n>>a>>b;
	int x[1<<17];
	for(int i=0;i<n;i++)cin>>x[i];
	int cnt=0;
	for(int i=1;i<n;i++)
	{
		int bet=x[i]-x[i-1];
		cnt+=min(bet*a,b);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int a[n],b = 0,flag = 0;
    rep(i,n){
        a[i] = s[i]-'1';
        if (a[i] == 1) flag = 1;
    }
    rep(i,n){
        if (((n-1)&i) == i) b += a[i]%2;
    }
    if (b%2) PRINT(1);
    else{
        b = 0;
        if(flag) PRINT(0);
        else{
            rep(i,n) a[i] = a[i]/2;
            rep(i,n){
                if (((n-1)&i) == i) b += a[i];
            }
            if (b%2) PRINT(2);
            else PRINT(0);
        }
    }
}


Measured memory_bytes: 5276
n = int(input())
x = list(map(int, input().split()))

y = []

for i in range(n):
    y.append([x[i], i])

y.sort()

ans = [-1 for i in range(n)]

for i in range(n // 2):
    ans[y[i][1]] = y[n // 2][0]

for i in range(n // 2, n):
    ans[y[i][1]] = y[n // 2 - 1][0]

for i in range(n):
    print(ans[i])

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

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = input()
n = len(s)
mod = 2019
cum = [0] * (n + 1)
cum[0] = 0
for i in range(n):
    # print(int(s[i]) - 48)
    cum[i + 1] = (cum[i] * 10 + int(s[i])) % mod
# print(cum)
mod_cum = [0] * (n + 1)
for i in range(n + 1):
    mod_cum[i] = (cum[i] * pow(10, n - i, mod)) % mod
# print(pow(10, 15, mod))
mod_cum.sort()
# print(mod_cum)
ans = 0
cnt = 1
tmp = mod_cum[0]
for i in range(n):
    if mod_cum[i + 1] == tmp:
        cnt += 1
    else:
        tmp = mod_cum[i + 1]

        if cnt > 1:
            # print(i, cnt, tmp, ans)
            ans += cnt * (cnt - 1) // 2
        cnt = 1
if cnt > 1:
    ans += cnt * (cnt - 1) // 2
print(ans)


Measured memory_bytes: 24028
def solve():
    N = int(input())
    S2 = [0]*N
    for i in range(N):
        S2[i] = input()
    ans = 0
    for k in range(N):
        cum = [[0]*(N+1) for _ in range(N+1)]
        for i in range(1,N+1):
            for j in range(1,N+1):
                cum[i][j] = cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+(S2[i-1][j-1]==S2[(j-1+k)%N][(i-1-k)%N])
                if i==N and j==N:
                    ans += (cum[i][j]==N*N)*N
    return ans
print(solve())

Measured memory_bytes: 75356
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

void solve(){
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; ++i){
        ans += (i%d == 0);
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K,S;
  cin >> K >> S;
  int X,Y,Z,cnt;
  for(X = 0;X <= K;X++){
    for(Y = 0;Y <= K;Y++){
      Z = S - X - Y;
      if(0 <= Z && Z <= K) cnt++;
    }
  }
  cout << cnt << endl;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    rep(i,n,999){
        S s=to_string(i);
        if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

struct Node {
	int key;
	Node *parent, *left, *right;
	Node (int x) {
		key = x;
		parent = left = right = NIL;
	}
};

struct Tree {
	Node *root;
	Tree() {
		root = NIL;
	}
	void insert(int x) {
		Node *temp_parent = NIL;
		Node *now_node = root;
		while (now_node != NIL) {
			temp_parent = now_node;
			if (now_node->key > x)
				now_node = now_node->left;
			else
				now_node = now_node->right;
		}
		if (temp_parent == NIL) {
			root = new Node(x);
		} else if (temp_parent->key > x) {
			temp_parent->left = new Node(x);
			temp_parent->left->parent = temp_parent;
		} else {
			temp_parent->right = new Node(x);
			temp_parent->right->parent = temp_parent;
		}
	}
	Node * find(int x) {
		Node *now_node = root;
		while (now_node != NIL && now_node->key != x)
			if (now_node->key > x)
				now_node = now_node->left; 
			else
				now_node = now_node->right;
		return now_node;
	}
	void deleteE(int x) {
		Node *z = find(x);
		Node *temp_p = z->parent;
		if (z->left == NIL && z->right == NIL) { // no children
			if (temp_p != NIL) {
				if (temp_p->key > z->key) {
					temp_p->left = NIL;
				} else {
					temp_p->right = NIL;
				}
			} else {
				root = NIL;
			}
			delete z;
		} else if (z->left != NIL && z->right != NIL) { // two children
			Node *choice = NIL;
			Node *temp = z->right;
			while (temp != NIL) {
				choice = temp;
				temp = temp->left;
			}
			z->key = choice->key;
			if (choice != z->right) {
				choice->parent->left = choice->right; // NIL or some node				
				if (choice->right != NIL) {
					choice->right->parent = choice->parent;
				}
			} else {
				z->right = choice->right;
				if (choice->right != NIL) {
					choice->right->parent = z;					
				}
			}
			delete choice;
		} else { // one children
			Node *c;
			if (z->left != NIL)
				c = z->left;
			else
				c = z->right;
			if (temp_p != NIL) {
				if (temp_p->key > z->key) {
					temp_p->left = c;
				} else {
					temp_p->right = c;
				}
			} else {
				root = c;
			}
			c->parent = temp_p;
			delete z;
		}
	}
	void printInorder() {
		inorder(root);
	}
	void inorder(Node *v) {
		if (v == NIL)
			return;
		inorder(v->left);
		cout << " " << v->key;
		inorder(v->right);
	}
	void printPreorder() {
		preorder(root);
	}
	void preorder(Node *v) {
		if (v == NIL)
			return;
		cout << " " << v->key;
		preorder(v->left);
		preorder(v->right);
	}
};

int main(void) {
	Tree T;
	int n, i, x;
	string com;
	cin >> n;
	while (n--) {
		cin >> com;
		if (com == "insert") {
			cin >> x;
			T.insert(x);
		} else if (com == "find") {
			cin >> x;
			if (T.find(x) != NIL) {
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}
		} else if (com == "print") {
			T.printInorder();
			cout << endl;
			T.printPreorder();
			cout << endl;
		} else if (com == "delete") {
			cin >> x;
			T.deleteE(x);
		}
	}
}


Measured memory_bytes: 21932
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    FOR(i, 1, N + 1) {
        ll Y = N / i;
        ans += (Y + 1) * Y / 2 * i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
N = int(input())
LR = []
p = 0
max_L = 0
q = 0
min_R = 10**9 + 1

for i in range(N):
    L, R = map(int, input().split())
    R += 1
    LR.append((L, R))
    if L > max_L:
        p = i
        max_L = L
    if R < min_R:
        q = i
        min_R = R

ans1 = max(R - L for L, R in LR) + max(min_R - max_L, 0)

if N == 2:
    print(sum(R - L for L, R in LR))
    exit()

if p == q:
    print(ans1)
    exit()

L1, R1 = LR[p]
L2, R2 = LR[q]
LR = [(L, R) for i, (L, R) in enumerate(LR) if i != p and i != q]
LR.sort(key=lambda x: (x[1], x[0]), reverse=True)

n = len(LR) + 1
min_sr = [R1] * n
max_tl = [L2] * n

for i in range(1, n):
    min_sr[i] = min(min_sr[i-1], LR[i-1][1])
    max_tl[n-i-1] = max(max_tl[n-i], LR[n-i-1][0])

ans2 = max(max(r - L1, 0) + max(R2 - l, 0) for r, l in zip(min_sr, max_tl))

print(max(ans1, ans2))


Measured memory_bytes: 24560
#include<stdio.h>
#include<string.h>

#define N 41

int main(void)
{
  int i,j,k[N],n,S,m;
  char st1[N];

  while(1)
    {
      scanf("%d",&n);
      if(n==0) break;
      for(i=0;i<=n-1;i++)
	{
	  scanf("%s",st1);
	  k[i]=strlen(st1);
	}
      m=n;
      for(i=0;m==n;i++)
	{
	  S=0;
	  j=i;
	  while(S<=5)
	    {
	      S=S+k[j];
	      j++;
	      if(S==5)
	        {
	          S=0;
	          while(S<=7)
		    {
	              S=S+k[j];
	              j++;
	              if(S==7)
		        {
		          S=0;
	                  while(S<=5)
		            {
	                       S=S+k[j];
	                       j++;
		               if(S==5)
		                {
		                  S=0;
	                          while(S<=7)
	         	            {
	                              S=S+k[j];
	                              j++; 
		                      if(S==7)
			                {
			                  S=0;
	                                  while(S<=7)
		                            {
	                                      S=S+k[j];
	                                      j++;
			                      if(S==7 && m>=i)
			                        {
						    m=i+1;
			                        }
					    }
				        }
				    }
				}
			    }
			}
		    }
		}
	    }
	}
      printf("%d\n",m);
    }
  return 0;
}

Measured memory_bytes: 604
import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou.append(i)
    if A[i] >= 4:
        seihou.append(i)

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)

Measured memory_bytes: 18600
#include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from); x<(to); (x)++)
#define rep(x,to) rep2(x,0,to)
vector<int> s, t;
int main() {
	int n, q;
	cin >> n;
	rep(i,n) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	cin >> q;
	rep(i,q) {
		int b;
		cin >> b;
		t.push_back(b);
	}
	int cnt = 0;
	rep(i,q) {
		rep(j,n) {
			if(t[i] == s[j]) {
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1320
#include<iostream>
using namespace std;
int main() {
	int height[10], i, a=0, b=0, c=0;
	for (i = 0; i < 10; i++) {
		cin >> height[i];
	}
	for (i = 0; i < 10; i++) {
		if (height[i] >= a) {
			c = b;
			b = a;
			a = height[i];
		}
		else if (height[i] >= b) {
			c = b;
			b = height[i];
		}
		else if (height[i] >= c) {
			c = height[i];
		}
	}
	cout << a << endl << b << endl << c << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<math.h>
#define int long long
using namespace std;
signed main(){
	int t,n,i,j,k,l,cac;
	cin>>t;
	while(t--){
		cac=0;
		cin>>j>>k;
		if(j>k){
			swap(j,k);
		}
		l=sqrtl(j*k-1);
		if(j<=l){
			cac=1;
		}
		if(l*(l+1)<j*k){
			cout<<2*l-cac<<endl;
		}
		else{
			cout<<2*l-cac-1<<endl;
		}
	}
}

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

template<class T>
void WarshallFloyd(vector<vector<T>> &G, T INF) {
    for(int i = 0; i < G.size(); ++i) G[i][i] = 0;
    for(int k = 0; k < G.size(); ++k) {
        for(int i = 0; i < G.size(); ++i) {
            for(int j = 0; j < G.size(); ++j) {
                if(G[i][k] == INF || G[k][j] == INF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
}

void solve() {
    int V, E;
    cin >> V >> E;
    const long long INF = 1e18;
    vector<vector<long long>> G(V, vector<long long>(V, INF));
    for(int i = 0; i < E; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a][b] = c;
    }
    WarshallFloyd(G, INF);
    for(int i = 0; i < V; ++i) if(G[i][i] < 0) {
        cout << "NEGATIVE CYCLE" << '\n';
        return;
    }
    for(auto &v : G) {
        for(int i = 0; i < (int)v.size(); ++i) {
            if(i) cout << " ";
            if(v[i] == INF) cout << "INF";
            else cout << v[i];
        }
        cout << "\n";
    }
}

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



Measured memory_bytes: 3244
#include<iostream>
using namespace std;
int check[100009];
int balls[100009];

int main(){
    int N,M,x,y;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        check[i]=0;
        balls[i]=1;
    }
    check[0]=1;
    for(int i=0;i<M;i++){
        cin >> x >> y;
        x--;y--;
        if(check[x]==1)check[y]=1;

        balls[x]--;
        balls[y]++;
        if(balls[x]==0)check[x]=0;
    }
    int sum=0;
    for(int i=0;i<N;i++){
        if(check[i]==1)sum+=1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
def SUNUKE(i):
    x=str(i)
    SUM=0

    for j in range(len(x)):
        SUM+=int(x[j])

    return SUM,i/SUM

SUNUKESUU=[0,1,2,3,4,5,6,7,8,9]
i=10
keta=0

while i<10**16:


    if SUNUKE(i)[1]>=10**keta:
        i-=10**keta
        keta+=1
        
    else:
        if SUNUKESUU[-1]!=i:
            SUNUKESUU+=[i]
        i+=10**keta
    

for i in range(1,int(input())+1):
    print(SUNUKESUU[i])

Measured memory_bytes: 3188
temp=input()
n=int(temp.split()[0])
a=int(temp.split()[1])
b=int(temp.split()[2])

def rel(n):
  k10000=n//10000
  k1000=(n%10000)//1000
  k100=(n%1000)//100
  k10=(n%100)//10
  k1=n%10//1
  return k10000+k1000+k100+k10+k1

result=[]
for x in range(1,n+1):
  if b >= rel(x) >= a:
    result.append(x)

print(sum(result))

Measured memory_bytes: 3412
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        int n;
        scanf("%d", &n);
        std::vector<int> a(n);
        for(int i=0; i<n; i++) scanf("%d", &a[i]);

        std::vector<int> dp(n, 1e11);
        dp[0] = 0;
        for(int i=0; i<n; i++){
                if(i>0) dp[i] = std::min(dp[i], dp[i-1]+abs(a[i]-a[i-1]));
                if(i>1) dp[i] = std::min(dp[i], dp[i-2]+abs(a[i]-a[i-2]));
        }
        printf("%d\n", dp[n-1]);
        return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	char s[1000000];
	char alfer[26];
	int a = 0;
	int count = 0;
	char al[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

	for (int i = 0; i < 26; i++)
	{
		alfer[i] = 0;
	}
	cin >> s;
	while (s[a] != '\0')
	{
		if (s[a] == 'a')
			alfer[0] = 1;
		if (s[a] == 'b')
			alfer[1] = 1;
		if (s[a] == 'c')
			alfer[2] = 1;
		if (s[a] == 'd')
			alfer[3] = 1;
		if (s[a] == 'e')
			alfer[4] = 1;
		if (s[a] == 'f')
			alfer[5] = 1;
		if (s[a] == 'g')
			alfer[6] = 1;
		if (s[a] == 'h')
			alfer[7] = 1;
		if (s[a] == 'i')
			alfer[8] = 1;
		if (s[a] == 'j')
			alfer[9] = 1;
		if (s[a] == 'k')
			alfer[10] = 1;
		if (s[a] == 'l')
			alfer[11] = 1;
		if (s[a] == 'm')
			alfer[12] = 1;
		if (s[a] == 'n')
			alfer[13] = 1;
		if (s[a] == 'o')
			alfer[14] = 1;
		if (s[a] == 'p')
			alfer[15] = 1;
		if (s[a] == 'q')
			alfer[16] = 1;
		if (s[a] == 'r')
			alfer[17] = 1;
		if (s[a] == 's')
			alfer[18] = 1;
		if (s[a] == 't')
			alfer[19] = 1;
		if (s[a] == 'u')
			alfer[20] = 1;
		if (s[a] == 'v')
			alfer[21] = 1;
		if (s[a] == 'w')
			alfer[22] = 1;
		if (s[a] == 'x')
			alfer[23] = 1;
		if (s[a] == 'y')
			alfer[24] = 1;
		if (s[a] == 'z')
			alfer[25] = 1;
		a++;
	}
	for (int i = 0; i < 26; i++)
	{
		if (alfer[i] == 0)
		{
			cout << al[i] << "\n";
			break;
		}
		count++;
	}
	if (count == 26)
		cout << "None" << "\n";
}

Measured memory_bytes: 384
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=305;
int n,k;
int h[M];
int dp[M][M][M];
int solve(int pos,int last,int baki)
{
   if(pos>n)
   {
       return 0;
   }
   int &ret=dp[pos][last][baki];
   if(ret!=(-1))return ret;
   ret=0;
   int cost=h[pos]-h[last];
   cost=max(cost,0LL);
   ret=cost+solve(pos+1,pos,baki);
   if(baki>=1)ret=min(ret,solve(pos+1,last,baki-1));
   return ret;
}
 main()

{
    fast
    cin>>n>>k;
    f(i,1,n)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof dp);
    int ses=solve(1,0,k);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 225316
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define F(i,a,b) for(int i=a;i<b;i++)
#define RF(i,a,b) for(int i=a;i>b;i--)
#define mp(a,b) make_pair(int a,int b)
#define ll long long
const int mxn=1e5+10,mxm=4e5+10;
const ll modl=998244353;
int nm,n,m,p,t,k;
int ans,sum;
int a[mxn],b[mxn],h[mxn];
int l,r;
int main(){
    ios_base::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    cin>>nm;
//    string s,s1,s2;char c;
    while(cin>>m>>n>>p){
//        priority_queue<dp,vector<dp>,cmp>q;
        cout<<p<<" "<<m<<" "<<n<<" ";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  double f=n/2;
  double r=n-f;
  cout << fixed << setprecision(10);
  cout << r/n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
const ll INF = 1e18;

ll int aditya(ll int x)
{
	while(x/10 > 0)
	{
		x /= 10;
	}
	return x;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
	ll int c[10][10];
	memset(c, 0, sizeof(c));
 	ll int n,i,j,res=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		c[aditya(i)][i%10]++;
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			res+=c[i][j]*c[j][i];
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		for(int i=0;i<n;i++) cin >> a[i];
		int max = -1000000;
		for(int i=0;i<n;i++){
			int b = 0;
			for(int j=i;j<n;j++){
				b += a[j];
				if(max<b) max = b;
			}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 1168
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  G[u-1].append([v-1,w])
  G[v-1].append([u-1,w])
dist=[-1]*n
from collections import deque
q=deque()
q.append(0)
dist[0]=0
while q:
  cur=q.popleft()
  for nx,nd in G[cur]:
    if dist[nx]!=-1:continue
    dist[nx]=(dist[cur]+nd)%2
    q.append(nx)
print(*dist,sep='\n')


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

int main(){
	int n;
	int d=100000;
	do{
	cin >> n;
	}while(n>100);
	
	for(int i=n;i>0;i--){
		d += d*0.05;
		if(d % 1000 != 0){
			d += 1000;
			d -= d%1000;
		}
	}
	cout << d <<endl;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
#define int long long
using namespace std;
/* 
对kruskal算法的彻底理解。

A_i,B_i连接了C_i。

所以A_{i+1},B_i连接了C_i +1 等价于和这个连通块连接了C_i +1的边
（C_i<C_i +1) 所以此刻如果要连接这条边，A_i，B_i已经连接上了（必然）

所以等价于A_i A_{i+1} 连接了C_i +1,B_i B_{i+1} 连接了 C_i +2

设D数组表示 i 向后每一个点扩展连边，最小值为多少。
前缀最小值即可。做两遍。
D[i]=min(D[i],D[(i-1+n)%n]+2); 
D[i]=min(D[i],D[(i-1+n)%n]+2); 
*/
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
struct edge{
	int from,to,dis;
}g[10000001];
int F[2200001],tot,n,m;
int find(int u){
	if (F[u]!=u) F[u]=find(F[u]);
	return F[u];
}
inline void made(int a,int b,int c){
	g[++tot].from=a;g[tot].to=b;g[tot].dis=c;
}
inline bool cmp(edge a,edge b){
	return a.dis<b.dis;
}
int D[1000001];
signed main(){
	n=read();m=read();
	memset(D,0x3f,sizeof D);
	for (int i=1;i<=m;i++){
		int a=read(),b=read(),c=read();
		made(a,b,c);
		D[a]=min(D[a],c+1);
		D[b]=min(D[b],c+2);
	}
	for (int i=0;i<n;i++) F[i]=i;
	for (int i=0;i<n;i++) D[i]=min(D[i],D[(i-1+n)%n]+2);
	for (int i=0;i<n;i++) D[i]=min(D[i],D[(i-1+n)%n]+2);
	for (int i=0;i<n;i++){
		made(i,(i+1)%n,D[i]);
	}
	sort(g+1,g+1+tot,cmp);
	int ans=0;
	for (int i=1;i<=tot;i++){
		int u=g[i].from,v=g[i].to;
		int uu=find(u),vv=find(v);
		if (F[uu]!=vv){
			F[uu]=vv;ans+=g[i].dis;
		}
	}
	cout<<ans;
    return 0;
}

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

int main(){
  int n,m,a;
  set<int> s,t;
  cin >> n;
  while(n--){
    cin >> a;
    s.insert(a);
  }
  cin >> m;
  while(m--){
    cin >> a;
    t.insert(a);
  }
  vector<int> v;
  set_intersection(s.begin(),s.end(),t.begin(),t.end(),back_inserter(v));
  r(i,v.size()){
    cout << v.at(i)<<endl;
  }
}


Measured memory_bytes: 21924
N = int(input())

x = (3500 * N + (4 * 2500 - 2 * N) - 1) //(4 * 2500 - 2 * N) #n, wを3500としたときのwの値、wはx以下
for h in range(x, 0, -1):
    for n in range(3500, 0, -1):
        if (N * h * n) >= (4 * h * n - N * (h + n)) > 0:
            if (N * h * n) % (4 * h * n - N * (h + n)) == 0:
                w = (N * h * n) // (4 * h * n - N * (h + n))
                print (h, n, w)
                exit()


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>

int max(int a, int b){
  if( a > b ) return a;
  else return b;
}

int main(){

  int shop;
  scanf("%d",&shop);

  int open[101][11];
  for(int i = 1; i <= shop; ++i){
    for(int j = 1; j <= 10 ; ++j){
      scanf("%d",&open[i][j]);
    }
  }

  int p[101][11];
  for(int i = 1; i <= shop ; ++i){
    for(int j = 0; j <= 10 ; ++j){
      scanf("%d",&p[i][j]);
   }
  }

  long long int ans = -99999999999999999;
  for(int bit = 1; bit < (1 << 10) ; ++bit){
    int tmp = 0;

      for(int i = 1; i <= shop; ++i){
        int shop_count = 0;
        for(int j = 1; j <= 10 ; ++j){
          if( ( ((bit >> (j-1)) & 1) == 1 ) && open[i][j] == 1 ){
            shop_count ++;
          }
        }
      tmp += p[i][shop_count];
      }
      ans = max(ans,tmp);

  }
  printf("%d",ans);
}


Measured memory_bytes: 128
N, K, S = map(int, input().split())

huge = 1000000000
if S == huge:
    huge -= 2

A = [huge] * N

for i in range(N):
    if K == 0:
        break

    A[i] = S

    K -= 1


for i in range(N):
    print(A[i], end=" ")

Measured memory_bytes: 49752
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(10) << num << endl;
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string s; cin >> s;
    ll ans=0;
    bool ue=0;
    for(int i=s.size()-1;i>=0;i--){
        int x=s[i]-'0';
        x+=ue;
        if(x==5){
            if(i>0&&(s[i-1]-'0')>4) ue=1;
            else ue=0;
            ans+=5;
        }else{
            ans+=min(x,10-x);
            if(x<5) ue=0;
            else ue=1;
        }
    }
    ans+=ue;
    cout << ans << endl;
}



Measured memory_bytes: 1412
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int n, max = -1;
        long sum;
        int[] x, yx;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = new int [n];
        yx = new int [n];
        for (int i = 0; i < n; i++)
            x[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            yx[i] = sc.nextInt() - x[i];

        sum = 0;
        for (int i = 0; i < n; i++)
            sum += Math.abs(yx[i]);
        System.out.println(sum);

        sum = 0;
        for (int i = 0; i < n; i++)
            sum += yx[i] * yx[i];
        System.out.println(Math.sqrt(sum));

        sum = 0;
        for (int i = 0; i < n; i++)
            sum += Math.abs(yx[i] * yx[i] * yx[i]);
        System.out.println(Math.cbrt(sum));

        sum = 0;
        for (int i = 0; i < n; i++) {
            if (Math.abs(yx[i]) > max)
                max = Math.abs(yx[i]);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 26508
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
int main() {
	int k;
	cin >> k;
	vector<long long int> a(k + 10);
	a.at(0) = 2;
	a.at(1) = 1;
	for (int i = 2; i <= k; i++) {
		a.at(i) = a.at(i - 1) + a.at(i - 2);
	}
	cout << a.at(k ) << endl;

	return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
vt<vt<ll>> adj(100);
ll dfs(ll x,vt<vt<ll>> &adj,vt<bool> &visited){
    ll i,ans=1;
    visited[x]=true;
    f(i,0,adj[x].size(),1)
        if (!visited[adj[x][i]])
            ans+=dfs(adj[x][i],adj,visited);
    return ans;
}
void solve(){
    ll n,m,i,j,x,y,temp,ans=0,p;
    cin>>n>>m;
    f(i,0,m,1){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    f(i,1,n+1,1){
        f(j,0,adj[i].size(),1){
            p=adj[i][j];
            adj[i].erase(adj[i].begin()+j);
            vt<bool> visited(100,false);
            temp=dfs(1,adj,visited);
            if (temp<n)
                ans++;
            adj[i].insert(adj[i].begin()+j,p);
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  vector<int> rows(H, 0);
  vector<int> cols(W, 0);
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      cin >> grid[h][w];
      if (grid[h][w] == '#') {
        ++rows[h];
        ++cols[w];
      }
    }
  }

  for (int h = 0; h < H; ++h) {
    if (rows[h] == 0) continue;
    for (int w = 0; w < W; ++w) {
      if (cols[w] == 0) continue;
      cout << grid[h][w];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 5000000+10;
bitset<MAXN> bit;
int n, a;

void solve()
{
	int sum = 0;
	scanf("%d", &n);
	bit[0] = 1;
	while( n-- ){
		scanf("%d", &a);
		sum += a;
		bit |= bit << a;
	}
	for(int i = (sum+1)/2; ;i++){
		if( bit[i] ){
			printf("%d\n", i);
			return;
		}
	}
}

int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 2176
def gcd(a,b):
	return gcd(b,a%b) if b else a

a,b=map(int,input().split())
c=gcd(a,b)
ans=1
cnt=2
while(cnt*cnt<c):
	bo=False
	while(c%cnt==0):
		if not bo:
			ans+=1
			bo=True
		c//=cnt
	cnt+=1
if c!=1:
	ans+=1
	
print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;
const ll INF = 1e12;

ll snuke(std::vector< ll >& va, ll b) {
  std::vector< ll >::iterator it;
  ll ans = 0;
  for (it = va.begin(); it != va.end(); it++) {
    ll idx = std::distance(va.begin(), it);
    ans += (ll)std::fabs(va[idx] - (b + idx));
  }
  return ans;
}

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  ll ans = INF;
  ll max_val = *std::max_element(va.begin(), va.end());


  ll l = -max_val * 100;
  ll r = +max_val * 100;
  while (r - l > 1) {
    ll mid = (r + l) / 2;
    ll l_val = snuke(va, mid - 1);
    ll m_val = snuke(va, mid + 0);
    ll r_val = snuke(va, mid + 1);
    //std::cout << l << " " << r << " " << mid << " " << ans << std::endl;
    //std::cout << "val: " << l_val << " " << m_val << " " << r_val << std::endl;
    if (m_val <= r_val && m_val <= l_val) {
      ans = m_val;
      break;
    }
    if (l_val <= m_val && m_val <= r_val) {
      r = mid;
      ans = l_val;
    } else {
      l = mid;
      ans = r_val;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int n, i, fib[45];

  scanf("%d", &n);
  for(i=0; i<=n; i++){
    if(i==0 || i==1) fib[i] = 1;
    else fib[i] = fib[i-1] + fib[i-2];
  }
  printf("%d", fib[n]);
  putchar('\n');
    
  return 0;
}

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

map <int,int> m;

int main() {
    int n,cnt=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int i = 0;
    while(m[i] == 0 && i != 1)
    {
        m[i] = 1;
        i = a[i] - 1;
        cnt++;
    }
    if(i!=1)
        cout<<"-1\n";
    else
        cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 5376
from collections import  Counter

n=int(input())
a=list(map(int,input().split()))
a.sort()

tmp=Counter(a)
if len(tmp)>3:
    print("No")
elif len(tmp)==1:
    if not 0 in a:
        print("No")
    else:
        print("Yes")
elif len(tmp)==2:
    if tmp[0]==n//3 :
        print("Yes")
    else:
        print("No")
else:
    values, counts=zip(*tmp.most_common())
    if counts[0]==counts[1]==counts[2] and values[0]^values[1]^values[2]==0:
        print("Yes")
    else:
        print("No")



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

int main() {
  string s;cin>>s;
  rep(i,s.size()){
    if(s[i]=='C'){
    for(int j=i+1;j<s.size();j++){
    if(s[j]=='F'){
      cout<<"Yes"<<endl;
      return 0;
    }
    }
    }
  }
  cout<<"No"<<endl;
}

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

int main()
{
	int n;
	cin>>n;
	int ar[n+1];
	for(int i =0; i < n; i++)
	cin>>ar[i];
	sort(ar , ar+n);
	int prev = ar[n-1];
	int cnt = 1;
	for(int i = n-1; i >= 0; i--)
	{
		if(prev > ar[i])
		{
			cnt++;
			prev = ar[i];
		}
	}
	cout<<cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int k, x;

    scanf("%d%d", &k, &x);
    if (x - k < -1000000) {
        for (int i = -1000000; i < x + k; i++) {
            printf("%s%d", i == -1000000 ? "" : " ", i);
        }
    } else if (1000000 - x < k) {
        for (int i = x - k + 1; i <= 1000000; i++) {
            printf("%s%d", i == x - k + 1 ? "" : " ", i);
        }
    } else {
        for (int i = x - k + 1; i < x + k; i++) {
            printf("%s%d", i == x - k + 1 ? "" : " ", i);
        }
    }

    printf("\n");
    return 0;
}


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

int main() {
	long long n;
	cin>>n;
	long long ans = LONG_MAX;
    for(int i =1 ; i <= sqrt(n) ; i++)
    {
        if(n%i == 0)
        {
            ans = min(ans , (i-1)+(n/i - 1));
        }
    }
    cout<<ans<<endl;
	exit(0);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;


int main(){

	int id;
	double weight,height;

	while(scanf("%d,%lf,%lf",&id,&weight,&height)!=EOF){
		if((weight/(height*height)) >= 25.0){
			printf("%d\n",id);
		}
	}
	return 0;
}



Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
#define INF 10e10
#define LL long long int
LL dp[100001];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n,w,valSum=0;
    cin >> n >> w;
    int wgt[n+1],val[n+1];
    for(int i=1; i<100001; i++) dp[i] = INF;
    for(int i=1; i<=n; i++) {
        cin >> wgt[i] >> val[i];
        valSum += val[i];
    }
    for(int i=1; i<=n; i++) {
        for(int j=valSum; j>=val[i]; j--) {
            dp[j] = min(dp[j],dp[j-val[i]]+wgt[i]);
        }
    }
    for(int i=valSum; i>=0; i--) {
        if(dp[i]<=w) {
            cout << i << "\n";
            break;
        }
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,d;
	cin>>n>>d;
	
	vvi x(n,vi(d));
	REP(i,n){
		REP(j,d){
			cin>>x[i][j];
		}
	}
	
	int ans=0;
	for(int i=0;i<n-1;++i){
		for(int j=i+1;j<n;++j){
			double tmp=0;
			REP(k,d){
				tmp+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			tmp=sqrt(tmp);
			if((int)tmp==ceil(tmp)) ans++;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define PI pair<int,int>

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = (ll)(1e9 + 7);
const int N = 1000010;

int A, B, H, M;

int main() {    
    while (cin >> A >> B >> H >> M) {
        double e1 = -(1.0 * (H * 60 + M) / 360 * pi - pi / 2);
        double e2 = -(1.0 * M / 30 * pi - pi / 2);
        double a = A * cos(e1), b = A * sin(e1);
        double c = B * cos(e2), d = B * sin(e2);
        double dis = sqrt((a - c) * (a - c) + (b - d) * (b - d));
        cout << setprecision(14) << dis << endl;
    }
    return 0;
}
    


Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
#define PB push_back
#define FF first
#define SS second

const int INF = 2000000000;
const int N = 100000;
int arr[N];

class BIT{
	#define lowbit(x) ((x)&(-(x)))
	private:
		lld* arr;
		int size;
	public:
		//1-base (l, r]
		void init(int n){
			size=n;
			arr=new lld[n];
			fill(arr,arr+n,0);
		}
		void add(int l, int r, lld v){
			add(r, v);
			add(l, -v);
		}
		void add(int r, lld v){
			while(r){
				arr[r]+=v;
				r-=lowbit(r);
			}
		}
		lld query(int x){
			lld sm=0;
			while(x<size){
				sm+=arr[x];
				x+=lowbit(x);
			}
			return sm;
		}
	#undef lowbit
};

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, m;cin>>n>>m;
	for(int i=0;i<n;i++) cin>>arr[i];
	lld sumL=0, sumR=0;
	for(int i=0;i<n-1;i++) sumL+=arr[i];
	for(int i=1;i<n;i++) sumR+=arr[i]+m*(arr[i-1]>arr[i]);
	BIT cnt, sm;
	cnt.init(m+5);sm.init(m+5);
	for(int i=1;i<n;i++){
		if(arr[i-1]>arr[i]){
			cnt.add(arr[i-1], m, 1);
			cnt.add(0, arr[i], 1);
			sm.add(arr[i-1], m, arr[i-1]);
			sm.add(0, arr[i], arr[i-1]-m);
		}else{
			cnt.add(arr[i-1], arr[i], 1);
			sm.add(arr[i-1], arr[i], arr[i-1]);
		}
	}
	lld val=sumR-sumL;
	for(int i=1;i<=m;i++){
		lld curV=sumR-sumL-cnt.query(i)*i+sm.query(i)+cnt.query(i);
		if(curV < val) val=curV;
	}
	cout<<val<<'\n';
	return 0;
}

Measured memory_bytes: 2176
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
d=[]
max=0
num=0
for i in range(n):
            d.append(v[i]-c[i])
"""
for i in range(n-1):
    num=d[i]

    for k in range(n-i-1):
        if(num+d[i+1+k]>max):
            max=num+d[i+1+k]
"""
d.sort()
d.reverse()
for i in range(n):
    num=max+d[i]
    if num>max:
        max=num

print(max)

Measured memory_bytes: 3064
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    state = np.zeros((m,n),dtype=int)
    for i in range(m):
        ks = list(map(int,ipt().split()))
        for j in ks[1::]:
            state[i][j-1] = 1
    p = [int(i) for i in ipt().split()]
    ans = 0
    fm = "0"+str(n)+"b"
    for i in range(2**n):
        li = np.array(list(map(int,format(i,fm))))
        for i,si in enumerate(state):
            if not np.count_nonzero(li&si)%2 == p[i]:
                break
            if i == m-1:
                ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 14436
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();
    //500
    let a = list[0];
    //100
    let b = list[1];
    //50
    let c = list[2];
    let x = list[3];

    let mut n = 0;
    for i in 0..(a + 1) {
        for j in 0..(b + 1) {
            for k in 0..(c + 1) {
                if i * 500 + j * 100 + k * 50 == x {
                    n += 1;
                }
            }
        }
    }
    n.to_string()
}

#[test]
fn test() {
    let tests = vec![
        (
            "2
2
2
100",
            "2",
        ),
        (
            "5
1
0
150",
            "0",
        ),
        (
            "30
40
50
6000",
            "213",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


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

const int N = 1e5;
vector<int> g[N];
vector<int> v(N, -1);
int ml[N], mr[N];

int imp = 0;
pair<int, int> dfs(int i, int p, int l, int r) {
  if(v[i] != -1) {
    if((l % 2 + 2) % 2 != v[i] % 2 || (v[i] < l || v[i] > r)) {
      imp = 1;
      cerr << 1 << endl;
      return make_pair(0, 0);
    }
    l = r = v[i];
  }
  int nl = l, nr = r;
  for(int j : g[i]) if(j != p) {
    auto d = dfs(j, i, l - 1, r + 1);
    nl = max(nl, d.first);
    nr = min(nr, d.second);
  }
  if(nl > nr) imp = 1, cerr << 2 << endl;
  ml[i] = nl;
  mr[i] = nr;
  return make_pair(nl - 1, nr + 1);
}

void dfs2(int i, int p, int l) {
  l = max(l, ml[i]);
  if(v[i] == -1) {
    v[i] = l;
  }
  for(int j : g[i]) if(j != p) {
    dfs2(j, i, v[i] - 1);
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k; cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  int p = -1;
  cin >> k;
  for(int i = 0; i < k; i++) {
    int a, b; cin >> a >> b;
    a--;
    v[a] = b;
  }
  for(int i = 0; i < n; i++) if(v[i] != -1) p = i;
  dfs(p, -1, v[p], v[p]);
  dfs2(p, -1, v[p]);
  if(imp) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for(int i = 0; i < n; i++) {
      cout << v[i] << endl;
    }
  }
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b, c; cin >> a >> b >> c;
    cout << ((b - a == c - b) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N);
	in(string, S);
	vector<ll> sum(N+1);
	ll tmp = 0, cnt = 0;
	loop(i, N){
		sum[i] = tmp;
		tmp += (S[i] == 'E' ? 1 : 0);
	}
	sum[N] = tmp;
	ll ans = INF;
	loop(i, N) {
		ll cnt = (sum[N] - sum[i+1]) + (i - 0) - (sum[i] - sum[0]);
		ans = std::min(ans, cnt);
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 2964
#include <iostream>
#include <cstring>
using namespace std;
char s1[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
int cnt;
char s2[16];
int main()
{
	cin>>s2;
	for(int i=0;i<16;i++)
	{
		if(s1[i]!=s2[i])
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main() {
    string s; bool ans=1;
    cin>>s;
    for(int i=0;i<s.size();i++) {
        if(i%2==0) {
            if((s.at(i)!='R' && s.at(i)!='U') && s.at(i)!='D') {
            ans=0; cout<<"No"<<endl; return 0;
            }
        }
        else if(i%2==1) {
            if((s.at(i)!='L' && s.at(i)!='U') && s.at(i)!='D') {
            ans=0; cout<<"No"<<endl; return 0;
            }
        }
    }
    if(ans) cout<<"Yes"<<endl;
    return 0;
}

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


int main(){
  string s,t;
  int a=0,k=0;
  
  cin >> s >> t;
  

   rep(i,(int)s.size()-(int)t.size()+1){
     
     rep(j,(int)t.size()){
       if(s.at(i+j)==t.at(j))
         a++;
     }
     k=max(k,a);
     a=0;
  /*for(int i=j;i<(int)s.size()-j;i++){
    
    

    /*if(s.at(i)==t.at(j)){
      while(s.at(i+a)==t.at(j+a) && i+a<(int)s.size() && j+a<(int)t.size()){
        a++;
      }
      k=max(k,a);
      a=0;
    }
      */
    //}
     //cout << k << endl;
  }
  
cout << (int)t.size()-k << endl;;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
#define pb push_back
#define fr first
#define sc second

int main(){
	int N;
	scanf("%d",&N);
	ll sum;
	scanf("%lld",&sum);
	
	static int cnt = 0;
	static vector<ll> vec[100010];
	for(int i = 2 ; i <= N ; i ++){
		char c;
		ll x;
		scanf(" %c %lld",&c,&x);
		sum += x;
		if(c == '-')cnt ++;
		vec[cnt].pb(x);
	}
	if(cnt == 0){
		cout << sum << endl;
		return 0;
	}
	ll ret = 1000000000000000000;
	ll S = 0;
	for(int i = 1 ; i <= cnt+1 ; i ++){
		if(vec[i].size() == 0){
			ret = min( ret , S );
			break;
		}
		ll T = S;
		for(int j = 0 ; j < vec[i].size() ; j ++){
			T += vec[i][j];
		}
		ret = min( ret , T );
		S += vec[i][0];
	}
	cout << sum-ret*2 << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int N;
        int t[100010],x[100010],y[100010];

        cin >> N;
        t[0]=0;
        x[0]=0;
        y[0]=0;
        for(int i=1; i<=N; i++) cin >> t[i] >> x[i] >> y[i];

        for(int i=1; i<=N; i++){
                int T=t[i]-t[i-1], X=abs(x[i]-x[i-1]), Y=abs(y[i]-y[i-1]);
                if((T<X+Y)||(T%2!=(X+Y)%2)){
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;
        return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d[] = new int[3];
     d[0] = sc.nextInt();
     d[1] = sc.nextInt();
     d[2] = sc.nextInt();
     Arrays.sort(d);
     System.out.println(d[0]+d[1]);
   }
}

Measured memory_bytes: 21972