akhauriyash/Code-Regression huggingface dataset:
def C():
    N = int(input())
    values = list(map(int, input().split()))

    values = sorted(values, reverse=True)
    weights = [(1/2)**(i+1) for i in range(N-1)] + [(1/2)**(N-1)]

    total_value = sum([values[i]*weights[i] for i in range(N)])

    print(total_value)


if __name__ == '__main__':
    C()


Measured memory_bytes: 3060
Nn, M, K = map(int, input().split())
MOD = 998_244_353

p = MOD
N = Nn  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

# 事前計算した項を掛け合わせ
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

ans = 0
M_1_pwr = pow(M-1, Nn-1-K, MOD)
for j in range(K,-1,-1):
  tmp = 1
  tmp *= cmb(Nn-1,j,MOD)
  tmp *= M_1_pwr
  tmp %= MOD
  
  #print(cmb(Nn-1,j,MOD), tmp)
  
  ans += tmp
  ans %= MOD
  
  M_1_pwr *= (M-1)
  M_1_pwr %= MOD
  
ans *= M
ans %= MOD

print(ans)

Measured memory_bytes: 117896
'''
問題：
    高橋君は金色の硬貨が好きです。
    自分が持っている 500円硬貨 1枚につき 1000、
    5円硬貨 1枚につき 5の嬉しさ を得ます。

    高橋君は X 円を持っています。
    これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか？

    (なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5円玉、1 円玉の 6 種類とします。)
'''

'''
Xは整数
0 ≦ X ≦ 1,000,000,000
'''
# def calc

# 標準入力から X の値を取得する
input_x = int(input())

ret1 = input_x // 500  # 500円で割った商
ret2 = ret1 * 1000  # 高橋君 500円の喜び
ret3 = input_x - (ret1 * 500)   # X円から500円の枚数分を引いたお金
ret4 = ret3 // 5 # （X円から500円の枚数分を引いたお金）÷ 5
ret5 = ret4 * 5 # 高橋君 5円の喜び
print(ret2 + ret5)



Measured memory_bytes: 8952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n, 0);
  rep(i, 0, n){
    cin >> h[i];
  }
  vector<vector<int>> v(n);
  rep(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<int> x(n, 0);
  int good = 0;
  rep(i, 0, n){
    for(int j: v[i]){
      if(h[i] <= h[j]){
        x[i]++;
        break;
      }
    }
  }
  rep(i, 0, n){
    if(x[i] == 0){
      good++;
    }
  }
  cout << good << "\n";
}

Measured memory_bytes: 9072
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#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 << '\n'; }
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__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , m ;
    cin >> n >> m ;
    int ans = INF ;
    for(int i = 1; i <= m - 1; i++){
        int a = i * n ; 
        int rem = m - i ;
        int b = n / 2 * rem ;
        int c = (n + 1) / 2 * rem ;
        vector<int> v = {a, b ,c} ;
        sort(v.begin(), v.end()) ;
        ans = min(ans, v[2] - v[0]) ;
        b = rem / 2 * n ;
        c = (rem + 1) / 2 * n ;
        vector<int> t = {a, b , c} ;
        sort(t.begin(), t.end()) ;
        ans = min(ans, t[2] - t[0]) ;
    }
    for(int i = 1; i <= n - 1; i++){
        int a = i * m ;
        int rem = n - i ;
        int b = m / 2 * rem ;
        int c = (m + 1) / 2 * rem ;
        vector<int> v = {a, b ,c} ;
        sort(v.begin(), v.end()) ;
        ans = min(ans, v[2] - v[0]) ;
        b = rem / 2 * m ;
        c = (rem + 1) / 2 * m ;
        vector<int> t = {a, b , c} ;
        sort(t.begin(), t.end()) ;
        ans = min(ans, t[2] - t[0]) ;
    }
    cout << ans << endl;
    return 0; 
}

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

