akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> a(n);
    string t;
    rep(i,n)cin >> s[i] >> a[i];
    bool f = false;
    cin >> t;
    ll ans = 0;
    rep(i,n){
        if(s[i] == t){
            f = true;
            continue;
        }
        if(f){
            ans += a[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

#include <string>
#include <regex>
#include <vector>
#include <memory>
//namespace fs = boost::filesystem;
const long int MOD = 1e9+7;
int main(void){
    long long int N,M;
    //N:number of s
    //M:number of c
    std::cin>>N>>M;

    if(N>=M/2){
        std::cout<<M/2<<std::endl;
    }
    else{
        long long int Cnum = M - 2*N;
        std::cout<<Cnum/4+N<<std::endl;

    }


 	return 0;
}



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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sm = 0;
    forn(i, n) {
      cin >> a[i];
      sm += a[i];
    }
    ll curr = 0ll, res = 1e18;
    forn(i, n) {
        if(curr+a[i] >= sm - (curr + a[i])) {
            res = min(res, abs(curr + a[i] - (sm - (curr + a[i]))));
        } else
            res = min(res, abs(sm - (curr + a[i]) - (curr + a[i])));
        curr += a[i];
    }
    cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

struct RURM {
	using t1 = int;
	using t2 = int;
	static t1 id1() { return INT_MAX; }
	static t2 id2() { return -1; }
	static t1 op1(const t1& l, const t1& r) { return min(l, r); }
	static t1 op2(const t1& l, const t2& r) { return r != -1 ? r : l; }
	static t2 op3(const t2& l, const t2& r) { return r != -1 ? r : l; }
};

template <typename M>
class LazySegmentTree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int n;
	vector<T1> data;
	vector<T2> lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
	void suc(int l, int r, int node, int lb, int ub, T2 val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) {
			lazy[node] = M::op3(lazy[node], val);
			return;
		}
		push(node);
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]), M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
	T1 sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id1();
		if (l <= lb && ub <= r) return M::op2(data[node], lazy[node]);
		int c = (lb + ub) / 2;
		return M::op2(M::op1(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub)), lazy[node]);
	}
public:
	LazySegmentTree(int n_) : n(size(n_)), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	LazySegmentTree(int n_, T1 v1, T2 v2) : n(size(n_)), data(n * 2, v1), lazy(n * 2, v2) {}
	LazySegmentTree(const vector<T1>& data_)
		: n(size(data_.size())), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {
		init(data_);
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void init(const vector<T1>& data_) {
		for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
		init();
	}
	void update(int l, int r, T2 val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T1 find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y, val;
	cin >> n >> q;
	LazySegmentTree<RURM> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			cin >> val;
			st.update(x, y, val);
		}
	}
	return 0;
}



Measured memory_bytes: 4944
#include<iostream>
#include<algorithm>
using namespace std;
int N;
int dp[2000][2000],X[2000],Y[2000],nX[2000],nY[2000];
int A[3];
int tmp[2000];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)dp[i][j]=-1e9;
	for(int i=0;i<N;i++)X[i]=Y[i]=-1e9;
	cin>>A[0]>>A[1];
	A[0]--,A[1]--;
	dp[A[0]][A[1]]=0;
	X[A[0]]=0;
	Y[A[1]]=0;
	int ans=0;
	for(int i=1;i<N;i++)
	{
		int T[3];
		for(int j=0;j<3;j++)
		{
			cin>>A[j];
			A[j]--;
			T[j]=dp[A[j]][A[j]];
		}
		if(A[0]==A[1]&&A[1]==A[2])
		{
			ans++;
			continue;
		}
		int MX=0;
		for(int j=0;j<N;j++)
		{
			nX[j]=X[j];
			nY[j]=Y[j];
			if(MX<X[j])MX=X[j];
			if(MX<Y[j])MX=Y[j];
		}
		for(int j=0;j<3;j++)
		{
			int a=A[j],b=A[(j+1)%3],c=A[(j+2)%3];
			if(a==b)
			{
				for(int k=0;k<N;k++)tmp[k]=max(dp[a][k],dp[k][a]);
				for(int k=0;k<N;k++)
				{
					int now=dp[k][c]=max(dp[k][c],tmp[k]+1);
					if(nX[k]<now)nX[k]=now;
					if(nY[c]<now)nY[c]=now;
				}
			}
		}
		for(int j=0;j<3;j++)
		{
			int b=A[(j+1)%3],c=A[(j+2)%3];
			int now=dp[b][c]=max(dp[b][c],T[j]+1);
			if(nX[b]<now)nX[b]=now;
			if(nY[c]<now)nY[c]=now;
		}
		for(int j=0;j<3;j++)for(int k=0;k<3;k++)if(j!=k)
		{
			int a=A[j],b=A[k];
			int now=dp[a][b]=max(dp[a][b],MX);
			if(nX[a]<now)nX[a]=now;
			if(nY[b]<now)nY[b]=now;
		}
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<3;k++)
			{
				int a=A[k];
				int now=dp[j][a]=max(dp[j][a],max(X[j],Y[j]));
				if(nX[j]<now)nX[j]=now;
				if(nY[a]<now)nY[a]=now;
				now=dp[a][j]=max(dp[a][j],max(X[j],Y[j]));
				if(nX[a]<now)nX[a]=now;
				if(nY[j]<now)nY[j]=now;
			}
			X[j]=nX[j];
			Y[j]=nY[j];
		}
	}
	int x;cin>>x;x--;
	int MX=0;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		MX=max(MX,dp[i][j]+(i==j&&j==x));
	}
	cout<<MX+ans<<endl;
}


