akhauriyash/Code-Regression huggingface dataset:
A,B,M = map(int,input().split())

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

discount = []
for i in [0]*M:
    discount.append(list(map(int,input().split())))

min_comb = min(a)+min(b)

for i in range(M):
    min_comb = min(min_comb,a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2])
ans = min_comb
print(ans)

Measured memory_bytes: 39268
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

int main(){
    map<char, unsigned int> dict;
    string w;
    cin >> w;
    for(int i=0; i<w.size(); i++){
        dict[w[i]] += 1;
    }
    for(auto element:dict){
        if(element.second%2!=0){
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100001];
signed main()
{
    
	int n;
	long long ans=0;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=ans+max(0ll,lower_bound(a+1,a+n+1,a[i]+a[j])-a-1-j);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, K, w[100100];

bool C(int x){
    int cnt = 0;
    int sum = 0;
    for(int i = 0; i < N; i++){
        if(w[i] > x){
            cnt = INF;
            break;
        }
        if(sum + w[i] <= x)sum += w[i];
        else {
            cnt++;
            i--;
            sum = 0;
        }
    }
    cnt++;
    return cnt <= K;
}

int bs(int lb, int ub){
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        if(C(mid))ub = mid;
        else lb = mid;
    }
    return ub;
}

signed main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> w[i];
    }
    cout << bs(0, INF) << endl;

    return 0;
}

/*

*/


Measured memory_bytes: 3472
N, K = map(int, input().split())
P = list(map(int, input().split()))
P_sum = [0]
for p in P:
    P_sum.append(P_sum[-1] + (p + 1) / 2)

print(max([P_sum[i + K] - P_sum[i] for i in range(N - K + 1)]))


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

int main(){
    int n,m;
    cin >> n >> m;
    int ans1 =0,ans2 = 0;
    if(n > 1) ans1 = n * (n-1)/2;
    if(m > 1) ans2 = m * (m-1)/2;
    cout << ans1 + ans2 << endl;
}

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

int main(){
	string s;
	cin>>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<"-1"<<endl;
		return 0;
	}
	if(s.size()<26){
		for(char c='a';c<='z';c++){
			if(s.find(c)==string::npos){
				s+=c;
				cout<<s<<endl;
				return 0;
			}
		}
	}
	if(s.size()==26){
		for(int i=s.size()-1;i>=0;i--){
			vector<bool> flag(26,false);
			for(int j=0;j<i;j++){
				flag[s[j]-'a']=true;
			}
			int cnt=s[i]-'a'+1;
			while(cnt<26&&flag[cnt])cnt++;
			if(cnt==26)continue;
			else if(cnt<26){
				s=s.substr(0,i);
				s+=(char)(cnt+'a');
				cout<<s<<endl;
				return 0;
			}
		}
	}
	return 0;
}

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

bool primeN(int A){
  if(A<=1)return false;
  for(int i=2;i<A;i++){
    if(A%i==0)return false;
  }
  return true;
}

signed main(){
  int N;
  cin>>N;
  int A=N;
  while(!primeN(A))A++;
  cout<<A<<endl;
}

Measured memory_bytes: 256
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main() {
    int a, b;
    readf("%s %s", &a, &b);
    readln;
    
    if (a > 9 || b > 9) {
        writeln(-1);
        return;
    }
    
    writeln(a * b);
}

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

