akhauriyash/Code-Regression huggingface dataset:
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ,mod = 1e9+7 ;

int n ,k ,u ,v ,ans = 1 ;
vector<int> adj[N] ;
void dfs(int p,int gp,int take){
    if(take>=k){
        cout << 0;
        exit(0);
    }
    int c = k - take ;

    ans = 1ll*ans*c%mod ;
    int cur = 1+(gp!=0) ;
    for(int ch:adj[p]){
        if(ch==gp) continue ;
        dfs(ch,p,cur++);
    }
}
int main(){
    scanf("%d%d",&n,&k);
    if(n==1) return cout << k,0 ;
    for(int i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,0,0) ;
    cout << ans ;
    return 0;
}


Measured memory_bytes: 9216
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s = readline() |> chomp
	n = length(s)
	tc = 0
	sc = 0
	for i in 1:n
		if s[i]=='T'
			if sc>0
				sc-=1
			else
				tc+=1
			end
		else
			sc+=1
		end
	end
	println(tc+sc)
end

main()

Measured memory_bytes: 120976
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int h = Integer.parseInt(sc.next());
  int n = Integer.parseInt(sc.next());
  int a = 0;
  for (int i = 0; i < n; i++){
  	a += Integer.parseInt(sc.next());
  }
  if (a>=h){
  	System.out.println("Yes");
  }
  else{
  	System.out.println("No");
  }
}
}

Measured memory_bytes: 46912
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val y = sc.nextLong()
    println(problem085c(n, y))
}

fun problem085c(n: Int, y: Long): String {
    for (i in 0..n) {
        for (j in 0..n) {
            if (i + j > n) break
            for (k in 0..n) {
                if (i + j + k > n) break
                if (i + j + k == n && i * 10000L + j * 5000L + 1000L * k == y) {
                    return "$i $j $k"
                }
            }
        }
    }
    return "-1 -1 -1"
}

Measured memory_bytes: 31392
N = int(input())
S = input()

if N == 1:
    print(1)
    exit()

ans = 0
pre = S[0]
for i in range(1, N - 1):
    if S[i] == pre:
        pass
    else:
        ans += 1
        #print(pre)
        pre = S[i]

if S[-1] != pre:
    ans += 2
else:
    ans += 1
print(ans)

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

int main()
{
    int a, b, ans;
    cin >> a >> b;
    if (a >= 13)
        ans = b;
    else if (a <= 5)
        ans = 0;
    else
        ans = b / 2;
    cout << ans << endl;
    return 0;
}


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

const long inf = 10000000000000000;

int main(int argc, char *argv[]) {
  long x, k, d;
  std::cin >> x >> k >> d;
  x = std::abs(x);
  k = std::abs(k);
  d = std::abs(d);

  long ans = inf;
  long a = x / d;
  if (a >= k)
    ans = x - (k * d);
  else {

    k -= a;
    long b = x % d;
    if (k % 2 == 0)
      ans = b;
    else {
      ans = b - d;
    }
  }

  if (ans == inf)
    throw "Error";

  std::cout << std::abs(ans) << std::endl;
}


Measured memory_bytes: 3192
N, C, K = map(int, input().split())

T = [int(input()) for i in range(N)]

T.sort()
A = T[0]
SUM = 1
ans = 0
for i in range(1, N):
    SUM += 1
    if T[i] - A > K:
        ans += 1
        SUM = 1
        A = T[i]
    elif SUM > C:
        ans += 1
        SUM = 1
        A = T[i]

        
print(ans+1)
    

Measured memory_bytes: 7384
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n; cin>>n;
	int a[4] = {0};
	string check[4];
	check[0] = "AC";
	check[1] = "WA";
	check[2] = "TLE";
	check[3] = "RE";
	forn(i,n){
		string s; cin>>s;
		forn(j,4){
			if(s == check[j]) a[j]++;
		}
	}
	forn(i,4){
		cout<<check[i]<<" x "<<a[i]<<ln;
	}

	return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

