akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

template<class T, class S>
inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}





int main(){
    int N; std::cin >> N;
    std::vector<std::vector<bool>> a(N, std::vector<bool>(N));
    {
        int b;
        for(int i(0); i < N; ++i){
            for(int j(0); j < N; ++j){
                std::cin >> b;
                a[i][j] = !!b;
            }
        }
    }
    //dp[i] := iのj桁目が0:j人目の男はペアになっていない
    std::vector<int> dp((1<<N), 0);
    dp[0] = 1;
    {
        for(int S(1), S_len(1<<N); S < S_len; ++S){
            int i(std::bitset<32>(S).count());
            for(int j(0); j < N; ++j){
                if(((S>>j) & 1) && a[i-1][j])
                    dp[S] = (dp[S] + dp[S - (1<<j)]) % MOD;
            }
        }
    }
    std::cout << dp[(1 << N) - 1] << std::endl;
    return 0;
}


Measured memory_bytes: 8448
# -*- coding: utf-8 -*-

N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N):
    for j in range(i+1,N):
        k = 2*j-i
        if N > k and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(ans)

Measured memory_bytes: 68112
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        k: usize,
        s: usize,
    }
    let mut ans = 0;
    for i in 0..k + 1 {
        for j in 0..k + 1 {
            if s - i - j >= 0 && s - i - j <= k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    int a,b;
    cin >> a >> b;
    bool ok=false;
    for(int i=1;i<=3;++i) {
        int x=a*b*i;
        if(x%2!=0) {
            ok=true;
            break;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<ctime>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
    int x = 0; char ch = gc(); bool positive = 1;
    for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
    for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
    return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
    }
    write(a); puts("");
}
ll n,ans;
ll solve(ll a,ll b){return a%b?solve(a*(b-1)/b,b):a/b;}
ll Dec(ll a,ll b){return a-a*(b-1)/b;}
ll Solve(ll a,ll b){
	for(;a%b;){
		ll l=1,r=1e9,ans=0,dec=Dec(a,b);
		for(;l<=r;){
			ll mid=(l+r)>>1;
			if (a-mid*dec>=0&&Dec(a-mid*dec,b)==dec)ans=mid,l=mid+1;
			else r=mid-1;
		}
		a-=dec*(ans+1);
	}
	return a/b;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){ll x=read(),y=read();ans^=Solve(x,y);}
	puts(ans?"Takahashi":"Aoki");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;
const int K = 61;

int dp[K][2][2];

int gb(int i, int j) {
	return (i >> j) & 1;
}

int proc(int lmask, int mn, int mx) {
	mn -= (1LL << lmask);
	mn = max(mn, (int)0);
	mx = min(mx, (1LL << lmask) - 1);
	if (lmask == 0) {
		return mx >= 0 && mn <= 0;
	}
	if (mn >= (1LL << lmask)) {
		return 0;
	}
	for (int i = 0; i < K; i++) {
		for (int f = 0; f < 2; f++) {
			for (int s = 0; s < 2; s++) {
				dp[i][f][s] = 0;
			}
		}
	}
	dp[lmask][0][0] = 1; 
	for (int i = lmask; i > 0; i--) {
		for (int wf = 0; wf < 2; wf++) {
			for (int ws = 0; ws < 2; ws++) {
				if (dp[i][wf][ws] == 0) continue;
				for (int f = 0; f < 2; f++) {
					for (int s = 0; s < 2; s++) {
						if ((f & s) != s) continue;
						if (!wf && f > gb(mx, i - 1)) continue;
						if (!ws && s < gb(mn, i - 1)) continue;
						int nwf = (wf | (f < gb(mx, i - 1)));
						int nws = (ws | (s > gb(mn, i - 1)));
						dp[i - 1][nwf][nws] += dp[i][wf][ws];
						dp[i - 1][nwf][nws] %= MOD;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int f = 0; f < 2; f++) {
		for (int s = 0; s < 2; s++) {
			ans += dp[0][f][s];
			ans %= MOD;
		}
	}
	return ans;
}

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

	int l, r;
	cin >> l >> r;
	int ans = 0;
	for (int i = 0; i < K; i++) {
		if ((1LL << i) <= r) {
			ans += proc(i, l, r - (1LL << i));
			ans %= MOD;
		}
	}
	cout << ans << endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const int N=300005;

int n;
ll a[N],b[N],c[N]; 
int main(){
	//freopen("aa.in","r",stdin);
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;++i)cin>>a[i];
	for(i=1;i<=n;++i)b[i]=b[i-1]^a[i];
	for(i=1;i<=n;++i)c[i]=c[i-1]+a[i];
	ll ans=0;
	for(j=0,i=1;i<=n;++i){
		for(;j<i&&(b[i]^b[j])!=(c[i]-c[j]);++j);
		ans+=i-j;
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vi d(n);
	rep(i, n) cin >> d[i];

	sort(all(d));

	cout << d[n/2] - d[n/2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] x = new long[n];
        long[] y = new long[n];
        long[] z = new long[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            z[i] = sc.nextLong();
        }

        long[][] mm = new long[8][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 8; j++) {
                long kk = 0;
                if ((j & 4) == 0) {
                    kk += x[i];
                } else {
                    kk -= x[i];
                }

                if ((j & 2) == 0) {
                    kk += y[i];
                } else {
                    kk -= y[i];
                }

                if ((j & 1) == 0) {
                    kk += z[i];
                } else {
                    kk -= z[i];
                }
                mm[j][i] = kk;
            }
        }
        long ans = 0;
        for (int i = 0; i < 8; i++) {
            Arrays.sort(mm[i]);
            long tmp = 0;
            for (int j = 0; j < m; j++) {
                tmp += mm[i][n - j - 1];
            }
            ans = Math.max(ans, tmp);
        }

        System.out.println(ans);

    }

}


Measured memory_bytes: 26812
n = gets.to_i
h = gets.split.map(&:to_i)
ans = 0
cnt = 0
(n-1).times do |i|
  if h[i] >= h[i+1]
    cnt += 1
  else
    ans = cnt if cnt > ans
    cnt = 0
  end
end
ans = cnt if cnt > ans
puts ans


Measured memory_bytes: 20788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int p[26] = {};
    for (int i = 0; i < n; i++) {
        p[s[i] - 'a']++;
    }

    for (int i = 0; i < 26; i++) {
        if (p[i] % 2 != 0) {
            cout << "No" << endl;
            quick_exit(0);
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(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
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	if n == 1 {
		fmt.Fprintln(writer, "First")
		return
	}
	ee := make([][]edge, n)
	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		appendEdge(a, b, i, ee)
		appendEdge(b, a, i, ee)
	}
	dd := make([]int, n)
	dfs(0, -1, 0, dd, ee)
	win := make([]bool, n+1)
	win[0] = true
	for i := 2; i < n+1; i++ {
		win[i] = !(win[i-1] && win[i-2])
	}
	mx := -1
	for i := 0; i < n; i++ {
		mx = maxint(mx, dd[i])
	}
	if win[mx] {
		fmt.Fprintln(writer, "First")
		return
	}
	fmt.Fprintln(writer, "Second")
}

func dfs(c, p, d int, dd []int, ee [][]edge) int {
	dd[c] = d
	hh := make([]int, 2)
	hh[0] = d
	hh[1] = d
	for _, e := range ee[c] {
		if e.to == p {
			continue
		}
		h := dfs(e.to, c, d+1, dd, ee)
		if hh[0] < h {
			hh[0] = h
		}
		if hh[0] > hh[1] {
			hh[0], hh[1] = hh[1], hh[0]
		}
	}
	dd[c] = hh[0] + hh[1] - d<<1
	return hh[1]
}

func maxint(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func appendEdge(from, to, id int, ee [][]edge) {
	ee[from] = append(ee[from], edge{
		to: to,
		id: id,
	})
}

type edge struct {
	to, id int
}


Measured memory_bytes: 122112
use proconio::*;
fn main() {
    input! {
        x:i32,
        y:i32,
    }
    // a + b = x
    // 2a + 4b = y
    // a = ( 4x - y) /2
    // b = (-2x + y) /2
    let a = (4 * x - y) / 2;
    let b = (-2 * x + y) / 2;
    if a >= 0 && b >= 0 && a + b == x && 2 * a + 4 * b == y {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2112
a, b = map(int, input().split())

# get GCD(Gratest Common Divisor: 最大公約数)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# get divisors(公約数)
def divisors(n):
    nums = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            nums.append(i)
            if i != n // i:
                nums.append(n//i)
    return sorted(nums)

# is prime(Prime Number: 素数)
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0: return False
    return True

x = divisors(gcd(a, b))

ans = 1
for _x in x:
    ans += is_prime(_x)

print(ans)


Measured memory_bytes: 41452
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   int n, m;
   cin >> n >> m;
   priority_queue<int> pq;
   for (int i = 0; i < n; i++){
	   int x;
	   cin >> x;
	   pq.push(x);  
	 }
	int ret = 0;
	for (int i = 0; i < m; i++){
	 int val = pq.top();
	 pq.pop();
	 int copy = val >> 1;
	 pq.push(copy);	
   }
   while (pq.size()){
	     ret += pq.top();
	     pq.pop(); 
	  }
	cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto D=vecin(N);
	ll sum=0;
	REP(i,N){
		for(int j=i+1;j<N;j++){
			sum += D[i]*D[j];
		}
	}
	
	out(sum);
	return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=[-1]*n
    cnt=0
    now=0
    for i in range(n):
        while now<=i:
            if cnt+a[i]==cnt^a[i]:
                cnt+=a[i]
                ans[i]=now
                break
            else:
                cnt-=a[now]
                now+=1
    print(sum([i-ans[i] for i in range(n)])+n)
main()

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

int main() {
	long long h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}
	cout << (h * w + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
using namespace std;
const int INF = (int) 1e9;

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> P(D), C(D);
    for (int i = 0; i < D; ++i) {
        cin >> P[i] >> C[i];
    }

    int ans = INF;
    for (int complete_set = 0; complete_set < (1 << D); ++complete_set) {
        int score = 0, solved = 0;
        for (int i = 0; i < D; ++i) {
            if (complete_set >> i & 1) {
                score += P[i] * 100 * (i + 1) + C[i];
                solved += P[i];
            }
        }
        for (int i = D; i >= 0; --i) {// 残りはスコアが大きい方から考えていく。
            if (i == D) {
                if (score >= G) {
                    ans = min(ans, solved);
                    break;
                }
            } else if (!(complete_set >> i & 1)) {
                int pb_score = 100 * (i + 1);
                if (score + (P[i] - 1) * pb_score >= G) {
                    solved += (G - score + pb_score - 1) / pb_score;
                    ans = min(ans, solved);
                    break;
                }
                score += (P[i] - 1) * pb_score;
                solved += P[i] - 1;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    long long a,b;
    cin >> a >> b;
    long long ans=(b/a+1)*a;
    if(b%a==0)cout<<-1<<endl;
    else if(ans/a<ans%b+1)cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 3112
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int x, y, z;
		x = scanner.nextInt();
		y = scanner.nextInt();
		z = scanner.nextInt();
		//swap box A and B
		int copy = x;
		x = y;
		y = copy;
		//swap box A and C
		copy = x;
		x = z;
		z = copy;
		System.out.println("" + x + " " + y + " " + z);
	}
}

Measured memory_bytes: 23764
from collections import deque

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m = nm()

p = [[] for _ in range(n)]

for i in range(m):
  a,b = nm()
  p[a-1].append(b-1)
  p[b-1].append(a-1)

visited = [False]*n

visited[0]=True

q = deque()
q.append(0)

ans = [0]*n

while len(q) > 0:
  num = q.popleft()
  for i in p[num]:
    if visited[i]:
      continue
    ans[i]=num+1
    visited[i]=True
    q.append(i)

if len(visited)==n:
  print('Yes')
  for i in range(1,len(ans)):
    print(ans[i])
else:
  print('No')

Measured memory_bytes: 94696
#include <iostream>
#include <set>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <vector>



#define MAX_N 10000
#define INF   100000000

using namespace std;


long long par[MAX_N];  //parent 0f node
long long rank[MAX_N]; //depth of node

long long fib[MAX_N];



//n個ので初期化、
void init(long long n) { 
    for (long long i=1; i <= n; i++){
        par[i] = i;
        rank[i] = 0;
    }
}

//代表ノードの親は自分自身
long long find(long long x) { 
    if (par[x] == x) {
        return x;
    } else {
        par[x] = find(par[x]);
        return par[x];
    }
}

void unite(long long x, long long y){
    x = find(x);
    y = find(y);
    if (x==y) { return; }
    else if (rank[x] < rank[y]) { 
        par[x] = y;
    }
    else if (rank[y] < rank[x]) { 
        par[y] = x;
    }
    else {
        par[y] = x;
        rank[x]++;
    }
}

void init_fib(){
    for( long long i = 0; i<MAX_N; i++){
        fib[i] = INF;
    }
}

long long f(long long n){
    if(n == 0 || n==-1) { return 1;} 
    else if(fib[n] != INF ) {return fib[n];}
    else { return fib[n] = (  f(n-1) + f(n-2) )%1001 ; }
}

void print_fib(){
    for ( long long i = 1; i<=10 ; i++ ) {
        cout << f(i) << " " ;
    }
    cout << endl;
}

int main()
{
    init_fib();
    //cout << f(100);
    //print_fib();

    long long V,d;
    while( cin >> V >>d ){
       if( V==0 && d==0){ break;}
       init(MAX_N);
       for( long long i=1; i<=V; i++ ){
           for( long long j=i + 1; j<=V; j++ ){
               if( abs( f(i) - f(j) )%1001 < d ){
                   //cout << "unite(" << i << "," << j << ")" << endl;
                   //cout << f(i) << "-" << f(j) << " = " <<  abs( f(i) - f(j) ) << endl;
                   unite(i,j);
               }
           }
       }

       set<long long> count;
       for( long long i=1; i<=V; i++){
           //cout << "count = " << find(i) << endl;
           count.insert( find(i) );
       }
       cout << count.size() << endl;
    }
    return 0;
}

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

int main(void){
    ll n;
    cin >> n;

    map<ll, ll> a;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a[tmp]++;
    }

    ll ma = 0;
    for(auto a_t: a){
        ll tmp = a_t.second;
        if(a.count(a_t.first+1)){
            tmp += a[a_t.first+1];
        }
        if(a.count(a_t.first-1)){
            tmp += a[a_t.first-1];
        }
        ma = max(ma, tmp);
    }

    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 4224
n=int(input())
a=[int(x) for x in input().split()] # n+1　個
b=[int(x) for x in input().split()] # n 個

ans=0
for i in range(n):
    if a[i]>=b[i]:
        a[i]-=b[i]
        ans+=b[i]
        b[i]=0
    else:
        b[i]-=a[i]
        ans+=a[i]
        a[i]=0
        if a[i+1]>=b[i]:
            a[i+1]-=b[i]
            ans+=b[i]
            b[i]=0
        else:
            ans+=a[i+1]
            b[i]-=a[i+1]
            a[i+1]=0
print(ans)


Measured memory_bytes: 19004
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vi a(n); 
    rep(i, n) cin >> a[i];
    
    vi ans;
    vector<bool> seen(n, false);
    P mx = {-1, -1};

    rep(j, n){
        int cnt = 0;
        rep(i, n){
            if(seen[i]) cnt++;
            else if(a[i] == i + 1 - cnt) mx = {i, a[i]};
        }
    
        if(mx.se == -1){
            cout << -1 << endl;
            return;
        }else{
            ans.pb(mx.se);
            seen[mx.fi] = true;
            mx = {-1, -1};
        }
    }

    reverse(all(ans));
    for(auto x : ans){
        cout << x << endl;
    }
    return;
}

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

Measured memory_bytes: 3636
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Measured memory_bytes: 38152
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e9;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号


int main(){
	int x;
	while(cin>>x){
		if(x%39==0)cout<<"3C39"<<endl;
		else cout<<"3C"<<setw(2)<<setfill('0')<<x%39<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll func(int n,int w,int wt[],int val[],ll dp[][101])
{
	if(w==0 || n<0)
		return 0;
	if(dp[w][n]!=-1)
		return dp[w][n];
	if(w-wt[n]<0)
		return dp[w][n] = func(n-1,w,wt,val,dp);
	else
		return dp[w][n] = max(val[n]+func(n-1,w-wt[n],wt,val,dp),func(n-1,w,wt,val,dp));
}
int main()
{
	int n,w;
	cin>>n>>w;
	int wt[n],val[n];
	for(int i=0;i<n;i++)
		cin>>wt[i]>>val[i];
	ll dp[w+1][101];
	memset(dp,-1,sizeof(dp));
	cout<<func(n-1,w,wt,val,dp);
}

Measured memory_bytes: 82496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		sc.close();
		
		for(int i = 1; i <= n ;i++) {
			int x = i;
			boolean ok = false;
			
			if(x % 3 == 0) {
				ok = true;
			} else {
				
				while(x > 0) {
					if(x % 10 == 3) {
						ok = true;
						break;
					}
					x /= 10;
				}
				
			}
			
			if(ok) System.out.print(" " + i);
			
		}
                System.out.println();
	}
}

Measured memory_bytes: 28784
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main(){
    int N;
    long res,initial[5];
    char name[5] = {'M','A','R','C','H'};
    string buf;

    scanf("%d",&N);

    res = 0;
    REPI(5)
        initial[i] = 0;
    

    REPI(N){
        cin >> buf;        
        REPJ(5){
            if(buf[0] == name[j])
                initial[j]++;
        }
    }


    REPI(5){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                res += initial[i] * initial[j] * initial[k];
            }
        }
    }

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


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

int main() {
  long W, a, b, ans = 0;
  cin >> W >> a >> b;
  
  if (a <= b) ans = b - a - W;
  else ans = a - b - W;
  
  if (ans < 0) ans = 0;
  
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int k, a, b; cin >> k >> a >> b;
  for(int i=a; i<=b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}

// EOF


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll x,t;
	cin>>x>>t;
	cout<<max(x-t,0ll)<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,k,a[N];
bool judge(int m)
{
    long long ans=0;
    for(int i=1;i<=n;i++)
        ans+=(a[i]-1)/m;
    return ans<=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    int l=1,r=1,ans;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),r=max(r,a[i]);
    while(l<=r)
    {
        int m=l+r>>1;
        if(judge(m)) ans=m,r=m-1;
        else l=m+1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using P = pair<ll, ll>;
void prp(P& p) {cout << p.first << " " << p.second << endl;}

int main()
{
    int n, m; cin >> n >> m;
    map<ll, ll> a;
    vector<ll> a_uniq;
    rep(i, n){
        ll t; cin >> t;
        a[t]++;
        if(a[t]==1) a_uniq.push_back(t);
    }
    sort(ALL(a_uniq));

    vector<P> b;
    rep(i, m){
        ll s, t; cin >> s >> t;
        b.push_back({t, s});
    }
    sort(b.rbegin(), b.rend());

    // rep(i, b.size()){
    //     printf("%ld, %ld\n", b[i].first, b[i].second);
    // }

    int ai=0, bi=0;
    while(ai < a_uniq.size() && bi < b.size()){
        if(b[bi].first <= a_uniq[ai]) break;

        ll anum, asize;
        ll bnum, bsize;
        anum = a_uniq[ai]; asize = a[anum];
        bnum = b[bi].first; bsize = b[bi].second;

        // cout << anum << " " << asize << "| " << bnum << " " << bsize << endl;
        if(asize > bsize){
            a[anum] -= bsize;
            a[bnum] += bsize;
            bi++;
        }else if(bsize > asize){
            a[anum] = 0;
            a[bnum] += asize;
            b[bi].second -= asize;
            ai++;
        }else{
            a[anum] = 0;
            a[bnum] += bsize;
            ai++;
            bi++;
        }

        // for(auto t: a) cout << t.first << "." << t.second << " ";
        // pr("");
    }

    ll ans = 0;
    for(auto t: a) ans += t.first*t.second;
    pr(ans);
    return 0;}

Measured memory_bytes: 15248
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;


int main (){
     ll a,b,c,d;
     cin >> a >> b >> c >> d;
     ans = b*d;
     ans = max(ans,a*d);
     ans = max(ans,b*c);
     ans = max(ans,a*c);
     cout << ans << endl;
}

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

void serch(long long n) {
    long long m;

    if (n/26 > 0) {
        serch(n/26-1);
    }

    printf("%c", 'a'+(n%26));
}

int main() {

    long long n;
    scanf("%lld", &n);

    serch(n-1);

    return 0;
}

Measured memory_bytes: 3804
N = int(input())
A = list(map(int,input().split()))

apex = [0]*(N+1)
apex[0] = 1
a = 0
listed = [0]*(N+1)
listed[0] = 1
listed[N] = A[N]

if (A[0] != 0)&(N != 0):
    a = 1
elif (A[0] != 1)&(N==0):
    a = 1

for d in reversed(range(1,N)): #N-1から1まで
    listed[d] = listed[d+1] + A[d]

for d in range(1,N+1):
    listed[d] = min(listed[d],apex[d-1]*2)
    apex[d] = listed[d] - A[d]
    if A[d] > listed[d]:
        a = 1
        break


if a == 1:
    print('-1')
else:
    print(sum(listed))

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

int main()
{
    int n; cin>>n;
    vector<int> a(n+2);
    for(int i=1; i<=n; ++i) cin>>a[i];

    int sum=0;
    for(int i=1; i<=n+1; ++i) sum+=abs(a[i]-a[i-1]);

    for(int i=1; i<=n; ++i)
        cout<<sum-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1])<<endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    int n; cin>>n;
    vector<int>v(n);
    rep(i,n)cin>>v[i];
    vector<bool>hoge(n);
    int cnt=0;
    rep(i,n){
        if(v[v[i]-1]==i+1)cnt++;
    }
    cout<<cnt/2<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  /*
  ll M;
  std::cin >> A >> B >> C;
  */

  ll M;
  std::cin >> M;
  ll ans = 48 - M;
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
 
	int x,a,b;
 
	cin >> x >> a >> b;
 
	if(abs(x-a) >= abs(x-b)){
		cout << "B";
	}
	else{
		cout << "A";
	}
 
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <set>
#include <utility>
#include <vector>

#define MAX_Q (200000L)

using namespace __gnu_pbds;
using namespace std;

typedef tree<pair<long, long>, null_type, less<pair<long, long>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

int main(int argc, char *argv[]) {
  // read number of queries
  long Q, ts[MAX_Q], as[MAX_Q], bs[MAX_Q];
  scanf("%ld", &Q);
  for (long q = 0; q < Q; q++) {
    scanf("%ld", &ts[q]);
    if (ts[q] == 1) {
      scanf("%ld %ld", &as[q], &bs[q]);
    }
  }

  // respond to each query
  long total_b = 0, total_d = 0, min_q = -1, min_a = -1;
  ordered_set ps;
  // process query 0
  total_b += bs[0];
  ps.insert(make_pair(as[0], 0));
  min_q = 0;
  min_a = as[0];
  // printf("q = %ld, total_b = %ld, min_a = %ld, total_d = %ld\n", 0L, total_b,
  //        min_a, total_d);
  // process the other queries
  for (long q = 1; q < Q; q++) {
    const long t = ts[q];
    if (t == 1) {
      const long a = as[q], b = bs[q];
      total_b += b;
      ps.insert(make_pair(a, q));
      const long k = ps.size();
      total_d += abs(a - min_a);
      // does min_q, min_a change?
      if (k % 2L == 0L && a < min_a) {
        const pair<long, long> new_min_p = *ps.find_by_order((k - 1) / 2);
        const long new_min_a = new_min_p.first, new_min_q = new_min_p.second;
        // total_d -= abs(new_min_a - min_a);
        // printf("min_a changed from %ld to %ld\n", min_a, new_min_a);
        min_a = new_min_a;
        min_q = new_min_q;
      } else if (k % 2L == 1L && a > min_a) {
        const pair<long, long> new_min_p = *ps.find_by_order((k - 1) / 2);
        const long new_min_a = new_min_p.first, new_min_q = new_min_p.second;
        total_d -= abs(new_min_a - min_a);
        // printf("min_a changed from %ld to %ld\n", min_a, new_min_a);
        min_a = new_min_a;
        min_q = new_min_q;
      }
      // printf("q = %ld, total_b = %ld, min_a = %ld, total_d = %ld\n", q, total_b,
      //        min_a, total_d);
    } else {
      printf("%ld %ld\n", min_a, total_b + total_d);
    }
  }

  return 0;
}


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

using namespace std;

double dice_in_line(int N, int K, vector<int>& p) {
	double max_sum, sum;
	int size = *max_element(p.begin(), p.end()) + 1;
	vector<double> E(size);
	
	for (int i = 1; i < size; i++) {
		double e = 0;
		for (int j = 1; j <= i; j++)
			e += (1.0 / i) * j;
		E[i] = e;
	}

	max_sum = 0;
	for (int i = 0; i < K; i++)
		max_sum += E[p[i]];
	sum = max_sum;
	
	for (int i = K; i < N; i++) {
		sum -= E[p[i - K]];
		sum += E[p[i]];
		max_sum = max(sum, max_sum);
	}

	return max_sum;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	for (int i = 0; i < N; i++)
		cin >> p[i];
	cout << fixed << setprecision(12) << dice_in_line(N, K, p);
	return 0;
}

Measured memory_bytes: 1024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
a=array(N)
2.times do|i|
    a[i]=get_i
end
dp=array(N,0,2)
dp[0][0]=a[0][0]
2.times do|i|
    N.times do|j|
        dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i][j]) if i-1>=0
        dp[i][j]=max(dp[i][j],dp[i][j-1]+a[i][j]) if j-1>=0
    end
end
puts dp[1][N-1]

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#define MAX 1000000

int main(void){
  _Bool table[MAX];
  int i, j;
  int cnt;
  int n;

  memset(table,1,sizeof(table));

  for (i = 0; i < MAX; i+=2){
    table[i] = 0;
  }
  table[0] = 0;
  table[1] = 0;
  table[2] = 1;

  for (i = 3; i < MAX; i+=2){
    if (table[i]){
      for (j = i+i; j < MAX; j+=i){
	table[j] = 0;
      }
    }
  }

  while (scanf("%d", &n) != EOF){
    cnt = 0;
    for (i = 0; i <= n; i++){
      if (table[i]){
	cnt++;
      }
    }
    printf("%d\n", cnt);
  }

  return 0;
}

Measured memory_bytes: 1580
#include<stdio.h>
#include<string.h>
#define MAX 1000
 
typedef struct{
  char str1[MAX+1];
  char str2[MAX+1];
}info;

int a[10099][10099];

int long_sub(info p)
{
  int m,n,i,j;
  m = strlen(p.str1); //count the number of letters
  n = strlen(p.str2);
  
  for(i=1;i<=m;i++)a[i][0]=0;
  for(j=1;j<=n;j++)a[0][j]=0;
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(p.str1[i-1]==p.str2[j-1]) a[i][j]=a[i-1][j-1]+1;
      else if(a[i-1][j]>=a[i][j-1]) a[i][j]=a[i-1][j];
      else a[i][j]=a[i][j-1];
    }
  }
  return a[m][n];
}


int main()
{
  int q,i;
  info p;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s%s",p.str1,p.str2);
    printf("%d\n",long_sub(p));
      }
  return 0;
}



Measured memory_bytes: 9608
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

const long long mod=1e9+7;

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> ok(n+1,true);
    rep(i,m) {
        int a;
        cin >> a;
        ok[a] = false;
    }
    vector<int> dp(n+1);
    dp[0]= 1;
    if (ok[1]==1) dp[1]=1;
    else dp[1] = 0;
    for(int i=2;i<=n;i++){
        if (ok[i]==true){
            dp[i] = (dp[i-1]+dp[i-2])%mod;
        }else{
            dp[i] = 0;
        }
    }
    cout << dp[n] << endl;

   
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	S := nextLine()
	len := len(S)
	numbers := []int{753}
	for i := 0; i < len-2; i++ {
		num, _ := strconv.Atoi(S[i : i+3])
		if num == 753 {
			fmt.Println(0)
			return
		}
		numbers = append(numbers, num)
	}
	sort.Ints(numbers)
	for i, num := range numbers {
		if num != 753 {
			continue
		}
		if i == 0 {
			fmt.Println(numbers[i+1] - 753)
			return
		} else if i == len-2 {
			fmt.Println(753 - numbers[i-1])
			return
		} else {
			prevDiff := 753 - numbers[i-1]
			nextDiff := numbers[i+1] - 753
			if prevDiff < nextDiff {
				fmt.Println(prevDiff)
				return
			} else {
				fmt.Println(nextDiff)
				return
			}
		}
	}
}


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

int main()
{
	string S;
	cin >> S;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		if ('x' == S.at(i)) {
			cnt++;
		}
	}
	if (cnt > 7)
		cout << "NO";
	else
		cout << "YES";
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

  class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int arr[] = new int[x];
        int arr2[] = new int[x];
        for(int i = 0 ; i<x ; i++){
            arr[i]=scan.nextInt();
            arr2[i]=arr[i];
        }
        Arrays.sort(arr2);
        int max1 = arr2[x-1];
        int max2 = arr2[x-2];
        for(int i = 0 ; i<x ; i++){
            if(arr[i]==max1){
                System.out.println(max2);
            }else{
                System.out.println(max1);
            }
        }
        
         
        
    }
}


Measured memory_bytes: 94264
#include<stdio.h>
int main()
{
    int a,b;
  char x,y;
  scanf("%c %c",&x,&y);
  a=x;
  b=y;
  if(a<b)printf("<\n");
  if(a>b)printf(">\n");
  if(a==b)printf("=\n");
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    x = n%k
    print(min(x,abs(k-x)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            #if i != n // i:
            divisors.append(n//i)
    return divisors


num = 0
div = make_divisors(N)
#print(div)
'''
for i in range(0,len(div)-1,2): #k
    if div[i+1]+1-div[i] >= 2 and div[i+1]+1-div[i] <= div[i+1]:
        num += div[i+1]-1
'''
for i in range(0,len(div)-1,2): #k
    if div[i] <= div[i+1]-2:
        num += div[i+1]-1
        #print(div[i+1]-1)


print(num)

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
  bool s = true;
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b == c) s = false;
  if(a != b && b != c && c != a) s = false;
  if(s) cout << "Yes" << endl;
  else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>

using namespace std;

class Vertex
{
public:
    int number_of_edges;
    vector<int> edges;
};

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

    vector<Vertex> adjacency_list(n);
    for (int i = 0; i < n; ++i) {
        int index;
        cin >> index >> adjacency_list[i].number_of_edges;

        adjacency_list[i].edges.resize(adjacency_list[i].number_of_edges);
        for (int j = 0; j < adjacency_list[i].number_of_edges; ++j)
            cin >> adjacency_list[i].edges[j];
    }

    vector<vector<int>> adjacency_matrix(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < adjacency_list[i].number_of_edges; ++j)
            adjacency_matrix[i][adjacency_list[i].edges[j] - 1] = 1;
    }

    for (int i = 0; i < n; ++i) {
        cout << adjacency_matrix[i][0];
        for (int j = 1; j < n; ++j)
            cout << ' ' << adjacency_matrix[i][j];
        cout << '\n';
    }
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k; cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)  cin>>a[i];
for(int i=k;i<=n-1;i++){
if(a[i]>a[i-k]) cout<<"Yes\n";
else{
cout<<"No\n";
}
}
}

Measured memory_bytes: 4424