akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    int n4=0;
    int n2=0;
    int no=0;
    bool ans= false;
    cin>>n;
    for(int i=0;i<n;i++){
    	int a;
	cin>>a;
	if(a%4==0){
    	    n4+=1;
            }else if(a%2==0){
                n2+=1;
            }else{
                no+=1;
        }
    }
    
    if(n%2==0){	//even
	if(n4>=n/2){
		ans=true;
	}else{
		if(n4>0){
			if(no<=n4){
				ans=true;
			}else{
				ans=false;
			}
			// if(n-((2*n4)+1)>1){
			// 	if(n2>=n-((2*n4)+1)&&(no<=n4+1)){
			// 		ans=true;
			// 	}else{
			// 		ans=false;
			// 	}
			// }else if(n-((2*n4)+1)==1){
			// 	if(n2>=n-((2*n4))&&(no<=n4)){
			// 		ans=true;
			// 	}else{
			// 		ans=false;
			// 	}
			// }else{
			// 	ans= false;
			// }
		}else{
			if(n2==n){
				ans=true;
			}else{
				ans=false;
			}
		}
	}
    }else{
    	if(n4>=(n-1)/2){
		ans=true;
	}else{
		if(n4>0){
			if(no<=n4){
				ans=true;
			}else{
				ans=false;
			}
			// if(n2>=n-((2*n4)+1)&&(no<=n4+1)){
			// 	ans=true;
			// }else{
			// 	ans=false;
			// }
		}else{
			if(n2==n){
				ans=true;
			}else{
				ans=false;
			}
		}
	}
    }
    if(ans==true){
	cout<<"Yes";	
    }else{
    	cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];

 
ll n,m,ans=0;
int i,j;
ll dp[12][12];
int a,b;
bool vis[12];

void dfs(int x){
	vis[x] = true;
	int count=0;
	for(i=1;i<=n;i++){
		if(vis[i])
		count++;
	}
	if(count==n){
		ans += 1;
	}else{
		for(int i=1;i<=n;i++){
			if(dp[x][i] && !vis[i]){
				dfs(i);
			}
		}
	}
	vis[x]=false;
	return;
}


int main(){
	cin>>n>>m;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			dp[i][j]=0;
		}
	}
	for(i=0;i<m;i++){
		cin>>a>>b;
		dp[a][b]=dp[b][a]=1;
	}
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[]a = new int[n];
        for(int i = 0; i < a.length; i++) {
            a[i] = stdIn.nextInt();
        }
        for(int i = n - 1; i >= 0; i--) {
            if(i == 0) {
                System.out.print(a[i]);
            } else {
                System.out.print(a[i] + " ");
            }
        }
        System.out.println("");
    }
}


Measured memory_bytes: 26492
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	vector<int> point(N, K - Q);
	for (int i = 0; i < Q; ++i) {
		++point[a[i] - 1];
	}

	for (int i = 0; i < N; ++i) {
		if (point[i] > 0) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}

	return 0;
}


Measured memory_bytes: 1408
// ITP1_8_A:   Toggling Cases
// 2017.7.27

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	char buf[1250];
	char *p, c;

	gets(buf);
	p = buf;
	while (*p) {
		c = *p++;
		if (isupper(c)) c = tolower(c);
		else if (islower(c)) c = toupper(c);
		putchar(c);
	}
	putchar('\n');
	return 0;
}

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

int n, c = INT_MAX, d, a[101];
unordered_map<int, int> cnt;
bool valid = true;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		++cnt[a[i]];
		c = min(a[i], c);
		d = max(a[i], d);
	}
	for(int x = d; x > c; x--) valid &= cnt[x] >= 2;
	valid &= c >= d+1 >> 1;
	if(d % 2) valid &= cnt[c] == 2;
	else valid &= cnt[c] == 1;
	cout << (valid ? "Possible" : "Impossible");
}


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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll query(ll x, ll y)
{
	ll lo = 0; ll hi = ll(3e9);
	ll ans = 0;
	while(lo<=hi)
	{
		ll mid=(lo+hi)>>1; ll tmp=0;
		for(ll i=max(mid/2-50,1LL); i<=min(mid/2+50,mid); i++)
		{
			//pair i-th smallest with i-th greatest
			ll L = i;
			if(i>=x) L++;
			ll R = mid + 1 - i;
			if(i<=mid-y+1) R++;
			tmp=max(tmp,L*R);
		}
		if(tmp<x*y)
		{
			ans=mid; lo=mid+1;
		}
		else
		{
			hi=mid-1;
		}
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int q; cin>>q;
	while(q--)
	{
		ll x,y; cin>>x>>y;
		cout<<query(x,y)<<'\n';
	}
}


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

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

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int a, b, c;
    cin >> a >> b >> c;

    if(a == 5 && b == 5 && c == 7) cout << "YES" << endl;
    else if(a == 5 && b == 7 && c == 5) cout << "YES" << endl;
    else if(a == 7 && b == 5 && c == 5) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);
        int t = int.Parse(cin[2]);
        Console.WriteLine((int)(t + 0.5) / a * b);
    }
}