/*
 * 撃墜ケース
 * <input>
 * 5
 * 1 4 1 2 2
 *
 * <correct output>
 * No
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            int a4Cnt = 0;
            int a2Cnt = 0;
            int a1Cnt = 0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                if ( a % 4 == 0 ) {
                    a4Cnt++;
                } else if ( a % 2 == 0 ) {
                    a2Cnt++;
                } else {
                    a1Cnt++;
                }
            }

            a1Cnt += a2Cnt % 2;

            if ( a1Cnt > a4Cnt + 1 ) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 47624
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;

int main() {

    string S;
    cin >> S;
    string out = "";
    if(S == "Sunny") out = "Cloudy";
    else if(S == "Cloudy") out = "Rainy";
    else out = "Sunny";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int kMaxN = 300001;

struct E {
  int x, y;
} e[kMaxN];
int c[2][kMaxN], a[2], b[2];
int n, m, t, ans;

bool F() {
  long long x = (long long)b[0] * b[1];
  for (int i = 1; i <= t; i++) {
    x -= c[0][e[i].x] && c[1][e[i].y];
  }
  return !x;
}

int main() {
  cin >> n >> m >> t;
  for (int i = 1; i <= t; i++) {
    cin >> e[i].x >> e[i].y;
    c[0][e[i].x]++;
    c[1][e[i].y]++;
  }
  for (int i = 0; i <= 1; i++) {
    for (int j = 1; j < kMaxN; j++) {
      a[i] = max(a[i], c[i][j]);
    }
    for (int j = 1; j < kMaxN; j++) {
      c[i][j] = a[i] == c[i][j];
      b[i] += c[i][j];
    }
  }
  cout << a[0] + a[1] - F();
  return 0;
}

Measured memory_bytes: 8296
import sys
input = sys.stdin.readline

def main():
    r, c = map(int, input().split())
    tab = [list(map(int, input().split())) for i in range(r)]

    col_sums = [0] * c
    
    for i in range(r):
        tmp = 0
        for j in range(c):
            tmp += tab[i][j]
            col_sums[j] += tab[i][j]
            print(tab[i][j], end=" ")
        print(tmp)
    
    tmp = 0
    for i in range(c):
        tmp += col_sums[i]
        print(col_sums[i], end=" ")
    print(tmp)


if __name__ == "__main__":
    main()


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

int main(){
  int n,rank;
  char shape;
  int S[13] = {0};
  int H[13] = {0};
  int C[13] = {0};
  int D[13] = {0};
  cin >> n;
  for(int i=0; i < n ; i++){
    cin >> shape >> rank;
    switch (shape){
    case 'S':
      S[rank-1] = 1;
      break;
    case 'H':
      H[rank-1] = 1;
      break;
    case 'C':
      C[rank-1] = 1;
      break;
    case 'D':
      D[rank-1] = 1;
      break;
    }  
  }

  for(int i=0; i < 13 ; i++){
    if(S[i] == 0) cout << "S " << (i+1) << endl;
  }
  for(int i=0; i < 13 ; i++){
    if(H[i] == 0) cout << "H " << (i+1) << endl;
  }
  for(int i=0; i < 13 ; i++){
    if(C[i] == 0) cout << "C " << (i+1) << endl;
  }
  for(int i=0; i < 13 ; i++){
    if(D[i] == 0) cout << "D " << (i+1) << endl;
  }
  return 0;
}



Measured memory_bytes: 3036
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

const int N = 256;

int main(int argc, char const *argv[]) {

  char a[N], b[N], c[N];
  int n, count, ab, bc, ca;

  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  scanf("%s", c);

  for(int i=0; i<n; i++){
    ab = 0; bc = 0; ca = 0;
    if(a[i] == b[i]) ab++;
    if(b[i] == c[i]) bc++;
    if(c[i] == a[i]) ca++;
    if(ab + bc + ca == 1) count++;
    if(ab + bc + ca == 0) count += 2;
  }

  printf("%d\n", count);


  return 0;
}


Measured memory_bytes: 128
/*
[abc128] E - Roadwork
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2e5;
const int MAX_Q = 2e5;

enum EV {
    EV_T = 0,
    EV_S = 1,
    EV_D = 2,
};

int N, Q;
int S[MAX_N], T[MAX_N], X[MAX_N];
int D[MAX_Q];

void solve() {
    vector<pair<int, pair<EV, int>>> es;
    for (int i = 0; i < N; i++) {
        es.push_back({S[i] - X[i], {EV_S, X[i]}});
        es.push_back({T[i] - X[i], {EV_T, X[i]}});
    }
    for (int i = 0; i < Q; i++) {
        es.push_back({D[i], {EV_D, i}});
    }
    sort(es.begin(), es.end());

    vector<int> ans(Q);
    set<int> cur;
    for (auto& e : es) {
        switch (e.second.first) {
            case EV_T:
                cur.erase(e.second.second);
                break;
            case EV_S:
                cur.insert(e.second.second);
                break;
            default:
                ans[e.second.second] = cur.empty() ? -1 : *cur.begin();
        }
    }

    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> T[i] >> X[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> D[i];
    }

    solve();

    return 0;
}


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

int solve(int h, int w, vector<string> s) {
    vector<vector<int>> L(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        int prev = -1;
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') {
                prev = j;
            }
            L[i][j] = prev;
        }
    }

    vector<vector<int>> R(h, vector<int>(w));
    for (int i = 0; i < h; ++i) {
        int prev = w;
        for (int j = w-1; j >= 0; --j) {
            if (s[i][j] == '#') {
                prev = j;
            }
            R[i][j] = prev;
        }
    }

    vector<vector<int>> T(h, vector<int>(w));
    for (int j = 0; j < w; ++j) {
        int prev = -1;
        for (int i = 0; i < h; ++i) {
            if (s[i][j] == '#') {
                prev = i;
            }
            T[i][j] = prev;
        }
    }

    vector<vector<int>> B(h, vector<int>(w));
    for (int j = 0; j < w; ++j) {
        int prev = h;
        for (int i = h-1; i >= 0; --i) {
            if (s[i][j] == '#') {
                prev = i;
            }
            B[i][j] = prev;
        }
    }

    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            ans = max(ans, R[i][j] - L[i][j] + B[i][j] - T[i][j] - 3);
        }
    }

    return ans;
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> s;
    for (int i = 0; i < h; ++i) {
        string l; cin >> l;
        s.push_back(l);
    }
    cout << solve(h, w, s) << endl;
    return 0;
}

Measured memory_bytes: 71168
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){
string ws;
map<char,string> aa;
	aa['A']="00000";
	aa['B']="00001";
	aa['C']="00010";
	aa['D']="00011";
	aa['E']="00100";
	aa['F']="00101";
	aa['G']="00110";
	aa['H']="00111";
	aa['I']="01000";
	aa['J']="01001";
	aa['K']="01010";
	aa['L']="01011";
	aa['M']="01100";
	aa['N']="01101";
	aa['O']="01110";
	aa['P']="01111";
	aa['Q']="10000";
	aa['R']="10001";
	aa['S']="10010";
	aa['T']="10011";
	aa['U']="10100";
	aa['V']="10101";
	aa['W']="10110";
	aa['X']="10111";
	aa['Y']="11000";
	aa['Z']="11001";
	aa[' ']="11010";
	aa['.']="11011";
	aa[',']="11100";
	aa['-']="11101";
	aa['\'']= "11110";
	aa['?']="11111";
	map<string,char> bb;
	bb["101"]=' ';
	bb["000000"]='\'';
	bb["000011"]=',';
	bb["10010001"]='-';
	bb["010001"]='.';
	bb["000001"]='?';
	bb["100101"]='A';
	bb["10011010"]='B';
	bb["0101"]='C';
	bb["0001"]='D';
	bb["110"]='E';
	bb["01001"]='F';
	bb["10011011"]='G';
	bb["010000"]='H';
	bb["0111"]='I';
	bb["10011000"]='J';
	bb["0110"]='K';
	bb["00100"]='L';
	bb["10011001"]='M';
	bb["10011110"]='N';
	bb["00101"]='O';
	bb["111"]='P';
	bb["10011111"]='Q';
	bb["1000"]='R';
	bb["00110"]='S';
	bb["00111"]='T';
	bb["10011100"]='U';
	bb["10011101"]='V';
	bb["000010"]='W';
	bb["10010010"]='X';
	bb["10010011"]='Y';
	bb["10010000"]='Z'; 
	
	
	while(getline(cin,ws)){

		string wws="", ans="";
		rep(i, ws.size()) wws += aa[ws[i]];
//		cout << wws <<endl;
		string ww="";
		rep(i,wws.size()){
			ww += wws[i];
			if(bb[ww]!=0){
				ans += bb[ww];
				ww="";
			}
		}
		if(cin.eof()) break;
		cout << ans << endl;
	}

	return 0;
	
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,X,Y;
  cin >> N >> X >> Y;
  vector<vector<int>> G(N);
  for(int i=0; i<N-1; i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  X--;
  Y--;
  G[X].push_back(Y);
  G[Y].push_back(X);
  queue<int> que;
  vector<int> cnt(N,0);
  for(int i=0; i<N; i++){
    vector<int> dist(N,-1);
    dist[i] = 0;
    que.push(i);
    while(que.size()){
      int v = que.front();
      que.pop();
      for(int nv: G[v]){
        if(dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
    for(int j=i+1; j<N; j++){
      cnt[dist[j]]++;
    }
  }
  for(int i=1; i<N; i++){
    cout << cnt[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n,m;
    cin >> n >> m;
    int s[m],c[m];
    for(int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
    }
    
    int ans = -1;
    int a,b,d;
    for(int i = 0; i < 1000; i++) {
        int flag = 0;
        a = i/100;
        b = (i%100)/10;
        d = i%10;
        if(i >= 100) {
            for(int j = 0; j < m; j++) {
                if(s[j] == 1) {
                    if(a == c[j]) {
                        flag++;
                    }
                }
                if(s[j] == 2) {
                    if(b == c[j]) {
                        flag++;
                    }
                }
                if(s[j] == 3) {
                    if(d == c[j]) {
                        flag++;
                    }
                }
            }
        }
        if(i >= 10 && i <= 99) {
            for(int j = 0; j < m; j++) {
                if(s[j] == 1) {
                    if(b == c[j]) {
                        flag++;
                    }
                }
                if(s[j] == 2) {
                    if(d == c[j]) {
                        flag++;
                    }
                }
            }
        }
        if(i <= 9) {
            for(int j = 0; j < m; j++) {
                if(s[j] == 1) {
                    if(d == c[j]) {
                        flag++;
                    }
                }
            }
        }
        string t = to_string(i);
        if(t.size() == n) {
            if(flag == m) {
                ans = i;
                break;
            }
        }
    }
    
    if(ans == -1) {
        cout << -1;
    }else {
        cout << ans;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)


def dfs(node, dist):
    for children in tree[node]:
        if not visited[children]:
            visited[children] = True
            dist[children] = dist[node] + 1
            dfs(children, dist)


N, u, v = map(int, input().split())
u -= 1
v -= 1
tree = [[] for i in range(N)]
for i in range(N-1):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    tree[A].append(B)
    tree[B].append(A)
dist_u = [0] * N
dist_v = [0] * N
visited = [False] * N
visited[u] = True
dfs(u, dist_u)
visited = [False] * N
visited[v] = True
dfs(v, dist_v)

max_move_same = -1
max_move = 0
for i in range(N):
    if dist_u[i] == dist_v[i]:
        if max_move_same == -1 or max_move_same > dist_v[i]:
            max_move_same = dist_v[i]
    if dist_u[i] < dist_v[i]:
        max_move = max(max_move, dist_v[i] - 1)

print(max(max_move_same, max_move))


Measured memory_bytes: 102428
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 0x3f3f3f3f, N = 500005;

int p[N], nxt[N][2], in[N];
pi t[4*N];
int n, k;

void upd(int pos, pi val, int v = 1, int tl = 1, int tr = n) {
	if(tl == tr) {
		t[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) upd(pos, val, v*2, tl, tm);
	else 		  upd(pos, val, v*2+1, tm+1, tr);
	t[v] = min(t[v*2], t[v*2+1]); 
}

pi qry(int l, int r, int v = 1, int tl = 1, int tr = n) {
	if(l > r) return MP(INF, INF);
	if(l == tl && r == tr) return t[v];
	int tm = (tl + tr) / 2;
	return min(qry(l, min(r, tm), v*2, tl, tm),
			qry(max(l, tm+1), r, v*2+1, tm+1, tr));
}

signed main()
{
	IO_OP;
	memset(t, 0x3f, sizeof t);
	cin >> n >> k;
	for(int i=1;i<=n;i++) {
		int t;
		cin >> t;
		p[t] = i;
	}
	for(int i=n;i>=1;i--) {
		nxt[p[i]][0] = qry(max(1, p[i]), min(p[i]+k-1, n)).S;
		nxt[p[i]][1] = qry(max(1, p[i]-k+1), min(p[i], n)).S;
		upd(p[i], MP(i, p[i]));
		for(int j=0;j<2;j++)
			if(nxt[p[i]][j] != INF)
				in[nxt[p[i]][j]]++;
	}
	set<pi> s;
	for(int i=1;i<=n;i++)
		s.insert(MP(in[i], i));
	vi v;
	while(s.size()) {
		pi p = *s.begin(); s.erase(s.begin());
		v.PB(p.S);
		for(int i=0;i<2;i++)
			if(nxt[p.S][i] != INF) {
				int pp = nxt[p.S][i];
				s.erase(MP(in[pp], pp));
				in[pp]--;
				s.insert(MP(in[pp], pp));
			}		
	}
	for(int i=0;i<n;i++)
		p[v[i]] = i + 1;
	for(int i=1;i<=n;i++)
		cout << p[i] << endl;
	
}




Measured memory_bytes: 52596
N=int(input())
h=list(map(int,input().split()))

cost=[]

for i in range(N):
  if(i==0):
    cost.append(0)
  if(i==1):
    cost.append(abs(h[i]-h[i-1]))
  if(i>=2):
    cost.append(min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2])))
print(cost[N-1])

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;

	if(b-a == c-b) puts("YES");
	else puts("NO");
	
	return 0;
}


Measured memory_bytes: 256
import sys


def solve(A: int, P: int):
    return (3 * A + P) // 2


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    ans = solve(A, P)
    if ans is not None:
        print(ans)

if __name__ == "__main__":
    main()


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

int main(){
    int n;
    cin >> n;
    vector<int> a(100);
    rep(i,n) {
        cin >> a[i];
    }
    int mx=0;
    for(int i=0; i < n; i++){
        for(int j=i; j < n;j++){
            int df = abs(a[i] - a[j]);
            if(mx < df) mx = df;
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
A=list(map(int,input().split()))
a=10**10
b=0
c=0
ans=0
for i in range(n):
  if A[i]<a:
    a=A[i]
    b=0
  if A[i]>b:
    b=A[i]
    if b-a>c:
      c=b-a
      ans=0
    elif b-a==c:
      ans=ans+1
print(ans+1)

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}


int main() {
  int n; cin >> n;
  set <int> s;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    s.insert(x);
  }
  if(s.size() == n) {
    print("YES");
  }
  else {
    print("NO");
  }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll xor_(ll num) {
	ll ans = (num+1) / 2 % 2;
	if(num % 2 == 0) {
		ans ^= num;
	}
	return ans;
}
int main()
{
	ll a,b;
	cin >> a >> b;
	
	ll r1 = xor_(a-1);
	ll r2 = xor_(b);
	ll r = r1 ^ r2;
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 384
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
ll mod=1000000007;

ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string s[n];
    int ar[n];
    map<string,int> ma;
    forn(i,n){
            cin>>s[i]>>ar[i];
            ma[s[i]]=i;
    }
    string s1;
    cin>>s1;
    int ans=0;
    for(int i=ma[s1]+1;i<n;i++)ans+=ar[i];
    cout<<ans;

	return 0;
}


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

int main() {
  int A, B;
  scanf("%d%d", &A, &B);
  int count = 0;
  int target = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        target = 10000 * i + 1000 * j + 100 * k + 10 * j + i;
        if (A <= target && target <= B) count++;
      }
    }
  }
  printf("%d", count);
}

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

int main()
{
	string x;
	cin >> x;
	int i, j, p, m;
	for(i = 0; i <x.size(); i++){
		if(x[i] == 'A'){
			p = i;break;
		}
	}
	for(j = (x.size()-1) ; j >= 0; j--){
		if(x[j] == 'Z'){
			m = j; break;
		}
	}
	cout << m - p+1 << endl;
	
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;
int a,b,h,m;
double s,si,ans;
int main(){
    cout<<fixed<<setprecision(20);
    cin >> a >> b >> h >> m;
    si = abs(h*30+m*0.5-m*6);
    double st = (double)(si * acos(-1) /180);
    s = (double)a*a +(double)b*b -(double)2*a*b*cos(st);
    ans = sqrt(s);
    if(abs(h*30+m*0.5-m*6) == 0) ans = abs(a-b);
    if(abs(h*30+m*0.5-m*6) == 180) ans = a+b; 
    cout << ans << endl;
}

Measured memory_bytes: 4160
import java.io.*;

public class Main {

  private static int n, min, max, number;
  private static long sum;

  public static void main(String[] args) throws NumberFormatException, IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    n = Integer.parseInt(br.readLine());
    String[] input_numbers = br.readLine().split(" ");
    min = Integer.parseInt(input_numbers[0]);
    max = Integer.parseInt(input_numbers[0]);
    sum = 0;

    for (String input_number : input_numbers) {
      number = Integer.parseInt(input_number);
      if (min > number) {
        min = number;
      }
      if (max < number) {
        max = number;
      }
      sum += number;
    }

    System.out.println(min + " " + max + " " + sum);

  }
}

Measured memory_bytes: 28436
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        int d = int.Parse(Console.ReadLine());
        int e = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        if ((e - a) <= k) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, a; scanf("%d%d", &n, &a);
	n %= 500;
	
	if(n <= a) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
main(){float a,b,c,d,e,f;for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",c/a-b/a*f,f/=e-d*b/a))f=f-d*c/a;}

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

int main(void) {
  int i, j, k, n, f;
  vector< pair< pair<string, string>, int> > v;
  scanf("%d%d", &n, &f);
  rep(i, n) {
    int m, l = 0;
    scanf("%d", &m);
    string s[m];
    rep(j, m) cin >> s[j];
    sort(s, s + m);
    rep(j, m) for(k = j + 1; k < m; ++k) {
      l = 0;
      pair<string, string> p = make_pair(s[j], s[k]);
      vector< pair< pair<string, string>, int> >::iterator it;
      for(it = v.begin(); it != v.end(); ++it) {
        if((*it).first.first == s[j] && (*it).first.second == s[k]) {
          (*it).second++;
          l = 1;
          break;
        }
      }
      pair< pair<string, string>, int> p1 = make_pair(p, 1);
      if(!l) v.push_back(p1);
    }
  }
  sort(v.begin(), v.end());
  vector< pair< pair<string, string>, int> >::iterator it;
  int ans = 0;
  for(it = v.begin(); it != v.end(); ++it) {
    if((*it).second >= f) ++ans;
    /*cout << (*it).first.first << " " << (*it).first.second << " " << (*it).second << "\n";*/
  }
  printf("%d\n", ans);
  for(it = v.begin(); it != v.end(); ++it) {
    if((*it).second >= f) cout << (*it).first.first << " " << (*it).first.second << "\n";
  }
  return 0;
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAX = 1010000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int x, y;
  ll ans;
  cin >> x >> y;
  if ((x + y) % 3 == 0) {
    ans = COM((x + y) / 3, x - (x + y) / 3);
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int n, m, q;
vector<int> a, b, c, d;

ll calc_score(vector<int> &x){
    ll res = 0;
    for(int i=0; i<q; i++){
        if(x[b[i]] - x[a[i]] == c[i]) res += d[i];
    }
    return res;
}

ll dfs(vector<int> &A){
    if(A.size() == n){
        return calc_score(A);
    }

    ll res = 0;
    int last = (A.empty() ? 0 : A.back());
    for(int i=last; i<m; i++){
        A.push_back(i);
        res = max(res, dfs(A));
        A.pop_back();
    }
    return res;
}

int main(void){
    
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    vector<int> zzz;
    cout << dfs(zzz) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=200000000;
//setprecision(2) <<

const int MOD = 1000000007;




long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
class Ans{
public:
	long long x;
	long long y;
	long long x_;
	long long y_;
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N;
	cin>>N;
	long long ans=0;
	int d[N];
	long long allsum=0;
	long long sum=0;
	for(int i=0;i<N;i++){
		cin>>d[i];
		sum+=d[i]*d[i];
		allsum+=d[i];
	}
	
	cout<<(allsum*allsum-sum)/2<<endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    for(int i=K; i<N; i++)
    {
        if(A[i] > A[i-K]) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}


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


int main(void){
	int n, m;
	cin >> n;
	while(n){
		char henkan[100][2];
		for(int i = 0; i < n; i++)
			cin >> henkan[i][0] >> henkan[i][1];
		cin >> m;
		char data;
		string moji;
		for(int i = 0; i < m; i++){
			cin >> data;
			for(int j = 0; j < n; j++){
				if(data == henkan[j][0]){
					data = henkan[j][1];
					break;
				}
			}
			moji += data;
		}

		cout << moji << endl;
		cin >> n;
	}
}

Measured memory_bytes: 1324
#include<iostream>
using namespace std;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  int n;
    scanf("%d%",&n);
  int Sum=0;
  int Min=1000000;
  for(int i=0;i<n;++i){
    int a;
      scanf("%d",&a);
    if(a%10!=0){
      chmin(Min,a);
    }
      Sum+=a;
  }

  if(Sum%10==0){
    Sum-=Min;
  }
  printf("%d\n",max(0,Sum));
}


Measured memory_bytes: 256
def comb_mod(n, r, mod):
    up = 1
    down = 1
    for i in range(r):
        up *= n - i
        up %= mod
        down *= i + 1
        down %= mod
    return ((up * pow(down, mod - 2, mod)) % mod)


def main():
    MOD = 10**9 + 7
    n, a, b = [int(x) for x in input().split()]

    result = pow(2, n, MOD) - 1
    a_cmb = comb_mod(n, a, MOD)
    b_cmb = comb_mod(n, b, MOD)

    result = (result - a_cmb) % MOD
    result = (result - b_cmb) % MOD

    print(result)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 998244353;

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

const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll COM(int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll HCOM(int n, int k) {
    return (n == 0 && k == 0) ? 1 : COM(n+k-1, k);
}

ll modpow(ll a, ll n) {
   ll res = 1;
   while (n > 0) {
      if (n & 1) {
         res *= a;
         res %= mod;
      }
      a *= a;
      a %= mod;

      n >>= 1;
   }
   return res;
}

ll N, M, K;
vector<vector<ll>> dp;

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

    cin >> N >> M >> K;

    COMinit();

    ll ans = 0;

    for (int i = 0; i <= K; i++) {
        ll res = M;
        res *= COM(N - 1, i);
        res %= mod;
        res *= modpow(M - 1, N - i - 1);
        res %= mod;
        ans += res;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15600
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
ll n,s,ans,sum = 0,Min = 0x3f3f3f3f3f3f;
ll a[1005];

int main(){
    int n;
    scanf("%d",&n);

    printf("Christmas");

    int t = 25 - n;
    while(t--){
        printf(" Eve");
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		long sum = 0;
		
		for(int i = 1; i <= n; i++) {
			if(i%5 != 0 && i%3 != 0)
				sum += i;
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 35776
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import combinations_with_replacement, accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, Q = MAP()
graph = [[] for _ in range(N)]
abcd = [LIST() for _ in range(Q)]
ans = 0

for x in combinations_with_replacement(range(1, M+1), N):
	tmp = 0
	for a, b, c, d in abcd:
		a -= 1
		b -= 1
		if x[b]-x[a] == c:
			tmp += d
	ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 69524
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int n, c, d[31][31], cnt[3][31]{};

int main() {
    cin >> n >> c;
    REP(i, c) {
        REP(j, c) { cin >> d[i][j]; }
    }
    REP(i, n) {
        REP(j, n) {
            int a;
            cin >> a;
            cnt[(i + j) % 3][a - 1]++;
        }
    }
    int dmin = INT32_MAX;
    REP(i, c) {
        REP(j, c) {
            if (i == j) continue;
            REP(k, c) {
                if (i == k || j == k) continue;
                int tmp = 0;
                REP(t, c) {
                    tmp += cnt[0][t] * d[t][i];
                    tmp += cnt[1][t] * d[t][j];
                    tmp += cnt[2][t] * d[t][k];
                }
                dmin = min(dmin, tmp);
            }
        }
    }
    cout << dmin << endl;
    return 0;
}


Measured memory_bytes: 256
X,K,D=list(map(int,input().split()))
 
def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0
 
def solve():
    if X>0:
        x_greedy=X-K*D
    else:
        x_greedy=X+K*D
 
    if sgn(X)==sgn(x_greedy):
        return print(abs(x_greedy))
 
    else:
        x_r=X%D
        x_l=x_r-D
 
        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))
 
if __name__=='__main__':
    solve()

Measured memory_bytes: 9068
n=int(input())
S=list(map(str,[input() for i in range(n)]))
m=int(input())
T=list(map(str,[input() for i in range(m)]))
A=[]
for i in range(n):
    score=S.count(S[i])-T.count(S[i])
    A.append(score)
ans=max(0,max(A))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i,n) cin >> s.at(i);
  
  sort(s.begin(),s.end());
  int ans =0;
  rep(i,n){
    ans += s[i];
  }
  if(ans%10 != 0) cout << ans << endl;
  else{
    rep(i,n){
      if((ans-s[i]) % 10 != 0){
        cout << ans-s[i] << endl;
        return 0;
      }
    }
    cout << 0 << endl;
  }
  

  return 0;
}



Measured memory_bytes: 256
while n = gets.to_i
  break if n == 0

  count = 0
  0.upto(9) do |a|
    0.upto(9) do |b|
      0.upto(9) do |c|
        0.upto(9) do |d|
          if a + b + c + d == n
            count += 1
          end
        end
      end
    end
  end

  puts count
end

Measured memory_bytes: 8476
def getint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main(fr,el,discount):
    return fr+el-discount

freeze,elec,disc = getint()
frprice = getint()
elecprice = getint()
price = []
elec_min = elecprice[0]
for i in range(elec):
    elec_min = min(elec_min,elecprice[i])
fr_min = frprice[0]
for i in range(freeze):
    fr_min = min(fr_min,frprice[i])
price.append(fr_min+elec_min)

for i in range(disc):
    x,y,c = getint()
    price.append(main(frprice[x-1],elecprice[y-1],c))
ans = price[0]
for i in range(len(price)):
    ans = min(ans,price[i])
    
print(ans)

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



int main(){
    string s;
    string ans;
    cin >> s;
    int x;
    x=s.length();
    rep(i,x){
        if(i%2==1) continue;
        ans+=s[i];
    }
    cout << ans << endl;
   return 0;
}

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


int main(){
	int n ; cin >> n ;
	vector<long long> a(n) ;
	for(auto &i:a) cin >> i ;
	sort(a.begin(),a.end()) ;
	long long l,m ;
	l = m = 0 ;
	for(int i=n-1;i>0;i--){
		if(a.at(i)==a.at(i-1)){
			if(l==0) l = a.at(i) ;
			else{
				m = a.at(i) ;
				break ;
			}
			i-- ;
		}
	}
	cout << l*m << endl ;
}


Measured memory_bytes: 1024
def Euclidean(input_list):
  # print input_list
  x = input_list[1]
  y = input_list[0]
  r = x % y
  if r != 0:
    list = [r, y]
    list.sort()
    return Euclidean(list)
  else:
    return y

list = map(int, raw_input().split(" "))
list.sort()
print Euclidean(list)

Measured memory_bytes: 6456
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	int k, x;
	cin >>k >> x;
	if(500 * k >= x)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(all(a));
  ll x = 0, y = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (x == 0 && a[i] == a[i - 1]) {
      x = a[i];
      i--;
    } else if (a[i] == a[i - 1]) {
      y = a[i];
      break;
    }
  }
  cout << x * y << endl;
}

Measured memory_bytes: 640
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{    string s;    cin>>s;    s[3]='8';    cout<<s;    system("pause");   
 return 0;}

Measured memory_bytes: 504
/*
	Name: None
	Copyright: zhangjingcanËùÓÐ£¬Î´¾­ÔÊÐí²»µÃ×ªÔØ
	Author: zhangjingcan
	Date:
	Description: C++ÎÄ¼þ
*/
#include <bits/stdc++.h>
using namespace std;
string s[101];
int h,w;
int main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		cin>>s[i];
	}
	for(int i=1;i<=h;i++){
		cout<<s[i]<<"\n";
		cout<<s[i]<<"\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long

int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};