Measured memory_bytes: 19252
#include<bits/stdc++.h>
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i,a,b) for (int i = a, to = b; i < to; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

typedef long long Long;

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int arr[5];
    Rep(i,0,5){
        cin>>arr[i];
        if(arr[i]==0){
            cout<<i+1;
        }
    } 
	return 0;
}

Measured memory_bytes: 3624
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

bool G[20][20];
vector<pair<int, int> > DXDY { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int main() {
  int h, w; cin >> h >> w;
  loop(y,0,h) loop(x,0,w) {
    char c; cin >> c;
    G[y][x] = c == '.';
  }
  int max_ = 0;
  const int INF = 10000000;
  {
    loop(startY,0,h) loop(startX,0,w) loop(endY,0,h) loop(endX,0,w) {
      if (!G[startY][startX]) continue;
      if (!G[endY][endX]) continue;
      if (startX == endX and startY == endY) continue;
      int dp[20][20];
      loop(y,0,h) loop(x,0,w) dp[y][x] = INF;
      queue<pair<int, int> > Q;
      Q.push({ startX, startY });
      dp[startY][startX] = 0;
      bool finish = false;
      while (Q.size() and !finish) {
        auto xy = Q.front(); Q.pop();
        for (auto&&dxdy : DXDY) {
          int x = xy.first + dxdy.first;
          int y = xy.second + dxdy.second;
          if (x < 0 or x >= w) continue;
          if (y < 0 or y >= h) continue;
          if (!G[y][x]) continue;
          if (dp[y][x] < INF) continue;
          dp[y][x] = dp[xy.second][xy.first] + 1;
          Q.push({ x, y });
          if (y == endY and x == endX) {
            max_ = max(max_, dp[y][x]);
            finish = true;
            break;
          }
        }
      }
    }
  }
  cout << max_ << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

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

int main() {
    int a;
    string input;
    cin >> a;
    cin >> input;
    int ans = 0;
    vector<char> arpha;
    for(char moji='a'; moji<='z'; ++moji) {
        arpha.push_back(moji);
    }
    for (int i = 0; i < a; i++) {
        int count = 0;
        string first = input.substr(0, i);
        string second = input.substr(i, a - i);
        for(char element : arpha){
            count << first.find(element);
            if (first.find(element) != std::string::npos && second.find(element) != std::string::npos) {
                count++;
            }
        }
        if (ans < count) {
            ans = count;
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
   while(true){
     C = C - B;
     if(C <= 0){
       cout << "Yes" << endl;
       break;
     }
     A = A - D;
     if(A <= 0){
       cout << "No" << endl;
       break;
     }
   }
}


Measured memory_bytes: 3620
def getMaxValue(s)
  return s.split(//).sort.reverse.join.to_i
end

def getMinValue(s)
  return s.split(//).sort.join.to_i
end

$stdin.gets.to_i.times{
  input = $stdin.gets.chomp
  p getMaxValue(input) - getMinValue(input)
}

Measured memory_bytes: 6100
n,m,*t=map(int,open(0).read().split())
s=sorted
a=s(t[:n])[::-1]
m=0
for c,b in s(zip(t[n+1::2],t[n::2]))[::-1]:
 while a and(c>a[-1])*b:m+=c;b-=1;a.pop()
print(m+sum(a))

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        h1: isize,
        m1: isize,
        h2: isize,
        m2: isize,
        k: isize
    }

    let mut h3 = h2;
    let mut k2 = k;
    if k2 >= 60 {
        h3 = h3 - (k2 / 60);
        k2 = k2 % 60;
    }

    let m3 = if m2 >= k2 {
        m2 - k2
    } else {
        h3 = h3 - 1;
        60 - (k2 - m2)
    };
    // println!("{},{},{},{},{}", h1, m1, h2, m2, k);
    // println!("h3 = {}", h3);
    // println!("/ {}", (k / 60));
    // println!("m3 {}", m3);


    let h4 = (h3 - h1) * 60;
    let m4 = m3 - m1;

    // println!("h4 = {}", h4);
    // println!("m4 = {}", m4);

    return (h4 + m4).to_string();
}


Measured memory_bytes: 2080
import math

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

def gcd(C,D):
    if D==0:
        return C
    else:
        return gcd(D,C%D)

U=B-A+1
num1=B//C-(A-1)//C + B//D-(A-1)//D
x=C//gcd(C,D)*D
num2=B//x-(A-1)//x
print(U-num1+num2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >>K;
  int L = 0;
  
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
  
    if(x <= K-x){
      L += (2*x);
    }
    else {
      L += (2*K - 2*x);
    }
  }
  cout << L <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    double ans = 0.0;

    double rate = 380000.0;

    for(int i=0; i<N; i++){
        double x; string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans += x*rate;
    }

    printf("%.8lf\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string S, T;
  cin >> S;
  cin >> T;
  for(int i = 0; i < S.size(); i++) {
    S.push_back(S[0]);
    S.erase(S.begin());
    if(S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	w := getNextInt(scanner)
	k := getNextInt(scanner)
	cc := make([]string, h)
	for i := 0; i < h; i++ {
		cc[i] = getNextString(scanner)
	}

	var ans int
	for i := 0; i < 1<<uint(h); i++ {
		for j := 0; j < 1<<uint(w); j++ {
			kk := k
			for ii := 0; ii < h; ii++ {
				for jj := 0; jj < w; jj++ {
					if i>>uint(ii)&1 == 0 {
						continue
					}
					if j>>uint(jj)&1 == 0 {
						continue
					}
					if cc[ii][jj] == '#' {
						kk--
					}
				}
			}
			if kk == 0 {
				ans++
			}
		}
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 1816
while n = gets.to_i
  break if n == 0
  d = [1, 2, 3, 4, 5, 6]
  n.times do
    case gets.chomp
    when 'north'
      d = [d[4], d[0], d[2], d[3], d[5], d[1]]
    when 'south'
      d = [d[1], d[5], d[2], d[3], d[0], d[4]]
    when 'east'
      d = [d[2], d[1], d[5], d[0], d[4], d[3]]
    when 'west'
      d = [d[3], d[1], d[0], d[5], d[4], d[2]]
    end
  end
  p d[0]
end

Measured memory_bytes: 8932
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d;
    cin >> a >> b >> c >> d;
    long long int i,j,k,l;
    i = a*c;
    j = b*c;
    k = a*d;
    l = b*d;
    cout << max(i,max(j,max(k,l))) << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,sum,m,i,sum1=0,sum2,s[105];
    scanf("%d %d",&n,&sum);
    for(i=0;i<n;i++)
        scanf("%d",&s[i]);
    for(i=0;i<n;i++)
    {
        sum1=sum1+s[i];
    }
    sum2=sum-sum1;
    sort(s,s+n);
    m=sum2/s[0];
    printf("%d\n",m+n);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	char s[100];
	int i,c=0;
	scanf("%s",s);
	for(i=0; s[i]!='\0'; ++i);
	for(int j=0;j<i/2;j++){
		if(s[j]!=s[i-j-1])c++;
	}
	printf("%d",c);
	// your code goes here
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<cstdio>
#include <string.h>
using namespace std;

const int LEN = 100000;  //constは関数内で値が変更されるのを防ぐ
struct pp{
    char name[11];
    int t;  //time  
} queue[LEN];

int head, tail;


int isEmpty(){   //空か確認
    return head == tail;
}


//入れる
void enqueue(char m[], int a){
    strcpy(queue[tail].name, m);  //strcpy（A,B)はAの配列にBの文字列をコピー
    queue[tail].t = a;
    tail++;
    
    if(tail >= LEN) tail = 0;
}

//出すやつのstruct
struct pp dequeue(){
    struct pp de = queue[head];
    head++;
    
    if(head >= LEN) head = 0;
    return de;
}



int main(void){
    // Your code here!
    int n,q;  //nはプロセス数を表す整数、ｑクオンタムを表す整数
    cin >> n >> q;
    //pp Q[101];
    int total = 0;
    char c[101];
    int t;
    struct pp de;
    
    for(int i = 0; i < n; i++){   //キューにいれる
        scanf("%s %d", c, &t);
        //cout <<i << " " <<  Q[i].name  << " " << Q[i].t<< endl;
        enqueue(c, t);
    }
    
    //int j = 0;
    while(!isEmpty()){  
        de = dequeue();
        
        if(de.t > q){
            total += q;
            enqueue(de.name, de.t - q);
        
        }else{
            total += de.t;
            cout << de.name << " " << total << endl;
        }
        
        //j++;
    }
    
}




Measured memory_bytes: 4628
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=40005;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		for(int j=i-1;j>=0;j--)
		{
			if(s[i]!=s[j])
			{
				cout<<"Yes\n";
				return 0;
			}
		}
	}
	cout<<"No";
}
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]
M = []

for i in range(n):
    M.append(A[i] - (i + 1))
    
M.sort()
b = M[len(M) // 2]

ans = 0
for i in range(n):
    ans += abs(A[i] - (b + i + 1))
    
print(ans)

Measured memory_bytes: 26128
//In the name of God
#include<bits/stdc++.h>
#define int long long

using namespace std;

int n , A , a[60] , dp[60][60][3000];

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n >> A;
        for(int i=1 ; i <= n ; i++)
                cin >> a[i];
        dp[0][0][0] = 1;
        for(int i=1 ; i <= n ; i++){
                dp[i][0][0] = 1;
                for(int j=1 ; j <= i ; j++)
                        for(int k=1 ; k < 2800 ; k++){
                                dp[i][j][k] = dp[i-1][j][k];
                                if(k >= a[i])
                                        dp[i][j][k] += dp[i-1][j-1][k - a[i]];
                        }
        }
        int res = 0;
        for(int i=1 ; i <= n ; i++)
                res += dp[n][i][i*A];
        cout << res;
} 

Measured memory_bytes: 69888
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, k, ans = 1;
  cin >> n >> k;
  for (size_t i = 0; i < n; i++) {
    if (2*ans < ans + k) ans *= 2;
    else ans += k;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	const int MAX=4001;
	int n;
	static int k[MAX][MAX];
	static ll s[MAX],dp[MAX][MAX];
	cin >> n;
	rep(i,0,n){
		ll w;
		cin >> w;
		s[i+1]=s[i]+w;
	}

	fill_n((ll*)dp,MAX*MAX,INF_);
	rep(i,0,n+1){
		dp[i][i]=0;
		k[i][i]=i;
		if(i+1<=n){
			dp[i][i+1]=0;
			k[i][i+1]=i+1;
		}
	}

	rep(l,1,n+1){
		for(int i=0,j=i+l; j<=n; ++i,++j){
			rep(r,k[i][j-1],k[i+1][j]+1){
				ll c=dp[i][r]+dp[r][j]+s[j];
				if(i!=0) c-=s[i];
				if(dp[i][j]>c){
					dp[i][j]=c;
					k[i][j]=r;
				}
			}
		}
	}

	cout << dp[0][n] << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 187900
s = int(input())

used = [False] * (1000000 + 1)
used[s] = True

def f(n):
    if n % 2 == 0:
        ret = n // 2
    else:
        ret = 3 * n + 1
    return ret

i = 1
cur = s
while True:
    cur = f(cur)
    i += 1
    if (used[cur]):
        print(i)
        exit()
    else:
        used[cur] = True


Measured memory_bytes: 10868
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>


using namespace std;

const int N = 1e5 + 5;
const long long inf = 1e17 + 5;
int a[N];
long long dp[N];

 
int main () 
{
    int n, E, T; 
    cin >> n >> E >> T;
    for (int i = 1; i <= n; i++) 
    {
        cin >> a[i];
    }
    memset(dp, 127, sizeof dp);
    dp[0] = 0;
    int pos = 0;
    long long minj = inf;
    for (int i = 1; i <= n; i++) 
    {
        while (2 * (a[i] - a[pos + 1]) >= T) 
        {
            minj = min(minj, dp[pos] - 2 * a[pos + 1]);
            pos++;
        }
        dp[i] = minj + 2 * a[i];
        if (pos != i)
        { 
            dp[i] = min(dp[i], dp[pos] + T);
        }
    }
    cout << dp[n] + E;
}




Measured memory_bytes: 1408
N=int(input())
B=list(map(int,input().split()))
A=[0 for _ in range(N)]
A[N-1]=B[N-2]
for i in reversed(range(1,N-1)):
    A[i]=min(B[i-1],B[i])
A[0]=B[0]    
print(sum(A))

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		StringBuilder sb = new StringBuilder();
		while (scanner.hasNextLine()) {
			String[] xy = scanner.nextLine().split(" ");
			int x = Integer.parseInt(xy[0]);
			int y = Integer.parseInt(xy[1]);
			sb.append(String.valueOf(x + y).length()).append("\n");
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 17488
#include <bits/stdc++.h>
using namespace std;
#define N 3100
#define mod 1000000007
int n,m,ans;
int f[N][N][2];
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++)
		f[0][i][0]=1;
	for(int i=0;i<m;i++)
		for(int j=0;j<=n;j++)
		{
			int k=n-j;
			if(j>=1)
			{
				//jj
				(f[i+1][j-1][j==1]+=f[i][j][0])%=mod;
		 		(f[i+1][j-1][1]+=f[i][j][1])%=mod;
				//jk
				(f[i+1][j][j==1]+=f[i][j][0])%=mod;
				(f[i+1][j][1]+=f[i][j][1])%=mod;
			}
			if(k>=1)
			{
				//kj
				(f[i+1][j][j==0]+=f[i][j][0])%=mod;
				(f[i+1][j][1]+=f[i][j][1])%=mod;
				//kk
				(f[i+1][j+1][j==0]+=f[i][j][0])%=mod;
				(f[i+1][j+1][1]+=f[i][j][1])%=mod;
			}
		}
	for(int i=0;i<=n;i++)
		(ans+=f[m][i][1])%=mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 73984
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    multiset<ll> balls;
    Rep (i, N) {
        cin >> A[i];
        balls.insert(-A[i]);
    }

    ll ans = 0;
    while (balls.size()) {
        ll target = *balls.begin();
        balls.erase(balls.begin());
        target *= -1;
        // cout << target << endl;
        ll p = 1;
        while (p <= target) {
            p *= 2;
        }

        auto itr = balls.find(target-p);
        if (itr != balls.end()) {
            ans++;
            balls.erase(itr);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
ll a[maxn];
map<ll,int> mp;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,k;cin>>n>>k;
    rep(i,1,n) {cin>>a[i];a[i]+=a[i-1];}
    rep(i,1,n){a[i]=(a[i]-(ll)i)%k;}
    ll ans=0;
    
    rep(j,0,n){//a[0]=0
        if(j>=k)mp[a[j-k]]--;
        if(mp.count(a[j]))ans+=mp[a[j]];
        mp[a[j]]++;
    }
    cout<<ans<<endl;
}
/* 
1 2
1

5 4
1 4 2 3 5

求# str S: sum(S) mod k == len(S)
sum[j]-sum[i] mod k == j - i
sum[j]-j== sum[i]-i  j-i<k

trick

partial_sum(begin(a), end(a), begin(a));
 */

Measured memory_bytes: 14336
#include <vector>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <tuple>
#include <cassert>
using namespace std;
using int64 = long long int;

struct UnionFind {
    vector<int> par, node, anc, color;
    UnionFind(int n) : node(n, 1), anc(n), color(n) {
        for(int i=0; i<n; i++) par.push_back(i);
    }
    int find(int k) { return par[k] == k ? k : find(par[k]); }
    bool same(int u, int v) { return find(u) == find(v); }
    bool unite(int u, int v) {
        if(same(u, v)) return false;
        u = find(u), v = find(v);
        if(node[u] > node[v]) {
            par[v] = u;
        }
        else if(node[u] < node[v]) {
            par[u] = v;
        }
        else {
            par[u] = v; node[v]++;
        }
        return true;
    }
};

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    vector< vector< tuple<int, int, int> > > G(N);
    for(int i=0; i<N-1; i++) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        a--; b--; c--;
        G[a].emplace_back(b, c, d);
        G[b].emplace_back(a, c, d);
    }

    vector<int64> ans(Q), neg(Q);
    vector< vector< tuple<int, int, int, int> > > info(N), tmp(N);
    for(int i=0; i<Q; i++) {
        int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
        x--; u--; v--;
        info[u].emplace_back(x, y, i, v);
        info[v].emplace_back(x, y, i, u);
    }

    UnionFind uf(N);
    function<void(int, int)> find_lca = [&](int cur, int par) {
        uf.anc[cur] = cur;
        for(auto e : G[cur]) {
            int to = get<0>(e);
            if(to == par) continue;
            find_lca(to, cur);
            uf.unite(to, cur);
            uf.anc[uf.find(cur)] = cur;
        }
        uf.color[cur] = 1;
        for(auto e : info[cur]) {
            int col, d, idx, to; tie(col, d, idx, to) = e;
            if(to < 0) continue;
            if(uf.color[to] == 1 and neg[idx]++ == 0) {
                int lca = uf.anc[uf.find(to)];
                tmp[lca].emplace_back(col, d, idx, -1);
            }
        }
    };

    vector<int64> sum(N), cnt(N);
    int64 cost = 0;
    function<void(int, int)> go = [&](int cur, int par) {
        for(auto e : info[cur]) {
            int col, d, idx, p; tie(col, d, idx, p) = e;
            int64 diff = cost + cnt[col] * d - sum[col];
            if(p < 0) {
                ans[idx] -= 2 * diff;
            }
            else { 
                ans[idx] += diff;
            }
        }

        for(auto e : G[cur]) {
            int to, col, dist; tie(to, col, dist) = e;
            if(to == par) continue;
            sum[col] += dist;
            cnt[col]++;
            cost += dist;
            go(to, cur);
            sum[col] -= dist;
            cnt[col]--;
            cost -= dist;
        }
    };

    find_lca(0, -1);
    for(int i=0; i<N; i++) for(auto e : tmp[i]) info[i].push_back(e);
    go(0, -1);
    for(auto a : ans) printf("%lld\n", a);
    return 0;
}


Measured memory_bytes: 33144
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    ll n, m; cin>>n>>m;
    vector<ll> x(n), y(m);
    for(int i=0; i<n; i++) cin>>x[i];
    for(int i=0; i<m; i++) cin>>y[i];

    vector<ll> num1(n), num2(m);
    for(ll i=0; i<n-1; i++){
        num1[i]=(i+1)*(n-i-1);
    }
    for(ll i=0; i<m-1; i++){
        num2[i]=(i+1)*(m-i-1);
    }

    ll ans1=0, ans2=0;
    for(int i=0; i<n-1; i++){
        ans1+=(x[i+1]-x[i])*num1[i];
        ans1%=MOD;
    }
    for(int i=0; i<m-1; i++){
        ans2+=(y[i+1]-y[i])*num2[i];
        ans2%=MOD;
    }
    cout << (ans1*ans2)%MOD << endl;
}

Measured memory_bytes: 3328
n=int(input())
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
  
ans=0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            
            ans+=gcd(a,b,c)  
print(ans)

Measured memory_bytes: 69800
export class Main {
  static main(input: string): string {
    const s = input.split("\n")[0];
    return new Date(s) <= new Date("2019/4/30") ? "Heisei" : "TBD";
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int slow(vector<int> w) {
	vector<int> they;
	int n = w.size();
	for(int mask = 1; mask < (1 << n); ++mask) {
		int s = 0;
		for(int i = 0; i < n; ++i) if(mask & (1 << i)) s += w[i];
		they.push_back(s);
	}
	sort(they.begin(), they.end());
	return they[(1<<(n-1))-1];
}

const int nax = 2005*2005;
bitset<nax> B;

int main() {
	B[0] = 1;
	int n;
	scanf("%d", &n);
	int s = 0;
	while(n--) {
		int x;
		scanf("%d", &x);
		s += x;
		B = B | (B << x);
	}
	int should = (s + 1) / 2;
	while(!B[should]) ++should;
	printf("%d\n", should);
	//~ printf("%d\n", slow({1,2,3,4,5,6,7}));
	//~ printf("%d\n", slow({1,2,3,4,5,99,100}));
	//~ printf("%d\n", slow({1,2,3,4,5,99,102}));
	//~ printf("%d\n", slow({100,101,102,103,104,105}));
	//~ printf("%d\n", slow({1,2,1}));
	//~ printf("%d\n", slow({58}));
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    int n;
    cin >> n;
    vector<long> l(3*n);
    for(int i = 0; i < 3 * n;i ++){
        cin >> l[i];
    }
    long sum = 0;
    sort(l.begin(), l.end(), greater<int>());
    for(int i = 0; i < 2*n; i++){
        if(i%2 == 1) sum += l[i];
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main() {
  int a, b, c, d, n, k;
  while (scanf("%d", &n) != EOF) {
    k = 0;
    for (a = 0; a < 10; a ++) {
      for (b = 0; b < 10; b ++) {
	for (c = 0; c < 10; c ++) {
	  for (d = 0;d < 10; d ++) {
	    if (a + b + c + d == n) k ++;
	  }
	}
      }
    }
    printf("%d\n", k);
  }
  return 0;
}

Measured memory_bytes: 592
n,m=map(int,input().split())
w=[i for i in range(n+1)]
s=[1]*(n+1)
def root(x):
    if w[x]==x:
        return x
    x=w[x]
    return root(w[x])
def unite(x,y):
    x=root(x)
    y=root(y)
    if x!=y:
        if s[x]<s[y]:
            w[x]=y
            s[y]+=1
        else:
            w[y]=x
            s[x]+=1
for i in range(m):
    x,y=list(map(int,input().split()))[:2]
    unite(x,y)
go=set()
for i in range(1,n+1):
    go.add(root(i))
print(len(go))

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

int main()
{
    ll N, ans = 0;
    cin >> N;
    ll A[N + 1], B[N];

    for (int i = 0; i < N + 1; i++)
    {
        cin >> A[i];
    }

    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }

    for (int i = 0; i < N; i++)
    {

        if (B[i] > A[i])
        {
            ans += A[i];
            B[i] -= A[i];

            if (B[i] > A[i + 1])
            {
                ans += A[i + 1];
                A[i + 1] = 0;
            }

            else
            {
                ans += B[i];
                A[i + 1] -= B[i];
            }
        }

        else
        {
            ans += B[i];
        }
    }
    cout << ans << endl;
}


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

#define deb(x) cout << #x << " " << x << "\n";
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define endl "\n"
#define ll long long
#define vi vector<int>


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



	int t, i, sum = 0, ans = 0;
	cin >> t;
	int arr[t];
	fo(i, t) {
		cin >> arr[i];
		sum += arr[i];
	}

	sum = round((float)sum / t);

	fo(i, t) {
		ans += pow(arr[i] - sum, 2);

	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3696
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long int a[5],ans[5],min;
	for(int i = 1;i <= 3; i++)
	{
		scanf("%lld",&a[i]);
		if(a[i] % 2 == 0)
		{
			printf("0\n");
			return 0;
		}
	}
	ans[1] = a[1] * a[2];
	min = ans[1];
	ans[2] = a[3] * a[2];
	ans[3] = a[3] * a[1];
	for(int i = 2;i <= 3; i++)
	{
		if(ans[i] < ans[i - 1])
			min = ans[i];
	}
			printf("%lld\n",min);
		return 0;
}

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

public class Hello{
    public static void Main(){
        long[] arr = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

        while(arr[0] >= 0 || arr[2] >= 0){
            arr[2] -= arr[1];
            if(arr[2] <= 0){
                Console.WriteLine("Yes");
                break;
            }
            arr[0] -= arr[3];
            if(arr[0] <= 0){
                Console.WriteLine("No");
                break;
            }

        }
    }
}


Measured memory_bytes: 28160
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n,k;cin>>n>>k;
    int a[n];
    int sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    vector<int> v;
    for(int i=1;i*i<=sum;i++){
        if(sum%i==0){
            v.push_back(i);
            if(i*i<sum)v.push_back(sum/i);
        }
    }
    sort(v.begin(),v.end());
    rrep(i,v.size()-1,0){
        vector<int> h;
        int su=0;
        rep(j,0,n){
            h.push_back(a[j]%v[i]);
            su+=a[j]%v[i];
        }
        //cout<<su<<endl;
        if(su%v[i]!=0)continue;
        sort(h.begin(),h.end(),greater<int>());
        su/=v[i];
        
        int ans=0;
        int ans2=0;
        rep(j,0,su){
            ans+=v[i]-h[j];
        }
        rep(j,su,n)ans2+=h[j];
        
        ans=min(ans,ans2);
        if(ans<=k){
            cout<<v[i]<<endl;
            return 0;
        }
    }
}


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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

struct Edge {
    ll to, a, b;
    Edge(ll to, ll a, ll b) : to(to), a(a), b(b) {}
};

struct State {
    ll index;
    ll money;
    ll cost;    
    State(int i, ll c, ll m) : index(i), cost(c), money(m) {}
    bool operator>(const State &r) const { return cost > r.cost; }
};

vector<vector<ll>> dijkstra(const vector<vector<Edge>> &G, int start, vector<ll> &C, vector<ll> &D, ll S) {
    priority_queue<State, vector<State>, greater<State>> que;
    ll max_m = 50 * 50 + 10;
    vector<vector<ll>> memo(G.size(), vector<ll>(max_m, INFL));    
    que.emplace(start, 0, min<ll>(S, max_m));
    while (not que.empty()) {
        State now = que.top();        
        // cerr << now.index << " " << now.money << " " << now.cost << endl;
        que.pop();
        if(memo[now.index][now.money] < now.cost) continue;
        bool flg = false;
        for(ll m = now.money, t = 0; !flg; m += C[now.index], t += D[now.index]) {
            if(m > max_m) {
                flg = true;
                m = max_m - 1;
            }
            if(t > 0 and memo[now.index][m] <= now.cost + t) continue;
            memo[now.index][m] = now.cost + t;
            for (Edge e : G[now.index]) {
                ll nm = m - e.a;
                if(nm < 0) continue;
                if (memo[e.to][nm] > now.cost + e.b + t) {
                    State nxt  = State(e.to, now.cost + e.b + t, nm);
                    memo[e.to][nm] = nxt.cost;
                    que.push(nxt);
                }
            }            
        }        
    }
    return memo;
}

int main() {
    
    ll N, M, S; cin >> N >> M >> S;    
    vector<vector<Edge>> E(N);
    rep(i, M) {
        ll u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;
        E[u].emplace_back(v, a, b);
        E[v].emplace_back(u, a, b);        
    }
    vector<ll> C(N), D(N);
    rep(i, N) cin >> C[i] >> D[i]; 

    vector<vector<ll>> res = dijkstra(E, 0, C, D, S);
    repeat(i, 1, N) {   
        ll ans = INFL;
        rep(j, res[i].size()) set_min(ans, res[i][j]);
        cout << ans << endl;
    } 
    return 0;
}


Measured memory_bytes: 28708
function Main(input) {
    input = input.split(" ");
    var X = a(parseInt(input[0],10));
    var Y = a(parseInt(input[1],10));
    if(X == 300000 && Y == 300000){
        console.log(X+Y+400000);
    }else{
        console.log(X+Y)
    }
    function a(b){
        if(b == 1){
            return 300000;
        }else if(b == 2){
            return 200000;
        }else if(b == 3){
            return 100000;
        }else{
            return 0;
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
from collections import deque
CORRECT_STATE = "123456780"


class PuzzleState:
    __slots__ = ['state', 'spc_x', 'spc_y', 'depth']

    def __init__(self, state: str, depth=0):
        self.state = state
        index = state.find('0')
        self.spc_x = index % 3
        self.spc_y = index // 3
        self.depth = depth

    def swap_state(self, ch_x, ch_y):
        conv_char = self.state[ch_y * 3 + ch_x]
        self.state = self.state.replace('0', 'X')
        self.state = self.state.replace(conv_char, '0')
        self.state = self.state.replace('X', conv_char)
        self.spc_x, self.spc_y = ch_x, ch_y

    def is_correct(self):
        return self.state == CORRECT_STATE

    def __repr__(self):
        return f'{self.state}'


move = [(0, -1), (0, 1), (-1, 0), (1, 0)]
def puzzle8_breadth_first_search(puzzle: PuzzleState):
    mem_state = {puzzle.state: ''}
    p_queue = deque()
    p_queue.append(puzzle)

    while len(p_queue) != 0:
        u = p_queue.popleft()
        if u.is_correct():
            #print("CORRECT")
            return u.depth
        for mx, my in move:
            sp_new_x = u.spc_x + mx
            sp_new_y = u.spc_y + my
            if not(0 <= sp_new_x <= 2 and 0 <= sp_new_y <= 2):
                continue
            new_puzzle = PuzzleState(u.state, depth=u.depth+1)
            new_puzzle.swap_state(sp_new_x, sp_new_y)

            if new_puzzle.state not in mem_state:
                mem_state[new_puzzle.state] = ''
                p_queue.append(new_puzzle)
    return False


def main():
    input_text = ""
    for i in range(3):
        input_text += "".join(input().split())

    # 8 puzzle main
    ans_puzzle = puzzle8_breadth_first_search(PuzzleState(input_text))
    print(ans_puzzle)
    return

main()


Measured memory_bytes: 33588
#include <stdio.h>
#include <math.h>
int main(){
  int i,n;
  double v,y;
  while(scanf("%lf",&v)!=EOF){
    y=v*v/19.6;
   
    for(i=1;5*i-5<y;i++);
         
    printf("%d\n",i);
  }
  
  return 0;
}

Measured memory_bytes: 628
#include<iostream>
#include<cmath>
using namespace std;
int gcd(int a,int b)
{
	return b==0?a:(gcd(b,a%b));
}
int main()
{
    int n;
    long long sum=0;
    cin>>n;
    for(int i =1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int x=1;x<=n;x++)
            {
                sum+=gcd(gcd(i,j),x);
            }
        }
    }
    cout<<sum;

}


Measured memory_bytes: 3624
function main(input){
  const args = input.split(" ");
  const A = parseInt(args[0]),
        op = args[1],
        B = parseInt(args[2]);
  
  if (op === "+")
    console.log(A + B);
  else
    console.log(A - B);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29636
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll N;cin>>N;ll ans=1;
  for(int i=1;i<=N;i++){
    ans =ans*i%MOD;
    
  }
  cout<<ans<<endl;
}   





Measured memory_bytes: 256
n,m = map(int,input().split())
ans = []
for i in range(n):
    ans.append('m')
err = 0
for i in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == 'm':
        ans[s-1] = str(c)
    else:
        if ans[s-1] != str(c):
            err = 1
if n == 1:
    if ans[0] == 'm':
        ans[0] = '0'
else:
    if ans[0] == '0':
        err = 1
    else:
        if ans[0] == 'm':
            ans[0] = '1'
for i in range(1,n):
    if ans[i] == 'm':
        ans[i] = '0'
#print(ans)
if err == 0:
    if n == 1:
        print(ans[0])
    elif n == 2:
        print(ans[0]+ans[1])
    else:
        print(ans[0]+ans[1]+ans[2])
else:
    print(-1)

Measured memory_bytes: 9172