akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int a[200000], b[200000];
int main() {
	int n;
	scanf("%d", &n);
	fup(i, 0, n - 1, 1)
	{
		scanf("%d", a + i);
		b[i] = a[i];
	}
	sort(b, b + n);
	int t1 = b[n / 2 - 1], t2 = b[n / 2];
	if (t1 == t2) while (n--)printf("%d\n", t1);
	else
	{
		fup(i, 0, n - 1, 1)
			if (a[i] <= t1)printf("%d\n", t2);
			else printf("%d\n", t1);
	}
}

Measured memory_bytes: 3712
#include<stdio.h>

int main()
{
	int a,b,c;
	int flag=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			flag++;
		}
	}
	if(flag==1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2112
n = int(input())
t = []
a = []

for i in range(0, n):
    ti, ai = [int(_) for _ in input().split()]
    t.append(ti)
    a.append(ai)

newest_t = t[0]
newest_a = a[0]

for i in range(0, n):
    div_t = newest_t // t[i]
    div_a = newest_a // a[i]

    for j in range(max(div_t, div_a)-1, max(div_t, div_a)+2):
        if j * t[i] >= newest_t and j * a[i] >= newest_a:
            newest_t = j * t[i]
            newest_a = j * a[i]
            break

print(newest_t + newest_a)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int n;
	while (scanf("%d", &n), n) {
		int b = 0, r = 1, c = 0;
		while (n) {
			c += (n%5) * b;
			n /= 5;
			b += r;
			r *= 5;
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define nn 1000008
#define mod 998244353
vector<int> fact[nn];int pos[nn];
int ans[nn];long long  output;
int ele[nn];int n;

void add(int &x,int y){
	x=(x+y)%mod;
}

long long qpow(long long  x,int y=mod-2){
	long long res=1;
	while(y){
		if(y&1) res=res*x%mod;x=x*x%mod;y=y/2;
	}
	return res;
}
int main(){
	for(int i=1;i<nn;i++) for(int j=i;j<nn;j+=i) fact[j].push_back(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&ele[i]);output-=ele[i];
		for(int j=0;j<fact[ele[i]].size();j++) add(pos[fact[ele[i]][j]],ele[i]);
	}
	for(int i=0;i<nn;i++) pos[i]=1ll*pos[i]*pos[i]%mod;
	
	for(int i=nn-1;i>=1;i--) if(pos[i]){
		for(int j=0;j<fact[i].size();j++){
			int k=fact[i][j];
			if(k!=i)pos[k]-=pos[i];
			if(pos[k]<0) pos[k]+=mod;
		}
	//	cout<<i<<" "<<pos[i]<<"\n";
		output=(output+1ll*pos[i]*qpow(i))%mod;
	}
	
	printf("%lld\n",(output%mod+mod)*qpow(2)%mod);
	return 0;
}

Measured memory_bytes: 123136
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;


 void test_cases()
{

	ll a,b;
	char op;
	
	cin>>a>>op>>b;
	if(op=='+')cout<<a+b;
	else cout<<a-b;
}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


Measured memory_bytes: 3576
#include <iostream>

using namespace std;


int main()
{
    int N,A,B,a,b,p,q,sum;
    cin>>N >>A>>B;
    for(a = 1; a<=N; a++){
        b = a;
        q = 0;
        while(b>0){
            p = b % 10;
            q += p;
            b /= 10;
        }

        if (A <= q && q <= B){
            sum += a;
        }
    }
    
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 888
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
//unordered_map
typedef long long ll;
//已AC 尝试去并查集 典型的权值并查集 再写一遍巩固并理解 
int fa[MAXN],sum[MAXN];
int Find(int x)
{
	return fa[x]==x ? x : fa[x]=Find(fa[x]);
}
int main()
{
	int n,m,ans=0;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) fa[i]=i,sum[i]=1;
	while(m--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		int x=Find(a),y=Find(b);
		if(x!=y)
		{
			fa[x]=y;
			sum[y]+=sum[x];
		}
	}
	for(int i=1;i<=n;i++) ans=max(ans,sum[i]);
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 5276
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

use std::collections::BinaryHeap;

fn main() {
    let n:usize;
    input!(n);
    let mut v=Vec::new();
    let mut hp=BinaryHeap::new();
    for z in 0..n{
        let buf:usize;
        input!(buf);
        v.push(buf);
        hp.push(buf);
    }
    for z in v{
        if *hp.peek().unwrap()!=z{
            p(*hp.peek().unwrap());
        }else{
            hp.pop();
            p(*hp.peek().unwrap());
            hp.push(z);
        }
    }

}

Measured memory_bytes: 11144
#include<stdio.h>

int main(){

   int H,W;
   int i,j;

   scanf("%d %d", &H, &W);

   while(H!=0 || W!=0){
      for(i=0;i<H;i++){
         for(j=0;j<W;j++){
            if(i%2 == 0){
               if(j%2 == 0) printf("#");
               else printf(".");
            }else{
               if(j%2 == 0) printf(".");
               else printf("#");
            }
         }
         printf("\n");
      }
      printf("\n");
      scanf("%d %d", &H, &W);
   }

   return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	rep(i,1000){
		string t;
		t[0] = i/100;
		t[1] = (i%100)/10;
		t[2] = i%10;
		int k = 0;
		rep(j,s.size()){
			if(s[j] - '0' == t[k]){
				k++;
			}
			if(k == 3){
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
    return 0;
}



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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        k:i64,
        x:i64,
    }
    let diff = k -1;
    let ans:Vec<i64> = (x-diff..x+diff+1).collect();
    for i in 0..ans.len() {
        print!("{}",ans[i]);
        if i != ans.len()-1 {
            print!(" ");
        }
    }
    println!("")
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i<(int)n; i++)
int main() {
  int H,W; //行、列
  cin >> H >> W;
  vector <int> hflag(H,0);
  vector <int> wflag(W,0);
  vector <vector <char>> field(H,vector <char> (W));
  //入力格納
  rep(i,H)rep(j,W) cin >> field.at(i).at(j);
  //探索
  rep(i,H){
    rep(j,W){
      if(field.at(i).at(j) == '.') {
        hflag.at(i)++;
        wflag.at(j)++;
      }
    }
  }
  //変換
  rep(i,field.size()){
    if(hflag.at(i)==W){
      rep(j,field.at(0).size()) field.at(i).at(j) = 'F';
    }
  }
  //変換２
  rep(j,field.at(0).size()){
    if(wflag.at(j)==H){
      rep(i,field.size()) field.at(i).at(j) = 'F';
    }
  }
  //表示
  rep(i,field.size()) {
    int fd = 0;
    rep(j,field.at(0).size()) {
      if(field.at(i).at(j) != 'F'){
        cout << field.at(i).at(j);
        fd = 1;
      }
    }
    if(fd != 1) continue;
    cout << endl;
  } 
}


Measured memory_bytes: 256
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
    	long N=0,ans=0;
		char A[1000]={},B[1000]={},C[1000]={};
		long a[1000]={};

		cin >> A;
		cin >> B;
		cin >> C;

		if(A[strlen(A)-1]==B[0] && B[strlen(B)-1]==C[0]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}


    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <functional>

using namespace std;

int N,a[109];
int main() {
  cin >> N;
  
  for (int i=0; i<N; i++) cin >> a[i];
  sort(a,a+N);
  reverse(a,a+N);
  
  int A=0, B=0;
  for (int i=0; i<N; i++) {
    if (i %2 ==0) {
      A += a[i];
    } else {
        B+= a[i];
      }
  }
  
  cout << A-B << endl;
  return 0;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    ll XOR = 0;
    for (int i = 0; i < N; ++i) XOR = XOR ^ A[i];

    for (int i = 0; i < N; ++i) cout << (XOR ^ A[i]) << " ";
    cout << endl;
}


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

int main() {
	string s, t;
	cin >> s >> t;
    int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == t[i]) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
    long N,A[5]={0};
    string S;
 
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> S;
        if(S[0] == 'M'){
            A[0]++;
        }else if(S[0] == 'A'){
            A[1]++;
        }else if(S[0] == 'R'){
            A[2]++;
        }else if(S[0] == 'C'){
            A[3]++;
        }else if(S[0] == 'H'){
            A[4]++;
        }
    }
    long ans=0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += A[i] * A[j] * A[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		

		int second = scan.nextInt();

		int h = second / 3600;
		int m = (second % 3600) / 60;
		int s = ((second % 3600) % 60);
		
		System.out.println(h + ":" + m + ":" + s);
		
		scan.close();

	}

}

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

/*数値のとりうる範囲から、while処理はよくない*/
/*町の間隔がすべて等しいこと、すべての都市に必ずN人はやってくること、それら全員に対して交通機関で対応することに注目*/

/*切り上げ関数*/
uint64_t round_up(uint64_t n, uint64_t x){
  if(n % x == 0)
    return n/x;
  else
    return n/x + 1;
}

int main(){
  uint64_t  N, A, B, C, D, E, mi, time;
  
  cin >> N >> A >> B >> C >> D >> E;
  mi = min(A, min(B, min(C, min(D, E))));    //A～Eの最小値を取得

  /*4は、運搬全工程を通して運搬人数が最小の交通機関を持つ町に滞在していない総時間
      切り上げるのは、最後の運搬の際に、運搬可能人数以下の運搬も回数に含めるため*/
  time = round_up(N, mi) + 4;                         
  cout << time << endl;
  
}




Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int a, b, tmp, result;
    while (1) {
        result = 0;
        if (scanf("%d %d", &a, &b) == EOF) {
            break;
        }
        else {
            tmp = a + b;
            while(tmp != 0){
                tmp = tmp / 10;
                result++;
            }
            printf("%d\n", result);
        }
    }
    return 0;
}

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

typedef long long int lli;
typedef long int li;


int main(){
    ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long double a, b;
    cin >> a >> b;
    cout << (long long) floor(a * b) << '\n';
}	

/*
	check for corner cases.
	When using log check for zeros.
	Use queues and stacks if they are helping.           
                            
    (___)           
    . . )____________ 
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )     
          < |     ||  
*/



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n;
cin>>n;
map<char,int>m[n];
string S[n];
rep(i,n){
  cin>>S[i];
  rep(j,S[i].size()){
    m[i][S[i][j]]++;
  }
}
vector<char> ans;
for(char i='a';i<='z';i++){
    int count=m[0][i];
for(int k=1;k<n;k++){
count=min(count,m[k][i]);
}
if(count){
  for(int q=0;q<count;q++){
    ans.push_back(i);
  }
}
}
rep(i,ans.size()){
  cout<<ans[i];
}

  return 0;
}


