akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))

cur_town = 1
visited = {1: 1}
before_loop = [1]
cnt = 2
while True:
    cur_town = A[cur_town - 1]
    if cur_town in visited:
        break
    visited[cur_town] = cnt
    before_loop.append(cur_town)
    cnt += 1

# loop に入る前の回数
before_loop_cnt = visited[cur_town] - 1
if K < before_loop_cnt:
    print(before_loop[K])
else:
    loop_lst = before_loop[visited[cur_town] - 1 :]
    print(loop_lst[(K - before_loop_cnt) % len(loop_lst)])

Measured memory_bytes: 38916
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s,t;
	cin>>s>>t;
	int res = 0;
	for(int i=0;i<3;i++)if(s[i]==t[i])++res;
	cout<<res<<endl;			
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
const int maxn = 30;
double a[maxn][maxn];

int n,d;
double dis(int i,int j)
{
    double ans = 0;
    double sum=0;
    for(int k=0;k<d;k++)
    sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
    ans = sqrt(sum);
    return ans;
}
int main()
{
    cin>>n>>d;
    for(int i=0;i<n;i++)
    for(int j=0;j<d;j++)
    cin>>a[i][j];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            double now = dis(i,j);
            if(now == (int)now)
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll m;
  cin >> m;
  ll k = 0, s = 0;
  rep(i, m) {
    ll d, c;
    cin >> d >> c;
    k += c;
    s += d * c;
  }
  cout << k - 1 + (s - 1) / 9 << endl;
}

Measured memory_bytes: 3588
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 1e6;

void solve(int tc)
{
	int n;
	cin >> n;
	v32 arr(n, 0);
	multiset<int> bst;
	int g = 0;
	for (int i = 0; i < n; i++)
		cin >> arr[i], g = __gcd(g, arr[i]), bst.insert(arr[i]);
	bool pairwise = true;
	bool setwise = (g == 1);
	int mx = *max_element(arr.begin(), arr.end());
	vector<int> ctr(mx + 1, 0);
	for (int i = 2; i < mx + 1; i++)
	{
		if (ctr[i])
			continue;
		int cnt = 0;
		for (int j = i; j < mx + 1; j += i)
		{
			cnt += bst.count(j);
			ctr[j]++;
			if (cnt > 1)
			{
				pairwise = false;
				break;
			}
		}
	}
	if (pairwise)
		cout << "pairwise coprime" << ln;
	else if (!pairwise && setwise)
		cout << "setwise coprime" << ln;
	else
		cout << "not coprime" << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 57844
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {
	int n, k[1005];
	cin >> n;
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	sort(k, k + n);
	cout << (k[n - 1] - k[0] + 1) / 2 << endl;
}


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

using namespace std;
int main(){
    string S;
    cin >> S;
    if(S=="SUN"){
        cout << "7" << endl;
    }

    if(S=="MON"){
        cout << "6" << endl;
    }

    if(S=="TUE"){
        cout << "5" << endl;
    }

    if(S=="WED"){
        cout << "4" << endl;
    }

    if(S=="THU"){
        cout << "3" << endl;
    }

    if(S=="FRI"){
        cout << "2" << endl;   
    }
    if(S=="SAT"){
        cout << "1" << endl;
    }
}

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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int N, A, B, C;
vector<int> L(10);

int dfs(int cur, int a, int b, int c){
    if(cur == N){
        if(a > 0 && b > 0 && c > 0) return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        else return INF;
    }
    int v1 = dfs(cur + 1, a, b, c);
    int v2 = dfs(cur + 1, a + L.at(cur), b, c) + 10;
    int v3 = dfs(cur + 1, a, b + L.at(cur), c) + 10;
    int v4 = dfs(cur + 1, a, b, c + L.at(cur)) + 10;
    return min(v1, min(v2, min(v3, v4)));
}

int main(){
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> L.at(i);
    int ans = dfs(0, 0, 0, 0);
    cout << ans << endl;    
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    repeat(h) {i->
        val idx = readLine()!!.split(' ').indexOf("snuke")
        if (idx != -1) {
            println("${'A' + idx}${i + 1}")
            return
        }
    }
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 100100;

int n, m;
int d[M];
bool u[M];
vector<int> g[M];

vector<int> dfs(int v) {
  if (d[v] >= 4) {
    return {v};
  }
  if (u[v]) return {};
  u[v] = true;
  
  vector<int> ans;
  for (int to : g[v]) {
    auto cur = dfs(to);
    for (int x : cur)
      ans.push_back(x);
  }
  return ans;
}

void read() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;

    g[u].push_back(v);
    g[v].push_back(u);

    d[u]++;
    d[v]++;
  }
}

