akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        v: [usize; n]
    }

    let mut ans = 0;
    let kk = ((k*(k-1))/2)%1_000_000_007;

    for i in 0..n {
        let left = (0..i).filter(|&j| v[j] < v[i]).count();
        let right = (i..n).filter(|&j| v[j] < v[i]).count();
        ans += kk*(left+right) + k*right;
        ans %= 1_000_000_007;
    }


    println!("{}",ans)
}

Measured memory_bytes: 2124
import java.util.*;

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);                                            
      
      String S = sc.next();
      
      boolean isW = S.contains("W");
      boolean isE = S.contains("E");
      
      boolean isN = S.contains("N");
      boolean isS = S.contains("S");
      
      if((isW == false && isE == false || isW == true && isE == true) && ((isN == false && isS == false) || (isN == true && isS == true))){
          System.out.println("Yes");
      }else{
          System.out.println("No");
      }

   }   
        
 }

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005;
int a[N], b[N], c[N];
ll resb[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
    }
    sort(b, b + n);
    sort(c, c + n);
    for (int i = n - 1; i >= 0; i--) {
        int l = 0, r = n - 1;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (c[mid] <= b[i]) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        resb[i] = n - l;
        resb[i] += resb[i+1];
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
        int l = 0, r = n - 1;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (b[mid] <= a[i]) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        res += resb[l];
    }
    printf("%lld", res);
    return 0;
}


Measured memory_bytes: 5744
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const int INF=100100;
const ll mod=1000000007;

int main(){
  int n,m;
  map<string,int> map;
  string a;
  cin>>n;
  rep(i,n){
    cin>>a;
    map[a]++;
  }
  cin>>m;
  rep(i,m){
    cin>>a;
    map[a]--;
  }
  
  int ans=0;
  
  
  for(auto x:map){
    ans=max(ans,x.se);
  }
  
  cout<<ans<<endl;
}


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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    if(m2 < m1){
        m2 += 60;
        h2 -= 1;
    }
    cout << (h2 - h1) * 60 + (m2 - m1) - k << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define M 200010
#define rep(i, x, y) for(int i = (x); i <= (y); i ++)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	} while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
int p[200010], tp[200010];
int Log[200010];
struct ST{
	int mn[200010][20];
	inline void build(int n, int val) {
		rep(i, 1, n) {
			if((i & 1) == val) mn[i][0] = p[i];//, printf("%d %d\n", val, p[i]);
			else mn[i][0] = 2147483647;
		} rep(j, 1, 19) {
			for(int i = n - (1 << j) + 1; i > 0; i --) {
				//printf("%d %d %d %d\n", i, j - 1, i + (1 << j - 1), j - 1);
				mn[i][j] = min(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);
			}
		}
	}
	inline int query(int l, int r) {
		int L = Log[r - l + 1];
		return min(mn[l][L], mn[r - (1 << L) + 1][L]);
	}
} T[2];
struct Node{
	int l, r, L, R;
	inline void calc() {;
		L = T[l & 1].query(l, r);
		//printf("%d %d %d\n", l, r, L);
		R = T[(l & 1) ^ 1].query(tp[L], r);
	//	printf("%d %d\n", L, R);
	}
	inline bool operator < (const Node& rhs) const {
		return L > rhs.L;
	}
}; priority_queue<Node> Q;
inline Node init(int l, int r) {
	Node ret; ret.l = l; ret.r = r;
	ret.calc(); //printf("%d %d %d %d\n", ret.l, ret.r, ret.L, ret.R);
	return ret;
}
int main() {
	int n = read();
	rep(i, 1, n) p[i] = read(), tp[p[i]] = i;
	T[0].build(n, 0); T[1].build(n, 1);
	//puts("2333");
	for(int i = 0; (1 << i) <= n; i ++) {
		for(int j = (1 << i); j <= min(n, (1 << i + 1) - 1); j ++) {
			Log[j] = i;
		}
	} Q.push(init(1, n));
	while(!Q.empty()) {
		Node x = Q.top(); Q.pop();
		printf("%d %d ", x.L, x.R);
		if(x.l < tp[x.L]) Q.push(init(x.l, tp[x.L] - 1));
		if(tp[x.L] + 1 < tp[x.R]) Q.push(init(tp[x.L] + 1, tp[x.R] - 1));
		if(tp[x.R] < x.r) Q.push(init(tp[x.R] + 1, x.r));
	} return 0;
}

