akhauriyash/Code-Regression huggingface dataset:
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>
#include <tuple>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b){
	if(a<b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b){
	if(a>b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) {return std::vector<T>(len, elem);}
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i] <<std:: endl;
		else std::cout << da[i] << ' ';
	}
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;


int main(){
	int h,n;
	cin >> h >> n;
	vector<Pll> da(n);
	rip(i,n,0) cin >> da[i].first >> da[i].second;
	vector<ll> dp(h+2,LLONG_MAX);
	dp[0] = 0;
	rip(i,h+1,1){
		rip(j,n,0){
			if(i - da[j].first >= 0){
				chmin(dp[i], dp[i - da[j].first] + da[j].second);
			}
			else{
				chmin(dp[i], da[j].second);
			}
		}
	}
	cout << dp[h] << endl;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
i = 0
c = 0
while (i + 1) + i < (n - i - (i + 1)) and c < m:
    print(i + 1, n - i)
    c += 1
    i += 1
a = n // 2 + n % 2
for i in range(m - c):
    print(a - i - 1, a + i + 1)

Measured memory_bytes: 70236
#include <iostream>
#include <climits>

long long int merge(long long int* A, int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	
	long long int* L = new long long int[n1+1];
	for (int i=0; i<n1; i++) L[i] = A[left+i];
	L[n1] = INT_MAX;
	
	long long int *R = new long long int[n2+1];
	for (int i=0; i<n2; i++) R[i] = A[mid+i];
	R[n2] = INT_MAX;
	
	long long int count = 0;
	int i=0, j=0;
	for (int k=left; k<right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i]; i++;
		}
		else {
			A[k] = R[j]; j++; 
			count += (long long int)(n1 - i);
		}
	}
	
	delete[] L;
	delete[] R;
	
	return count;
}

long long int mergeSort(long long int* A, int left, int right)
{
	long long int count = 0;
	
	if (left+1 < right) {
		int mid = (left + right) / 2;
		count += mergeSort(A, left, mid);
		count += mergeSort(A, mid, right);
		count += merge(A, left, mid, right);
	}
	
	return count;
}

int main()
{
	int n;
	std::cin >> n;
	
	long long int *A = new long long int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	long long int inversion = mergeSort(A, 0, n);
	
	std::cout << inversion << std::endl;
	
	delete[] A;
	
	return 0;
}




Measured memory_bytes: 5880
#include <iostream>
#include <math.h>
using namespace std;

int f(long long a, long long b){
  int numa = 0;
  int numb = 0;
  while(a > 0){
    numa++;
    a /= 10;
  }
  while(b > 0){
    numb++;
    b /= 10;
  }
  if(numa > numb) return numa;
  else return numb;
}

int main(void){
  long n;
  cin >> n;
  int ans = 100;
  int temp;
  for(long  long i = 1; i <= sqrt(n); i++){
    if(n % i == 0) temp = f(i, n / i);
    if(temp < ans) ans = temp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#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 INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){ 
    ll N;
    string S;
    cin >> N >> S;
    ll ans=0;
    for(int i = 0; i < N-2; i++){
        if( S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int ans = 0;
    int n;

    scanf("%d", &n);
    int b[n - 1];
    for (int i = 0; i < n - 1; i++)
        if (i == 0)
        {
            scanf("%d", &b[0]);
            ans += b[0];
        }
        else
        {
            scanf("%d", &b[i]);
            if (b[i] < b[i - 1])
                ans += b[i];
            else
                ans += b[i - 1];
        }

    ans += b[(n - 1) - 1];

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

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int numCount = inpt[0];

        for (int i = 0; i < numCount; i++)
        {
            src.Add(Reader.ReadLine());
        }
        src.Sort();


        string ans = string.Join("", src);
        Console.WriteLine(ans);


    }

    List<String> src = new List<string>();



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



3 3
dxx
axx
cxx

";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

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

int main() {
	while (1) {
		string s;
		cin >> s;
		if (s == "-")
			break;
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			int h;
			cin >> h;
			s = s.substr(h, s.size() - h) + s.substr(0, h);
		}
		cout << s << endl;
	}
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    string s1,s2;
    cin>>s1>>s2;
    int cnt=0;
    for(int i=0;i<s1.length();i++)
    {
        if(s1[i]!=s2[i])
            cnt++;
    }
    cout<<cnt<<endl;
}       
  
main()
{
    int t=1;
    //cin>>t;
    while(t)
    {
        t--;
        solve();
   }         
   return 0;
}

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

int main(){
  int d;
  long long sum;
  while(scanf("%d",&d)!=EOF){
    sum=0;
    for(int i=0;i<=600-d;i+=d){
      sum+=(i*i)*d;
    }
    printf("%lld\n",sum);
  }
  return 0;
}

Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {

            var vals = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            int N = vals[0];
            int M = vals[1];

            var A = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            int sum = 0;
            foreach(int x in A)
            {
                sum += x;
            }
            var ans = Math.Max(N - sum, -1);
            Console.WriteLine(ans);
            


        }
       

    }
}


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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

