akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int bubbleSort(int *a, int n);
void swap(int *a, int *b);

int main(void)
{
	int i;
	int n;
	int ans;
	int a[100];
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	
	ans = bubbleSort(a, n);
	for (i = 0; i < n - 1; i++) printf("%d ", a[i]);
	printf("%d\n%d\n", a[i], ans);
	
	return (0);
}

int bubbleSort(int *a, int n)
{
	int i;
	int count;
	int flag;
	
	flag = 1;
	count = 0;
	while (flag){
		flag = 0;
		for (i = n - 1; i >= 1; i--){
			if (a[i] < a[i - 1]){
				swap(&a[i], &a[i - 1]);
				flag = 1;
				count++;
			}
		}
	}
	
	return (count);
}

void swap(int *a, int *b)
{
	int tmp;
	
	tmp = *a, *a = *b, *b = tmp;
}

Measured memory_bytes: 600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    sc.useDelimiter("\\s");
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if(a > b ){
     int t = a;   
         a = b;
         b = t; 
         if(b > c){
     int y = b;
         b = c;
         c = y;

            if(a > b){
               int u = b;
               b = a;
               a = u;


            }
       }
    }
    
    if(a == c){
               int i = b;
               b = c;
               c = i;
     }

	System.out.println(a + " " + b + " " + c);

    

       
   
  }

}

Measured memory_bytes: 26204
N, Q = map(int, input().split())
from collections import defaultdict
g = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

w = defaultdict(int)
for _ in range(Q):
    p, x = map(int, input().split())
    w[p] += x
    
ans = [0] * (N + 1)

visited = defaultdict(bool)
stack = []
visited[1] = True
stack.append(1)
while len(stack) != 0:
    v = stack.pop()
    W = w[v]
    ans[v] += W
    for c in g[v]:
        if not visited[c]:
            visited[c] = True
            stack.append(c)
            ans[c] += ans[v]

print(*ans[1:])


Measured memory_bytes: 108936
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int cnt=1,n,b[100005];
ll f[200005],now,a[100005];
int lowbit(int x)
{
	return x&(-x);
}
void modify(int x,int num)
{
	for(int i=x;i<=200001;i+=lowbit(i))
	{
		f[i]+=num;
	}
}
ll query(int x)
{
	int ret=0;
	for(int i=x;i>=1;i-=lowbit(i))
	{
		ret+=f[i];
	}
	return ret;
}
bool check(int x)
{
	//cout<<x<<" ";
	ll ans=0;now=0;
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=x) b[i]=1;
		else b[i]=-1;
	}
	for(int i=1;i<=n;i++)
	{
		modify(100001+now,1);
		now+=b[i];
		//cout<<now<<" "<<query(200001);
		ans+=query(100001+now);
	}
	ll sum=1LL*n*(n+1)/2;
	//<<ans<<endl;
	if(ans>=sum-ans) return 1;
	return 0;
}
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
	}
	int l=1,r=1000000000,ans=1;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(check(mid))
		{
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<ans;
}


Measured memory_bytes: 2944
from collections import deque


def BFS():
    color=[["white" for _ in range(w)] for _ in range(h)]
    D=[[0 for _ in range(w)] for _ in range(h)]

    num=0
    queue=deque([])
    for i in range(h):
        for j in range(w):
            if A[i][j]=="#":
                queue.append([i,j])
                color[i][j]="gray"

    while len(queue)>0:
        a,b=queue.popleft()
        for c,d in [[1,0],[-1,0],[0,1],[0,-1]]:
            X,Y=a+c,b+d
            if 0<=X<h and 0<=Y<w:
                if color[X][Y]=="white":
                    D[X][Y]=D[a][b]+1
                    num=max(num,D[X][Y])
                    color[X][Y]="gray"
                    queue.append([X,Y])
        color[a][b]="black"

    return num


h,w=map(int,input().split())
A=[list(input()) for _ in range(h)]
print(BFS())

Measured memory_bytes: 187484
package main 

import (
        "fmt"

)