void kill() {
  bool eul = true;
  int cnt6 = 0, cnt4 = 0;
  for (int v = 0; v < n; ++v) {
    eul &= d[v] % 2 == 0;
    if (d[v] >= 4)
      ++cnt4;
    if (d[v] >= 6)
      cnt6++;
  }

  if (eul) {
    if (cnt6 >= 1 || cnt4 >= 3) {
      cout << "Yes\n";
      return;
    } else if (cnt4 == 2) {
      for (int v = 0; v < n; ++v)
        if (!u[v] && d[v] == 2) {
          auto cur = dfs(v);
          assert(cur.size() == 2);
          if (cur[0] == cur[1]) {
            cout << "Yes\n";
            return;
          }
        }
    }
  }

  cout << "No\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 9216
N=int(input())
L=list(map(int,input().split()))
A=1
ANS=IND=0
while A!=0:
  A = 0
  for i in range(IND, N):
    if L[i] % 2 == 0 and A == 0:
      L[i] = L[i] // 2
      A = 1
      break
    else:
      IND += 1
  if A != 0:
  	ANS += 1
print(ANS)

Measured memory_bytes: 4148
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		if (n % i == 0 && n / i < 10) {
			dump("Yes");
			return 0;
		}
	}
	dump("No");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9 + 9;

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

	int n, a, b;
	cin >> n >> a >> b;

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

	auto ok = [&](int m) {
		auto t = h;
		rep(i, n) {
			t[i] -= m * b;
		}
		int s = (a - b);
		int c = m;
		rep(i, n) {
			if (t[i] > 0) {
				int a = (t[i] + s - 1) / s;
				c -= a;
			}
			if (c < 0) return false;
		}
		return true;
	};

	int l = 0, r = INF;
	while (r - l > 1) {
		int m = (r + l) / 2;
		if (ok(m)) {
			r = m;
		}
		else {
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}

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

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	map<int, int> cnt;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		cnt[a] += b;
	}

	for (auto i : cnt) {
		if (k <= i.second) {
			cout << i.first << endl;
			return;
		} else k -= i.second;
	}
}

// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

// COME ON DUDE .... GIVING UP NOT GONNA HELP
// JUST GET YOUR ASS TO WORK ALREADY ..


Measured memory_bytes: 7568
#include <iostream>
using namespace std;
int a[200005];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	if(m==1||m==2*n-1)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	a[n]=m;
	a[n-1]=m-1;
	a[n+1]=m+1;
	int now=0;
	for(int i=1;i<n*2;i++)
	{
		if(i==n||i==n-1||i==n+1)
			continue;
		++now;
		if(now==m-1)
			now=m+2;
		a[i]=now;
	}
	for(int i=1;i<n*2;i++)
		cout << a[i] << endl;
	return 0;
}

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

enum Suit
{
	Spade = 0,
	Club = 2,
	Diamond = 3,
	Heart = 1,
};

char SuitToString(int s) {
	switch (s)
	{
	case Spade:
		return 'S';
		break;
	case Heart:
		return 'H';
		break;
	case Club:
		return 'C';
		break;
	case Diamond:
		return 'D';
		break;
	default:
		break;
	}
}

int main()
{
	int n;
	bool c[4][13] = { false };

	cin >> n;
	for (int i = 0; i < n; i++) {
		char s;
		int m;
		cin >> s >> m;
		if (s == 'S') {
			c[Spade][m - 1] = true;
		}
		else if (s == 'C')
		{
			c[Club][m - 1] = true;
		}
		else if (s == 'D')
		{
			c[Diamond][m - 1] = true;
		}
		else
		{
			c[Heart][m - 1] = true;
		}
	}

	for (int j = 0; j < 4; j++) {
		for (int i = 0; i < 13; i++) {
			if (!c[j][i]) {
				cout << SuitToString(j) << " " << (i + 1) << endl;
			}
		}
	}
	return 0;

}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define N 123

using namespace std;

