akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) {
    return a.first < b.first;
  } else if (a.first == 0) {
    if (a.second >= 0) {
      return true;
    } else {
      return a.first < b.first;
    }
  } else if (b.first == 0) {
    if (b.second >= 0) {
      return false;
    } else {
      return a.first < b.first;
    }
  }
  return a.second * b.first < a.first * b.second;
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}


/* -------- <templates end> -------- */


void solve() {
  int n; cin >> n;
  vl arr(n);
  rep(i,n) cin >> arr[i];

  ll sum = 0;
  rep(i,n) sum ^= arr[i];

  int idx = 0;
  rrep(i,64) {
    if ((sum>>i) & 1) continue;

    bool skip = true;
    for (int j=idx; j<n; ++j) {
      if ((arr[j]>>i) & 1) {
        swap(arr[idx], arr[j]);
        skip = false;
        break;
      }
    }
    if (skip) continue;

    rep(j,n) {
      if (j == idx) continue;
      if ((arr[j]>>i) & 1) {
        arr[j] ^= arr[idx];
      }
    }
    ++idx;
  }

  ll ans = 0;
  rep(i,idx) ans ^= arr[i];
  cout << ans + (sum ^ ans) << endl;
}


/* -------- <programs end> -------- */


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pq = priority_queue<int>;
using q = queue<int>;

int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
 
     return 0;
 
}
     

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, c) for (int i = 0; i < (c); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<ll> monsters(n+1);
  vector<ll> max_killing(n);

  rep(i, n+1) {
      cin >> monsters.at(i);
  }

  rep(i, n){
    cin >> max_killing.at(i);
  }
  ll ans = 0;
  for (int i = n-1; i >= 0; i--)
  {
      /* code */
      if (max_killing.at(i) > monsters.at(i+1))
      {
          /* code */
          ans += monsters.at(i+1);
          if (monsters.at(i+1) + monsters.at(i) <= max_killing.at(i))
          {
              /* code */
              ans += monsters.at(i);
              monsters.at(i+1) = 0;
              monsters.at(i) = 0;
          }
          else
          {
              /* code */
              ans += max_killing.at(i) - monsters.at(i+1);
              monsters.at(i) -= max_killing.at(i) - monsters.at(i+1);
          }
      }
      else
      {
          /* code */
          ans += max_killing.at(i);
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n;
char s[500004];
int dp[500002] = {0};
int pre[500002];
int mi[26] = {0};
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	reverse(s + 1, s + n + 1);
	for(int i = 1; i <= n; i ++) {
		int c = 0;
		for(int j = 1; j < 26; j ++) if(dp[mi[j]] < dp[mi[c]]) c = j;
		pre[i] = mi[c];
		dp[i] = dp[mi[c]] + 1;
		mi[s[i] - 'a'] = i;
	}
	int ans = 0;
	for(int i = 1; i < 26; i ++) if(dp[mi[i]] < dp[mi[ans]]) ans = i;
	if(mi[ans] == 0) return putchar(ans + 'a'), 0;
	ans = mi[ans];
	while(pre[ans]) putchar(s[ans]), ans = pre[ans];
	putchar(s[ans]);
	bool vis[26] = {0};
	for(int i = 1; i < ans; i ++) vis[s[i] - 'a'] = 1;
	for(int i = 0; i < 26; i ++)
		if(! vis[i]) {
			putchar(i + 'a');
			break;
		}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 3200
n, k = [int(item) for item in input().split()]
s = [int(item) for item in list(input())]

dp = [0] * (n + 1)
dp[0] = [0, 0, 0]
for i in range(1, n + 1):
    if s[i - 1]:
        dp[i] = [dp[i - 1][0], dp[i - 1][1] + 1, dp[i - 1][2] + 1]
    elif i == 1 or s[i - 1 - 1]:
        dp[i] = [dp[i - 1][0] + 1, dp[i - 1][1] + 1, 0]
    else:
        dp[i] = [dp[i - 1][0], dp[i - 1][1] + 1, 0]

K = [[0] * 2 for _ in range(max((n + 1), k + 1))]
for x in dp:
    K[x[0]] = [x[1], x[2]]

# print(K, dp, dp[-1][0])
ans = 0

for i in range(dp[-1][0] + 1):
    if k + i <= dp[-1][0]:
        ans = max(ans, K[i + k][0] - K[i][0] + K[i][1])
    else:
        ans = max(ans, K[dp[-1][0]][0] - K[i][0] + K[i][1])

# for i in range(n + 1):
#     if dp[i][0] + k > dp[-1][0]:
#         ans = max(ans, K[dp[-1][0]][0] - dp[i][1] + K[dp[-1][0]][1])
#     else:
#         ans = max(ans, K[dp[i][0] + k][0] - dp[i][1] + K[dp[i][0] + k][1])

print(ans)


Measured memory_bytes: 31012
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    int N,M;cin >> N >> M;
    priority_queue<long long,vector<long long>,greater<long long>> PQ;
    vector<pair<long long,int>> change(M);
    for(int i = 0;i<N;i++){
        long long a;cin >> a;
        PQ.push(a);
    }
    for(int i = 0;i<M;i++){
        cin >> change.at(i).second >> change.at(i).first;
    }
    sort(change.begin(),change.end(),greater<pair<long long,int>>());

    int count = 1;
    int index = 0;
    while(index < M){
        if(count > change.at(index).second){
            index++;
            count = 1;
            continue;
        }
        long long target = PQ.top();PQ.pop();
        if(target >= change.at(index).first){
            PQ.push(target);
            break;
        }
        count++;
        PQ.push(change.at(index).first);
    }
    long long ans = 0;
    for(int i = 0;i<N;i++){
        long long plus = PQ.top();PQ.pop();
        //cout << plus << endl;
        ans += plus;
    }
    cout << ans << endl;

}


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

int main() {
  int n,sum = 0;
  cin >> n;
  
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n-1);
  
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n-1; i++) {
    cin >> c.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    sum += b.at(i);
  }
  for (int i = 0; i < n-1; i++) {
    if (a.at(i) + 1 == a.at(i+1)) {
      sum += c.at(a.at(i) -1);
    }
  }
  cout << sum;
}

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

