akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	string s; cin >> s;
	int num1 = (s[0]-'0')*10 + s[1]-'0';
	int num2 = (s[2]-'0')*10 + s[3]-'0';
	if((num1>=1 && num1 <= 12) && (num2 >= 1 && num2 <= 12)){
		cout << "AMBIGUOUS";
	} else if(num2 >= 1 && num2 <= 12){
		cout << "YYMM";
	} else if(num1>=1 && num1 <= 12){
		cout << "MMYY";
	} else{
		cout << "NA";
	}
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3652
N = int(input())
x = [0]*N
y = [0]*N
f_0 = [0]*N
f_1 = [0]*N
for i in range(N):
    x[i],y[i] = map(int, input().split())
    f_0[i] = x[i] - y[i]
    f_1[i] = x[i] + y[i]
    
print(max(max(f_0)-min(f_0),max(f_1)-min(f_1)))


Measured memory_bytes: 40228
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll MOD = 2019;

ll mpow(ll a,ll b){
    ll res = 1;
    while(b > 0){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

int main(){
    string S;cin>>S;
    vector<int> v(2019,0);
    ll a = 0;
    v[0]++;
    for(int i = 0;i < S.size();i++){
        const char num[] = {S[S.size()-i-1]};
        a = (a + mpow(10,i) * atoi(num))%2019;
        v[a]++;
    }
    ll result = 0;
    for(int i = 0;i < 2019;i++){
        // if(v[i] > 0)
        // cout<<v[i]<<" "<<i<<endl;
        result += v[i] * (v[i]-1) / 2;
    }
    cout<<result<<endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
inline int read()
{
    int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int n;
int a[105];
int sum;
int main ()
{
	n=read();
	for(int i=1;i<n;i++)
		a[i]=read();
	sum+=a[1]+a[n-1];
	for(int i=2;i<n;i++)
		sum+=min(a[i],a[i-1]);
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);

            str = Console.ReadLine ().Split (' ');
            int[] A = new int[N];

            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse (str[i]);
            }

            Array.Sort (A);
            Array.Reverse (A);

            // for (int i = 0; i < N; i++) Console.WriteLine (A[i]);

            long ans = 0;
            for (int i = 0; i <= N - 2; i++)
            {
                // Console.WriteLine (A[(int) Math.Ceiling (((double) i) / 2)]);
                ans += A[(int) Math.Ceiling (((double) i) / 2)];
            }

            Console.Write (ans);
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 45920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    // cout << s << endl;
    // cout << t << endl;
    if(s < t) cout << "Yes" << endl;
    else      cout << "No"  << endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();

		int c = stdIn.nextInt();
		int d = stdIn.nextInt();

		int takahashiTurn = (int) Math.ceil(1.0 * c / b);
		int aokiTurn = (int) Math.ceil(1.0 * a / d);

		if(takahashiTurn > aokiTurn) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

		stdIn.close();
	}
}

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


class PostorderReconstructor {

public:
    int *preIds;
    int *inIds;
    int *postIds;
    int count;
    int currentPrePos = 0;
    int currentPostPos = 0;

    PostorderReconstructor(int preorderIds[], int inorderIds[], int cnt) {
        preIds = preorderIds;
        inIds = inorderIds;
        count = cnt;
        postIds = (int *)malloc(sizeof(int) * cnt);
    }

    ~PostorderReconstructor() {
        free(postIds);
    }

    void reconstruct(int leftPos, int rightPos) {
        if (leftPos >= rightPos)
            return;

        auto nextRoot = preIds[currentPrePos];
        currentPrePos += 1;
        auto middlePos = findInorderPos(nextRoot);

        reconstruct(leftPos, middlePos);
        reconstruct(middlePos + 1, rightPos);

        postIds[currentPostPos] = nextRoot;
        currentPostPos += 1;
    }

private:
    
    int findInorderPos(int id) {
        for (int i = 0; i < count; i++)
        {
            if (inIds[i] == id)
                return i;
        }
        throw "can`t find index in inorder ids";
    }
};


int main() {
    int N, i;

    cin >> N;

    int preorderIds[N], inorderIds[N];

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

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

    unique_ptr<PostorderReconstructor> reconstructor(new PostorderReconstructor(preorderIds, inorderIds, N));

    reconstructor->reconstruct(0, N);

    for (i = 0; i < N; i++)
    {
        if (i > 0)
            cout << " ";

        cout << reconstructor->postIds[i];
    }
    
    cout << endl;

}



Measured memory_bytes: 3088
#include<stdio.h>
int main()
{
	int a[5],i,g,t,p,r[5];
	while(1){
		g=p=t=0;
		scanf("%d",&a[0]);
		if(a[0]==0){
			break;
		}
		scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);
		for(i=0;i<5;i++){
			switch(a[i]){
			case 1:
				g++;
				break;
			case 2:
				t++;
				break;
			case 3:
				p++;
				break;
			}
		}
		if((g!=0&&t!=0&&p!=0)||g==5||t==5||p==5){
			for(i=0;i<5;i++){
				r[i]=3;
			}
		}else if(g==0){
			for(i=0;i<5;i++){
				if(a[i]==2){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}else if(t==0){
			for(i=0;i<5;i++){
				if(a[i]==3){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}else{
			for(i=0;i<5;i++){
				if(a[i]==1){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}
		for(i=0;i<5;i++){
			printf("%d\n",r[i]);
		}
	}
	return 0;
}

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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a >= 13)
		cout<<b<<endl;
	else if(a >= 6 && a <= 12)
		cout<<b/2<<"\n";
	else cout<<0<<"\n";
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

const ll N = 1e5 + 10;
ll f[N] = {0};

void solve() {
    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        sum += x;
        f[x]++;
    }
    ll q;
    cin >> q;
    for(ll i = 0; i < q; i++) {
        ll b, c;
        cin >> b >> c;
        sum -= b * f[b];
        sum += c * f[b];
        f[c] += f[b];
        f[b] = 0;
        cout << sum << "\n";
    }
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);



int main(){
	string s;
	cin>>s;
 bool a=false;
 bool b=false;
 for(auto j:s){
 	if(j=='A') a=true;
 	else b=true;
 }
 if(a&&b) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

    
}

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

#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

ii dish[3005];
int dp[3005][3005];
int ans = 0;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, t;
	cin >> n >> t;
	for (int i = 1; i <= n; i++) {
		cin >> dish[i].x >> dish[i].y;
	}
	sort(dish + 1, dish + n + 1);
	for (int i = 1; i <= n; i++) {
		int temp = 0;
		for (int j = 1; j < t; j++) {
			temp = max(temp, dp[i - 1][j] + dish[i].y);
			dp[i][j] = dp[i - 1][j];
			if (j >= dish[i].x) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - dish[i].x] + dish[i].y);
			}
		}
		ans = max(ans, temp);
	}
	cout << ans;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  IN(N,M);
  OUT((N*(N-1))/2+(M*(M-1)/2));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <math.h>

#define INT_MAX       2147483647

using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> candles(n);
	int cnt_plus = 0;
	int cnt_minus = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> candles[i];
		if (candles[i] > 0) cnt_plus++;
		if (candles[i] < 0)cnt_minus++;
	}
	int min_len = INT_MAX;
	for (int i = max(0, n - cnt_plus - k); i <= min(cnt_minus, n - k); i++)
	{
		int len = 0;
		if (candles[i + k - 1] <= 0) len = -candles[i];
		else if (candles[i] >= 0) len = candles[i + k - 1];
		else len = min(abs(candles[i]), abs(candles[i + k - 1])) * 2 + max(abs(candles[i]), abs(candles[i + k - 1]));

		if (len < min_len) min_len = len;
	}

	cout << min_len << endl;
}

