akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

bool is_prime(int n) {
	if (n < 2) {
			return false;
	}
	if (n==2||n==3) {
		return true;
	}
	for (int i = 3; i < n; i = i+2) {
		if (n%i==0) {
			return false;
		}
	}
	return true;
}

int main(void) {
	int N = 123456*2;
	int n;
	cin >> n;

	std::vector<bool> prime(N);
	for (int i = 0; i < N+2; i++) {
		prime[i] = true;
	}
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i <= sqrt(N); i++) {
		if (is_prime(i)) {
			for (int j = 2; i*j < N+2; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (n!=0) {
		int count = 0;
		for (int i = n+1; i < (2*n)+1; i++) {
			if (prime[i]) {
				count++;
			}
		}
		cout << count << endl;

		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=10*x+ch-'0',ch=getchar();
	return x*f;
}
int A,B,C;
int main(){
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);
	A=read();B=read();C=read();
	for(int i=0;;i++){
		if(A%2 || B%2 || C%2){
			printf("%d\n",i);
			return 0;
		}
		if(i>100000000){
			puts("-1");
			return 0;
		}
		int a=A,b=B,c=C;
		A=b/2+c/2;
		B=a/2+c/2;
		C=a/2+b/2;
	}

	// fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void sortBy(int a[], long v[]) {
		int n = a.length;
		if (n == 0) {
			return;
		}
		for (int i = 1; i < n; i++) {
			int j = i;
			int ca = a[i];
			long cv = v[ca];
			do {
				int nj = (j - 1) >> 1;
				int na = a[nj];
				if (cv <= v[na]) {
					break;
				}
				a[j] = na;
				j = nj;
			} while (j != 0);
			a[j] = ca;
		}
		int ca = a[0];
		for (int i = n - 1; i > 0; i--) {
			int j = 0;
			while ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {
				j <<= 1;
				j += (v[a[j + 2]] > v[a[j + 1]]) ? 2 : 1;
			}
			if ((j << 1) + 2 == i) {
				j = (j << 1) + 1;
			}
			int na = a[i];
			a[i] = ca;
			ca = na;
			long cv = v[ca];
			while (j != 0 && v[a[j]] < cv) {
				j = (j - 1) >> 1;
			}
			while (j != 0) {
				na = a[j];
				a[j] = ca;
				ca = na;
				j = (j - 1) >> 1;
			}
		}
		a[0] = ca;
	}

	static void solve() throws Exception {
		int n = scanInt();
		long l[] = new long[n + 1];
		long r[] = new long[n + 1];
		for (int i = 0; i < n; i++) {
			l[i] = scanLong();
			r[i] = scanLong();
		}
		int idxL[] = new int[n + 1];
		int idxR[] = new int[n + 1];
		for (int i = 0; i < n + 1; i++) {
			idxL[i] = idxR[i] = i;
		}
		sortBy(idxL, l);
		sortBy(idxR, r);
		boolean taken[] = new boolean[n + 1];
		long ans = 0;
		int pL = n + 1, pR = 0;
		while (true) {
			while (pL > 0 && taken[idxL[pL - 1]]) {
				--pL;
			}
			while (pR < n + 1 && taken[idxR[pR]]) {
				++pR;
			}
			if (pL == 0 || pR == n + 1 || l[idxL[pL - 1]] <= r[idxR[pR]]) {
				break;
			}
			ans += l[idxL[pL - 1]] - r[idxR[pR]];
			taken[idxL[pL - 1]] = taken[idxR[pR]] = true;
			--pL;
			++pR;
		}
		out.print(2 * ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 44820
def is_even(num):
    return num % 2 == 0

A, B = map(int, input().split())
# 1, 2, 3で繰り返す
for C in range(1, 4):
    if not is_even(A*B*C):
        print('Yes')
        # exitでプログラムを終わらせる
        exit()
# 'Yes'の場合ここまで到達しない
print('No')

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


char S[1000];
int len;

int main(void) {
  cin >> S;
  len = strlen(S);

  bool n = false, s = false, e = false, w = false;

  REP(i, 0, len) {
    if(S[i] == 'N') n = true;
    if(S[i] == 'S') s = true;
    if(S[i] == 'E') e = true;
    if(S[i] == 'W') w = true;
  }

  cout << (((s && n && !e && !w) || (!s && !n && e && w) || (s && n && e && w)) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int D,N;scanf("%d%d",&D,&N);
	if(N==100) printf("101");
	else printf("%d",N);
	for(int i=0;i<D;i++)
		printf("00");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f[10000009];
main(){
   int n;
   cin >> n;
   for(int i = 1; i <= n; i++)
    for(int j = i; j <= n; j+=i)
        f[j]++;
        ll ans = 0;
   for(int i = 1; i <= n; i++)
    ans += f[i]*i;
   cout<<ans<<endl;
}


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

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    
    double log = 0;
    int sum = 0;
    for (int i = 1; i <= N; i++) {
      log = Math.log10(i);
      if (
        log < 1.0 || 
        2.0 <= log && log < 3.0 ||
        4.0 <= log && log < 5.0
      ) {
        sum ++;
      }
    }
    
    System.out.println(sum);
  }
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int k;
  cin>>k;
  ll ans = 0;
  for(int a=1;a<=k;++a){
    for(int b=1;b<=k;++b){
      for(int c=1;c<=k;++c){
        ans += gcd(gcd(a,b),c);
      }
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3564
import java.util.*

fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map { it.toInt() }
    val list = Array(N) { ArrayList<Int>() }
    repeat(N - 1) {
        val (ai, bi) = readLine()!!.split(" ").map { Integer.parseInt(it) }
        list[ai - 1].add(bi - 1)
        list[bi - 1].add(ai - 1)
    }
    val cost = Array(N) { 0 }
    repeat(Q) {
        val (pi, xi) = readLine()!!.split(" ").map { Integer.parseInt(it) }
        cost[pi - 1] += xi
    }
    val visited = Array(N) { false }
    val queue = ArrayDeque<Pair<Int, Int>>()
    visited[0] = true
    queue.add(0 to cost[0])
    while (queue.isNotEmpty()) {
        val (parent, parentCost) = queue.poll()
        for (child in list[parent]) {
            if (visited[child]) continue
            visited[child] = true
            cost[child] += parentCost
            queue.add(child to cost[child])
        }
    }
    println(cost.joinToString(" "))
}

Measured memory_bytes: 159804
#include<bits/stdc++.h>
using namespace std;
int temp=0,temp1=0;
int main()
 {  string a;cin>>a;
    temp=a[0]-'0'-1;
    temp+=a.size()*9-9;
    for(int i=0;i<a.size();i++)
    temp1+=a[i]-'0';
    int final=max(temp1,temp);
    printf("%d\n",final);
}


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

public class Main {
	public static void main(String[] args) throws InterruptedException, IOException {
		BufferedReader din = new BufferedReader(new InputStreamReader(System.in));
		String data , str;
		char tmp;
		while ( true ){
			data = din.readLine();
			if ( data == null ) break;
			while ( true ) {
				String sarch = data;
				Scanner sc = new Scanner(sarch);
				if ( sc.findInLine("this") != null || sc.findInLine("the") != null || sc.findInLine("that") != null ) {
					break;
				} else {
					str = "";
					for ( int j = 0; j < data.length(); j++ ) {
						if ( data.charAt(j) == '.' ) tmp = '.';
						else if ( data.charAt(j) == ' '  ) tmp = ' ';
						else {
							tmp = (char)(data.charAt(j)+1);
							if ( tmp > 122 ) tmp -= 26;
						}
						str += tmp;
					}
				}
				data = str;
			}
			System.out.println(data);
		}
	}
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab(m);
    for (int i = 0; i < m; i++) cin >> ab[i].first >> ab[i].second;
    sort(ab.rbegin(), ab.rend());

    int div_point = 0, ans = 0;
    for (int i = 0; i < m; i++) {
        if (ab[i].first <= div_point && div_point < ab[i].second) {
            continue;
        } else {
            div_point = ab[i].first;
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

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

int main(){
	scanf("%d %d %d %d", &n, &a, &b, &c);
	for(int i=0; i<n; i++){
		int t;
		scanf("%d", &t);
		d.push_back(t);
	}
	sort(d.rbegin(), d.rend());
/*
	printf("%d %d %d %d\n", n, a, b, c);
	for(int i=0; i<n; i++) printf("%d ", d[i]);
	printf("\n");
*/

	int ans = 0;
	for(int i=0; i<n+1; i++){
		int cal;
		cal = c;
		for(int j=0; j<i; j++) cal += d[j];
		cal /= a + b * i;
		if(ans <= cal) ans = cal;
		else break;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1052
from decimal import Decimal
import sys
for l in sys.stdin:
  xa,ya,xb,yb,xc,yc,xd,yd=list(map(Decimal,l.split(",")))
  a=xd-xb
  b=yd-yb
  c=xa-xb
  d=ya-yb
  e=xc-xb
  f=yc-yb
  try:
    s=(a*f-b*e)/(c*f-d*e)
    t=(-a*d+b*c)/(c*f-d*e)
  except:
    print("NO")
  if s>=0 and t>=0 and s+t>=1:
    print("YES")
  else:
    print("NO")


Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string A,B,C; cin >> A >> B >> C;
    if(A[A.length()-1]==B[0] && B[B.length()-1]==C[0]) pr("YES");
    else pr("NO");

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define fi first
#define se second
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll A,B;cin >> A >> B;
    ll ans = 0;
    if(A % 2 == 1){
        A++;
        ans ^= A-1;
    }
    ll cnt = (B-A+1)/2;
    if(cnt % 2 == 1) ans ^= 1;
    if((B-A+1) % 2 == 1){
        ans ^= B;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll d, t, s; cin>>d>>t>>s;

    if (t * s < d) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main()
{
int i,j,count=0,k=0,l=0,x[100000];
scanf("%d", &i);
for(j=0;j<i;j++){
scanf("%d",&x[j]);
if(x[j] ==2) l++;
}
if(l==0){
printf("-1\n");
return 0;
}
while(x[k]!=2){
k=x[k]-1;
count++;
if(count>j)break;
}
count++;
if(count>j){
printf("-1\n");
return 0;
}
printf("%d\n",count);
return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << '\n';
	else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2 << '\n';
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << '\n';
	else cout << 0 << '\n';
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
}

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

	solve();
}

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

int main() {
    ll n;
    cin >> n;
    ll rn=sqrt(n);
    
    ll ans;
    for (ll i=rn;i>0;i--) {
        if (n%i==0) {
            ans=i+n/i-2;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	vll x(n);
	Loop(i, n) cin >> x[i];
	ll ans = 0;
	Loop(i, n - 1) {
		ans += min((x[i + 1] - x[i]) * a, b);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    ll n;
    string c;
    cin>>n>>c;
    ll cnt=0;
    rep(i,n){
        if(c[i]=='R') cnt++;
    }
    ll ans=0;
    rep(i,cnt){
        if(c[i]=='W') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int W, H, x, y;
    cin >> W >> H >> x >> y;

    cout << setprecision(15);
    cout << double(W) * H / 2 << " " << (2 * x == W && 2 * y == H) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int j[1001*1001];
int cmp(const void* a,const void* b)
{
  return (*(int *)b) - (*(int *)a);
}
int main()
{
  int n,m,k,l,h,f;
  for(;;){
    scanf("%d%d",&n,&m);
    if(n==0 && m==0) break;
    memset(j,0,sizeof(j));
    for(k=1;k<=n;k++) scanf("%d",&j[k]);
    h = n+1;
    for(k=1;k<=n;k++){
      for(l=k;l<=n;l++){
	j[h++] = j[k]+j[l];
      }
    }
    qsort(j,h,sizeof(int),cmp);
    f = 0;
    l = h;
    for(k=0;k<h;k++){
      if(j[k] > m) continue;
      while(j[k] + j[l] < m) l--;
      if (f < j[k] + j[l+1]) f = j[k]+j[l+1];
    }
    printf("%d\n",f);
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<vector>
#include<algorithm>
long long a[100005], b[100005];
long long c[100005];
int order[100005];
long long sum[100005], p[100005];
std::vector<int>g[100005];
std::vector<int>e[100005];
int vis[100005];
long long f[100005];

long long min(long long a,long long b){ return a>b?b:a; }

long long max(long long a,long long b){ return a>b?a:b; }

int find(int u){
    if(p[u]==u) return u;
    else return p[u] = find(p[u]);
}

void dp(int u){
    sum[u] = b[u];
    for(int v: e[u]){
        dp(v);
        sum[u] += sum[v];
    }
    f[u] = c[u]+sum[u];
    for(int v: e[u]){
        f[u] = min(f[u],max(f[v],c[u])+sum[u]-sum[v]);
    }
}

int cmp(int a,int b){ return c[a]<c[b]; }

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++){
        order[i] = p[i] = i;
        sum[i] = 0;
        scanf("%lld%lld",&a[i],&b[i]);
        c[i] = a[i]-b[i];
        if(c[i]<0) c[i] = 0;
    }
    for(int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    std::sort(order+1,order+1+n,cmp);
    for(int i = 1; i <= n; i++){
        int u = order[i]; 
        vis[u] = 1;
        for(int v: g[u]){
            if(vis[v] && find(v)!=u){
                int root = find(v);
                p[root] = u;
                //sum[u] += sum[root];
                e[u].push_back(root);
            }
        }
    }
    //printf("ok\n");
    int root = find(1);
    dp(root);
    printf("%lld\n",f[root]);
    return 0;
}


Measured memory_bytes: 23260
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <cmath>

using namespace std;
void tolow(char *a);
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  tolow(&s[k-1]);
  cout<<s<<'\n';
}
void tolow(char *a)
{
  if(*a>='A' && *a<='Z')
    *a+='a'-'A';
}

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

#pragma GCC optimize "O3"
#define rep(i, a, n) for (long long i = a; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = (int)1e9 + 7;
const ll INF = MOD * MOD;
const double EPS = 1e-9;
const ll powll = 1LL << 1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int retTime(int y, int m, int d)
{
    int ans = 0;

    while (y < 1000)
    {
        if (y % 3 == 0)
        {
            if (d == 20)
            {
                m++;
                d = 1;
            }
            else
            {
                d++;
            }

            if (m == 11)
            {
                y++;
                m = 1;
            }
        }
        else
        {
            if (m % 2 == 0 && d == 19)
            {
                m++;
                d = 1;
            }
            else if (m % 2 && d == 20)
            {
                m++;
                d = 1;
            }
            else
            {
                d++;
            }

            if (m == 11)
            {
                y++;
                m = 1;
            }
        }
        ans++;
    }

    return ans;
}

int main(void)
{
    int n;
    cin >> n;
    while (n--)
    {
        int y, m, d;
        cin >> y >> m >> d;

        cout << retTime(y, m, d) << "\n";
    }
}


Measured memory_bytes: 3100
A = [0] * 9
nums = dict()
for i in range(3):
  temp = list(map(int, input().split()))
  for j, var in enumerate(temp):
    nums[var] = i * 3 + j
N = int(input())

for _ in range(N):
  i = int(input())
  if i in nums:
    A[nums[i]] = 1

bingo = [
  A[0] + A[1] + A[2],
  A[3] + A[4] + A[5],
  A[6] + A[7] + A[8],
  A[0] + A[3] + A[6],
  A[1] + A[4] + A[7],
  A[2] + A[5] + A[8],
  A[0] + A[4] + A[8],
  A[2] + A[4] + A[6]]

if 3 in bingo:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 61424
#include<stdio.h>
int main()
{long long int a,b,c,k,sum=0;
     scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
     while(k!=0&&a!=0)
     {sum++;
     a--;k--;
     }
      while(k!=0&&b!=0)
     {b--;k--;
     }
      while(k!=0&&c!=0)
     {sum--;
     c--;k--;
     }
     printf("%lld\n",sum);
}


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

int INF = (int)1e9 + 5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        for(int j = 1; j <= k; j++){
            if(i-j >= 0){
                dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int countUp(const string str, const string target)
{
    int cnt = 0;
    auto pos = str.find(target);
    while (pos != string::npos) {
        cnt++;

        pos = str.find(target, pos + target.size());
    }

    return cnt;
}

int main(void)
{
    int N;
    cin >> N;

    vector<string> s(N);
    for (int i = 0; i < N; i++)
        cin >> s[i];

    int cntAB, cntxA, cntBx, cntBxA;
    cntAB = cntxA = cntBx = cntBxA = 0;
    for (int i = 0; i < N; i++) {
        cntAB += countUp(s[i], "AB");

        char top = s[i].front();
        char back = s[i].back();
        if (top == 'B' && back == 'A')
            cntBxA++;
        else if (top == 'B')
            cntBx++;
        else if (back == 'A')
            cntxA++;
    }

    if (cntBxA > 0) {
        cntAB += cntBxA - 1;

        if (cntxA > 0) {
            cntAB++;
            cntxA--;
        }

        if (cntBx > 0) {
            cntAB++;
            cntBx--;
        }
    }
    //cntAB += max(0, cntBxA - 1);
    //cntBxA = 0;

    //if (cntxA > 0) {
    //    cntAB++;
    //    cntxA--;
    //}
    //if (cntBx > 0) {
    //    cntAB++;
    //    cntBx--;
    //}

    int n = min(cntxA, cntBx);
    cntAB += n;
    cntxA -= n;
    cntBx -= n;

    //if (cntBxA == 0)
    //    cntAB += min(cntBx, cntxA);
    //else if (cntBx + cntxA > 0)
    //    cntAB += cntBxA + min(cntBx, cntxA);
    //else
    //    cntAB += cntBxA - 1;

    cout << cntAB << endl;

    return 0;
}


Measured memory_bytes: 768
import scala.io.StdIn._
object Main extends App {
  case class Elem(num: Int, cnt: Int)
  readLine.toInt
  val vs = readLine.split(" ").map{_.toInt}
  val (evens, odds) = vs.zipWithIndex.partition(_._2 % 2 == 0)

  val (even1st, even2nd) = take2(count(evens), evens.size)
  val (odd1st, odd2nd) = take2(count(odds), odds.size)
  println(if (even1st.num != odd1st.num) even1st.cnt + odd1st.cnt
          else Math.min(even1st.cnt + odd2nd.cnt, even2nd.cnt + odd1st.cnt))

  def take2(arr: Array[Elem], fullSize: Int): (Elem, Elem) = 
    (arr(0), if (arr.size == 1) Elem(0, fullSize) else arr(1))

  def count(s_i: Array[(Int, Int)]): Array[Elem] = {
    val size = s_i.size
    s_i.map{_._1}
       .groupBy(identity)
       .map{case (num, nums) => Elem(num, size - nums.size)}
       .toArray
       .sortBy(_.cnt)
  }
}

Measured memory_bytes: 106924
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, 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, insort, insort_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
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

tmp_A = [0]*N
for i, x in enumerate(A):
	if i%2 == 0:
		tmp_A[i] = x
	else:
		tmp_A[i] = -x

tmp = sum(tmp_A)/2

ans = []

for i in range(N):
	print(int(tmp*2), end = " ")
	tmp = A[i] - tmp

print()

Measured memory_bytes: 21992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

std::string str;

int main() {
	std::cin >> str;
	bool a = (str[0] == 'x'), b = (str[str.size() - 1] == 'x');
	if (a && b)std::cout << 'x' << std::endl;
	else std::cout << 'o' << std::endl;

	return 0;
}

Measured memory_bytes: 1176
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    cpdef int merge(self,a,b): return self.ptr.merge(a,b)
    cpdef bool same(self,a,b): return self.ptr.same(a,b)
    cpdef int leader(self,a): return self.ptr.leader(a)
    cpdef int size(self,a): return self.ptr.size(a)
    cpdef vector[vector[int]] groups(self): return self.ptr.groups()

cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class fenwick_tree_:
    cdef fenwick_tree[long] *ptr
    def __cinit__(self, int n): self.ptr = new fenwick_tree[long](n)  
    def __dealloc__(self): del self.ptr
    cpdef void add(self, int p, long x): self.ptr.add(p, x)
    cpdef long sum(self, int l, int r): return self.ptr.sum(l, r)
"""
import os
try:
    from atcoder import *
except:
    open('atcoder.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

N,Q=map(int,input().split())
A=list(map(int,input().split()))
QRS=[list(map(int,input().split())) for i in range(Q)]
f=fenwick_tree_(N)
for i in range(N):
    f.add(i,A[i])
a=[]
for q,r,s in QRS:
    if q==0:
        f.add(r,s)
    else:
        a.append(f.sum(r,s))
print(*a,sep='\n')

Measured memory_bytes: 139648
n=int(input())
a=[[0]*10 for i in range(10)]
for i in range(1,n+1):
  keta=str(i)[0]
  makkou=str(i)[-1]
  a[int(makkou)-1][int(keta)-1]+=1
ans=0
for j in range(10):
  for i in range(10):
    ans+=a[j][i]*a[i][j]
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long x = sc.nextLong();
			long en = 100;
			
			for(int i=1;;i++) {
				en = en + (en/100);

				if(en>=x) {
					System.out.println(i);
					return;
				}
			}
			
		}
		
		
		
	}


Measured memory_bytes: 35816
#include <stdio.h>

#define MAX_H  1000
#define MAX_W  1000
#define WORKLIST_LEN  (MAX_H * MAX_W * 4)

char A[MAX_H][MAX_W + 1];
int table[MAX_H][MAX_W];
int vi[] = { -1,  0, 1, 0 };
int vj[] = {  0, -1, 0, 1 };

struct Worklist {
  int d, i, j;
};
struct Worklist worklist[WORKLIST_LEN];
int worklistHead = 0;
int worklistTail = 0;

void append(struct Worklist worklist[], int d, int i, int j)
{
  worklist[worklistTail].d = d;
  worklist[worklistTail].i = i;
  worklist[worklistTail].j = j;
  worklistTail++;
  worklistTail = worklistTail % WORKLIST_LEN;
}

void popleft(struct Worklist worklist[], int *d, int *i, int *j)
{
  *d = worklist[worklistHead].d;
  *i = worklist[worklistHead].i;
  *j = worklist[worklistHead].j;
  worklistHead++;
  worklistHead = worklistHead % WORKLIST_LEN;
}

int isEmpty(struct Worklist worklist[])
{
  worklist[0].d = worklist[0].d;
  return (worklistHead == worklistTail);
}

int main()
{
  int H, W;
  int i, j, k, d, m;
  scanf("%d%d", &H, &W);
  for (i = 0; i < H; i++) {
    scanf("%s", A[i]);
  }

  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      if (A[i][j] == '#') {
        append(worklist, 0, i, j);
      }
      table[i][j] = -1;
    }
  }

  m = 0;
  while (! isEmpty(worklist)) {
    popleft(worklist, &d, &i, &j);
    if (table[i][j] < 0) {
      table[i][j] = d;
      if (m < d) {
        m = d;
      }
      for (k = 0; k < 4; k++) {
        if (0 <= i + vi[k] && i + vi[k] < H &&
            0 <= j + vj[k] && j + vj[k] < W)
        {
          append(worklist, d + 1, i + vi[k], j + vj[k]);
        }
      }
    }
  }

  printf("%d\n", m);
  return 0;
}


Measured memory_bytes: 52096
N = int(input())
list_str = []
for i in range(3):
  list_str.append(list(input()))
count = 0
for j in range(N):
    if list_str[0][j] == list_str[1][j] and list_str[1][j] == list_str[2][j] and list_str[2][j] == list_str[0][j]:
      count = count
    elif list_str[0][j] == list_str[1][j] and list_str[1][j] != list_str[2][j] and list_str[2][j] != list_str[0][j]:
      count = count + 1
    elif list_str[0][j] != list_str[1][j] and list_str[1][j] != list_str[2][j] and list_str[2][j] == list_str[0][j]:
      count = count + 1
    elif list_str[0][j] != list_str[1][j] and list_str[1][j] == list_str[2][j] and list_str[2][j] != list_str[0][j]:
      count = count + 1
    else:
      count = count + 2
print(count)

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    
    int len = (int)S.size();
    int res = len;
    for(int i = 0; i < len; ++i) {
        if(S[i] == S[i+1]) --res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        t: f64,
        x: f64,
    }

    let ans = 0;

    println!("{}", t / x);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h> //ライブラリ全読み込み
using namespace std; //std:を省略できる

int main(){
    int a,d,l;
    cin >> d >> l;
    a = d%l;
    if(a == 0){
      cout << d/l << endl;
      return 0;
    }
    cout << a+d/l << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
  int a;
  int b;
  int at;
  int ans;  
  while(cin>>a>>b>>at){
    if(a==-1&&b==-1) break;
    if(a==-1||b==-1){
      cout << 'F' << endl;
      continue;
    }
    ans = a + b;
    if(ans>=80) cout << 'A' << endl;
    else if(ans>=65&&ans<80) cout << 'B' << endl;
    else if(ans>=50&&ans<65) cout << 'C' << endl;
    else if(ans>=30&&ans<50&&at>=50) cout << 'C' << endl;
    else if(ans>=30&&ans<50) cout << 'D' << endl;
    else if(ans<30) cout << 'F' << endl;
  }
  return 0;
}
 

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

using int64 = long long;
using pii = pair<int64, int64>;
using Graph = vector<vector<pii>>;
constexpr int64 INIT_VAL = 1e18;

vector<int64> dijkstra(Graph &G, int s)
{
    int N = G.size();
    vector<int64> d(N, INIT_VAL);
    d[s] = 0;

    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(pii(0, s));

    while (!pq.empty()) {
        pii p = pq.top(); pq.pop();
        int v = p.second;

        if (d[v] < p.first) {
            continue;
        }
        
        for (pii np : G[v]) {
            int nv = np.first;
            if (d[v] + np.second < d[nv]) {
                d[nv] = d[v] + np.second;
                pq.push(pii(d[nv], nv));
            }           
        }
    }
    return d;
}

int main()
{
    int N;
    cin >> N;
    Graph G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    int Q, K;
    cin >> Q >> K;
    K--;
    vector<int64> d = dijkstra(G, K);

    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }   
    return 0;
}


Measured memory_bytes: 11120
N = int(input())
B = list(map(int, input().split()))

A = [0] * N

for i in range(N):
    if i == 0:
        A[0] = B[0]
    elif i == N - 1:
        A[i] = B[i - 1]
    else:
        a = min(B[i - 1], B[i])
        A[i] = a

ans = sum(A)
print(ans)

Measured memory_bytes: 3064
a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))
b = [0 for _ in range(9)]
n = int(input())
for _ in range(n):
  tmp = int(input())
  for i in range(9):
    if tmp == a[i]:
      b[i] = 1
if b[0] == b[1] == b[2] == 1:
  print('Yes')
  exit()
if b[3] == b[4] == b[5] == 1:
  print('Yes')
  exit()
if b[6] == b[7] == b[8] == 1:
  print('Yes')
  exit()
if b[0] == b[3] == b[6] == 1:
  print('Yes')
  exit()
if b[1] == b[4] == b[7] == 1:
  print('Yes')
  exit()
if b[2] == b[5] == b[8] == 1:
  print('Yes')
  exit()
if b[0] == b[4] == b[8] == 1:
  print('Yes')
  exit()
if b[2] == b[4] == b[6] == 1:
  print('Yes')
  exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ans = -1e9;
  vector<vector<int>> F(N, vector<int>(10));
  REP(i, N) REP(j, 10) { cin >> F[i][j]; }
  vector<vector<int>> P(N, vector<int>(11));
  REP(i, N) REP(j, 11) { cin >> P[i][j]; }
  for(int bit = 1; bit < (1 << 10); bit++) {
    vector<int> c(N, 0);
    int tmp = 0;
    for(int i = 0; i < 10; i++) {
      if(bit & (1 << i)) {
        REP(j, N) {
          if(F[j][i] == 1) { c[j]++; }
        }
      }
    }
    REP(i, N) {
      tmp += P[i][c[i]];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
X,Y,Z,K = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
A = A[0:K]
B.sort(reverse=True)
B = B[0:K]
AB = [a+b for a in A for b in B]

AB.sort(reverse=True)

AB = AB[0:K]

C.sort(reverse=True)
C=C[0:K]
ABC = [ab+c for ab in AB for c in C]

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])


Measured memory_bytes: 161252
#include <stdio.h>
#include <queue>
using namespace std;

int main()
{
	const int INF = 10000000;
	int n, k, map[100][100], a, b, c;
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;

	while(true)
	{
		scanf("%d%d", &n, &k);
		if(n == 0 && k == 0)
			break;

		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
				map[i][j] = INF;
		}

		for(int g = 0; g < k; ++g)
		{
			scanf("%d", &a);
			if(a == 0)
			{
				//vZ
				int ans = -1;
				bool flag[100] = {};

				scanf("%d%d", &a, &b);
				q.push(pair<int, int>(0, a - 1));

				while(!q.empty())
				{
					pair<int, int> p = q.top();
					q.pop();
					int &cost = p.first, &num = p.second;
					if(flag[num])
						continue;
					flag[num] = true;

					if(num == b - 1)
					{
						ans = cost;
						for(int i = q.size(); i > 0; --i)
							q.pop();
						break;
					}

					for(int i = 0; i < n; ++i)
					{
						if(map[num][i] == INF || flag[i])
							continue;
						q.push(pair<int, int>(cost + map[num][i], i));
					}
				}

				printf("%d\n", ans);
			}
			else
			{
				//ÇÁ
				scanf("%d%d%d", &a, &b, &c);
				if(map[a - 1][b - 1] > c)
					map[a - 1][b - 1] = map[b - 1][a - 1] = c;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 872
S = input()
s = len(S)
n = 0
for i in range(s):
    n+= int(S[i])*(10**(s-1-i))*2**i
lis = []
for i in range(s-1):
    lis.append(2**i)
for i in range(s-1):
    for j in range(s-1-i):
        n += int(S[i])*(10**(s-2-i-j))*(lis[i+j])
print(n)

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

struct UnionFind {
    vector<int> p;
    UnionFind(int n) : p(n, -1) {};
    bool unite(int u, int v) {
        if ((u = root(u)) == (v = root(v))) return false;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v]; p[v] = u;
        return true;
    }
    bool find(int u, int v) { return root(u) == root(v); }
    int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); }
    int size(int u) { return -p[root(u)]; }
};

struct Edge {
    int src, dst, cost;
    Edge(int s, int d, int c) : src(s), dst(d), cost(c) {};
    bool operator<(const Edge& e) const {
        return cost < e.cost;
    }
};


int main() {
    int n, m;
    while (cin >> n >> m, n) {
        vector<Edge> es;
        rep(i, m) {
            int a, b, c; cin >> a >> b >> c;
            es.emplace_back(a, b, c);
        }
        sort(es.begin(), es.end());
        UnionFind uf(n);
        int tot = 0;
        for (auto&& e : es) {
            if (uf.unite(e.src, e.dst))
                tot += e.cost;
        }
        cout << tot << "\n";
    }
    return 0;
}


Measured memory_bytes: 3024
//
// ABC120B :
//
//


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;



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

	int count1=0;
	int max1=min(A,B);
	for(int i =max1; i>=1; i--) {

		if( A % i ==0 && B % i == 0) {
			count1++;
			if (count1==K) {
				cout << i << endl;
				break;
			}
		}
	}


	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

vector<int> f(int n) {
	ll p = 0;

	vector<int> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;

	for (int i = 2; i <= n; i++) {
		if (!isPrime[i]) {
			continue;
		}

		for (int j = 2 * i; j <= n; j += i) {
			isPrime[j] = false;
		}
	}

	vector<int> memo(n + 1);
	for (int i = 3; i <= n; i++) {
		memo[i] = isPrime[i] && isPrime[(i + 1) / 2];
	}
	for (int i = 1; i <= n; i++) {
		memo[i] += memo[i - 1];
	}

	return memo;
}

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


	const int N_MAX = (int)1e5 + 30;
	vector<int> memo = f(N_MAX);

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;

		cout << memo[r] - memo[l - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void){
    
    string s,t;
    
    cin >> s >> t;
    
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0])cout<<"YES";
    else cout<<"NO";
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int d = Integer.parseInt(str[1]);

		int ans = 0;
		for (int i = 0; i < n; i++) {
			str = br.readLine().split(" ");

			long x = Long.parseLong(str[0]);
			long y = Long.parseLong(str[1]);

			double dist = Math.sqrt(x * x + y * y);

			if (dist <= d) {
				ans++;
			}
		}

		System.out.println(ans);
	}
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#ifdef LOCAL
#define cerr cout
#else
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 200005;
int a[N], b[N];
const int M = 29;
vector<int> va[M][2], vb[M][2];
int main(){
	int n; sd(n);
	for(int i = 1; i <= n; i++){
		sd(a[i]);
		for(int j = 0; j < M; j++){
			va[j][a[i] >> j & 1].push_back(a[i] % (1 << j));
		}
	}

	for(int i = 1; i <= n; i++){
		sd(b[i]);
		for(int j = 0; j < M; j++){
			vb[j][b[i] >> j & 1].push_back(b[i] % (1 << j));
		}
	}

	for(int i = 0; i < M; i++)
		for(int j = 0; j < 2; j++)
			sort(vb[i][j].begin(), vb[i][j].end());
	ll ans = 0;
	for(int i = 0; i < M; i++){
		int ans1 = 0;
		for(int j = 0; j < 2; j++)
			for(int k = 0; k < 2; k++){
				int now = j ^ k;
				for(int t : va[i][j]){
					int num = upper_bound(vb[i][k].begin(), vb[i][k].end(), (1 << i) - 1 - t) - vb[i][k].begin();
					ans1 ^= ((num & 1) * now) & 1;
					ans1 ^= (((((int)vb[i][k].size()) - num) & 1) * (now ^ 1)) & 1;
				}
			}
			ans += ans1 << i;
	}
	printf("%lld\n", ans);
}

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

using namespace std;

using ll = long long;

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

    int a, b;
    cin >> a >> b;
    int m = a + b;
    cout << (m + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int aa,bb,cc,k;

bool calc(vector<int>const& status){
  int a=aa;int b=bb;int c=cc;
  rep(i,k){
    if(status[i]==0)a*=2;
    if(status[i]==1)b*=2;
    if(status[i]==2)c*=2;
  }
  return (b>a)&&(c>b);
}
bool rec(vector<int> status,int cur){
  if(cur==k)return calc(status);
  bool flag=rec(status,cur+1);
  status[cur]=1;
  flag=flag||rec(status,cur+1);
  status[cur]=2;
  flag=flag||rec(status,cur+1);
  return flag;
}
signed main(){
  cin>>aa>>bb>>cc;
  cin>>k;
  vector<int> status(k,0);
  bool flag=rec(status,0);
  	if(flag){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3628