int main() {
  string s;
  cin >> s;
  string ans = "No";
  if (s[1] == s[2]) {
    if (s[0] == s[1] || s[2] == s[3]) ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0) {
    c-=b;
    if(c <= 0)break;
    a-=d;
  }
  if(a > 0)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3628
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
typedef array<LL,3> A;

const LL inf=1LL<<60;

void solve(long long N, std::vector<long long> X, std::vector<long long> Y, std::vector<long long> Q){
	vector<A> ps;
	for(int i=0;i<N;i++){
		ps.push_back({X[i],Y[i],Q[i]});
	}
	sort(ps.begin(),ps.end());
	vector<P> ys;
	LL pl[15]={};
	LL dvs[15];
	for(int i=0;i<N;i++){
		ys.push_back(P(ps[i][1],i));
		pl[i]=ps[i][2];
		dvs[i]=min(abs(ps[i][0]),abs(ps[i][1]));
	}
	sort(ys.begin(),ys.end());
	sort(X.begin(),X.end());
	LL ret[16];
	for(int i=0;i<=N;i++){
		ret[i]=inf;
	}
	LL vs[15];
	for(int u=0;u<(1<<N);u++){
		int c=0;
		for(int i=0;i<N;i++){
			if(u&(1<<i)){
				c++;
			}
		}
		for(int v=u;;v=(v-1)&u){
			LL p=-inf;
			for(int i=0;i<N;i++){
				if((u&(1<<i))&&!(v&(1<<i))){
					p=X[i];
				}
				vs[i]=X[i]-p;
			}
			p=inf;
			for(int i=N-1;i>=0;i--){
				if((u&(1<<i))&&!(v&(1<<i))){
					p=X[i];
				}
				vs[i]=min(vs[i],p-X[i]);
			}
			p=-inf;
			for(int j=0;j<N;j++){
				int i=ys[j].second;
				LL y=ys[j].first;
				if(v&(1<<i)){
					p=y;
				}
				vs[i]=min(vs[i],y-p);
			}
			p=inf;
			for(int j=N-1;j>=0;j--){
				int i=ys[j].second;
				LL y=ys[j].first;
				if(v&(1<<i)){
					p=y;
				}
				vs[i]=min(vs[i],p-y);
			}
			LL sum=0;
			for(int i=0;i<N;i++){
				sum+=pl[i]*min(dvs[i],vs[i]);
			}

			ret[c]=min(ret[c],sum);
			if(v==0){
				break;
			}
		}
	}
	for(int i=0;i<=N;i++){
		cout << ret[i] << endl;
	}
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(X), std::move(Y), std::move(Q));
    return 0;
}


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

