akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long

const int MOD = 1e9 + 7;
const int INF = 2e10;
const int mx = 1e4 + 5;

void debug(vector <int> &dp, int l, int r) {
	for (int i = 1; i <= r; i++) {
		if (dp[i] == INF) cout << "inf ";
		else cout << dp[i] << " ";
	}
	cout << endl;
}

void max_self(int &a, int b) {
	a = max(a, b);
}

void min_self(int &a, int b) {
	a = min(a, b);
}

signed main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int n, w;
	cin >> n >> w;

	vector <int> weight(n);
	vector <int> value(n);

	int total = 0;

	for (int i = 0; i < n; i++) {
		cin >> weight[i] >> value[i];
		total += value[i];
	}

	vector <int> dp(total + 1, INF);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		int val = value[i];
		int cost = weight[i];

		for (int j = total; j >= val; j--) {
			min_self(dp[j], dp[j - val] + cost);
		}
	}

	int ans = 0;

	for (int i = 0; i < dp.size(); i++) {
		if (dp[i] <= w) {
			max_self(ans, i);
		}
	}

	cout << ans << endl;
}

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

struct edge{int to; ll cost;};
typedef pair<ll, int> P;
const ll INF = 1e18;
const int MAX_V = 1e5;

vector<edge> G[MAX_V];
vector<ll> d(MAX_V,INF); 

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  for(int i = n-1; i >= 1; i--) G[i].push_back(edge{i-1,0});
  rep(i,m) {
    int l, r; ll c;
    cin >> l >> r >> c;
    l--; r--;
    G[l].push_back(edge{r,c});
  }
  dijkstra(0);
  if(d[n-1] == INF) cout << -1 << endl;
  else cout << d[n-1] << endl;
  return 0;
}

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

int main(){
 int a[3];
 int sum=0;
 for(int i=0;i<3;i++){
   cin>>a[i];
   sum+=a[i];
 } 
 if(sum>=22){
   cout<<"bust"<<endl;
 }
 else{
   cout<<"win"<<endl;
 }
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N, A, B;
	cin >> N >> A >> B;
	if ((A - B) % 2 == 0) { cout << "Alice"; }
	else { cout << "Borys"; }

	
	
	system("PAUSE");

}





