akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b;
    cin >> a >> b;
    int ab = a + b;
    if(ab % 2)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << ab / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s;
  ll k,tmp;
  cin >> s >> k;
  for(int i=0;i<s.size()-1;i++){
    tmp = 'z'-s[i]+1;
    if(s[i]!='a'&&tmp<=k){
      s[i]='a';
      k-=tmp;
    }
  }
  tmp=k%26;
  tmp=(tmp+(s.back()-'a'))%26;
  s.back() = 'a'+tmp;
  cout <<s<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i, n;
    cin >> n;
    vector <int> a(n), b(n);
    for(i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    bool ans = false;
    for(i=0; i<n-2; i++){
        if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2]){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3656
def main() -> None:
    A, B, C = map(int, input().split())
    l = [A, B, C]
    l.sort()
    if l[0] == 5 and l[1] == 5 and l[2] == 7:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {

	long long N;
	cin >> N;

	string ans;
	while (N > 0) {
		N--;
		ans += 'a' + N % 26;
		N /= 26;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define  REP(i, n) for(int i=0; i<(n); ++i)
#define  ALL(obj) (obj).begin(), (obj).end()
#define ll long long
#define ul unsigned long

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B;
  cin >> A >> B;
  int i, count=1;
  for(i=0; count < B;)
  {
    count = count-1 + A;
    ++i;
  }
  cout << i;
  return 0;
}

Measured memory_bytes: 256
fn main(){
    let mut sc = Scanner::new();
    while sc.read() {
        let n = sc.next();
        let m = sc.next();
        let mut graph = vec![vec![]; n];
        for _ in 0..m {
            let a = sc.next::<usize>() - 1;
            let b = sc.next::<usize>() - 1;
            graph[a].push(b);
            graph[b].push(a);
        }
        let mut flg = vec![false; n];
        println!("{}", rec(0, &mut flg, &graph));
    }
}

fn rec(v: usize, flg: &mut Vec<bool>, graph: &Vec<Vec<usize>>) -> i32 {
    flg[v] = true;
    let mut end = true;
    for f in flg.iter() {
        end &= *f;
    }
    let res = if end {
        1
    } else {
        let mut s = 0;
        for w in graph[v].iter() {
            if !flg[*w] {
                s += rec(*w, flg, graph);
            }
        }
        s
    };
    flg[v] = false;
    res
}

#[allow(dead_code)]
struct Scanner {
    buf: Vec<u8>, i: usize, next: Option<String>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner { buf: vec![], i: 0, next: None, }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        self.wrapped::<T>().unwrap()
    }

    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut res = Vec::<T>::with_capacity(n);
        for _ in 0..n { res.push(self.next()) }
        res
    }

    fn wrapped<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.read();
        self.next.take().and_then(|s| s.parse::<T>().ok())
    }

    fn read(&mut self) -> bool {
        if self.next.is_some() { return true }
        let mut s = String::with_capacity(16);
        while let Some(c) = self.get_char() {
            if !c.is_whitespace() { s.push(c); }
            else if !s.is_empty() { break; }
        }
        self.next = if !s.is_empty() { Some(s) } else { None };
        self.next.is_some()
    }

    fn get_char(&mut self) -> Option<char> {
        if self.i >= self.buf.len() {
            use std::io::BufRead;
            let reader = std::io::stdin();
            let mut buffer = reader.lock();
            let len = match buffer.fill_buf() {
                Ok(bytes) => {
                    self.buf.resize(bytes.len(), b'\0');
                    self.buf.copy_from_slice(bytes);
                    Some(bytes.len())
                },
                Err(_) => None,
            };
            self.i = 0;
            if len.is_some() { buffer.consume(len.unwrap()); }
            if len.is_none() || len.unwrap() == 0 { return None }
        }
        self.i += 1;
        Some(self.buf[self.i - 1] as char)
    }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	static int N;
	static int M;
	static int a[];
	static int b[];
	static long c[];
	static long v[];
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		a = new int[M];
		b = new int[M];
		c = new long[M];
		v = new long[N];
		Arrays.fill(v, Long.MAX_VALUE / 2);
		v[0] = 0;
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			c[i] = sc.nextLong() * -1;
		}
		if(Bellmanford()) {
			System.out.println(-1 * v[N - 1]);
		} else {
			System.out.println("inf");
		}
	}
	
	public static boolean Bellmanford() {
		long pre = 0;
		for(int k = 0; k <= 2 * N; k++) {
			boolean flag = false;
			for(int i = 0; i < M; i++) {
				if(v[a[i]] + c[i] < v[b[i]]) {
					if(k == N - 2) {
						pre = v[N - 1];
					}
					if(k == 2 * N && v[N - 1] < pre) {
						return false;
					} else if(k == 2 * N){
						return true;
					}
					flag = true;
					v[b[i]] = v[a[i]] + c[i];
				}
			}
			if(!flag) {
				break;
			}
		}
		return true;
	}
}


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