Measured memory_bytes: 35828
//package  com.company;

import java.util.Arrays;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n,k;
        n=sc.nextInt();
        k=sc.nextInt();
        sc.nextLine();
        int[] a=new int[n];
        for(int i=0;i<n;++i)a[i]=sc.nextInt();
        Arrays.sort(a);
        int ans=0;
        for(int i=0;i<k;++i)ans+=a[i];
        System.out.println(ans);

    }
}

Measured memory_bytes: 30184
#include<iostream>
#include<math.h>
#include<string>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    string c[110];
    for(int i=0;i<a;++i) cin>>c[i];
    for(int i=0;i<a;++i){
        cout<<c[i]<<endl;
        cout<<c[i]<<endl;
    }
}

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) - 1; i >= 0; i--)

using namespace std;

constexpr int MOD = 1000000007;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};
mint operator "" _m(unsigned long long n) { return n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[-n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

mint alt(int n) {
  return n % 2 == 0 ? 1 : MOD - 1;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, M, L, R; cin >> N >> M >> L >> R;
  auto f = [&](int t) {
    mint ans = H(N+1, t);
    for (int i=1; i*M<=t; i++) {
      for (int j=0; t-(M+j)*i>=0; j++) {
        ans -= alt(j)*C(N,M)*C(N-M,j)*H(N+1,t-(M+j)*i);
        ans += alt(j)*C(N,M)*C(N-M,j)*H(N+1,t-M*(i+1)-j*i);
      }
    }
    return ans;
  };
  cout << f(R) - f(L - 1) << endl;
}

Measured memory_bytes: 14668
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
 const int N=100005;
 const int inf=1e18;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int h;
    cin>>h;
    int ans=0;
    int w=1;
    while(h!=1){
        ans+=w;
        w*=2;
        h=h/2;
    }
    ans+=w;
    cout<<ans;








	
return 0;
}


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

{
long long a=1,b,c,d,e,f,g,h,i,j,k,l=0,m,n;

cin>>n>>k;
b=k+1;

long long ar[n];

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


while(1)
{
    if(ar[b]>ar[a])
    {
        cout<<"Yes"<<endl;
        b++;
        a++;
        if(b>n)
            return 0;
    }
    else
    {
        cout<<"No"<<endl;
        b++;
        a++;

        if(b>n) return 0;
    }

}
}
















Measured memory_bytes: 5192
A, B, C, X, Y = map(int, input().split(" "))
p1 = A * X + B * Y
p2 = C * min(X, Y) * 2
if X > Y:
    p2 += (X - Y) * A
else:
    p2 += (Y - X) * B
p3 = C * max(X, Y) * 2
print(min(p1, p2, p3))

Measured memory_bytes: 3060
# Author: cr4zjh0bp
# Created: Tue Mar 17 19:50:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from itertools import permutations

n, m, R = na()
r = na()
abc = nan(m)
adj = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = abc[i]
    a -= 1
    b -= 1
    adj[a][b] = c
    adj[b][a] = c

dist = [[inf for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            dist[i][j] = 0
        elif adj[i][j]:
            dist[i][j] = adj[i][j]

for i in range(n):
    for j in range(n):
        for k in range(n):
            dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

ans = inf
for p in permutations(r):
    res = 0
    for i in range(R - 1):
        f, t = p[i] - 1, p[i + 1] - 1
        res += dist[f][t]
    ans = min(ans, res)

print(ans)

Measured memory_bytes: 45916
#include <stdio.h>

int main(void) {
	int c1,c2,c3,yn;
	scanf("%d%d%d",&c1,&c2,&c3);
	yn = c1 * 1 + c2 * 1 + c3 * 2;
	if (yn == 2){
		printf("Open\n");
	}
	else {
		printf("Close\n");
	}
	return 0;
}
//aoj 0257

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>

using namespace std;

vector< vector<int> > dp;
vector<int> w,v;
int n,weight;

int rec(int i,int j){

	if(dp[i][j]>=0) return dp[i][j];

	int res;
	if(i==n) res=0;
	else if(j<w[i]) res=rec(i+1,j);
	else res=max(rec(i+1,j),rec(i+1,j-w[i])+v[i]);

	return dp[i][j]=res;
}

int main(){

	int count=1;
	cin>>weight;
	while(weight!=0){
		cin>>n;
		w.resize(n); v.resize(n);
		for(int i=0;i<n;i++) scanf("%d,%d",&v[i],&w[i]);

		dp = vector< vector<int> >(n+1);
		for(int i=0;i<n+1;i++) dp[i]=vector<int>(weight+1,-1);

		int ans_v=rec(0,weight);
		cout<<"Case "<<count<<":"<<endl<<ans_v<<endl;
	
		weight--;
		while(weight){
			dp = vector< vector<int> >(n+1);
			for(int i=0;i<n+1;i++) dp[i]=vector<int>(weight+1,-1);
			if(ans_v!=rec(0,weight)) break;
			weight--;
		}
		cout<<weight+1<<endl;

		count++;
		cin>>weight;

	}


	return 0;

}

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

using namespace std;

const int MOD = 998244353;

int add() {return 0;}
template<typename... Args>
int add(long long a, Args... args){
    return (a + add(args...)) % MOD;
}

int mul() {return 1;}
template<typename... Args>
int mul(long long a, Args... args){
    return (a * mul(args...)) % MOD;
}

int fp(int a, long long b){
    int ret = 1;

    while(b){
        if(b & 1) ret = mul(ret, a);

        a = mul(a, a);
        b >>= 1;
    }

    return ret;
}

int inv(int x){
    return fp(x, MOD - 2);
}

const int MAX = 200010;
int f[MAX], fi[MAX];

int C(int n, int k){
    return n < k ? 0 : mul(f[n], fi[k], fi[n - k]);
}

void gen(){
    f[0] = fi[0] = 1;

    for(int i = 1; i < MAX; i++)
        f[i] = mul(i, f[i - 1]), fi[i] = inv(f[i]);
}

int main(){
    gen();
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, m, k;

    cin >> n >> m >> k;

    int ans = 0;

    for(int i = 0; i <= k; i++)
        ans = add(ans, mul(m, fp(m - 1, n - i - 1), C(n - 1, i)));

    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  while(cin>>a>>b>>c&&a!=-1) {
    bool f=0;
    for(int i=2; i<17; i++) {
      int x=0,z=a;
      string s="";
      while(z) {
        s+=(char)(z%i+'0');
        z/=i;
      }
      reverse(s.begin(),s.end());
      bool ff=1;
      for(int j=0; j<s.size(); j++) {
        if(!isdigit(s[j])) ff=0;
        else if(s[i]-'0'>=i) ff=0;
      }
      if(!ff) continue;
      stringstream ss;
      ss<<s;ss>>x;
      if(x==b) f=1;
    }
    if(!f) {
      cout<<-1<<endl;
      continue;
    }
    for(int k=a+1; k<=c; k++) {
      int r=1<<29;
      for(int i=2; i<17; i++) {
        int x=0,z=k;
        string s="";
        while(z) {
          s+=(char)(z%i+'0');
          z/=i;
        }
        reverse(s.begin(),s.end());
        bool ff=1;
        for(int j=0; j<s.size(); j++) {
          if(!isdigit(s[j])) ff=0;
          else if(s[i]-'0'>=i) ff=0;
        }
        if(!ff) continue;
        stringstream ss;
        ss<<s;ss>>x;
        if(b<=x) r=min(r,x);
      }
      b=r;
    }
    cout<<b<<endl;
  }
  return 0;
}


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


def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        i = 1
        while i*i <= num:
            if num%i == 0:
                divisor_list.append(i)
#                divisor_list.append(num//i)

            i += 1
#        divisor_list.append(num)

        return sorted(set(divisor_list))

li = make_divisor_list(N)

A = li[-1]
B = len(str(N // A))
A = len(str(A))

print(max(A,B))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	private static int cnt = 0;
	public static void Main(string[] args)
	{
		var q = Input().ToInt();
		var n = q[0];
		var m = q[1];
		
		var graph = new List<List<int>>();
		for(int i = 0; i < n; i++)
			graph.Add(new List<int>());
		
		for(int i = 0; i < m; i++)
		{
			q = Input().ToInt();
			graph[--q[0]].Add(--q[1]);
			graph[q[1]].Add(q[0]);
		}
		Dfs(0, graph, new bool[n]);
		Console.WriteLine(cnt);
	}
	
	private static void Dfs(int index, List<List<int>> g, bool[] visited)
	{
		bool end = true;
		for(int i = 0; i < visited.Length; i++)
		{
			if(!visited[i] && i != index)
			{
				end = false;
				break;
			}
		}
		if(end)
		{
			cnt++;
			return;
		}
		visited[index] = true;
		foreach(var p in g[index])
		{
			if(visited[p]) continue;
			Dfs(p, g, visited);
		}
		
		visited[index] = false;
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> l(n+1),r(n+1);
    l[0] = 0;
    for(int i=0;i<n-1;i++){
        l[i+1] = gcd(l[i],a[i]);
    }
    r[n] = 0;
    for(int i=n-1;i>=0;i--){
        r[i] = gcd(r[i+1],a[i]);
    }
    int t=0;
    int ma = 0;
    for(int i=0;i<n;i++){
        t = gcd(l[i],r[i+1]);
        //cout << t << endl;
        ma = max(ma,t);
        //cout << "ma=" << ma << endl;
    }
    cout << ma << endl;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a + b <= 16 && a <= 8 && b <= 8)
    cout << "Yay!\n";
  else
    cout << ":(\n";  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<cstdio>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = (1 << 31) - 1;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl A, F;
bool check(ll x) {
	a = 0;
	rep(i, n) {
		a += max(A[i] - x / F[i], 0LL);
	}

	//cout << x << " " << a << endl;

	if (a > k)return false;
	return true;
}

void input() {
	cin >> n >> k;
	inputv(A, n);
	inputv(F, n);
}


void solve() {
	sort(all(A));
	sort(all(F));
	reverse(all(F));

	ll ok = 99999999999999999, ng = -1,mid;
	while (ok - ng > 1) {
		mid = (ok + ng) / 2;
		if (check(mid)) ok = mid;
		else ng = mid;
	}

	cout << ok << endl;

}

int main() {
	input();
	solve();
} 

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

int main() {
    
    int x, y, z; cin >> x >> y >> z;
    int tmp = x;
    tmp -= z;
    int ans = 1;
    while (true) {
        tmp -= y + z;
        if (tmp < 0) {
            ans--;
            break;
        }
        else if (tmp == 0) {
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll tt_aleb = 0;
    ll tt_bla = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= b[i]) {
            tt_aleb += (b[i] - a[i]) / 2;
        } else {
            tt_bla += a[i] - b[i];
        }
    }
    if (tt_aleb >= tt_bla) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    char op;
    cin >> A >> op >> B;
    int total;

    if (op=='+')
    {
        total = A + B;
    }
    else
    {
        total = A - B;
    }
    cout << total << endl;
    return 0;
}

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

int main() {
	// your code goes here
   int a,b,c,d;
   cin>>a>>b>>c;
   d=0;
   for( int i=a; i<=b; i++){
   	if(c%i==0){
   		d++;
   	}
   }
   cout<<d<<endl;
	  
	return 0;
}

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

int main(){
    int N,Q;
    long K;
    cin >> N >> K >> Q;
    vector<long> score(N,0L);
    for(int i = 0; i < Q; i++){
        int a;
        cin >> a;
        score[a-1] += 1;
    }
    for(int i = 0; i < N; i++){
        if(K + score[i] - Q > 0){
            cout << "Yes" << endl;
        } else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
//　孤立点があると終了

#include <iostream>
#include <string>

using namespace std;

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

string s[h];
int t[h+2][w+2];

for (int i= 0;i<h+2;i++){
  t[i][0]   = 0;
  t[i][w+1] = 0;}

for (int j= 0 ;j<w+2;j++){
  t[0][j]   = 0;
  t[h+1][j] = 0;}

for (int i= 0;i<h;i++){
  cin >> s[i];
  for (int j = 0; j<w;j++){
    if (s[i][j] == '#')t[i+1][j+1] = 1;
    else t[i+1][j+1] = 0;}
}

for (int i= 1;i<h+1;i++){
  for (int j = 1; j<w+1;j++){
    if ((t[i][j] != 0) && (t[i-1][j]==0) &&(t[i+1][j]==0)&&(t[i][j-1]==0)&&(t[i][j+1]==0)){
      cout << "No";goto Exit;}
  }
}

cout << "Yes";
Exit:;
}





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

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n - 1; i++) cin >> c[i];

  int tot = 0;
  for (int i = 0; i < n; i++) {
    tot += b[i];
    if (i < n - 1) {
      tot += (a[i+1] == a[i] + 1) * c[a[i]-1];
    }
  }
  cout << tot << '\n';
  return 0;
}

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

cities = []
ps = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  cities.append([p, y, ''])
  if p in ps.keys():
    ps[p].append([y, i])
  else:
    ps[p] = [[y, i]]
  
years = {}
ids = {}
for p in ps.keys():
  years[p] = sorted(ps[p], key=lambda x: x[0])
  for i, year in enumerate(years[p]):
    cities[year[1]][2] += to_id(p) + to_id(i+1)

for i in range(m):
  print(cities[i][2])

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

#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second

ll n,k;

int main()
{
    boost;
    if(fopen("inp.txt", "r")) {
      freopen("inp.txt", "r", stdin);
      freopen("outp.txt", "w", stdout);
    }

    cin>>n>>k;

    ll i,p,ans=0;
    for (i=0;i<n;i++) {
        cin>>p;
        ans+=min(2*p,2*(k-p));
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
const int AMAX = 100000; 
using namespace std;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define down(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
using LL = long long;
using ULL = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

int main(void) {
    string s1;
    cin >> s1;
    for (int i = 0; i < s1.size();i++){
      if(i%2==0){
         if (s1[i]=='R'||s1[i]=='U'||s1[i]=='D'){
         }else{
             cout << "No";
             return 0;
         }
      }  else{
if (s1[i]=='L'||s1[i]=='U'||s1[i]=='D'){
         }else{
             cout << "No";
             return 0;
         }
      }
    }
  cout <<"Yes";
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {
  long long n, sum = 0;
  std::cin>>n;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0)
      continue;
    else if (i % 5 == 0)
      continue;
    else if (i % 5 == 0 && i % 3 == 0)
      continue;
    sum += i;
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 3188
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);



 int binarySearch(pair<int,int>  box[],int start,int end,int check){
    int ans=-1;
    while (start<=end){
        int mid=start+(end-start)/2;
        int value=box[mid].F;
        if(value<=check){
            ans=mid;
            start=mid+1;
        }
        else {
            end=mid-1;
        }
    }


    return ans;
}
void solve() {
    int n;
    cin >> n;
    pair<int, int> a[n];
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a[i] = {x + y, x - y};
    }
    sort(a,a+n);
    int dp[n];
    for(int i=0;i<n;i++)dp[i]=1;
    for (int i=1; i<n; i++)
    {

        int inclProf = 1;
        int l = binarySearch(a,0,i-1, a[i].S);
        if (l != -1)
            inclProf += dp[l];

        dp[i] = max(inclProf, dp[i-1]);
    }
   cout<<dp[n-1]<<endl;

}
int32_t main() {
    IOS;
    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

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

using namespace std;

const int mod =1e9+7;

int main()
{
    int n; cin>>n;
    string s; cin>>s;
    int a[26];
    memset(a,0,sizeof a);
    for(int i=0;i<n;i++)
    {
        a[s[i]-'a']++;
    }
    long long int ans=1;
    for(int i=0;i<26;i++)
    {
        ans*=(a[i]+1);
        ans%=mod;
    }
    ans--;
    if(ans<0) ans+=mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let w:i32 = read();
    let h:i32 = read();
    let x:i32 = read();
    let y:i32 = read();
    let r:i32 = read();
    
    if w >= x + r && x - r >= 0 && h >= y + r && y - r >= 0 {
        println!{"Yes"};
    } else {
        println!{"No"};
    }
}



Measured memory_bytes: 5020
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,m,o,a[350],b[350],i,j,l,k[350]={0};
  int t[350]={0};
  int d[100][350]={0};
  scanf("%d %d %d",&n,&m,&o);
  for(i=0;i<m;i++)scanf("%d %d %d %d",&a[i],&b[i],&k[i],&t[i]);
  for(i=0;i<50;i++){
    for(j=0;j<=o;j++){
      d[i+1][j]=MAX(d[i+1][j],d[i][j]);
      for(l=0;l<m;l++){
	if(i==a[l]*10+b[l])d[i+k[l]][j+1]=MAX(d[i+k[l]][j+1],d[i][j]+t[l]);
      }
    }
  }
  /*for(i=0;i<=50;i++){
    for(j=0;j<=o;j++)printf("%d %d %d\n",i,j,d[i][j]);
    }//*/
  printf("%d\n",d[50][o]);
  return 0;
}

Measured memory_bytes: 752
def bikkuri(x):
  if x <= 0:
    return 1
  temp = 1
  for i in range(1,x+1):
    temp *= i
  return temp

def ncr(n,r):
  return bikkuri(n)//(bikkuri(r)*bikkuri(n-r))
  
#print(bikkuri(3))
#print(ncr(5,3))
from collections import defaultdict
dic = defaultdict(int)
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
MAX = max(v)
for x in v:
  dic[x] += 1
ans = 0
w = sorted(v, reverse=True)
Maxv = [] #(sum,i個)を保存
for i in range(A,B+1): #A-Bまで
  #print(Maxv)
  dic2 = defaultdict(int)
  SUM = 0
  for j in range(i):
    dic2[w[j]] += 1
    SUM += w[j]
  L = list(dic2.keys())
  if len(Maxv) == 0 or Maxv[0][0]*i == SUM*Maxv[0][1]:
    Maxv.append((SUM,i))
    temp = 1
    nokori = i*1
    for x in L:
      if dic[x] >= nokori:
        temp *= ncr(dic[x],nokori)
        #print(dic[x],nokori,ncr(dic[x],nokori))
      elif dic[x] == dic2[x]:
        nokori -= dic[x]
      if nokori == 0:
        break
        
    ans += temp
  elif Maxv[0][0]*i < SUM*Maxv[0][1]:
    ans = 0
    Maxv = [(SUM,i)]
    temp = 1
    for x in L:
      if dic[x] != dic2[x]:
        temp *= ncr(dic[x],dic2[x])
        #print(temp,x,dic[x],dic2[x])
    ans += temp
#print(Maxv)
print(Maxv[0][0]/Maxv[0][1])
print(ans)


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

int main(){
    int n;
    cin >> n;
    vector<unsigned long long> a(n);
    int check =0;
    for(int i = 0; i < n;i++){
        cin >> a[i];
        if(a[i] == 0){
            check = 2;
            cout << 0 << endl;
        }
    }
    unsigned long long sum = 1;
    if(check != 2){
        for(int i = 0; i < n;i++){
            if(a[i] <= 1000000000000000000/sum){
                sum *= a[i];
            }else{
                check = -1;
                cout << -1 << endl;
                break;
            }
        }
        if(check != -1){
            cout << sum << endl;
        }
    }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define ll long long
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=1e6+6;
pr a[N],b[N];
bool vis[N];
int main(){
    int n; cin>>n;
    rep(i,1,n) scanf("%d",&a[i].se);
    rep(i,1,n) scanf("%d",&a[i].fi);
    sort(a+1,a+1+n);
    rep(i,1,n) b[i]=mp(a[i].se,i);
    sort(b+1,b+1+n);
    rep(i,1,n)
        if (b[i].fi>a[i].fi){ cout<<"No"<<endl; return 0; }
    rep(i,1,n){
        int x=i,c=0;
        while (!vis[x]) vis[x]=true,++c,x=b[x].se;
        if (c&&c<n){ cout<<"Yes"<<endl; return 0; }
    }
    rep(i,1,n-1)
        if (a[i].fi>=b[i+1].fi){ cout<<"Yes"<<endl; return 0; }
    cout<<"No"<<endl;
    return 0;
}
/*
4
2 1 4 3
1 2 3 4
*/


Measured memory_bytes: 3200
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i]=nextInt()+1;
		}
		int []num = new int [N];
		int num_i = 0;
		int indexsum=0;
		for(int i=0;i<N;i++) {
			num_i = BinarySearch(num,indexsum,A[i]);
			if(num[num_i]<A[i]) {
				num[num_i]=A[i];
			}else {
				num_i++;
				while(true) {
					if(num[num_i]<A[i]) {
						num[num_i]=A[i];
						break;
					}
					num_i++;
				}
			}
			if(num_i>indexsum)indexsum=num_i;
			num_i=0;
		}
		out.println(indexsum+1);
	}

	//二部探索
	private int BinarySearch(int[] a, int indexsum, int Target) {
		int l = -1;
		int r = indexsum+1;
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(a[mid] < Target) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}
}

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

long long MOD=1000000007LL;

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

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<1000000;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 zero(){
	cout << "0" << endl;
	return 0;
}

int main(){
	COMinit();
	int X,Y;
	cin >> X >> Y;
	
	if((X+Y)%3!=0)return zero();
	
	int N=(X+Y)/3;
	if(N>X || N>Y)return zero();
	
	X-=N;
	Y-=N;
	
	cout << COM(X+Y,X) << endl;
	
	return 0;
}

Measured memory_bytes: 23680
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
 
int main(){
	bool flag=true;//下方程序循环判断的标志，如果最大的值小于n的话，那么就结束循环
	ll  ans=0;
 
	vector<ll>ve;
	int n;
	cin>>n;
  ll temporary;
	int position;
	ll x;
	for(int i=0;i<n;i++){
		cin>>x;
		ve.push_back(x);//把数据读入到一个不定长数组里
		
	}
	ll max;
	while(flag){
	max=ve[0];//首先假定第一个元素为最大值
	position=0;//同时也假定最大元素的坐标是0；
	
	for(int i=1;i<n;i++){
	if(ve[i]>max){
		max=ve[i];//开始寻找数组中的最大值，并记录它的位置
	position=i;
	}
	}
	if(max>=n){
	temporary=max/n;//计算减到n以下需要的次数
	ve[position]%=n; 
	ans+=temporary;
	for(int i=0;i<n;i++){
		if(position==i)
			continue;
		ve[i]+=temporary;//把其他的元素加上上边减到n一下需要的次数
	}
	}
	else{
	cout<<ans<<endl;
	flag=false;
	}
	}
return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i=0; i<4; i++){
        if (s[i] == '+')ans++;
        else ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  int arr[a];
  for(int x=0; x<a; x++){
    cin>>arr[x];
    }
  int dp[a];
  if(a>2){
  dp[1]=abs(arr[1]-arr[0]);
  dp[0]=0;
  for(int x=2; x<a; x++){
    dp[x]=min(dp[x-1]+abs(arr[x]-arr[x-1]),dp[x-2]+abs(arr[x]-arr[x-2]));
    
  }
                      cout<<dp[a-1];
}else{
    cout<<abs(arr[1]-arr[0]);
}
}
                      

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	}

	static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	int n;
	cin >> n;

	int l, r;

	int a[200005], b[200005];

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

	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);

	if (n % 2) {
		l = a[(n + 1) / 2];
		r = b[(n + 1) / 2];
	}
	else {
		l = a[n / 2] + a[n / 2 + 1];
		r = b[n / 2] + b[n / 2 + 1];
	}

	cout << r - l + 1 << endl;

	return 0;
}