string s, t, u;
int main()
{
	cin >> s >> t >> u;
	cout << s[0] << t[1] << u[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

        int m, n;
        cin >> m >> n;
        vector< int > v;
        for( int i = 0; i < n; ++i ) {
                int a;
                cin >> a;
                v.pb(a);

        }

        int res = 0;
        if( m == 2 ) {
                vector< int > p(n), q(n);
                p[0] = 1; q[0] = 2;

                for( int i = 1; i < n; ++i ) {
                        p[i] = q[i - 1];
                        q[i] = p[i - 1];

                }

                int cnt = 0;
                for( int i = 0; i < n; ++i ) {
                        if( v[i] != p[i] ) ++cnt;

                }
                res = cnt;
                cnt = 0;
                for( int i = 0; i < n; ++i ) {
                        if( v[i] != q[i] ) ++cnt;

                }
                cout << min(res, cnt) << endl;

                return 0;
        }
        for( int i = 1; i < n; ++i ) {
                if( v[i] == v[i - 1] ) {
                        if( v[i] == 1 ) v[i] = 2;
                        else v[i] = 1;
                        ++res;

                }

        }
        cout << res << endl;
    return 0;
}



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

int main() {
  int x;
  cin >> x;

  if (x == 7) {
    cout << "YES" << endl;
  }
  else if (x == 5) {
    cout << "YES" << endl;
  }
  else if (x == 3) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}
  
  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a= sc.nextInt();
		String T = sc.next();
		if (a>=3200) {
			System.out.println(T);
		} else {
			System.out.println("red");
		}
	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#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 A, B, C;
    cin >> A >> B >> C;

    if ((A == B) && (B == C) && (A%2==0)) {
        cout << -1 << "\n";
        return 0;
    }

    ll ans = 0;
    while ((A%2==0) && (B%2==0) && (C%2==0)) {
        ans++;
        ll a = A;
        ll b = B;
        ll c = C;
        A = b/2+c/2;
        B = c/2+a/2;
        C = a/2+b/2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int f(string s) {
    int result = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '+') {
            result++;
        } else if (s[i] == '-') {
            result--;
        }
    }
    return result;
}

int main() {

    string s;
    cin >> s;

    int result = f(s);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int n;
    cin >> n;
    int ans = 0;
    re(1000) {
        int d1 = i % 10;
        int d2 = i % 100 / 10;
        int d3 = i / 100;
        if (d1 > 0 && d1 <= n &&
            d2 > 0 && d2 <= n &&
            d3 > 0 && d3 <= n) {
            ++ans;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(n, m, _X, _Y) = readLineInts
    val x = readLineInts
    val y = readLineInts
    if ((x :+ _X).max < (y :+ _Y).min) {
      println("No War")
    } else {
      println("War")
    }
  }
}


Measured memory_bytes: 25932
s = input()
t = input()

start = [-1 for _ in range(26)]
goal  = [-1 for _ in range(26)]

for i in range(len(s)):
	a = ord(s[i]) -  ord('a')
	b = ord(t[i]) -  ord('a')

	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			print('No')
			exit()

	else:
		start[a] = b
		goal[b]  = a

print('Yes')


Measured memory_bytes: 41840
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b; cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}



Measured memory_bytes: 256
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! 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")
    };
}

fn main() {
    input! {
        a: [i32; 3]
    }
    let res: i32 = a.iter().sum();

    if res >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}


Measured memory_bytes: 4352
#include <iostream> 
#include <algorithm> 
#define ll long long
using namespace std;
int main(){
    ll n, a, b, final=0;
    cin >> n >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2 << endl;
    }
    else if (b-a==1){
        cout << min(n-a, b-1) << endl;
    }
    else{
        cout << min(n-a, b-1)+1+(a-b-1)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
#define long long long
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */
const int N = 2.5e5+1;
long P1, P2;
seed_seq seq{
	(uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
  (uint64_t) __builtin_ia32_rdtsc(),
  (uint64_t) (uintptr_t) make_unique<char>().get()
};

long modPow(long b, long e) {
	if(!e) return 1;
	if(e == 1) return b;
	return modPow(b*b % MOD, e >> 1) * modPow(b, e & 1) % MOD;
}

int n;
char s[N];
long ans, shift[N], h1[N], h2[N];
map<pair<long,long>, int> cnt;

void gen_base() {
	mt19937 rng(seq);
	P1 = uniform_int_distribution<int>(n+1, MOD-1)(rng);
	P2 = uniform_int_distribution<int>(n+1, MOD-1)(rng);
}

int main() {
	iostream_optimize();
	cin >> n >> (s+1);
	gen_base();
	shift[0] = n;
	for(int i = 1; i <= n; i++) {
		shift[i] = shift[i-1];
		h1[i] = h1[i-1];
		h2[i] = h2[i-1];
		if(s[i] == '>') --shift[i];
		if(s[i] == '<') ++shift[i];
		if(s[i] == '+') {
			h1[i] = (h1[i] + modPow(P1, shift[i])) % MOD;
			h2[i] = (h2[i] + modPow(P2, shift[i])) % MOD;
		}
		if(s[i] == '-') {
			h1[i] = (h1[i] - modPow(P1, shift[i]) + MOD) % MOD;
			h2[i] = (h2[i] - modPow(P2, shift[i]) + MOD) % MOD;
		}
	}
	++cnt[make_pair(h1[n], h2[n])];
	for(int i = 1; i <= n; i++) {
		ans += cnt[make_pair(h1[i], h2[i])];
		long coeff1 = (n > shift[i] ? modPow(modPow(P1, n - shift[i]), MOD-2) : modPow(P1, shift[i] - n));
		long coeff2 = (n > shift[i] ? modPow(modPow(P2, n - shift[i]), MOD-2) : modPow(P2, shift[i] - n));
		// cout << shift[i] << ' ' << h[i] << ' ' << (h[n] * coeff + h[i]) % MOD <<  ' ' << cnt[h[i]] << endl;
		pair<long,long> add = {(h1[n] * coeff1 + h1[i]) % MOD, (h2[n] * coeff2 + h2[i]) % MOD};
		++cnt[add];
	}
	cout << ans;
}


Measured memory_bytes: 37632
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := readInt()
	m := readInt()
	x := readInt()

	CA := make([][]int, n)
	for i := range CA {
		CA[i] = make([]int, m+1)
		for j := 0; j < m+1; j++ {
			CA[i][j] = readInt()
		}
	}

	ans := 0
	for i := 0; i < (1 << uint(n)); i++ {
		price := 0
		learn := make([]int, m)
		for k := 0; k < n; k++ {
			if i>>uint(k)&1 == 0 {
				price += CA[k][0]
				for l := 1; l < m+1; l++ {
					learn[l-1] += CA[k][l]
				}
			}
		}
		update := true
		for _, v := range learn {
			if v < x {
				update = false
			}
		}
		if update && (ans > price || ans == 0) {
			ans = price
		}
	}

	if ans > 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}

}