using namespace std;

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

    if(A >= 13)
    {
        cout << B << endl;
    }
    else if(A >= 6 && 12 >= A)
    {
        cout << B/2 << endl;
    } 
    else
    {
        cout << '0' << endl;
    }

    return 0;
}

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

#define int long long

signed main() {
    int N;
    cin >> N;
    set<int> st;
    for(int i=0; i<N; ++i) {
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << st.size() << endl;
    return 0;
}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

using Int = unsigned int;
using llong = long long;
using Llong = unsigned long long;
using ldouble = long double;
using intV = vector<int>;
using llongV = vector<long long>;
using llongVV = vector<vector<long long>>;

using Graph = vector<vector<llong>>;

struct Edge {
    llong from;
    llong to;
    llong cost;
};

template<typename T=llong>
using asc = less<T>();
template<typename T=llong>
using desc = greater<T>();

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N, M, L;
    cin >> N >> M >> L;

    llongVV dist(N, llongV(N, INF));

    FOR(i, N) {
        dist[i][i] = 0;
    }

    FOR(i, M) {
        llong fr, to, cost;
        cin >> fr >> to >> cost;
        fr--;
        to--;
        dist[fr][to] = cost;
        dist[to][fr] = cost;
    }

    FOR(k, N) {
        FOR(i, N) {
            FOR(j, N) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    llongVV fuel(N, llongV(N, INF));
    FOR(i, N) {
        fuel[i][i] = 0;
    }
    FOR(i, N) {
        FOR(j, N) {
            if(dist[i][j] <= L) fuel[i][j] = 1;
        }
    }
    FOR(k, N) {
        FOR(i, N) {
            FOR(j, N) {
                fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]);
            }
        }
    }

    llong Q;
    cin >> Q;
    llongV ans;
    FOR(i, Q) {
        llong s, t;
        cin >> s >> t;
        s--;
        t--;
        if(fuel[s][t] == INF) ans.push_back(-1);
        else ans.push_back(fuel[s][t] - 1);
    }

    FOR(i, Q) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 2816
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

main = do
  n <- readLn :: IO Int
  (a:as) <- getIntListBC
  let ans1 = solve a as
      x = (+1) $ abs a
      ans2 = if a >= 0 then x + solve (-1) as
                       else x + solve 1 as
  print $ min ans1 ans2

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine

solve :: Int -> [Int] -> Int
solve _ []    = 0
solve s (a:as)
  | s > 0     = let sum = s + a
                in if sum >= 0
                     then (sum + 1) + solve (-1) as
                     else solve sum as
  | s < 0     = let sum = s + a
                in if sum <= 0
                     then ((negate sum) + 1) + solve 1 as
                     else solve sum as
  | otherwise = 1 + solve 1 (a:as)


Measured memory_bytes: 13692
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

G = []
dp = []

def rec(v):
    global dp
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for node in G[v]:
        ans = max(ans, rec(node) + 1)
    dp[v] = ans
    return dp[v]

def main():
    global G, dp
    n, m = list(map(int, input().strip().split()))
    G = [[] for _ in range(n)]
    dp = [-1] * n
    for i in range(m):
        p, q = list(map(int, input().strip().split()))
        p -= 1
        q -= 1
        G[p].append(q)
    ans = 0
    for i in range(n):
        r = rec(i)
        # print("r: ", r)
        ans = max(ans, r)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116848
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
 
#define INF 1e9
#define LINF 1e18
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
  string s, t;
  cin >> s >> t;
  if(s == t){
    cout << s.size() << endl;
    return 0;
  }
  ll n = s.size(), m = t.size();
  vector<vector<ll>> list(m), tmp(26);
  rep(i, n){
    tmp[s[i] - 'a'].push_back(i);
  }
  rep(i, m){
    if(tmp[t[i] - 'a'].size() == 0){
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i, 26)tmp[i].push_back(INF);

  ll loop = 0, now = -1;
  rep(i, m){
    if(INF == *upper_bound(ALL(tmp[t[i] - 'a']), now)){
      loop++;
      now = tmp[t[i] - 'a'][0];
    }
    else {
      now = *upper_bound(ALL(tmp[t[i] - 'a']), now);
    }
  }
  ll res = loop * n + now + 1;
  cout << res << endl;
}
 

Measured memory_bytes: 6916
gcdlcm [a,b] = gcdlcm' [read a, read b]
  where
    gcdlcm' [x,y] = show (gcd x y) ++ " " ++  show (lcm x y)

main = do
  s  <- getContents
  putStr $ unlines   $ map gcdlcm $ map words $ lines s

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

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
using namespace std;
typedef long long ll;

//GAC AGC ACG がダメ ACGT

int N;
ll res, DP[100][4][4][4];

int main() {
	cin >> N;
	N -= 2;
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (i == 0 && j == 2 && k == 1)continue;
				if (i == 0 && j == 1 && k == 2)continue;
				if (i == 2 && j == 0 && k == 1)continue;
				DP[0][i][j][k] = 1;
			}
		}
	}
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				for (int l = 0; l < 4; ++l) {
					for (int m = 0; m < 4; ++m) {
						if (j == 0 && k == 2 && (l == 1 || m == 1))continue;
						if (j == 0 && k == 1 && l == 2)continue;
						if (j == 2 && k == 0 && l == 1)continue;
						if ((j == 0 || k == 0) && l == 2 && m == 1)continue;
						DP[i][k][l][m] = (DP[i][k][l][m] + DP[i - 1][j][k][l]) % mod;
					}
				}
			}
		}
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (i == 0 && j == 2 && k == 1)continue;
				if (i == 0 && j == 1 && k == 2)continue;
				if (i == 2 && j == 0 && k == 1)continue;
				res += DP[N - 1][i][j][k];
				res %= mod;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class ABC142
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        double count = 0;
        for (int i = 1; i <= n; i++)
        {
            if (i%2 == 1)
            {
                count++;
            }
        }

        Console.WriteLine(count/n);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int n, m;