int main(void)
{
  int N,K;
  scanf("%d",&N);
  char S[N];
  scanf("%s",S);
  scanf("%d",&K);
  for(int i=0;i<N;i++){
    if(S[i]!=S[K-1]){
      S[i]='*';
    }
    printf("%c",S[i]);
  }
  printf("\n");
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


inline long long gcd(long long a, long long b)
{
  if (b == 0)
    return a;

  return gcd(b, a % b);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long A, B;

  std::cin >> A >> B;

  std::cout << A / gcd(A, B) * B << std::endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string ss;
  cin >> ss;
  int s = 0;
  int ans = 0;
  rep(i, 0, ss.length()) {
    if(ss[i] == 'g') {
      if(s) ans++, s--;
      else s++;
    }else {
      if(s) s--;
      else ans--, s++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
N,M,X = map(int, input().split())
C_A = []
for i in range(N):
    hoge = list(map(int, input().split()))
    C_A.append(hoge)

mini_money = (10**5)*12 + 1

for i in range(2 ** N):
    rikai = [0]*M
    money = 0
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            money += C_A[j][0]
            for k in range(M):
                rikai[k] += C_A[j][k+1]
                #print(money,C_A[j])

    if min(rikai) >= X:
        mini_money = min(money,mini_money)
        #print(mini_money)

if mini_money == (10**5)*12+1:
    print("-1")
else:
    print(mini_money)

Measured memory_bytes: 68660
#include<bits/stdc++.h>
using namespace std;
int g[1000001];
int a[1000001];
int n,cnt,m,t=1;
bool f;
void insertsort(int n,int s){
	int v,j;
	for (int i=s; i<n; i++){
		v=a[i];
		j=i-s;
		while (j>=0 && a[j]>v){
			  a[j+s]=a[j];
			  cnt++;
			  j-=s;
		}
		a[j+s]=v;
	}
}
int main(){
    cin>>n;
    cnt=0; m=0; f=true;
    for (int i=0; i<n; i++){
    	cin>>a[i];
    	if (f){
    	   if (t<=n)
    	      g[m++]=t;
    	   else f=false;
    	   t=3*t+1;
		}
	}
	cout<<m<<endl;
	cout<<g[m-1];
	for (int i=m-2; i>=0; i--)
	    cout<<' '<<g[i];
	cout<<endl;
	for (int i=m-1; i>=0; i--)
	    insertsort(n,g[i]);
	cout<<cnt<<endl;
	for (int i=0; i<n; i++){
		cout<<a[i]<<endl;
	}
	
    return 0;
} 


Measured memory_bytes: 6988
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi p(n);
		int c=0;

		for(int i=0;i<n;i++)
		{
			scanf("%d", &p[i]);
			if(p[i]!=i+1) c++;
		}

		bool ans=(c<=2);
		printf("%s\n", ans?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    i64 n, k, answer;
    is >> n >> k;
    answer = k;
    rep(_, 0, n - 1) {
        answer *= (k - 1);
    }
    os << answer;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, m;
  cin >> n >> m; 
  int left = 1; int right = n;
  for(int i=0; i<m; ++i){
    int a, b;
    cin >> a >> b;
    left = max(left, a);
    right = min(right, b);
  }

  cout << max(right -left + 1, 0) << endl;
  return 0;
}

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


    class Solver5
    {
        /*
         * 
         * https://atcoder.jp/contests/abc115/tasks/abc115_d
         * 
         */
 public void Solve5()
        {
            var nx = u.readLongArrayBySplit();
			var n = nx[0];
            var x = nx[1];
            long ans = 0;

            while (true)
            {
                var thk = new long[5]{ 1, (long)Math.Pow(2,n + 1) - 3, 1, (long)Math.Pow(2, n + 1) - 3, 1 };
                var pc = new long[5] { 0, (long)Math.Pow(2, n ) - 1 , 1, (long)Math.Pow(2, n )- 1, 0 };
                for (int i = 0; i < 5; i++)
                {
                    if (x > thk[i])
                    {
                        x -= thk[i];
                        ans += pc[i];
                    }
                    else if (x < thk[i])
                    {
                        n--;
                        break;
                    }
                    else
                    {
                        ans += pc[i];
                        Console.WriteLine(ans.ToString());
                        return;
                    }
                }

            }

        }
        static void Main()
        {
            var solver = new Solver5();
            solver.Solve5();
        }
    }
    static class u
    {
      public static long[] readLongArrayBySplit() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORI(i, x, y) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n, ans[200005];
pii a[200005];
int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort (a, a+n);
    reverse (a, a+n);
    ans[a[0].se] = a[1].fi;
    for (int i=1; i<n; i++) {
        ans[a[i].se] = a[0].fi;
    }
    for (int i=0; i<n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Akash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBuffet solver = new BBuffet();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBuffet {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = ReadInput.readIntArray(n, in);
            int b[] = ReadInput.readIntArray(n, in);
            int c[] = ReadInput.readIntArray(n - 1, in);
            int prev = -1;
            long total = 0;
            for (int i = 0; i < n; i++) {
                int cur = a[i];
                total += b[cur - 1];
                if (cur - prev == 1) {
                    total += c[prev - 1];
                }
                prev = cur;
            }
            out.println(total);
        }

    }

    static class ReadInput {
        public static int[] readIntArray(int size, Scanner in) {
            int a[] = new int[size];
            for (int i = 0; i < size; i++) {
                a[i] = in.nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 21844
N = int(input())
list = []
for i in range(0,N):
  list.append(input())

frag = 1
for str in list:
  if list.count(str) != 1:
    frag = 0
for i in range(1,N):
  if list[i - 1][len(list[i - 1]) - 1] != list[i][0]:
    frag = 0
    
if frag == 1:
  print("Yes")
else:
  print("No")

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

S=0
for x in range(K,N+2):
  max=(N*(N+1)-(N-x)*(N-x+1))//2
  min=x*(x-1)//2
  S=S+(max-min+1)
S=S%(10**9+7)
print(S)

Measured memory_bytes: 9184
n = int(input())
aa = list(map(int, input().split()))

border = 3200 // 400
arr = [0] * 8
over = 0
for a in aa:
    x = a // 400

    if x >= border:
        over += 1
        continue

    arr[x] = 1

s = sum(arr)

print(max(1, s), s + over)


Measured memory_bytes: 9032
#include <iostream>

using namespace std;

int main() {
    int a;
   double b[15],d;
   string c[15];
    cin >> a;
    
    for(int i = 0; i < a; i++) {
       cin >>b[i]>>c[i];
    }
  
   d =0;
  for(int i=0; i<a;i++){
    
    if(c[i] == "JPY"){
       d += b[i];
    }
    if(c[i] == "BTC"){
      d += 380000*b[i];
    }
  }
  
  cout << d << endl;
  
  return 0;
}
      
    

Measured memory_bytes: 256
from collections import deque
H, W = list(map(int, input().split()))
S = [['#']*(W+2)]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(['#']*(W+2))

mv=[(0,-1),(0,1),(-1,0),(1,0)]
INF = H*W
depth = [[INF]*(W+2) for _ in range(H+2)]
depth[1][1] = 0
stk = deque([[1, 1]])
while len(stk)>0:
    l = stk.pop()
    # print(l)
    x = l[0]
    y = l[1]
    ct = depth[x][y]
    for i, j in mv:
        nx=x+i
        ny=y+j
        if 1<=nx<=H and 1<=ny<=W and S[nx][ny]=='.' and depth[nx][ny]==INF:
            stk.appendleft([nx,ny])
            depth[nx][ny]=ct+1
# print(depth)
if depth[H][W]==INF:
    print(-1)
else:
    dots=0
    for i in range(1,H+1):
        dots+=S[i].count('.')
    # print(dots)
    print(dots-depth[H][W]-1)

Measured memory_bytes: 74020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int juelSize = Integer.parseInt(sc.nextLine());
			String[] value = sc.nextLine().split(" ");
			String[] cost = sc.nextLine().split(" ");
			
			int sum = 0;
			
			for (int i = 0; i < juelSize; i++) {
				int benefit = Integer.parseInt(value[i]) - Integer.parseInt(cost[i]);
				if (benefit > 0) {
					sum += benefit;
				}
			}
			
			System.out.println(sum);
			
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n, m; cin>>n>>m;
  vector<ll> x(m);
  vector<ll> y(m);
  rep(i, m) {
    cin>>x[i]>>y[i];
    x[i]--; y[i]--;
  }

  vector<bool> flg(n, false);
  flg[0] = true;
  vector<ll> a(n, 1);

  rep(i, m) {
    if (a[x[i]] <= 0) continue;

    if (flg[x[i]]) flg[y[i]] = true;
    a[x[i]]--;
    if (a[x[i]] <= 0) flg[x[i]] = false;
    a[y[i]]++;
  }

  ll cnt = 0;
  rep(i, n) {
    cnt += flg[i];
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 5508
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let a: i64 = sc.get();
    let b: i64 = sc.get();
    let x: i64 = sc.get();
    let ans = b/x - (a+x-1)/x + 1;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s,cs;
    int ans = 999,c;
    cin >> s;
    rep(i, s.size() - 2){
        cs = s[i];
        cs += s[i + 1];
        cs += s[i + 2];
        c = atoi(cs.c_str());
        if (abs(753 - c) < ans) {
            ans = abs(753 - c);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W;
	int a = W / 2, b = (W + 1) / 2;
	if (H == 1 || W == 1) {
		cout << 1 << endl;
		return 0;
	}
	int ans = 0;
	ans += H / 2 * b + H / 2 * a;
	if (H & 1) {
		ans += b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    c = [-1]
    prev = -1
    for i in range(n):
        x = int(readline())
        if x != prev:
            c.append(x)
            prev = x

    l = len(c)

    dp = [0] * l
    dp[0] = 1

    idx = dict()

    for i in range(1, l):
        char = c[i]
        dp[i] += dp[i - 1]
        if idx.get(char):
            p = idx[char]
            dp[i] += dp[p]
        idx[char] = i
        dp[i] %= MOD

    print(dp[l - 1])


if __name__ == '__main__':
    main()


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

int main(void){
    string s;
    
    cin >> s;
    
    vector<string> weather = {"Sunny", "Cloudy", "Rainy", "Sunny"};
    
    rep(i, 3){
        if(s == weather.at(i)){
            cout << weather.at(i+1) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
class AOJ
  def initialize
    n = gets.chomp.to_i
    answer = -10e10
    min_value = 10e10

    n.times do |i|
      r = gets.chomp.to_i

      profit = r - min_value

      min_value = [min_value, r].min

      if i.nonzero?
        answer = [answer, profit].max
      end
    end

    puts answer
  end
end

AOJ.new

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

class UnionFind {
public:
    vector<int> parents;

    UnionFind(int n) : parents(n) {
        for (int i = 0; i < n; i++) {
            parents[i] = i;
        }
    }

    int root(int x) {
        if (parents[x] == x) { // root
            return x;
        } else {
            return parents[x] = root(parents[x]);
        }
    }

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return ;

        parents[x] = y;
    }
};

int main(void) {
    int n, q; cin >> n >> q;
    UnionFind uf(n);

    for (int i = 0; i < q; i++) {
        int com, x, y; cin >> com >> x >> y;
        if (com == 0) {
            uf.unite(x, y);
        } else {
            cout << (uf.isSame(x, y) ? 1 : 0) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, a[100009], l[100009], r[100009], ans, g;
int main()
{
    IO
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        l[i]=__gcd(a[i],l[i-1]);
    }
    for(int i=n; i>=1; i--)
    {
        ans=max(ans,__gcd(g,l[i-1]));
        g=__gcd(g,a[i]);
    }
    cout<<ans;
}


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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define int long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const int inf = 1e9+7;

int n, w, a[N], dp[N], b[N], ans;

 main()
{
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i], &b[i]);

    for (int i = 1; i <= n; i++)
    {
        for (int j = w - a[i]; j >= 0; j--)
            dp[j + a[i] ] = max( dp[j + a[i] ], dp[j] + b[i] );
    }
    for (int i = w; i >= 0; i--)
        ans = max(dp[i], ans);

    cout << ans << endl;
}


Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    d = defaultdict(int)
    for s in input():
        d[s] += 1
    print('Yes' if all(v==2 for v in d.values()) else 'No')


main()


Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m, a, b; cin >> n >> m >> a >> b;
  if (2 * (a + b) > n * m or a > n * (m / 2) or b > m * (n / 2)) return cout << "NO" << '\n', 0;
  V<string> c(n, string(m, '.'));
  auto f = [&](int xl, int xr, int yl, int yr, int& a, int& b) {
    int i = xl, j = yl;
    while (a) {
      if (a) c[i][j] = '<', c[i][j + 1] = '>', a--;
      if (a) c[i + 1][j] = '<', c[i + 1][j + 1] = '>', a--;
      if (j + 2 < yr) j += 2;
      else if (i + 2 < xr) i += 2, j = yl;
      else return;
    }
    while (b) {
      if (b) c[i][j] = '^', c[i + 1][j] = 'v', b--;
      if (b) c[i][j + 1] = '^', c[i + 1][j + 1] = 'v', b--;
      if (j + 2 < yr) j += 2;
      else if (i + 2 < xr) i += 2, j = yl;
      else return;
    }
  };
  if (!(n & 1) and !(m & 1)) {
    if (2 * (a + b) == n * m and a & 1) return cout << "NO" << '\n', 0;
    f(0, n, 0, m, a, b);
  } else if (!(n & 1)) {
    if (2 * (a + b) == n * m and a & 1) return cout << "NO" << '\n', 0;
    for (int i = 0; i < n; i += 2) {
      if (!b) break;
      c[i][m - 1] = '^', c[i + 1][m - 1] = 'v', b--;
    }
    f(0, n, 0, m - 1, a, b);
  } else if (!(m & 1)) {
    if (2 * (a + b) == n * m and b & 1) return cout << "NO" << '\n', 0;
    for (int j = 0; j < m; j += 2) {
      if (!a) break;
      c[n - 1][j] = '<', c[n - 1][j + 1] = '>', a--;
    }
    f(0, n - 1, 0, m, a, b);
  } else {
    if (n == 1) {
      for (int j = 0; j < m; j += 2) {
        if (!a) break;
        c[0][j] = '<', c[0][j + 1] = '>', a--;
      }
    } else if (m == 1) {
      for (int i = 0; i < n; i += 2) {
        if (!b) break;
        c[i][0] = '^', c[i + 1][0] = 'v', b--;
      }
    } else {
      for (int j = 0; j < m - 3; j += 2) {
        if (!a) break;
        c[n - 1][j] = '<', c[n - 1][j + 1] = '>', a--;
      }
      for (int i = 0; i < n - 3; i += 2) {
        if (!b) break;
        c[i][m - 1] = '^', c[i + 1][m - 1] = 'v', b--;
      }
      if (!(a & 1) and !(b & 1) and a >= 2 and b >= 2) {
        c[n - 3][m - 3] = c[n - 1][m - 2] = '<';
        c[n - 3][m - 2] = c[n - 1][m - 1] = '>';
        c[n - 3][m - 1] = c[n - 2][m - 3] = '^';
        c[n - 2][m - 1] = c[n - 1][m - 3] = 'v';
        a -= 2, b -= 2;
        f(0, n - 1, 0, m - 3, a, b);
        f(0, n - 3, m - 3, m - 1, a, b);
      } else {
        if (a & 1) c[n - 1][m - 3] = '<', c[n - 1][m - 2] = '>', a--;
        if (b & 1) c[n - 3][m - 1] = '^', c[n - 2][m - 1] = 'v', b--;
        f(0, n - 1, 0, m - 1, a, b);
      }
    }
  }
  cout << "YES" << '\n';
  for (int i = 0; i < n; i++) cout << c[i] << '\n';
}

Measured memory_bytes: 2304
# include<bits/stdc++.h>
using namespace std;
int main(){
long long int L,R;
  cin >> L >> R;
  //
  if(L/2019 != R/2019) cout << 0 <<'\n';
  else {
    int temp, l = L%2019, r = R%2019, res = 2019;
  	for (int i = l; i <r+1; i++){
    	for (int j = l; j < i; j++){
        	temp = (i*j)%2019;
          if(res > temp)
              res = temp;
        }
    }
  	cout << res << '\n';
  }

	return 0;
}

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

int abs(int a, int b) {
  if (a >= b) return a - b;
  else return b - a;
}

int main() {
  int n;
  cin >> n;
  int a0, b0, c0;
  cin >> a0 >> b0 >> c0;
  rep(i,n-1) {
    int a1, b1, c1, a2=a0, b2=b0, c2=c0;
    cin >> a1 >> b1 >> c1;
    a0 = max(b2, c2) + a1;
    b0 = max(a2, c2) + b1;
    c0 = max(a2, b2) + c1;
  }
  cout << max(max(a0, b0), c0);
}


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

vector<pair<int, int> > g[123450];
bool visit[123450];
int  dist[123450];
bool ok = true;

void dfs(int node)
{
    if (visit[node])
        return;

    visit[node] = true;

    for (auto i: g[node]) {
        if (!visit[i.first]) {
            dist[i.first] = dist[node] + i.second;
            dfs(i.first);
        }
        else if (dist[i.first] != dist[node] + i.second) {
            ok = false;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    int l, r, d;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d;
        g[l].push_back(make_pair(r, d));
        g[r].push_back(make_pair(l, -1*d));
    }

    for (int i = 1; i<= n; i++) {
        if (!visit[i]) {
            dfs(i);
        }
    }


    if (ok)
        cout << "Yes\n";
    else
        cout << "No\n";



}


Measured memory_bytes: 11776
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    string s;
    int H, A;
    cin >> H >> A;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    int res = 0;
    while (H > 0) {
        H -= A;
        ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
bool mem[1000001];
bool unprime[1000001];
int main(void){
  int n,x;
  for(int i=2; i<1000001; i++){
    if(!unprime[i]){
      for(int k=2; i*k<1000001; k++){
        unprime[i*k] = true;
      }
    }
  }
  while(cin>>n>>x){
    if(n==0) break;
    memset(mem,0,sizeof(mem));
    mem[0] = true;
    REP(i,n){
      int money;
      cin>>money;
      for(int j=0; j+money<=x; j++){
        if(mem[j]) mem[j+money] = true;
      }
    }
    for(int i = x; i>=1; i--){
      if(i==1){
        cout<<"NA"<<endl;
        break;
      }else if(!unprime[i]&&mem[i]){
        cout<<i<<endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2816
N = int(input())
A, B, C = [input() for _ in range(3)]

count = 0
for i in range(N):
    if A[i] == B[i] and B[i] == C[i]:
        continue
    elif A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
        count += 2
    else:
        count += 1
print(count)


Measured memory_bytes: 3060
N = int(input())
D = sorted(list(map(int, input().split())))
M = int(input())
T = sorted(list(map(int, input().split())))

c = M
for i in range(N):
    #print("i : ", i)
    if c == 0:
        break
    elif D[i] == T[M - c]:
        #print("c : ", c)
        c -= 1

if c == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 33784
#include <stdio.h>

int main()
{
	int n, a[100], min, max;
	
	scanf("%d", &n);
	
	int i;
	for(i=0; i<n; i++) {
		scanf("%d", &a[i]);
    	if(i==0) {
          min=a[i]; max=a[i];
        }
		if(a[i]<=min) min=a[i];
		if(a[i]>=max) max=a[i];
	}
	
	printf("%d", max-min);
	
	return 0;
	
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using std::min;
 
int m_abs(int z)
{
    if (z<0)
        return -z;
    else
        return z;
}
 
int main(void)
{
    int *a,*dp,N,i,j;
    scanf("%d",&N);
    a=new int [N];
    dp=new int [N];
    for (i=0;i<N;i++)
    {
        scanf("%d",a+i);
    }
    dp[N-1]=0;
    dp[N-2]=abs(a[N-2]-a[N-1]);
    for(i=N-3;i>=0;i--)
    {
        dp[i]=min(dp[i+1]+abs(a[i]-a[i+1]),dp[i+2]+abs(a[i]-a[i+2]));
    }
    printf("%d\n",dp[0]);
 
    delete [] a;
 
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio {
  int it, len;
  char s[LEN + 5];
  fastio() {
    it = len = 0;
  }
  char get() {
    if(it < len) return s[it++];
    it = 0, len = fread(s, 1, LEN, stdin);
    return len ? s[it++] : EOF;
  }
  bool notend() {
    char c;
    for (c = get();c == ' ' || c == '\n' || c == '\r';c = get());
    if (it) it--;
    return c != EOF;
  }
  void put(char c) {
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush() {
    fwrite(s, 1, it, stdout);
  }
}buff, bufo;
inline int getint() {
  char c; int res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1;
  for (;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll() {
  char c; ll res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char() {
  char c;
  for (c = buff.get(); c == ' ' || c == '\n' || c == '\r'; c = buff.get());
  return c;
}
#define maxn 200005
#define mp make_pair
typedef pair<int*, int> P;
const int inf = 0x3f3f3f3f;
int n, a[maxn];
vector<int> adj[maxn];
int f[maxn], ans[maxn];
stack <P> stk;
void dfs(int u, int fa) {
  int *p = lower_bound(f + 1, f + n + 1, a[u]);
  stk.push(mp(p, *p));
  *p = a[u];
  ans[u] = lower_bound(f + 1, f + n + 1, inf) - f - 1;
  for (auto v : adj[u]) {
    if (v != fa) dfs(v, u);
  }
  *stk.top().first = stk.top().second;
  stk.pop();
}
int main() {
  n = getint();
  for (int i = 1; i <= n; i++) a[i] = getint();
  for (int i = 1; i < n; i++) {
    int u = getint(), v = getint();
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(f, 0x3f, sizeof(f));
  dfs(1, 0);
  for (int i = 1; i <= n; i++) putint(ans[i], '\n');
  bufo.flush(); 
  return 0;
}



Measured memory_bytes: 36952
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>//"M_PI"→円周率(小数点以下5桁)
#include<iomanip>//fixed<<setprecision(15)<<
#define LL long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define E "\n"
#define PI 3.141592653589793


int main(){
  int a,b;cin>>a>>b;
  if((a+b)%2==0)
    cout<<(a+b)/2<<E;
  else cout<<(a+b+1)/2<<E;
}

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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    int a[m];
    int cnt1=0,cnt2=0;
    for(int i=0;i<m;i++){
        cin>>a[i];
        if(a[i]<x)cnt1++;
        else cnt2++;
    }
    if(cnt1>cnt2)cout<<cnt2<<endl;
    else cout<<cnt1<<endl;
    return 0;
}

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

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

int main() {
    int A, B;
    std::cin >> A >> B;
    std::cout << max(A-2*B, 0);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long pref[200005],n,k,kcl,bsr,ans;
const long long mod = 1000000007;
int main(){
    cin>>n>>k;
    for(int i =1;i<=n;i++){
        pref[i]=(pref[i-1]+i)%mod;
    }
    for(int i =k;i<=n+1;i++){
        kcl = pref[i-1];
        if(i==n+1)bsr = pref[n];
        else bsr = pref[n]-pref[n-i];
        ans =(ans+bsr-kcl+1)%mod;
    }
    cout<<(mod+ans)%mod<<endl;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

Graph G;
vector<int> ans;

void dfs(int itr, int p, int c) {
	ans[itr] = c;
	for (int i = 0; i < G[itr].size(); i++) {
		if (G[itr][i].first == p) continue;
		if (G[itr][i].second & 1) dfs(G[itr][i].first, itr, 1 - c);
		else dfs(G[itr][i].first, itr, c);
	}
}

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

	ans.assign(N, 0);
	G.assign(N, vector<Edge>());

	for (int i = 0; i < N - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(Edge{ v,w });
		G[v].push_back(Edge{ u,w });
	}

	dfs(0, -1, 0);

	for (int i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 11560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  vector<string> bluestring(N);
  
  for (int i = 0; i < N ; i++) {
    cin >> bluestring.at(i);
  }
  
  int M;
  cin >> M;
  
  vector<string> redstring(M);
  
  for (int i = 0; i < M ; i++) {
    cin >> redstring.at(i);
  }
  
  int YEN = 0;
  int C = 0;
  
  for (int i = 0; i < N ; i++) {
    
    for (int j = 0; j < N ; j++) {
      if (bluestring.at(i) == bluestring.at(j)) {
        C++;
      }
    }
    
    for (int j = 0; j < M ; j++) {
      if (bluestring.at(i) == redstring.at(j)) {
        C--;
      }
    }
    
    if (C>YEN) {
      YEN = C;
    }
    
    C = 0;
  }
  
  cout << YEN << endl;
}

Measured memory_bytes: 3608
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
   cin>>n;
   string s;
   while(n)
   {
    str.pb(n%10+'0');
      n/=10;
      a++;
   }
   rev(str);
   a--;
   temp=a;
   while(a>0)
   {
      s.pb('9');
      a--;
   }
   ll mx=9*temp;
  // cout<<str;
   //nl;
   for(int i=1;i<=9;i++)
   {
      s.pb(i+'0');
      rev(s);
      if(s<=str)
      {
         mx=9*temp+i;
       //  cout<<s<<' ';
        // nl;
         rev(s);
         s.pop_back();
      continue;
      }
      else
      break;
   }
   cout<<mx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int arr[10];
const int INF = 1e9;

int main()
{
	for (int i = 0; i < 10; i++)
		arr[i] = INF;

	int n;
	cin >> n;
	int s = 0;
	for (int i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		arr[v % 10] = min(arr[v % 10], v);
		s += v;
	}

	if (s % 10 != 0)
	{
		cout << s << '\n';
		return 0;
	}

	int res = 0;

	for (int i = 1; i < 10; i++)
	{
		res = max(res, s - arr[i]);
	}
	cout << res << '\n';
	return 0;	
}


Measured memory_bytes: 256