int v[N], n, m, total;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for(int i=0; i < n; ++i) {
        cin >> v[i];
        total += v[i];
    }
    sort(v, v + n, greater<int>());
    if(v[m - 1] * 4 * m < total) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val e = Array.ofDim[mutable.Set[Int]](N + 1)
    (0 until N - 1) foreach { _ =>
      val u = sc.nextInt()
      val v = sc.nextInt()
      if (e(u) == null) e(u) = mutable.Set.empty
      if (e(v) == null) e(v) = mutable.Set.empty
      e(u) += v
      e(v) += u
    }

    def findPath(s: Int, t: Int): Seq[Int] = {
      val INF = N + 10
      val d = Array.fill(N + 1)(INF)
      val q = mutable.PriorityQueue.empty[(Int, Int)](Ordering.by((_: (Int, Int))._1)) // (cost, 頂点)
      val prev = Array.fill(N + 1)(-1)

      d(s) = 0
      q.enqueue((0, s))

      while(q.nonEmpty) {
        val (cost, v) = q.dequeue()
        if (cost <= d(v)) {
          e(v).foreach { u =>
            if (d(u) > d(v) + 1) {
              d(u) = d(v) + 1
              prev(u) = v
              q.enqueue((d(u), u))
            }
          }
        }
      }

      def traceback(v: Int, end: Int, path: List[Int]): List[Int] = v match {
        case `end` => v :: path
        case _ => traceback(prev(v), end, v :: path)
      }

      traceback(t, s, Nil)
    }

    def delEdge(u: Int, v: Int): Unit = {
      e(u) -= v
      e(v) -= u
    }

    {
      val oneToN = findPath(1, N)
      val i = oneToN.length / 2 + (oneToN.length & 1) // １つ余ったら1寄りに分配する
      val (u, v) = (oneToN(i - 1), oneToN(i))
      delEdge(u, v)
    }


    val uf = new UnionFind(N + 1)
    e.indices foreach { v =>
      if (e(v) != null )
        e(v).foreach { u =>
          uf.unite(v, u)
        }
    }

    def countConnected(v: Int): Int = {
      val r = uf.find(v)
      ((1 to N) count (v => uf.find(v) == r)) - 1
    }

    val c1 = countConnected(1)
    val cN = countConnected(N)

    val winner = if (c1 > cN) "Fennec"
    else "Snuke"

    println(winner)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextChar(): Char = next.charAt(0)
  }

  class UnionFind(n: Int) {
    private val par = Array.iterate(0, n)(_ + 1)
    private val rank = Array.ofDim[Int](n)

    def find(x: Int): Int = {
      if (par(x) == x) x
      else {
        par(x) = find(par(x))
        par(x)
      }
    }

    def unite(x: Int, y: Int): Unit = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 != y1) {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += 1
        }
      }
    }
  }
}


Measured memory_bytes: 108264
from itertools import dropwhile
l=int(input())
k=[(l>>i & 1) for i in range(20)][::-1]
k=list(dropwhile(lambda x:x==0,k))
#print(k)
n=len(k)
path=[]
for i in range(n-1):
    path.append((i+1,i+2,0))
    path.append((i+1,i+2,2**i))

path_len=2**(n-1)
for i in range(1,n):
    if k[i]:
        x=n-1-i
        path.append((x+1,n,path_len))
        path_len+=(2**x)

m=len(path)
print(n,m)
for i in path:
    print(i[0],i[1],i[2])

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(p.rbegin(), p.rend());
  p[0] = p[0] / 2;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;