vector<int> p;
vector<P> xy;
int par[100003];

int root(int x)
{
    if (par[x] == x)
        return x;
    else
    {
        par[x] = root(par[x]);
        return par[x];
    }
}

void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y)
        return;
    else
    {
        par[x] = y;
    }
}

int main()
{
    cin >> n >> m;
    FOR(i, 1, n + 1)
    {
        par[i] = i;
    }
    REP(i, n)
    {
        int temp;
        cin >> temp;
        p.push_back(temp);
    }
    REP(i, m)
    {
        int x, y;
        cin >> x >> y;
        xy.push_back(make_pair(x, y));
        unite(x, y);
    }

    int ans = 0;
    FOR(i, 1, n + 1)
    {
        if (root(i) == root(p[i - 1]))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			
			int[] a = new int[n+2];
			int[] b = new int[n+2];
			int[] c = new int[n+2];
			int[] d = new int[n+2];
			int[] e = new int[n+2];
			int[] f = new int[n+2];
			
			int an = 0, bn = 0, cn = 0, dn = 0, en = 0, fn = 0;
			
			dn = sc.nextInt();
			for(int i=1;i<=dn;i++) d[i] = sc.nextInt();
			en = sc.nextInt();
			for(int i=1;i<=en;i++) e[i] = sc.nextInt();
			fn = sc.nextInt();
			for(int i=1;i<=fn;i++) f[i] = sc.nextInt();
			
			int ans = Integer.MAX_VALUE;
			int[] ini = new int[2];
			int com;
			
			if(d[dn]>e[en] && e[en]>f[fn]){
				ini[0] = 0;
				ini[1] = 2;
			}else if(d[dn]>e[en] && e[en]<f[fn]){
				ini[0] = 0;
				ini[1] = 3;
			}else if(d[dn]<e[en] && e[en]<f[fn]){
				ini[0] = 1;
				ini[1] = 3;
			}else if(d[dn]<e[en] && e[en]>f[fn]){
				ini[0] = 1;
				ini[1] = 2;
			}
			
			for(int k=0;k<2;k++){
				com = ini[k];
				for(int i=0;i<=n;i++){
					a[i] = d[i];
					b[i] = e[i];
					c[i] = f[i];
				}
				an = dn;
				bn = en;
				cn = fn;
				for(int i=0;i<=m;i++){
					if(bn==0 && (an==0 || cn==0)){
						ans = Math.min(ans, i);
						break;
					}
					
					if(com==0){
						bn++;
						b[bn] = a[an];
						an--;
						if(b[bn]>c[cn]) com = 2;
						else com = 3;
					}else if(com==1){
						an++;
						a[an] = b[bn];
						bn--;
						if(b[bn]>c[cn]) com = 2;
						else com = 3;
					}else if(com==2){
						cn++;
						c[cn] = b[bn];
						bn--;
						if(a[an]>b[bn]) com = 0;
						else com = 1;
					}else if(com==3){
						bn++;
						b[bn] = c[cn];
						cn--;
						if(a[an]>b[bn]) com = 0;
						else com = 1;
					}
				}
			}
			
			if(ans==Integer.MAX_VALUE) System.out.println(-1);
			else System.out.println(ans);
		}	
	}	
}