bool isPrime(int a) {
	if (a == 2) {
		return true;
	}

	if (a % 2 == 0) {
		return false;
	}

	for (int i = 3; i * i <= a; i += 2) {
		if (a % i == 0) {
			return false;
		}
	}

	return true;
}

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

	int n;
	cin >> n;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;

		ans += isPrime(a);
	}

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

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	long long ans=0;
	for(long i=1;i<=n;i++)
	{
		long long x;
		cin>>x;
		if(i%2!=0&&x%2!=0)
		{
			ans+=1;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3616
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ways = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500 + j*100 + k*50 == x:
        ways += 1
print(ways)

Measured memory_bytes: 3060
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextLong()

    var max = 1L
    while (true) {
        if ((max + 1) * (max + 1) > n) {
            println(max * max)
            return
        }
        max += 1
    }


}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int bot = max(a,c);
    int top = min(b,d);
    cout << max(top - bot,0);
    cout << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

s = sum(a)

if s%(n*(n+1)//2)!=0:
    print('NO')
    exit()

ss = s//(n*(n+1)//2)

b = [0 for i in range(n)]

# a[i]-a[i-1] = ss-b[i-1]*n
for i in range(n):
    b[i-1] = (ss-a[i]+a[i-1])//n
    if b[i-1]<0:
        print('NO')
        exit()

c = [0 for i in range(n)]
for i in range(n):
    c[0]+=b[i]*(n-i)

for i in range(1,n):
    c[i] = c[i-1] + ss - b[i-1]*n

if a==c:
    print('YES')
else:
    print('NO')



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

int main() {
  int N,M;
  cin >> N >> M;
  int a, b;
  vector<int> flag(N,999999);
  
  for (int i=0; i<M; ++i) {
    cin >> a >> b;
    flag[a-1] = min(flag[a-1],b-1);
  }
  
  int ans = 0;
  for (int i=0; i<N-1; ++i) {
    if (flag[i] == i+1) {
      ++ans;
    }
    else {
      flag[i+1] = min(flag[i+1],flag[i]);
    }
  }
  
  cout << ans << "\n";
}
  

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

int main() {
	string s;
	cin >> s;
	if (s=="Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy"){
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner scan = new Scanner(System.in);

        while(true){
            int h = scan.nextInt();
            int w = scan.nextInt();
            if(h == 0 && w == 0){
                break;
            }
            for(int i = 0;i<h;i++){
                for(int j= 0;j<w;j++){
                    if(i==0 || i == h-1 || j==0 || j== w-1){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }

    }

}



Measured memory_bytes: 59568
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];

        var k = n * (n - 1) / 2 + m * (m - 1) / 2;

        Console.WriteLine(k);
    }
}


Measured memory_bytes: 13268
/* ITP1_8_D */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      String s = br.readLine();
      String p = br.readLine();
      int s_len = s.length();
      int p_len = p.length();
      if(s_len < p_len) return;

      char[] s_char = s.toCharArray();
      boolean judge = false;

      for(int i = 0; i < s_len; i++){
        if(s_char[i] == p.charAt(0)){
          // CHECK
          if( ((i + 1) + p_len) > s_len ){
            sb.append(s.substring(i, s_len));
            sb.append(s.substring(0, (p_len - (s_len - i)) ));
          }else {
            sb.append(s.substring(i, i + p_len));
          }
          // JUDGE
          if(p.equals(sb.toString())){
            judge = true;
            break;
          }
          sb.delete(0, sb.length());
        }
      }
      // OUTPUT
      if(judge)
        System.out.println("Yes");
      else
        System.out.println("No");
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

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

int main(){
  int N,l,r;
  int total = 0;
  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> l >> r;
    total += r - l + 1;
  }
  cout << total << endl; 
}

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

int main() {
	int s[] = {0, 0}, n;
	char input[5];
	scanf("%s", input);
	for (int i = 0; i < 3; i++) s[input[i] - 48]++;
	
	printf("%d", s[1]);
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long s = fs.nextLong();
        long c = fs.nextLong();

        if (c <= s) {
            System.out.println(c / 2);
            return;
        }
        long count = s;
        c -= s * 2;
        count += c / 4;
        System.out.println(count);
    }
}