signed main(){
  int h,w;
  cin>>h>>w;
  char mp[50][50];
  int c[50][50]={0};
  int ans=0;
  rep(i,h){
    rep(j,w) cin>>mp[i][j];
  }

  rep(i,h){
    rep(j,w){
      if(mp[i][j]=='#'){
	rep(k,4){
	  if(mp[i+dx[k]][j+dy[k]]=='#') break;
	  else if(k==3){cout<<"No"<<endl;return 0;}	  
	}
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int max_weight;
int w[101];
long long int v[101];
long long int dp[101][100001];
long long int ans = 0;
int main()
{
    cin >> n >> max_weight;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= max_weight; j++)
        {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + w[i] <= max_weight)
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
        }
    }
    for (int i = 0; i <= max_weight; i++)
    {
        if (dp[n][i] >= ans)
            ans = dp[n][i];
    }
    cout << ans << endl;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  int c=0;
  if(s[0]==t[0]) c++;
  if(s[1]==t[1]) c++;
  if(s[2]==t[2]) c++;

  cout<<c<<endl;

}


Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())
if A+B > 2*C:
    AB = min(X,Y)
    if X<Y:
        if B <= 2*C:
            print(2*C*AB + A*(X-AB) + B*(Y-AB))
        else:
            print(2*C*Y)
    else:
        if A <= 2*C:
            print(2*C*AB + A*(X-AB) + B*(Y-AB))
        else:
            print(2*C*X)