func main () {
        var a, b, c, x, an, ka, ki, ku int
        fmt.Scan(&a,&b,&c,&x)
        for i := 0 ; i <= a ; i++ {
                ka = 500 * i
                        for t := 0 ; t <= b ; t ++ {
                                 ki = 100 * t
                                        for ii := 0 ; ii <= c ;  ii++ {
                                                        ku = 50 * ii 
                                                        ko := ka + ki + ku
                                                        if ko == x {
                                                                an += 1
                                                        }
                                        }
                        }
        }
        fmt.Println(an)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
#define FayeValentine 
void dz(){cerr<<NL;}template<typename H,typename... T> void dz(H h,T... t){cerr<<' '<<h;dz(t... );}
#ifdef  FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dz(__VA_ARGS__)
#else
#define debug(...) 
#endif

void absinthe() {
	int n, k; cin >> n >> k;
	ll sum = 0;
	for(ll i = k+1; i <= n; i++) {
		ll el = (i-k), d = n/i;
		ll cur_sum = el*d;
		if(n%i!=0) {
			ll ex = n-(d*i);
			if(ex >= k) cur_sum += (ex - k + 1);
			if(k == 0) cur_sum--;	
		}
		sum += cur_sum;
	}
	cout << sum << NL;

}
 
int main(){
  async();
  int __t = 1, __c; //cin >> __t;
  for(__c = 1; __c <=__t; __c++) {
    //cout << "Case " << __c << ": "; 
    absinthe();
  }
}  

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

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; }

const long long INF = 1LL << 60;

int f(int n)
{
  if(n%2 == 0) return n/2;
  else return 3*n+1;
}

int main(){
  int s; cin >> s;
  set<int> se;

  int a = s;
  int m = 1;
  while(!se.count(a)){
    se.insert(a);
    a = f(a);
    m++;
  }

  cout << m << endl; 

  return 0;
}


Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin>>n;
	int x=n%10;
	if(x==2 || x==4 || x==5 || x==7 || x==9){
		cout<<"hon";
		return 0;
	}
	else
	if(x==3){
		cout<<"bon";
		return 0;
	}
	else
		cout<<"pon";
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;