int main()
{

	solve();
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  ll ans = 1LL;
  ll MOD = 1000000007;
  for (int i = 1; i <= n; i++) {
    ans = ans * i % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), f = sc.nextInt(), b = sc.nextInt();

        if(m >= b) {
            System.out.println(0);
        } else if(m + f >= b) {
            System.out.println(b - m);
        } else {
            System.out.println("NA");
        }
    }
}

Measured memory_bytes: 26128
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      k: usize,
    }
    println!("{}", n-k+1);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
const int mod = 1000000007;
typedef long long ll;
//------------------------------------------------------------------------

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

  int n; cin >> n;
  vector<int> a(200005);
  rep1(i,n) cin >> a[i];
  
  int cnt=0;
  rep1(i,n){
    if(a[i]==cnt+1){
      cnt++;
    }
  }
  if(cnt == 0) cout << -1 << endl;
  else cout << n - cnt << endl;
  
  return 0;
}





Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
  ll N;
  cin >> N;
  ll ans = 0;
  for(ll i = 0; i < N; i++){
    ll a;
    cin >> a;
    ans += a;
  }
  cout << ans - N << endl;
  return 0;
}

Measured memory_bytes: 256
S = list(input())
lop = 0
cnt = 0
fg = True

while(True):
    if len(S) < 2:
        break

    if not S[lop] == S[lop+1]:
        cnt += 2
        S.pop(lop+1)
        S.pop(lop)
        fg = False
        if not lop == 0:
            lop -= 1
    else:
        lop += 1
    
    
    if lop == len(S)-1:
        if fg == True:
            break
        else:
            lop = 0
            fg = True