Measured memory_bytes: 256
#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()

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

    // start
    int n, k;
    cin >> n >> k;
    cout << (k == 1 ? 0 : n - k) << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vll a(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    sort(ALL(a));
    vll acca(n + 1, 0);
    for (int i = 0; i < n; i++) acca[i + 1] = acca[i] + a[i];

    ll low = 0, high = HIGHINF;
    while (low < high) {
        ll mid = (low + high) >> 1;
        ll tmpm = 0;
        for (int i = 0; i < n; i++) {
            auto it = lower_bound(ALL(a), mid - a[i]);
            tmpm += n - (ll)(it - a.begin());
            if (tmpm >= m) break;
        }
        if (tmpm < m) high = mid;
        else low = mid + 1;
    }
    low--;

    ll ans = 0, tmpm = 0;
    for (int i = 0; i < n; i++) {
        auto it = lower_bound(ALL(a), low - a[i] + 1);
        ll sz = it - a.begin();
        ans += a[i] * (n - sz);
        ans += acca[n] - acca[sz];
        tmpm += n - sz;
    }
    cout << ans + low * max(0LL, (m - tmpm)) << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,min,max=-1000000000;
    scanf("%d",&n);
    int R[n];
    scanf("%d",&R[0]);
    min = R[0];
    for(int i=1;i<n;i++)
    {
        scanf("%d",&R[i]);
        (R[i]-min)<max ? (max = max) : (max = R[i]-min);
        (R[i])<min ? (min = R[i]) : (min = min);
    }
    printf("%d\n",max);
    return 0;
}


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

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

    string target = "keyence";
    int target_size = (int)target.size();

    for(int k=0; k<(int)S.size(); k++){
        for(int j=k; j<S.size(); j++){
            string s1 = S.substr(0,k);
            string s2 = S.substr(j,S.size()-j);
            if(s1+s2 == target){
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
    
}

Measured memory_bytes: 3628
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();

        switch (s)
        {
            case "A":
                Console.WriteLine("T");
                break;
            case "T":
                Console.WriteLine("A");
                break;
            case "G":
                Console.WriteLine("C");
                break;
            case "C":
                Console.WriteLine("G");
                break;
            default:
                break;
        }

    }
}


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