int main() {
    int N,K; cin>>N>>K;
    int R,S,P; cin>>R>>S>>P;
    string T;cin>>T;
    vi sum(3,0);
    map<char,int> ctoi;
    ctoi['r']=0;ctoi['s']=1;ctoi['p']=2;
    for (int i = 0; i < K; i++)sum[ctoi[T[i]]]++;
    vector<bool> lose(N,false);
    for (int i = K; i < N; i++){
        if(T[i]==T[i-K] && !lose[i-K])lose[i]=true;
        else{
            sum[ctoi[T[i]]]++;
            lose[i]=false;
        }
    }
    cout<<sum[0]*P+sum[1]*R+sum[2]*S<<endl;
}

Measured memory_bytes: 3744
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=100005;
int r,c,n,xl[N],yl[N],xr[N],yr[N],stk[N];
struct data{
	int x,id,ck;
	data(){}
	data(int x,int id,int ck):x(x),id(id),ck(ck){}
	bool operator < (const data &n) const{
		return x<n.x;
	}
};
vector<data> vec;
int gao(int x,int y){
	if(x==0){
		return y;
	}
	if(y==c){
		return x+c;
	}
	if(x==r){
		return c+r+c-y;
	}
	if(y==0){
		return c+r+c+r-x;
	}
	return 0;
}
int main(){
	scanf("%d%d%d",&r,&c,&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d%d",&xl[i],&yl[i],&xr[i],&yr[i]);
		if(xl[i]!=0&&xl[i]!=r&&yl[i]!=0&&yl[i]!=c){
			continue;
		}
		if(xr[i]!=0&&xr[i]!=r&&yr[i]!=0&&yr[i]!=c){
			continue;
		}
		int ll=gao(xl[i],yl[i]);
		int rr=gao(xr[i],yr[i]);
		if(ll>rr){
			swap(ll,rr);
		}
		vec.push_back(data(ll,i,0));
		vec.push_back(data(rr,i,1));
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<(int)vec.size();i++){
		if(!vec[i].ck){
			stk[++stk[0]]=vec[i].id;
		}else{
			if(stk[stk[0]]!=vec[i].id){
				puts("NO");
				return 0;
			}
			stk[0]--;
		}
	}
	puts("YES");
	return 0;
}

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