print(cnt)


Measured memory_bytes: 3956
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0

# 負数の数(nc)、0の数(zc)、正数の数(pc)を数える
for i in range(n):
 if arr[i]<0:
   nc+=1
 elif arr[i]==0:
   zc+=1
 else:
   pc+=1

# 積が負となるペアの個数を求める
ncc=nc*pc
# 積が0となるペアの個数を求める
zcc=zc*(nc+pc)+(zc*(zc-1))//2
# 積が正となるペアの個数を求める
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2

# K番目の値が負の場合
if k <= ncc:
 arr1=[]
 arr2=[]
 # 負数、正数をそれぞれ昇順に並べる
 for i in range(n):
   if arr[i] < 0:
     arr1.append(-arr[i])
   elif arr[i] > 0:
     arr2.append(arr[i])
 arr1=arr1[::-1]
 c1=len(arr1)
 c2=len(arr2)
 l = 0         # left
 r = 10**18+1  # right 答えでもある
 # 負数のマイナスを取って計算しているため積の大小が逆転するので、大きなほうからK番目
 # 小さなほうから(積が負となるペアの個数-K)番目の値を求める
 k = ncc-k
 while r-l != 1: # rとlが1違い、すなわちrが答えとなるまで繰り返す
   mid=(l+r)//2 # 区間の中間値を更新
   cnt=0
   pos=c2-1
   # 区間[left, right)でのしゃくとり法
   # 各負数ごとに積が勝手に決めた値midよりも小さくなる正数の個数を求め足し合わせる
   for i in range(c1):
     while pos!=-1:
       if arr2[pos] > mid//arr1[i]:
         pos-=1
       else:
         break        
     cnt+=pos+1
   # 勝手に決めた値mid以下の個数が(積が負となるペアの個数-K)個以上であれば真の値はmid以下
   if cnt > k:
     r = mid  # rightをmidに更新してやり直し
   # そうでなければ真の値はmid以上
   else:
     l = mid  # leftをmidに更新してカウントやり直し
 # 負数のマイナスを取って計算したので最後にマイナスを付けて出力する
 print(-r)

# K番目の値が0の場合
elif k <= (ncc+zcc):
 print(0)