Measured memory_bytes: 5224
n, k = gets.chomp.split.map(&:to_i)
r, s, p = gets.chomp.split.map(&:to_i)
t = gets.chomp

po = {r: p, s: r, p: s}

point = 0

n.times do |i|
  if (i - k >= 0) && t[i] == t[i - k]
    t[i] = 'a'
    next
  end

  point += po[t[i].to_sym]
end
puts point


Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	int N,M;
	scanf("%d%d", &N, &M);
	char A[100][100],B[100][100];
	for (int i = 0; i < N; i++) {
		scanf("%s", A[i]);
	}
	for (int i = 0; i < M; i++) {
		scanf("%s", B[i]);
	}


	bool in = false;



	for (int i = 0; i < N - M +1; i++) {
		for (int j = 0; j < N - M+1; j++) {
			
			bool temp = true;
			for (int x = 0; x < M; x++) {
				for (int y = 0; y < M; y++) {
					
					if (A[i + x][j + y] != B[x][y]) {
						temp = false;
						break;
					}
				}
			}

			if (temp) {
				printf("Yes");
				return 0;
			}

		}
	}


	printf("No");






}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int s,a,b;
	scanf("%d", &s);
	a=s/100;
	b=s%100;
	if(a>0&&a<13&&b>0&&b<13)
	printf("AMBIGUOUS\n");
	else if(b>0&&b<13)
	printf("YYMM\n");
	else if(a>0&&a<13)
	printf("MMYY\n");
	else
	printf("NA\n");
	
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int a,b,m,x[100010],y[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>a>>b>>m;
	for(int i=1;i<=a;i++) cin>>x[i];
	for(int i=1;i<=b;i++) cin>>y[i];
	int minv1=x[1],minv2=y[1];
	for(int i=2;i<=a;i++){
		minv1=min(minv1,x[i]);
	}
	for(int i=2;i<=b;i++){
		minv2=min(minv2,y[i]);
	}
	int ans=minv1+minv2;
	for(int i=1;i<=m;i++){
		int c,xx,yy;
		cin>>xx>>yy>>c;
		ans=min(ans,x[xx]+y[yy]-c);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if(n == 1){
        cout << "Hello World" << '\n';
    }else{
        int a, b;
        cin >> a >> b;
        cout << a + b << '\n';
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

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

    ll n;
    cin >> n;
    vvll edge(n,vll(n,0));
    REP(i,n){
        REP(j,n){
            if(i!=j){
                edge[i][j] = 1;
            }
            else{
                edge[i][j] = 0;
            }
        }
    }

    if(n%2==0){
        REP(i,n){
            edge[i][n-1-i] = 0;
        }
    }
    else{
        REP(i,n-1){
            edge[i][n-2-i] = 0;
        }
    }
    ll m = 0;
    REP(i,n-1){
        FOR(j,i+1,n){
            if(edge[i][j]==1){
                m++;
            }
        }
    }
    cout << m <<endl;
    REP(i,n-1){
        FOR(j,i+1,n){
            if(edge[i][j]==1){
                cout << (i+1) <<" " << (j+1) <<endl;
            }
        }
    }



    
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;
VL neg, pos;
VL nmax, pmax;

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

int main() {
    ll a, b;
    while(cin >> a >> b) {
        cout << gcd(a, b) << " " << a * b / gcd(a, b) << "\n";
    }
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;
int n, res;
vector<int> x, y;

vector<int> zal(const string &s) {
	int n = s.size();
	vector<int> a(n);
	a[0] = n;
	int i = 1, j = 0;
	while (i<n) {
		while (i+j<n && s[j]==s[i+j]) ++j;
		a[i] = j;
		if (j==0) {++i; continue;}
		int k = 1;
		while (i+k<n && k+a[k]<j) a[i+k] =a[k], ++k;
		i += k, j -= k;
	}
	return a;
}

vector<int> pre() {
	vector<int> res(n+1,1), z = zal(s);
	reps(i,1,n) for (int j=2; (j-1)*i<=z[i]; j++) res[i*j] = 0;
	return res;
}

signed main() {
	cin >> s;
	n = s.size();
	if (count(all(s), s[0])==n) return cout << n << endl << 1 << endl, 0;
	x = pre();
	if (x[n]) return cout << 1 << endl << 1 << endl, 0;
	reverse(all(s));
	y = pre();
	reverse(all(y));
	reps(i,1,n) if (x[i] && y[i]) res++;
	cout << 2 << endl << res << endl;
}

Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[303][303];
int ok[303];
int cnt[303];
int O[303][303];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(y,N) FOR(x,M) cin>>A[y][x], A[y][x]--;
	
	int mi=N;
	FOR(i,M) ok[i]=1;
	FOR(i,M) {
		ZERO(cnt);
		FOR(y,N) {
			FOR(x,M) if(ok[A[y][x]]) {
				cnt[A[y][x]]++;
				break;
			}
		}
		x=max_element(cnt,cnt+M)-cnt;
		mi=min(mi,cnt[x]);
		ok[x]=0;
	}
	
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 640