else:
    print(A*X+B*Y)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define CLR(a) a.clear()
#define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
#define SIZE(a) a.size()
#define ERASE(a, b) memset(a, b, sizeof a)
#define PB(a, b) a.push_back(b)
#define PB2(a,i,b) a[i].push_back(b)
#define LL long long
#define ULL unsigned long long
#define DBG cout<<"I Am Here"<<endl
#define DBGA(a) cout<<a<<endl
#define DBGI(b,a) cout<<b<<' '<<a<<endl
#define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
#define INF 1e9
#define INV 1e-6
#define sll(a) scanf("%I64d", &a)
#define pll(a) printf("%I64d\n", a)
#define si(a) scanf("%d", &a)
#define pii pair<LL,LL>
#define MAX 100006
#define CASE(i) printf("Case %d: ", i);
#define CSH(i) printf("Case #%d: ", i);
#define PI acos(-1)
#define piis pair<int, string>
#define fast1 ios_base::sync_with_stdio(false);
#define fast2 cin.tie(0)
#define CHECK_BIT(var,pos) ((var & (1 << pos)) == (1 << pos))


LL MOD = 1000000007;

using namespace std;

LL bigmod(LL b, LL p, LL m)
{
    if(p==0)  return 1;
    if(p%2==0)
    {
        LL x = bigmod(b,p/2,m);
        return (x%m * x%m)%m;
    }
    else return ((b%m)*bigmod(b,p-1,m)%m)%m;
}


LL MODINVERSE(LL a)
{
    return bigmod(a, MOD-2, MOD);
}

int main()
{
    string str, res;
    cin>>str;
    int sz = str.size(); int bac = 0;
    for(int i=sz-1; i>=0; i--)
    {
        if(str[i]=='0'){
            if(bac==0){
               res = res + str[i];
            }
            if(bac>0)
                bac--;
        }
        else if(str[i]=='1'){
            if(bac==0){
                res = res + str[i];
            }
            if(bac>0)
                bac--;
        }
        else if(str[i]=='B'){
            bac++;
        }

    }
    reverse(res.begin(), res.end());
    cout<<res;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prev = sc.nextInt();
        int count = 0;
        for (int i = 1; i < n; i++) {
            int current = sc.nextInt();
            if (current == prev) {
                count++;
                prev = -1;
            } else {
                prev = current;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22228