# K番目の値が正の場合
else:
 arr1=[]
 arr2=[]
 for i in range(n): #負数、正数をそれぞれ昇順に並べる
   if arr[i] < 0:
     arr1.append(-arr[i])
   elif arr[i] > 0:
     arr2.append(arr[i])
 arr1=arr1[::-1]
 c1=len(arr1)
 c2=len(arr2)
 l=0
 r=10**18+1
 k -= (ncc+zcc) #正数の中で小さい順にK番目の数を調べたいので負数、0の数を取り除く
 while r-l != 1:
   mid=(l+r)//2
   cnt1=0
   pos1=c1-1
   # 各負数ごとに積が勝手に決めた値midよりも小さくなる負数の個数を求め足し合わせる(しゃくとり法)
   for i in range(c1):
     tmp=0
     while pos1 != -1:
       if arr1[pos1] > mid//arr1[i]:
         pos1-=1
       else:
         break
     tmp+=pos1+1
     # 各要素について、自身を2回選んだ場合の積が勝手に決めた値mid以下なら条件を満たすペアの個数を1減らす
     if arr1[i]**2 < mid:
       tmp-=1
     cnt1+=tmp
   cnt1 = cnt1//2 #上記の処理では同じペアが2回数えられているので個数を半分にする
   cnt2=0
   pos2=c2-1
   # 各正数ごとに積が勝手に決めた値midよりも小さくなる正数の個数を求め足し合わせる(しゃくとり法)
   for i in range(c2):
     tmp=0
     while pos2!=-1:
       if arr2[pos2] > mid//arr2[i]:
         pos2-=1
       else:
         break
     tmp+=pos2+1
     if arr2[i]**2 < mid:
       tmp-=1 #各要素について、自身を2回選んだ場合の積が勝手に決めた値mid以下なら条件を満たすペアの個数を1減らす
     cnt2+=tmp
   cnt2=cnt2//2 #上記の処理では同じペアが2回数えられているので個数を半分にする
   cnt=cnt1+cnt2
   if cnt >= k: #勝手に決めた値mid以下の個数がK個以上であれば真の値はmid以下
     r = mid
   else: #そうでなければ真の値はmid以上
     l = mid
 print(r)

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Array a(n);
	REP(i,n) cin>>a[i];

	Graph g(n);
	REP(i,n-1){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		add_edge(g,a,b,1,true,1);
	}

	auto dfs=[&](auto &&self,int v, int p)->P{
		//cout<<v<<en;
		ll sum=0;
		if(p!=-1 && g[v].size()==1) return {true,a[v]};
		ll con=0;
		for(auto e:g[v]){
			if(e.to==p) continue;
			P ret = self(self, e.to, v);
			if(ret.first==false || ret.second>a[v]) return {false,0};
			sum += ret.second;
			con++;
		}
		ll z=a[v];
		ll x = sum-z;
		ll y = z-x;
		//cout<<v<<" "<<x<<" "<<y<<en;
		if(x<0 || y<0) return {false,0};
		if(con==1 && x>0) return {false,0};
		return {true, y};
	};
	P ans = dfs(dfs,0,-1);
	cout<<((ans.first && (g[0].size()==1||ans.second==0))?"YES":"NO")<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 14976
// ARC092
// C - 2D Plane 2N Points

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100;
const int MAX_V = MAX_N * 2 + 2;
const int INF = 1e9;

struct edge {
    int to, cap, rev;  // 行き先, 容量, 逆辺番号
};

class Graph {
public:
    void add_edge(int from, int to, int cap);
    int max_flow(int s, int t);

private:
    void bfs(int s);
    int dfs(int v, int t, int f);

private:
    vector<edge> g[MAX_V];
    int level[MAX_V];
    int iter[MAX_V];
};

void Graph::add_edge(int from, int to, int cap) {
    g[from].push_back((edge){to, cap, (int)g[to].size()});
    g[to].push_back((edge){from, 0, (int)g[from].size() - 1});
    return;
}

int Graph::max_flow(int s, int t) {
    int f;
    int flow = 0;

    while (true) {
        bfs(s);
        if (level[t] < 0) {
            break;
        }
        memset(iter, 0, sizeof(iter));
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
    return flow;
}

void Graph::bfs(int s) {
    queue<int> que;
    int v;
    int i;

    memset(level, -1, sizeof(level));
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        v = que.front();
        que.pop();
        for (i = 0; i < (int)g[v].size(); i++) {
            if (g[v][i].cap > 0 && level[g[v][i].to] < 0) {
                level[g[v][i].to] = level[v] + 1;
                que.push(g[v][i].to);
            }
        }
    }
    return;
}