Measured memory_bytes: 22252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int K = scan.nextInt();
        int X = scan.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = X - K + 1; i < X + K; i++) {
            sb.append(i);
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
}


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

int main() {
  ll x;
  cin >> x;
  ll a = 1;
  while (true) {
    rep(j, a) {
      ll bp = j;
      ll bm = j * -1;
      if (pow(a, 5) - pow(bp, 5) == x) {
        cout << a <<" "<< bp << endl;
        return 0;
      }
      if (pow(a, 5) - pow(bm, 5) == x) {
        cout << a <<" "<< bm << endl;
        return 0;
      }
    }
		a++;
  }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const int INF = 1e9;

int main(){
   int n; cin >> n;
   vector<int> a(n);
   REP(i,n) cin >> a[i];
   sort(a.begin(),a.end(),greater<int>());
   vector<ll> edge;
   REP(i,n-1){
       if(a[i] == a[i+1]) {
           edge.push_back(a[i]);
           ++i;
       }
   }
   if(edge.size() <= 1) cout << 0 << endl;
   else cout << edge[0] * edge[1] << endl;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define pbp(a,b) push_back({a,b})
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

ll nextPowerOf2(ll n)   
{ 
    n--; 
    n |= n >> 1ll; 
    n |= n >> 2ll; 
    n |= n >> 4ll; 
    n |= n >> 8ll; 
    n |= n >> 16ll; 
    n++; 
    return n; 
}

bool cmp(ll a,ll b)
{
    return (a>b);
}

int main() {
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,i,j;

    int a[5],ans;
    rep(p,0,5){cin>>n;if(n==0)ans=p+1;}
    cout<<ans;
    return 0;
}

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

using namespace std;

typedef long long ll;

struct State
{
    int a, b;
};

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<State> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].a >> v[i].b;
    sort(v.begin(), v.end(), [](const State &a, const State &b) -> bool {
        return a.b < b.b;
    } );
    int cur = 0;
    for (int i = 0; i < n; i++)
    {
        cur += v[i].a;
        if (cur > v[i].b)
        {
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;


int main()
{

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


	int n; cin >> n;
	int mx = 0;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		if (x >= mx)
			ans++;
		mx = max(mx, x);
	}
	cout << ans << '\n';




	return 0;
}


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

abl = [map(int,input().split()) for _ in range(n)]

al = []
bl = []

for a,b in abl:
    al.append(a)
    bl.append(b)

al = sorted(al)
bl = sorted(bl)
if n % 2 == 0:
    min_a = (al[n//2-1] + al[n//2]) / 2
    max_a = (bl[n//2-1] + bl[n//2]) / 2
else:
    min_a = al[(n-1)//2]
    max_a = bl[(n-1)//2]

if n % 2 == 0:
    print(int((max_a - min_a) * 2 + 1))
else:
    print(max_a - min_a + 1)

Measured memory_bytes: 146520
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100;

int a[N][N];
int n,d;

bool is(int x,int y)
{
    int ans=0,tem;
    for(int i=1;i<=d;i++)
        ans+=(a[x][i]-a[y][i])*(a[x][i]-a[y][i]);
    tem=sqrt(ans);
    if(tem*tem==ans&&ans)return true;
    else return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>d;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=d;j++)
        cin>>a[i][j];
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(is(i,j))
        ans++;
    cout<<ans/2;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (n, taka, ao) = readLine()!!.split(' ').map(String::toInt)

    val branch = Array(n+1) { mutableSetOf<Int>() }
    (1 until n).forEach {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        branch[a].add(b)
        branch[b].add(a)
    }
    val takaMinCost = LongArray(n + 1) { Long.MAX_VALUE / 2 }
    val aoMinCost = LongArray(n + 1) { Long.MAX_VALUE / 2 }

    takaMinCost[taka]=0
    aoMinCost[ao]=0
    val queue = ArrayDeque<Int>().apply { addFirst(taka) }
    while (queue.isNotEmpty()) {
        val cur = queue.pollLast()!!
        for (to in branch[cur]) {
            if (takaMinCost[to] > takaMinCost[cur] + 1) {
                takaMinCost[to] = takaMinCost[cur] + 1
                queue.addFirst(to)
            }
        }
    }
    queue.add(ao)
    while (queue.isNotEmpty()) {
        val cur = queue.pollLast()!!
        for (to in branch[cur]) {
            if (aoMinCost[to] > aoMinCost[cur] + 1) {
                aoMinCost[to] = aoMinCost[cur] + 1
                queue.addFirst(to)
            }
        }
    }

    val aoTakaDist = aoMinCost[taka]
    val cost = aoMinCost[(1..n).filter { aoMinCost[it] > takaMinCost[it] }.maxBy { aoMinCost[it] }!!]
    println(cost - 1)
}

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

using namespace std;

#define MOD 1000000007
#define N 200005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

ll segt[4*N];
ll dp[N];
int h[N], a[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int i, x, n; 
    ll maxi;
    cin>>n;
    int base = 1;
    while(base <= n) base = base * 2;
    for(i=0; i<n; i++){
        cin>>h[i];
    }
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    for(i=0; i<n; i++){
        x = h[i] + base;
        maxi = 0;
        while(x > 1){
            if(x & 1) maxi = max(maxi, segt[x-1]);
            x = x>>1;
        }
        dp[h[i]] = maxi + a[i];
        x = h[i] + base;
        while(x>=1){
            segt[x] = max(segt[x], dp[h[i]]);
            x = x>>1;
        }
    }
    cout<<*max_element(dp, dp+n+1);
    return 0;
}

Measured memory_bytes: 8448
#include<stdio.h>
int main()
{
  int h,w;
  int i,j;
  int x[1000000],y[1000000];
  int c=0,s=0,e=0,kaisu=0;
  char a[1000][1001];
  
    scanf("%d %d", &h, &w);
  
    for(i=0;i<h;i++){
        scanf("%s", a[i]);
        for(j=0;j<w;j++){
            if(a[i][j]=='#'){
                x[e]=i;
                y[e]=j;
                e++;
            }
        }
    }
  
    if(e==h*w){
        puts("0");
        return 0;
    }
    while(e!=h*w){
        if(s==c){
            c=e;
            kaisu++;
        }
        if(x[s]-1>=0 && a[x[s]-1][y[s]]=='.'){
            a[x[s]-1][y[s]]='#';
            x[e]=x[s]-1;
            y[e]=y[s];
            e++;
        }
      if(x[s]+1<h&&a[x[s]+1][y[s]]=='.'){
            a[x[s]+1][y[s]]='#';
            x[e]=x[s]+1;
            y[e]=y[s];
            e++;
        }
        if(y[s]-1>=0&&a[x[s]][y[s]-1]=='.'){
            a[x[s]][y[s]-1]='#';
            x[e]=x[s];
            y[e]=y[s]-1;
            e++;
        }
        if(y[s]+1<w && a[x[s]][y[s]+1]=='.'){
            a[x[s]][y[s]+1]='#';
            x[e]=x[s];
            y[e]=y[s]+1;
            e++;
        }
        s++;
    }
    printf("%d", kaisu);
    return 0;
}

Measured memory_bytes: 8960
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    ans = 0
    s = set()
    while True:
        if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
            print(ans)
            break
        newA =  B / 2 + C / 2
        newB =  A / 2 + C / 2
        newC =  A / 2 + B / 2
        A = newA
        B = newB
        C = newC
        ans += 1
        n = ','.join(map(str, [A, B, C]))
        if n in s:
            print("-1")
            break
        s.add(n)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62092
import java.util.Scanner;


public class Main
{

	public static void main(String[] args)
	{
		Scanner in =new Scanner(System.in);
		int a,b;
		double f;
		a=in.nextInt();
		b=in.nextInt();
		f=(double)a/b;
		
		System.out.printf("%d %d %1.5f",(a/b),(a%b),f);

	}

}

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

int main(){
  int i,t;
  vector<int> a(100000),b(10000);
  for(i=0;i>=0;i++){

cin >> a[i] >> b[i];
if(a[i]==0 && b[i]==0){
  break;
}}
for(i=0;i>=0;i++){
if(a[i]==0 && b[i]==0){
  break;
} else {
string s1(b[i],'#');
for(t=0;t<a[i];t++){
  cout << s1 << endl;
}

} cout << endl;
}return 0;
}



Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    long long n,m,res,r,a,b,d,i;
    scanf("%lld%lld",&n,&m);
    if(n>m)
    {
        a=m;
        b=n;
    }
    else
    {
        a=n;
        b=m;
    }
        while(a!=0)
        {
            res=b%a;
            b=a;
            a=res;
        }
        printf("%lld\n",b);


    return 0;
}

Measured memory_bytes: 2712
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll a;
	cin >> a;
	if (a <= 999) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

string s, t;
ll dp[3100][3100];

int main() {
    cin >> s >> t;

    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string res = "";
    ll i = s.size(), j = t.size();
    while(i > 0 && j > 0) {
        if(dp[i-1][j] == dp[i][j]) i--;
        else if(dp[i][j-1] == dp[i][j]) j--;
        else {
            res = s[i-1] + res;
            i--; 
            j--;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 73984
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    if n == 1 {
        println!("Hello World");
        return;
    }
    let a = get!(usize);
    let b = get!(usize);
    println!("{}", a + b);

}


Measured memory_bytes: 8572
#!/usr/bin/env python3
import sys
import math
import collections

def comb(n, r):
    if n ==0 or n == 1: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def solve(N: int, A: "List[int]"):

    count_dict = collections.Counter(A)

    comb_list = []
    for i in range(0, N+1):
        comb_list.append(int(comb(i, 2)))

    ans_dic = {}
    sum_all = 0
    for key, value in count_dict.items():
        ans_dic[key] = comb_list[value]
        sum_all += comb_list[value]

    for k in range(N):
        ans = sum_all - ans_dic[A[k]] \
            + comb_list[count_dict[A[k]]-1]
        print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 51548
N = gets.to_i
array=gets.chomp.split(" ").map(&:to_i)
if array[0] != 0
    puts 0
    exit
end

grouped = array.group_by{|e| e}
if grouped[0].length != 1
    puts 0
    exit
end

d_max = array.max
ret = 1
(1..d_max).each do |d|
    if grouped[d] == nil
        puts 0
        exit
    end
    count = grouped[d].length
    if count == 0
        puts 0
        exit
    end
    count.times do
        ret = ret * grouped[d-1].length
        ret = ret % 998244353
    end
end
puts ret

Measured memory_bytes: 19340
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
#define ar array
const ll maxN=1e5+1 , N=1e2+5;
ar<ll,2> a[N];
ll dp[maxN];
ll n , w;
void solve(){
	cin>> n >> w ;
	for(ll i=0;i<maxN ; i++)dp[i]=inf;
	ll ans=0;
	dp[0]=0;
	for(ll i=0;i<n ;i++)cin>>a[i][0]>>a[i][1];
	for(ll i=0;i<n ; i++){
		for(ll j=maxN-1 ; j>=a[i][1] ; j--){
			if(dp[j-a[i][1]]+a[i][0]<=w){
				dp[j]=min(dp[j] , dp[j-a[i][1]]+a[i][0]);
				ans=max(ans , j);
			}
		}
	}
	cout<<ans;
}
int main(){
	//mahakal(),fast;
	ll t=1;
	// cin>> t ;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 4376
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        d: usize,
        x: [[i64; d]; n],
    }
    let  mut cnt  = 0;
    for i in 0..n {
        for j in 0..n {
            if i != j {
                let mut sum   = 0;
                for k in  0..d {
                    sum+=(x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                if f64::sqrt(sum as f64) == f64::sqrt(sum as f64) as i64 as f64{
                    cnt+=1;
                }
            }
        }
    }
    println!("{}", cnt / 2);
}

Measured memory_bytes: 4352
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n =scanner.nextInt()
    val list = arrayListOf<Long>()
    (1..n).forEach {
        list.add(scanner.nextLong())
    }
    println("${list.min()} ${list.max()} ${list.sum()}")
}



Measured memory_bytes: 44760
#include <stdio.h>

#define INF	(255)

int main(void)
{
	int r, l;
	int n, i;
	int in;

	scanf("%d", &n);
	while (n--){
		r = l = 0;
		for (i = 0; i < 10; i++){
			scanf("%d", &in);
			if (r < in && l < in){
				if (in - r > in - l) l = in;
				else r = in;
			}
			else if (r < in) r = in;
			else if (l < in) l = in;
			else r = l = INF;
		}
		puts(r != INF ? "YES" : "NO");
	}

	return (0);
}

Measured memory_bytes: 576
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int K;
	string s;
	cin >> s >> K;
	vector<string> a;
	for (int i = 0; i < s.size(); i++) {
		for (int j = i; j < s.size()&&j<i+K; j++) {
			string x;
			for (int k = i; k <= j; k++) {
				x += s[k];
			}
			a.push_back(x);
		}

	}
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << a[K - 1] << endl;

}


Measured memory_bytes: 1660
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=55;

string s,t,ans;

int main()
{
	cin>>s>>t;
	int n=SZ(s),m=SZ(t);

	for(int i=0;i<n-m+1;i++)
	{
		bool f=1;
		for(int j=i;j<i+m;j++) if(s[j]!='?'&&s[j]!=t[j-i]) f=0;

		if(!f) continue;

		string buf=s;
		for(int j=i;j<i+m;j++) buf[j]=t[j-i];
		for(int j=0;j<n;j++) if(buf[j]=='?') buf[j]='a';
		
		if(ans=="") ans=buf; else ans=min(ans,buf);
	}

	cout<<(ans==""?"UNRESTORABLE":ans);

	return 0;
}

Measured memory_bytes: 3628
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

best_i = -1
diff = float("inf")

for i in range(N):
    h = H[i]
    tmp = T - h * 0.006
    new_diff = abs(tmp - A)
    if new_diff < diff:
        best_i = i
        diff = new_diff

print(best_i + 1)

Measured memory_bytes: 3060
def solve(arr,n):
    maxx=[]
    ma=0  
    for i in arr:
        ma=max(ma,i)  
        maxx.append(ma) 
    ans=0 
    for i in range(n):
        ans+=abs(maxx[i]-arr[i])
    print(ans) 
n=int(input()) 
a=[int(x) for x in input().split()] 
solve(a,n)

Measured memory_bytes: 32188
#include <stdio.h>
#include <vector>

using namespace std;

struct Node{
	Node(){
		brother = parent = -1;
		height = depth = num_of_children = 0;
	}
	int parent,brother,depth,num_of_children,height;
	vector<int> children;
};

void calcDepth(Node nodes[],int root_id){
	for(int i = 0;i < nodes[root_id].num_of_children;i++){
		nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
		calcDepth(nodes,nodes[root_id].children[i]);
	}
}

void calcHeight(Node nodes[],int height,int parent){
	nodes[parent].height = max(nodes[parent].height,height+1);
	if(nodes[parent].parent != -1) calcHeight(nodes,height+1,nodes[parent].parent);
}

int main(){
	int n,id,left_id,right_id,root_id;
	scanf("%d",&n);
	Node nodes[n];

	for(int i = 0; i < n; i++){
		scanf("%d %d %d",&id,&left_id,&right_id);
		if(left_id != -1){
			nodes[id].children.push_back(left_id);
			nodes[id].num_of_children++;
			nodes[left_id].parent = id;
		}
		if(right_id != -1){
			nodes[id].children.push_back(right_id);
			nodes[id].num_of_children++;
			nodes[right_id].parent = id;
		}
		if(left_id != -1 && right_id != -1){
			nodes[left_id].brother = right_id;
			nodes[right_id].brother = left_id;
		}
	}

	for(root_id = 0; root_id < n; root_id++){
		if(nodes[root_id].parent == -1) break;
	}

	if(n > 1){
		calcDepth(nodes,root_id);

		for(int i = 0; i < n; i++){
			if(nodes[i].num_of_children == 0) calcHeight(nodes,0,nodes[i].parent);
		}
	}

	for(int i = 0; i < n; i++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
				,i,nodes[i].parent,nodes[i].brother,nodes[i].num_of_children,nodes[i].depth,nodes[i].height);
		if(nodes[i].parent == -1){
			printf(" root\n");
		}else if(nodes[i].num_of_children == 0){
			printf(" leaf\n");
		}else{
			printf(" internal node\n");
		}

	}
}


Measured memory_bytes: 2732
#include<stdio.h>

void qsort(int a[],int left,int right){
	
	int p=(left+right)/2;
	int pivot=a[p];
	int i,temp;
	if(left<right){
		p=left;
		pivot=a[p];
		for(i=left+1;i<=right;i++){
			if(a[i]<pivot){
				p++;
				temp=a[i];a[i]=a[p];a[p]=temp;//swap
			}
		}
		temp=a[left];a[left]=a[p];a[p]=temp;//swap
		qsort(a,left,p-1);
		qsort(a,p+1,right);
	}

}

int search(int key,int a[],int n){
	int i;
	for(i=0;i<n;i++){
		if(key==a[i])return i;
	}
	
	return i;
}

int isVisited(int v[],int n){
	int i;
	for(i=0;i<n;i++){
		if(v[i]!=1)return -1;
	}
	return 1;
}
	
int min(int a,int b){
	if(a<b)return a;
	return b;
}


int main(void){
	int n,i,j,minW,cost=0,w;
	int a[1000],b[1000],v[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
		v[i]=0;
	}
	qsort(b,0,n-1);
	
	for(i=0;i<n;i++){	
		int x=i;
		int sum=0;
		int count=0;
		minW=10000;
		while(v[x]==0){
			v[x]=1;
			sum+=a[x];
			count++;
			if(minW>a[x])minW=a[x];
			x=search(a[x],b,n);
		}
		if(count<2)continue;
		
		cost+=min(b[0]*(count+1)+sum+minW,sum+(count-2)*minW);
		if(isVisited(v,n)==1)break;
	}
	
	printf("%d\n",cost);
	return 0;
}

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

long long cnt[3] = {0};

long long solve();

int main() {
  while(1) {
    bool allzero = 1;
    for(int i = 0; i < 3; ++i) cnt[i] = 0;
    for(int i = 0; i < 6; ++i) {
      long long a;
      cin >> a;
      if(a != 0) allzero = 0;
      cnt[i % 3] += a;
    }
    if(allzero) break;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < 3; ++i) {
    long long now = i;
    bool ch = 1;
    for(int j = 0; j < 3; ++j) {
      if(cnt[j] - i < 0) {
        ch = 0;
        break;
      }
      now += (cnt[j] - i) / 3;
    }
    if(ch) ans = max(ans, now);
  }
  return ans;
}


Measured memory_bytes: 3088
n=int(input())
A=list(map(int,input().split()))

for i in range(n):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    B=A.copy()
    B=list(map(str,B))
    print(" ".join(B))

Measured memory_bytes: 7604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
#define MOD (1000000007LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

#define vv(t) vector< vector< T > >
#define pb push_back
#define pu push
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define EQ(a,b) (abs((a)-(b))<EPS)

int n;
double dp[100001][21];

int main(void){
  ios_base::sync_with_stdio(0);
  while(cin >> n, n){
    memset(dp, 0, sizeof(dp));

    double e = 0.0;
    dp[1][1] = 1.0;

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= min(i, 20); j++){
        e += dp[i][j] * pow(0.5, j - 1);
        dp[i+1][1] += dp[i][j] * (1.0 - pow(0.5, j - 1));
        dp[i+1][j+1] += dp[i][j] * pow(0.5, j - 1);
      }
    }
    cout << fixed << setprecision(8) << e << endl;
  }
  return 0; 
}

Measured memory_bytes: 17676