akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
ll arr[26];
int main()  
{     
    string s;
    cin>>s;
    for(ll i=0;i<s.length();i++)
        arr[s[i]-'a']++;
    for(ll i=0;i<26;i++)
    {
        if(arr[i]%2!=0)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}   

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-8;

int main()
{
	double N, K, T, U, V, L;
	cin >> N >> K >> T >> U >> V >> L;
	vi D(N+1);
	REP(i, N) {
		cin >> D[i];
	}
	D[N] = L+1;
	
	bool boost = false;
	double ans = 0, rest = 0; 
	int carrot = 0, pos = 0;

	FOR(d, 1, L+1) {
		if(!boost && carrot > 0) {
			boost = true;
			rest = T;
			carrot--;
		}

		if(boost) {
			ans += 1/V;
			rest -= 1/V;
			if(abs(rest) < EPS) {
				boost = false;
			}
		} else {
			ans += 1/U;
		}

		if(D[pos] == d) {
			pos++;
			carrot++;
			if(carrot > K) {
				carrot--;
				rest = T;
				boost = true;
			}
		}
	}

	printf("%.9f\n", ans);
}

Measured memory_bytes: 1248
var i,n,x,Min,Max:longint;
begin
    readln(n);
    Max:=0;Min:=1000;
    for i:=1 to n do
    begin
        read(x);
        if x>Max then Max:=x;
        if x<Min then Min:=x;
    end;
    Writeln(Max-Min);
end.

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

int digit(ll num) {
	int cnt = 0;
	while (num > 0) {
		cnt++;
		num /= 10;
	}

	return cnt;
}

int main() {
	ll n;
	cin >> n;
	int ans = 15;
	for (ll i = 1; i*i <=n; i++) {
		
		if (n % i == 0) {

			
			ans = min(ans, max(digit(i), digit(n / i)));
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef priority_queue<int> PQ;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	VI A(3);
	cin >> A[0] >> A[1] >> A[2];
	SORT(A);
	cout << A[0] + A[1] << endl;


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  int A,B;
  cin>>A>>B;

  int ans=max({A+B,A-B,A*B});

  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 256
//Russian Flag
#include <iostream>
#include <climits>

using namespace std;

enum COLOR {
    WHITE = 0,
    BLUE = 1,
    RED = 2
};

int main() {
    int N, M;
    cin >> N >> M;
    int Flag[N][3];
    char c;
    for(int i = 0; i < N; i++) {
        for(int c = 0; c < 3; c++) Flag[i][c] = 0;

        for(int j = 0; j < M; j++) {
            cin >> c;
            if(c == 'W') Flag[i][WHITE]++;
            if(c == 'B') Flag[i][BLUE]++;
            if(c == 'R') Flag[i][RED]++;
        }
    }

    for(int c = 0; c < 3; c++) {
        for(int i = 1; i < N; i++) {
            Flag[i][c] += Flag[i - 1][c];
        }
    }

    int minc = INT_MAX;
    for(int i = 1; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            int cost = 0;
            cost += i * M - Flag[i - 1][WHITE];
            cost += (j - i) * M - (Flag[j - 1][BLUE] - Flag[i - 1][BLUE]);
            cost += (N - j) * M - (Flag[N - 1][RED] - Flag[j - 1][RED]);
            minc = min(minc, cost);
        }
    }

    cout << minc << endl;
}


Measured memory_bytes: 3088
#include <stdio.h>
int cnt,m;
int gg[4096];
void insertionSort(int a[],int n,int g){
    int i,v,j;
    for(i=g;i<n;i++){
        v = a[i];
        j = i - g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }
}

void shellSort(int a[],int n){
    cnt=0;
    int i,x=1;
	m=0;
    for(i=0;;i++){
        gg[i]=x;
        x = 3*x+1;
        m++;
        if(x>=n){
            break;
        }
    }
    for(i=m-1;i>=0;i--){
        insertionSort(a, n, gg[i]);
    }
}
         
int main(void){
    int a[1000000];
	int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    shellSort(a,n);
    printf("%d\n",m);
    for(i=m-1;i>=0;i--){
        printf("%d",gg[i]);
        if(i!=0){
            printf(" ");
        }
    }
    printf("\n%d\n",cnt);
    for(i=0;i<n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  char s[100001];
  int l, a = 0;
  cin >> s;
  l = strlen(s);
  while(l)
    a += (s[--l] == 'g' ? 1 : -1);
  cout << a / 2 << endl;
  return 0;
}

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

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

    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    int mn = 999999;
    for (int i=0; i<N; i++) {
        if (S[i] == '(') cnt++;
        else if (S[i] == ')') cnt--;
        mn = min(mn, cnt);
    }
    for (int i=mn; i<0; i++) {
        cout << "(";
    }
    cnt += max(0, -mn);
    cout << S;
    for (int i=cnt; i>0; i--) cout << ")";
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){

int i,j;
int h=0,w=0;

while(1){

 cin >> h >> w;
 if(h==0 && w==0)  break;    //???????????????

  for(i=0;i<h;i++){
     for(j=0;j<w;j++){
         if((i+j)%2==0){       //??????????????´?????????
            cout << "#";
           }
         else{
            cout << ".";       //.???????????´?????????
           }
         }
       cout << endl;
    }
   cout << endl;              //??????
  }

return 0;

}
 

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

int main(){
  long long x; cin >> x;
  long long distance = 0;
  for(long long i = 1; distance < x; i++){
    distance += i;
    if(distance >= x){
      cout << i << endl;
      return 0;
    }
  }     
}


Measured memory_bytes: 3620
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")

Measured memory_bytes: 4724
N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
b = ["0" * (N - len(format(i, "b"))) + format(i, "b") for i in range(2 ** N)]
c = []

for i in b:
    d = []
    for j in range(M + 1):
        e = 0
        for k in range(N):
            e += a[k][j] * int(i[k])
        d.append(e)
    if min(d[1:]) >= X:
        c.append(d[0])
if c:
    print(min(c))
else:
    print(-1)

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



int main()
{
	long double a,b,c;
	cin>>a>>b>>c;
	if( c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a -b)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextInt();
		Store[] stores = new Store[n];
		for(int i = 0;i < n;i ++) {
			int price = sc.nextInt(), max = sc.nextInt();
			stores[i] = new Store(price,max);
		}
		Arrays.sort(stores);
		long drinksum = 0, pricesum = 0,diff = 0;
		for(int i = 0;i < n;i ++) {
			Store s = stores[i];
			long max = Long.valueOf(s.max);
			long price = Long.valueOf(s.price);
			drinksum += max;
			if(drinksum > m) {
				diff = drinksum - m;
				pricesum += price * (max - diff);
				break;
			}else if (drinksum == m) {
				pricesum += price * max;
				break;
			}
			pricesum += price * max;
		}
		System.out.println(pricesum);
	}
}

class Store implements Comparable<Store>{
	int price;
	int max;
	
	public Store(int price,int max){
		this.price = price;
		this.max = max;
	}

	@Override
	public int compareTo(Store s) {
		return this.price - s.price;
	}
}

Measured memory_bytes: 86500
#include<bits/stdc++.h>
using namespace std;
int xd[2]={0,1};
int yd[2]={1,0};
int hy,wx,total;
int yes[9][9];
char data;
void mygame(int x,int y);

int main(){
	cin>>hy>>wx;
	for(int i=1;i<=hy;i++){
		for(int j=1;j<=wx;j++){
			cin>>data;
			if(data=='.')
				yes[j][i]=0;
			else 
				yes[j][i]=1;
		}
	}
	if(yes[1][1]&&yes[wx][hy]){
		yes[1][1]=0;
		mygame(1,1);
		yes[1][1]=1;
	}
	if(total>0)
		cout<<"Possible";
	else
		cout<<"Impossible";
	return 0;
}
void mygame(int x,int y){
	if(x==wx&&y==hy){
		for(int i=1;i<=wx;i++){
			for(int j=1;j<=hy;j++){
				if(yes[i][j]==0)
					continue;
				else
					return;
			}
		}
		total++;
		return;
	}
	int xx,yy;
	for(int i=0;i<2;i++){
		xx=x+xd[i];
		yy=y+yd[i];
		if(xx<=wx&&yy<=hy&&yes[xx][yy]){
			yes[xx][yy]=0;
			mygame(xx,yy);
			yes[xx][yy]=1;
		}
			
	}
}



Measured memory_bytes: 256
S=input()
N=len(S)
C=[0]
for i in range(N):
  C.append(C[i]+int(S[i]))
for i in range(N):
  C.append(C[N])
B=C[N]
DP=[[0]*(B+1) for i in range(2*N+1)]
DP[0][0]=1
mod=998244353
for i in range(2*N):
  for j in range(B+1):
    if 2*min(i+1,N)-C[i+1]>=i+1-j:
      DP[i+1][j]=(DP[i+1][j]+DP[i][j])%mod
    if j<C[i+1]:
      DP[i+1][j+1]=DP[i][j]
print(DP[2*N][B])

Measured memory_bytes: 199312
import java.util.*;

public class Main {

	boolean[][] map;		// true --> 障害物
	Pos s, g;
	int h, w, ans;
	
	class Pos{
		int x;
		int y;
		Pos(int _x, int _y){
			x = _x;
			y = _y;
		}
	}
	
	// p座標がmap内にいるか返す
	boolean Inbox(Pos p){
		if(p.x<0||p.y<0||p.x>=h||p.y>=w){
			return false;
		}
		else{
			return true;
		}
	}
	
	// q座標から直接ゴール地点のg座標に到達できるか
	boolean check(Pos q){
		Pos p = new Pos(0,0);
		p.x = q.x;
		p.y = q.y;
		Pos gt = new Pos(0,0);
		gt.x = g.x;
		gt.y = g.y;
		// 判定方法は、xかy方向でp.dirとg.dirの間に障害物がないか
		if(p.y==g.y){
			if(p.x>gt.x){
				int tmp = p.x;
				p.x = gt.x;
				gt.x = tmp;
			}
			for(int i=p.x;i<=gt.x;i++){
				if(map[i][g.y]){
					return false;
				}
			}
		}
		else if(p.x==g.x){
			if(p.y>gt.y){
				int tmp = p.y;
				p.y = gt.y;
				gt.y = tmp;
			}
			for(int i=p.y;i<=gt.y;i++){
				if(map[g.x][i]){
					return false;
				}
			}
		}
		else{
			return false;
		}
		return true;
	}
	
	// q座標からdir方向に移動させ、止まった座標を返す
	Pos proceed(Pos q, int dir){
		Pos p = new Pos(0,0);
		p.x = q.x;
		p.y = q.y;
		while(true){
			if(dir==0){
				p.x++;
			}
			else if(dir==1){
				p.x--;
			}
			else if(dir==2){
				p.y++;
			}
			else if(dir==3){
				p.y--;
			}
			if(Inbox(p)){
				if(!map[p.x][p.y]){				
					continue;
				}
				else{
					if(dir==0){
						p.x--;
					}
					else if(dir==1){
						p.x++;
					}
					else if(dir==2){
						p.y--;
					}
					else if(dir==3){
						p.y++;
					}
					break;
				}
			}
			else{
				return null;
			}
		}
		return p;
	}
	
	// p座標から1つ i 方向先のマスの障害物を破壊または修復をする
	void Attack(Pos p, int i, boolean flag){
		if(i==0){
			map[p.x+1][p.y] = flag;
		}
		else if(i==1){
			map[p.x-1][p.y] = flag; 
		}
		else if(i==2){
			map[p.x][p.y+1] = flag;
		}
		else if(i==3){
			map[p.x][p.y-1] = flag;
		}
	}
	
	// バックトラック。引数は、p座標でcnt回目を動かす階層を表現
	void Search(Pos p, int cnt){
		// 現在のp座標から直接ゴール地点g座標に到達できるか
		if(check(p)){
			if(ans==-1||ans>cnt){
				ans = cnt;
			}
		}
		// 移動回数限界内で
		else if(cnt++<10){
			// 現在のp座標から4方向に移動
			for(int i=0;i<4;i++){
				// 現在のp座標からi方向に移動させ、止まったq座標を求める
				Pos q = proceed(p,i);
				// 止まった座標がmapの外に出た もしくはの方向には動かせない
				if(q==null||(p.x==q.x&&p.y==q.y)){
					continue;
				}
				// 障害物の破壊
				Attack(q,i,false);
				// q座標の再帰
				Search(q,cnt);
				// 障害物の修復
				Attack(q,i,true);
			}
		}
	}

	void run(){
		Scanner stdIn = new Scanner(System.in);
		while(true){
			w = stdIn.nextInt();
			h = stdIn.nextInt();
			if((w|h)==0){
				return;
			}
			map = new boolean[h][w];
			s = new Pos(0,0);
			g = new Pos(0,0);
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					int tmp = stdIn.nextInt();
					if(tmp==1){
						map[i][j] = true;
					}
					else if(tmp==2){
						s.x = i;
						s.y = j;
					}
					else if(tmp==3){
						g.x = i;
						g.y = j;
					}
				}
			}
			ans = -1;
			Search(s,1);
			System.out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 82

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

int a,sol=1 <<30,N,M,A[maxn][maxn],Dp[maxn][maxn][2*maxn*maxn];


int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> M;

    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            cin >> A[i][j];

    int D = 80*80 , DD = 2*D;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            cin >> a , A[i][j]-=a;

    Dp[1][1][ A[1][1] + D] =1;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            for(int k=0;k<=DD;k++)
                if( Dp[i][j][k]){

                    if(k + A[i][j+1]<=DD)
                        Dp[i][j+1][k + A[i][j+1]]=1;

                    if(k - A[i][j+1]>=0)
                        Dp[i][j+1][k - A[i][j+1]]=1;

                    if(k + A[i+1][j]<=DD)
                        Dp[i+1][j][k + A[i+1][j]]=1;

                    if(k - A[i+1][j]>=0)
                        Dp[i+1][j][k - A[i+1][j]]=1;
                }

    for(int i=0;i<=DD;i++)
         if(Dp[N][M][i])
            sol = min(sol, abs(i-D));



    cout << sol;



}


Measured memory_bytes: 349312
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int v;
  int Even[100001]={};
  int Odd[100001]={};
  int i;
  int odd1,odd2,even1,even2;
  for(i=0;i<n/2;i++){
    cin >> v;
    Odd[v]++;
    cin >> v;
    Even[v]++;
  }
  odd1 = 0;
  odd2 = 0;
  even1 = 0;
  even2 = 0;
  for(i=1;i<=100000;i++){
    if(Odd[i]>=Odd[odd1]){
      odd2 = odd1;
      odd1 = i;
    }else if(Odd[i]>=Odd[odd2]){
      odd2 = i;
    }
    if(Even[i]>=Even[even1]){
      even2 = even1;
      even1 = i;
    }else if(Even[i]>=Even[even2]){
      even2 = i;
    }
  }
  int ans = 0;
  if(odd1 != even1){
    ans = n-Odd[odd1]-Even[even1];
  }else{
    if(Odd[odd1]-Odd[odd2]<=Even[even1]-Even[even2])ans = n-Odd[odd2]-Even[even1];
    else ans = n-Odd[odd1]-Even[even2];
  }
  cout << ans;
 
}

Measured memory_bytes: 1024
n = int(input())
cuisine = list(map(int, input().split()))
saticefaction = list(map(int,input().split()))
moreSaticefaction = list(map(int, input().split()))
total = 0
beforeCuisine = -1
for i in cuisine:
  total += saticefaction[i - 1]
  if (i - 1) == beforeCuisine:
    total += moreSaticefaction[beforeCuisine - 1]
  beforeCuisine = i
print(total)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;

int main(){
    int n;
    s(n)
    int x,y;
    s(x)
    bool flag = true;
    x --;
    for(int i = 1; i < n; i ++){
        s(y)
        if(y == x){
            x = y;
        }else if(y > x){
            x = y-1;
        }else{
            flag = false;
        }
    }
    if(flag == true){
        puts("Yes");
    }else{
        puts("No");
    }


    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int MOD = 1e9 + 7;

// MODにおける階乗とその逆元、事前計算O(N * log(MOD))、参照O(1)
class FactMod {
  int MOD;
  int N;
  // x^a
  int pow(int x, int a) {
    if (a == 0) { return 1; }
    int half = pow(x, a / 2);
    return half * half % MOD * (a % 2 ? x : 1) % MOD;
  }
public:
  VI fact;
  VI fact_inv;
  FactMod(int n = 0, int mod = 1e9 + 7) : N(n), MOD(mod) {
    fact = VI(N + 1); fact[0] = 1;
    REP (i, N) {
      fact[i + 1] = fact[i] * (i + 1) % MOD;
    }
    fact_inv = VI(N + 1); fact_inv[N] = inv(fact[N]);
    for (int i = N - 1; i >= 0; i--) {
      fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
      assert(fact_inv[i] * fact[i] % MOD == 1);
    }
  }
  // xの逆元 x^(MOD - 2)
  int inv(int x) {
    return pow(x, MOD - 2);
  }
};

signed main() {
  int N; cin >> N;
  VI A(N);
  REP (i, N) { cin >> A[i]; }
  FactMod fm(N);
  VI acc(N + 1);
  REP (i, N) {
    acc[i + 1] = acc[i] + fm.inv(i + 1);
  }
  auto sum = [&](int x) {
    return (acc[x] - acc[1] + MOD) % MOD;
  };
  int ans = 0;
  REP (i, N) {
    int tmp = 0;
    (tmp += fm.fact[N]) %= MOD;
    if (i >= 1) {
      (tmp += fm.fact[N] * sum(i + 1) % MOD) %= MOD;
    }
    if (i < N - 1) {
      (tmp += fm.fact[N] * sum(N - i) % MOD) %= MOD;
    }
    (ans += tmp * A[i] % MOD) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
def resolve():
    n = int(input())
    S = tuple(input())

    c_e = S.count('E')
    c_w = 0
    ans = n

    for s in S:
        if s == 'E':
            c_e -= 1

        ans = min(ans, c_w + c_e)

        # 自分がWの場合はmax計算の後にカウントする
        if s == 'W':
            c_w += 1

    print(ans)
if __name__ == '__main__':
    resolve()

Measured memory_bytes: 5792
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a + b - (a + b) / 2;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

    if(n%2==0){
        cout << n << endl;
    }else{
        cout << n*2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
a, b, c = map(float, input().split())
s = 0.5 * a * b * math.sin(c * math.pi / 180)
l = a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(c * math.pi / 180)) ** 0.5
h = 2 * s / a
print("% f\n%f\n%f" % (s, l, h))



Measured memory_bytes: 5708
/*
Chase excellence, rating will come automatically.
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
    int n;
    cin >> n;
    int x, y;
    vector<int> dist1, dist2;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        dist1.push_back(x + y);
        dist2.push_back(x - y);
    }
    sort(dist1.begin(), dist1.end());
    sort(dist2.begin(), dist2.end());

    int ans = max(dist1[n - 1] - dist1[0], dist2[n - 1] - dist2[0]);


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

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 6676
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;


int main(){
	int ans = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++){
		int coun = 0;
		for (int j = i; j < s.length(); j++){
			if (s[j] =='A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') coun++;
			else break;
			ans = max(ans, coun);
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}


void solve()
{
    int n;
    ll m;
    cin>>n>>m;
    vl a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
        a[i]/=2;
    }
    ll lcm = a[0];
    for(int i=1;i<n;i++) {
        lcm = (lcm*a[i])/__gcd(lcm,a[i]);
        if(lcm>m) {
            cout<<0;
            return;
        }
    }

    for (int i = 0; i<n; ++i) {
        if ((lcm / a[i]) % 2 == 0) {
            cout<<0;
            return;
        }
    }
    ll ans = m/lcm;
    ans = (ans+1)/2;
    cout<<ans;

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int W,H,N;
int x[210],y[210];
double len(double Y)
{
	vector<double> v;
	for(int i=0;i<2*N;i++)v.pb(atan2(y[i]-Y,x[i]));
	sort(all(v));
	double low = tan(v[N-1])*(double)W + Y;
	double high = tan(v[N])*(double)W + Y;
	low = max(low,0.0);
	low = min(low,(double)H);
	high = max(high,0.0);
	high = min(high,(double)H);
	return high-low;
}
int main()
{
	while(1)
	{
		scanf("%d %d %d",&W,&H,&N);
		if(W==0&&H==0&&N==0)break;
		for(int i=0;i<N*2;i++)scanf("%d %d",&x[i],&y[i]);
		vector<P> v;
		for(int i=0;i<N*2;i++)v.pb(P(x[i],y[i]));
		v.pb(P(W,0));v.pb(P(W,H));
		vector<double> border;
		for(int i=0;i<v.size();i++)
		{
			for(int j=i+1;j<v.size();j++)
			{
				if(v[i].fi==v[j].fi)continue;
				double res = (double)v[i].sec-(double)v[i].fi*(double)(v[j].sec-v[i].sec)/(double)(v[j].fi-v[i].fi);
				if(0.0<=res&&res<=(double)H)border.pb(res);
			}
		}
		border.pb(0.0);border.pb(H);
		sort(all(border));
		border.erase(unique(all(border)),border.end());
		double ans = 0.0;
		for(int i=0;i<border.size()-1;i++)ans+=(len(border[i]+eps)+len(border[i+1]-eps))/2.0*(border[i+1]-border[i]);
		ans /= (double)H;
		ans /= (double)H;
		printf("%.12f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>
int main(){
    long long int a, b;
    char c;
    while(1){
        scanf("%lld %c %lld", &a, &c, &b);
        if(c == '?')break;

        switch(c){
        case '+':
            printf("%lld\n", a+b);
            break;
        case '-':
            printf("%lld\n", a-b);
            break;
        case '*':
            printf("%lld\n", a*b);
            break;
        case '/':
            printf("%lld\n", a/b);
            break;
        default:
            break;
        }
    }
return 0;
}



Measured memory_bytes: 2112
import java.util.PriorityQueue;
import java.util.Scanner;

class Activity implements Comparable<Activity> {
    int s;
    int t;

    Activity(int s, int t) {
        this.s = s;
        this.t = t;
    }

    public int compareTo(Activity act) {
        return t - act.t;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        PriorityQueue<Activity> que = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            que.add(new Activity(s, t));
        }

        int res = 0;
        int time = 0;
        while(!que.isEmpty()) {
            Activity act = que.poll();
            if(time >= act.s) continue;

            res++;
            time = act.t;
        }

        System.out.println(res);
 
        sc.close();
    }
}


Measured memory_bytes: 103000
#include <iostream>
#include <string>

using namespace std;

int n;
string str;

bool check(int mid){
    for(int i = 0; i < n - mid; i++){
        if(string(str.begin() + i + mid, str.end()).find(str.substr(i, mid)) != string::npos){
            return true;
        }
    }
    return false;
}

int main(){
    cin >> n;
    cin >> str;
    int s = 0, g = n / 2 + 1;
    while(g - s > 1){
        int mid = (s + g) / 2;
        if(check(mid)){
            s = mid;
        }else{
            g = mid;
        }
    }
    cout << s << "\n";
}

Measured memory_bytes: 384
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define forsaken
#ifdef forsaken
  #define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
  #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
	inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
int n,m;
ll a[max_n],b[max_n];
int p[max_n];
bool cmp(int x,int y)
{
    return a[x]<a[y];
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%lld%lld",a+i,b+i);
    for(int i=1;i<=n;i++)p[i]=i;
    sort(p+1,p+n+1,cmp);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        int now=p[i];
        if(m==0)break;
        if(m>=b[now])m-=b[now],ans+=b[now]*a[now];
        else ans+=m*a[now],m=0;
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
 string s,t,u;
 int a,b;
 cin>>s>>t>>a>>b>>u;
 if (u==s)
    cout<<a-1<<" "<<b;
 else
    cout<<a<<" "<<b-1;
    return 0;
}


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

using namespace std;

const long double CONST = 3.000000000;

long double N, a, ans;

int main ()
{
    cin >> N;

    a = N / CONST;

    ans = a * a * a;

    cout << setprecision(12) << fixed << (long double)ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
const int N=100005;
LL a[N];
LL Get_gcd(LL x,LL y)
{
    if (x>y) swap(x,y);
    if (!x) return y; else return Get_gcd(y%x,x);
}
int check(int n)
{
    int i,f0=0,f1=0;LL sum=0;
    for (i=1;i<=n;i++)
    {
        if (a[i]%2==0) f0++; else if (a[i]==1) f1=1;
        sum+=a[i];
    }
    if ((sum-n)%2) return 1;
    if (f1) return 0;
    if (f0==n-1) return -1; else return 0;
}
void work(int n)
{
    int i;LL gcd=0;
    for (i=1;i<=n;i++) {if (a[i]%2) a[i]--;gcd=Get_gcd(gcd,a[i]);}
    for (i=1;i<=n;i++) a[i]/=gcd;
}
int main()
{
   // freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n;
    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%lld",&a[i]);
    if (n==1) {puts("Second");return 0;}
    if (n==2) {if ((a[1]+a[2])%2) puts("First"); else puts("Second");return 0;}
    int ans=check(n),ff=0;
    while (ans<0) {work(n);ans=check(n);ff^=1;}
    ans^=ff;
    if (ans) puts("First"); else puts("Second");
    
    return 0;
}


Measured memory_bytes: 1024
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL f(vector<LL>& A,LL X){
	LL ans = 0;
	int size = A.size();
	for(int i=0;i<size;++i){
		LL temp = (A[i]-X)*(A[i]-X);
		if( A[i] >= X ){
			ans -= temp;
		}else{
			ans += temp;
		}
	}
	return ans;
}
LL calc(vector<LL>& A, LL X){
	int size = A.size();
	LL ans = 0;
	for(int i=0;i<size;++i){
		ans += (A[i]-X)*(A[i]-X);
	}
	return ans;
}

void solve(){
	int N;
	cin >> N;
	vector<LL> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	LL ans = LINF;
	for(LL i=-100;i<=100;++i){
		LL res = calc(A,i);
		ans = min(ans, res);
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <setjmp.h>
#include <string.h>
#define V 204
#define MAXE 23333
#define S 202
#define T 203
#define Min(x, y) ((x)<(y)?(x):(y))
#define Max(x, y) ((x)>(y)?(x):(y))
#define CMin(x, y) ((y)<x?(x=(y), 1):0)
#define CMax(x, y) (x<(y)?(x=(y), 1):0)
#define meow(args...) fprintf(stderr, args)
int e, x[80], y[80], lim[4][102], head[V], next[MAXE], to[MAXE], cap[MAXE], from[V], diff[V];
long long v[80], cost[MAXE], dis[V], maxcost;
jmp_buf env;
void adde(int u, int v, int w, long long c)
{
	next[e]=head[u], to[e]=v, cap[e]=w, cost[e]= c, head[u]=e++;
	next[e]=head[v], to[e]=u, cap[e]=0, cost[e]=-c, head[v]=e++;
}
void add_edge(int u, int v, int max, int min, long long c)
{
	CMax(min, 0);
	if(min>max) longjmp(env, 1);
	if(min<max) adde(u, v, max-min, c);
	diff[u]+=min;
	diff[v]-=min;
	maxcost+=min*c;
}
int ford()
{
	static int inq[V], queue[65536];
	unsigned short qhead=0, qtail=0;
	memset(dis, 192, V*sizeof(long long));
	dis[S]=0;
	inq[queue[qtail++]=S]=1;
	while(qhead!=qtail) {
		int x=queue[qhead++], i;
		inq[x]=0;
		for(i=head[x]; ~i; i=next[i])
			if(cap[i] && CMax(dis[to[i]], dis[x]+cost[i])) {
				from[to[i]]=i;
				if(!inq[to[i]]) inq[queue[qtail++]=to[i]]=1;
			}
	}
	return dis[T]>=-1e18;
}
int main()
{
	int n, m, i, j;
	long long ans=0;
	scanf("%d", &n);
	for(i=0; i<n; ++i) scanf("%d%d%lld", &x[i], &y[i], &v[i]);
	scanf("%d", &m);
	for(i=0; i<4; ++i) for(j=1; j<=100; ++j) lim[i][j]=n;
	for(i=0; i<m; ++i) {
		char d[2];
		int a, b;
		scanf("%s%d%d", d, &a, &b);
		lim[(d[0]=='R')+2*(d[0]=='U')+3*(d[0]=='D')][a]=b;
	}
	if(!setjmp(env)) {
		for(j=1; j<=lim[1][1] && j<=lim[3][100]; ++j) {
			maxcost=0;
			memset(head, -1, V*sizeof(int));
			memset(diff, 0, V*sizeof(int));
			e=0;
			for(i=1; i<=100; ++i) {
				add_edge(i-1, i, lim[2][i], j-lim[3][i-1], 0);
				add_edge(i+100, i+101, lim[0][i], j-lim[1][i+1], 0);
			}
			for(i=0; i<n; ++i) adde(y[i], x[i]+100, 1, v[i]);
			add_edge(201, 0, j, j, 0);
			for(i=0; i<202; ++i) {
				if(diff[i]>0) adde(i, T,  diff[i], 0);
				if(diff[i]<0) adde(S, i, -diff[i], 0);
			}
			while(ford()) {
				int flow=1e9;
				for(i=T; i!=S; i=to[from[i]^1]) CMin(flow, cap[from[i]]);
				maxcost+=flow*dis[T];
				for(i=T; i!=S; i=to[from[i]^1]) {
					cap[from[i]]-=flow;
					cap[from[i]^1]+=flow;
				}
			}
			for(i=head[S]; ~i; i=next[i]) if(cap[i]) longjmp(env, 1);
			CMax(ans, maxcost);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int a, b, m, c[100005], d[100005], x, y, e, mina = 100005, minb = 100005, ans;
int main(){
	scanf("%d%d%d", &a, &b, &m);
	rep(i,a){
		scanf("%d", c+i);
		mina = min(mina, c[i]);
	}
	rep(i,b){
		scanf("%d", d+i);
		minb = min(minb, d[i]);
	}
	ans = mina + minb;
	rep(i,m){
		scanf("%d%d%d", &x, &y, &e);
		ans = min(ans, c[x-1] + d[y-1] - e);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int M=50;
const int N=1010;
int x[N],y[N];
int abs(int x)
{
	return x>0?x:-x;
}
int t;
int d[M];
char ans[N][M];
int n;
void gao(int k)
{
	t++;
	d[t]=k;
	for(int i=1;i<=n;i++)
		if(abs(x[i])>abs(y[i]))
		{
			if(x[i]>0)
			{
				x[i]-=k;
				ans[i][t]='R';
			}
			else
			{
				x[i]+=k;
				ans[i][t]='L';
			}
		}
		else
		{
			if(y[i]>0)
			{
				y[i]-=k;
				ans[i][t]='U';
			}
			else
			{
				y[i]+=k;
				ans[i][t]='D';
			}
		}
}
int main()
{
	open2("d");
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=30;i>=0;i--)
		gao(1<<i);
	for(int i=1;i<=4;i++)
		gao(1);
	if(x[1]||y[1])
		gao(1);
	for(int i=1;i<=n;i++)
		if(x[i]||y[i])
		{
			printf("-1\n");
			return 0;
		}
	printf("%d\n",t);
	for(int i=1;i<=t;i++)
		printf("%d ",d[i]);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%s\n",ans[i]+1);
	return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]

A=[]
B=[]
for ab in AB:
  if ab[0]==1:
    A.append(ab[1])
  if ab[1]==N:
    B.append(ab[0])
#print(A)
#print(B)
C=list(set(A+B))
#print(C)

print("IMPOSSIBLE" if len(C)==len(A)+len(B) else "POSSIBLE")

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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<vector<pair<int, uint64_t>>> edges;
  edges.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int from, to, weight;
    cin >> from >> to >> weight;
    edges[from].emplace_back(make_pair(to, weight));
    edges[to].emplace_back(make_pair(from, weight));
  }
  int q, k;
  cin >> q >> k;

  vector<uint64_t> dist(n + 1);
  typedef pair<uint64_t, int> queue_entry;    // dist, vertex
  priority_queue<queue_entry,
                 std::vector<queue_entry>,
                 std::greater<queue_entry>> queue;
  queue.push(make_pair(0, k));  // starting point
  while (!queue.empty()) {
    auto entry = queue.top();
    queue.pop();
    uint64_t current_dist = entry.first;
    dist[entry.second] = current_dist;

    auto& edge = edges[entry.second];
    for (auto& entry : edge) {
      if (dist[entry.first] == 0 && entry.first != k) {
        queue.push(make_pair(current_dist + entry.second, entry.first));
      }
    }
  }

  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    cout << dist[x] + dist[y] << "\n";
  }
}


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

typedef long long LL;

const int N=15,M=N*N,Mod=1e9+7;

int n,m,x[M],y[M],dp[1<<N],out[N],qp[M],cnt[1<<N];

void Init() {
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;++i) scanf("%d%d",&x[i],&y[i]),x[i]--,y[i]--;
}

void Solve() {
	int ans=0;
	for (int i=0;i<m;++i) out[x[i]]|=1<<y[i];
	qp[0]=1; for (int i=1;i<=m;++i) qp[i]=qp[i-1]*2%Mod;
	int Max=1<<n; dp[0]=1;
	for (int i=0;i<Max;++i) cnt[i]=cnt[i>>1]+(i&1);
	for (int s=0;s<Max;++s) if ((s&3)==3 || (s&3)==0) {
		for (int w=s;w;w=(w-1)&s) if (dp[s^w] && ((w&3)==3 || (w&3)==0)) {
			LL sm=dp[s^w]; int t=s^w;
			for (int i=0;i<n;++i) {
				if ((1<<i)&w) sm=1ll*sm*qp[cnt[t&out[i]]]%Mod;
				else if ((1<<i)&t) sm=1ll*sm*(qp[cnt[w&out[i]]]-1)%Mod;
			}
			dp[s]=(dp[s]+sm)%Mod;
		}
		ans=(ans+dp[s])%Mod;
	} 
 	printf("%d\n",(qp[m]-dp[Max-1]+Mod)%Mod);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
ans = 1
for n in range(1, int(M ** 0.5) + 1):
    if M % n == 0 and M // N >= n:
        ans = max(ans, n)
        if M // n * N <= M:
            ans = max(ans, M // n)
print(ans)

Measured memory_bytes: 3060
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
l = []
o = []

for i in range(n):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += abs(x[i][k] - x[j][k]) ** 2
        l.append(t)

l.sort()
i = 1
while i ** 2 <= l[-1]:
    o.append(i ** 2)
    i += 1

p = 0
for i in range(len(o)):
    p += l.count(o[i])

print(p)

Measured memory_bytes: 9144
#pragma comment(linker, "/STACK:16777216")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long
#define MAXN 300005
using namespace std;
template <typename T>
inline void read(T& a)
{
	T ret(0),f(1);char ch(getchar());
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){ret = ret * 10 + (ch ^ 48);ch = getchar();}
	a = ret * f;
}
inline int Min(int x,int y){return x < y ? x : y;}
inline int Max(int x,int y){return x > y ? x : y;}
const ll mod = 998244353;
ll inv[MAXN],fact[MAXN];
inline void pre()
{
	inv[0] = inv[1] = fact[0] = fact[1] = 1;
	for(int i(2);i < MAXN;i++) inv[i] = ((mod - mod / i) * inv[mod % i] % mod);
	for(int i(2);i < MAXN;i++) inv[i] = (inv[i - 1] * inv[i]) % mod,fact[i] = (fact[i - 1] * i) % mod;
}
//一乘一取模！！
inline ll c(int m,int n){return ((fact[n] * inv[m] % mod) * inv[n - m]) % mod;}
int main()
{
	pre();
	int n;ll k,t,A,B,b,ans(0);
	read(n),read(A),read(B),read(k);
	for(ll a(0);a <= n;a++)
	{
		t = k - a * A;
		if(t < 0 || t % B) continue;
		b = t / B;
		if(b > n) continue;
		ans = (ans + (c(a,n) * c(b,n)) % mod) % mod;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
  return 0;
}

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

int main() {
	
	int K, X;
	int ans;

	scanf("%d %d", &K, &X);

	for (int i = 1; i < (K * 2); i++) {
		ans = X - K + i;
		printf("%d ", ans);
	}

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A,B,C=0,Q,W,E,R,T;
	cin>>A>>B;
	E=A;
	for(int i=0; i<(B-A+1); i++ ){
		Q=(E/10000)%10; //10000の位
		W=(E/1000)%10; //1000の位
		R=(E/10)%10; //10の位
		T=(E/1)%10; //1の位
		E++;
		if((Q==T)&&(W==R)){
			C++ ;
		}
		
	}
	cout<<C<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;


//UnionFind
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int n) : par(n, -1) { }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool merge(int x, int y) {//xの木とyの木を結合する
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {//sizeの取得
        return -par[root(x)];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    int n,m;
    cin >> n >> m;
    UnionFind u(n);
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        u.merge(x,y);
    }
    int ans = 1;
    rep(i,n-1){
        if(!u.same(0,i+1)){
            ans++;
            u.merge(0,i+1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640