int main() {
    int N,i,j,t;
    cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);

    for(i=0; i<N-1; i++)
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    
    for(i=0; i<N; i++) {
        int t=0;
        for(j=i; j<N-1; j++) {
            if(t < S.at(j))
                t = S.at(j);
            else if(t%F.at(j) != 0)
                t = t+F.at(j)-t%F.at(j);
            t += C.at(j);
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 256
from operator import itemgetter
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
MAX = 0
for i in AB:
  MAX = max(MAX,i[0])
AB.sort(key=itemgetter(1),reverse = True)
cnt = 0
for i in range(N):
  if AB[i][1] > MAX:
    H -= AB[i][1]
    cnt += 1
  if H <= 0:
    break
if H > 0:
  if H % MAX == 0:
    cnt += H // MAX
  else:
    cnt += H // MAX + 1
print(cnt)

Measured memory_bytes: 28896
import java.util.Scanner;

public class Main {

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

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int ans = 0;

		ans = (X-Z) / (Y+Z);

		System.out.println( ans );
	}
}

Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>

using namespace std;
static const long long int INF = 1e16;
typedef pair<int, int> P;


void solve()
{
	int K, S;
	cin >> K >> S;
	int ans = 0;
	for (int X = 0; X <= K; ++X)
	{
		for (int Y = 0; Y <= K; ++Y)
		{
			if (0 <= S - X - Y && S - X - Y <= K)
			{
				++ans;
			}
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    vector<ll> a(3*N);
    for (int i=0;i<3*N;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll res = 0;
    for (int i=N;i<3*N;i+=2) res += a[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACalc solver = new ACalc();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACalc {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            out.println(a + a * a + a * a * a);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;


void solve(){
  int n; cin >> n;
  int v[n], c[n];
  for(int i = 0; i < n; i++) cin >> v[i];
  for(int i = 0; i < n; i++) cin >> c[i];
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(v[i] - c[i] > 0) ans += v[i] - c[i];
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <string>
#include <iostream>
#include<vector>
#include <set>
#include<math.h>
#include<algorithm>

using namespace std;

int main()
{
	string str;
	
	cin >> str;
	for (int i=str.length()-1; i>=0; i--)
	{
		cout << str[i];
		if (i == 0) cout << endl;
	}
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

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

  vector<long long> money(n);
  money[0] = 1000;

  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      money[i + 1] = money[i] / a[i] * a[i + 1] + money[i] % a[i];
    } else {
      money[i + 1] = money[i];
    }
  }

  cout << money[n - 1] << '\n';

  return 0;
}



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

int main() {
 
  int N, A, B;
  cin >> N >> A >> B;
  if ((N *A) > B) {
    cout << B << endl;
  }
  else if ((N * A) < B) {
    cout << N * A << endl;
  }
  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    string s;
    scan(s);
    int n = s.length.to!int + 1;
    s = ">" ~ s ~ "<";

    auto a = new int[](n);
    a[] = inf;

    int rec(int i) {
        debug {
            writeln("i: ", i);
        }
        if (a[i] != inf) {
            return a[i];
        }
        a[i] = 0;
        if (s[i] == '<') {
            chmax(a[i], rec(i - 1) + 1);
        }
        if (s[i + 1] == '>') {
            chmax(a[i], rec(i + 1) + 1);
        }
        return a[i];
    }

    long ans;

    foreach (i ; 0 .. n) {
        ans += rec(i);
    }

    debug {
        writeln(a);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 50192
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

print(sum(a))

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 998244353;





int main() {

	int n, k;
	cin >> n >> k;
	VI a(n);
	REP(i, n)cin >> a[i];
	sort(ALL(a));

	VI dp(k + 1, -1);
	dp[0] = 0;

	FOR(i, 1, k + 1) {
		bool  b = false;
		REP(j, n) {
			if (i >= a[j]) {
				if (dp[i - a[j]]==0) {
					b = true;
				}
			}
		}
		if (b)dp[i] = 1;
		else dp[i] = 0;
	}

	if (dp[k])cout << "First" << endl;
	else cout << "Second" << endl;

}





Measured memory_bytes: 640
import java.util.*;

public class Main{

  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int sum=0;
    String temp = sc.next();
    char[] s = temp.toCharArray();
    for(int i=0;i<temp.length()/2;i++){
      if(s[i]!=s[temp.length()-i-1])sum++;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class T>
constexpr T inf=(T(1)<<(8*sizeof(T)-3));

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;

  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const Edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

class UnionFind {
  std::vector<intmax_t> tree;

public:
  UnionFind(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

int main() {
  size_t W, H;
  scanf("%zu %zu", &W, &H);

  std::vector<std::pair<Edge<intmax_t>, bool>> es;
  std::vector<intmax_t> p(W), q(H);
  for (size_t j=0; j<W; ++j) {
    scanf("%jd", &p[j]);
    es.emplace_back(Edge<intmax_t>(j, j+1, p[j]), true);
  }

  for (size_t i=0; i<H; ++i) {
    scanf("%jd", &q[i]);
    es.emplace_back(Edge<intmax_t>(W+i, W+i+1, q[i]), false);
  }

  std::sort(es.begin(), es.end());
  size_t a=W+1, b=H+1;
  intmax_t res=0;
  UnionFind uf(a+b);
  for (const auto &e: es) {
    if (uf.connected(e.first.src, e.first.dst))
      continue;

    uf.unite(e.first.src, e.first.dst);
    if (e.second) {
      res += p[e.first.src]*b;
      --a;
    } else {
      res += q[e.first.src-W]*a;
      --b;
    }
  }

  printf("%jd\n", res);
}


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

int main(){
  int n;
  cin >> n;
  vector <int> tako(n);
  for (int i = 0; i < n; i++) {
    cin >> tako.at(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += tako.at(i) * tako.at(j);
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;

const double PI = 3.14159265359;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, X;
    cin >> A >> B >> X;
    double t;
    if (2 * X > A * A * B) {
        t = (double)(2 * (A * A * B - X)) / (double)(A * A * A);
    }
    else {
        t = (double)(A * B * B) / (double)(2 * X);
    }
    cout << fixed << setprecision(7);
    cout << atan(t) * 180.0 / PI << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main(int argc, char *argv[])
{
  char n[4];
  int a,b,c,d;
  scanf("%s",&n);
  a=n[0]-'0';
  b=n[1]-'0';
  c=n[2]-'0';
  d=n[3]-'0';
  for (int i = 0; i < 8; i++) {
    char t[3];
    int sum = 0;
    if(i&1) {sum = a+b;t[0]='+';}
    else {sum = a-b;t[0]='-';}

    if((i>>1)&1) {sum +=c;t[1]='+';}
    else {sum -=c;t[1]='-';}

    if((i>>2)&1) {sum +=d;t[2]='+';}
    else {sum -=d;t[2]='-';}

    if(sum == 7){
      printf("%d%c%d%c%d%c%d=7\n",a,t[0],b,t[1],c,t[2],d);
      return 0;
    }
  }
  
  return 0;
}


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

//データの最大個数
#define MAX_COUNT 100000
//名前の最高文字数
#define NAME_LENGTH 10

int main(void)
{
	int i, n, q;
	/*
	first_pointはキューの先頭ポインタを、end_pointはキューの後尾ポインタを表す
	time_countはプロセスの処理時間の合計を表す
	*/
	int first_point, end_point, loop_end, time_count, end_process;
	char name[MAX_COUNT][NAME_LENGTH];
	int time[MAX_COUNT];

	//データの個数とクオンタムを入力
	scanf("%d %d", &n, &q);

	//名前と必要処理時間を入力
	for(i = 0; i < n; i++){
		scanf("%s %d", name[i], &time[i]);
	}

	time_count = end_process = 0;
	end_point = n - 1;
	loop_end = n;

	//全てのプロセスが終了したらループから抜ける
	while(n > 0){
		end_process = 0;

		//ループの最後のポイントまで繰り返す
		for(first_point = 0; first_point < loop_end; first_point++){
			time[first_point] -= q;
			time_count += q;

			//処理が終了した場合
			if(time[first_point] <= 0){
				//残った時間を加算する
				time_count += time[first_point];
				end_process++;
				//プロセスを1つ減らす
				n--;

				//名前と処理時間を出力
				printf("%s %d\n", name[first_point], time_count);
			}
			//処理が残った場合
			else{
				//キューの最後尾をずらす
				end_point++;
				if(end_point >= n){
					end_point = 0;
				}

				//先頭のデータを最後尾に移動する
				time[end_point] = time[first_point];
				strcpy(name[end_point], name[first_point]);
			}
		}

		//ループの最後のポイントを変動する
		loop_end -= end_process;
	}

	return 0;
}


Measured memory_bytes: 2400
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	cout << (a + b >= c ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    vector<int> odd, even;
    forn (i, m) {
        int a;
        cin >> a;
        if (a % 2)
            odd.push_back(a);
        else
            even.push_back(a);
    }
    if (odd.size() > 2) {
        cout << "Impossible\n";
        return 0;
    }
    vector<int> A, B;
    if (odd.size() == 2) {
        A = even;
        A.insert(A.begin(), odd[0]);
        A.push_back(odd[1]);
        B = A;
        B[0]++;
        B.back()--;
        if (B.back() == 0)
            B.pop_back();
    }
    if (odd.size() == 0) {
        A = even;
        B = A;
        B[0]--;
        B.push_back(1);
    }
    if (odd.size() == 1) {
        if (!even.empty()) {
            A = even;
            A.push_back(odd[0]);
            B = A;
            B[0]++;
            B.back()--;
            if (B.back() == 0)
                B.pop_back();
        } else {
            B = A = odd;
            if (odd[0] != 1) {
                B[0]--;
                B.push_back(1);
            }
        }
    }
    for (auto x: A)
        cout << x << ' ';
    cout << '\n';
    cout << B.size() << '\n';
    for (auto x: B)
        cout << x << ' ';
    cout << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N,K;
bool isokashi[105];
signed main(){
    scanf("%lld %lld",&N,&K);
    rep(i,K){
        int d;
        scanf("%lld",&d);
        rep(j,d){
            int a;
            scanf("%lld",&a);a--;
            isokashi[a]=true;
        }
    }
    int ans=0;
    rep(i,N){
        if(!isokashi[i])ans++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	int answer = 0;
	for(int i = 0; i < n; ++i) {
		long long x, y;
		cin >> x >> y;
		double cur = sqrt(x * x + y * y); 
		answer += cur <= d;
	}
	cout << answer;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int n, p;
long long ans = 0;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    string s;

    cin >> n >> p >> s;

    if (p == 2 || p == 5) {
        for (int i = 0; i < n; ++i) {
            int d = s[i] - '0';
            if (d % p == 0)
                ans += i+1;
        }
    } else {
        vector<int> cnt(p);
        cnt[0] = 1;

        long long cur = 0, weight = 1;
        for (int i = n-1; i >= 0; --i) {
            long long d = s[i] - '0';
            cur = (d * weight + cur) % p;
            ans += cnt[cur];
            ++cnt[cur];
            weight = weight * 10 % p;
        }
    }
    
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main(void){
    string s,ans = "Yes";
    cin >> s;
    
    if(s[0] == s[1] && s[0] == s[2]) ans ="No";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#input : 整数N、N個の値v_i
#output : vの中から２つを選び取り平均をとっていく、最終的に残った値の最大値を出力する

N = int(input())
v = list(map(int,input().split()))
v.sort()
i = 0

for i in range(N-1):
    n = (v.pop(0) + v.pop(0))/2
    v.insert(0,n)

print(v[0])

Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    words = ["dream", "dreamer", "erase", "eraser"]

    while s:
        for word in words:
            if len(s) >= len(word):
                if s[-len(word):] == word:
                    s = s[:-len(word)]
                    break
        else:
            print("NO")
            sys.exit()

    print("YES")

if __name__ == '__main__':
    main()


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

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

int main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  
  cout<<H*W-h*W-w*H+h*w;


  return 0;
}
  


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


int main()
{
    int n;
    cin>>n;
    vector<int> v;
    
    for(int i=0;i<n;i++)
    {
        
        int x;
        cin>>x;
        v.push_back(x);
    }
    vector<int> ans(n);

     if(n%2==0)
     {
          int mid=n/2;


          for(int i=0;i<n;i+=2)
          {
              int in=i/2;
              ans[mid+in]=v[i];
              ans[mid-in-1]=v[i+1];
          }   


          for(auto i:ans)
          cout<<i<<" ";
          cout<<endl;
     }
     else
     {

                ans[n/2]=v[0];
         for(int i=1;i<n;i+=2)
         {
            ans[n/2+(i+1)/2]=v[i];
            ans[n/2-(i+1)/2]=v[i+1];
            
         }
         for(auto i:ans)
         cout<<i<<" ";
         cout<<endl;

     }
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll n, x; cin >> n >> x;
	ll a[n];
	for(ll i = 0; i < n; ++i) cin >> a[i];
	ll po[n][n];
	for(ll i = 0; i < n; ++i)for(ll j = 0; j < n; ++j)po[i][j] = 0;
	for(ll i = 0; i < n; ++i)po[i][0] = a[i];
	for(ll i = 0; i < n; ++i)for(ll j = 1; j < n; ++j)po[i][j] = min(po[i][j - 1], a[(i + j) % n]);
	ll ans = 1145148931919810;
	for(ll i = 0; i < n; ++i){
		ll tmp = i * x;
		for(ll j = 0; j < n; ++j)tmp += po[j][i];
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 31488
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
  auto n = readln;
  auto m = map!(to!long)(readln.strip.split);
  auto v = reduce!(min,max,"a+b")(m);

  writefln("%d %d %d",v[0],v[1],v[2]);
}

Measured memory_bytes: 2676
N=int(input())
S=[input() for i in range(N)]
S.sort()
def list_count(my_list):
    dic={} #辞書型の宣言
    for num in my_list:
        if num in dic: #もしnumがkeyとして辞書にあれば
            dic[num]+=1 #valueに+1
        else: #なければ
            dic[num]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic
K=[]
A=list_count(S)
ookii=max(A.values())
K.append(ookii)
max_k_list = [kv[0] for kv in A.items() if kv[1] == K[0]]
max_k_list.sort()
for j in range(len(max_k_list)):
    print(max_k_list[j])

Measured memory_bytes: 35216
N, T = [int(i) for i in input().split()]
ct = []
for j in range(N):
  ct.append([int(i) for i in input().split()])
ct.sort()
flag = 0
for i in range(N):
  if ct[i][1] <= T:
    print(ct[i][0])
    flag = 1
    break
if flag == 0:
  print("TLE")

Measured memory_bytes: 3064
import java.io.*
import java.util.*

fun solve(R: Long, G: Long){
    // r + x/ 2 = g
    println(2*G-R)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val R = sc.next().toLong()
    val G = sc.next().toLong()
    solve(R, G)
}



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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	N, H;
	std::cin >> N >> H;
	std::vector<ll>	a(N);
	std::vector<ll> b(N);
	for (int i(0); i < N; ++i)
		std::cin >> a[i] >> b[i];

	std::sort(all(a));
	std::sort(all(b));
	ll	attack = a[N - 1];	
	std::vector<ll>	summ(N);

	summ[0] = b[N - 1];
	for (int i(1); i < N; ++i)
		summ[i] = summ[i - 1] + b[N - 1 - i];

	ll best = 1e10;

	for (int i(0); i < N; ++i)
		best = std::min(best, (ll)i + 1 + (ll)std::ceil(std::max(0.0, (1.0 * H - summ[i])) / attack));
	pnl(best);
}



Measured memory_bytes: 2560
#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 int64_t ll;
typedef long double ld;

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

ll solve(ll K, ll A, ll B) {
  if(B - A <= 2 || K <= A - 1) {
    return K + 1;
  }
  ll ret = (K - A + 1) / 2 * (B - A) + A;
  if((K - A + 1) % 2 == 1) ++ret;
  return ret;
}

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

  cout << solve(K, A, B) << endl;
  return 0;
}



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> x(n);
  arep(i, x) cin >> i;

  int ans = 1000;
  int kabu = 0;

  if (n == 2) {
    if (x[0] <= x[1]) {
      kabu += ans / x[0];
      ans %= x[0];
      ans += x[1] * kabu;
    }
    cout << ans << '\n';
    return 0;
  }

  rep(i, 0, n - 1) {
    if (i == n - 2) {
      if (x[i] > x[i + 1]) {
        kabu += ans / x[i];
        ans %= x[i];
        ans += kabu * x[i];
      } else {
        kabu += ans / x[i];
        ans %= x[i];
        ans += kabu * x[i + 1];
      }
      kabu = 0;
    } else {
      if (x[i] <= x[i + 1]) {
        kabu += ans / x[i];
        ans %= x[i];
      }
      if (x[i] > x[i + 1]) {
        ans += kabu * x[i];
        kabu = 0;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}

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

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

int main() {
	int n;
	cin >> n;
	vector<ll> luca(n + 1);
	luca[0] = 2;
	luca[1] = 1;
	for (int i = 2; i <= n; ++i) {
		luca[i] = luca[i - 1] + luca[i - 2];
	}
	cout << luca[n] << endl;
	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x = x2 - x1, y = y2 - y1;
    int dx = -y, dy = x;
    int x3 = x2 + dx, y3 = y2 + dy;
    int x4 = x3 - x, y4 = y3 - y;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;



}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
        solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


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

const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);

    rep(i, N)
    {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());

    cout << A.at(N - 1) - A.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define endl "\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}
int main() {
    
    
    Imposter
    
    
	int n;
	cin >> n;
	vector<int> A(n), B(n);
	map<int, int> ANum, BNum;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		ANum[A[i]]++;
	}
	for (int i = 0; i < n; i++) {
		cin >> B[i];
		BNum[B[i]]++;
	}
	for (int i = 0; i <= n; i++) {
		if (ANum.find(i) == ANum.end() || BNum.find(i) == BNum.end()) continue;
		if (ANum[i] + BNum[i] > n) {
			cout << "No" << endl;
			return 0;
		}
	}
	int j = 0, bef = -1;
	for (int i = 0; i < n; i++) {
		if (bef != A[i]) j = 0;
		if (A[i] == B[i]) {
			while (j < n) {
				if (A[j] != A[i] && B[j] != A[i]) {
					swap(B[i], B[j]);
					break;
				}
				j++;
			}
		}
		bef = A[i];
	}
	cout << "Yes" << endl;
	for (int b : B) cout << b << " ";
	cout << endl;
}

Measured memory_bytes: 23348
import heapq
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int, input().split())
    S = input()
    score = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            score += 1
    ans = min(score + 2*K, N-1)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
/*input
6 2 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b; cin >> n >> a >> b;
    cout << n/(a + b) * a + min(a, (n % (a + b)));

    return 0;
}

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

int main(){
  int income[10000];
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    int total=0;
    for(int i=0;i<n;i++){
      cin >> income[i];
      total += income[i];
    }
    int ave = total/n;
    int count=0;
    for(int i=0;i<n;i++){
      if(ave>=income[i])
        count++;
      }
      cout << count << endl;
    }
}



Measured memory_bytes: 3132
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#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 <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
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[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b,c;cin>>a>>b>>c;
    if(a+b>=c)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 22:57:26
*/

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


int main(){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int top;
int S[1000];

void push(int x) {
    top++;
    S[top] = x;
}

int pop() {
    top--;
    return S[top+1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];
    
    while(scanf("%s", s)!=EOF) {
        if(s[0]=='+') {
            a = pop();
            b = pop();
            push(a+b);
        }
        else if(s[0]=='-') {
            a = pop();
            b = pop();
            push(b-a);
        }
        else if(s[0]=='*') {
            a = pop();
            b = pop();
            push(a*b);
        }
        else {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
}


Measured memory_bytes: 3228
x, y = map(int,input().split(' '))

def gcd(x, y):
    new_x = max(x, y)
    new_y = min(x, y)
    while new_y > 0:
        r = new_x % new_y
        new_x = new_y
        new_y = r
    return new_x

print(gcd(x, y))


Measured memory_bytes: 5600
import sys
n = int(input())
A =  [int(input()) for i in range(n)]

max_benefit = -sys.maxsize
min_value = A[0]
for i in range(1,n):
    max_benefit = max(max_benefit, A[i]-min_value)
    min_value = min(min_value, A[i])
print(max_benefit)


Measured memory_bytes: 13596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m >> s;
	ll dpd[n+1];
	rep(i, 1, n){dpd[i] = INF;}
	
	ll maxi = 0;
	for(ll i = 0; i <= n-1; i++){
		if(dpd[i] != INF){
			rep(j, max(1LL, maxi-i+1), min(m, n-i)){
				if(s[i+j] == '0'){
					dpd[i+j] = j;
				}
				maxi = i+j;
			}
		}
		//rep(i, 1, n){cout << dpd[i] << " ";}cout << endl;
	}
	
	if(dpd[n] == INF){
		print(-1)
		return 0;
	}
	
	vector<ll> ans;
	ll itr = n;
	while(itr != 0){
		ans.push_back(dpd[itr]);
		itr -= dpd[itr];
	}
	
	ll aa = ans.size();
	rep(i, 1, aa){
		cout << ans[aa-i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2248
import java.util.*;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    private void solve() {
        int N = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < N; ++i) {
            set.add(sc.next());
        }
        System.out.println(set.size());
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 77032