public class Program
{
    public static void Main(string[] args)
    {
        var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderByDescending(x => x).ToArray();

        Console.WriteLine((line[0] * 10 + line[1]) + line[2]);
        Console.ReadLine();
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    vector<ll> v(50);
    iota(v.begin(), v.end(), k / 50);
    for (int i = 0; i < k % 50; ++i) {
        for (int j = 0; j < 50; ++j) {
            if (i == j) v.at(j) += 50;
            else --v.at(j);
        }
    }
    cout << "50\n";
    for (int i = 0; i < 50; ++i) cout << v.at(i) << (i == 49 ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int a[] = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int ans1 = a[n - 1];
        int ans2 = a[0];
        for (int i = 0; i < n - 1; i++) {
            if ((ans1 - ans2 * 2) > Math.abs(ans1 - a[i] * 2)) {
                ans2 = a[i];
            }
        }

        System.out.println(ans1 + " " + ans2);
    }

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


Measured memory_bytes: 50704
#include<bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
    int N, X;
    cin >> N >> X;
    int L[N];
    for(int i=0; i < N; i++)
        cin >> L[i];
    
    int sum = 0;
    for(int i=0; i < N; i++){
        sum += L[i];
        if(sum > X){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << N+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int N;
  cin >> N;

  ll t[N];

  ll sum=0;

  rep(i,N){
    ll tt;
    cin >> tt;
    t[i]= tt;
    sum+=tt;
  }


  int M;
  cin>>M;

  rep(i,M){
    ll p,xx;
    cin>>p>>xx;
    cout << sum+(xx-t[p-1]) <<"\n";
  }

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	a := ScanInt(scanner)
	b := ScanInt(scanner)
	
	if a <= 0 && 0 <= b {
	    fmt.Println("Zero")
	} else if a > 0 { 
	    fmt.Println("Positive")
	} else if b < 0 && (b - a + 1) % 2 == 1 {
	    fmt.Println("Negative")
	} else {
	    fmt.Println("Positive")
	}
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func Max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

Measured memory_bytes: 640
#include<cstring>
#include<cstdio>
#include<cmath>
#include<memory.h>
#include<algorithm>
#include<map>
#define ll long long
#define ld long double
#define maxn 310
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
const ll inf=1e9;
const ld eps=1e-7;
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }
void writeln(ll x){ wrote(x);   puts("");   }
ll n,sum,mn=1e9;
int main(){
	n=read();
	For(i,1,n){
		ll x=read();
		sum+=x;	if (x%10!=0)	mn=min(mn,x);
	}writeln(sum%10?sum:(mn!=1e9?sum-mn:0));
}

Measured memory_bytes: 128
N = int(input())
A_list = list(map(int, input().split()))
fumidai_list = [0] * N

for i in range(1, N):
    tmp = A_list[i] - (A_list[i-1] + fumidai_list[i-1])
    if tmp < 1:
        fumidai_list[i] = -tmp

print(sum(fumidai_list))

Measured memory_bytes: 32384
import Control.Monad
main=do
 n<-readLn;s<-replicateM n getLine
 m<-readLn;t<-replicateM m getLine
 print(max 0 (maximum (map (f s t) s)))
  where f s t l = (length(filter (==l) s))-(length(filter (==l) t))

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

int main()
{
    char a[105];
    scanf(" %[^\n]",&a);

    int n =strlen(a);
    int i,u;

    int p=0;
    for(i=0; i<((n-1)/2); i++)
    {
        if(a[i] != a[n-1-i])
        {
            p=1;
            break;
        }
    }
    //if(p==0)
      //  printf("Yes\n");
    int j=(n-1)/2;
    int q=0;
    for(i=0; i<j/2; i++)
    {
        if(a[i] != a[j-1-i])
        {
            q=1;
            break;
        }
    }
    int k=(n+3)/2;
    int r=0;
    for(i=k-1,u=0; i<n; i++,u++)
    {
        if(a[i] != a[n-1-u])
        {
            r=1;
            break;
        }
    }
    if(p==q && q==r  && p==0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<long long int> a(n);
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
  }
  for (int i = 1; i < n; i++)
  {
    int v=a.at(i);
    int j=i-1;
      for(int i=0; i<n; i++){
        cout<<a.at(i);
        if(i!=n-1){
          cout<<" ";
        }else{
          cout<<endl;
        }
      }
    while (j>=0&&a.at(j)>v){
      a.at(j+1)=a.at(j);
      j--;
      a.at(j+1)=v;
    }
    
  }
      for(int i=0; i<n; i++){
        cout<<a.at(i);
        if(i!=n-1){
          cout<<" ";
        }else{
          cout<<endl;
        }
      }
  return 0;
}


Measured memory_bytes: 3080
import sys
import math
from collections import deque
input = sys.stdin.readline
#INF = 1145141919810893364
#S,L,R = map(int, input().split())

#入力、ついでに辺集合を作る
N,M = map(int,input().split())
edge = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    a-=1;b-=1
    edge[a].append(b)
    edge[b].append(a)


#BFSの準備
Ans = [-1]*N;
visited = [False]*N;
Queue = deque([0])

#BFS
while(Queue):
    t = Queue.popleft()
    for v in edge[t]:
        if visited[v]:
            continue
        Queue.append(v)
        Ans[v]=t
        visited[v]=True
    
#Noの条件を満たさないかどうかチェック
#余談:今回はNoにならないことを示せる
for i in range(1,N):
    if Ans[i]==-1:
        print("No")
        sys.exit()
    
#答えの出力
print("Yes")
for i in range(1,N):
    print(Ans[i]+1)
    


Measured memory_bytes: 34820
n=int(input())
Tree_List=list(map(int,input().split()))
ct =0
for i in range(n):
    while Tree_List[i] != 0:
        k = i
        while k + 1 < n and Tree_List[k + 1] != 0: 
            k+=1
        Tree_List[i:k + 1]=map(lambda x:x-1,Tree_List[i:k + 1])
        ct += 1
        
print(ct)

Measured memory_bytes: 3060
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double a = gi();
    a /= 3.0L;
    a = a*a*a;
    cout << setprecision(9) << a << endl;

    return 0;
}


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

using namespace std;

const int nax = 3000;
double dp[nax][nax]; //guarda a probabilidade de sair j caras em i moedas

int main(){

  int n;

  cin >> n;

  vector <double> prob(n+1);

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

    dp[0][0] = 1;
    dp[1][0] = 1 - prob[1];
    for(int i = 2; i <= n; i++)
        dp[i][0] = dp[i - 1][0] * (1 - prob[i]);

  for(int i=1;i<=n;i++){
    for(int j=1;j<=i;j++){
      dp[i][j] = prob[i] * dp[i-1][j-1] + (1-prob[i]) * dp[i-1][j];
    }
  }

  double ans = 0;

  for(int i=(n/2) + 1;i<=n;i++)
    ans += dp[n][i];

  cout << setprecision(10) << ans << endl;

  return 0;
}

Measured memory_bytes: 68864
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int n;

map<int, int> counter;

int main(void)
{
    int ai, ans = 0, num, times;
    cin >> n;

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

    for (auto num_times : counter)
    {
        num   = num_times.first;
        times = num_times.second;

        if (num == times)
            continue;

        while (times != num and times != 0)
        {
            --times;
            ++ans;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans = 0;
  string s;cin>>s;
  ll cnt = 0;
  for(auto c:s){
    if(c == 'R')cnt++;
    else cnt = 0;
    ans = max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
package main

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

var (
	BufferSize = 100
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	ans := n - 1

	for i := int(math.Sqrt(float64(n))); i >= 1; i-- {
		if n%i == 0 {
			ans = i + n/i - 2
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#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;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cout<<N*N*N<<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);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 892
import java.util.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String [] x = new String[N];
		for(int i=0;i<N;i++){
			x[i] = sc.next();

		}
		int M = sc.nextInt();
		String [] y = new String[M];
		for(int i=0;i<M;i++){
			y[i] = sc.next();

		}
		String [] z = new String[N+M];
		for(int i=0;i<N;i++){
			z[i] = x[i];
			
		}
		for(int i=0;i<M;i++){
			z[N+i] = y[i];
		}
		int max = 0;

		for(String str:z){
			int ans = 0;
			for(int i=0;i<N;i++){
				if(str.equals(x[i])){
					ans ++;
				}

			}
			for(int i=0;i<M;i++){
				if(str.equals(y[i])){
					ans --;
				}

			}
			max = Math.max(max,ans);
		}
		System.out.println(max);


		


	}
}

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

int main()
{
	int a[4],b[4],c[4],n;
	long long int ans=0;
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	cin>>n;
    b[0]=a[0]*8;
    b[1]=a[1]*4;
    b[2]=a[2]*2;
    b[3]=a[3];
    c[0]=a[0]*4;
    c[1]=a[1]*2;
    c[2]=a[2];
     if(n>=2)
    	{
    		int x=n/2;
           ans+=1LL*min(b[0],min(b[1],min(b[2],b[3])))*x;
          // cout<<ans<<endl;
           if(n%2)
           n=1;
          else
          	n=0;
    	}
    if(n==1)
    	{
           ans+=1LL*min(c[0],min(c[1],c[2]));
           n--;
    	}
    cout<<ans<<endl;
	return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	string s;
	cin>>s;
	vector<int> dis((int)s.size());
	queue<int> que;
	stack<int> sta;

	char now='R';

	for(int i=0;i<(int)s.size();i++){
		if(s.at(i)==now){
			if(now=='R') que.push(i);
			else sta.push(i);
		}else{
			if(now=='R'){
				while(!que.empty()){
					dis.at(que.front())=que.size();
					que.pop();
				}
				sta.push(i);
			}else{
				while(!sta.empty()){
					dis.at(sta.top())=sta.size();
					sta.pop();
				}
				que.push(i);
			}

			now=s.at(i);
		}
	}

	if(now=='R'){
		while(!que.empty()){
			dis.at(que.front())=que.size();
			que.pop();
		}
	}else{
		while(!sta.empty()){
			dis.at(sta.top())=sta.size();
			sta.pop();
		}
	}

	vector<int> kids((int)s.size(),0);

	for(int i=0;i<(int)s.size();i++){
		if(s.at(i)=='R'){
			int here=i+dis.at(i);
			if(dis.at(i)%2==1) here--;

			kids.at(here)++;
		}else{
			int here=i-dis.at(i);
			if(dis.at(i)%2==1) here++;

			kids.at(here)++;
		}
	}

	for(int i=0;i<(int)s.size();i++){
		cout<<kids.at(i);
		if(i<(int)s.size()-1) cout<<" ";
		else cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct music
{
    long time;
    string title;
};

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

    std::vector<music> musicList;

    long playcount;
    cin >> playcount;
    for(int i = 0; i < playcount; i++){
        string title;
        long time;
        cin >> title >> time;
        music data;
        data.time = time;
        data.title = title;
        musicList.push_back(data);
    }
    string x;
    cin >> x;

    long sum = 0;
    bool isOn = false;
    for(std::vector<music>::iterator it = musicList.begin(); it != musicList.end(); ++it){
        if(it->title == x){
            isOn = true;
            continue;
        }
        if(isOn){
            sum += it->time;
        }
    }
    
    cout << sum <<  endl;

    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;

int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a[i];
    vector<int> cnt(n);
    rep (i,n) cnt[i] = k - q;
    rep(i,q){
        cnt[a[i] - 1]++;
    }
    rep(i,n){
        if(cnt[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

int main() {
  string S;
  cin >> S;
  int ans=0;
  int count =0;
  
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='A'||S.at(i)=='T'||S.at(i)=='C'||S.at(i)=='G'){
      count ++;
      if(ans<count)ans=count;
    }
    else{count =0;}
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3576
f x y = if x<y then (y-x)`div`2 else y-x 
cond x y p = if p then x else y

getIntegers = map read . words <$> getLine :: IO [Integer]

main = getLine >> zipWith f <$> getIntegers <*> getIntegers >>= putStrLn . cond "Yes" "No" . (>=0) . sum

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll X; cin >> X;
    ll dist[N];
    rep(i, N){
        ll a; cin >> a;
        dist[i] = abs(X-a);
    }
    ll ans = 0;
    rep(i, N) ans = __gcd(ans, dist[i]);
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> T;
    for (int i = 0; i < N; i++)
    {
        int t;
        cin  >> t;
        T.push_back(t);
    }
    
    int total=0;
    for (int i = 0; i < N; i++)
        total+= T[i];

    int M;
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        int p, x;
        cin >> p >> x;
        p--;
        
        int ans = total - T[p] + x;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
ans = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

k = int(input()) - 1
print(ans[k])


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define int ll

void solve()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<n;i++){
        ans+=(n/i)-(n%i==0);
    }
    cout<<ans<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n; cin >> n;
  int ans = 0;
  if(n < 3){cout << "0" << endl; return 0;}
  vector<ll> data(n); REP(i,n) cin >> data[i];
  sort(ALL(data));
  REP(i,n-2){FOR(j,i+1,n-1){FOR(k,j+1,n){
    if(data[i] == data[j] || data[j] == data[k] || data[k] == data[i])
      continue;
    if(data[i] + data[j] > data[k] && data[j] + data[k] > data[i] && data[k] + data[i] > data[j] )
      ans++;
  }}}
  cout << ans << endl;
}

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

int main()
{
 int a,b,c;
  cin >> a >> b >> c;
  if ((a==b&&a!=c) || (b==c&&b!=a) || (a==c&&a!=b))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg = str(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll n, m;
    std::cin >> n >> m;

    vll a(n);
    for (ll i = 0; i < n; i++)
        std::cin >> a[i];

    std::sort(a.begin(), a.end());

    vpll b(m);
    for (ll i = 0; i < m; i++)
        std::cin >> b[i].first >> b[i].second;

    std::sort(b.begin(), b.end(), [](pll a, pll b) -> bool {
        return a.second > b.second;
    });

    for (ll i = 0, j = 0; i < m && j < n; j++) {
        if (chmax(b[i].second, a[j]))
            b[i].first--;
        if (b[i].first == 0) i++;
    }

    ll ans = std::accumulate(a.begin(), a.end(), 0LL);

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


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    while(n > 0){
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

fmax = 0
for i in range(40, 0, -1):
  x = 2 ** (i - 1)
  f1 = 0
  f0 = 0
  for a in A:
    a_ = a & x
    f1 += x ^ a_
    f0 += a_
  #print(i, f0, f1)
  if f0 >= f1:
    fmax += f0
  else:
    if k >= x:
      fmax += f1
      k -= x
    else:
      fmax += f0
print(fmax)

Measured memory_bytes: 69264
#include<bits/stdc++.h>
using namespace std;
int n,ans[10010];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(i==0)ans[0]+=x;
		x=n-x;
		for(int j=1;j<n;j++){
			ans[n-j]=(ans[n-j]+x)%n;
			x=(x*i)%n;
		}
	}
	for(int i=0;i<n;i++)printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int n;
	cin>>n;
	long long *numArray = new  long long[n];
	long long sum = 0;
	rep(i,n){
		cin>>numArray[i];
		sum += numArray[i];
	}
	long long ans = sum;
	long long left = 0,right = sum;
	rep(i,n){
		left += numArray[i];
		right -= numArray[i];
		if( ans > abs(left-right)) ans = abs(left-right);
		/*cout<<"left ="<<left<<" right="<<right<<endl;
		cout<<abs(left - right)<<endl;*/
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, INF = 0x3f3f3f3f, M = 2e6 + 5;
int zz = 0;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])
int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int k,n;
    cin >> k >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll m = 0;
    rep(i,n-1){
        chmax(m,abs(a[i+1] - a[i]));
    }
    chmax(m,abs(k - a[n-1]) + a[0]);
    cout << k - m << endl;
}

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

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

	vector<int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d.at(i);
	}

	sort(d.begin(), d.end(), greater<int>());

	int ans = 1;
	for (int i = 1; i < d.size(); i++) {
		if (d.at(i) == d.at(i - 1))	continue;
		else ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
int tem(int x){
    if(x<9)return x+1;
        else return 1;
}
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
    int a,b;cin>>a>>b;
    string ans="NG";
    for(int i=a;i<=b;i++){
        if(i%n==0){
            ans="OK";break;
        }
    }cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
using System;

public class Test
{
	public static void Main()
	{
		string line = System.Console.ReadLine();
		int sum = 0;
	    for(int i=0; i<line.Length; i++){
	    	sum += line[i] - '0';
	    	sum %= 9;
	    }
	    if(sum == 0) Console.WriteLine("Yes");
	    else Console.WriteLine("No");
	}
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define MAX_V 300

struct edge{ int to,cap,rev; };
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front(); que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int h,w;
string s[111];

int main(){
	cin.sync_with_stdio(false);
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  int sc=h+w,sn=h+w+1;
  rep(i,h)rep(j,w){
    if(s[i][j]=='S'){
      add_edge(sc,i,INF);
      add_edge(sc,j+h,INF);
      rep(k,h)if(s[k][j]=='T'){
        cout<<-1<<endl;
        return 0;
      }
      rep(k,w)if(s[i][k]=='T'){
        cout<<-1<<endl;
        return 0;
      }
    }
    if(s[i][j]=='T'){
      add_edge(i,sn,INF);
      add_edge(j+h,sn,INF);
    }
    if(s[i][j]=='o'){
      add_edge(i,j+h,1);
      add_edge(j+h,i,1);
    }
  }
  int res=max_flow(sc,sn);
  cout<<res<<endl;
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// Topological Sort {{{
bool _visit(ll n, std::vector<ll> *marks,
        const std::vector<std::vector<ll>> &edges, std::vector<ll> *res) {
    if ((*marks)[n] == 1) {
        return false;
    } else if ((*marks)[n] == 0) {
        (*marks)[n] = 1;
        for (ll nxt : edges[n]) {
            if (!_visit(nxt, marks, edges, res)) {
                return false;
            }
        }
        (*marks)[n] = 2;
        res->push_back(n);
    }
    return true;
}

// 出力辺が存在しない頂点から順に，トポロジカルソート
// つまり，edgesには後に続く頂点を記述する
// 返値は，頂点番号を要素とするベクトル
// 閉路があれば返値の要素数を0にする
std::vector<ll> topologicalSort(std::vector<std::vector<ll>> edges) {
    ll N = edges.size();
    // 結果
    std::vector<ll> res;

    // 頂点に対する情報
    // 0: 印なし
    // 1: 一時的
    // 2: 恒久的
    std::vector<ll> marks(N, 0);

    bool ok = true;
    for (ll i = 0; i < N; i++)
        if (marks[i] == 0) {
            if (!_visit(i, &marks, edges, &res)) {
                ok = false;
                break;
            }
        }
    reverse(begin(res), end(res));
    return (ok ? res : std::vector<ll>());
}
// }}}

ll N,M;
vector<vector<ll>> edges;
vector<vector<ll>> r_edges;
vector<ll> depth; // トポロジカルソートにおける深さ
vector<ll> ans;

signed main() {
  cin >> N >> M;
  edges.resize(N);
  r_edges.resize(N);
  depth.resize(N);
  ans.resize(N);
  rep(i,N+M-1){
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    r_edges[b].push_back(a);
  }
  auto tsort = topologicalSort(edges);
  rep(i,tsort.size()){
    depth[tsort[i]] = i;
  }

  for(auto cur: tsort){
    ll par;
    if (r_edges[cur].size() == 0) { // 根
      par = -1;
    } else { // 葉
      par = r_edges[cur][0];
      for (auto cp : r_edges[cur]) {
        if (depth[cp] > depth[par]) {
          par = cp;
        }
      }
    }
    // cout << "cur:" << cur << " par:" << par << endl;
    ans[cur] = par;
  }

  rep(i,N){
    cout << ans[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 24952
#include<cmath>
#include <bits/stdc++.h>
#include <atcoder/dsu>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

using namespace atcoder;

int main(){
    int n,q;
    cin >> n>> q;
    dsu tree=dsu(n);
    rep(i,q){
        int t,u,v;
        cin >> t>> u>> v;
        if(t==0){
            tree.merge(u,v);
        }else{
            if(tree.same(u,v)){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4064
def examA():
    S = SI()
    if len(S)%2==1:
        print("No")
        return
    for i in range(len(S)//2):
        if S[i*2:i*2+2]!="hi":
            print("No")
            return
    print("Yes")
    return

def examB():
    a, b, M = LI()
    A = LI()
    B = LI()
    D = [LI()for _ in range(M)]
    ans = min(A) + min(B)
    for x,y,c in D:
        cur = A[x-1]+B[y-1]-c
        ans = min(ans,cur)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    int la = 0, fb = 0, w = 0;
    ll ans = 0;
    rep(i, N) {
        cin >> s[i];
        if (s[i][0] == 'B' and s[i][s[i].size()-1] == 'A') w++;
        else if (s[i][0] == 'B') fb++;
        else if (s[i][s[i].size()-1] == 'A') la++;

        rep(j, s[i].size()-1) {
            if (s[i][j] == 'A' and s[i][j+1] == 'B') {
                ans++;
            }
        }
    }

    if (w >= 1) {
        ans += w-1;    
        if (la >= 1) {
            ans++;
            la--;
        }
        if (fb >= 1) {
            ans++;
            fb--;
        }
    }

    if (la == fb) {
        ans += la;
    }
    else {
        ans += min(la, fb);
    }

//     if (la == fb) {
//         if (w >= 1) {
//             ans += w-1;
//             if (la >= 1) {
//                 ans += 2;
//                 la--;
//                 lb--;
//             }
//         }
//         ans += la;
//     }
//     else if (la < fb) {
//         if (w >= 1) {
//             ans += w-1;
//             if (la >= 1) {
//                 ans += 2;
//                 la--;
//                 lb--;
//             }
//         }
//         ans += la;
//         fb -= la;
//         if (fb > 0) ans++;
//     }
//     else if (la > fb) {
//         ans += fb;
//         la -= fb;
//         if (w-1 >= 0) ans += w-1;
//
//         if (la > 0) ans++;
//     }

    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int x = N % 10;
    if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) cout << "hon" <<endl;
    else if (x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
    else if (x == 3) cout << "bon" << endl;
    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int ans = 10000;
	rep(i,N)
	{
		ll A;
		cin >> A;
		int temp = 0;
		while(A % 2 == 0)
		{
			A /= 2;
			temp++;
		}
		ans = min(ans,temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  char s[MAX];
  scanf("%s", s);

  int bin[2] = {0};
  int len = strlen(s);
  rep(i, 0, len)
  {
    int num = (int)(s[i] - '0');
    bin[num]++;
  }
  int ans = min(bin[0], bin[1]) * 2;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256