Measured memory_bytes: 504
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Union-Find -- START --
class UnionFind():
  def __init__(self,sz):
    self.sz=sz
    self.data=[-1]*sz

  def unite(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return False
    if self.data[x]>self.data[y]:
      x,y=y,x
    self.data[x]+=self.data[y]
    self.data[y]=x
    return True

  def find(self,k):
    if self.data[k]<0:
      return k
    self.data[k]=self.find(self.data[k])
    return self.data[k]

  def size(self,k):
    return -self.data[self.find(k)]
# Union-Find --- END ---

def main():
  n,m=LI()
  uf=UnionFind(n)
  for _ in range(m):
    a,b=LI()
    a-=1
    b-=1
    uf.unite(a,b)
  
  d={}
  for i in range(n):
    d[uf.find(i)]=i

  return len(d)-1

# main()
print(main())


Measured memory_bytes: 16636
alphabet = "abcdefghijklmnopqrstuvwxyz"

s = input()
ans = 100
for target in alphabet:
    if target not in s:
        continue

    indexes = []
    for i in range(len(s)):
        if s[i] == target:
            indexes.append(i)
    tmp = 0
    tmp = max(indexes[0], (len(s)-1) - indexes[-1])

    for i in range(len(indexes)-1):
        tmp = max(tmp, (indexes[i+1]-1) - indexes[i])

    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn dist(x: i64, y: i64) -> f64 {
    let u = x as f64;
    let v = y as f64;
    (u * u + v * v).sqrt()
}

fn goal(es: &mut Vec<(i64, i64)>, gx: i64, gy: i64) -> f64 {
    es.sort_by_key(|&p| -(p.0 * gx + p.1 * gy));
    let mut r = 0.0;
    let mut r_grd = 0.0;
    let mut x = 0;
    let mut y = 0;
    let mut x_grd = 0;
    let mut y_grd = 0;
    let mut ret = 0.0;
    for &e in es.iter() {
        x += e.0;
        y += e.1;
        r = dist(x, y);
        if r_grd < dist(x_grd + e.0, y_grd + e.1) {
            r_grd = dist(x_grd + e.0, y_grd + e.1);
            x_grd += e.0;
            y_grd += e.1;
        }
        ret = max!(ret, r, r_grd);
    }
    ret
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut es: Vec<(i64, i64)> = (0..n).map(|_| (sc.cin(), sc.cin())).collect();

    let m: i64 = 1000;
    let mut ans = 0.0;
    for x in -m..m+1 {
        ans = max!(ans, goal(&mut es, x, m));
        ans = max!(ans, goal(&mut es, x, -m));
    }
    for y in -m..m+1 {
        ans = max!(ans, goal(&mut es, m, y));
        ans = max!(ans, goal(&mut es, -m, y));
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

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

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

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

int num[7368792];

void solve(int m, int n) {
	int cnt = 0;
	FOR(i, m - 1, 7368792) {
		if(num[i]) {
			++cnt;
			num[i] = 0;
			for(int j  = 2; (i + 1) * j <= 7368792; ++j) {
				num[(i + 1) * j - 1] = 0;
			}
		}
		if(cnt == n) return;
	}	
}

int main() {
	int m, n;
	while(scanf("%d %d", &m, &n), m | n) {
		memset(num, 1, sizeof(num));
		solve(m, n);
		FOR(i, m, 7368792) {
			if(num[i]) {
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 31940
#include<stdio.h>
  
  static int INFTY = 999999;

  static int WHITE = 0;

  static int GRAY = 1;
  static int BLACK = 2;

  int n;
  int M[100][100];
  void cal(){
    int min;
    int d[100],c[100];
    
    for(int i = 0; i < n;i++){
      d[i] = INFTY;
      c[i] = WHITE;
    }
    
    d[0] = 0;
    c[0] = GRAY;
    while(1){
      
      min = INFTY;
      int u = -1;
      for(int i = 0;i < n;i++){
	
if(min > d[i] && c[i] != BLACK){
 u = i;
 min = d[i];
}
}
      if(u == -1)break;
      c[u] = BLACK;
      for(int v = 0;v < n;v++){
	
if(c[v] != BLACK && M[u][v] != INFTY){
 if(d[v] > d[u] + M[u][v]){
   
   d[v] = d[u] + M[u][v];
   c[v] = GRAY;
   }
}
      }
    }

    for(int i = 0;i < n;i++){
      
        printf("%d %d\n",i,(d[i] == INFTY? -1 : d[i]));
        }
  }

  int main(){
    
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
      
      for(int j = 0;j < n;j++){
M[i][j] = INFTY;
      }
    }

    int k,cube,u,v;
    for(int i = 0; i < n;i++){
      
      scanf("%d%d",&u,&k);
      
      for(int j = 0;j < k;j++){
	
          scanf("%d%d",&v,&cube);
	  
          M[u][v] = cube;
      }
    }
    cal();
    return 0;
 }



Measured memory_bytes: 2036
n = gets.to_i
b = gets.split.map(&:to_i)
sum = b[0]
n.times do |i|
  if b[i + 1].nil?
    sum += b[i]
    break
  end
  if b[i] > b[i +1]
    sum += b[i +1]
  else
    sum += b[i]
  end
end
puts sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string S;
  cin >> S;
  bool is_ok = true;
  if (S[0] == S[1] && S[1] == S[2] && S[2] == S[0])
    is_ok = false;
  printYesNo(is_ok);
  return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
S = abs(X)//D

if abs(X)/D >= K:
    X = abs(X)-D*K
    print(X)
else:
    X = min(abs(X-D*S), abs(X+D*S))
    K = K - S
    for k in range(K):
        if min(abs(X+D), abs(X-D)) < abs(X):
            X = min(abs(X+D), abs(X-D))
            K -= 1
        else:
            if K%2 == 0:
                print(X)
                break
            else:
                X = min(abs(X+D), abs(X-D))
                print(X)
                break

    if K == 0:
        print(X)


Measured memory_bytes: 61820
n, q = gets.split.map(&:to_i)
s = gets.chomp
cum = Array.new(s.length)
cum[0] = 0
(1..s.length - 1).each do |i|
  if s[i - 1] == 'A' && s[i] == 'C'
    cum[i] = cum[i - 1] + 1
  else
    cum[i] = cum[i - 1]
  end
end
q.times do
  l, r = gets.split.map(&:to_i)
  puts cum[r - 1] - cum[l - 1]
end

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

const LL M = 2e5 + 100;
const LL mod = 998244353;
LL fac[M];

LL add(LL a, LL b) {
	return (a + b) % mod;
}

LL mul(LL a, LL b) {
	return a * b % mod;
}

LL fpow(LL a, LL b) {
	LL res = 1;
	while (b > 0) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

LL inv(LL a) {
	return fpow(a, mod - 2);
}

LL C(LL n, LL m) {
	if (m == 0) return 1;
	return mul(fac[n], mul(inv(fac[m]), inv(fac[n - m])));
}

void init() {
	fac[0] = 1;
	for (int i = 1; i < M; i++) fac[i] = mul(fac[i - 1], i);
}

int main() {
	init();
	LL n, m, k; cin >> n >> m >> k;
	LL ans = 0;
	for (int i = 0; i <= k; i++) {
		ans = add(ans, mul(m, mul(C(n - 1, i), fpow(m - 1, n - 1 - i))));
	}
	cout << ans;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S; cin >> S;
  int K; cin >> K;
  int N; N = S.size();

  vector<vector<ll>> dp1(N,vector<ll>(K+1,0)); 
  // dp1[i][j]: S以下確定、先頭からi番目まで、0以外がj個
  vector<vector<ll>> dp2(N,vector<ll>(K+1,0)); // S以下確定、
  // dp2[i][j]: S以下未確定、先頭からi番目まで、0以外がj個

  int d0 = S[0] - '0';
  for(int k = 0; k <= d0; k++){
    if(k < d0){
      if(k != 0){
        dp1[0][1]++;
      } else { 
        dp1[0][0]++;
      }
    } else { 
      dp2[0][1]++;
    }
  }

  for(int i = 0; i < N-1; i++){
    int d = S[i+1] - '0';
    for(int k = 0; k <= d; k++){
      if(k < d){
        for(int j = 0; j <= K; j++){
          if(k==0){
            dp1[i+1][j] += dp2[i][j];
          } else {
            if(j+1<=K) dp1[i+1][j+1] += dp2[i][j];
          }
        }
      } else {
        for(int j = 0; j <= K; j++){
          if(k==0){
            dp2[i+1][j] += dp2[i][j];
          } else { 
            if(j+1<=K) dp2[i+1][j+1] += dp2[i][j];
          }
        }
      }
    }
  }

  for(int i = 0; i < N-1; i++){
    int d = S[i+1] - '0';
    for(int j = 0; j <= K; j++){
      for(int k = 0; k <= 9; k++){
        if(k==0){
          dp1[i+1][j] += dp1[i][j];
        } else { 
          if(j+1<=K) dp1[i+1][j+1] += dp1[i][j];
        }
      }
    }
  }


  cout << dp1[N-1][K] + dp2[N-1][K] << endl;
  // cerr << dp1[N-1][K] << " " <<  dp2[N-1][K] << endl;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
void bingo(int a[],int b[],int c){
  int flag[9] = {};
  for(int i = 0;i < 9;i++){
    for(int j = 0;j < c;j++){
      if(a[i] == b[j]){
        flag[i] = 1;
        
      }
    }
  }

    if(flag[0] == 1 && flag[3] == 1 && flag [6] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[1] == 1 && flag[4] == 1 && flag [7] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[2] == 1 && flag[5] == 1 && flag [8] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[0] == 1 && flag[1] == 1 && flag [2] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[3] == 1 && flag[4] == 1 && flag [5] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[6] == 1 && flag[7] == 1 && flag [8] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[0] == 1 && flag[4] == 1 && flag [8] == 1){
      cout << "Yes" << endl;
    }
    else if(flag[2] == 1 && flag[4] == 1 && flag [6] == 1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }

}

int main(){
  int a[9],b;
  for(int i = 0;i < 9;i++){
    cin >> a[i];
  }
  cin >> b;
  int c[b];
  for(int i = 0;i < b;i++){
    cin >> c[i];
  }
  bingo(a,c,b);
}
      

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



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

    cin >> a >> b;
    if(a <= b){
        cout << "unsafe" << endl;
    }else{
        cout << "safe";
    }

    return 0;
}

Measured memory_bytes: 3168
import numpy as np

N, M, X = map(int, input().split())

C = []
A = []
for _ in range(N):
    inp = list(map(int, input().split()))
    C.append(inp[0])
    A.append(inp[1:])
A = np.array(A)

for i in range(M):
    if np.sum(A, axis=0)[i] < X:
        print(-1)
        exit()

min_c = 999999999999999
for i in range(2**N):
    item = []
    tmp_c = 0
    for j in range(N):
        if ((i >> j) & 1):
            item.append(A[j])
            tmp_c += C[j]
    if len(item) == 0:
        continue
    for j in range(M):
        if np.sum(item, axis=0)[j] < X:
            break
        if j == M-1:
            if min_c > tmp_c:
                min_c = tmp_c

print(min_c)


Measured memory_bytes: 27316
//============================================================================
// Author      : JCH
// Copyright   :
// Description : Contest ACM Div2
//============================================================================

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

#define top (int)(100005)

int amount[top ], n, m, a, b;
bool check[top ];

int main() {

	cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);

	for (int i = 0; i < top ; ++i)
		amount[i] = 1;

	check[1] = 1;

	cin >> n >> m;

	while (m--) {

		cin >> a >> b;

		if (amount[b] == 0)
			check[b] = 0;

		if (amount[a] == 0) {
			check[a] = 0;
			continue;
		}

		amount[a]--;
		amount[b]++;

		if (check[a])
			check[b] = 1;

		if (amount[b] == 0)
			check[b] = 0;
	}

	int boxes = 0;

	for (int i = 1; i < top ; ++i)
		if (check[i] && amount[i] > 0)
			boxes++;

	cout << boxes << endl;

	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

vector<ll>ba(51, 0), pa(51, 0);


ll func(ll n, ll x) {

	if (n == 0) {
		return 1;
	}
	else if (x == 1) {
		return 0;
	}
	else if (x > 1 && x <= ba[n-1] + 1) {
		return func(n - 1, x - 1);
	}
	else if (x == ba[n-1]+2) {
		return pa[n - 1] + 1;
	}
	else if (x > ba[n - 1] + 1 && x < ba[n]) {
		return pa[n - 1] + 1 + func(n - 1, x - ba[n - 1] - 2);
	}
	else if (x == ba[n]) {
		return pa[n];
	}


	return 0;
}



signed main() {
	int i, j;
	ll n, x;
	

	cin >> n >> x;

	ba[0] = 1;
	pa[0] = 1;

	for (i = 1; i <= n; i++) {
		ba[i] = ba[i-1] * 2 + 3;
	}
	
	for (i = 1; i <= n; i++) {
		pa[i] = pa[i-1] * 2 + 1;
	}





	cout << func(n, x) << endl;



	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n;
void swap(int *a,int *b){
  int temp=*a;
  *a=*b;
  *b=temp;
}
void qsort(int* a, int left,int right){
  int i,j,pivot;
  if(left>=right) return;
  for(pivot=a[left],i=left,j=right;i<j;){
    while(i<=j && a[i]<=pivot){
      i++;
    }
    while(i<=j && a[j]>pivot){
      j--;
    }
    if(i<j) swap(&a[i],&a[j]);
  }
  swap(&a[left],&a[j]);
  qsort(a,left,j-1);
  qsort(a,j+1,right);
}
int main(){
  int k,i,temp=0;
  scanf("%d%d",&n,&k);
  int l[n];
  for(i=0;i<n;i++)
    scanf("%d",&l[i]);
  qsort(l,0,n-1);
  for(i=0;i<k;i++)
    temp+=l[n-1-i];
  printf("%d\n",temp );

}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

signed main()
{
    int2(a, b);
    int2(c, d);

    vb used(101, false);
    for (int i = a; i < b; i++) {
        used[i] = true;
    }
    int cnt = 0;
    for (int i = c; i < d; i++) {
        if (used[i]) {
            cnt++;
        }
    }
    std::cout << cnt << std::endl;

    return 0;
}


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

int main() {
    int ave = 0;
    for(int i=0;i<5;i++){
        int a;
        cin >> a;
        ave += max(40,a);
    }
    ave /= 5;
    cout << ave << endl;
    return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define endl            "\n"
#define ll                long long
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define clr(v, d)        memset(v, d, sizeof(v))
#define rep(i, v)        for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define vi                vector <int>
#define vl                vector <ll>
#define ii                pair <ll,ll>
#define vii                vector <ii>
const double PI = 2 * acos(0.0);
void run() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
}
const ll M = 1e5, mod = 1e9 + 7;
ll n;
int dp[M + 5][2];
vi v;
ll k;
int sol(int rem, bool turn) {
	if (rem < 0)
		return turn ? 1 : 2;
	int &ret = dp[rem][turn];
	if (~ret)
		return ret;
	if (turn) {
		lp(j,n)
		{
			ret = sol(rem - v[j], !turn);
			if (ret == 1)
				return ret;
		}
		return ret;
	} else {
		lp(j,n)
		{
			ret = sol(rem - v[j], !turn);
			if (ret == 2)
				return ret;
		}
		return ret;
	}
}
int main() {
	run();
	cin >> n >> k;
	v.resize(n);
	lp(i,n)
		cin >> v[i];
	//cout << "HI" << endl;
	clr(dp, -1);
	cout << ((sol(k, 1)==1)?"First":"Second");
}


Measured memory_bytes: 5760
#-*-coding:utf-8-*-
 
import sys
 
def main():
    k = int(input())
    sevens=0
    if k%2==0:
      print(-1)
      exit()
    for i in range(1,10**6+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9080
S = input()
 
if S[1]==S[2]==S[3]==S[0]:
        print('No')
        
elif S[0]==S[1] and S[2]==S[3]:
        print('Yes')
 
elif S[1]==S[2] and  S[0]==S[3]:
        print('Yes')
        
elif S[1]==S[3] and  S[0]==S[2]:
        print('Yes')
 
else :
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


int N, M;
VI g[100010];
int S, T;
int d[100010][3];


signed main(){
    cin >> N >> M;
    rep(i, 0, M){
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
    }
    cin >> S >> T;
    S--, T--;

    queue<PII> q;
    q.push({ S, 0 });
    d[S][0] = 0;
    while(!q.empty() && !d[T][0]){
        PII p = q.front();
        q.pop();
        for(int u : g[p.first])
            if(!d[u][(p.second+1)%3]) d[u][(p.second+1)%3] = d[p.first][p.second]+1, q.push({ u, (p.second+1)%3 });
    }

    if(d[T][0]) cout << d[T][0]/3 << endl;
    else cout << -1 << endl;

    return 0;
}

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

using namespace std;

int N,K;
const long long mod=1e9+7;
long long c[2010][2010];

long long C(int n,int m)
{
	if(m>n)
		return 0;
	return c[n][m];
}
void q(int n)
{
	for(int i=0;i<=n;i++)
		c[i][0]=c[i][i]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=(i-1);j++)
		{
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
}

int main()
{
	cin>>N>>K;
	q(N);
	for(int i=1;i<=K;i++)
		cout<<C(N-K+1,i)*C(K-1,i-1)%mod<<endl;
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

string X;

const int maxn = 2e5 + 5;
int st[maxn], tot;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> X;
    int n = X.length();
    for(int i = 0;i < n;i++){
        if(X[i] == 'T'){
            if(tot > 0 and st[tot] == 0){
                tot--;
            }else{
                st[++tot] = 1;
            }
        }
        else{
            st[++tot] = 0;
        }
    }
    string ans = "";
    for(int i = 1;i <= tot;i++){
        if(st[i] == 1){
            ans.push_back('T');
        }else{
            ans.push_back('S');
        }
    } 
    cout << ans.length() << endl;
    return 0;
}


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

using namespace std;
#define ll long long int

int main()
{
    int n;
    cin >> n;
    long double a[n];
    for(int i =0 ; i < n ; i ++)
    cin >> a[i];
    long double dp[ n + 1][n + 1];
    dp[0][0] = 1;
    for(int i = 1; i <=n ; i ++)
    {
        dp[0][i] = dp[0][i - 1] * (1 - a[i - 1]);
    }
    for(int i = 1; i <=n ; i ++)
    dp[i][0] = 0;

    for(int i = 1; i <=n ; i ++)
    {
        for(int j = 1; j<=n ; j ++)
        {
            dp[i][j] =  a[j - 1] * dp[i - 1][j - 1] + (1 - a[j - 1]) * dp[i][j - 1];
        }
    }
    long double ans = 0.0;
    for(int i = (n + 1) /2 ; i<=n ; i ++)
    {
        ans += dp[i][n];
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 140928
n, y = map(int, input().split())

for a in range(n+1):
    for b in range(n-a+1):
        c = n - (a+b)
        if y == 10000*a + 5000*b + 1000*c and c >= 0:
            print(a, b, c)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
A,B,C=map(int,input().split())

if A==max(A,B,C):
  print(A*10+B+C)
elif B==max(A,B,C):
  print(B*10+A+C)
elif C==max(A,B,C):
  print(C*10+A+B)  
  
  

Measured memory_bytes: 2940
n = int(input())
title_list = []
time_list = []
for i in range(n):
    title,time = input().split(" ")
    time = int(time)
    title_list.append(title)
    time_list.append(time)

x = input()

total = 0
for i,j in enumerate(title_list):
    total += time_list[i]
  
time_res = 0
for i,j in enumerate(title_list):
    if j != x:
        time_res += time_list[i]
    else:
        time_res += time_list[i]
        break


        
print(total - time_res)
    

Measured memory_bytes: 3064
n = int(input())
cnt = 0
for x in range(n):
    d1, d2 = [int(i) for i in input().split()]
    if d1 == d2:
        cnt += 1
    elif cnt == 3:
        break
    else:
        cnt = 0

if cnt >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62260
ary=$stdin.read.lines.map(&:to_i)
plus = []
result = 0

5.times do |i|
  result += ary[i] / 10 * 10
  plus.push(ary[i]%10) if ary[i]%10 != 0
end
if !plus.empty?
  result += (plus.size-1) * 10
  result += plus.min
end
puts result

 

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

int64_t GCD(int64_t a, int64_t b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
  int64_t N, X;
  cin >> N >> X;
    
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x.at(i);
  
  int64_t res = 0;
  for (int i = 0; i < N; i++){
    res = GCD(res, abs(X-x.at(i)));
  }
  
  cout << res << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int len=sc.nextInt();
		String s=sc.next();
		long[] a=new long[26];
		Arrays.fill(a,0);
		for(int i=0; i<s.length(); i++) {
			a[s.charAt(i)-97]++;
		}
		long ans=1;
		for(int i=0; i<26; i++) {
			ans*=(a[i]+1);
			ans%=1000000007L;
		}
		pl(ans-1);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 25044
#include <iostream>
using namespace std;
int main(void){
  int A,B,answer;
  std::cin >> A>>B;
  if (B<A)
  {
      int C=A;
      A=B;
      B=C;
  }
  if (A==B)
  {
      answer=2*A;
  }else
  {
      answer=B;
      B--;
      answer=answer+B;
  }
  cout<<answer<<endl;
  return 0;
}


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

using namespace std;

const int MAX_N = 200005;

int n,a[MAX_N],dp[MAX_N][30][30];
char s[MAX_N];

int f(int i, int x, int y)
{
	if (i == n)
		return 0;
	if (dp[i][x][y] != -1)
		return dp[i][x][y];
	int ans=0;
	//take 1
	if (x != 0 || y != a[i])
		ans = 1+f(i+1,0,a[i]);
	//take 2
	if (i + 1 < n && (x == 0 || (x != a[i] && y != a[i+1])))
		ans = max(ans,1+f(i+2,a[i],a[i+1]));
	return dp[i][x][y] = ans;
}

int main()
{
	scanf("%s",s);
	n=strlen(s);
	for (int i=0; i<n; i++)
	{
		a[i]=s[i]-'a'+1;
		for (int j=0; j<30; j++)
			for (int k=0; k<30; k++)
				dp[i][j][k]=-1;
	}
	printf("%d\n",f(0,0,0));
	return 0;
}


Measured memory_bytes: 716416
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }
    for(const auto& x:m){
        if(n%2&&x.first==0){if(x.second!=1){cout<<0<<endl;return 0;}}
        else{if(x.second!=2||(x.first%2==n%2)){cout<<0<<endl;return 0;}}
    }
    ll ans=1;
    for(int i=0;i<(n/2);i++){
        ans=(ans*2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3584
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		String S = sc.nextLine();
		String Out = "";
		for(int i = 0; i < S.length(); i++) {
			int temp = S.charAt(i);
			temp = temp + N;
			if(temp > 90) {
				temp = temp - 26;
			}
			Out = Out + (char)temp;
		}
		System.out.println(Out);
	}
}


Measured memory_bytes: 147388
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		int n,p[];
		
		while(true){
			n=sc.nextInt();
			if(n==0) break;
			p=new int[n];
			for(int i=0;i<n;i++){
				p[i]=sc.nextInt();
			}
			int count=0;

			if(n==1){
				System.out.println(p[0]);
			}
			else{
				for(int i=0;i<n-1;i++){
					//System.out.println(i+"!"+p[i]);
					if(p[i+1]-p[i]==1){
						count++;
					}
					else{
						if(count==0){
							System.out.print(p[i]);
						}
						else{
							System.out.print(p[i-count]+"-"+p[i]);
						}
						count=0;
						System.out.print(" ");
					}
					if(i==(n-2)){
						if(count==0){
							System.out.print(p[i+1]);
						}
						else{
							System.out.print(p[i-count+1]+"-"+p[i+1]);
						}
						count=0;
					}	
				}
				System.out.println();
			}
		}

	}

}

Measured memory_bytes: 26864
n, a = map(int, input().split())
x = list(map(int, input().split()))

#aとの差を記録してリストに入れなおす
x = list(map(lambda i: i-a, x))
#print(x)

#dp初期値
dp = {0: 1}

#dpにぶち込む値をxから取り出す
for num in x:
  #dpにあるすべてのkey,valueに対して、すでにdpにkeyがi+kのデータがあればそのvalueなければ,0を返し、それ+vをdpとする。
  for k,v in list(dp.items()):
    dp[num+k]=dp.get(num+k,0)+v
    
  #print(dp)
#全部使わない選択肢だけ引いておく  
print(dp[0]-1)
#print(dp)

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

int main() {
    string s;
    cin >> s;
    int a = 10000;
    for (int i = 0; i < s.length() - 2; i++) {
        string t = s.substr(i, 3);
        a = min(a, abs(753-stoi(t)));
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#if 0
?????????????????£????????????????????§?????????????????¢??????????????????????????????
(0,0)???????????????(1,1)?????????(=???????????????????¶????)
?§?????????´??????(gx+1,gy+1)????????????

#endif

#include <iostream>
using namespace std;

int main(){
	int n,gx,gy,p,x1,y1,x2,y2;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> gx >> gy >> p;
		int Vert[gx+10][gy+10]; //????????????????????????????????????????????????T/F??§??¨???
		int Horiz[gx+10][gy+10]; //?????????
		int T[gx+10][gy+10]; //?????????????????????????????????????????°
		for(int a=1; a<gx+2; a++){
			for(int b=1; b<gy+2; b++){ 
				Vert[a][b]=true;
				Horiz[a][b]=true;
			}
		}
		for(int k=0; k<p; k++){  //?????????????????????????¨????
			cin >> x1 >> y1 >> x2 >> y2;
			if (x1==x2)//????????????(=false)???????¨????
				Vert[x1+1][max(y1+1,y2+1)]=false;
			if (y1==y2)//?????¨????§?
				Horiz[max(x1+1,x2+1)][y1+1]=false;
		}

		for(int a=0; a<gx+2; a++) //?????????
			for(int b=0; b<gy+2; b++)
				T[a][b]=0;

		for(int a=1; a<gx+2; a++){ 
			for(int b=1; b<gy+2; b++){
				if(a==1&&b==1)
					T[a][b]=1;
				else if(Vert[a][b]==false && Horiz[a][b]==false)//??????????????????
					T[a][b]=0;
				else if(Vert[a][b]==true && Horiz[a][b]==false)
					T[a][b]=T[a][b-1];
				else if(Vert[a][b]==false && Horiz[a][b]==true)
					T[a][b]=T[a-1][b];
				else if(Vert[a][b]==true && Horiz[a][b]==true)
					T[a][b]=T[a-1][b]+T[a][b-1];
			}
		}
		if(T[gx+1][gy+1]==0)
			cout << "Miserable Hokusai!" << endl;
		else cout << T[gx+1][gy+1] <<endl;
	}
}

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

int main() {
    double a,b,c,d,e,f;
    while (cin>>a>>b>>c>>d>>e>>f) {
        double x=round((c*e-b*f)/(a*e-b*d)*1000)/1000;
        double y=round((a*f-c*d)/(a*e-b*d)*1000)/1000;
        if (x==-0)
            x=0;
        if (y==-0)
            y=0;
        cout<<fixed<<setprecision(3)<<x<<' '<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3320
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : (-1 * (a)))

int main(int argc, char *argv[argc])
{
  string str;
  vector<int> vec(1);
  char c;
  int index = 0;

  while(scanf("%c", &c)) {
    if (c == '\n') break;

    if (c == 'x') vec[index]++;
    else {
      str.push_back(c);
      vec.push_back(0);
      index++;
    }
  }

  string rstr = str;
  reverse(rstr.begin(), rstr.end());
  if (str != rstr) printf("-1\n");
  else {
    int front = 0;
    int back = vec.size() - 1;
    int ans = 0;
    while (front < back) {
      ans += ABS(vec[front] - vec[back]);
      front++;
      back--;
    }
    printf("%d\n", ans);
  }
  
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rev(a,b){return a>b}
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
int arr[25];




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr[i];
    int maxtill = arr[0];
    int ans = 1;
    for(int i=1;i<n;i++)
    {
        if(arr[i]>=maxtill)
        {
            ans++;
            maxtill = arr[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())

l = 1
r = n + 1


def ask(k):
    print(*k)
    x = input()
    return x[0]


al = ask(['?'] + [str(i) for i in range(1, n + 1)])

while r - l > 1:
    m = (l + r) // 2
    am = ask(['?'] + [str(i) for i in range(m, m + n)])
    if am == al:
        l = m
    else:
        r = m

ans = [0] * (2 * n + 1)
ans[l] = al
ans[r + n - 1] = 'R' if al == 'B' else 'B'
t = ['?'] + [str(i) for i in range(r, r + n - 1)]
tt = ['?'] + [str(i) for i in range(1, l)] + [str(i) for i in range(r + n, 2 * n + 1)]
# print(tt)
for i in range(1, 2 * n + 1):
    if ans[i] == 0:
        if i < r or i >= r + n:
            ans[i] = ask(t + [str(i)])
        else:
            ans[i] = ask(tt + [str(i)])

s = ''.join(ans[1:])
print('! '+s)


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

int main(void){
  int a, b;
  cin >> a >> b;
  if(a == b){
    cout << "Draw" << endl;
    return 0;
  }
  if(a == 1){
    cout << "Alice" << endl;
    return 0;
  }
  if(b == 1){
    cout << "Bob" << endl;
    return 0;
  }
  if(a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
  return 0;
}


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

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2700
#include<stdio.h>

int main(){
  int x,y,i,tmp;
  for(i=0;;i++){
    scanf("%d %d",&x,&y);
    if(x == 0 && y ==0) break;
    if(x>y){
      printf("%d %d\n",y,x);
    } else {
      printf("%d %d\n",x,y);
    }
  }

    return 0 ;
  }


Measured memory_bytes: 1920
from collections import Counter
N = int(input())
A = list(map(int, (input().split())))
Q = int(input())
Cnt = Counter(A)
ans = sum(A)
for i in range(Q):
    b, c = map(int, input().split())
    if b in Cnt:
        ans += Cnt[b] * (c-b)
        Cnt[c] += Cnt[b]
        Cnt[b] = 0
    print(ans)

Measured memory_bytes: 21360
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vector<int> idx(n);
  iota(idx.begin(), idx.end(), 0);
  int fac = 1;
  for (int i = 2; i <= n; i++)
    fac *= i;
  double ans = 0;
  do {
    double res = 0;
    rep(i, n-1) {
      int dix = x[idx[i+1]]-x[idx[i]];
      int diy = y[idx[i+1]]-y[idx[i]];
      res += sqrt(dix*dix+diy*diy);
    }
    res /= fac;
    ans += res;
  } while (next_permutation(idx.begin(), idx.end()));
  cout << fixed << setprecision(9) << ans << endl;
  return 0;
}


Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int in_s = scan.nextInt();
		
		int h,m,s;
		
		h = in_s / 3600;
		in_s = in_s % 3600;
		
		m = in_s / 60;
		s = in_s % 60;
		
		System.out.println(h + ":" + m + ":" + s);
	}

}



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


int main(){
    int64_t N,M,A=0;
    cin>>N>>M;
    for (int i=0;i<M;i++){
        int64_t Ai;
        cin>>Ai;
        A+=Ai;
    }
    if(N<A){
        cout<<-1<<endl;
    }
    else{
        cout<<N-A<<endl;
    }

}

Measured memory_bytes: 3624
#include <stdio.h>
 
int main()
{
    int a[3];
    int n, i, j, max;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
      
      max = 0;
      
      for(j = 0; j < 3; j++){
        scanf("%d", &a[j]);
        if(a[max] < a[j])
          max = j;
      }
      
      if(2*a[max]*a[max] == (a[1]*a[1]) + (a[2]*a[2]) + (a[0]*a[0]))
        puts("YES");
      else
        puts("NO");
    }
    
    return 0;
}

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

int main() {
  std::set<int> a;
  a.insert(0);

  int n;
  std::cin >> n;

  for (int i = 0; i < n; i++) {
    int s;
    std::cin >> s;
    const auto b = a;
    for (const auto j : b) {
      a.insert(j + s);
    }
  }

  for (auto itr = a.crbegin(); itr != a.crend(); itr++) {
    if (*itr % 10 != 0) {
      std::cout << *itr << std::endl;
      return 0;
    }
  }
  std::cout << 0 << std::endl;
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int n,a[10005],b[10005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    long long ans1=0,ans2=0;
    for(int i=1;i<=n;i++){
        if(a[i]>b[i]){
            ans2+=a[i]-b[i];
        }else if(a[i]<b[i]){
            ans1+=(b[i]-a[i])/2+(b[i]-a[i])%2;
            ans2+=(b[i]-a[i])%2;
        }
    }
    if(ans1<ans2) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long

int main(){
  ll n,i;
  char s[10001];
  scanf("%lld",&n);
  scanf("%s",s);

  for(i=0;i<strlen(s);i++){
    s[i]='A'+(s[i]-'A'+n)%26;
  }
  printf("%s",s);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll H, W;
  cin >> H >> W;
  vector<string> S(H);
  for(auto&& i : S){
    cin >> i;
  }
  vector<vector<vector<ll>>> jougesayuu(4, vector<vector<ll>>(H, vector<ll>(W, 0)));
  iikae ue = jougesayuu.at(0);
  iikae shita = jougesayuu.at(1);
  iikae hidari = jougesayuu.at(2);
  iikae migi = jougesayuu.at(3);
  /*while(shita.at(0).at(0) < H){
    if(S.at(0).at(shita.at(0).at(0)) == H) break;
    shita.at(0).at(0)++;
  }
  while(migi.at(0).at(0) < H){
    if(S.at(0).at(migi.at(0).at(0)) == W) break;
    migi.at(0).at(0)++;
  }*/
  rep(tate, 0, H){
    rep(yoko, 0, W){
      if(S.at(tate).at(yoko) == '#') ue.at(tate).at(yoko) = 0;
      else if(tate == 0) ue.at(tate).at(yoko) = 1;
      else ue.at(tate).at(yoko) = ue.at(tate - 1).at(yoko) + 1;
    }
  }
  rem(tate, 0, H){
    rep(yoko, 0, W){
      if(S.at(tate).at(yoko) == '#') shita.at(tate).at(yoko) = 0;
      else if(tate == H - 1) shita.at(tate).at(yoko) = 1;
      else shita.at(tate).at(yoko) = shita.at(tate + 1).at(yoko) + 1;
    }
  }
  rep(tate, 0, H){
    rep(yoko, 0, W){
      if(S.at(tate).at(yoko) == '#') hidari.at(tate).at(yoko) = 0;
      else if(yoko == 0) hidari.at(tate).at(yoko) = 1;
      else hidari.at(tate).at(yoko) = hidari.at(tate).at(yoko - 1) + 1;
    }
  }
  rep(tate, 0, H){
    rem(yoko, 0, W){
      if(S.at(tate).at(yoko) == '#') migi.at(tate).at(yoko) = 0;
      else if(yoko == W - 1) migi.at(tate).at(yoko) = 1;
      else migi.at(tate).at(yoko) = migi.at(tate).at(yoko + 1) + 1;
    }
  }
  ll ans{};
  rep(tate, 0, H){
    rep(yoko, 0, W){
      ll kei = ue.at(tate).at(yoko) + shita.at(tate).at(yoko) + hidari.at(tate).at(yoko) + migi.at(tate).at(yoko) - 3;
      ans = max(kei, ans);
      //cout << kei << sp;
    }
    //cout << rt;
  }
  cout << ans << rt;
}

Measured memory_bytes: 161152