Measured memory_bytes: 2148
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int n;
	cin >> n;
	if (n / 100 == n % 10) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = 0
tmp = 0
prev = H[0]
for h in H[1:]:
  if prev >= h:
    tmp += 1
  else:
    ans = ans if ans >= tmp else tmp
    tmp = 0
  prev = h
ans = ans if ans >= tmp else tmp
print(ans)

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		//入力読み込み
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();
		String T = scan.next();
		//読み込み終わり
		scan.close();

		//読み込んだ文字列をchar型の配列に変換
		char[] tmpS = S.toCharArray();
		char[] tmpT = T.toCharArray();

		//SとTの文字を交互に出力
		for(int i=0;i<N;i++) {
			System.out.print(tmpS[i]);
			System.out.print(tmpT[i]);
		}
	}
}

Measured memory_bytes: 21332
package main

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

func main() {
	n := readI()
	s := readS()
	var r, g, b int
	for i := 0; i < n; i++ {
		switch s[i] {
		case 'R':
			r++
		case 'G':
			g++
		case 'B':
			b++
		}
	}
	all := r * g * b
	complement := 0
	ceiling := (n - 3) / 2
	for i := 0; i <= ceiling; i++ {
		for j := 0; j+2*i+2 <= n-1; j++ {
			if s[j] != s[j+i+1] && s[j+i+1] != s[j+2*i+2] && s[j] != s[j+2*i+2] {
				complement++
			}
		}
	}
	fmt.Println(all - complement)
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


Measured memory_bytes: 1812
import numpy as np
N, S = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
mod = 998244353
coef = np.zeros(3001, dtype=int)
coef[0] = 1
for a in A:
    coef2 = coef[:-a].copy()
    coef *= 2
    coef[a:] += coef2
    coef %= mod
print(coef[S])


Measured memory_bytes: 27348
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#define INF 2000000000
using namespace std;



int merge(int *A,int left,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int *L = new int[n1+1];
	int *R = new int[n2+1];
	for(int i = 0; i < n1; i++){
		L[i] = A[left + i];
	}

	for(int i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = INF;
	R[n2] = INF;
	int i = 0;
	int j = 0;
	int count = 0;
	for(int k = left; k < right; k++){
		count++;
		if( L[i] <= R[j]){
			A[k] = L[i];
			i++;
		}else{
			A[k] = R[j];
			j++;
		}
	}
	//delete[] L,R;
	return count;
}


int mergeSort(int *A,int left,int right){
	int totalCount = 0;
	if(left + 1 < right){
		int mid = (left + right) / 2;
		totalCount += mergeSort(A,left,mid);
		totalCount += mergeSort(A,mid,right);
		totalCount += merge(A,left,mid,right);
	}
	return totalCount;
}

void printArray(int *A,int n){
	cout << A[0];
	for(int i = 1; i < n; i ++){
		cout<<" "<<A[i];
	}
	cout<<endl;
}

int main()
{
	int n;
	cin >> n;
	int *A = new int[n];
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	int count = 0;
	count = mergeSort(A,0,n);
	printArray(A,n);
	cout<<count<<endl;
	return 0;
}





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

int main() {
	string S; cin >> S;
	int w; cin >> w;

	int l=0;

	while (l < S.size()) {
		cout << S.at(l);
		l += w;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> //sort,二分探査など
//#include<bitset>
//#include<cmath>//pow,logなど
//#include<deque>
//#include<functional>
//#include<iterator>
//#include<map>
//#include<numeric>//gcd,lcm
//#include<queue>
//#include<set>
//#include<stack>
//#include<string>
//#include<utility>//pair

//QCFium法
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//浮動小数点処理高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;

constexpr i64 INF = 1010000000000000017LL;
constexpr u64 MOD = 998244353LL;
constexpr f80 PI = 3.14159265358979323846;

#define _overload3(_1, _2, _3, name, ...) name
#define repi(i, start, end) for (int i = (int)(start); i < (int)(end); ++i)
#define _rep(i, n) repi(i, 0, n)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, start, end) for (int i = (int)(start); i > (int)(end); --i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()

#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef v(int) vi;

#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>

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;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
  for (T &in : v)
    is >> in;
  return is;
}

//sort(rng(P),[](const vi &a, const vi &b){return a[1]<b[1];});

void Main()
{
  int N, K;
  cin >> N >> K;
  v(int) l(K);
  v(int) r(K);
  rep(i, K)
  {
    cin >> l[i] >> r[i];
  }


  v(int) dp(N, 0);
  dp[0] = 1;
  dp[1] = MOD - 1;
  int csum = 0;

  rep(i, N)
  {
    csum += dp[i];
    csum %= MOD;
    rep(j, K)
    {
      if (i + l[j] < N)
      {
        dp[i + l[j]] += csum;
        dp[i + l[j]] %= MOD;
      }
      if (i + r[j] + 1 < N)
      {
        dp[i + r[j] + 1] += MOD - csum;
        dp[i + r[j] + 1] %= MOD;
      }
    }
  }

  cout << csum << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <cmath>
#define INF 1000000000000000000LL
using namespace std;

int main()
{
  int n;
  cin >> n;
  int zflag = 0;
  unsigned long long a[n];
  for(int i=0; i<n; ++i) {
    cin >> a[i];
    if (a[i]==0) zflag = 1;
  }

  unsigned long long ans = a[0];
  int isOf = 0;
  for(int i=1; i<n; ++i){
    if(log10(a[i])+log10(ans)>18.0){
      isOf = 1;
    }
    ans *= a[i];
    if(ans > INF){
      isOf = 1;
    }
  }
  if(zflag == 1){
    cout << 0 << endl;
  }else if(isOf == 1){
    cout <<  -1 << endl;;
  }else{
    cout << ans << endl; 
  }

  return 0;
}

Measured memory_bytes: 4668
#include<stdio.h>
int main(){
	int H;
	int W;
	int N;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &N);
	if(H > W){
		if(N%H == 0){
			printf("%d", N/H);
		}else{
			printf("%d", N/H + 1);
		}
	}else{
		if(N%W == 0){
			printf("%d", N/W);
		}else{
			printf("%d", N/W + 1);
	}
	return 0;
}
}

Measured memory_bytes: 1700
# N が展望台の数
# M が展望台を結ぶ道の数
N, M = list(map(int, input().split()))

# 展望台の標高
H = list(map(int, input().split()))

# 各展望台ごと周辺で一番大きな展望台の高さ
highest = [True] * N

res = 0

for i in range(M):
  a, b = list(map(int, input().split()))

  a = a - 1
  b = b - 1

  if(highest[a]):
    highest[a] = H[a] > H[b]
    
  if(highest[b]):
    highest[b] = H[a] < H[b]

for i, value in enumerate(highest):
  if(highest[i]):
    res += 1

print(res)

Measured memory_bytes: 20124
#include<bits/stdc++.h>
//#define attrib +h /s /d
using namespace std;
int main(){

   int n,a,b,c,d,e,i;
   set<int> s;
   cin>>a>>b;
   while(b--){
     cin>>c;
     for(i=0;i<c;i++){
        cin>>d;
        s.insert(d);
     }
   }
   e=s.size();
   cout<<abs(a-e)<<endl;



   return 0;
}


Measured memory_bytes: 3636
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(N):
  a.append(A[i] + a[i])
for i in range(M):
  b.append(B[i] + b[i])
  
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break;
  while b[j] > K-a[i]:
    j -= 1
  ans = max(ans, i+j)
  
print(ans)

Measured memory_bytes: 47456
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
  ll ans=0;
  vector<vector<int>> a(26,vector<int> (0));
  for(int i=0;i<n;i++){
    a[s[i]-'a'].push_back(i);
  }
  for(int i=0;i<n;i++){
    a[s[i]-'a'].push_back(i+n);
  }
  int p=0;
  for(int i=0;i<m;i++){
     int c = t[i] - 'a';
    if(a[c].size()==0){
      cout<<"-1"<<endl;
      return 0;
    }
     p=* lower_bound(ALL(a[c]), p)+1;
    if(p>=n){
      ans+=n;
      p-=n;
    }
  }
  
  cout<<ans+p<<endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((c-1)/b+1<=(a-1)/d+1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

ll l[200020];

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  set<ll> s;
  l[0]=0;
  for(int i=1;i<n+1;i++){
    l[i]=l[i-1]+a[i-1];
  }
  for(int i=0;i<=n;i++)s.insert(l[i]);
  sort(l,l+n+1);
  cout << endl;
  ll ans=0;
  for(auto i=s.begin();i!=s.end();++i){
    ll x=upper_bound(l,l+n+1,*i)-lower_bound(l,l+n+1,*i);
    ans+=x*(x-1)/2;
  }
  cout << ans << endl;
return 0;}

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

e = [[i for i in input().split()] for i in range(n)] 

for i in range(n):
    e[i][1] = int(e[i][1])
    e[i].append(i+1)

e.sort(key=lambda x:(x[0],-x[1]))


for i in range(n):
    print(e[i][2])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int main()
{
    int a;
    int b;
    int c;
    cin >> a >> b >> c;

    rep(i,1,b)
    {
        if((a * i) % b == c)
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    
}

Measured memory_bytes: 256
def main():
    N, M, X, Y = map(int, input().split())
    max_x = max(list(map(int, input().split())))
    min_y = min(list(map(int, input().split())))

    for z in range(X + 1, Y + 1):
        if max_x < z <= min_y:
            print("No War")
            exit()
    print("War")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    int n,m;cin >> n >> m;
    vector<ll> a(n);
    vector<l_l> cb(m);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++){
        int b,c;cin >> b >> c;
        cb[i]=l_l(c,b);
    }
    sort(a.begin(),a.end());
    sort(cb.rbegin(),cb.rend());
    ll pre=-1;
    vector<l_l> calc;
    for(int i=0;i<m;i++){
        ll itr=lower_bound(a.begin(),a.end(),cb[i].first)-a.begin();
        itr--;
        if(itr>pre){
            ll pre2=min(itr,pre+cb[i].second);
            calc.push_back({cb[i].first,pre2-pre});
            pre=pre2;
        }
    }
    ll ans=0;
    for(int i=pre+1;i<n;i++){
        ans+=a[i];
    }
    for(int i=0;i<calc.size();i++){
        ans+=calc[i].first*calc[i].second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<cstdio>
#include<algorithm>
using std::min;
const int MAXN=5e5+5;

int n,D,Q;
int d[MAXN],q[MAXN];

int f[MAXN],g[MAXN];

int main()
{
	int i;scanf("%d%d",&n,&D);
	for(i=1;i<=n;i++) scanf("%d",d+i);
	scanf("%d",&Q);
	for(i=1;i<=Q;i++) scanf("%d",q+i);

	f[1]=D;for(i=2;i<=n;i++) f[i]=min(f[i-1],abs(f[i-1]-d[i-1]));
	g[n]=1;for(i=n-1;i;i--) g[i]=g[i+1]+(d[i+1]<2*g[i+1]?d[i+1]:0);
	for(i=1;i<=Q;i++) puts(f[q[i]]>=g[q[i]]?"YES":"NO");
	return 0;
}

Measured memory_bytes: 9728
#include<stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a<b){
		printf("a < b\n");
	}else if (a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}

	return 0;
}

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

using namespace std;


#define PI 3.14159265
#define int long long

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;


int f[MAXN];
int inv[MAXN];

int binpow(int a, int n){

	int res = 1;
	
	while(n){
		if(n & 1)
			res *= a;
		
		a *= a;
		n >>= 1;

		a %= MOD;
		res %= MOD;
	}


	return res;
}

int MMI(int a){
	return binpow(a, MOD - 2);
}

int ckn(int k, int n){
	if(k == n) return 1;
	return (((f[n] * inv[k]) % MOD) * inv[n - k]) % MOD;
}

void calc(){
	f[0] = f[1] = 1;
	inv[1] = inv[0] = 1;
	for(int i = 2; i < MAXN; i++){
		f[i] = f[i - 1] * i;
		f[i] %= MOD;
		inv[i] = MMI(f[i]);
	}
}



main(){

	calc();

	int n, k; cin >> n >> k;

	vector <int> a(n);

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

	int maxim = 0, minim = 0;

	sort(a.begin(), a.end());

	for(int i = k - 1; i < n; i++){
		maxim += a[i] * ckn(k - 1, i);
		maxim %= MOD;
		// cout << ckn(k - 1, i) << endl;
	}

	sort(a.rbegin(), a.rend());

	for(int i = k - 1; i < n; i++){
		minim += a[i] * ckn(k - 1, i);
		minim %= MOD;
	}

	// cout << maxim << " " << minim << endl;

	cout << (maxim - minim + MOD) % MOD << endl;

	
	
	return 0;
}

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

#define PI 3.141592653589793238462643383279

int  main()
{
	int A,B,H,M;
	cin >> A >> B >> H >> M;
	double k;
	//長針
	double l = M*6;
	//短針
	double s = (H*30) + (0.5*M);
	k = (s - l);
	if (k > 120)
		k = 360 - k;
	if (k < 0)
		k *= -1;
	double deg = k * (PI/180);
	// int h = H, m = M;
	// long double rad =   PI * 2 *  ((long double)h / 12.0 + 
	// ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	double ans = (double)(A*A + B*B) - (double)2*A*B*cos(deg);

	printf("%.15f\n", sqrt(ans));
	// printf("%f\n", deg);
	// printf("%Lf\n", rad);
	return (0);
}


Measured memory_bytes: 4196
package main

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

type Tuple struct {
	x int
	y int
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()
	edge := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		edge[i] = make([]int, 0)
	}

	for i := 0; i < M; i++ {
		x := sc.NextInt()
		y := sc.NextInt()
		edge[x] = append(edge[x], y)
		edge[y] = append(edge[y], x)
	}

	checked := make([]int, N+1)

	count := 0

	for i := 1; i <= N; i++ {
		if checked[i] > 0 {
			continue
		}
		queue := make([]int, 1)
		queue[0] = i
		mp_hit := map[int]bool{}
		p_hit := map[int]bool{}
		mp_hit[i] = true
		p_hit[p[i-1]] = true

		c := 0
		for c < len(queue) {
			current := queue[c]
			for _, v := range edge[current] {
				if checked[v] > 0 {
					continue
				}
				mp_hit[v] = true
				p_hit[p[v-1]] = true
				checked[v] = 1
				queue = append(queue, v)
			}
			c++
		}

		for k, _ := range mp_hit {
			if _, ok := p_hit[k]; ok {
				count++
			}
		}
	}
	fmt.Println(count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 21120
"""
https://atcoder.jp/contests/abc137/submissions/6808061

heapq構造をうまく使っている
「要素を追加」＆「その要素から最小値を取得」といったものを大規模に早く処理したい場合はこのやり方が基本となりそう
"""

import sys
from heapq import heappush, heappop
 
n, m = list(map(int, input().split()))
works = []
for line in sys.stdin:
    a, b = map(int, line.split())
    if a > m:
        continue
    works.append((a, b))
 
works.sort(reverse=True) # works [(4, 3), (4, 1), (2, 2)]

q = []
ans = 0
for i in range(1, m + 1):
    ## 日単位で報酬をqueueに入れる＆worksのリストから削除
    # 仕事がある、かつ、まだ給料を受け取ることができる
    while works and works[-1][0] <= i: 
        _, b = works.pop() # 報酬を取得&worksから削除
        heappush(q, -b) # queueに報酬の負の値を入れる(heapqは最小値を取得するものなので負の値にする)
    ## 一番報酬が高いものを選択
    if q:
        b = -heappop(q) # queueからもっとも報酬の高い仕事の報酬を取得&queueから削除
        ans += b

print(ans)

Measured memory_bytes: 17208
s = str(input())
t = str(input())

ans = len(s)
for i in range(len(s) - len(t) + 1):
  count = 0
  for j in range(len(t)):
    if s[i + j] != t[j]:
      count += 1
  ans = min(ans, count)    
  
print(ans)  

Measured memory_bytes: 9024
//============================================================================
// Name        : Queue.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;



int main() {
	string line;
	getline(cin, line);
	istringstream iss(line);

	int n, q;
	iss >> n >> q;

	vector<string> name_list;
	vector<int> time_list;
	for(int i=0; i<n; i++){
	    getline(cin, line);
		istringstream iss(line);
		string input1;
		int time;
		iss >> input1 >> time;
		//cout << input1 << " " << time << "\n";
		//int time;
		//time = stoi(input2);

		name_list.push_back(input1);
		time_list.push_back(time);
	}

	int total_time = 0;
	int n_jobs = n;
	int n_jobs_unfinished = 0;
	while(n_jobs > 0){
		for(int i=0; i<n_jobs; i++){
			int residual = time_list.at(i) - q;
			if(residual>0){
				total_time = total_time + q;
				time_list.at(n_jobs_unfinished) = residual;
				name_list.at(n_jobs_unfinished) = name_list.at(i);
				n_jobs_unfinished = n_jobs_unfinished + 1;
			}else{
				total_time = total_time + time_list.at(i);
				cout << name_list.at(i) << " " << total_time << "\n";
			}
		}

		n_jobs = n_jobs_unfinished;
		n_jobs_unfinished = 0;
	}

}



Measured memory_bytes: 5796
from itertools import product
N = input()
ans = 0
for i in range(3,len(N)+1):
    for k in product(["3","5","7"],repeat=i):
        if k.count("3") > 0 and k.count("5") > 0 and k.count("7") > 0:
            if int(''.join(k)) <= int(N):
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

const long long MOD = 2;

void solve(long long N, std::vector<long long> a){
  vector<long long> ans(N);
  long long t, x;
  for (long long i = N-1; i >= 0; i--) {
    t = i;
    x = 0;
    x ^= a[t];
    t += i+1;
    while (t < N) {
      x ^= ans[t];
      t += i+1;
    }
    ans[i] = x;
  }
  long long num = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i] != 0) {
      num++;
    }
  }
  std::cout << num << std::endl;
  for (int i = 0; i < N; i++) {
    if (ans[i] != 0) {
      std::cout << i+1 << std::endl;
    }
  }
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N , a , b;
  cin >> N;
  for(int i = 1 ; i <= 9 ; i++)
  {
    a = N / i;
    b = N % i;
    if(b == 0 && a <= 9 && 1 <= a)
    {
      cout << "Yes" << endl;
      break;
    }
    if(i == 9)
    {
      cout << "No" << endl;
    }
  }
}

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    if(s[0] != '1'){
        cout << s[0];
        return 0;
    }
    int i = 0 ;
    while(i < s.size()&&s[i]=='1')
        i++;
    if(k-1 > i-1)
        cout << s[i];
    else
        cout << "1";
}


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