int Graph::dfs(int v, int t, int f) {
    int d;

    if (v == t) {
        return f;
    }
    for (; iter[v] < (int)g[v].size(); iter[v]++) {
        edge &e = g[v][iter[v]];
        if (e.cap > 0 && level[v] < level[e.to]) {
            d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                g[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int N;
int a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N];
Graph g;

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

    int s = 2 * N;
    int t = 2 * N + 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (a[i] < c[j] && b[i] < d[j]) {
                g.add_edge(i, j + N, 1);
            }
        }
    }
    for (int i = 0; i < N; i++) {
        g.add_edge(s, i, 1);
        g.add_edge(i + N, t, 1);
    }

    int ans = g.max_flow(s, t);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
N, P = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] %= 2
A_1 = A.count(1)
A_0 = A.count(0)

import math
def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    return math.factorial(n) //(math.factorial(r) * math.factorial(n-r))


# print ('A_0, A_1 = ', A_0, A_1)
if P == 0: #2の倍数
    ans = 2 ** A_0 #偶数のものの選び方
    if A_1 >= 1:
        tmp = 0
        # A_1個の奇数から偶数個を選ぶ
        for i in range(0, A_1 + 1, 2):
            tmp += conbination(A_1, i)
        ans *= tmp
else:
    ans = 2 ** A_0 #偶数のものの選び方
    tmp = 0
    # A_1個の奇数から偶数個を選ぶ
    for i in range(1, A_1 + 1, 2):
        # print (i, end = ' ')
        tmp += conbination(A_1, i)
    ans *= tmp

print (ans)


    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
#define pb push_back
#define F first
#define S second
#define inf LLONG_MAX
#define mod 1000000007
#define PI 3.1415926536
#define vll vector <ll>
#define pll pair <ll,ll>
#define dbg(n) cout<<n<<' '
#define cu continue
#define br break
#define N 1000005
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 

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

    ll a,b,c;
    cin>>a>>b>>c;
    ll x=c-a-b;
    if(x<=0)
    {
        cout<<"No\n";
        return 0;
    }
    x*=x;
    ll y=4*a*b;
    if(y>=x)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}


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

