akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){//тоже не работает
	int n,c=-1;
	scanf("%d",&n);
	int i,j,a[n],b[n],left,right;
	for (i=0;i<n;i++) scanf("%d",&a[i]);
	for (i=0;i<n;i++) scanf ("%d",&b[n-1-i]);
	for(i=0;i<n;i++)
		if (a[i]==b[i]){
			c=a[i];
			left=i;
			break;
		}
	if (c==-1) goto mark;
	for (i=n-1;i>=0;i--)
		if (a[i]==b[i]){
			right=i;
			break;
		}
	for (i=0;i<n;i++){
		if(a[i]!=c&&b[i]!=c&&left<=right){
			j=b[i];
			b[i]=b[left];
			b[left]=j;
			left++;
		}
	}
	if (left<=right){
		printf("No\n");
		return 0;
	}
	else {
mark:		printf("Yes\n");
		for (i=0;i<n;i++) printf("%d ",b[i]);
		printf("\n");
		return 0;
	}
}


Measured memory_bytes: 3272
#143_D
from bisect import bisect_left
n = int(input())
l = sorted(list(map(int, input().split())))

res = 0
for i in range(n):
    for j in range(i+1, n):
        res += max(bisect_left(l,l[i]+l[j]) - j - 1, 0)
        
print(res)

Measured memory_bytes: 3188
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;

fn main() {
	let stdin = stdin();
	let mut reader = InputScanner::new(stdin.lock(),256);

	let h:usize = reader.next();

	let mut heap:Vec<i64> = Vec::with_capacity(h+1);
	heap.resize(h+1, 0);

	for i in 1..(h+1) {
		heap[i] = reader.next();
	}

	for i in 1..(h+1) {
		print(&heap,i);
	}
}
fn print(heap:&Vec<i64>, i:usize) {
	let mut s:String = String::new();

	s.push_str(format!("node {}: key = {}, ",i,heap[i]).as_str());

	if i/2 > 0 {
		s.push_str(format!("parent key = {}, ",heap[i/2]).as_str());
	}

	if 2*i < heap.len() {
		s.push_str(format!("left key = {}, ", heap[2*i]).as_str());
	}

	if 2*i+1 < heap.len() {
		s.push_str(format!("right key = {}, ", heap[2*i+1]).as_str());
	}

	print!("{}\n",s);
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



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

int main() {
  cout << setprecision(15);
  char s[2000000];
  scanf("%s", s);
  int ans = 0;
  const int n = strlen(s);
  for (int length = 1; length <= 2; ++length) {
    if (n - length <= ans) break; 
    int prev_length = length;
    int count = 1;
    for (int j = length; j < n; ) {
      if (prev_length == 1 && s[j] == s[j-1]) {
        if (j > n - 2) break;
        j += 2;
        prev_length = 2;
        count++;
        continue; 
      }
      prev_length = 1;
      j++;
      count++;
    } 
    ans = max(ans, count);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        while(true) {
        	for (int i = 0; i < N; i++) {
            	if (map[i] % 2 != 0) {
            		System.out.println(count);
            		return;
            	} else {
            		map[i] /=2;
            	}
            }
        	count++;
        }
        
    }
    
}

Measured memory_bytes: 23764
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        for (int i = a; i < a+k; i++) {
            if (i > b) break;
            System.out.println(i);
        }

        for (int i = b-k+1; i <= b; i++) {
            if (i < a+k) continue;
            System.out.println(i);
        }
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string s;

    cin >> s;

    int n = s.size();
    long long result = 0;

    for (int i = 0; i < n-1; ++i) {
        for (int j = 0; j < n-i; ++j) {
            if (j == 0 || j == n-i-1) {
                result += stoll(s.substr(j, i+1)) * pow(2, n-i-2);
            } else {
                result += stoll(s.substr(j, i+1)) * pow(2, n-i-3);
            }
        }
    }

    result += stoll(s);

    cout << result << endl;
}


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