int main(){
  int n;
  int res = 0;
  for(int i = 0 ; i < 5; i++){
    cin >> n;
    if(n==0){
      res = i + 1;
      break;
    }
  }
  cout << res <<endl;
  return 0;
}
  

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int zero=0;
  int one=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0') zero++;
    else one++;
  }
  cout<<2*min(zero,one)<<endl;
}


Measured memory_bytes: 512
solve :: [Int] -> String
solve (a:b:c:d:xs)
  | l > r     = "Left"
  | l < r     = "Right"
  | otherwise = "Balanced"
  where l = a + b
        r = c + d

infixl 1 |>
x |> f = f x

main = do
  str <- getLine
  str |> words |> map (\x -> read x :: Int) |> solve |> putStrLn

Measured memory_bytes: 508
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<int> Vi;
typedef pair<int, int> Pii;
# define pb push_back
# define mp make_pair
# define MOD 1000000007
# define INF 1000000000
# define bug puts("H");

const int N = 10000 + 5;

inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int main ()
{
    int n;
    scanf("%d", &n);
    printf("%d\n",3*n*n);
    return 0;
}


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


def solve(S: int):
    S = str(S)
    for i in range(len(S) - 1):
        if S[i] == S[i+1]:
            print ("Bad")
            return
    print("Good")
    return