Measured memory_bytes: 11092
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	ll n,k,sum=0;cin>>n>>k;
	for(ll i=k;i<=n+1;i++){
		sum=(sum+(n*i%hell-(i-1)*i%hell+hell+1)%hell)%hell;
		//cout<<sum<<endl;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3644
'use strict'

const main = (input) => {
    const a = input.split(' ')[0]
    const b = input.split(' ')[1]
    const num = parseInt(a + b)
    const sqrt = Math.floor(Math.sqrt(num)) 
    if(sqrt * sqrt === num){
        console.log('Yes')
    }else{
        console.log('No')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

a=list(map(int,input().split()))

r=1000
k=0
for ii in range(n-1):
	if a[ii+1]<a[ii]:
		r+=k*a[ii]
		k=0
	else:
		dk=r//a[ii]
		r-=dk*a[ii]
		k+=dk
	#print(ii,r,k)
print(r+k*a[n-1])


Measured memory_bytes: 9176
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

const ll MAX = 1e6+7;
ll fac[MAX], finv[MAX], inv[MAX];
//初期化
void COMinit() {
    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1]  = 1;

    for(int i = 2; i < MAX; ++i){
        fac[i]  = fac[i - 1] * i % MOD;
        inv[i]  = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
//nCk
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll n, k;
    cin >> n >> k;

    COMinit();

    for(ll i = 1; i <= k; ++i){
        cout << (COM(n-k+1, i) * COM(k-1, i-1)) % MOD << endl;
    }

}

Measured memory_bytes: 27048
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

N = INT()
cnt = 0

for _ in range(N):
    D1, D2 = MI()
    
    if D1 == D2:
        cnt += 1
    else:
        cnt = 0
    
    if cnt == 3:
        print("Yes")
        exit()
    
print("No")

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

int main() {
   int N,M;
  cin >> N>>M;
  int S=0;
  int A;
  for (int i= 0; i<M;i++){ cin>>A; S+=A;}
  
  
  
  if (S>N)
cout << -1;
  else cout<<N-S;
  
}  


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b; cin >> a >> b;
  ll x = max(a,b);
  while(x%a||x%b)x+=max(a,b);
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int base(ll n){
    return to_string(n).size() - 1;
}

int main(){
    int n;  cin >> n;
    vector<ll>a(n);
    rep(i, n)   cin >> a[i];
    sort(a.begin(), a.end());
    if(!a[0]){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i, n){
        if(a[i] <= 1000000000000000000/ans){
            ans *= a[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4060
#include	<iostream>
#include	<vector>
#include	<sstream>
#include	<iomanip>
using namespace std;

void
Main() {
	int	N;	cin >> N;
	int	K;	cin >> K;
	int	Q;	cin >> Q;

	long long	A[ N ];
	long long	wSorted[ N ];
	for ( auto i = 0; i < N; i++ ) {
		cin >> A[ i ];
		wSorted[ i ] = A[ i ];
	}

	sort( wSorted, wSorted + N );
	long long v = 1e10;

	for ( auto i = 0; i < N; i++ ) {
		vector< long long > wCandidate;
		vector< long long > wCurrent;
		for ( auto j = 0; j <= N; j++ ) {
			if ( j == N || A[ j ] < A[ i ] ) {
				sort( wCurrent.begin(), wCurrent.end() );
				if ( wCurrent.size() >= K ) wCandidate.insert( wCandidate.end(), wCurrent.begin(), wCurrent.end() - K + 1 );
				wCurrent.clear();
			} else {
				wCurrent.emplace_back( A[ j ] );
			}
		}
		sort( wCandidate.begin(), wCandidate.end() );
		if ( wCandidate.size() >= Q ) v = min( v, wCandidate[ Q - 1 ] - A[ i ] );
	}
	cout << v << endl;
}

int
main() {
	Main();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#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,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

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

int main(void){
  string a, b;
  cin >> a >> b;
  istringstream iss(a + b);
  int num = 0;
  iss >> num;
  int k = 0;
  REP(i, 10000) {
    if(i * i == num) k = 1;
  }
  cout << (k ? "Yes" : "No") << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
	ll n, k;
    cin >> n >> k;
	string s;
    cin >> s;
	
	ll count = 0;
	

	for (int i = 0; i < n; i++){
		if (i != 0 && s[i] != s[i - 1])	count++;
	}
	ll ans = n - count + 2 * k-1;
	cout << min(ans, n - 1);
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
	int n,m,i,j;
	static int a[100][100]={0},b[110]={0},c[110]={0};
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=m;i++){
		scanf("%d",&b[i]);
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			c[i]+=a[i][j]*b[j];
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int  a , b ;
  cin >> a >> b ;
  int ans = -1;
  
 rep(i,1300){
   if(i*8/100  == a && i*10/100 == b){
     ans = i;
     break;
   }
 }
   
   cout << ans ;
  
}

    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int a,b;
    REP(i,5){
        cin>>a;
        if(a==0) b=i;
    }
    cout<<b+1<<endl;
}

Measured memory_bytes: 3520
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start

let N=readInt()

let xy=[|
  for _ in 1..N ->
    let A=readInt()
    [|
      for _ in 1..A ->
        let (x,y)=readInts()|>pair
        (x-1,y)
    |]
|]

let check n =
  xy
  |> Array.mapi (fun i x->i,x)
  |> Array.forall (fun (i,xy) ->
    if n&&&(1<<<i)=0 then true
    else
      xy
      |> Array.forall (fun (x,y) ->
        let a=n&&&(1<<<x)
        if y=1 then a<>0 else a=0
      )
  )

let rec popcnt n =
  if n=0 then 0
  else
    popcnt (n>>>1)
    + if n&&&1<>0 then 1 else 0

seq {
  for i in 0..((1<<<N)-1) do
    if check i then
      yield i
}
|> Seq.map popcnt
|> Seq.max
|> printfn "%d"


Measured memory_bytes: 18520
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

template <class A, class B> inline int Max(const A &a, const B &b){ return (a < b ? b : a); }
template <class A, class B> inline int Min(const A &a, const B &b){ return (a > b ? b : a); }

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


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
 
    string t;
    cin >> t;

    for(auto&& e : t){
        if(e == '?'){
            e = 'D';
        }
    }

    cout << t << '\n';
 
    return (0);
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
#define ll long long
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
const ll MOD=1000000007L;
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
    long long N;
    cin>>N;
    ll suma=0;
    ll a2=0;
    ll ans =0;
    ll tmp2=0;
    ll suma2=0;
    rep(i,N){
        ll tmp;
        cin>>tmp;
        tmp2=(tmp*tmp)%MOD;
        a2=a2+tmp2;
        suma=suma+tmp;
        a2=a2%MOD;
        suma=suma%MOD;
    }
    if(suma<0){
        suma=suma+MOD;
    }
    if(a2<0){
        a2=a2+MOD;
    }
    suma2=(suma*suma)%MOD;
    ans=(suma2-a2)%MOD;
    if(ans<0){
        ans=ans+MOD;
    }
    //正しい答え*2%MOD=ansになるようなやつが正しい答え
    ll ans2=0;
    ll inv2=modinv(2,MOD);
    ans2=(ans*inv2)%MOD;
    //(ans2*2)%MOD=ansなるans2が答え
    if(ans2<0){
        ans2+MOD;
    }
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll n,a,b;
    cin>>n>>a>>b;
  ll now;
    cin>>now;
  ll ans=0;
  FOR(i,0,n-1){
    ll x;
      cin>>x;
    ans+=min((x-now)*a,b);
    now=x;
  }

  cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n<=5)
        printf("0\n");
    else
    if(n>=6&&n<13)
        printf("%d\n",m/2);
    else
        printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,X,M;
    cin >> N >> X >> M;
    ll cur = X;
    ll cnt = 0;
    ll stop = 0;
    bool flag = 0;
    vector<ll> memo(M,0);
    deque<ll> v;
    while(memo[cur] == 0){
        memo[cur] = 1;
        if(cur == 0){
            flag = 1;
            break;
        }
        cur = (cur*cur) % M;
        stop = cur;
    }
    //ll ini = 0;
    ll sum_b = 0;
    cur = X;
    vector<ll> u;
    ll cnt_b = 0;
    rep(i,M){
        if(cur == stop){
            break;
        }
        u.push_back(cur);
        sum_b += cur;
        cnt_b++;
        cur = (cur*cur)%M;
    }

    ll sum = 0;
    v.push_back(cur);
    cnt = 1;
    sum += cur;
    cur = (cur*cur)%M;
    while(stop != cur){
        v.push_back(cur);
        sum += cur;
        cur = (cur*cur)%M;
        cnt++;
    }
    ll ans = 0;
    if(N <= cnt_b){
        cout << sum_b << endl;
        return 0;
    }
    N -= cnt_b;
    ans = sum_b;
    ll q = N/cnt;
    ll r = N%cnt;
    if(!flag){
        ans += q*sum;
    }else{
        rep(i,min(ll(v.size()),N)){
            ans += v[i];
        }
        cout << ans << endl;
        return 0;
    }
    /*cout << cnt << endl;
    cout << sum << endl;
    cout << sum_b << endl;
    //cout << ini << endl;
    cout << ans << endl;
    cout << r << endl;*/
    rep(i,r){
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll a , b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
import numpy as np

def main():
    N, K, Q = map(int, input().split())

    point = np.array([K for _ in range(N)])
    ct = np.array([Q for _ in range(N)])
    for i in range(Q):
        A = int(input())
        ct[A-1] = ct[A-1] - 1
    point = point - ct
    for p in point:
        if p < 1:
            print("No")
        else:
            print("Yes")
    return 0



if __name__ == '__main__':
    main()

Measured memory_bytes: 21924
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int mod;
vector <int> g[MAXN];
int par[MAXN];
int sz[MAXN];
long long dp[MAXN];
long long dp2[MAXN];

void dfs(int v, int p = -1) {
  par[v] = p;
  sz[v] = 1;
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    dfs(to, v);
    sz[v] += sz[to];
  }
}

long long calc(int v) {
  dp[v] = 1;
  for (int to : g[v]) {
    if (to == par[v]) {
      continue;
    }
    dp[v] = dp[v] * (1ll + calc(to)) % mod;
  }
  return dp[v];
}

void calc2(int v, long long mul = 0) {
  // cerr << "MUL " << v << " " << mul << endl;
  dp2[v] = (1ll + mul) * dp[v] % mod;
  vector <long long> ch, pref, suff;
  for (int to : g[v]) {
    if (to == par[v]) {
      continue;
    }
    ch.push_back(to);
    pref.push_back(1 + dp[to]);
    suff.push_back(1 + dp[to]);
  }
  for (int i = 1; i < sz(pref); i++) {
    pref[i] = pref[i] * pref[i - 1] % mod;
  }
  for (int i = sz(suff) - 2; i >= 0; i--) {
    suff[i] = suff[i] * suff[i + 1] % mod;
  }
  for (int i = 0; i < sz(ch); i++) {
    long long goMul = 1 + mul;
    if (i > 0) {
      goMul = goMul * pref[i - 1] % mod;
    }
    if (i + 1 < sz(suff)) {
      goMul = goMul * suff[i + 1] % mod;
    }
    calc2(ch[i], goMul);
  }
}

int main() { 

  scanf("%d %d", &n, &mod);
  for (int i = 0; i < n - 1; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }

  dfs(0);
  calc(0);
  calc2(0);

  for (int i = 0; i < n; i++) {
    // cerr << i << " " << sz[i] << " " << dp[i] << endl;
    printf("%lld\n", dp2[i]);
  }

  return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct S {
    ll cnt, zero, one;

    static S op(S a, S b){
        return {a.cnt + b.cnt + a.one * b.zero, a.zero + b.zero, a.one + b.one};
    }

    static S e() { return {0, 0, 0}; }
};

struct OP{
    ll ch;

    static S ac(OP f, S a){
        if(f.ch){
            return {a.one * a.zero - a.cnt, a.one, a.zero};
        }else{
            return a;
        }
    }

    static OP me(OP g, OP f){
        return {g.ch ^ f.ch};
    }

    static OP id() { return {0}; }
};

// ACL template
int main() {
    ll N, Q;
    cin >> N >> Q;
    vc<S> A(N);
    rep(i, N){
        ll a;
        cin >> a;
        if(a) A[i] = {0, 0, 1};
        else A[i] = {0, 1, 0};  
    }

    lazy_segtree<S, S::op, S::e, OP, OP::ac, OP::me, OP::id> seg(A);

    rep(_, Q){
        ll t, l, r;
        cin >> t >> l >> r, l--;

        if(t == 1){
            seg.apply(l, r, {1});
        }else{
            cout << seg.prod(l, r).cnt << '\n';
        }
    }
}

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

int m[410][410];

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  m[0][0] = 1;
  for (int ni = 0; ni < n; ni++) {
    int x, y, c;
    cin >> x >> y >> c;
    for (int u = 400; u >= 0; u--) {
      for (int v = 400; v >= 0; v--) {
        if (m[u][v] > 0) {
          if (m[u+x][v+y] == 0) m[u+x][v+y] = m[u][v]+c;
          else m[u+x][v+y] = min(m[u][v] + c, m[u+x][v+y]);
        }
      }
    }
  }
  int ans = 1e9;
  for (int d = 1; d * a < 410 && d * b < 410; d++) {
    if (m[d*a][d*b] > 0) ans = min(ans, m[d*a][d*b]);
  }
  if (ans == 1e9) cout << -1 << endl;
  else cout << ans - 1 << endl;
  return 0;
}


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

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

	int l,r,d;
	cin>>l>>r>>d;
	int count=0;
	for(int i=l;i<=r;++i)
	{
		if(i%d==0)
			count++;
	}
	cout<<count<<"\n";
}

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



int main(void){
   
    
    int N,M;
    cin>>N>>M;
    int S[M+1];
    for(int i=0;i<=M;i++){
        S[i]=0;
    }
    for(int i=1;i<=N;i++){
        int K;
        cin>>K;
        for(int j=1;j<=K;j++){
            int A;
            cin>>A;
           S[A]=S[A]+1;
        }
    }
    int P;
    P=0;
    for(int i=1;i<=M;i++){
        if(S[i]==N){
            P=P+1;
        }
    }
    cout<<P<<endl;

    return 0;
}

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

int main(){
    int n, k, x, y, ans=0;
    cin >> n >> k >> x >> y;

    if(n<=k){
        cout << x * n << endl;
    } else {
        cout << x * k + y * (n-k) << endl;
    }

    return 0;
}

Measured memory_bytes: 3568
import collections

N = int(input())

si = []
base_i = ord('a')
for i in range(N):
    inp = input()
    si.append(str(sorted(inp)))

c = collections.Counter(si)

def nc2(n):
    return n*(n-1)//2

ans = 0
for i in c.values():
    if i > 1:
        ans += nc2(i)

print(ans)

Measured memory_bytes: 24552
import java.util.Scanner;

/**
 * Created by zzt on 17-5-6.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] degree = new int[n];
        for (int i = 0; i < m; i++) {
            degree[scanner.nextInt()-1] ++;
            degree[scanner.nextInt()-1] ++;
        }
        for (int i = 0; i < n; i++) {
            if (degree[i]%2==1){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 64908
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;

ll combi(ll n, ll r) {
	int i;
	ll p = 1;
	for (i = 1; i <= r; i++)
		p = p*(n - i + 1) / i;
	return p;
}

int main(void) {
	int N, A, B;
	cin >> N >> A >> B;
	vll v(N);
	rep(i, N) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	int same = 0;
	rep(i, N) {
		if (v[i] == v[0])same++;
		else break;
	}

	if (same >= A) {
		ll ans = 0;
		repl(i, A, min(same + 1, B + 1)) {
			ans += combi(same, i);
		}
		cout << fixed << setprecision(14) << (double)v[0] << endl;
		cout << ans << endl;
		return 0;
	}

	int idx = 0;
	ll sum = 0;
	while (idx < N) {
		int rest = A - idx;
		ll num = v[idx];
		int cnt = 0;
		while (idx < N && v[idx] == num) {
			cnt++;
			idx++;
		}
		if (idx < A) {
			sum += num*cnt;
		}
		else {
			sum += num*rest;
			cout << fixed << setprecision(14) << (double)sum / A << endl;
			cout << combi(cnt, rest) << endl;
			return 0;
		}
	}

	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> card = new ArrayList<>(9);
        for (int i = 0; i < 9; i++) {
            card.add(sc.nextInt());
        }
        int count = sc.nextInt();
        int res = 0;
        for (int i = 0; i < count; i++) {
            int num = sc.nextInt();
            int index = card.indexOf(num);
            if (-1 < index) {
                res += Math.pow(2, index);
            }
        }
        int[] yesArr = {7, 56, 448, 73, 146, 292, 273, 84};
        boolean bingo = false;
        for (int yes : yesArr) {
            if ((res & yes) == yes) {
                bingo = true;
                break;
            }
        }
        System.out.println(bingo ? "Yes" : "No");
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    for (;;) {
        c -= b;
        if (c <= 0) {
            cout << "Yes";
            return;
        }
        a -= d;
        if (a <= 0) {
            cout << "No";
            return;
        }
    }
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;

std::vector<std::vector<int>> edges;

int dfs(int index, std::set<int> visited) {
  visited.insert(index);
  if (visited.size() == edges.size() - 1) return 1;

#if DEBUG
  std::cout << index << ":";
  for (int v : edges[index]) {
    if (visited.count(v)) continue;
    std::cout << v << " ";
  }
  std::cout << std::endl;
#endif

  int sum = 0;
  for (int v : edges[index]) {
    if (visited.count(v)) continue;
    sum += dfs(v, visited);
  }
  return sum;
}

int main() {
  int N, M; std::cin >> N >> M;
  edges = std::vector<std::vector<int>>(N+1);

  for (int m = 0; m < M; ++m) {
    int a, b; std::cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  std::set<int> visited;
  std::cout << dfs(1, visited) << std::endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

// ---------- begin ModInt ----------
// Thank you @sansen for referring to code

const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 { 0 } else { MOD - self.0 })
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------

fn main() {
    input! {
    n: usize,
    k: usize
    }
    let mn = ModInt::from(n);
    let mk = ModInt::from(k);
    for i in 0..k {
        let bc = calc_comb(mk - ModInt::one(), i);
        let ans = bc * calc_comb(mn - mk + ModInt::one(), i + 1);
        println!("{}", ans);
    }
}

fn calc_comb(n: ModInt, r: usize) -> ModInt {
    let mut num = ModInt::one();
    for i in 1..=r {
        let mi = ModInt::from(i);
        num = num * (n + ModInt::one() - mi) * mi.inv();
    }
    num
}



Measured memory_bytes: 2160
N = int(input())
S = list(input())

cntOne = S.count('R') * S.count('G') * S.count('B')
cntTwo = 0


for i in range(N-1):
    for j in range(i+1, N):
        k = (j - i) + j
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cntTwo += 1
print(cntOne - cntTwo)

Measured memory_bytes: 9192
from collections import deque

n=int(input())
X=[[] for _ in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    X[a-1].append([b-1,c])
    X[b-1].append([a-1,c])
    
visited=[0]*n
distance=[0]*n

q,k=map(int,input().split())

Que=deque([[k-1,0]])

while Que:
    b,c=Que.popleft()
    if visited[b]==1:
        continue
    visited[b]=1
    distance[b]=c
    for pb,pc in X[b]:
        Que.append([pb,c+pc])

for i in range(q):
    x,y=map(int,input().split())
    print(distance[x-1]+distance[y-1])

Measured memory_bytes: 109984
#abc110 b
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x_max=max(x)
y_min=min(y)
flag=False
for i in range(X+1,Y+1):
    if x_max<i<=y_min:
        flag=True
        break
if flag:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int N,K;
vector<int> a;
vector<int> sum;

int main() {
  while(cin >> N,cin >> K) {
    if(N==0&&K==0) break;
    a.resize(N);
    sum.resize(N+1);
    sum[0] = 0;
    rep(i,N) {
      cin >> a[i];
      sum[i+1] = a[i] + sum[i];
    }
    ll ans = 0;
    rep(i,N-K) {
      ll tmp = sum[i+K] - sum[i];
      ans = max(ans,tmp);
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3656
X = int(input())
break_flag = False

if X == 0:
    print("0 0")
elif X > 0: # a > b
    for i in range(-1000,1000):
        for j in range(-1000,i):
            if X == i**5-j**5:
                print(i,j)
                break_flag = True
                break
        if break_flag == True:
            break        

elif X < 0: #a < b
    for i in range(-1000,1000):
        for j in range(i+1,1000):
            if X == i**5-j**5:
                print(i,j)
                break_flag = True
                break
        if break_flag == True:
            break         


Measured memory_bytes: 64892
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <bitset>
#include <cmath>

using ll = long long;

using namespace std;

using BS = bitset<1000010>;

int main() {
    int n;
    string s, t = "";
    cin >> n >> s;
    bool one = false, two = false;
    for (int i=0; i<n-1; i++) {
        int c1 = s[i]-'0', c2 = s[i+1]-'0';
        char add = (char)(abs(c1 - c2) + '0');
        t += add;
        if (add == '1') one = true;
        if (add == '2') two = true;
    }
    if (n == 2) {
        cout << t[0] << '\n';
        return 0;
    }
    if (one) {
        BS bs;
        for (int i=0; i<n-1; i++) bs[i] = (t[i] == '1');
        int m = n-2, d = (1 << 30);
        while (m) {
            if (m >= d) {
                bs ^= (bs >> d);
                m -= d;
            }
            d /= 2;
        }
        cout << (bs[0] ? '1' : '0') << '\n';
    }
    else if (two) {
        BS bs;
        for (int i=0; i<n-1; i++) bs[i] = (t[i] == '2');
        int m = n-2, d = (1 << 30);
        while (m) {
            if (m >= d) {
                bs ^= (bs >> d);
                m -= d;
            }
            d /= 2;
        }
        cout << (bs[0] ? '2' : '0') << '\n';
    } else {
        cout << 0 << '\n';
    }
    return 0;
}

Measured memory_bytes: 2820
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

int main() {
    ll N;
    cin >> N;
    VV<PLL> X(N);
    for(ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        while(a--) {
            ll x, y;
            cin >> x >> y;
            X[i].emplace_back(x - 1, y);
        }
    }

    ll ans = 0;
    for(ll S = 0; S < (1 << N); S++) {
        V<ll> which(N, -1);
        bool ok = true;
        for(ll i = 0; i < N; i++) {
            bool honest = (S >> i) & 1;
            if(honest) {
                for(auto &&ele : X[i]) {
                    ll x, y;
                    tie(x, y) = ele;
                    bool by = y;
                    bool val = !(by ^ honest);
                    if(which[x] == -1) {
                        which[x] = val;
                    } else if(which[x] != (ll)val) {
                        ok = false;
                        break;
                    }
                }
            }
        }
        for(ll i = 0; i < N; i++) {
            bool s = (S >> i) & 1;
            if(which[i] != -1 && s != which[i]) ok = false;
        }
        if(!ok) continue;
        ll cnt = 0;
        ll cpy = S;
        while(cpy) {
            cnt += cpy & 1;
            cpy /= 2;
        }
        chmax(ans, cnt);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> x(N), y(N), idxs(N), memo(H, W);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        memo[x[i]] = min(memo[x[i]], y[i]);
        idxs[i] = i;
    }
    
    int ans = H;
    int cy = 0;
    for (int i = 1; i < H; i++) {
        if (memo[i] <= cy) {
            ans = i;
            break;
        } else if (memo[i] != cy + 1) {
            cy++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  ll sum=0;
  int n=s.size();
  for(int temp=0; temp<(1<<n-1);temp++){
    ll t=s[0]-'0';
    for(int i=0;i<n-1;i++){
      if(temp&(1<<i)){
        sum+=t;
        t=s[i+1]-'0';
      }
      else{
        t*=10;
        t+=s[i+1]-'0';
      }
    }
    sum+=t;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256