akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define long long long
#define filein freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

int main() {
    //filein
    long n;
    cin>>n;
    vector<long> divofn,divofn1;
    for (long i = 2; i*i <=n ; ++i) {
        if (n%i==0){
            divofn.push_back(i);
            if(i*i!=n)
                divofn.push_back(n/i);
        }
    }
    divofn.push_back(n);


    long k=n-1;
    for (long i = 2; i*i <=k ; ++i) {
        if (k%i==0){
            divofn1.push_back(i);
            if(i*i!=k)
                divofn1.push_back(k/i);
        }
    }
    if (k!=1)divofn1.push_back(k);

    long ans=divofn1.size();
    for(auto x:divofn){
        long t=n;
        while (t%x==0)t/=x;
        if (t%x==1)ans++;
    }
    cout<<ans;



}


Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int N,A=0;
	cin >> N;
	if (N / 100 == 1) {
		A += 900;
	}else {
		A += 100;
	}
	if (N % 100/10 == 1) {
		A += 90;
	}
	else {
		A += 10;
	}
	if (N % 100%10 == 1) {
		A += 9;
	}
	else {
		A += 1;
	}
	cout << A << endl;
	return 0;
}


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;

int a,b;
int n,m;
int cntf,cnts;

char ar[101][101];
char f = '.',s = '#';

int main () {
      cin >> a >> b;

      if (a < b)
            swap(a,b),swap(f,s);

      int o = ceil(sqrt(a));

      for (int i = 1; i <= (o * 4 - 1); i ++) {
            for (int j = 1; j <= (o * 4 - 1); j ++) {
                  ar[i][j] = s;
            }
      }

      for (int i = 1; i <= (o * 4 - 1); i += 4) {
            for (int j = 2; j <= (o * 4 - 1); j += 4) {
                  if (cntf < a)
                        ar[i][j] = f,cntf ++;
            }
      }
      for (int i = 2; i <= (o * 4 - 1); i += 4) {
            for (int j = 2; j <= (o * 4 - 1); j += 4) {
                  if (cnts < b - 1) {
                        ar[i + 1][j] = f;
                        ar[i + 1][j + 1] = f;
                        ar[i + 1][j - 1] = f;
                        ar[i][j - 1] = f;
                        ar[i - 1][j - 1] = f;
                        ar[i - 1][j + 1] = f;
                        ar[i][j + 1] = f;
                        ar[i][j] = s,cnts ++;
                  }
            }
      }
      cout << (o * 4 - 1) << " " << o * 4 - 1 << endl;
      for (int i = 1; i <= (o * 4 - 1); i ++) {
            for (int j = 1; j <= (o * 4 - 1); j ++) {
                  cout << ar[i][j];
            }
            cout << endl;
      }
}


Measured memory_bytes: 256
n = int(input())
l = 0
s = []
start = [0]
end = [n]
check = 1