# Generated by 1.1.4 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()
    S = next(tokens)  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[80][80];
int B[80][80];
const int MAX = (80 + 79) * 80;
bool dp[80][80][MAX + 1]; // dp[i][j][k]: マス(i, j)までの偏りをkにできるか

int main() {
	int H, W;
	cin >> H >> W;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			cin >> A[i][j];
		}
	}

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

	int v0 = abs(A[0][0] - B[0][0]);
	dp[0][0][v0] = true;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			for (int k=0; k<=MAX; k++) {
				if (dp[i][j][k] == false) continue;

				if (i < H-1) {
					int v1 = abs(k + (A[i+1][j] - B[i+1][j]));
					int v2 = abs(k - (A[i+1][j] - B[i+1][j]));
					dp[i+1][j][v1] = true;
					dp[i+1][j][v2] = true;
				}

				if (j < W-1) {
					int v1 = abs(k + (A[i][j+1] - B[i][j+1]));
					int v2 = abs(k - (A[i][j+1] - B[i][j+1]));
					dp[i][j+1][v1] = true;
					dp[i][j+1][v2] = true;
				}
			}
		}
	}

	int ans;
	for (int i=0; i<=MAX; i++) {
		if (dp[H-1][W-1][i] == true) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 78848
#include <iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int max;
    vector<int>A(N);
    vector<int>B(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    B=A;
    sort(A.begin(),A.end());
    for(int j=0;j<N;j++){
        if(B[j]==A[N-1]){
            cout<<A[N-2]<<endl;
        }else{
            cout<<A[N-1]<<endl;
        }
    }
}

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

int odd(int x){
  if(x%2 == 0)
    return x/2;
  else
    return 3*x+1;
}

int main(){
  vector<int> S(1000000,0);
  cin >> S[0];




bool check=false;
  int ans=0;
for(int i=0;i<1000000 ;i++){
  S[i+1]=odd(S[i]);
  ans=i+2;  
  for(int j=i; j>-1;j--){
   if(S[i+1]==S[j]){
     check = true;

     break; 
   }
  }
  
  if(check==true){
    break;
  }
}


  cout << ans <<endl;
 

}

Measured memory_bytes: 4096
# coding: utf-8
# Your code here!
N,L =  list(map(int,input().split()))
ringo=0
min=99999999
kekka = []

for i in range(N):
    ringo+=(i+L)
 
    if i+L>0:
        if min >i+L:
            min = i+L
    elif i+L<0:
        if 0 <abs(i+L):
            min = i+L
    elif i+L == 0:
        min = 0
        

print(ringo-min)

Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main {
 
	static Scanner scanner;
 
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
 
	    int a=gi();
	    int b=gi();
	    int c=gi();
 
	    //System.out.print(String.valueOf(c));
 
        if ((a==b && a!=c) || (a==c && a!=b) || (b==c && b!=a)) {
        	System.out.print("Yes");
        }else {
        	System.out.print("No");
        }
 
 
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}
 
	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}
 
	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
 
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35536
import Foundation
func main() {
    let inputs = readLine()!.split(separator: " ")
    let X = Int(inputs[0])!
    // var fives = Array(repeating: 0, count: 400)
    // for i in -200..<200 {
    //     fives[i + 200] = Int(pow(Double(i), 5.0))
    // }
    // for i in 0..<400 {
    //     for j in 0..<400 {
    //         let diff = fives[i] - fives[j]
    //         // print("diff: \(diff)")
    //         if diff == X {
    //             // print("i: \(i - 99) j: \(j - 99)")
    //             print("\(i - 199) \(j - 199)")
    //             return
    //         }
    //     }
    // }

    for i in -118..<120 {
        for j in -118..<120 {
            let pi = pow(Double(i), 5.0)
            let pj = pow(Double(j), 5.0)
            if Int(pi - pj) == X {
                print("\(i) \(j)")
                return
            }
        }
        
        // for j in −118...119 {

        // }
    }
}