void solve()
{
    int n,m,k,i,j,count=0,sum=0,maxi=0,mini=1e18,flag=0;
    cin>>n>>k;
    
    vector<int> a(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    for(i=1;i<=k;i++)
    {
        vector<int> freq(n+1,0);
        flag=0;
        for(j=1;j<=n;j++)
        {
            int l=max((long long)1,j-a[j]);
            int r=min(n,j+a[j]);
            freq[l]++;
            if(r+1<=n) freq[r+1]--;
        }
        for(j=2;j<=n;j++)
        {
            freq[j]+=freq[j-1];
        }
        
        for(j=1;j<=n;j++)
        {
            if(freq[j]!=n)
            {
                flag=1;
                break;
            }
        }
        
        a=freq;
        
        if(flag==0) break;
    }
    
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 6336
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h> // fabs(doubleの変数)とか
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明


// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }


// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }


//  ll my_lcm(ll a, ll b){
//  	return a*b / my_gcd(a,b);
//  }


// ll factorial(ll a){
// 	ll ans = 1;
// 	for(ll i=a; i>0; i--){
// 		ans *= i;
// 	}
// 	return ans;
// }

int main(int argc, char *argv[]){
    int N;
    double T, A;
    cin >> N >> T >> A;

    double H[N];
    double ans_T = -10000;
    int ans_i = -1;

    for(int i=0; i<N; i++){
        cin >> H[i];
        H[i] = T - H[i]*0.006;
        if(fabs(H[i] - A) < fabs(ans_T - A)){
            ans_T = H[i];
            ans_i = i;
        }
    }

    cout << ans_i + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else if(a==b){
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 2572
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt();
            var ans = Math.Pow(10, 9);
            for (int i = 0; i < A.Length; i++)
            {
                var cnt = 0;
                var num = A[i];
                while (num % 2 == 0)
                {
                    num /= 2;
                    cnt++;
                }
                if (cnt < ans) ans = cnt;
                if (ans == 0) break;
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e5+5;
const ll MOD=1e9+7;

int n, cnt[N][64];
ll a[N], pow2[N], res;

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for (int i=1; i<=n; ++i) cin>>a[i];
    for (int i=n; i>=1; --i) {
        for (int j=0; j<60; ++j) {
            cnt[i][j]=cnt[i+1][j];
            if (a[i]&(1LL<<j)) ++cnt[i][j];
        }
    }

    for (int i=1; i<n; ++i) {
        for (int j=0; j<60; ++j) {
            if (a[i]&(1LL<<j)) {
                (res+=((1LL<<j)%MOD)*(n-i-cnt[i+1][j]))%=MOD;
            } else {
                (res+=((1LL<<j)%MOD)*(cnt[i+1][j]))%=MOD;
            }
        }
    }

    cout<<res;
    return 0;
}

Measured memory_bytes: 77952
import itertools
A = list(itertools.chain.from_iterable([input().split() for _ in range(3)]))
N = int(input())
B = [input() for _ in range(N)]

for i in range(9):
    if A[i] in B:
        A[i] = "Bingo"

if A[0] == A[1] == A[2]:
    print("Yes")
elif A[3] == A[4] == A[5]:
    print("Yes")
elif A[6] == A[7] == A[8]:
    print("Yes")
elif A[0] == A[3] == A[6]:
    print("Yes")
elif A[1] == A[4] == A[7]:
    print("Yes")
elif A[2] == A[5] == A[8]:
    print("Yes")
elif A[0] == A[4] == A[8]:
    print("Yes")
elif A[2] == A[4] == A[6]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int w, h, i, j, c, x, y;
  char tiles[102][102];
  while(scanf("%d%d", &h, &w) && w && h){
    for(i = 0;i < h;i++)
      scanf("%s", tiles[i]);
    y = x = 0; c = w * h + 1;
    while(c > 0){
      switch(tiles[y][x]){
      case '>': x++; break;
      case '<': x--; break;
      case '^': y--; break;
      case 'v': y++; break;
      case '.': c = 0; break;
      }
      c--;
    }
    printf(c == 0 ? "LOOP\n" : "%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if (N % 1000 % 111 == 0) {
    cout << "Yes" << endl;
  } else if (N / 10 % 111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl; 
  } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int k;
	string s;
	cin >> k >> s;
	if (k >= sz(s)) cout << s << '\n';
	else
	{
		rep(i, k) cout << s[i];
		cout << "..." << endl;
	}


	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin>>B.at(i);
  }
  int ans=B.at(0)+B.at(N-2);
  for(int i=1;i<N-1;i++){
    ans=ans+min(B.at(i-1),B.at(i));
    }
  cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main(void)
{
  int n,i,j,k;
  int tmp,max;
  int *a;
  while(1){
    scanf("%d",&n);
    if(n==0)
      break;
    a=malloc(sizeof(int)*n);
    for(i=0;i<n;i++)
      scanf("%d",&a[i]);
    //for(i=0;i<n;i++)
      //  printf("a[%d]=%ld\n",i,a[i]);
    max=a[0];
    tmp=0;
    for(i=0;i<n;i++){
      for(j=i;j<n;j++){  
	  tmp+=a[j];
  
	  //printf("tmp=%ld\n",tmp);
	  if(tmp>max)
	    max=tmp;
      }
      tmp=0;
    } 
   
    printf("%d\n",max);
    free(a);
  }

  return 0;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i,n) cin >>a[i];
	
	rep(i,n) {
		if(a[i] %4==0) b[i] |=2;
		else if(a[i] %2==0) b[i] |=1;
	}
	//for(auto x :b) printf("%d, ",x); puts("");
	int ct[4]={};
	rep(i,n) ct[b[i]]++;
	//for(auto x :ct) printf("%d, ",x); puts("");
	
	//int sa = ct[0] - (ct[1]/2 + ct[2]);
	//cout <<"sa=" <<sa <<"\n";
	if(ct[1] > 0) ct[0]++;
	//if(ct[1] >1) ct[2]++;
	if(ct[0]   <= ct[2] + 1) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int A[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int saidai = 1;
	rep(i, N) {
		A[i] = getint();
		if (A[i] > saidai) saidai = A[i];
	}
	nth_element(A, A + N / 2, A + N);

	if (N % 2) {
		ll kotae = -A[N / 2] - saidai;
		for (int i = N / 2; i < N; i++) {
			kotae += 2 * A[i];
		}
		printf("%lld\n", kotae);
	}
	else {
		ll kotae = - saidai;
		for (int i = N / 2; i < N; i++) {
			kotae += 2 * A[i];
		}
		printf("%lld\n", kotae);
	}


	Would you please return 0;
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        string s;
        s = to_string(i);
        int n = s.size();
        int cnt = 0;
        rep(j,n)cnt+= s[j]-'0';
        if(cnt >= a && cnt <= b)ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n;
 //cin>>t;
 while(t--)
 {cin>>n;
  vll v(n);
  rep(i,0,n){
    cin>>v[i];
  }
  map<ll,int> m;
  rep(i,0,n){
    ll b=i+v[i];
    m[b]++;
  }
  ll ans=0;
  rep(i,0,n){
    ll b=i-v[i];
    ans+=m[b];
  }
  cout<<ans<<endl;
 }
 return 0;
}


Measured memory_bytes: 27372
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main(int argc, char **argv)
{
  (void)argv; debug = argc;

  int h, w;
  string s;
  cin >> h >> w;

  rep (y, 0, h) {
    rep (x, 0, w) {
      cin >> s;

      if (s == "snuke") {
        cout << (char)('A' + x) << 1 + y << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int num = 0;

	for (int i = 0; i < N - 1; i++) {
		int min_idx = i;
		int min = a[i];
		for (int j = i; j < N; j++) {

			if (min > a[j]) {
				min_idx = j;
				min = a[j];
			}

			}
		if (i < min_idx) {
			int tmp;
			tmp = a[i];
			a[i] = a[min_idx];
			a[min_idx] = tmp;
			num++;
		}
	}
	for (int i = 0; i < N - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[N - 1] << endl;
	cout << num << endl;
}

Measured memory_bytes: 1196
#include<stdio.h>


int main(){
	long long N;
	scanf("%lld",&N);
	long long a[N],b[N];
	long long a_sum=0,b_sum=0,ap=0,bp=0;
	for(long long i=0;i<N;i++){
		scanf("%lld",&a[i]);
		a_sum+=a[i];
	}
	for(long long i=0;i<N;i++){
		scanf("%lld",&b[i]);
		b_sum+=b[i];
	}
	long long dif=b_sum-a_sum;
	for(long long i=0;i<N;i++){
		if(a[i]>=b[i])bp+=a[i]-b[i];
		else ap+=(b[i]-a[i]+1)/2;
	}
	if(ap<=dif && bp<=dif)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N;
	in(N);
	auto p = mv(N);
	in(p);
	auto q = mv(N);
	in(q);
	int P = -1,Q = -1;
	REP(i,N){
		--p[i];
		--q[i];
	}
	int cnt = 0;
	auto a = mv(N);
	iota(ALL(a),0);
	do{
		if(a == q)Q = cnt;
		if(a == p)P = cnt;
		cnt++;
	}while(next_permutation(ALL(a)));
	out(abs(P-Q));
}

Measured memory_bytes: 768
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [usize; n]);

    let mut step = 0;
    let mut now = a[0];
    for v in &a {
        if now <= *v {
            now = *v;
            continue;
        }

        let buff = now - v;
        step += buff;
    }

    println!("{}", step);
}


Measured memory_bytes: 5596
n=str(input())
l = len(n)

n1 = int((l - 1) / 2) 
n2 = int((l + 3) / 2) - 1

s1 = n[0:n1]
s2 = n[n2:]

if n == n[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int n,k,ans = 1;
    cin >> n >> k;

    for(int i = 0;i < n;i++){
        if(ans+k < ans*2)ans += k;
        else ans *= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int a,v,b,w,t;
  cin>>a>>v;
  cin>>b>>w;
  cin>>t;
  if(b<a){
  	if(b-w*t>=a-v*t){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
    return 0;
  }
	if(b+w*t<=a+v*t){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int sai[100000][6];
int x[100000];
int main(){
    int y[6];
    string S;
    cin>>y[0]>>y[1]>>y[2]>>y[3]>>y[4]>>y[5];
    cin>>S;
    for(int i=0;i<S.size();i++){
        if(S[i]=='N'){
            x[i+1]=0;
        }
        if(S[i]=='E'){
            x[i+1]=1;
        }
        if(S[i]=='S'){
            x[i+1]=2;
        }
        if(S[i]=='W'){
            x[i+1]=3;
        }
    }
    for(int i=0;i<6;i++){
        sai[0][i]=y[i];
    }
    for(int i=1;i<=S.size();i++){
        if(x[i]==2){
            sai[i][0]=sai[i-1][4];
            sai[i][1]=sai[i-1][0];
            sai[i][2]=sai[i-1][2];
            sai[i][3]=sai[i-1][3];
            sai[i][4]=sai[i-1][5];
            sai[i][5]=sai[i-1][1];
        }
        if(x[i]==3){
            sai[i][0]=sai[i-1][2];
            sai[i][1]=sai[i-1][1];
            sai[i][2]=sai[i-1][5];
            sai[i][3]=sai[i-1][0];
            sai[i][4]=sai[i-1][4];
            sai[i][5]=sai[i-1][3];
        }
        if(x[i]==0){
            sai[i][0]=sai[i-1][1];
            sai[i][1]=sai[i-1][5];
            sai[i][2]=sai[i-1][2];
            sai[i][3]=sai[i-1][3];
            sai[i][4]=sai[i-1][0];
            sai[i][5]=sai[i-1][4];
        }
        if(x[i]==1){
            sai[i][0]=sai[i-1][3];
            sai[i][1]=sai[i-1][1];
            sai[i][2]=sai[i-1][0];
            sai[i][3]=sai[i-1][5];
            sai[i][4]=sai[i-1][4];
            sai[i][5]=sai[i-1][2];
        }
    }
    cout<<sai[S.size()][0]<<endl;
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
 
using namespace std;
 
vector<pair<int, int>> graph[21];
 
int main()
{
	int L;
	cin >> L;
	int l = 0;
	for(; (1 << l) <= L; l++);
	l--;
	int N = l + 1;
	for(int i = 1; i < N; i++)
	{
		graph[i].push_back({i + 1, 0});
		graph[i].push_back({i + 1, (1 << (i - 1))});
	}	
	L -= (1 << l);
	int sum = (1 << l);
	while(L > 0)
	{
		l = 0;
		for(; (1 << l) <= L; l++);
		l--;
		graph[l + 1].push_back({N, sum});
		sum += (1 << l);
		L -= (1 << l);
	}
	int e = 0;
	for(int i = 1; i <= N; i++)
	{
		e += graph[i].size();
	}	
	cout << N << " " << e << endl;
	for(int i = 1; i <= N; i++)
	{
		for(auto &edge : graph[i])
		{
			cout << i << " " << edge.first << " " << edge.second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]) {


        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        long val=7%k;
        for(int i=1;i<=1e7;i++)
        {
            if(val%k==0)
            {
                System.out.print(i);
                return;
            }
            //System.out.print(val+" ");
            val=(val*10+7)%k;
            
            
            

        }
        System.out.print("-1");
        return;




    }
}

Measured memory_bytes: 35664
# 入力を受け取る
input_line = input()

# 入力データを分割する
input_list = input_line.split()
W = int(input_list[0])
H = int(input_list[1])
x = int(input_list[2])
y = int(input_list[3])
r = int(input_list[4])

flag = 0

if H >= y + r and y - r >= 0:
    flag+=1
if W >= x + r and x - r >= 0:
    flag+=1
if flag ==2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596