int main () {
    int r, g, b;
    cin >> r >> g >> b;

    int x;
    x = r * 100 + g * 10 + b;
    
    if (x % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {    
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A, B, ans;
		A = in.nextInt();
		B = in.nextInt();
		
		if (B%A == 0) ans = A+B;
		else ans = B -A;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21332
#include<stdio.h>
int main(void){
int i,j,H,W;
while(1){
scanf("%d %d",&H ,&W);
if (H == 0 && W == 0)break;
for(i=1;i <= H;i++){
for(j=1;j <= W;j++){
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
n = int(input())
m = [0]*100

for i in range(1,n+1):
    if str(i)[-1] != "0":
        m[((int(str(i)[0])) * 10)+(int(str(i)[-1]))] += 1

res = sum([m[i]*m[int(str(i)[::-1])] for i in range(100)])

print(res)

Measured memory_bytes: 3060
S = input()

max_len = 0
memo_len = 0
flag = True

for i in range(len(S)):
    if S[i]=="A" or S[i]=="T" or S[i]=="G" or S[i]=="C":
        if flag == True:
            memo_len += 1
        else:
            memo_len = 1
            flag = True
    else:
        if max_len < memo_len:
            max_len = memo_len
        flag = False
        
if max_len < memo_len:
    max_len = memo_len
print(max_len)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,k; cin >> n >> k;
	vl a(n), f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(all(a)); sort(rall(f));
	ll ok = 1e12, ng = -1;
	while(ok-ng>1){
		ll mid = (ok+ng)/2;
		ll cnt = 0;
		rep(i,n){
			ll t = mid / f[i];
			cnt += max(0LL,a[i]-t);
		}
		if(cnt > k) ng = mid;
		else ok = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=2009;

int n,sum,a[N];
bitset<N*N> bit;

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		sum+=(a[i]=read());
	bit[0]=1;
	for(int i=1;i<=n;i++)
		bit|=bit<<a[i];
	for(int i=ceil((double)sum/2.0);;i++)
		if(bit[i])
			return printf("%d\n",i),0;
	return 0;
}


Measured memory_bytes: 1792
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); while( _t-- )
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

string str;
ll n, k, a, b;
ll ara[106];

start;

    cin2(n, k);
    if(n&k==0) coul("0");
    else if(n>k){
        a = n%k;
        if(a > k-a)
            a = k- a;
            coul(a);
    }
     else{
         if(k-n < n)
            n = k-n;
        coul(n);
    }
        //coul(gcd(n, k));


finish



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

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

    bool f;
    if(s[0] == s[2]) f = true;
    else f = false;
    cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,a[3010],ans=0;cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
        a[i]--;
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = tuple(map(int, input().split()))
x, y = 0, abs(h[0]-h[1])
for i in range(2, n):
    d1 = x+abs(h[i-2]-h[i])
    d2 = y+abs(h[i-1]-h[i])
    x, y = y, d1 if d1 < d2 else d2
print(y)

Measured memory_bytes: 14108
#include<cstdio>

using namespace std;

int main(){
    int n,m;
    scanf("%d %d", &n, &m);
    int t;
    t = (1900 * m) + (100 * (n - m));
    int ans = 1;
    for(int i = 0; i < m; i++) ans *= 2;
    ans *= t;
    printf("%d\n", ans);
    
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  int cnt = 0;
  REP(i,n){
    int a;
    cin >> a;
    if(d%a==0){
      cnt += d/a;
    }else{
      cnt += d/a+1;
    }
  }
  cout << cnt + x << 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[] a = new int[2];
		int[] b = new int[2];
		boolean act = true;
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		b[0] = sc.nextInt();
		b[1] = sc.nextInt();
		while (a[0] > 0 && b[0] > 0) {
			if (act) {
				b[0] -= a[1];
				act = !act;
			} else {
				a[0] -= b[1];
				act = !act;
			}
		}
		if (b[0] <= 0) {
			System.out.println("Yes");
		} else if (a[0] <= 0) {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35764
from collections import deque


def bfs(sx, sy, gx, gy):
    que = deque()
    que.append([sx, sy])
    d[sx][sy] = 0
    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            return d[gx][gy]
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and s[nx][ny] != "#" and d[nx][ny] == -1):
                que.append([nx, ny])
                d[nx][ny] = d[p[0]][p[1]] + 1
    return -1


H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
d = [[-1] * W for _ in range(H)]
b = 0

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            b += 1
l = bfs(0, 0, H - 1, W - 1)
if l < 0:
    print(l)
else:
    print(H*W - b-l-1)


Measured memory_bytes: 40560
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt= 0;
int A[1000000];
int N;
vector<int> G;

void insertionSort(int A[],int N,int g){
	for(int i = g;i<N;i++){
		int v = A[i];
		int j = i-g;
		while(j >=0&&A[j]>v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	} 
} 

void shellsort(int A[],int N){
	for(int h = 1;;){
		if(h>N) break;
		G.push_back(h);
		h = 3*h+1;
	}
	for(int j = G.size()-1;j>=0;j--)
	{
		insertionSort(A,N,G[j]);
	}
}

int main(){
	scanf("%d",&N);
	for(int i = 0; i<N;i++){
		scanf("%d",&A[i]);
	}
	shellsort(A,N);
	printf("%d\n",G.size());
	for(int i = G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i) printf(" ");
	}
	printf("\n%d\n",cnt);
	for(int i = 0; i<N;i++){
		if(i) printf("\n");
		printf("%d",A[i]);
	}
	return 0;
	 
}


Measured memory_bytes: 7080
#include<iostream>
 #include<algorithm>
 using namespace std;
 #define N 100010
 int main(){
 int n,m,h[N],ma[N];
 cin>>n>>m;
 for(int i=1;i<=n;i++){
 cin>>h[i];
 ma[i]=0;
 }
 for(int i=0;i<m;i++){
 int a,b;
 cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
 ma[b]=max(ma[b],h[a]);
 }
 int ans=0;
 for(int i=1;i<=n;i++){
 ans+=h[i]>ma[i];
 }
 cout<<ans<<endl;
 }


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

#define all(x) x.begin(),x.end()

using namespace std;

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

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

    ll n, t;
    cin >> n >> t;
    vi shower(n);
    for (ll i = 0; i < n; i++)
        cin >> shower[i];

    ll answer = shower.back() + t;
    for (ll i = 0; i < n - 1; i++) {
        shower[i] += t;
        if (shower[i + 1] - shower[i] > 0)
            answer -= shower[i + 1] - shower[i];
    }
    cout << answer << '\n';

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll res[202];

int main()
{
    ll n,i,j;
    cin>>n;
    for(i=1;i<201;i++)
    {
        res[i]=i*i*i*i*i;
    }
    for(i=0;i<201;i++)
    {
        for(j=0;j<201;j++)
        {
            if(abs(n-res[i])==res[j])
            {
                if(res[i]<n)printf("%lld %lld\n",i,j*(-1));
                else printf("%lld %lld\n",i,j);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3604
k, n = list(map(int,input().split()))
a = list(map(int,input().split()))

inter = 0


for i in range(n-1):
    inter = max(inter, a[i+1]-a[i])
    if inter == int(k/2):
        break

inter = max(inter, a[0]+k-a[n-1])

print(k-inter)

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

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;


int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>b&&b>c)cout<<b+c+pow(2,k)*a<<endl;
  else if(b>a&&b>c)cout<<a+c+pow(2,k)*b<<endl;
  else cout<<b+a+pow(2,k)*c<<endl;

}


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

using namespace std;

long long _();
int main() { _(); return 0; }
#define main _
#define int long long 

const int N = 2e3;

int n, x, y;
int ans[N];
int d[N];

void count(int ind) {
    queue<pair<int, int>> q;
    q.push({ind, 0});
    while(!q.empty()) {
        auto w = q.front();
        q.pop();
        int a = w.first, b = w.second;
        if(d[a])
            continue;
        d[a] = b;
        if(a < n)
            q.push({a+1, b+1});
        if(a > 0)
            q.push({a-1, b+1});
        if(a == x)
            q.push({y, b+1});
        if(a == y)
            q.push({x, b+1});
    }
    for(int i=0; i<n; i++)
        if(i != ind)
            ans[d[i]]++;
}
    
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> x >> y;
    x--; y--;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++)
            d[j] = 0;
        count(i);
    }
    for(int i=1; i<n; i++)
        cout << ans[i]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int a,b;
    cin >> a >> b;
    cout << (((a*b)%2==0)?"Even":"Odd") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  
  char b, enki;
  
  scanf("%c", &b);
  
  if(b == 'A'){
    enki = 'T';
    printf("%c\n", enki);
  }
  
  if(b == 'T'){
    enki = 'A';
    printf("%c\n", enki);
  }
  
  if(b == 'G'){
    enki = 'C';
    printf("%c\n", enki);
  }
  
  if(b == 'C'){
    enki = 'G';
    printf("%c\n", enki);
  }
  

  return 0;
}
  
  

Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,a = map(int, input().split())
    x = list(map(int, input().split()))
    for i in range(n):
        x[i] -= a
    dp = [[0]*5001 for _ in range(n+1)]

    dp[0][0] = 1

    for i in range(1, n+1):
        for j in range(-2500, 2501):
            dp[i][j] += dp[i-1][j]
            if -2500 <= j-x[i-1] <= 2500:
                dp[i][j] += dp[i-1][j-x[i-1]]
    print(dp[-1][0]-1)

if __name__ == '__main__':
    main()

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

int main(){
    string s; cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size()/2; i++){
        if(s[i] != s[s.size() - i - 1]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
  int r,d,x;
  cin >> r >> d >> x;
  vector<int> X(11);
  X.at(0) = r*x-d;
  for(int i=0;i<10;i++){
    X.at(i+1)=r*(X.at(i))-d;
  }
  for(int j=0;j<10;j++)
  {
    cout << X.at(j) << endl;
  }
  
}

Measured memory_bytes: 256
use std::*;

fn main() {
    let _ : usize = read();
    let a: Vec<i64> = read_vec();
    let Mod = 1e9 as i64 + 7;
    let mut s = a.iter().sum::<i64>() % Mod;
    let mut ans = 0i64;
    for x in a {
        s = (s + Mod - x) % Mod;
        ans = (ans + s * x % Mod) % Mod;
        
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: str::FromStr>() -> T {
    let mut _in = String::new();
    io::stdin().read_line(&mut _in).ok();
    _in.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: str::FromStr>() -> Vec<T> {
    read::<String>().split(' ').map(|w| w.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 6540
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        if(y==(i*2+(x-i)*4)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var S, T string
	var A, B int
	var U string
	fmt.Scan(&S, &T)
	fmt.Scan(&A, &B)
	fmt.Scan(&U)
	if S == U {
		fmt.Println(A-1, B)
	} else {
		fmt.Println(A, B-1)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    int start = 1;
    int cnt = 0;
    while (start < b) {
        start += a - 1;
        cnt ++;
    }
    cout << cnt;
    
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
c = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        t = A[i]
        A[i] = A[minj]
        A[minj] = t
        c += 1
	
print(" ".join(map(str,A)))
print(c)

Measured memory_bytes: 7644
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC119B
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var ans = 0m;

            for (var i = 0; i < N; i++)
            {
                var X = ss.Next(decimal.Parse);
                var U = ss.Next();

                if (U == "BTC") X *= 380000;
                ans += X;
            }

            sw.WriteLine(ans);
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = { ' ' };
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 11220
import sys
sys.setrecursionlimit(10**8)
n, m = map(int, input().split())

graph = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b - 1].append(a - 1)

memo = [0 for i in range(n)]
color = [-1 for i in range(n)]
black = 0
white = 0
flag = 0


def search(v):
    for i in graph[v]:
        if memo[i] == 0:
            memo[i] = 1
            color[i] = (color[v] + 1) % 2
            if color[i] == 0:
                global black
                black += 1
            else:
                global white
                white += 1
            search(i)
        else:
            if color[v] == color[i]:
                global flag
                flag = 1

memo[0] = 1
color[0] = 0
black += 1
search(0)

if flag == 1:
    print(n*(n-1)//2 - m)
else:
    print(black * white - m)

Measured memory_bytes: 44392
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
long long int a[100005];
int main()
{
	long long int N;
	while (scanf("%lld", &N) != EOF)
	{
		memset(a, 0, sizeof(a));
		for (long long int i = 1; i <= N; i++)
			scanf("%lld", &a[i]);
		if (a[1] != 0) 
		{
			printf("0\n");
			continue;
		}
		sort(a + 1, a + N + 1);
		long long int flog = 0;
		for (long long int i = 2; i <= N; i++) 
		{
			if (abs(a[i] - a[i - 1]) != 0 && abs(a[i] - a[i - 1]) != 1) 
			{
				flog = 1;
				break;
			}
		}
		if (flog==1) 
		{
			printf("0\n");
			continue;
		}
		long long int i = 2, cnt = 1, n = 0;
		for (; a[i] == 1; i++)
			n++;
		for (; i <= N;) 
		{
			long long int d = a[i], s = 1, nn = 0;
			for (; a[i] == d && i <= N; i++) 
			{
				nn++;
				s = (s * n) % 998244353;
			}
			cnt = (cnt * s) % 998244353;
			n = nn;
		}
		printf("%lld\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = new int[n];
			double sum = 0;
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
				sum += a[i];
			}

			double avg = sum / n;
			double diff = INF;
			int idx = -1;
			for (int i = 0; i < n; i++) {
				if (Math.abs(avg - a[i]) < diff) {
					diff = Math.abs(avg - a[i]);
					idx = i;
				}
			}

			out.println(idx);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e5+5;
ll n,a[N],prfx[N],sfx[N],ans;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    cin>>n;
    for(ll i=0;i<n;i++)cin>>a[i];
    sfx[n-1]=0;
    stack<ll> stk;
    for(ll i=n-2;i>=0;i--){
        sfx[i]=sfx[i+1];
        ll nxt=a[i+1] , cur=a[i];
        while(nxt<cur){
            ll val = (stk.empty()?n-1:stk.top());
            sfx[i]+=(val-i)*2;
            if(!stk.empty())stk.pop();
            nxt*=4;
        }
        while(nxt>=cur*4)stk.push(i),cur*=4;
    }
    while(!stk.empty())stk.pop();
    prfx[0]=1;
    for(ll i=1;i<n;i++){
        prfx[i]=prfx[i-1]+1;
        ll cur=a[i],prv=a[i-1];
        while(prv<cur){
            ll val = (stk.empty()?0:stk.top());
            prfx[i]+=(i-val)*2;
            if(!stk.empty())stk.pop();
            prv*=4;
        }
        while(prv>=cur*4)stk.push(i),cur*=4;
    }
    ans=min(prfx[n-1] , sfx[0]);
    for(ll i=0;i<n-1;i++)ans=min(ans , prfx[i] + sfx[i+1]);
    cout<<ans;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<ll> a;
    vector<ll> acca;

    acca.pback(0);

    rep(i,n){
        ll tmp;
        cin >> tmp;
        a.pback(tmp);
        acca.pback(acca[i] + tmp);
    }

    ll ans = LLONG_MAX;

    //奇数項までの和を-1以下にする場合

    ll fix = 0;
    ll tmpans = 0;

    rep(i,n){
        ll tmpsum = acca[i + 1] + fix;
        if((i + 1) % 2 == 1){
            if(tmpsum > -1){
                ll tmpfix = tmpsum + 1;
                fix = fix - tmpfix;
                tmpans = tmpans + abs(tmpfix);
            }

        }else{
            if(tmpsum < 1){
                ll tmpfix = -1 * tmpsum + 1;
                fix = fix + tmpfix;
                tmpans = tmpans + abs(tmpfix);
            }

        }
    }

    ans = min(ans, tmpans);

    
    //奇数項までの和を1以上にする場合

    fix = 0;
    tmpans = 0;

    rep(i,n){
        ll tmpsum = acca[i + 1] + fix;
        if((i + 1) % 2 == 1){
            if(tmpsum < 1){
                ll tmpfix = -1 * tmpsum + 1;
                fix = fix + tmpfix;
                tmpans = tmpans + abs(tmpfix);
            }

        }else{
            

            if(tmpsum > -1){
                ll tmpfix = tmpsum + 1;
                fix = fix - tmpfix;
                tmpans = tmpans + abs(tmpfix);
            }

        }
    }

    ans = min(ans, tmpans);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2036