main()

Measured memory_bytes: 13988
# -*- coding: utf-8 -*-
import sys

X,Y,A,B,C=map(int, sys.stdin.readline().split())
R=map(int, sys.stdin.readline().split())
G=map(int, sys.stdin.readline().split())
N=map(int, sys.stdin.readline().split())
R.sort(reverse=True)
G.sort(reverse=True)

L=R[:X]+G[:Y]+N
L.sort(reverse=True)
print sum(L[:X+Y])

Measured memory_bytes: 66160
using System;

class Program
{
    static int n;
    static int m;
    static int[] a;
    static int[] b;

    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split();
        n = int.Parse(nm[0]);
        m = int.Parse(nm[1]);

        a = new int[m];
        b = new int[m];
        for (int i = 0; i < m; i++)
        {
            var ab = Console.ReadLine().Split();
            a[i] = int.Parse(ab[0]);
            b[i] = int.Parse(ab[1]);
        }

        var v = new bool[n];
        v[0] = true;
        var ans = m1(1, v);
        Console.WriteLine(ans);
    }

    static int m1(int x, bool[] v)
    {
        var all = true;
        for (int i = 0; i < n; i++) all &= v[i];
        if (all) return 1;

        var ans = 0;
        for (int i = 0; i < m; i++)
        {
            if (a[i] == x && !v[b[i] - 1])
            {
                v[b[i] - 1] = true;
                ans += m1(b[i], v);
                v[b[i] - 1] = false;
            }
            else if (b[i] == x && !v[a[i] - 1])
            {
                v[a[i] - 1] = true;
                ans += m1(a[i], v);
                v[a[i] - 1] = false;
            }
        }
        return ans;
    }
}


Measured memory_bytes: 13140
def main():
    n, m = map(int, input().split())
    digit = {}
    for i in range(m):
        s, c = map(int, input().split())
        if digit.get(s) is not None and digit.get(s) != c:
            print(-1)
            return
        digit[s] = c
    ans = ''
    for i in range(1, n+1):
        ans += str(digit.get(i, '0'))

    if ans == str(int(ans)):
        print(ans)
    elif ans[0] == '0' and digit.get(1) is None:
        print('1' + ans[1:])
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long res,p2[11],p10[11];
string s;
int main()
{
    cin>>s;
    int n=s.length();
    p2[0]=p10[0]=1;
    for (int i=1;i<=10;++i) {
        p2[i]=p2[i-1]*2;
        p10[i]=p10[i-1]*10;
    }
    for (int i=0;i<n;++i)
        for (int j=i;j<n;++j)
            res+=p2[i+max(0,n-j-2)]*(s[i]-'0')*p10[j-i];
    cout<<res<<endl;
    return 0;
}


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

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


Measured memory_bytes: 1024