for i in range(20):
	print(l)
	stemp = str(input())
	s.append(stemp)
	if stemp == 'Vacant':
		break
	elif i!=0:
		if check == 1:
			if s[i-1] == s[i]:
				start[0] = l
				if ((end[0]-start[0])//2)%2==0:
					l = start[0]+(end[0]-start[0])//2
				else:
					l = start[0]+(end[0]-start[0])//2+1
				
			else:
				end[0] = l
				if ((end[0]-start[0])//2)%2==0:
					l = start[0]+(end[0]-start[0])//2
				else:
					l = start[0]+(end[0]-start[0])//2+1
				check = check*-1

		elif check == -1:
			if s[i-1] == s[i]:
				end[0] = l
				if ((end[0]-start[0])//2)%2==0:
					l = start[0]+(end[0]-start[0])//2
				else:
					if abs((end[0]-start[0])) == 2:
						l = start[0]+(end[0]-start[0])//2
					else:
						l = start[0]+(end[0]-start[0])//2-1
				
			else:
				start[0] = l
				if ((end[0]-start[0])//2)%2==0:
					l = start[0]+(end[0]-start[0])//2
				else:
					l = start[0]+(end[0]-start[0])//2+1
				check = check*-1
	else:
		if (n//2)%2==0:
			l = l+n//2
		else:
			l = l+(n//2)+1

Measured memory_bytes: 3788
from collections import deque
n = int(input())
L = deque()
for i in range(n):
    command = input()
    if command == 'deleteFirst':
        L.popleft()
    elif command == 'deleteLast':
        L.pop()
    else:
        c, x = command.split()
        if c == 'insert':
            L.appendleft(x)
        elif c == 'delete':
            try:
                L.remove(x)
            except ValueError:
                pass
print(' '.join(L))


Measured memory_bytes: 69740
cmdPrint :: String -> Int -> Int -> IO ()
cmdPrint str a b =
  putStrLn $ take (b-a+1) $ drop a str

cmdReverse :: String -> Int -> Int -> String
cmdReverse str a b =
  let h = take a str
      m = drop a $ take (b+1) str
      f = drop (b+1) str
  in
    h ++ (reverse m) ++ f

cmdReplace :: String -> Int -> Int -> String -> String
cmdReplace str a b p =
  let h = take a str
      f = drop (b+1) str
  in
    h ++ p ++ f


play :: String -> [[String]] -> IO ()
play _ [] = return ()
play str (("print":a:b:_):cmds) = do
  let a' = read a :: Int
      b' = read b :: Int
  cmdPrint str a' b'
  play str cmds

play str (("reverse":a:b:_):cmds) = do
  let a' = read a :: Int
      b' = read b :: Int
      s  = cmdReverse str a' b'
  play s cmds

play str (("replace":a:b:p:_):cmds) = do
  let a' = read a :: Int
      b' = read b :: Int
      s  = cmdReplace str a' b' p
  play s cmds

main = do
  l <- getLine
  c <- getContents
  let i = drop 1 $ map words $ lines c
  play l i

Measured memory_bytes: 5444
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		int n=in.nextInt();
		int [] d=new int [n];
		for(int i=0;i<n;i++)
		{
			d[i]=in.nextInt();
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				ans=ans+d[i]*d[j];
			}
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 23252
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i], y[i]  = map(int ,input().split())
    
ans = 0
for i in range(n):
  for j in range(n):
    if i != j:
      ans += ((x[i] - x[j])**2 +  (y[i] - y[j])**2 )**0.5

print(ans / n)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
 
constexpr uint64_t MOD = 1e9 + 7;
 
int main() {
  std::string S;
  std::cin >> S;
  const auto len = S.size();
  
  std::vector<std::vector<uint64_t>> dp(1e5 + 5, std::vector<uint64_t>(13));
  dp[0][0] = 1;
  
  for(int i = 0; i < len; ++i) {
    for(int j = 0; j < 13; ++j) {
      if(S[i] == '?') {
        for(int k = 0; k < 10; ++k) {
          (dp[i+1][(j*10+k) % 13] += dp[i][j]) %= MOD;
        }
      } else {
        int val = S[i] - '0';
        (dp[i+1][(j*10+val) % 13] += dp[i][j]) %= MOD;
      }
    }
  }
  std::cout << dp[len][5] << std::endl;
  return 0;
}

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

int main(void){
    
    int H,W;
    
    cin >> H >> W;
    
    string S[H];
    
    for(int i = 0; i < H; i++)cin >> S[i];
    
    int cont = 0;
    for(int i = 0; i < H; i++){
        
        
        for(int j = 0; j < W; j++){
        
            cont = 0;
            if(S[i][j] == '#'){
                
                if(i!=W-1){
                    if(S[i+1][j]=='#')cont++;       
                }
                if(i!=0){
                    if(S[i-1][j]=='#')cont++;       
                }
                if(j!=H-1){
                    if(S[i][j+1]=='#')cont++;       
                }
                if(j!=0){
                    if(S[i][j-1]=='#')cont++;       
                }
                
                if(cont == 0){
                    cout << "No" << endl;
                    return 0;
                }
                
                
            }

        }  
        
        
    }
    
    cout << "Yes" << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

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

int main() {
    int n;
    cin>>n;
    vector<int>b(n-1);
    for(int i=0;i<n-1;i++){
        cin>>b.at(i);
    }
    vector<int>a(n);
    a.at(n-1)=b.at(n-2);
    for(int i=n-2;i>0;i--){
        a.at(i)=min(b.at(i),b.at(i-1));
    }
    a.at(0)=b.at(0);
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=a.at(i);
    }
    // for(int i=0;i<n;i++){
    //     cout<<a.at(i)<<" ";
    // }
    // cout<<endl;
    cout<<ans<<endl;






    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    from collections import Counter, defaultdict
    ri = defaultdict(int, dict(Counter(S)))
    le = defaultdict(int, {'W': 0, 'E': 0})
    pre = ''
    ans = 1 << 60
    for s in S:
        le[pre] += 1
        ri[s] -= 1
        ans = min(ans, le['W'] + ri['E'])
        pre = s
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41696
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    string week[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string S;
    int count = 1;
    cin >> S;

    for(int i = 6; i >= 0; i--){
        if(week[i] == S){
            break;
        }
        else{
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

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

typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
#define log sdfdsfdsf

const ll DIM = 2E5+7;
const ll MOD = 1e9+123;

const ll INF = 1E17;
const ld eps = 0.00000000000001;
const ld PI = 3.14159265358979323846;
int getInt(int a = 0, int b = INT_MAX){
    static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution <int> (a, b)(rng);
}
typedef unsigned long long ull;
typedef pair<ull,ll> upp;
const ll base = 31;
ll cnt[30];
ull gi(char ch){
    return ch-'a'+1;
}
string A[DIM];
map<upp,map<ll,ll> > M;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;

    forn(i,n){
        cin>>A[i];

    }
    ll res = 0;
    forn(j,n){
        string s;
        s = A[j];
        memset(cnt,0,sizeof(cnt));
        for(char to:s){
            cnt[gi(to)]++;
        }
        upp h = {0,0};
        for(ll i = ll(s.length())-1;i>=1;--i){
            h.fi = (h.fi*base+gi(s[i]));
            h.sc = (h.sc*base+gi(s[i]))%MOD;
        }

        M[h][gi(s[0])]++;
    }

    forn(j,n){
        string s = A[j];
        memset(cnt,0,sizeof(cnt));
        upp h = {0,0};
        for(char to:s)cnt[gi(to)]++;
        for(ll i = ll(s.length())-1;i>=0;--i){
            for(pp to:M[h])
                if (cnt[to.fi]!=0)res+=to.sc;
            --cnt[gi(s[i])];

            h.fi = h.fi*base+gi(s[i]);
            h.sc = (h.sc*base+gi(s[i]))%MOD;

        }


    }
    res-=n;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 119980
n = int(input())
a = list(map(int, input().split()))

odd_index = []
even_index = []
for i in range(n):
    if (i + 1) % 2 == 1:
        odd_index.append(a[i])
    else:
        even_index.append(a[i])

if n % 2 == 1:
    res = odd_index[::-1] + even_index
else:
    res = even_index[::-1] + odd_index

print(*res)


Measured memory_bytes: 30744
#include <iostream>
#include <vector>

using ll = long long int;

using namespace std;


ll N, M;
ll N2, M2;


int main() {
  cin >> N >> M;
  N2 = (1 << N) - 1;
  M2 = (1 << M) - 1;

  ll tz[114514] = { 0 };

  for (ll i = 1; i < 114514; i++) {
    ll count = 0;
    ll x = i;
    while ((x & 1) == 0) {
      x = x >> 1;
      count++;
    }

    tz[i] = count;
  }


  for (ll i = 1; i <= N2; i++) {
    for (ll j = 1; j <= M2; j++) {
      if (tz[i] == tz[j]) {
        cout << '1';
      } else {
        cout << '0';
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 200005

int a[100];
int main(){
	string str;
	cin >> str;
	char s = str[0], e = str[3];
	if(s == str[1] && s == str[2])cout << "Yes" << endl;
	else if(e == str[1] && e == str[2])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int const N = 100000;
int n, x[N], y[N], z[N], fn[N << 1 | 1];

inline void ad(int i) { i += N; while (i <= N << 1)++fn[i], i += i & -i; }
inline int gt(int i) { i += N; int an = 0; while (i)an += fn[i], i ^= i & -i; return an; }
inline void reset() { f(i, 0, N << 1 | 1)fn[i] = 0; }

bool ok(int w){
	f(i, 0, n)if (x[i] >= w)z[i] = 1; else z[i] = -1;
	reset();
	ll mn = 0, mx = 0;
	ad(0);
	int cs = 0;
	f(i, 0, n){
		cs += z[i];
		int t = gt(cs);
		mx += t;
		mn += i + 1 - t;
		ad(cs);
	}
	return mx >= mn;
}

int main(){
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", x + i);
	f(i, 0, n)y[i] = x[i];
	sort(y, y + n);
	int l = 0, r = n - 1;
	while (r > l){
		int m = l + r + 1 >> 1;
		if (ok(y[m]))l = m;
		else r = m - 1;
	}
	printf("%d\n", y[l]);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll a,b,f=0;
  ll w,x,y,z;
  cin>>a>>b;
  for(ll i=a;i<=b;i++){
    w = i % 10;
    x = i / 10000 % 10;
    y = i / 10 % 10;
    z = i / 1000 % 10;
    if(w == x && y == z){
      f++;
    }
  }
  cout<<f<<"\n";
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B, C = [list(map(int, input().split())) for i in range(3)]

S = 0

for i in range(N):
    S += B[i]
    try:
        if A[i+1] == A[i]+1:
            S += C[A[i]-1]
    except IndexError as e:
        continue

print(S)

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    string A, B;    cin >> A >> B;
    int a = A.length(), b = B.length();
    if(a > b)   print("GREATER");
    else if(a < b)  print("LESS");
    else{
        for(int i=0; i<a; i++){
            if(A[i] > B[i]){print("GREATER");return 0;}
            else if(A[i] < B[i]){print("LESS");return 0;}
            else if(i == a-1)   print("EQUAL");
        }
    }
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String args[]) {
     
    Scanner sc = new Scanner(System.in);
 	
      int a,b,c;
      int sum = 0;
      
      a = sc.nextInt();
      b = sc.nextInt();
      c = sc.nextInt();
      
      sc.close();
      
      sum = a + b + c;
      
      if(sum < 22) {
        System.out.println("win");
      } else if(sum >= 22) {
        System.out.println("bust");
      }
      
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define go(i,a,b) for(int i=(a);i<=(b);++(i))
#define com(i,a,b) for(int i=(a);i>=(b);--(i))
#define mem(a,b) memset((a),(b),sizeof(a))
#define inf 0x3f3f3f3f
#define fin freopen("input.txt","r",stdin)
#define fout freopen("output.txt","w",stdout)
typedef unsigned long long ull;
int a[10];
ull f[3010];

void read(int &x){
    int f=1;char s=getchar();x=0;
    while(!isdigit(s)){
    	if(s=='-') f=-1;s=getchar();
    }
    while(isdigit(s)){
   		x=(x<<3)+(x<<1)+s-'0';s=getchar();
    }
    x*=f;
}//读入优化

int main()
{
	//fin;
	int n;
	go(i,1,3) read(a[i]);
	read(n);
	f[0]=1;
	go(i,1,3)
	go(j,a[i],n)
	f[j]+=f[j-a[i]];
	printf("%lld",f[n]);
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32  n;
i64 a[300000];
i64 t[100001][2];

i32 main()
{
	cin >> n;
	times(3*n, i) {
		cin >> a[i];
	}

	{
		multiset<i64> m;
		i64 acc = 0, sumv = 0;
		times(n, i) {
			m.insert(a[i]);
			sumv += a[i];
		}
		upto(n, 2 * n, c) {
			t[c-n][0] = sumv - acc;
			m.insert(a[c]);
			acc += *m.begin();
			m.erase(m.begin());
			sumv += a[c];
		}
	}
	{
		multiset<i64> m;
		i64 acc = 0, sumv = 0;
		range(2*n, 3*n, i) {
			m.insert(a[i]);
			sumv += a[i];
		}
		downto(2*n, n, c) {
			t[c-n][1] = sumv - acc;
			m.insert(a[c-1]);
			acc += *--m.end();
			m.erase(--m.end());
			sumv += a[c-1];
		}
	}

	i64 ans = LLONG_MIN;
	times(n+1, c) {
		ans = max(ans, t[c][0] - t[c][1]);
	}

	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  const Int INF = 1e15;
  vector<Int> s(n+1,INF);
  vector<Int> ls(n);
  Int len=0;
  for(Int i=0;i<n;i++){
    ls[i]=lower_bound(s.begin(),s.end(),a[i])-s.begin();
    s[ls[i]]=a[i];
    chmax(len,ls[i]+1);
    //cout<<i<<":"<<ls[i]<<endl;
  }
  const Int MAX = 1e5+100;
  vector<map<Int, Int> > dp(MAX);
  for(Int i=0;i<MAX;i++){
    dp[i][-INF]=-INF;
    dp[i][+INF]=+INF;
  }
  dp[0][0]=0;
  for(Int i=0;i<n;i++){
    Int res=(--dp[ls[i]].lower_bound(a[i]))->second;
    res+=a[i];
    
    auto &ms=dp[ls[i]+1];
    chmax(ms[a[i]],res);
    
    {
      auto it=ms.find(a[i]);
      auto ushi=it;ushi--;
      if(ushi->second>=it->second){
        ms.erase(it);
        continue;
      }
    }
    while(1){
      auto it=ms.find(a[i]);
      auto uku=it;uku++;
      if(it->second>=uku->second){
        ms.erase(uku);
        continue;
      }
      break;
    }
  }  
  cout<<((----dp[len].end())->second)<<endl;
  return 0;
}



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

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

int main()
{
    int s;
    cin >> s;
    vector<int> v(1000010, 0);
    int i = 1;
    while(true) {
        if (v[s] > 0) break;
        v[s]++;
        s = func(s);
        i++;
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 4096
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
n = int(input())
p = list(map(int,input().split()))


ans = 0

for i in range(n-2):
    if p[i] < p[i+1] and p[i+2] > p[i+1]:
        ans += 1
    elif p[i] > p[i+1] and p[i+2] < p[i+1]:
        ans += 1
        
print(ans)

Measured memory_bytes: 21424
// One Clue
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>

using namespace std;

int main()
{
    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i < X + K; i++) {
        cout << i << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int main(){
  int S, W;
  scanf("%d", &S);
  scanf("%d", &W);
  if (W>=S){
    printf("unsafe\n");
  } else {
    printf("safe\n");
  }
  return 0;
}


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

int main()
{
	string S;
	cin >> S;

	sort(S.begin(), S.end());

	if (S[0] == S[1] && S[2] == S[3] && S[1] != S[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






Measured memory_bytes: 3524
CMD=0
VAL=1

class Node
  attr_accessor :value,:left,:right
  def initialize (value)
    @value = value
    @left = nil
    @right = nil
  end

  def insert (value)
    if value < @value
      if @left.nil?
        @left = Node.new(value)
      else
        @left.insert(value)
      end
    else
      if @right.nil?
        @right = Node.new(value)
      else
        @right.insert(value)
      end
    end
  end

  def find(value)
    #p "@value:#{@value}"
    if value==@value
      print "yes\n"
    elsif value < @value
      #p "left:#{@left}"
      if @left.nil?
        print "no\n"
      else
        @left.find(value)
      end
    else
      #p "right:#{@right}"
      if @right.nil?
        print "no\n"
      else
        @right.find(value)
      end
    end
  end
  
  def print_inorder
    @left.print_inorder unless @left.nil?
    print " #{value}"
    @right.print_inorder unless @right.nil?
  end
  
  def print_preorder
    print " #{value}"
    @left.print_preorder unless @left.nil?
    @right.print_preorder unless @right.nil?
  end
end

num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }

root=nil
inputs.each do |input|
  if input[CMD] == 'insert'
    if root.nil?
      root = Node.new(input[VAL].to_i)
    else
      root.insert(input[VAL].to_i)
    end
  elsif input[CMD] == 'find'
    root.find(input[VAL].to_i)
  else
    root.print_inorder unless root.nil?
    print "\n"
    root.print_preorder unless root.nil?
    print "\n"
  end
end

Measured memory_bytes: 192332
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int qsz=1e6;int qLen,qHead,Q[1000000];
static inline void PUSH(int n){Q[(qHead+qLen)%qsz]=n;qLen++;}
static inline int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%qsz;return q;}
int H,W,grid[1000][1000];
const int dx[24]={0,1,0,-1,0,0,1,1,1,1,-1,-1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2};
const int dy[24]={1,0,-1,0,2,-2,1,2,-1,-2,1,2,-1,-2,0,1,2,-1,-2,0,1,2,-1,-2};
static inline int f(int x,int y){return W*x+y;}
static inline void DFS(int x,int y)
{
  if(x>=0&&x<H&&y>=0&&y<W&&!grid[x][y])
  {
    grid[x][y]=1;PUSH(f(x,y));rep(i,4){DFS(x+dx[i],y+dy[i]);}
  }
}
int main(void)
{
  int C[2],D[2],step=0;H=IN(),W=IN(),C[0]=IN()-1,C[1]=IN()-1,D[0]=IN()-1,D[1]=IN()-1;
  rep(i,H){char str[1001];if(!scanf("%s",str)){return -1;}rep(j,W){grid[i][j]=(str[j]=='#');}}
  PUSH(f(C[0],C[1]));
  while(qLen)
  {
    int size=qLen;
    while(size--){int x=POP();DFS(x/W,x%W);}
    size=qLen;
    while(size--)
    {
      int z=POP(),x=z/W,y=z%W;
      if(x==D[0]&&y==D[1]){return OUT(step),0;}
      rep(i,20)
      {
        int nx=x+dx[4+i],ny=y+dy[4+i];
        if(nx>=0&&nx<H&&ny>=0&&ny<W&&!grid[nx][ny]){PUSH(f(nx,ny));}
      }
    }
    step++;
  }
  return puts("-1"),0;
}

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r;
  int g;
  cin >> r;
  cin >> g;
  
  if(r > 4500 || g > 4500){
 // invalid rating
  }
  
  cout << 2 * g - r << endl; 
}

Measured memory_bytes: 3528
#include <iostream>
typedef long long ll;
using namespace std;

int n;
ll T;
ll t[200010];

void solve() {
  ll sum = 0;
  t[n] = 1e9 + T;
  for (int i=0;i<n;i++) {
    sum += min(t[i+1] - t[i], T);
  }
  cout << sum << endl;
}

int main() {
  cin >> n >> T;
  for (int i=0;i<n;i++) {
    cin >> t[i];
  }
  solve();
}


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

typedef long long LL;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    LL ans = 1000, num = 0, dq = 1e9;
    while (n--)
    {
        LL ls;
        cin >> ls;
        if (ls <= dq)
        {
            num = ans / ls;
            dq = ls;
        }
        else
        {
            ans += num * (ls - dq);
            dq = ls;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> H(N);
  rep(i,0,N) cin >> H[i];
  sort(all(H));
  reverse(all(H));
  i64 ans = 0;
  for(int i = K; i < N; i++) {
    ans += H[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        map<ll,ll> mp;
        for(ll i=1;i<=100;i++){
            for(ll j=1;j<=100;j++){
                for(ll k=1;k<=100;k++){
                    mp[i*i+k*k+j*j+i*j+j*k+k*i]++;
                }
            }
        }
        ll n;cin>>n;
        for(ll i=1;i<=n;i++)
        cout<<mp[i]<<endl;


}


Measured memory_bytes: 6100
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using  namespace std;
int main(int argc, char const *argv[])
{
	int n, m;
	priority_queue<int> pq;
	while(cin >> n >> m){
		while(!pq.empty()) pq.pop();
		for(int i = 0; i < n; i++){
			int temp; cin >> temp;
			pq.push(temp);
		}
		for(int i = 0; i < m; i++){
			int top = pq.top(); pq.pop();
			pq.push(top/2);
		}
		long long ans = 0;
		while(!pq.empty()){
			ans += pq.top(); pq.pop();
		}
		printf("%lld\n", ans);
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s,t;
    cin>>s>>t;
    bool ans = true;
    vector<int> s2t(26,-1),t2s(26,-1);
    REP(i,s.size()) {
        int ss = (int)(s[i] - 'a');
        int tt = (int)(t[i] - 'a');
        if (s2t[ss] == -1) {
            s2t[ss] = tt;
        }
        else {
            if (s2t[ss] != tt) ans = false;
        }
        if (t2s[tt] == -1) {
            t2s[tt] = ss;
        }
        else {
            if (t2s[tt] != ss) ans = false;
        }
    }
    if (ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<int>L(N);
  int sum=0;
  for(int i=0; i<N; i++){
   cin>>L[i];
   sum+=L[i];}
  
  int maxL=*max_element(L.begin(), L.end());
  if(sum-maxL>maxL){cout<<"Yes";}
  else{cout<<"No";}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int sum;
int main()
{
	char a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(a==d)
	sum++;
	if(b==e)
	sum++;
	if(c==f)
	sum++;
	cout<<sum<<endl;
	return 0;
}

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

int main(){
  vector<int> n(3);
  cin >> n.at(0) >> n.at(1) >> n.at(2);
  sort(n.begin(), n.end());
  //if(n%2==1)cout << n*2 << endl;
  //else cout << n << endl;
  cout << n.at(2)-n.at(0) << endl;
  return 0;
}

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


int main(void){
    int N;
    scanf("%d",&N);
    int t[N],x[N],y[N];
    for(int i=0;i<N;i++){
        scanf("%d %d %d",&t[i],&x[i],&y[i]);
    }
    if((t[0]-(x[0]+y[0]))%2 != 0 || t[0]-(x[0]+y[0])<0){
        printf("No");
        return 0;
    }
 //   printf("OK");
    int T=0,X=0,Y=0;
    for(int i=1;i<N;i++){
        T = abs(t[i]-t[i-1]);
        X = abs(x[i]-x[i-1]);
        Y = abs(y[i]-y[i-1]);
//        printf("T=%d,X=%d,Y=%d",T,X,Y);
        if((T-(X+Y))%2 !=0 || T-(X+Y)<0){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]

    return (s, )


def solve(s, ):

    win = s.count("o")
    lose = s.count("x")
    
    result = "NO"
    if 15 - lose >= 8:
        result = "YES"

    return result

def main():
    # 出力

    print("%s" % solve(*parse_input()))


if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
li1 = list(map(int,input().split()))
cnt=0
j=0
drink=[]
for i in range(li1[0]):
    drink.append(list(map(int,input().split())))
drink=sorted(drink,key=lambda x:x[0])
while li1[1]>0:
    if li1[1]>drink[j][1]:
        li1[1]-=drink[j][1]
        cnt+=drink[j][0]*drink[j][1]
    else:
        cnt+=drink[j][0]*li1[1]
        li1[1]=0
    j+=1
print(cnt)

Measured memory_bytes: 29792
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int x,y;cin>>x>>y;
    if(y%2!=0){
        cout<<"No"<<endl;
    }
    else if(4*x<y){
        cout<<"No"<<endl;
    }
    else if(y<2*x){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
    //-------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


















































Measured memory_bytes: 3608
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
#define id(i) (((i)+1)/2)
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,p[N],degree[N],cnt[N],t,stk[N<<1],top,tot;
struct data{int to,nxt;
}edge[N<<1];
bool flag[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void dfs(int k,int t)
{
	if (k==t) {tot++;return;}
	flag[k]=1;
	for (int i=p[k];i;i=edge[i].nxt)
	if (!flag[edge[i].to]||edge[i].to==t)
	{
		dfs(edge[i].to,t);
	}
}
signed main()
{
	n=read(),m=read();
	for (int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		degree[x]++,degree[y]++;
		addedge(x,y),addedge(y,x);
	}
	for (int i=1;i<=n;i++) if (degree[i]&1) {cout<<"No";return 0;}
	for (int i=1;i<=n;i++) if (degree[i]>=6) {cout<<"Yes";return 0;}
	int cnt=0;
	for (int i=1;i<=n;i++) if (degree[i]>=4) {cnt++;}
	if (cnt>=3) {cout<<"Yes";return 0;}
	if (cnt<=1) {cout<<"No";return 0;}
	int x=0,y=0;for (int i=1;i<=n;i++) if (degree[i]>=4) if (x) y=i;else x=i;
	dfs(x,y);
	if (tot==2) cout<<"Yes";else cout<<"No";
	/*dfs(1);
	reverse(stk+1,stk+top+1);
	//for (int i=1;i<=top;i++) cout<<stk[i]<<' ';cout<<endl;
	for (int i=1;i<top;i++) cnt[stk[i]]++;
	for (int i=1;i<=n;i++) if (cnt[i]>=3) {cout<<"Yes";return 0;}
	if (cnt[1]==2)
	{
		int p=0;
		for (int i=2;i<top;i++) if (stk[i]==1) {p=i;break;}
		memset(cnt,0,sizeof(cnt));
		for (int i=2;i<p;i++)
		{
			cnt[stk[i]]++;
			if (cnt[stk[i]]==2) {cout<<"Yes";return 0;}
		}
		memset(cnt,0,sizeof(cnt));
		for (int i=p+1;i<top;i++)
		{
			cnt[stk[i]]++;
			if (cnt[stk[i]]==2) {cout<<"Yes";return 0;}
		}
	}
	memset(cnt,0,sizeof(cnt));
	int p=top;
	for (int i=2;i<top;i++)
	{
		cnt[stk[i]]++;
		if (cnt[stk[i]]==2) {p=i;break;}
	}
	memset(cnt,0,sizeof(cnt));
	for (int i=top-1;i>=2;i--)
	{
		cnt[stk[i]]++;
		if (cnt[stk[i]]==2) 
		{
			if (i>p) {cout<<"Yes";return 0;}
			break;
		}
	}
	cout<<"No";*/
	return 0;
	//NOTICE LONG LONG!!!!!
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int sumfront[105],sumbeh[105];
int n,a[105];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n; ++ i)
    {
        scanf("%d",&a[i]);
        sumfront[i] = sumfront[i - 1] + a[i];
    }
    for(int i = 1;i <= n; ++ i)
        scanf("%d",&a[i]);
    for(int i = n;i >= 1; -- i)
        sumbeh[i] = sumbeh[i + 1] + a[i];
    int maxn = 0;
    for(int i = 1;i <= n; ++ i)
        maxn = max(maxn,sumfront[i] + sumbeh[i]);
    printf("%d\n",maxn);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
long long a[205];
int main()
{
    long long n, m;
    int k;
    while(scanf("%lld%lld%d",&n,&m,&k) != EOF)
    {
       map<long long,bool>mm;
        int cnt = 0;

        for(int i = n; i <= n + k - 1 && i <= m; i ++){
            //cout<<i<<endl;
            if(!mm[i]){
            a[++ cnt] = i;
            mm[i] = 1;
            }
        }
        for(int i = m - k + 1; i <= m && i >= n; i ++){
            //cout<<i<<endl;
            if(!mm[i]){
            a[++ cnt] = i;
            mm[i] = 1;
            }
        }
        sort(a + 1, a + cnt + 1);
        for(int i = 1; i <= cnt; i ++)
        {
            cout<<a[i]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
char a,b,c;
int main(){
	cin>>a>>b>>c;
	if(a=='7'||b=='7'||c=='7')
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>

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

int main() {
	int a, b, m; cin >> a >> b >> m;
	vector<int> A(a);
	int mia = 1001001;
	rep(i, a) {
		cin >> A[i];
		mia = min(A[i], mia);
	}
	vector<int> B(b);
	int  mib = 1001001;
	rep(i, b) {
		cin >> B[i];
		mib = min(B[i], mib);
	}
	vector<vector<int>> M(m, vector<int>(3));
	rep(i, m) {
		rep(j, 3) {
			cin >> M[i][j];
		}
	}

	int v = 0;
	int ans = mia + mib;
	rep(i, m) {
		v = A[M[i][0]-1] + B[M[i][1]-1] - M[i][2];
		ans = min(v, ans);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int k;
int c[10000];
int main(){
  int i;
  int sum;
  while(scanf("%d",&k), k != 0){
    for(i = 0; i < k*(k-1)/2; i++){
      scanf("%d",&c[i]);
    }
    sum = 0;
    for(i = 0; i < k*(k-1)/2; i++){
      sum += c[i];
    }
    sum = sum/(k-1);
    
    printf("%d\n",sum);
  }
  return 0;   
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main(){
  int N;
  cin >> N;
  vector<int> u(N - 1), v(N - 1), w(N - 1);
  REP(i, N - 1) {
    cin >> u[i] >> v[i] >> w[i];
    --u[i]; --v[i];
    w[i] = w[i] % 2;
  }
  Graph g(N);
  REP(i, N - 1){
    g[u[i]].push_back(Edge(u[i], v[i], w[i]));
    g[v[i]].push_back(Edge(v[i], u[i], w[i]));
  }

  vector<int> color(N, -1);
  queue<Edge> que;
  que.push(Edge(-1, 0, 0));

  while(!que.empty()) {
    Edge e = que.front(); que.pop();
    if(color[e.dst] != -1) continue;
    if(e.src == -1){
      color[e.dst] = 0;
    }else if(e.weight == 1){
      color[e.dst] = 1 - color[e.src];
    }else if(e.weight == 0 ) {
      color[e.dst] = color[e.src];
    }
    for(Edge f: g[e.dst]) {
      if(f.dst == e.src) continue;
      que.push(f);
    }
  }

  REP(i, N) cout << color[i] << endl;
  return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long x;
    cin >> x;
    long long yen = 100;
    int years = 0;
    while (yen < x) {
        yen += yen/100;
        years++;
    }
    cout << years;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    cout << a[n - 1] - a[0];
}


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

before = []
answer = 'Yes'

for i in range(N):
    s = input()
    if s in before:
        answer = 'No'
    if len(before) > 0:
        if before[-1][-1] != s[0]:
            answer = 'No'

    before.append(s)

print(answer)



Measured memory_bytes: 2940
from itertools import accumulate

N = int(input())
a = list(accumulate([int(i) for i in input().split()]))
l, r = 0, 1
ans = float("inf")
for i in range(1, N-2):
    while abs(a[i] - 2 * a[l+1]) < abs(a[i] - 2 * a[l]) and l < i - 1: l += 1
    while abs(a[-1] - 2 * a[r+1] + a[i]) < abs(a[-1] - 2 * a[r] + a[i]) and r < N - 2: r += 1
    t = [a[l], a[i] - a[l], a[r] - a[i], a[-1] - a[r]]
    ans = min(ans, max(t) - min(t))
print(ans)

Measured memory_bytes: 24180
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	lli vis[1000005];
	lli cand[1000005];
	void solve(){
		lli N,i,j,p,q,res=0,maxi=0;
		cin>>N;
		set <lli> aux;
		for(i=1;i<=N;i++){
			cin>>arr[i];
			aux.insert(arr[i]);
			cand[arr[i]]+=1;
			vis[arr[i]]=1;
			maxi=max(maxi,arr[i]);
		}
		set <lli>::iterator it;
		for(it=aux.begin();it!=aux.end();it++){
			p=*it;
			if(cand[p]>1)vis[p]=0;
			for(j=p+p;j<=maxi;j+=p){
				vis[j]=0;
				cand[j]=0;
			}
		}
		for(i=1;i<=maxi;i++){
			if(vis[i]){
				//cout<<i<<" "<<cand[i]<<"\n";
				res+=cand[i];
			}
		}
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
	
}


Measured memory_bytes: 28760
//use proconio::{input, fastout};
use proconio::input;
use std::collections::HashMap;

//#[fastout]
fn main() {
    input! {
        n: usize, k: u64,
        a: [usize; n],
    }

    if a[0] == 1 {
        println!("{}", 1);
        return;
    }

    let mut h = HashMap::new();
    let mut count = 0;
    let mut p = 1;
    while count < k {
        h.insert(p, count);
        count += 1;
        let next = a[p - 1];
        if let Some(s) = h.get(&next) {
            let loops = count - s;
            let k = (k - s) % loops + s;
            let (p, _) = h.iter().find(|(_, v)| **v == k).unwrap();
            println!("{}", p);
            return;
        }
        p = next;
    }
    println!("{}", p);
}


Measured memory_bytes: 11548
#include<bits/stdc++.h>
using namespace std;
int n;
double m;
int main(){
    cin>>n;
    for(int i=n;i>=0;i--){
        m=sqrt(i);
        if(int(sqrt(i))==m){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(void){
	int n;
	while(cin >> n,n){
		map<int,int> name;
		long long int list[4001]={0};
		long long int a,b,c,j=0;
		for(int i=0;i<n ;i++){
			cin >> a >> b >> c;
			name[j]=a,j++;
			if(list[a]<1000000)
				list[a]+=b*c;
		}
		bool check=true;
		for(int i=0;i<4000;i++)
			if(list[name[i]]>=1000000)
				cout << (name[i]) << endl,check=false,list[name[i]]=0;
		if(check)
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1428
#include<cstdio>
#include<vector>
using namespace std;
const int MAX = 200010;
vector<int> v[MAX];
bool vis[MAX];
int val[MAX];
int ans[MAX];
 
void dfs(int x, int s = 0) {
    s += val[x];
    ans[x] = s;
    vis[x] = true;
    for(auto e: v[x]) {
        if(vis[e]) continue;
        dfs(e, s);
    }
}
 
int main () {
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 0 ; i < n-1 ; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    while(q--) {
        int x, y;
        scanf("%d %d", &x, &y);
        val[x] += y;
    }
    dfs(1);
    for(int i = 1 ; i <= n ; i++) {
        printf("%d ", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 21120
a = list(map(int,input().split()))

a.sort()

count = 0

#最大値との差
n = a[2]-a[1]
m = a[2]-a[0]

#最大値との差が両方とも奇数の場合、'２つ選んで１つずつ増やす操作'が１回必要
if (n % 2 == 1) and (m % 2 == 1) :
  count += 1

#最大値との差が片方だけ奇数の場合、'２つ選んで１つずつ増やす操作'が２回必要
elif ((a[2]-a[1])%2 == 1) or ((a[2]-a[0])%2 == 1) :
  count += 2

#最大値との差が両方とも偶数の場合、'２つ選んで１つ増やす操作'は不要

#'１つ選んで２つ増やす操作'の回数を足していく
count += (n//2)
count += (m//2)

print(count)

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

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

    cout << (n >= 30 ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;

int main(){
  vector<int> a(50001);
  int n;
  cin >> n;
  
  for(int i=1;i<46300;i++){
    
    a[i*108/100]=i;
  }
  if(a[n]==0){
    cout << ":(" << endl;
  }
  else{
    cout << a[n] << endl;
  }

}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var N, D int
	fmt.Scan(&N, &D)
	var ans int
	if N%(2*D+1) == 0 {
		ans = N / (2*D + 1)
		fmt.Println(ans)
	} else {
		ans = N/(2*D+1) + 1
		fmt.Println(ans)
	}
}

Measured memory_bytes: 512
let gcd m n =
  let rec doit x y =
    if y <= 0 then x else doit y (x mod y) in
  doit (max m n) (min m n)

let ext_euclid a b g =
  let rec doit (x, y, z) (s, t, u) =
    if u = g || u = 0 then (s, t)
    else
      let c = (z - z mod u) / u in
      doit (s, t, u) (x - c*s, y - c*t, z - c*u) in
  doit (1, 0, a) (0, 1, b)

let () =
  let (a, b) = Scanf.scanf "%d %d\n" (fun a b -> (a, b)) in
  let (x, y) = ext_euclid a b (gcd a b) in
  Printf.printf "%d %d\n" x y

Measured memory_bytes: 2448
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
p=p[:x]
q.sort(reverse=True)
q=q[:y]
all=p+q+r
all.sort(reverse=True)
print(sum(all[:x+y]))

Measured memory_bytes: 23456