Measured memory_bytes: 81748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define 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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;


int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  vector<ll> lis(n+1,INFLONG);
  rep(i,n){
    cin >> vec[i];
  }
  rep(i,n){
    auto itr = lower_bound(all(lis),vec[i]);
    *itr = vec[i];
  }
  ll ans = 0;
  rep(i,n){
    if(lis[i] != INFLONG){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4404
using System;
using System.Linq;
using System.Collections.Generic;

namespace CF2017qC
{
    class C
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToList();

            int count = 0;
            while (0 < s.Count)
            {
                if (s[0] == s[s.Count - 1])
                {
                    s.RemoveAt(0);
                    if (0 < s.Count) s.RemoveAt(s.Count - 1);
                }
                else if (s[0] != s[s.Count - 1])
                {
                    if (s[0] != 'x' && s[s.Count - 1] != 'x')
                    {
                        Console.WriteLine(-1); return;
                    }
                    else if (s[0] != 'x')
                    {
                        s.Insert(0, 'x');
                        count++;
                    }
                    else if (s[s.Count - 1] != 'x')
                    {
                        s.Add('x');
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13228
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        String a1 = sc.next();
        String a2 = sc.next();
        for(int i=0;i<a1.length();i++)
        {
            if(a1.charAt(i)!=a2.charAt(2-i))
            {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");

    }
}

Measured memory_bytes: 22484
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
#define DEBUG_OUTPUT_ARRAY(XXX,ONE) for(int i=0;i<(ONE);i++){cout<<"DEBUG: i = "<<i<<" -> "<<XXX[i]<<endl;}
#define DEBUG_OUTPUT_ARRAY2(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<"<<< i = "<<i<<" >>>"<<endl;for(int j=0;j<(TWO);j++){cout<<"DEBUG: j = "<<j<<" -> "<<XXX[i][j]<<endl; } }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<i<<"  ";for(int j=0;j<(TWO);j++){cout<<XXX[i][j]<<" "; } cout<<endl;}

typedef pair<long long int,long long int> pll;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int A,B,C,X,Y;
string str,resstr;
int main() {
	cout << fixed << setprecision(18);
    
    cin>>A>>B>>C>>X>>Y;
    cout<<min({2*C*max(X,Y),A*X+B*Y,2*C*Y+max(A*(X-Y),0LL),2*C*X+max(B*(Y-X),0LL)})<<endl;
    /*
    if(2*C<=A&&2*C<=B){
        cout<<2*C*max(X,Y)<<endl;
        return 0;
    }
    if(2*C>=A+B){
        cout<<A*X+B*Y<<endl;
        return 0;
    }
    if(2*C<A+B&&(2*C>A||2*C>B)){
        if(X>=Y)cout<<2*C*Y+A*(X-Y)<<endl;
        else{cout<<2*C*X+B*(Y-X)<<endl;}
    }
    */
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#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 MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int n; cin >> n;
  vl a(n),b(n),v(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) v[i] = a[i] - b[i];
  
  ll s_plus = 0LL,s_minus = 0LL;
  rep(i,n) {
    if(v[i] < 0){
      if(v[i]%2 == 1) v[i]++;
      s_minus += v[i]/2;
    }
    else s_plus += v[i];
  }

  //cout << s_minus << " " << s_plus << endl;

  ll s = s_minus + s_plus;
  string ans;
  if(s > 0) ans = "No";
  else ans = "Yes";

  cout << ans << endl;
}


Measured memory_bytes: 512
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A =list(map(int,input().split()))
a=1
b=[0,0,0]
for i in A:
    t=b.count(i)
    if i==b[0]:
        b[0]+=1
    elif i==b[1]:
        b[1]+=1
    elif i==b[2]:
        b[2]+=1
    a=a*t%(10**9+7)
print(a)

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





struct Dsu {
  vector<int> pa, w, rk;
  int n;
  Dsu(int n) : n(n) {
    pa.resize(n);
    iota(pa.begin(), pa.end(), 0);
    rk.assign(n, 0);
    w.assign(n, 0);
  }

  pair<int, int> anc(int u) {
    if (u == pa[u]) return {u, w[u]};
    int a, t; tie(a, t) = anc(pa[u]);
    return {a, t + w[u]};
  }

  void merge(int a, int b, int wt) { // w = wb - wa
    int wb, wa;
    tie(a, wa) = anc(a);
    tie(b, wb) = anc(b);
    wt += wb - wa;
    if (rk[b] < rk[a]) swap(a, b), wt = -wt;
    pa[a] = b;
    w[a] = wt;
    rk[b] += rk[a] == rk[b];
  }
  int ask(int a, int b) {
    int wb, wa;
    tie(a, wa) = anc(a);
    tie(b, wb) = anc(b);
    if (a != b) return INT_MAX;
    return wa - wb;
  }
};



int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M; 
  while (cin >> N >> M) {
    Dsu djs(N);
    while (M--) {
      string s; cin >> s;
      int a, b, w;
      if (s == "!") {
        cin >> a >> b >> w;
        --a, --b;
        djs.merge(a, b, w);
      }
      else {
        cin >> a >> b;
        --a, --b;
        int ans = djs.ask(a, b);
        if (ans == INT_MAX) cout << "UNKNOWN\n";
        else cout << ans << '\n';
      }
    }
  }
}



Measured memory_bytes: 4256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int x = Integer.parseInt(sa[0]);
		br.close();

		for (long a = -1000; a <= 1000; a++) {
			for (long b = -1000; b <= 1000; b++) {
				if (a * a * a * a * a - b * b * b * b * b == x) {
					System.out.println(a + " " + b);
					return;
				}
			}
		}
	}
}


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

int main() {
    int N, K;
    std::cin >> N >> K;

    int x[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> x[i];
    }

    int min = INT32_MAX;
    for (int i = 0; i <= N - K; ++i) { 
        const int d = std::abs(x[i + K - 1] - x[i]) + std::min(std::abs(x[i]), std::abs(x[i + K - 1]));
        min = std::min(min, d);
    }

    std::cout << min << std::endl;

    return 0;
}



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

using namespace std;

template <int p>
struct Modint
{
	int value;

	Modint() : value(0) {}
	Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

	inline Modint &operator+=(const Modint &b)
	{
		if ((this->value += b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator-=(const Modint &b)
	{
		if ((this->value += p - b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator*=(const Modint &b)
	{
		this->value = (int)((1LL * this->value * b.value) % p);
		return (*this);
	}
	inline Modint &operator/=(const Modint &b)
	{
		(*this) *= b.inverse();
		return (*this);
	}

	Modint operator+(const Modint &b) const { return Modint(*this) += b; }
	Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
	Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
	Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

	inline Modint &operator++(int) { return (*this) += 1; }
	inline Modint &operator--(int) { return (*this) -= 1; }

	inline bool operator==(const Modint &b) const { return this->value == b.value; }
	inline bool operator!=(const Modint &b) const { return this->value != b.value; }
	inline bool operator<(const Modint &b) const { return this->value < b.value; }
	inline bool operator<=(const Modint &b) const { return this->value <= b.value; }
	inline bool operator>(const Modint &b) const { return this->value > b.value; }
	inline bool operator>=(const Modint &b) const { return this->value >= b.value; }

	//requires that "this->value and p are co-prime"
	// a_i * v + a_(i+1) * p = r_i
	// r_i = r_(i+1) * q_(i+1) * r_(i+2)
	// q == 1 (i > 1)
	// reference: https://atcoder.jp/contests/agc026/submissions/2845729 (line:93)
	inline Modint inverse() const
	{
		assert(this->value != 0);
		int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
		while (r1)
		{
			int q = r0 / r1;
			r0 -= q * r1;
			swap(r0, r1);
			a0 -= q * a1;
			swap(a0, a1);
		}
		return Modint(a0);
	}

	friend istream &operator>>(istream &is, Modint<p> &a)
	{
		long t;
		is >> t;
		a = Modint<p>(t);
		return is;
	}
	friend ostream &operator<<(ostream &os, const Modint<p> &a)
	{
		return os << a.value;
	}
};

const int MOD = 1e9 + 7;

using Int = Modint<MOD>;


void solve()
{
	int N;
	string S;
	cin >> N >> S;
	vector<Int> dp(N, 1);
	for (int i = 0; i < N-1; i++)
	{
		vector<Int> nx(N-i);
		if (S[i] == '>')
		{
			for (int j = N-i-2; j >= 0; j--)
			{
				nx[j] = nx[j+1] + dp[j+1];
			}
		}
		else
		{
			nx[0] = dp[0];
			for (int j = 0; j < N-i-2; j++)
			{
				nx[j+1] = nx[j] + dp[j+1];
			}
		}
		swap(dp, nx);
	}
	cout << dp[0] << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define Min 10000000000000

int main()
{    
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef APNA_IO
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
    #endif

ll n;
    cin>>n;
    ll h[n];

     for(int i=0;i<n;i++)
     {
        cin>>h[i];
     }

     ll p[n];
     p[0]=0;
     p[1]=abs(h[1]-h[0]);
     
     for(int i=2;i<n;i++)
     {
      p[i]=min(abs(h[i-2]-h[i])+p[i-2],abs(h[i-1]-h[i])+p[i-1]);
  	 }
     cout<<p[n-1];
    	
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a >= c) {
		printf("0\n");
	}
	else if ((a + b) < c) {

		printf("NA\n");
	}
	else {
		printf("%d\n", c - a);

	}
	return 0;
}


Measured memory_bytes: 2740
import sys

def isInc(a, n):
    for i in range(n-1):
        if a[i] > a[i+1]:
            return False
    return True


n = int(input())

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

if isInc(a,n):
    print("YES")
    sys.exit(0)

for i in range(n):
    for j in range(i+1,n):
        a[i], a[j] = a[j], a[i]
        if isInc(a,n):
            print("YES")
            sys.exit(0)
        a[i], a[j] = a[j], a[i]

print("NO")

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

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

  for (int i = 0; i < 8; i++) {
    if (pow(2, i) > n) {
      cout << pow(2, i - 1) << endl;
      return 0;
    }
    if (pow(2, i) == n) {
      cout << pow(2, i) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 384
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
//constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);

int c[300300];
int n, q;
int main() {
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(c, c + n);
	int a;
	for (int i = 0; i < q; i++) {
		cin >> a;
		int ans = 0;
		for (int j = a; j - a <= c[n - 1]; j += a) {
			ans = max(ans, *(std::lower_bound(c, c + n, j) - 1) % a);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 4328
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define INF 5000000000000000

signed main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (k == 1 && s[0] == '1') {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] - '0' > 1) {
      cout << s[i] << endl;
      return 0;
    } else if (s[i] - '0' == 1 && k == i + 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vll arr(n);
  rep(i, n) cin >> arr[i];

  bool res = true;

  rep(i, n) {
    if (i == 0) {
      continue;
    }

    if (arr[i] < arr[i - 1]) {
      res = false;
      break;
    }

    if (arr[i] > arr[i - 1]) {
      --arr[i];
    }
  }

  if (res) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    ll ans = 0;

    // 尺取り法
    int right = 0;
    ll now = 0;  // 現在のXOR値
    for(int i = 0; i < n; ++i){
        while(right < n){
            ll num1 = now, num2 = a[right];
            bool flag = false;
            while(max(num1, num2) > 0){
                if((num1 & 1) & (num2 & 1)){
                    flag = true;
                    break;
                }
                num1 >>= 1;
                num2 >>= 1;
            }

            if(flag){
                break;
            }
            else{
                now ^= a[right++];
            }
        }
        ans += right - i;
        now ^= a[i];
    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

using ll = long long;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> sum(n + 1);
	rep (i, m) {
	  int l, r;
	  cin >> l >> r;
	  sum[l - 1]++, sum[r]--;
	}
	rep (i, n) sum[i + 1] += sum[i];
	int res = 0;
	rep (i, n) if (sum[i] == m) res++;
	cout << res << endl;
	
    return 0;
}


Measured memory_bytes: 3692
NX = input().split(' ')
n = int(NX[0])
x = int(NX[1])

lis = []
X = 0
for i in range(n) :
    p = int(input())
    lis.append(p)
    X += p

x = x - X

lis = sorted(lis)

donuts = x // lis[0]

print( n + donuts )


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
int ans=0;
rep(i,1,n)
{
	int kk=0,x=i;
	while(x)
	{
		x/=10;
		kk++;
	}
	ans+=kk%2;
}
ol(ans);
return 0;
}



Measured memory_bytes: 256
#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 INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int N;
    cin >> N;
    string s;
    int p;
    vector<tuple<string, int, int> > book(N);
    REP(i,N){
        cin >> s >> p;
        book[i] = make_tuple(s, (-1)*p, i);
    }
    sort(ALL(book));
    REP(i,N) cout << get<2>(book[i])+1 << endl;
}

    

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
#define INF 2000000000

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int a[] = {y - x, x + y + 1, -x - y + 1, x - y + 2};
    for(int i=0; i<4; i++)
        if(a[i] < 0) a[i] = INF;

    cout << *min_element(a, a+4) << endl;


    return 0;
}


Measured memory_bytes: 256
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=[int(v)-1 for v in input().split()]
    c+=1
    G[a].append((b,c))
    G[b].append((a,c))
q,k=[int(v) for v in input().split()]
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while stack!=[]:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=[int(v)-1 for v in input().split()]
    print(dis[x]+dis[y])



Measured memory_bytes: 81312
L = list(map(int,input().split()))

L.sort(reverse = True)
d0 = L[0]%2
d1 = L[1]%2
d2 = L[2]%2

S = 2*L[0]-L[1]-L[2]

if d1==d2:
    print(int(S/2))

else:
    print(int((S+1)/2+1))


Measured memory_bytes: 3060
def solve():
        from itertools import permutations
        N, M, R = map(int, input().split())
        rs = map(lambda x: int(x) - 1, input().split())
        dist, ans = [[float("inf") for _ in range(N)] for _ in range(N)], float("inf")
        for _ in range(M):
            v1, v2, d = map(int, input().split())
            dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
        for i in range(N):
            dist[i][i] = 0
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    if dist[i][j] > dist[i][k] + dist[k][j]:
                        dist[i][j] = dist[i][k] + dist[k][j]
        for r in permutations(rs):
            t = 0
            for i in range(R - 1):
                t += dist[r[i]][r[i + 1]]
            ans = min(t, ans)
        print(ans)

if __name__ == "__main__":
    solve()

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    string s;
    cin >> s;
    if (s == ".") return 0;
    
    int it = 0, keep = 0;
    vector<vector<char>> x(40);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '[') {
        it++;
      }
      else if (s[i] == ']') {
        reverse(x[it].begin(), x[it].end());
        for (int j = 0; j < x[it].size(); j++) {
          x[it - 1].emplace_back(x[it][j]);
        }
        x[it].clear();
        it--;
      }
      else if (s[i] == '+') {
        keep++;
      }
      else if (s[i] == '-') {
        keep--;
      }
      else if (s[i] == '?') {
        x[it].emplace_back('A');
        keep = 0;
      }
      else {
        keep += s[i];
        while (keep < 65) keep += 26;
        while (keep > 90) keep -= 26;
        x[it].emplace_back((char) keep);
        keep = 0;
      }
    }
    
    for (int i = 0; i < x[it].size(); i++) cout << x[it][i];
    cout << '\n';
  }
}


Measured memory_bytes: 3152
class Node
  def initialize(id, left, right)
    @id = id
    @parent = -1
    @left = left
    @right = right
  end

  attr_accessor :id, :parent, :left, :right
end

def find_root(node_map)
  node_map.values.each do |node|
    return node if node.parent == -1
  end
end

def walk_inorder(node, node_map, container)
  if (node.left != -1) then
    walk_inorder(node_map[node.left], node_map, container)
  end
  container << node.id
  if (node.right != -1) then
    walk_inorder(node_map[node.right], node_map, container)
  end
end

def walk_preorder(node, node_map, container)
  container << node.id
  if (node.left != -1) then
    walk_preorder(node_map[node.left], node_map, container)
  end
  if (node.right != -1) then
    walk_preorder(node_map[node.right], node_map, container)
  end
end

def walk_postorder(node, node_map, container)
  if (node.left != -1) then
    walk_postorder(node_map[node.left], node_map, container)
  end
  if (node.right != -1) then
    walk_postorder(node_map[node.right], node_map, container)
  end
  container << node.id
end

n = gets.chomp.to_i
node_map = {}

(n).times do |i|
  node_map[i] = Node.new(i, -1, -1)
end

(n).times do
  inputs = gets.chomp.split.map(&:to_i)
  node_map[inputs[0]].left = inputs[1]
  node_map[inputs[0]].right = inputs[2]
  inputs[1..2].each do |child|
    if child != -1 then
      node_map[child].parent = inputs[0]
    end
  end
end

root_node = find_root(node_map)

puts "Preorder"
container1 = []
walk_preorder(root_node, node_map, container1)
puts " " + container1.join(' ')
puts "Inorder"
container1 = []
walk_inorder(root_node, node_map, container1)
puts " " + container1.join(' ')
puts "Postorder"
container1 = []
walk_postorder(root_node, node_map, container1)
puts " " + container1.join(' ')

Measured memory_bytes: 8780
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a=[];
  for($i=0;$i<$n;$i++){
    list($a[]) = explode(" ", trim(fgets(STDIN)));
  }
  $sum=array_sum($a);
  if($sum % 10 != 0){
    echo $sum.PHP_EOL;
    exit;
  }

  $min=PHP_INT_MAX;
  for($i=0;$i<$n;$i++){
    if($a[$i] % 10 == 0) continue;
    $min = min($min, $a[$i]);
  }

  if($min==PHP_INT_MAX) echo "0";
  else echo $sum-$min;
  echo PHP_EOL;
    

Measured memory_bytes: 16256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> board(h, vector<char>(w));
    rep(y, h) rep(x, w) cin >> board[y][x];
    int count = 0;
    rep(y, h) rep(x, w) if (board[y][x] == '#') count++;
    cout << (count == h + w - 1 ? "Possible" : "Impossible") << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  sort(A.begin(),A.end());
  vector<long long> sum(N+1,0);
  for(int i=1;i<=N;i++)  sum.at(i)=sum.at(i-1)+A.at(i-1);
  int ans=1;
  for(int i=N-1;i>=0;i--){
    if(2*sum.at(i)>=A.at(i))  ans++;
    else  break;
  }
  cout << ans << endl;

  return 0;
}


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

struct Unionfind {
	vector< int > par;
	Unionfind(int N) : par(N,-1){
	}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(x == y) return 0;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return 1;
	}
	int root(int k) {
		if(par[k] < 0) return (k);
		return (par[k] = root(par[k]));
	}
	int size(int k) {
		return (-par[root(k)]);
	}
};
struct BipartiteGraph : Unionfind {
	vector< int > color;
	
	BipartiteGraph(int v) : color(v + v, -1), Unionfind(v + v) {}
	
	bool bipartite_graph_coloring()
	{
		for(int i = 0; i < color.size() / 2; i++) {
			int a = root(i);
			int b = root(i + (int) color.size() / 2);
			if(a == b) return (false);
			if(color[a] < 0) color[a] = 0, color[b] = 1;
		}
		return (true);
	}
	
	bool operator[](int k)
	{
		return (bool(color[root(k)]));
	}
};

int main() {
	
	int n;
	cin >> n;
	BipartiteGraph bg(n);
	for(int i=0; i<n-1; i++){
		int u,v,w;
		cin >> u >> v >> w;
		u--;
		v--;
		if(w%2==1) {
			bg.unite(u,v+n);
			bg.unite(u+n,v);
		}
		else{
			bg.unite(u,v);
			bg.unite(u+n,v+n);
		}
	}
	bg.bipartite_graph_coloring();
	for(int i=0; i<n; i++) cout << bg[i] << endl;
}

Measured memory_bytes: 2048