//62D
int main(void) {
	priority_queue<ll,vector<ll>,greater<ll>> f;
	priority_queue<ll,vector<ll>> b;
	ll n;
	vector<ll> as;
	vector<ll> f_ans, b_ans;
	std::cin >> n;
	ll fSum = 0, bSum = 0;
	rep(0, 3*n) {
		ll a;
		std::cin >> a;
		if (i < n) {
			f.push(a);
			
			fSum += a;
		}
		else if (i < 2 * n) {
			as.push_back(a);
		}
		else{
			b.push(a);
			bSum += a;
		}
	}

	f_ans.push_back(fSum);
	
	rep(0, n) {		
		f.push(as[i]);
		ll del = f.top();
		f.pop();
		fSum += as[i];
		fSum -= del;
		f_ans.push_back(fSum);
	}

	b_ans.push_back(bSum);
	for (ll i = n-1; i >= 0; i--) {
		b.push(as[i]);
		ll del = b.top();
		b.pop();
		bSum += as[i];
		bSum -= del;
		b_ans.push_back(bSum);
	}
	ll ans = -1 * pow(10, 14);
	reverse(b_ans.begin(), b_ans.end());
	rep(0, n+1) {
		ans = max(ans, f_ans[i] - b_ans[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4852
#include <iostream>

using namespace std;

int main() {
	int k, s; cin >> k >> s;
	int ans = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s - i - j <= k and s - i - j >= 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

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

signed main(){
	int n,d;
	cin>>n>>d;
	int s=n/(d*2+1);
	if(n%(d*2+1))s++;
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
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];
}
sort(a,a+n);
ll cnt=0;
ll sum=0;
for(ll i=0;i<n;i++){
if(sum+a[i]<=x){cnt++;}
sum+=a[i];
}
if(sum<x)cnt--;
cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*c, max(a*d, max(b*c, b*d))) << endl;
}


Measured memory_bytes: 3636
#include<bits/extc++.h>
#ifndef __unix__
#define getchar_unlocked _getchar_nolock
#endif
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(_n) for(int __i = _n;__i--;)
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define yn(i) ((i)?"Yes" : "No")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define multi int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
inline void read(char &a){static char p; while(isspace(p = getchar_unlocked())); a = p; }
inline void read(string &a){static char p; while(isspace(p = getchar_unlocked())); a = p; while(!isspace(p = getchar_unlocked()))a.push_back(p);}
template<typename T> inline void read(T& a){static char p; static bool b; while (!isdigit(p = getchar_unlocked()))b = p == '-'; a = p ^ '0'; while (isdigit(p = getchar_unlocked())) a *= 10, a += p ^ '0'; if(b)a *= -1; }
template<typename T1, typename T2> inline void read(pair<T1, T2> &a){read(a.first), read(a.second);}
template<typename T> inline void read(T begin, const T &end){while(begin != end)read(*begin), ++begin;}
inline void R(){} template<class T1, class... T2> inline void R(T1 &h, T2 &... e){read(h), R(e...);}
template<typename T> inline void write(T begin, const T &end){while(begin != end)cout << *begin << " \n"[next(begin) == end], ++begin;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 101*101;
int c[maxn][maxn], a[maxn], n, m, k;
struct it{
	int i = 0, j = 0, wi = 1;
	void operator++(){
		i += wi;
		if(i >= n || i < 0)i += -wi, wi *= -1, ++j;
	}
	void operator + (int v){
		c[i][j] = v;
		// dout(i),dout(j)<<'\n';
	}
};
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	R(n, m, k);
	read(a+1, a+1+k);
	it now;
	rep1(i, k){
		rep(a[i])now + i, ++now;
	}	
	rep0(i, n)rep0(j, m)cout << c[i][j] << " \n"[j == m-1];
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;
const int mo = 1000000007;

int n;
int a[N];

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	LL ans = 1; int d = 0;
	for (int i = 1; i <= n; i++) {
		d = max(d, i - 1 - (a[i - 1] + 1) / 2);
		ans = ans * (LL)(i - d) % mo;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;


ll i,j,k;


int main(){
   ll A,B,C,K;
   cin>>A>>B>>C>>K;
   ll cnt=0;
   ll point=0;
   point+=min(A,K);
   cnt+=min(A,K);
   cnt+=min(B,K-min(A,K));
   point+=(-K+cnt);
   cout<<point<<endl;

}


Measured memory_bytes: 3672
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <functional>
#define N 2020
using namespace std;

pair<int, int> a[N];
long long f[N][N];

int main(void)
{
    int n;
    int i, j;

    cin >> n;
    for(i = 1; i <= n; i ++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1, greater<pair<int, int> >());

    for(i = 1; i <= n; i ++)
        for(j = 0; j <= i; j ++)
        {
            if(j)
                f[i][j] = max(f[i][j], f[i - 1][j - 1] + (long long)a[i].first * (a[i].second - j));
            if(i - j)
                f[i][j] = max(f[i][j], f[i - 1][j] + (long long)a[i].first * (n + 1 - (i - j) - a[i].second));
        }
    cout << *max_element(f[n], f[n] + n + 1) << endl;

    return 0;
}


Measured memory_bytes: 26296
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
	int from,to;
	int cost;

	edge(int t,int c) : to(t),cost(c) {}
	edge(int f,int t,int c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

vector<edge> E;
int d[1005];

bool bellman_ford(int s, int n){
	fill(d,d+n,INF);
	d[s] = 0;
	int cnt = 0;

	while(true) {
		bool update = false;
		rep(i, E.size()) {
			edge e = E[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}

		if(!update) break;
		cnt++;
		if(cnt > n) {
			return false;
		}
	}

	return true;
}

bool find_negative_loop(int n) {
	memset(d,0,sizeof(d));
	
	rep(i,n) {
		bool update = false;
		rep(j,E.size()) {
			edge e = E[j];
			if(d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}

		cout << "I:" << i << endl;
		rep(j, n) {
			cout << d[j] << endl;
		}

		if(update && i == n-1) {

			cout << "---" << endl;
			return true;
		}
	}

	return false;
}

int main() {
	int n, m, r;
	cin >> n >> m >> r;

	rep(i, m) {
		int s, t, c;
		cin >> s >> t >> c;

		E.push_back(edge(s, t, c));
	}

	if(bellman_ford(r, n)) {
		rep(i, n){
			if(d[i] == INF) cout << "INF" << endl;
			else cout << d[i] << endl;
		}
	} else {
		cout << "NEGATIVE CYCLE" << endl;
	}


	// if(find_negative_loop(n)) {
	// 	cout << "NEGATIVE CYCLE" << endl;
	// } else {
	// 	bellman_ford(r, n);
	// 	rep(i, n) {
	// 		if(d[i] == INF) cout << "INF" << endl;
	// 		else cout << d[i] << endl;
	// 	}
	// }
	return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<cstdio>

using namespace std;
#define MAX 1000000

int main(){
  int i, n, a, b, cnt;
  bool prime[MAX];
  for(i = 0;i <= MAX; i++) prime[i] = true;
  prime[0] = prime[1] = false;
  
  for(i=2;i<MAX;i++){
    if(prime[i]){
      for(int j = i*2; j < MAX; j += i){
	prime[j] = false;
      }
    }
  }
  while(cin >> a >> b >> n, n != 0 ) {
    
    cnt = 0;
    for(i = a; i < MAX; i += b) {
      if(prime[i] == true)
	cnt++;
      if(cnt == n) break;
    }
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 2132
import sys
input=sys.stdin.readline
from collections import deque

def main():
    S=deque(input().strip())
    q=int(input())
    rev=0
    for _ in range(q):
        query=input().strip()
        if query=='1':
            rev^=1
        else:
            _,f,c=query.split()
            if (int(f)+rev)%2:
                S.appendleft(c)
            else:
                S.append(c)
    if rev:
        S.reverse()
    print(''.join(S))
    
if __name__=='__main__':
    main()

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

int firstdigit(long long int n){
    return n%10;
}

int lastdigit(long long int n){
    while(n>=10){
        n=n/10;
    }
    return n;
}

int main(){
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	cout.tie(NULL);
	
	long long int n;
	cin>>n;
	long long int arr[10][10];
	long long int i,j;
	for(i=0;i<=9;i++){
	    for(j=0;j<=9;j++){
	        arr[i][j]=0;
	    }
	}
	for(i=1;i<=n;i++){
	    long long int x,y;
	    x=firstdigit(i);
	    y=lastdigit(i);
	    arr[x][y]++;
	}
	
	long long int ans=0;
	for(i=0;i<=9;i++){
	    for(j=0;j<=9;j++){
	        ans=ans+(arr[i][j])*(arr[j][i]);
	        //cout<<i<<" , "<<j<<" : "<<arr[i][j]<<" , "<<arr[j][i]<<"\n";
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
// AOJ 0033
#include<cstdio>
#define rep( i, a ) for( int i = 0; i != (a); ++i )

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

	rep( i, N )
	{
		int l = 0, r = 0;
		bool fl = true;

		rep( j, 10 )
		{
			int a;
			scanf( "%d", &a );

			if( a > l && a > r )
			{
				if( l > r )
					l = a;
				else
					r = a;
			}
			else if( a > l )
				l = a;
			else if( a > r )
				r = a;
			else
				fl = false;
		}

		puts( fl ? "YES" : "NO" );
	}

	return 0;
}

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

int main(void){
  int n;
  int ans[5]={0};
  
  cin >> n;
  for (int i=0; i<n; i++){
    string s; cin >> s;
    for (int i=0; i<4; i++){
      if (s[0]=="AWTR"[i]) ans[i]++;
    }
  }
  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;
  
  return 0;
}

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

int main() {
    long long int L, R;
    std::cin >> L >> R;
    if(R - L >= 2019) {
        std::cout << 0 << std::endl;
    } else {
        int l0 = L%2019;
        int r0 = R%2019;
        int min = 2018;
        for(int i = l0; i < r0; ++i) {
            for(int j = i + 1; j < r0 + 1; ++j) {
                if((i * j)%2019 < min) {
                    min = (i * j)%2019;
                };
            }
        }
        std::cout << min << std::endl;
    }
}
            



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n, b, f, r, v;
    int room[5][4][11];  //わかりやすいように要素0番目はないものとして考える。
    cin >> n;
    for (int x=1; x<5; x++){
        for (int y=1; y<4; y++){
            for (int z=1; z<11; z++){
                room[x][y][z] = 0 ; //すべての部屋を0人に初期設定する
            }
        }
    }            
    for (int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        if (room[b][f][r] == 0){
            room[b][f][r] = v;
        } else{
            room[b][f][r] += v; 
        }
    }for (int x=1; x<5; x++){
        for (int y=1; y<4; y++){
            for (int z=1; z<11; z++){
                cout << " " << room[x][y][z] ;
            }cout << endl;
        }if (x!=4){
            cout << "####################" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
//JOI 2008??´???3??? ?????????

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define MAX -210000000
#define MIN 210000000

int a,b;
int d[1002],c[1001*1001],hk=0,mcunt,low,high;
int x,pr=0/*,flg[200000000]*/,m,ff=0;

int main(){ 
	
	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0){
		d[0]=0;
		hk=0;
		ff=0;
		pr=0;
		for(int i=1;i<=a;i++) scanf("%d",&d[i]);
		
		for(int i=0;i<=a;i++){
			for(int j=0;j<=a;j++){
				c[hk]=d[i]+d[j];
				hk++;
			}
		}
		sort(c,c+hk);									 
		for(int i=0;i<hk;i++){
			x=b-c[i];
			low=0;
			high=hk-1;
			while(low<=high){
				m=(low+high)/2;
				if(x==c[m]){
					ff=1;
					break;
				}
				if(x>c[m]) low=m+1;
				else if(x<c[m]) high=m-1;
			}
			if(ff==1){
				pr=c[i]+c[m];
				break;
			}
			if(b>c[i]+c[high] && pr<c[i]+c[high]){
				pr=c[i]+c[high];
			}
		}
		printf("%d\n",pr);
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf=1e15;
ll h,w,dis[510][510];
ll dy[4]={0,-1,0,1},dx[4]={1,0,-1,0};
char c[510][510];
ll dfs(ll sy,ll sx,ll gy,ll gx){
	queue<pair<ll,ll>> que;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)dis[i][j]=inf;
	que.push(pair<ll,ll>(sy,sx));
	dis[sy][sx]=0;
	while(!que.empty()){
		pair<ll,ll> now=que.front();
		que.pop();
		if(now.first==gy&&now.second==gx)break;
		for(int i=0;i<4;i++){
			ll ny,nx;
			ny=now.first+dy[i];
			nx=now.second+dx[i];
			if(nx>=0&&ny>=0&&ny<h&&nx<w&&c[ny][nx]=='.'&&dis[ny][nx]==inf){
				que.push(pair<ll,ll>(ny,nx));
				dis[ny][nx]=dis[now.first][now.second]+1;
			}
		}
	}
	return dis[gy][gx];
}
int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>c[i][j];
	ll ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int k=0;k<h;k++){
				for(int l=0;l<w;l++){
					if(c[i][j]=='.'&&c[k][l]=='.')ans=max(ans,dfs(i,j,k,l));
				}
			}
		}
	}
	cout<<ans;
	return 0;
}


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

int main() {
  string s, t;
  int ok=0;
  
  cin >> s >> t;
  for(int i=0; i<3; i++){
    if(s[i]==t[i]){
      ok++;
    }
  }
  cout << ok <<endl;
  return 0;
}


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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

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

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

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

int dfs(int x, int y, int dir, int target){
	int nx = x+dx[dir];
	int ny = y+dy[dir];
	if(nx < 0 or nx > 7 or ny < 0 or ny > 7) return -1;
	if(b[nx][ny] == 0) return -1;
	if(b[nx][ny] == -target) return 0;
	int ret = 0;
	ret = dfs(nx, ny, dir, target);
	if(ret == -1) return -1;
	return 1 + ret;
}

void update(int x, int y, vector<int> ds, int target){
	b[x][y] = -target;
  REP(i, ds.size()){
		int nx = x+dx[ds[i]]; int ny = y+dy[ds[i]];
		while(b[nx][ny] == target){
			b[nx][ny] = -target;
		 	nx += dx[ds[i]]; ny += dy[ds[i]];
		}
	}
	return;
}

int main() {
	REP(i, 8) { string str; cin >> str; REP(j, 8) { if(str[j] == '.') continue; b[i][j] = (str[j] == 'o' ? 1 : -1); } }
	int x = -1;
	int y = -1;
	bool bad = false;
	int taken = -1;
	while(true){
		int maxim = 0;
		vector<int> ds;
		REP(xx, 8) REP(yy, 8){
			int i, j;
			if(taken == -1) { i = xx; j = yy; }
			else { i = 7-xx; j = 7-yy; }
			if(b[i][j] != 0) continue;
			int count = 0;
			int total = 0;
			vector<int> dirs;
			REP(k, 8) { count = max(dfs(i, j, k, taken), 0); if(count) dirs.push_back(k); total += count; }
			if(total > maxim) { x=i; y=j; maxim=total; bad=false; ds = dirs; }
		}
 		if(maxim == 0) { if(bad) break; bad = true; }
		else update(x, y, ds, taken);
		taken = -taken;
	}
	string tmp;
	REP(i, 8) {
		REP(j, 8) {
			if(b[i][j] == 0) tmp = ".";
			if(b[i][j] == 1) tmp = "o";
			if(b[i][j] == -1) tmp = "x";
			cout << tmp; 
		}
		cout << endl;
 }
	return 0;
}

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

long int n,m,used[100001]={0},a[100001]={0};

int cmp(const void* x, const void* y) {
	long int a = *(const long int*)x, b = *(const long int*)y;
	return a > b ? -1 : a < b;
}

/*
void quicksort(long int* number,long int first,long int last){
    long int i, j, pivot, temp;

    if(first<last){
        pivot=first;
        i=first;
        j=last;
        
        while(i<j){
            while(number[i]>=number[pivot]&&i<last)
                i++;
            while(number[j]<number[pivot])
                j--;
            if(i<j){
                temp=number[i];
                number[i]=number[j];
                number[j]=temp;
            };
        };
        
        temp=number[pivot];
        number[pivot]=number[j];
        number[j]=temp;
        quicksort(number,first,j-1);
        quicksort(number,j+1,last);
    };
};
*/

void display_scores(void){
    long int i,j;
    printf("   |");
    for(i=1;i<=n;i++){
        printf("%7ld    ",i);
    };
    printf("\n---+");
    for(i=1;i<=n;i++){
        printf("-----------");
    };
    printf("\n");
    for(j=1;j<=n;j++){
        printf("%2ld |",j);
        for(i=1;i<j;i++){
            printf("        ");
        };
        for(i=1;i<=n;i++){
            if(i<=used[j])putchar('*');else putchar(' ');
            printf("%-10ld",a[i]+a[j]);
        };
        printf("\n");
    };
    return;
};

long int count_larger_combintion(long int x){
    long int low,high,mid,i,j,ans=0,prev_threshold;
    prev_threshold=n;
    for(i=1;i<=n;i++){
        low=1;
        high=prev_threshold;
        if(a[i]+a[1]<x){
            for(j=i;j<=n;j++) used[j]=0;
            return ans;
        };
        if(a[i]+a[high]>=x){
            used[i]=high;
            ans+=high;
            continue;
        };
        while(high-low>1){
            mid=(high+low)/2;
            if(a[i]+a[mid]>=x){
                low=mid;
            }else{
                high=mid;
            };
        };
        ans+=low;
        used[i]=low;
        prev_threshold=low;
    }
    return ans;
};


int main(void){
    long int i,xlow, xhigh, x,larger_num=0,threshold;
    long int sum[100001],ans=0;
    scanf("%ld %ld",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%ld",&a[i]);
    };
    //quicksort(a,1,n);
    qsort(&a[1],n,sizeof(a[1]),cmp);
    xlow=2*a[n];
    xhigh=2*a[1];
    while(larger_num!=m && xhigh-xlow>1){
        x=xlow+(xhigh-xlow)/2;
        larger_num=count_larger_combintion(x);
        if(larger_num>=m) xlow=x;
        if(larger_num<m) xhigh=x;
        //printf("x=%d, num=%d\n",x,larger_num);
        //display_scores();
    };
    threshold=xlow;
    //printf("result: threshold=%d\n",threshold);
    sum[1]=a[1];
    for(i=2;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    };
    for(i=1;i<=n;i++){
        ans+=a[i]*used[i]+sum[used[i]];
    };
    ans-=(larger_num-m)*threshold;
    printf("%ld",ans);
    return 0;
};


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

class bipartite_matching {
public:
    int n;
    vector<vector<int>> g;
    vector<int> match;

    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for(int v = 0; v < n; ++v){
            if (match[v] < 0) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }

private:
    vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u: g[v]) {
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w))) {
                match[v] = u; match[u] = v;
                return true;
            }
        }
        return false;
    }
};

int N,M,L;
int mat[110][110];
pair<int,int> node[1010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> N >> M >> L && N){
        rep(i,N)rep(j,N) mat[i][j] = (i == j ? 0 : INF);
        rep(i,M){
            int u,v,d;
            cin >> u >> v >> d;
            mat[u][v] = mat[v][u] = d;
        }
        rep(k,N)rep(i,N)rep(j,N) mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j]);
        rep(i,L) cin >> node[i].second >> node[i].first;
        sort(node, node+L);

        bipartite_matching bm(L*2);

        rep(i,L)rep(j,i){
            int dt = node[i].first - node[j].first;
            int dist = mat[node[i].second][node[j].second];
            if(dt >= dist){
                bm.add_edge(j, i+L);
            }
        }

        int f = bm.maximum_matching();
        cout << L-f << '\n';
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;i++){cin >> A[i]; p[i]=make_pair(A[i],i+1);}
  sort(p.begin(),p.end());
  for(int i=0;i<N;i++){cout << p[i].second << " ";}
}

Measured memory_bytes: 2048
s = input().split()
for j in range(len(s)):
  for k in range(j-1,-1,-1):
    if s[k] >= s[k+1]:
      s[k],s[k+1] = s[k+1],s[k]
a = int(s[0])
b = int(s[1])
c = int(s[2])
print(a,b,c)



Measured memory_bytes: 5596
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var ST = ReadLine().Split(' ');
        var (S, T) = (ST[0], ST[1]);
        var AB = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (A, B) = (AB[0], AB[1]);
        var U = ReadLine();

        if (U == S)
            A--;
        else
            B--;

        WriteLine($"{A} {B}");
    }
}


