akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x = [0] + list(map(int, input().split()))
y = [0] + list(map(int, input().split()))
tmp = [[0 for i in range(6)] for j in range(n+1)]
max = 0
for i in range(1, n+1, 1):
    absDiff = abs(x[i]-y[i])
    tmp[i][0] = absDiff
    tmp[i][1] = absDiff ** 2
    tmp[i][2] = tmp[i][1] * absDiff
    tmp[i][3] = tmp[i-1][3] + tmp[i][0]
    tmp[i][4] = tmp[i-1][4] + tmp[i][1]
    tmp[i][5] = tmp[i-1][5] + tmp[i][2]
    if absDiff > max:
        max = absDiff
print(tmp[n][3])
print(tmp[n][4] ** (1/2))
print(tmp[n][5] ** (1/3))
print(max)

Measured memory_bytes: 7836
import sys
sys.setrecursionlimit(10 ** 9)

N, M, P = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

edges = [[] for _ in range(N)]
to = [[] for _ in range(N)]
ot = [[] for _ in range(N)]

for a, b, c in X:
    a -= 1
    b -= 1
    c = -(c - P)
    edges[a].append((b, c))
    to[a].append(b)
    ot[b].append(a)

ok_1 = [False] * N
ok_n = [False] * N

# Reachable
def dfs(u):
    if ok_1[u]:
        return
    
    ok_1[u] = True
    for v in to[u]:
        dfs(v)
        
def rdfs(u):
    if ok_n[u]:
        return
    
    ok_n[u] = True
    for v in ot[u]:
        rdfs(v)
        
dfs(0)
rdfs(N - 1)
flag = [ok_1[i] & ok_n[i] for i in range(N)]

# Bellman ford
INF = 10 ** 9 + 7
d = [INF] * N
d[0] = 0
cnt = 0
updated = True
while updated and cnt <= N:
    updated = False
    cnt += 1
    for u in range(N):
        if not flag[u]:
            continue
        for v, c in edges[u]:
            if not flag[v]:
                continue

            value = d[u] + c
            if d[v] > d[u] + c:
                d[v] = value
                updated = True

if cnt > N:
    print(-1)
else:
    print(max(0, -d[-1]))


Measured memory_bytes: 65368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200005];