int main(){
    int c[3][3];
    string ans = "Yes";
    rep(i,3){
        rep(j,3)cin >> c[i][j];
    }

    int x[3], y[3];
    x[0] = 0;
    rep(i,3)y[i] = c[0][i] - x[0];
    rep(i,3)x[i] = c[i][0] - y[0];

    rep(i,3){
        rep(j,3){
            if(c[i][j] != x[i] + y[j])ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

int main() {
    int N, i, j;
    scanf("%d", &N);
    int h[N], sorted[N+1];
    for (i = 0; i < N; i++) scanf("%d", &h[i]);
    memcpy(sorted, h, sizeof(int)*(size_t)N);
    sorted[N] = 0;
    std::sort(sorted, sorted+N+1);
    int sum=0, count;
    bool cut;
    for (i = 0; i < N; i++) {
        cut = true;
        count = 0;
        for (j = 0; j < N; j++) {
            if (h[j] - sorted[i] <= 0)
                cut = true;
            else if (cut) {
                cut = false;
                count++;
            }
        }
        sum += count * (sorted[i+1] - sorted[i]);
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n,m;
  cin>>n>>m;
  if(n==m) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

//nを2進数展開してarrに入れる
void binary(int n, int roop, bool arr[]){
  rep(i, roop){
    if(n!= 0){
      arr[i] = n%2;
      n /= 2;
    }
    else
      arr[i] = 0;
  }
  arr[roop] = 0;
}


int main(){
  string S;
  cin >> S;
  //ここまで入力
  
  long long ans = 0;
  
  //+を挿入することのできる場所の数
  int psize = S.size()-1;

  //+をi番目のスペースに入れるか入れないか
  bool pflag[psize]; 

  rep(i, pow(2, psize) ){
    vector<char> str;
    binary(i, psize, pflag);
    rep(j, psize+1){
      //数字追加
      str.push_back(S[j] );
      //フラッグに従って+を追加
      if(pflag[j] == true)
	str.push_back('+');
    } //j

    //10の累乗を制御
    int count = 0;
    
    for(int j=str.size()-1; j>=0; j--){
      //1の位から順に足していく
      if(str[j] != '+')
	ans += (long long)(str[j]-'0')*pow(10, count++);
      //+が来たら累乗カウントのリセット
      else
	count = 0;
    } //j
  } //i

  cout << ans << endl;

  return 0;
}


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

int main()
{
    int n;
    int graph[105][105] = {};

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        int u, k;
        cin >> u >> k;
        for ( int j = 0; j < k; j++ ) {
            int v;
            cin >> v;
            graph[u][v] = 1;
        }
    }
    
    for ( int i = 1; i <= n; i++ ) {
        cout << graph[i][1];
        for ( int j = 2; j <= n; j++ ) {
            cout << " " << graph[i][j];
        }
        cout << endl;
    }

    return ( 0 );
}



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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

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

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

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
int inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n;


//inputします
void input() {
    cin >> n;

}

//ライブラリ置き場

//main
int main() {
    input();
    vector<int> pp(n);
    vector<int> qq(n);
    ff(i, 0, n) {
        cin >> pp[i];
    }
    ff(i, 0, n) {
        cin >> qq[i];
    }
    vector<int> aa;
    ff(i, 1, n+1) {
        aa.push_back(i);
    }
    int now = 0;
    int a, b;
    do {
      now++;
        if (aa == pp) {
            a = now;
        }
        if (aa == qq) {
            b = now;
        }
    } while (next_permutation(aa.begin(), aa.end()));
    cout << abs(b - a) << endl;
	return 0; 
}

Measured memory_bytes: 256
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let n: usize = read!();
    let mut b:usize = 0;
    let mut c:usize = 0;
    let g: &str = "R";
    let r: Vec<char> = g.chars().collect();
    let gg: &str = "W";
    let w: Vec<char> = gg.chars().collect();
    let a: String = read!();
    let mut v: Vec<char> = a.chars().collect();
    for i in 0..n {
        if v[i] == w[0] {
            b += 1;
        }
    }
    for i in 0..b {
        if v[n-i-1] == r[0] {
            c+=1;
        }
    }
println!("{}",c);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> UT(N);
  int sum = 0;
  for (int &e : UT) {
    cin >> e;
    sum += e;
  }
  
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int Q, T;
    cin >> Q >> T;
    cout << sum + T - UT[Q-1] << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int n;  cin >> n;
    int ans = 1;
    for (ans = 1; ans <= 500000; ans++) {
        if (ans * 108 / 100 == n) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
class Dice {
  public:
    int dev[6],arr[6][4] = {{1,2,4,3},{2,0,3,5},{0,1,5,4},{4,5,1,0},{5,3,0,2},{3,4,2,1}};
    void setNum(int i, int num) {
      dev[i] = num;
    }
    int search(int num, int *array, int arrsize) {
      for (int i = 0; i < arrsize; i++) {
        if (num == array[i]) return i;
      }
    }
    int right(int top, int front) {
      front = search(front, dev, 6);
      top = search(top, dev, 6);
      int tmp = search(front, arr[top], 4);
      if (tmp == 3) tmp = arr[top][0];
      else tmp = arr[top][tmp+1];
      return dev[tmp];
    }
};

int main() {
  int foo,num,a,b;
  Dice dice;
  for (int i = 0; i < 6; i++) {
    scanf("%d", &foo);
    dice.setNum(i,foo);
  }
  scanf("%d", &num);
  for (int j = 0; j < num; j++) {
    scanf("%d %d", &a, &b);
    printf("%d\n", dice.right(a, b));
  }
  return 0;
}



Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ul = uint32_t;
using ull = uint64_t;
using l = int32_t;
using ll = int64_t;
using namespace std;

int main() {
    fastIO;

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    if (a >= k) {
        cout << k;
        return 0;
    }
    sum += a;
    k -= a;

    if (b >= k) {
        cout << sum;
        return 0;
    }
    sum += 0;
    k -= b;

    if (c == k)
        cout << sum - c;
    else
        cout << sum - k;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353
//https://naoyat.hatenablog.jp/entry/k-dimension-manhattan-distance
int N;
int x[200005],y[200005];
int fx[200005],fy[200005];
signed main(){
    scanf("%lld",&N);
    int fxmax=-LLINF,fxmin=+LLINF;
    int fymax=-LLINF,fymin=+LLINF;
    rep(i,N){
        scanf("%lld %lld",&x[i],&y[i]);
        fx[i]=x[i]-y[i];
        fy[i]=x[i]+y[i];
        fxmax=max(fxmax,fx[i]);
        fxmin=min(fxmin,fx[i]);
        fymax=max(fymax,fy[i]);
        fymin=min(fymin,fy[i]);
    }
    int ans=0;
    ans=max(ans,fxmax-fxmin);//d=0
    ans=max(ans,fymax-fymin);//d=1
    //printf("%lld %lld %lld %lld\n",fxmax,fxmin,fymax,fymin);
    printf("%lld\n",ans);
}

Measured memory_bytes: 7984
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}
 
void solve() {
    int w, h;
    cin >> w >> h;
    vector<ll> p(w);
    REP(i, w) cin >> p[i];
    vector<ll> q(h);
    REP(i, h) cin >> q[i];
    sort(ALL(p)); 
    sort(ALL(q));

    int c = 0;
    int r = 0;
    ll ans = 0;
    while (c < w && r < h) {
        if (p[c] > q[r]) {
            ans += q[r] * (w + 1 - c);
            r++;
        } else {
            ans += p[c] * (h + 1 - r);
            c++;
        }
    }
    if (c == w) {
        FOR(i, r, h) {
            ans += q[i];
        }
    } else {
        FOR(i, c, w) {
            ans += p[i];
        }
    }
    cout << ans << EOL;

}



Measured memory_bytes: 1792
using System;
using System.Linq;

// https://atcoder.jp/contests/abc123/tasks/abc123_c
namespace CFiveTransportations
{
    class Program
    {
        static void Main(string[] args)
        {
            const int Transportations = 5;
            // 入力の取得
            var n = long.Parse(Console.ReadLine());
            var capacities = new long[Transportations];
            for (var i = 0; i < Transportations; i++)
            {
                capacities[i] = long.Parse(Console.ReadLine());
            }

            // すべての交通手段の所要時間が1minなため、それぞれの収容人数によってボトルネックが決まる
            var bottleneck = capacities.Min();
            var bottleneckRequiredTime = (long)Math.Ceiling((double)n / bottleneck);
            var allRequiredTime = Transportations + bottleneckRequiredTime - 1;

            // 解答の出力
            Console.WriteLine(allRequiredTime);
        }
    }
}


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

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

  ll n;
  cin >> n;
  ll dc = 0, ds = 0;
  for (int i = 1; i <= n; i++) {
    ll a, b;
    cin >> a >> b;
    dc += b;
    ds += a * b;
  }

  cout << dc - 1 + (ds - 1) / 9 << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int a, b; cin >> a >> b;
    if(a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7696
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	final int INF = Integer.MAX_VALUE;

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] w = new int[n];
		int[] a = new int[n];
		int[] _a = new int[n];
		int[] rank = new int[n];
		for (int i = 0; i < n; i++)
			rank[i] = INF;
		for (int i = 0; i < n; i++)
			a[i] = w[i] = scan.nextInt();
		Arrays.sort(a);
		int min = a[0];
		for (int i = 0; i < n; i++)
			_a[i] = Arrays.binarySearch(a, w[i]);
		if (DEBUG) {
			System.out.println(Arrays.toString(w));
			System.out.println(Arrays.toString(_a));
			System.out.println(Arrays.toString(a));
		}
		int index = 0;
		for (int i = 0; i < n; i++) {
			int idx = i;
			if (rank[i] != INF)
				continue;
			while (rank[i] == INF) {
				rank[_a[idx]] = index;
				idx = _a[idx];
			}
			index++;
		}
		if (DEBUG)
			System.out.println(Arrays.toString(rank));
		HashMap<Integer, LinkedList<Integer>> map = new HashMap<Integer, LinkedList<Integer>>();
		for (int i = 0; i < n; i++) {
			LinkedList<Integer> list = map.get(rank[i]);
			if (list == null) {
				LinkedList<Integer> l = new LinkedList<Integer>();
				l.add(w[i]);
				map.put(rank[i], l);
			} else {
				list.add(w[i]);
				map.put(rank[i], list);
			}
		}
		if (DEBUG) {
			System.out.println(map.size());
			for (int i = 0; i < map.size(); i++) {
				LinkedList<Integer> list = map.get(i);
				System.out.println("map " + i + ": " + list.toString());
			}
		}
		int ans = 0;
		for (int i = 0; i < map.size(); i++) {
			LinkedList<Integer> list = map.get(i);
			if (list.size() == 1)
				continue;
			int sum = 0;
			int m = INF;
			int length = list.size();
			for (int j = 0; j < length; j++) {
				int num = list.get(j);
				sum += num;
				m = Math.min(m, num);
			}
			if (DEBUG)
				System.out.println(sum + " " + m + " " + ((length + 1) * min));
			ans += Math.min(sum + (length - 2) * m, sum + m + (length + 1) * min);
		}
		System.out.println(ans);
	}

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



Measured memory_bytes: 31776
#include<stdio.h>

#define N_MAX 1000

void swap(int *x, int *y) {
	int temp = 0;

	temp = *x;
	*x = *y;
	*y = temp;
}

void quick_sort(int array[], int left, int right) {
	int l = left, r = right;
	int p = 0;
	p = array[(left + right) / 2];
	
	while (1) {
		while (array[l] < p) {
			l++;
		}
		while (p < array[r]) {
			r--;
		}
		if (r <= l) { break; }
		swap(&array[l], &array[r]);
		l++;
		r--;
	}

	if (left < l - 1) {
		quick_sort(array, left, l - 1);
	}
	if (right > r + 1) {
		quick_sort(array, r + 1, right);
	}

}

void print_array(int array[], int len) {
	for (int i = 0; i < len; i++) {
		printf("%d ", array[i]);
	}
	printf("\n");

}

int main(void)
{
	int n = 0, k = 0;
	scanf("%d%d", &n, &k);
	//printf("n = %d k = %d\n", n, k);

	int p[N_MAX];
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	//print_array(p, 0, n - 1);

	quick_sort(p, 0, n - 1);
	//print_array(p, n);

	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  s.erase(unique(all(s)),s.end());

  //現状の幸せの人の人数
  int cnt = n - s.size();

  int ans = min(cnt+2*k, n-1);
  std::cout << ans << '\n';
}


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

#define min(a, b) ((a) < (b))?(a):(b)

#define INF 1001001001

struct list {
	int item;
	struct list * next;
} **to;

void initializeList(int n)
{
	int i;
	for (i = 0; i < n; i++) {
		to[i] = NULL;
	}
}

struct list *insertList(struct list *p, int x)
{

	struct list *q;
	q = (struct list *)malloc(sizeof(struct list));
	q->item = x;
	q->next = p;
	
	return q;
}

struct queue {
	int item;
	struct queue *next;
} *head, *tail;

void initializeQueue(void)
{
	head = tail = (struct queue *)malloc(sizeof(struct queue));
}

void addQueue(int x)
{
	tail->item = x;
	tail->next = (struct queue *)malloc(sizeof(struct queue));
	tail = tail->next;
}

int removeQueue(void)
{
	int x;
	struct queue *p;
	p = head;
	head = p->next;
	x = p->item;
	free(p);
	return x;
}

int main()
{
	int ret, i, n, m;
	int a, b;
	int *prev;
	int *dist;
	int v, u;
	struct list *pu;
	int ans;
	
	ret = scanf("%d %d", &n, &m);

	to = (struct list **)malloc(sizeof(struct list*)*n);
	for (i = 0; i < n; i++)
		to[i] = (struct list *)malloc(sizeof(struct list)*n);
	initializeList(n);
	
	prev = (int *) malloc(sizeof(int)*n);
	for (i = 0; i < n; i++)
		prev[i] = -1;
	dist = (int *) malloc(sizeof(int)*n);
	for (i = 0; i < n; i++)
		dist[i] = INF;
	
	for (i = 0; i < m; i++) {
		ret = scanf(" %d %d", &a, &b);
		--a;
		--b;
		to[a] = insertList(to[a], b);
		to[b] = insertList(to[b], a);
	}

	initializeQueue();
	dist[0] = 0;
	addQueue(0);
	do {
		v = removeQueue();
		for (pu = to[v]; pu != NULL; pu = pu->next) {
			u = pu->item;
			if (dist[u] !=INF) continue;
			dist[u] = dist[v]+1;
			prev[u] = v;
			addQueue(u);
		}
	} while(head != tail);
	
	printf("Yes\n");
	for (i = 0; i < n; i++) {
		if (i == 0) continue;
		ans = prev[i];
		++ans;
		printf("%d\n", ans);
	}
	
	fflush(stdout);
	free(prev);
	free(dist);
	for (i=0;i<n;i++)
		free(to[i]);
	free(to);
	return EXIT_SUCCESS;
}


Measured memory_bytes: 723668
#include<bits/stdc++.h>
using namespace std;
int arr[100005][3],dp[100005][3];
int main()
{
    int n,i,j;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }


    int ans[3]={0,0,0};
    for(i=1;i<=n;i++){
        for(j=0;j<3;j++){
            if(j==0) dp[i][j]=max(dp[i-1][1],dp[i-1][2])+arr[i][j];
            if(j==1) dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][j];
            if(j==2) dp[i][j]=max(dp[i-1][0],dp[i-1][1])+arr[i][j];

            }
        }

    printf("%d\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
}


Measured memory_bytes: 2560
n = gets.to_i
p = gets.split.map(&:to_i)
q = gets.split.map(&:to_i)

i = 0
p_i,q_i = nil,nil
ary = (1..n).to_a.permutation(n)
ary.each_with_index do |item,i|
  p_i = i if item == p
  q_i = i if item == q
end

puts (p_i-q_i).abs


Measured memory_bytes: 2172
import math
n=int(input())
m=math.floor(math.sqrt(n))
i=1
bk=[0,0]
while i<=m:
  wk=n/i
  if math.floor(wk)==math.ceil(wk):
    bk[0]=wk
    bk[1]=i
  i+=1
next
print(math.floor(sum(bk))-2)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[] s = S.toCharArray();
    ArrayList<Character> b = new ArrayList<>();
    
    for(int i = 0; i < s.length; i++){
      if(s[i] == '0'){
        b.add('0');
      }else if(s[i] == '1'){
        b.add('1');
      }else{
        if(b.size() != 0){
           b.remove(b.size()-1);
        }else{
          continue;
        }
      }
    }

    for(int i = 0; i < b.size(); i++){
      System.out.print(b.get(i));
    }
     
    System.out.println();
  }  
}

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

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

    int n, q;
    cin>>n>>q;

    vector<long long> ops;
    ops.push_back(n);
    for (int i=1; i<=q; i++) {
        long long x;
        cin>>x;
        while(ops.size() && ops.back() > x) ops.pop_back();
        ops.push_back(x);
    }

    long long sz = ops.back();
    map<long long, long long> mp;
    mp[sz] = 1;

    reverse(ops.begin(), ops.end());

    for (long long x: ops) {
        while(mp.rbegin()->first > x) {
            auto it = mp.end(); it--;
            long long u = it->first;
            long long cnt = it->second;
            mp[x] += (u/x)*cnt;
            if (u%x)    mp[u%x] += cnt;
            mp.erase(it);
        }
    }

    for (int i=n; i>0; i--) mp[i] += mp[i+1];

    for (int i=1; i<=n; i++)    cout<<mp[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 10324
n = int(input())
s = []
count = 0
boa = 0
boo = 0
ooa = 0
for _ in range(n):
  i = input()
  s += [i]
  l = len(i)
  for k in range(l-1):
    if i[k:k+2] == 'AB':
      count += 1
  if i[0] == 'B' and i[-1] == 'A':
    boa += 1
  elif i[0] == 'B':
    boo += 1
  elif i[-1] == 'A':
    ooa += 1
if boo==0 and ooa==0 and boa!=0:
  rest = boa-1
else:
  rest = boa + min(boo,ooa)
print(count+rest)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define ll unsigned long long
#define endl '\n'

using namespace std;

ll n;

ll ans;

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

    cin >> n;
    for(ll i=1; i <= n; ++i) {
        if(i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
from math import sqrt
while 1:
    n = input()
    if n == 0:
        break
    C = [map(int, raw_input().split()) for i in xrange(n)]
    P = [[C[0][:2]]]
    for i in xrange(n-1):
        x0, y0, r0 = C[i]
        x1, y1, r1 = C[i+1]
        rr = (x1 - x0)**2 + (y1 - y0)**2; rd = sqrt(rr)
        rc = (r0**2 + rr - r1**2) / (2 * rd); rs = sqrt(4*r0**2*rr - (r0**2 + rr - r1**2)**2) / (2 * rd)
        ex = (x1 - x0) / rd; ey = (y1 - y0) / rd
        bx = x0 + ex * rc; by = y0 + ey * rc
        P.append([(bx + ey * rs, by - ex * rs), (bx - ey * rs, by + ex * rs)])
        #for x, y in P[-1]:
        #    assert (x - x1)**2 + (y - y1)**2 <= r1**2 + 10**-6, "%f, %f" % ((x - x1)**2 + (y - y1)**2, r1**2)
    P.append([C[-1][:2]])
    #print "\n".join(str(e) for e in P)
    #print

    def calc((x0, y0), (x1, y1)):
        return sqrt((x1 - x0)**2 + (y1 - y0)**2)
    def cross((x0, y0), (x1, y1), (x2, y2)):
        return (x1-x0) * (y2-y0) - (x2-x0) * (y1-y0)
    INF = 10**18
    dist = {(0, 0): 0}
    for i in xrange(n):
        #print i
        for j, (x, y) in enumerate(P[i]):
            left = p_left = None; right = p_right = None
            d = dist[i, j]
            for k in xrange(i+1, n):
                lp, rp = P[k]
                # left
                if left is None or cross((x, y), left, lp) >= 0:
                    left = lp
                if right is None or cross((x, y), rp, right) >= 0:
                    right = rp
                if cross((x, y), left, right) < 0:
                    break
                #print k, left, right, cross((x, y), left, right)
                if p_left != left:
                    #G.setdefault((i, j), set()).add((k, 0))
                    dist[k, 0] = min(dist.get((k, 0), INF), d + calc((x, y), left))
                    p_left = left
                if p_right != right:
                    #G.setdefault((i, j), set()).add((k, 1))
                    dist[k, 1] = min(dist.get((k, 1), INF), d + calc((x, y), right))
                    p_right = right
            else:
                # (x, y) -> goal
                gp = P[-1][0]
                if (left is None and right is None) or (cross((x, y), left, gp) >= 0 and cross((x, y), gp, right) >= 0):
                    #G.setdefault((i, j), set()).add((len(P)-1, 0))
                    dist[len(P)-1, 0] = min(dist.get((len(P)-1, 0), INF), d + calc((x, y), gp))
    print "%.06f" % dist[len(P)-1, 0]

Measured memory_bytes: 6616
q, h, s, d = map(int,input().split())
n = int(input())

ans = min(4 * q * n, 2 * h * n, s * n)
ans = min(ans, d * (n // 2) + min(s * (n % 2), h * 2 * (n % 2), q * 4 * (n % 2)))
print(ans)


Measured memory_bytes: 2940
import sys

sys.setrecursionlimit(10 ** 7)
import bisect


# from collections import deque


# map(int, sys.stdin.read().split())


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [False] * (K + 1)
    dp[0] = False  # 後手の勝ち
    for i in range(K + 1):
        for j in A:
            if j <= i and dp[i-j]==False:
                dp[i] = True
                break
    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    main()


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_N 10000

int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		depth[i] = 0;
	}
}

// 木の根を求める
int find(int x) {
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(depth[x] < depth[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}

// xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}


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

	string S, T;
	cin >> S >> T;

	int used1[26], used2[26];
	rep(i, 0, 26) {
		used1[i] = -1;
		used2[i] = -1;
	}

	rep(i, 0, S.size()) {
		int tmp1 = int(S[i]) - 'a';
		int tmp2 = int(T[i]) - 'a';

		if(used1[tmp1] >= 0) {
			if(used1[tmp1] != tmp2) {
				cout << "No" << endl;
				return 0;
			}
		} else used1[tmp1] = tmp2;
		if(used2[tmp2] >= 0) {
			if(used2[tmp2] != tmp1) {
				cout << "No" << endl;
				return 0;
			}
		} else used2[tmp2] = tmp1;
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 916
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        //500 1000, 5 5
        int result = x / 500;
        result *= 1000;
        int temp = x % 500;

        int temp2 = temp / 5;
        result += temp2 * 5;
        System.out.println(result);



    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
using namespace std;
int L[1001][1001];
int getc(int i,int j){
    if(i>=0&&j>=0)
        return L[i][j];
    else
        return 0;
}
int main(){
    int N;
    string X,Y;
    cin >> N;
    for(int k=0;k<N;++k){
        cin>>X>>Y;
        for(int i=0;i<X.length();++i){
            for(int j=0;j<Y.length();++j){
                if(X[i]==Y[j]){
                    L[i][j]=getc(i-1,j-1)+1;
                }
                else{
                    L[i][j]=max(getc(i-1,j),getc(i,j-1));
                }
            }
        }
        cout <<L[X.length()-1][Y.length()-1]<< endl;
    }
    return 0;
}

Measured memory_bytes: 7120
#include<iostream>
#include<map>

using namespace std;

int main(){
  string s;
  cin >> s;
  map<char,int> m;

  for(char c :s){
    m[c]++;
  }
  if(m.size()!=2){
    cout << "No" << endl;
  }
  else{
    for(auto x:m){
      if(x.second !=2){
        cout << "No" << endl;
        return 0;
      }
    }

    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    int a, b;

    while (cin >> a >> b) 
        cout << gcd(a, b) << endl;
        

    return 0;
}

Measured memory_bytes: 1160
import numpy as np
from math import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k in a:
    print("POSSIBLE")
    exit()
x=np.gcd.reduce(a)
if x==1:
    print("POSSIBLE")
else:
    if k<max(a) and k%x==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 37944
#include<bits/stdc++.h>
using namespace std;
bool used[3];
string s;

bool check(){
  while(1){
    memset(used,0,sizeof(used));
    int flag=0;
    for(int i=0;i<s.size();i++)
      if(i<s.size()-2&&s[i]+1==s[i+1]&&s[i+1]+1==s[i+2]){
	i+=2;
	flag=1;
      }
      else used[s[i]-'A']=true;
    if(used[0]+used[1]+used[2]==2&&flag){
      string t;
      for(int i=0;i<3;i++){
	if(used[i])continue;
	for(int j=0;j<s.size();j++)
	  if(j<s.size()-2&&s[j]+1==s[j+1]&&s[j+1]+1==s[j+2]){
	    t+=i+'A';
	    j+=2;
	  }else t+=s[j];
      }
      s=t;
    }
    else if(s=="ABC")return true;
    else break;
  }
  return false;
}

int main(){
  cin>>s;
  if(check())cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3204
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a*100+b*10+c)%4==0)printf("YES\n");else printf("NO\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int stat = 0;
	for (int i = 0; i < s.size(); i++) {
		char c = s[i];
		if (stat == 0 && c == 'C') {
			stat = 1;
		} else if (stat == 1 && c == 'F') {
			stat = 2;
		}
	}
	cout << (stat == 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	val bingo = (0 until 3).map(x => readLine.split(" ").map(_.toInt)).toList
  	val state = readInt;
  	val called = (0 until state).map(x => readInt).toList
  	val punched = bingo.map(_.map(x => called.contains(x)))
  	
  //this is the smartest solution in the universe
  	if(punched(0)(0) && punched(0)(1) && punched(0)(2)){println("Yes")}
  	else if(punched(1)(0) && punched(1)(1) && punched(1)(2)){println("Yes")}
  	else if(punched(2)(0) && punched(2)(1) && punched(2)(2)){println("Yes")}
  	else if(punched(0)(0) && punched(1)(0) && punched(2)(0)){println("Yes")}
  	else if(punched(0)(1) && punched(1)(1) && punched(2)(1)){println("Yes")}
  	else if(punched(0)(2) && punched(1)(2) && punched(2)(2)){println("Yes")}
  	else if(punched(0)(0) && punched(1)(1) && punched(2)(2)){println("Yes")}
    else if(punched(2)(0) && punched(1)(1) && punched(2)(0)){println("Yes")}
  	else println("No")
    
}

Measured memory_bytes: 54600
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

signed main() 
{
    speed;
    
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(A[1]-A[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


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

bool judge(vector<int> vec){
    int sum = 0;
    for(int i = 0;i < vec.size();i++){
        if((vec.at(i) % 2) == 0){
            sum++;
        }else{
            break;
        }
    }
    if(sum == vec.size()){
        return true;
    }else{
        return false;
    }
}

int main(){
    int N;
    int count = 0;
    cin >> N;

    vector<int> vec(N);
    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
    }

    while(judge(vec)){
        count++;
        for(int i = 0;i < N;i++){
            vec.at(i) /= 2;
        }
    }

    cout << count << endl;


   

  
}

Measured memory_bytes: 256
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

const double PI = acos(-1.0);

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist(const Point& p) const{
        return sqrt(pow(y - p.y, 2) + pow(x - p.x, 2));
    }
};

void rotate(Point& p, const Point& c, double dist)
{
    double r = p.dist(c);
    if(r < 1.0e-10)
        return;
    double theta = atan2(p.y - c.y, p.x - c.x);
    theta += dist / r;
    p = c;
    p.y += r * sin(theta);
    p.x += r * cos(theta);
}

int main()
{
    for(;;){
        int n, d;
        cin >> n >> d;
        if(n == 0)
            return 0;

        Point left(0, -d), right(0, d);

        while(--n >= 0){
            int speedL, speedR, time;
            cin >> speedL >> speedR >> time;

            Point v = right - left;
            v = v / v.length();

            if(speedL == speedR){
                swap(v.y, v.x);
                v.x *= -1;
                v = v * speedL / 180.0 * PI * time;
                left = left + v;
                right = right + v;
                continue;
            }

            double r = d * (speedL + speedR) / (double)(speedL - speedR);
            Point c = left + v * (d + r);
            if(r < -d){
                rotate(left, c, speedL / 180.0 * PI * time);
                rotate(right, c, speedR / 180.0 * PI * time);
            }else if(r > d){
                rotate(left, c, - speedL / 180.0 * PI * time);
                rotate(right, c, - speedR / 180.0 * PI * time);
            }else{
                rotate(left, c, - speedL / 180.0 * PI * time);
                rotate(right, c, speedR / 180.0 * PI * time);
            }
        }

        Point ret = (left + right) / 2;
        printf("%.10f\n%.10f\n", ret.x, ret.y);
    }
}

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

int n;
vector <int> V;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
    	int temp;
        scanf("%d", &temp);
        if((n + i) & 1) V.push_back(temp);
        else V.insert(V.begin(), temp);
    }
    for (int i = 0; i < n; ++i) printf("%d ", V[i]);
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> pr(n + 1, 0), pg(n + 1, 0), pb(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        pr[i + 1] = pr[i];
        pg[i + 1] = pg[i];
        pb[i + 1] = pb[i];
        if (s[i] == 'R') pr[i + 1] = pr[i] + 1;
        if (s[i] == 'G') pg[i + 1] = pg[i] + 1;
        if (s[i] == 'B') pb[i + 1] = pb[i] + 1;
    }
    /*for (auto it : pr) {
        cout << it << " ";
    }
    cout << "\n";
    for (auto it : pg) {
        cout << it << " ";
    }
    cout << "\n";
    for (auto it : pb) {
        cout << it << " ";
    }
    cout << "\n";*/
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (s[i] != s[j]) {
                set<char> t;
                t.insert('R'); t.insert('G'); t.insert('B');
                t.erase(s[i]); t.erase(s[j]);
                char nw = *t.begin();
                if (nw == 'R') {
                    ans += pr[n] - pr[j + 1];
                }
                if (nw == 'G') {
                    ans += pg[n] - pg[j + 1];
                }
                if (nw == 'B') {
                    ans += pb[n] - pb[j + 1];
                }
                //cout << i << " " << j << " " << ans << " ";
                if (2 * j - i < n && nw == s[2 * j - i]) ans--;
                //cout << ans << "\n";
            }
        }
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3704
A, B, C, D= map(int, input().split())
th = A
ah = C
flag = True

while th > 0 and ah > 0:
  ah -= B
  if ah <=0:
    break
  th -= D
  if th <= 0:
    flag = False
    break
  
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9128
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std; 
pair<long long,long long>a[100100];
bool cmp(pair<long long,long long>x,pair<long long,long long>y){
	return x.first+x.second<y.first+y.second;
}
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&a[i].first,&a[i].second);
	}
	sort(a+1,a+1+n,cmp);
	int ans=1;
	for(i=2;i<=n;i++){
		if(a[i-1].first+a[i-1].second<=a[i].first-a[i].second)
		ans++;
		else
		a[i]=a[i-1];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(void)
{
    int n, k, i, p=1, cnt=0;
    double ans=0.0000000000, me;
    scanf("%d%d", &n, &k);
    for(i=1;i<=n;i++){
        p=i;
        me=1.0/n;
        while(p<=k-1){
            p=p*2;
            me=me/2.0;
        }
        ans=ans+me;
    }
     printf("%.12f\n", ans);
        
    return 0;
}


Measured memory_bytes: 128
# coding=utf-8


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


if __name__ == '__main__':
    A, B, K = map(int, input().split())
    gcd = solve_gcd(A, B)
    ctr = 0
    for i in range(gcd, 0, -1):
        if gcd % i == 0:
            ctr += 1
        if ctr == K:
            print(i)
            break


Measured memory_bytes: 3060