Measured memory_bytes: 28260
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value


void solve() {

	int A, B;
	cin >> A >> B;

	if (A >= 13) cout << B << endl;
	else if (A >= 6) cout << B / 2 << endl;
	else cout << 0 << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
import math
def sosu(x):
    if x == 1:
        return False
    for i in range (2, int(math.sqrt(x))+1):
        if x % i == 0:
            return False
    return True

while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for i in range(n+1, 2*n+1):
        if sosu(i):
            a.append(i)
    print(len(a))


Measured memory_bytes: 5976
/*
   Username : moondancer
   Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod=1e9+7;

int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    t=(t*t)%p;
    if(b%2)return (a*t)%p;
    return t;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    int t1=pw(10,n,mod);
    int t2=pw(9,n,mod);
    int t3=pw(8,n,mod);
    t1=(t1-2*t2)%mod;
    t1=(t1+mod)%mod;
    t1=(t1+t3)%mod;
    cout<<t1;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int main(){
	int n,a,b=1;cin>>n;
	for(int i=0;i<n;i++)cin>>a,b=lcm(a,b);
	cout<<b<<"\n";
	return 0;
}


Measured memory_bytes: 3104
N,X=map(x->parse(Int,x),split(readline()))
A=map(x->parse(Int,x),split(readline()))
ans=0
if A[1]>X
  ans+=A[1]-X
  A[1]=X
end
for i=2:N
  if A[i-1]+A[i]>X
    ans+=A[i-1]+A[i]-X
    A[i]=X-A[i-1]
  end
end
println(ans)

Measured memory_bytes: 141184
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    string s;
    cin >> s;
    string s2;
    for(char c: s) {
        if (c == 'T') {
            if (!s2.empty() && s2.back() == 'S')
                s2.pop_back();
            else
                s2 += c;
        } else {
            s2 += c;
        }
    }
    cout << s2.size() << endl;

    return 0;
}



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

int two(int K, int S){
    if(2 * K < S) return 0;
    if(S <= K) return S+1;
    return 2 * K - S + 1;
}

// int main(){
//     int K, S;
//     int cnt=0;
//     cin >> K >> S;
//     for(int i=0;i<=K;++i){
//         cnt += two(K, S-i);
//     }
//     cout << cnt << endl;
// }

int main(){
    int K, S;
    int cnt=0;
    cin >> K >> S;
    for(int i=0;i<=K;++i){
        for(int j=0;j<=K && i+j<=S;++j){
            int k = S - i - j;
            if(0 <= k && k <= K){
                ++cnt;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main (void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	int now = 1, ans = 0;
	while(now<b)
	{
		now = now + a - 1;
		++ans;
	}
	printf("%d\n", ans);
	return 0;
}

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


int R, C, m, cnt, x, y;
bool b[10][10000];

int main(void) {
  while(cin >> R >> C, !(R == 0 && C == 0)) {
    REP(i, 0, R) REP(j, 0, C) cin >> b[i][j];

    m = 0;
    REP(i, 0, 1 << R) {
      cnt = 0;
      REP(j, 0, C) {
        x = y = 0;
        REP(k, 0, R) {
          if(i & (1 << k)) {
            b[k][j] ? y++ : x++;
          } else {
            b[k][j] ? x++ : y++;
          }
        }
        cnt += max(x, y);
      }
      m = max(m, cnt);
    }

    cout << m << endl;
  }

  return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2 ;
    //cout << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl;
    printf("%.5f\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}


Measured memory_bytes: 3212