int main()
{
	ios::sync_with_stdio(false);
	int n,k;cin>>n>>k;
	for (int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	for (int i = 0; i <n-k; i++)
	{
		if(a[i+k]>a[i]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}


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


int main() {
    int N;
    cin>>N;
    int data[N];
    rep(i,N)cin>>data[i];
    map<int,int>mp;
    rep(i,N){
        mp[data[i]]++;
    }
    int count =0;
    for(auto p:mp){
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, q;
    cin >> n >> q;

    vector<pair<pair<int,int>,int>> vec;
    rep(i, n){
        int s, t, x;
        cin >> s >> t >> x;

        vec.push_back({{max(0,s - x), x}, 0});
        vec.push_back({{max(0,t - x), x}, 1});
    }

    sort(all(vec));
    vector<int> d(q);

    rep(i, q){
        cin >> d[i];
    }

    int now = 0;
    multiset<int> st;
    rep(i, q){
        while(d[i] >= vec[now].first.first && now < vec.size()){
            //cout << now << " " << vec[now].first.first << " " << vec[now].first.second <<" "<< vec[now].second << endl;
            if(!vec[now].second){
                st.insert(vec[now].first.second);
            } else {
                auto itr = st.find(vec[now].first.second);
                st.erase(itr);
            }
            now++;
        }

        cout << (st.size()==0?-1:*st.begin()) << endl;

    }
}

Measured memory_bytes: 16620
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf=1e9+7;

/*
全ての宝石が自分のもので，そこから割って行くことを考える
「何もしない」→「割る」の順で考えた．
容量0の辺を無闇に作ってはいけない
*/

struct Dinic{
	const long long INF=1e18+9;
	
	struct edge {
		long long to,cap,rev;
		edge(){}
		edge(long long to,long long cap,long long rev):to(to),cap(cap),rev(rev){}
	};

	long long n;
	vector<vector<edge> > G;
	vector<map<long long,long long> > M;
	vector<long long> level,iter;

	Dinic(){}
	Dinic(long long sz):n(sz),G(n),M(n),level(n),iter(n){}
	
	void add_edge(long long from,long long to,long long cap){
		M[from][to]=G[from].size();
		M[to][from]=G[to].size();
		G[from].push_back(edge(to,cap,G[to].size()));
		// undirected
		//G[to].push_back(edge(from,cap,G[from].size()-1));
		// directed
		G[to].push_back(edge(from,0,G[from].size()-1));
	}
	
	void bfs(long long s){
		fill(level.begin(),level.end(),-1);
		queue<long long> que;
		level[s]=0;
		que.push(s);
		while(!que.empty()){
			long long v=que.front();que.pop();
			for(long long i=0;i<(long long)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);
				}
			}
		}
	}
	
	long long dfs(long long v,long long t,long long f){
		if(v==t) return f;
		for(long long &i=iter[v];i<(long long)G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0&&level[v]<level[e.to]){
				long long 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;
	}
	
	long long flow(long long s,long long t,long long lim){
		long long fl=0;
		for(;;){
			bfs(s);
			if(level[t]<0||lim==0) return fl;
			fill(iter.begin(),iter.end(),0);
			long long f;
			while((f=dfs(s,t,lim))>0){
				fl+=f;
				lim-=f;
			}
		}
	}

	long long flow(long long s,long long t){
		return flow(s,t,INF);
	}

	//cap==1 only
	bool back_edge(long long s,long long t,long long from, long long to){
		for(long long i=0;i<(long long)G[from].size();i++) {
			edge& e=G[from][i];
			if(e.to==to) {
				if(e.cap==0&&flow(from,to,1)==0) {
					flow(from,s,1);
					flow(t,to,1);
					return 1;
				}
			}
		}
		return 0;
	}
};

int main(void){
	ll n,sum=0;
	Dinic f(110);
	cin>>n;
	reg(i,1,n){
		ll a;
		cin>>a;
		if(a>0){
			sum+=a;
			f.add_edge(0,i,a);//割る
		}else if(a<0){//容量0の辺を無闇に作ってはいけない
			f.add_edge(i,n+1,-a);//残す
		}
		reg(j,1,n){
			if(i*j>n)break;
			f.add_edge(i*j,i,inf);//自分が割られたら自分の倍数も割る
		}
	}
	cout<<sum-f.flow(0,n+1)<<endl;
	// cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define For(i,A,B) for(i=A;i<=(B);++i)
using namespace std;
typedef long long ll;
int a[100050],n,m,v,p;
inline bool cmp(int x,int y){return x>y;}
inline bool check(int k){
	if(a[k]>=a[p])return 1;
	if(a[k]+m<a[p])return 0;
	if(p+n-k>=v)return 1;
	int i;
	ll s=0ll;
	For(i,p,k-1)s+=a[k]+m-a[i];
	return s>=(ll)(v-p-n+k)*m;
}
int main(){
	int i,l,r,mid;
	scanf("%d%d%d%d",&n,&m,&v,&p);l=p;r=n;
	For(i,1,n)scanf("%d",a+i);
	sort(a+1,a+n+1,cmp);
	while(l<r){
		mid=l+r+1>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int n,m,s[10],c[10];

bool check(int x){
    vector<int> num;

    if(x==0){
        num.push_back(0);
    }
    while(x!=0){
        num.push_back(x%10);
        x/=10;
    }

    reverse(num.begin(),num.end());

    for(int i=0;i<m;i++){
        int idx = s[i] - 1;
        if(idx >= num.size()) return false;
        if(num[idx] != c[i]) return false;
    }

    return true;
}

int main(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> s[i] >> c[i] ;
    }

    int z = 1;
    for(int i=0;i<n;i++){
        z*=10;
    }
    int start;
    if(z==10)start=0; else start = z/10;
    for(int i=start;i<z;i++){
        if(check(i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;

    return 0;
}

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

double deg_rad(double x)
{
	return (x*M_PI)/180.0;
}
double abs(double x)
{
	if (x<0)
		return x*-1;
	else
		return x;
}
int main()
{
	int A, B, H, M;
	
	double angle, angle_rad, C;
	scanf("%d %d %d %d",&A,&B,&H,&M);
	angle = abs(30*H-5.5*M);
	angle_rad = deg_rad(angle);
	C = sqrt(A*A + B*B - 2*A*B*cos(angle_rad));
	printf("%.16g",C);
	return 0;
	
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[10];
bool ans;

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) {
         cin >> a[i];
      }
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}


Measured memory_bytes: 2956
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=1e5+5,MD=1e9+7,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-9,e=exp(1),PI=acos(-1.);
int a[N];
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k&1)
        cout<<b-a;
    else cout<<a-b;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
const int MOD = 1000000007;
const char nl = '\n';
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
	cout << "Execution Time: ";
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
//const int N = 200200;
//bool p[N];
vector<int> a;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n, d;
    cin >> n >> d;
    int cnt=0;
    while(n--){
        int x, y;
        cin >> x >> y;
        if(d >= sqrt((pow(x,2) + pow(y,2)))) cnt++;
    }
    cout << cnt;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<pair<string, pair<i64, i64>>> d(n);
  for (i64 i = 0; i < n; i++)
  {
    cin >> d[i].first >> d[i].second.first;
    d[i].second.second = i + 1;
  }
  sort(d.begin(), d.end(), [](const pair<string, pair<i64, i64>> &x, const pair<string, pair<i64, i64>> &y) {
    return (x.first == y.first ? x.second.first > y.second.first : x.first < y.first);
  });
  for (i64 i = 0; i < n; i++)
    cout << d[i].second.second << endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cassert>

template<class T>
struct potentialized_union_find {
    using value_type = T;
    using size_type = std::size_t;
private :
    size_type _size;
    std::vector<int> node;
    std::vector<value_type> potential;

public :
    potentialized_union_find (size_type n, const value_type &ie) : 
        _size(n), node(n, -1), potential(n, ie) { }

    size_type root (size_type x) {
        if (node[x] < 0) return x;
        int r = root(node[x]);
        potential[x] += potential[node[x]];
        return (node[x] = r);
    }

    value_type weight (size_type x) {
        root(x);
        return (potential[x]);
    }

    bool unite (size_type x, size_type y, value_type p) {
        p += (weight(x) - weight(y));
        if ((x = root(x)) == (y = root(y))) return false;
        if (node[x] > node[y]) {
            std::swap(x, y);
            p = -p;
        }
        node[x] += node[y];
        node[y] = x;
        potential[y] = p;
        _size--;
        return true;
    }

    bool same (size_type x, size_type y) {
        return (root(x) == root(y));
    }

    value_type diff (size_type x, size_type y) {
        assert(same(x, y));
        return (weight(y) - weight(x));
    }

    const size_type& size () const noexcept {
        return (_size);
    }

    size_type size (size_type x) {
        return (size_type(-node[root(x)]));
    }

};


#include <bits/stdc++.h>

int main() {
    std::size_t n;
    int m, k;
    std::cin >> n >> m >> k;

    potentialized_union_find<int> uf(n, 0);
    std::vector<int> ans(n, -1);
    
    for (int i = 0; i < m; i++) {
        std::size_t x, y;
        std::cin >> x >> y;
        x--; y--;
        uf.unite(x, y, 0);
        ans[x]--; ans[y]--;
    }

    for (int i = 0; i < k; i++) {
        std::size_t x, y;
        std::cin >> x >> y;
        x--; y--;
        if (uf.same(x, y)) {
            ans[x]--; ans[y]--;
        }
    }

    for (std::size_t i = 0; i < n; i++) {
        std::cout << ans[i] + int(uf.size(i)) << '\n';
    }

    return 0;
}

Measured memory_bytes: 4188
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a=scanner.nextInt();
    int b=scanner.nextInt();

    int ans=0;
    for(int i=0;i<2;i++){
      if(a>b){
        ans+=a;
        a--;
      }
      else{
        ans+=b;
        b--;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define fork(a,b) for(int k=a;k<b;k++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define seto(x,i) memset(x,i,sizeof x)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pf first
#define ps second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=300010;
ll n,f[N],x,sum[N],mid;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("", "r", stdin);
    cin>>n;
    fori(0,n)
    {
        cin>>x;
        f[x]++;
    }
    f[0]=inf; sort(f,f+n+1); reverse(f,f+n+1);
    fori(1,n+1)
        sum[i]=sum[i-1]+f[i];
    mid=1;
    fori(1,n+1)
    {
        x=sum[n]-sum[i];
        while(f[mid]*(i-mid)-(sum[i]-sum[mid])>x)
            mid++;
        cout<<f[mid]+(x-f[mid]*(i-mid)+sum[i]-sum[mid])/(i-mid+1)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 5632
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)


  val MOD = 1e9.toLong + 7
  val N, M = in.next().toInt
  val S = new Array[Int](N+1)
  val T = new Array[Int](M+1)
  for (i <- 1 to N)
    S(i) = in.next().toInt
  for (i <- 1 to M)
    T(i) = in.next().toInt

  //
  val imos = Array.ofDim[Long](N+1, M+1)
  val dp = Array.ofDim[Long](N+1, M+1)
  for (n <- 1 to N) {
    for (m <- 1 to M) {
      if (S(n) == T(m)) {
        dp(n)(m) = imos(n-1)(m-1) + 1
        dp(n)(m) %= MOD
      }

      imos(n)(m) = imos(n-1)(m) + imos(n)(m-1) - imos(n-1)(m-1)
      if (imos(n)(m) < 0)
        imos(n)(m) += MOD
      imos(n)(m) %= MOD
      imos(n)(m) += dp(n)(m)
      imos(n)(m) %= MOD
    }
  }


  var ans = 0L
  for (n <- 1 to N)
    for (m <- 1 to M) {
      ans += dp(n)(m)
      ans %= MOD
    }

  println((ans + 1) % MOD)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 113616
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(b-a == c-b) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    for (int i = 0; i < A; ++i){
        cin >> a.at(i);
    }
    vector<int> b(B);
    for (int i = 0; i < B; ++i){
        cin >> b.at(i);
    }

    int ans1 = 10e7;


    for (int i = 0; i < M; ++i){
        int x, y, c;
        cin >> x >> y >> c;
        --x;
        --y;
        int sum = a.at(x) + b.at(y) - c;
        ans1 = min(ans1, sum);
    }
    int a_min = *min_element(a.begin(), a.end());
    int b_min = *min_element(b.begin(), b.end());

    cout << min(ans1,a_min+b_min) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint a[200005];
vector<llint> pvec, nvec, zvec;
vector<P> vec;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i] > 0) pvec.push_back(a[i]);
		else if(a[i] < 0) nvec.push_back(a[i]);
		else zvec.push_back(a[i]);
	}
	sort(pvec.begin(), pvec.end());
	sort(nvec.rbegin(), nvec.rend());
	
	for(int i = 0; i < nvec.size(); i++){
		nvec[i] = (nvec[i]%mod+mod)%mod;
	}
	
	llint ans = 1;
	if(n == k){
		for(int i = 1; i <= n; i++) ans *= (a[i]%mod+mod)%mod, ans %= mod;
		cout << ans << endl;
		return 0;
	}
	if(nvec.size() == n && k % 2){
		for(int i = 0; i < k; i++) ans *= nvec[i], ans %= mod;
		cout << ans << endl;
		return 0;
	}
	if(zvec.size() > n-k){
		cout << 0 << endl;
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		vec.push_back(P(abs(a[i]), (a[i]>=0)?1:-1));
	}
	sort(vec.rbegin(), vec.rend());
	
	llint cnt = 0;
	for(int i = 0; i < k; i++){
		ans *= vec[i].first, ans %= mod;
		if(vec[i].second == -1) cnt++;
	}
	if(cnt % 2){
		llint p = -1, ne = -1, p2 = -1, n2 = -1;
		for(int j = 0; j < k; j++){
			if(vec[j].second == 1) p2 = vec[j].first;
			else ne = vec[j].first;
		}
		for(int j = n-1; j >= k; j--){
			if(vec[j].second == 1) p = vec[j].first;
			else n2 = vec[j].first;
		}
		bool flag;
		if(p2 == -1) flag = true;
		else if(ne == -1) flag = false;
		else if(p*p2 >= ne*n2) flag = true;
		else flag = false;
		
		if(flag){
			ans *= p, ans %= mod;
			ans *= modpow(ne, mod-2), ans %= mod;
		}
		else{
			ans *= n2, ans %= mod;
			ans *= modpow(p2, mod-2), ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

int main (){

 int n;
  cin >>n;
  int c[500],s[500],f[500];
  for(int i=0; i<n-1; i++) cin >> c[i] >> s[i] >> f[i];
  
  int t;
  for(int i=0; i<n; i++){
    t=0;
    for(int j=i; j<n-1; j++){
    	if(t<s[j]) t=s[j];
      	else if(t%f[j]==0) t=t;
      	else t=t+f[j]-(t%f[j]);
      	t+=c[j];
    }
    cout << t << endl;
  }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

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

  vi a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  vi num(n);
  iota(all(num), 0);
  sort(all(num), [&](const int &x, const int &y){
        return b[x] < b[y];
      });

  int cur = 0;
  for(int i : num){
    cur += a[i];
    if(cur > b[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>

#define MAX 100000
#define INFTY 1000000002

typedef struct node{
  int key;
  char type;
}Card;

int n;
Card trump1[MAX],trump2[MAX];
Card L[MAX/2+2],R[MAX/2+2];

void Merge(int l,int m,int r){
  int i,j,k;
  int na = m - l;
  int nb = r - m;

  for(i = 0; i < na; i++)L[i] = trump1[l + i];
  for(j = 0; j < nb; j++)R[j] = trump1[m + j];
  L[na].key = R[nb].key = INFTY;
  i = j = 0;
  for(k = l; k < r; k++){
    if(L[i].key <= R[j].key){
      trump1[k] = L[i] ;
      i++;
    }
    else {
      trump1[k] = R[j];
      j++;
    }
  }
}

void MergeSort(int l,int r){
  int m;
  if(l + 1 < r){
    m = (l + r)/2;
    MergeSort(l,m);
    MergeSort(m,r);
    Merge(l,m,r);
  }
}
int Partition(int p,int r){
  int i,j;
  Card x,v;
  
  x = trump2[r];
  i = p - 1;
  for(j = p; j <= r - 1; j++){
    if(trump2[j].key <= x.key){
      i = i + 1;
      v = trump2[i];
      trump2[i] = trump2[j];
      trump2[j] = v;
    }
  }
  v = trump2[i+1];
  trump2[i+1] = trump2[r];
  trump2[r] = v;

  return i+1;
}

void QuickSort(int p,int r){
  int h;
  if(p < r){
    h = Partition(p,r);
    QuickSort(p,h-1);
    QuickSort(h+1,r);
  }
}

void isStable(){
  int i,stable = 0;
  for(i = 0; i < n; i++){
    if(trump1[i].type == trump2[i].type){
      stable = 1;
    }
    else {
      stable = 0;
      break;
    }
  }
  
  if(stable == 1)printf("Stable\n");
  else printf("Not stable\n");
}

int main(){
  int i,key;
  char type;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s %d",&type,&key);
    trump1[i].key = trump2[i].key = key;
    trump1[i].type = trump2[i].type = type;
  }
  //if(n <= 2)MergeSort(0,n-1);
  MergeSort(0,n);
  QuickSort(0,n - 1);
  isStable();

  for(i = 0; i < n; i++)printf("%c %d\n",trump2[i].type,trump2[i].key);
  //for(i = 0; i < n; i++)printf("%c %d\n",trump1[i].type,trump1[i].key);
  
  return 0;
}



Measured memory_bytes: 4076
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define MAX 100000
using namespace std;
int n,a[MAX+5],cnt_first[MAX+5],cnt_second[MAX+5],cnt[MAX+5];
vector<int>q;
void run()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	scanf("%d",&a[i]);
}
int rule(int a,int b)
{
	return a>b;
}
void solve()
{
	for(int i=1; i<=n; i++)
	{
	   if(i%2==1)
		cnt_first[a[i]]++;
		 else
		  cnt_second[a[i]]++;
	}
	for(int i=1; i<=100000; i++)
	{
		q.push_back(max(cnt_first[i],cnt_second[i]));
	}
	sort(q.begin(),q.end(),rule);
	int ans=0;
	for(int i=0; i<2; i++)
	{
	    ans+=n/2-q[i];
	}
	printf("%d",ans);
}
int main()
{
	run();
	solve();
	return 0;
} 

Measured memory_bytes: 2044
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int input = 0;
        int count = 0;
        do{
            input = sc.nextInt();
            if(input != 0){
                System.out.println("Case " + ++count + ": " +  input);
            }
            
        }while(input != 0);
    }
}


Measured memory_bytes: 40584
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
a=input()
l=list("abcdefghijklmnopqrstuvwxyz")
if a in l:
    print("a")
else:
    print("A")


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

int main(){
  string S;
  cin >> S;
  vector<int> num(26,0);
  for(int i=0;i<S.size();i++){
    num.at(S.at(i)-'a')++;
  }
  for(int i=0;i<26;i++){
    if(num.at(i)==0){
      char C=i+'a';
      cout << C << endl;
      break;
    }
    if(i==25){
      cout << "None" << endl;
    }
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int n,jc[200005]={1},ny[200005]={1};
vector<int> g[200005];
ll f[200005],f2[100005],size[200005];
int Power(int x,long long y,int mod) {
	int ret=1;
	while(y) {
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
int C(int x,int y){
	return 1ll*jc[x]*ny[y]%mod*ny[x-y]%mod;
}
void DFS(int x,int fa) {
	f[x]=size[x]=1;
	for(int y:g[x]) {
		if(y==fa)continue;
		DFS(y,x);
		f[x]=1ll*f[x]*f[y]%mod*C(size[x]+size[y]-1,size[x]-1)%mod;
		size[x]+=size[y];
	}
}
void HuanGen(int x,int fa){
	for(int y:g[x]){
		if(y==fa)continue;
		int tmp=1ll*f2[x]*Power(C(n-1,n-size[y]-1),mod-2,mod)%mod*Power(f[y],mod-2,mod)%mod;
		f2[y]=1ll*f[y]*tmp%mod*C(n-1,size[y]-1)%mod;
		HuanGen(y,x);
	}
}
int main() {
	cin>>n;
	for(int i=1; i<n; i++) {
		int x,y;
		cin>>x>>y;
		g[x].push_back(y),g[y].push_back(x);
	}
	for(int i=1; i<=n; i++)jc[i]=1ll*jc[i-1]*i%mod;
	ny[n]=Power(jc[n],mod-2,mod);
	for(int i=n-1; i>=1; i--)ny[i]=1ll*(i+1)*ny[i+1]%mod;
	memset(size,0,sizeof(size));
	DFS(1,0);
	f2[1]=f[1];
	HuanGen(1,0);
	for(int i=1;i<=n;i++)cout<<f2[i]<<endl;
	return 0;
}


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

int Q, c, a, n;

int main(){
    for(scanf("%d", &Q);Q--;){
        scanf("%d%d%d", &c, &a, &n);
        int ans = 0;
        ans += min(c, min(a, n));
        c -= ans; a -= ans;
        ans += min(c/2, a);
        c -= 2*min(c/2, a);
        ans += c/3;
        printf("%d\n", ans);
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll> > DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX/3
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define rep(i,n)    repl(i,0,n-1)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#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 exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<int>())
#define mkp(x,y)    make_pair(x,y)

void print_vector(Vector a){
 cout << a[0];
 repl(i, 1, a.size()-1) cout << ' ' << a[i];
 cout << endl;
}

void bubbleSort(Vector a){
  bool flag = true;
  int count = 0;
  while(flag){
    flag = false;
    repl(j,1,a.size()-1){
      if(a[j] < a[j-1]){
        swap(a[j],a[j-1]);
        count++;
        flag = true;
      }
    }
  }
  print_vector(a);
  cout << count << endl;
}

int main(){
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  Vector a(n);
  rep(i,n)cin >> a[i];
  bubbleSort(a);
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7; 
ll f[maxn],inv[maxn];
ll quick(ll a,ll b){ 
    ll ans=1;  
    a=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
ll cal(int n,int k)
{
	return f[n]*inv[n-k]%mod*inv[k]%mod;
}
int main()
{
	int n,k;
	f[0]=inv[0]=1;
	for(int i=1;i<maxn;++i) f[i]=f[i-1]*i%mod,inv[i]=quick(f[i],mod-2); 
	scanf("%d %d",&n,&k);
	ll ans=0;
	for(int i=0;i<=min(n-1,k);++i) ans+=cal(n,i)*cal(n-1,i)%mod,ans%=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,y = LI()
    n = x+y
    if n%3 != 0:
        print(0)
        return
    n //= 3
    ans = 1
    for i in range(max(x,y)-n):
        ans *= n-i
        ans %= mod
        ans *= pow(i+1,mod-2,mod)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39504
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
const int maxn=505;
struct Node {
    LL c,s,f;
}node[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<n;i++) {
        cin>>node[i].c>>node[i].s>>node[i].f;
    }
    for(int i=1;i<n;i++) {
        LL time=node[i].s+node[i].c;
        for(int j=i+1;j<n;j++) {
            if(time<=node[j].s) {
                time=node[j].s+node[j].c;
            }
            else {
                LL temp=0;
                if(time%node[j].f==0) time+=node[j].c;
                else {
                    while(time%node[j].f!=0) time++;
                    time+=node[j].c;
                }
            }
        }
        cout<<time<<endl;
    }
    cout<<0<<endl;
    return 0;
}


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

int main() {
	double L;
	cin >> L;
	double a = L/3;
	cout << fixed << setprecision(9);
	cout << a*a*a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define pb push_back
        #define mp make_pair
        #define ii pair<int,int>
        #define modulo 1000000007
        #define modulus 10000000000000003
        #define INF 100000000000000000
        #define int long long int
        using namespace std;
        
		vector<int> stones;
		vector<int> depe;
        int32_t main(){
			ios_base::sync_with_stdio(0);
			cin.tie(NULL);
			int n,a;
			cin >> n;
			stones.resize(n+1);
			depe.resize(n+1,-1);
			for(int i=1;i<=n;i++){
				cin >> a;
				stones[i]=a;
				}
			depe[n]=0;
			depe[n-1]=abs(stones[n]-stones[n-1]);
			for(int i=n-2;i>=1;i--){
				depe[i]=min(abs(stones[i]-stones[i+2])+depe[i+2],abs(stones[i]-stones[i+1])+depe[i+1]);
				}
			cout << depe[1];
			}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
int W,H,x,y,r;
scanf("%d %d %d %d %d", &W,&H,&x,&y,&r);
if(x < r || x > W-r || y < r || y > H - r)
printf("No\n");
else
printf("Yes\n");

return 0;
}

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

#define ll                  long long
#define scl(n)              scanf("%lld", &n)
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
#define pfl(x)              printf("%lld\n",x)
#define endl 	            "\n"
#define pb                  push_back
#define l(s)                s.size()
#define asort(a)            sort(a,a+n)
#define dsort(a)            sort(a,a+n,greater<int>())
#define vasort(v)           sort(v.begin(), v.end());
#define vdsort(v)           sort(v.begin(), v.end(),greater<int>());
#define pn                  printf("\n")
#define md                  10000007

ll n;
vector<ll>v[1000005];
ll cnt=1;
bool vis[1000005];
ll clr[1000005];
queue<ll>q;
void bfs(ll s, ll d)
{
    q.push(s);
    clr[s]=d;
    while(!q.empty())
    {
         ll p=q.front(); q.pop();
         for(ll i=0;i<v[p].size();i++)
         {
             ll u=v[p][i];
             if(clr[u]==-1)
             {
                 q.push(u);
                 clr[u]=d;
             }
         }
    }
}

void colour( )
{
    fr(i,1000000)clr[i]=-1;

    fr(i,n)if(clr[i]==-1)bfs(i, cnt++);
}
int main()
{
    ll m,t,b,c,d,i,j,k,x,y,z,l,q,r;

      ll cnt=0,ans=0;
      scl(n);scl(m);

      fr(i,m)
      {
          cin>>x>>y;
          v[x].pb(y);
          v[y].pb(x);
      }
      colour();

      cin>>q;
      while(q--)
      {
          cin>>x>>y;
          if(clr[x]==clr[y])cout<<"yes"<<endl;
          else cout<<"no"<<endl;
      }
return 0;
}



Measured memory_bytes: 37824
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/* Grid
 * Clock at 0,0
 * horizontal east west streets
 * vertical north south streets
 * Two initial railroads, x-axis and y-axis
 *
 * Note that points are weighted by p[i]
 * Since N is small we should be able to brute force somehow.
 *
 * Note that with n railroads ans eq 0.
 *
 * With one railroad we got basically 4
 * Building one railroad in a quadrant must be done
 * on median element (median with p[]).
 * Building secdon railroad in same quadrant...
 * ...
 * Brute force all of it.
 * All railroads should go through a position. But if a position has
 * a railroad, there is never need to build a second through it.
 *
 * So we got N positions and a horz or a vert or non railroad.
 * This is 3^n possible states.
 * Foreach one find the dist value, and update the ans for
 * number of build railroads.
 *
 * How to iterate 012? -> implement on vector
 * How to precalc the distances?
 */
const int INF=1e18;

void solve() {
    cini(n);
    vi x(n);
    vi y(n);
    vi p(n);

    for(int i=0; i<n; i++)
        cin>>x[i]>>y[i]>>p[i];

    vi ans(n+1, INF);
    ans[0]=0;
    for(int i=0; i<n; i++)
        ans[0]+=min(abs(x[i]), abs(y[i]))*p[i];

    for(int s=0; s<(1<<n); s++) { // rails throug houses where s bit is set
        vi nobits;
        vi bits;
        for(int i=0; i<n; i++) {
            if((s>>i)&1)
                bits.push_back(i);
            else
                nobits.push_back(i);
        }

        for(int t=s; true; t=(t-1)&s) {    // horz rail if t set else vert rail
            int dist=0;
            for(int i : nobits) {    // all houses
                int d=min(abs(x[i]), abs(y[i]));
                for(int j : bits) {    // all rails
                    if((t>>j)&1)
                        d=min(d, abs(x[i]-x[j]));
                    else
                        d=min(d, abs(y[i]-y[j]));
                }
                dist+=d*p[i];
            }
            ans[bits.size()]=min(ans[bits.size()], dist);
            if(t==0)
                break;
        }

    }

    for(signed i=0; i<=n; i++)
        cout<<ans[i]<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main(){
  prep();
  long long n, k;
  cin >> n >> k;
  int arr[n];
  int graph[200001];
  int graph2[200001];
  for (int i=0; i<n; i++){
      cin >> arr[i];
     
  }
  if (n == 1){
      if (k%2 == 1){
          cout << arr[0];
      }
      return 0;
  }
  int nums[200001];
  memset(graph, -1, sizeof(int)*200001);
  memset(graph2, -1, sizeof(int)*200001);
  memset(nums, -1, sizeof(int)*200001);
  for (int j=0; j<2; j++){
      for (int i=n-1; i>=0; i--){
          if (nums[arr[i]] != -1){
              graph[i] = nums[arr[i]];
              if (nums[arr[i]] > i){
                  graph2[i] = nums[arr[i]];
              }
          }
          nums[arr[i]] = i;
      }
  }
  
  int cur = (graph[0]+1)%n;
  int times = 1+(cur == 1);
  while (cur != 0){
      int before = cur;
      if (graph[cur] <= before){
          //cout << graph[cur] << " " << before << endl;
          times++;
      }
      cur = (graph[cur]+1)%n;
  }
  //cout << times << endl;
  if (k%times == 0){
      return 0;
  }
  int other = k%times;
  cur = 0;
  times = 0;
  while (times < other-1){
      int before = cur;
      if (graph[cur] <= before){
          times++;
      }
      cur = (graph[cur]+1)%n;
      
  }
  vector<int> res;
  while (cur < n){
      int next = graph2[cur];
      if (next == -1){
          res.push_back(arr[cur]);
          cur++;
      }else{
          cur = graph2[cur]+1;
      }
  }
  for (int i=0; i<res.size(); i++){
      cout << res[i] << " ";
  }
  return 0; 
}

Measured memory_bytes: 5620
import java.util.Scanner;

public class Main {

  public static void main(final String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final var A = scanner.nextDouble();
    final var B = scanner.nextDouble();
    final var H = scanner.nextDouble();
    final var M = scanner.nextDouble();

    final var alpha = (2.0d * Math.PI) * (H / 12.0d)
        + (2.0d * Math.PI) * (1.0d / 12.0d) * (M / 60.d);
    final var beta = (2.0d * Math.PI) * (M / 60.0d);
    final var theta = Math.abs(alpha - beta);

    if (Double.compare(theta, 0.0d) == 0) {
      System.out.printf("%1.12f\n", Math.abs(A - B));
      return;
    }

    if (Double.compare(theta, Math.PI) == 0) {
      System.out.printf("%1.12f\n", A + B);
    } else {
      final var gamma = theta > Math.PI ? 2 * Math.PI - theta : theta;
      final var C = Math.pow(A, 2) + Math.pow(B, 2) - 2.0d * A * B * Math.cos(gamma);
      final var c = Math.sqrt(C);

      System.out.printf("%1.12f\n", c);
    }
  }
}


Measured memory_bytes: 37500
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std; 
int main(){
    int a,b,c,k;
    cin >>a >> b >> c >> k;
    if(a >= k){
        cout << k << endl;
    }
    else if(a + b >= k){
        cout << a <<endl;
    }
    else cout <<a-(k-a-b) << endl;
   return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int ti = clock();
    int d;
    cin >> d;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vector<vi> s(d, vi(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vi last(26), t(d);
    ll sum = 0;
    rep1(i, d) {
        ll cm = 0;
        rep(j, 26) cm += c[j] * (i - last[j]);
        pii m(-INF, -1);
        rep(j, 26) {
            ll sat = s[i-1][j] - cm + c[j] * (i - last[j]);
            m = max(m, {sat, j});
        }
        sum += m.first;
        last[m.second] = i;
        t[i-1] = m.second;
        //cout << (m.second + 1) << endl;
    }
    srand((unsigned)time(NULL));
    while (clock()-ti < CLOCKS_PER_SEC*195/100) {
        int dr = rand() % d + 1, qr = rand() % 26;
        int fq = t[dr-1], tq = qr;
        int td = dr;
        int fl = dr-1, fr = dr+1, tl = dr, tr = dr;
        while (fl > 0) {
            if (t[fl-1] == fq) break;
            --fl;
        }
        while (fr <= d) {
            if (t[fr-1] == fq) break;
            ++fr;
        }
        while (tl > 0) {
            if (t[tl-1] == tq) break;
            --tl;
        }
        while (tr <= d) {
            if (t[tr-1] == tq) break;
            ++tr;
        }
        ll nsum = sum;
        nsum -= s[td-1][fq];
        nsum += (td-fl)*(td-fl-1)*c[fq]/2 + (fr-td)*(fr-td-1)*c[fq]/2;
        nsum -= (fr-fl)*(fr-fl-1)*c[fq]/2;
        nsum += s[td-1][tq];
        nsum -= (td-tl)*(td-tl-1)*c[tq]/2 + (tr-td)*(tr-td-1)*c[tq]/2;
        nsum += (tr-tl)*(tr-tl-1)*c[tq]/2;
        //cout << sum << endl;
        if (nsum > sum) t[td-1] = tq;
    }
    rep(i, d) cout << (t[i] + 1) << endl;
    return 0;
}


Measured memory_bytes: 3724
#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))
//-------------------------------------------------------


void solve() {
    ll i; string s;
    bool exit = false;
    ll N;
    ll X;
    cin >> N >> X;
    vector <ll> x;
    FOR(i,N){
        ll input;
        cin >> input;
        x.push_back(input);
    }
    sort(ALL(x));
    vector <ll> cand;
    ll tryNum,tryNum_,i_;
    ll cost=0;
    ll ret=LLONG_MAX;
    ll xSum[N+1];
    xSum[0] = 0;
    FOR(i, N){
        xSum[i+1] = xSum[i] + x[i];
    }
    FOR(tryNum_, (N+1)/2){
        exit = false;
        tryNum = tryNum_ +  1;
        //cout<<cost<<endl;
        //cout<<tryNum<<endl;
        cost = tryNum*X + N * X;
        if(ret<cost)
            continue;
        //if(tryNum==2)cout<<cost<<endl;
        if( tryNum*2 > N){
            cost += 5 * (xSum[N]-xSum[0]);
            if(ret<cost)
                continue;
            //cand.push_back(cost);
            //continue;
        }else{
            cost += 5 * (xSum[N]-xSum[N-tryNum*2]);
            if(ret<cost)
                continue;
        }
        //if(tryNum==2)cout<<cost<<endl;
        FOR(i_ , (N-tryNum*2 + tryNum-1)/tryNum){
            i = i_ + 1;
            if(tryNum*i > N-tryNum*2){
                cost += (5+i*2) * (xSum[N-tryNum*2 - tryNum*(i-1)] - xSum[0]);
                break;
            }else{
                cost += (5+i*2) * (xSum[N-tryNum*2-tryNum*(i-1)] - xSum[N-tryNum*2-tryNum*i]);
                if(ret<cost){
                    break;
                }
            }
        }
        //cout<<cost<<endl;
        //cand.push_back(cost);
        if(cost < ret)
            ret = cost;
    }
    //sort(ALL(cand));
    //FORR(i, cand)      cout<<i<<endl;
    //cout<<cand[0]<<endl;
    cout<<ret<<endl;
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<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: 3568