akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Control.Arrow ((&&&))
import Control.Monad.State
import Data.List

main :: IO ()
main = do
  [d,n] <- getl $ wrds toInt
  solve <$> replicateM d (getl toInt) <*> replicateM n (getl $ wrds toInt) >>= print

solve :: [Int] -> [[Int]] -> Int
solve ds cs = h $ execState (mapM_ g (tail ls)) ((0,fst (head ls)),(0,snd (head ls)))
  where
    f x = (maximum &&& minimum) . map (!!2) . filter (\[a,b,_] -> a <= x && x <= b) $ cs
    ls = map f ds
    g :: (Int,Int) -> State ((Int,Int),(Int,Int)) ()
    g (h,l) = do
      ((th,xh),(tl,xl)) <- get
      let h1 = th + abs (h - xh)
          h2 = tl + abs (h - xl)
          l1 = th + abs (l - xh)
          l2 = tl + abs (l - xl)
      put ((max h1 h2, h),(max l1 l2,l))
    h ((x,_),(y,_)) = max x y
      
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    deque<int> b;

    if(n%2==0) {
        REP(i, n) {
            if(i % 2 == 0) {
                b.push_back(a[i]);
            } else {
                b.push_front(a[i]);
            }
        }
    } else {
        REP(i, n) {
            if(i % 2 == 0) {
                b.push_front(a[i]);
            } else {
                b.push_back(a[i]);
            }
        }
    }

    REP(i, n) cout << b[i] << " " ;

}


Measured memory_bytes: 3840
// C++ program to print all the cycles
// in an undirected graph
#include <bits/stdc++.h>
using namespace std;
long long int dp[3010][3010];
long long int A[3010];
long long int solve(int i,int j){
  if(i>j){
    dp[i][j]=0;
    return dp[i][j];
  }
  if(dp[i][j]!=INT_MIN){
    return dp[i][j];
  }
  if(A[i]-solve(i+1,j) > A[j]-solve(i,j-1)){
    dp[i][j]=A[i]-solve(i+1,j);
    return dp[i][j];
  }else{
    dp[i][j]=A[j]-solve(i,j-1);
    return dp[i][j];
  }

}
int main(){
int n;
cin>>n;
 //long long int ans=0;
 //long long int A[n];
 for(int i=0;i<n;++i){
    cin >> A[i];
 }
 for(int i=0;i<n;++i){
    for(int j=0;j<n;++j)
        dp[i][j]=INT_MIN;
 }
 cout << solve(0,n-1)<<endl;
 return 0;

}


Measured memory_bytes: 74352
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    l = n//x
    if l*x<n:
        l+=1
    print(l*t)
    return

if __name__=='__main__':
    n,x,t = IL()
    solve()

Measured memory_bytes: 27124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long 
#define inf 1000000007

int main () {
  ll n;
  cin >> n;
  vector<ll> sitigosannumber;
  int l; 
  for (int keta = 3; keta <= 9; keta++) {
    int sub[keta];
    for (int i = 1; i <= keta; i++) {
      for (int j = 1; j <= keta; j++) {
        if (i + j >= keta) {
          break;  
        } 
        else {
          l = keta - i - j;
          int itr = 0;
          for (int sub_i = 0; sub_i < i; sub_i++) {
            sub[itr] = 3;  
            itr++;
          }     
          for (int sub_j = 0; sub_j < j; sub_j++) {
            sub[itr] = 7;
            itr++;  
          }
          for (int sub_l = 0; sub_l < l; sub_l++) {
            sub[itr] = 5;
            itr++;  
          }
          sort(sub, sub + keta); // next_permutationのため
          do {
            ll subsub = 0;
            ll ten = 1;
            for (int sub_ten = 0; sub_ten < keta; sub_ten++) {
              subsub += sub[sub_ten] * ten;
              ten = ten * 10;
            }    
            sitigosannumber.push_back(subsub);
          } while (next_permutation(sub, sub + keta));
        } 
      }  
    }
  }
  ll answer = 0;
  for (ll i = 0; i < sitigosannumber.size(); i++) {
    if (n >= sitigosannumber[i]) {
      answer++;  
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 640
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto a = new long[](N);
	foreach (i; 0..N)
	{
		a[i] = RD-1;
	}

	auto used = new bool[](N);
	long ans;
	long pos;
	used[0] = true;
	while (pos != 1)
	{
		if (used[a[pos]])
		{
			ans = -1;
			break;
		}
		else
		{
			pos = a[pos];
			used[pos] = true;
			++ans;
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 4092
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, W, i, j, w[110], v[110], dp[110][100010]={0};

    cin >> N >> W;

    for(i=1; i<=N; i++){
        cin >> w[i] >> v[i];
    }

    for(i=0; i<N; i++){
        for(j=0; j<=W; j++){
            if(j >= w[i+1]){
                chmax(dp[i+1][j], dp[i][j-w[i+1]] + v[i+1]);
            }

            chmax(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;
    
    return 0;
}

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

info=[]

for i in range(n):
  s,p=input().split()
  info.append([i,s,int(p)])

info=sorted(info,key=lambda x:x[2],reverse=True)
info=sorted(info,key=lambda x:x[1])

for i in range(n):
  print(info[i][0]+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr);
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 

int32_t main(){
    // boost;
    
        int n,tot;
        cin>>tot>> n  ;
        int a[n+1];
        map<int,int>cn;
        for(int i =0 ; i < n ;i ++) cin>>a[i] , cn[a[i]]++;
        
        // int dp1[n+1];
        // int dp2[n+1];
        
        int prev = -1;
        int res = 0;
        
        for(int i = 1; i < n ; i++ ){
            res+=(a[i]-a[i-1]);
        }
       int ans = res;
       
    //   cout<<ans<<endl;
       
        res = res + (a[0] - 0 + tot - a[n-1]);
       
        // cout<<res<<endl;
       
        for(int i =1 ; i < n; i++ ){
            
            ans = min(ans , res -( a[i] - a[i-1]));
        }
        cout<<ans<<endl;
    
}

Measured memory_bytes: 14336
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 100 + 5;
const int M = 5e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,l[N],ans;

void init() {}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

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

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            for (int k = j+1; k < n; ++k) {
                set<int> s;
                s.insert(l[i]);
                s.insert(l[j]);
                s.insert(l[k]);
                if(s.size()==3) {
                    auto mid = s.begin();
                    ++mid;
                    auto lst = s.end();
                    --lst;
                    if(*s.begin()+*mid>*lst) ++ans;
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)>1) cout << "Alice\n";
    else cout << "Brown\n"; 


 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x=100000;
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		x=x*1.05;
		if(x%1000!=0)
			x=((x/1000)+1)*1000;
	}
	printf("%d\n",x);
	return 0;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    sort(all(a));

    ll ans = 0;

    rep(i,N)
    {
        if( x >= a[i] )
        {
            ans++;
            x -= a[i];
        }
    }
    if( N == ans && x != 0 ) cout << ans-1 << endl;
    else cout << ans << endl;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> L(N);
    for (ll &l : L) cin >> l;
    sort(L.begin(), L.end());
    ll sum = accumulate(L.begin(), L.end() - 1, 0ll);
    cout << (sum > *(L.end() - 1) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>

int main()
{
    std::string S;
    std::cin >>S;
    int len=S.length();
    int A,min=1000;
    for(int i=0; i<len;i++){
        std::string T;
        T[0]=T[1];
        T[1]=T[2];
        T[2]=S[i];
        A=std::atoi(T.c_str());
        A=abs(753-A);
        if(min >=A){
            min=A;
        }
    }
    std::cout << min<< std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
string S;

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

  int white[N], black[N];

  int b = 0, w = 0;
  REP(i, N) {
    if(S[i] == '#') b++;
    black[i] = b;
    if(S[N - 1 - i] == '.')w++;
    white[N - 1 - i] = w;
  }

  int ans = min(white[1], black[N - 1]);
  for(int i = 1; i < N - 1; i++) {
    ans = min(ans, black[i - 1] + white[i + 1]);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2180
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define db double
#define RE register
#define ll long long
#define P 998244353
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define pb(x) push_back(x)
#define ull unsigned long long
#define getc(c) scanf("%s",c+1)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=1e6+10;
int n;
char c[N];
struct wy{int mn,sm;}a[N];

inline ll read()
{
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline bool cmp(wy a,wy b)
{
	if(a.sm>0&&b.sm>0) return a.mn>b.mn;
	if((a.sm<0&&b.sm<0)||(a.sm==0&&b.sm==0)) return a.sm+b.mn>b.sm+a.mn;
	return a.sm>b.sm;
}

inline void work(int s)
{
	int m=strlen(c+1);
	int sum=0;a[s].mn=INF;
	rep(i,1,m)
	{
		int k=(c[i]=='('?1:-1);
		sum+=k;
		a[s].mn=min(a[s].mn,sum);
	}
	a[s].sm=sum;
}

int main()
{
//	freopen("1.in","r",stdin);
//	freopen("bf.out","w",stdout);
	get(n);
	rep(i,1,n) getc(c),work(i);
	sort(a+1,a+n+1,cmp);
	int sum=0;
	rep(i,1,n) 
	{
		if(sum+a[i].mn<0) {puts("No");return 0;}
		sum+=a[i].sm;
	}
	if(sum!=0) puts("No");
	else puts("Yes");
	return (0^_^0);
}
//以吾之血,祭吾最后的亡魂







Measured memory_bytes: 11476
#include <iostream>

using namespace std;
const long long MAXN = 3010;
const long long MOD = 1e9+7;
long long dp[MAXN][MAXN];
long long dp2[MAXN];
int main(){
    long long n;
    cin>>n;
    string s;
    cin>>s;
    for(long long i=1;i<=n;i++){
       
        dp2[i] = 1;
    }
    for(long long i=1;i<n;i++){
        if(s[i-1] == '<'){
            for(long long j=1;j<=i+1;j++){
                
                dp[i][j] = dp2[j-1];
               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
            
        }else{
            for(long long j=1;j<=i+1;j++){
                
                dp[i][j] = ((dp2[n]-dp2[j-1]) + MOD)%MOD;
                //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
            
        }
        dp2[0] = dp[i][0];
        for(long long j=1;j<=n;j++){
            dp2[j] = dp2[j-1] + dp[i][j];
            dp2[j]%=MOD;
        }
        
    }
    long long ans = 0;
    for(long long i=1;i<=n;i++){
        ans+=dp[n-1][i];
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 69248
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    string ss;
    cin>>ss;
    vi<ll>r,g,b;
    map<ll,ll>mppR,mppG,mppB;
    for(ll i=0;i<n;i++){
        if(ss[i]=='R'){
            r.pb(i);
            mppR[i]=1;
        }else if(ss[i]=='G'){
            g.pb(i);
            mppG[i]=1;
        }else{
            b.pb(i);
            mppB[i]=1;
        }
    }
    ll ans=0;
    ll chk,temp,mx,mn;
    ll rs=r.size(),bs=b.size(),gs=g.size();
    for(auto it:r){
        for(auto it2:g){
            //debugg(it);
            //debugg(it2);
            temp=abs(it-it2);
            mx=max(it,it2);
            mn=min(it,it2);
            ans+=bs;
            ans-=mppB[temp+mx];
            if(!(temp&1)){
                ans-=mppB[mn+temp/2];
            }
            ans-=mppB[mn-temp];
            //debugg(ans);
        }
    }
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 4492
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a[2];
char c;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll j=0;
	for(ll i=1; i<=3; i++)
	{
	    if(i&1)
	    {
	        cin>>a[j];
	        ++j;
	    }
	    else
	    cin>>c;
	}
	if(c=='-')
	cout<<a[0]-a[1];
	else
	cout<<a[0]+a[1];
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	long N,S;

	public long f(long b,long n){
		if(n < b)return n;
		return f(b,n / b) + (n % b);
	}

	public void solve() {
		N = nextLong();
		S = nextLong();

		if(N == S){
			out.println(N + 1);
			return;
		}
		long ans = Long.MAX_VALUE;
		for(int i = 2;(long)i * i <= N;i++){
			long res = f(i,N);
			if(res == S){
				ans = Math.min(ans,i);
			}
		}

		for(int i = 1;(long)i * i <= N - S;i++){
			long B = (N - S) / i + 1;
			if(f(B,N) == S){
				ans = Math.min(ans,B);
			}
		}
		out.println(ans == Long.MAX_VALUE ? -1 : ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 8404
#include<iostream>
#include<cstdbool>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    int n,i,j;
    scanf("%d",&n);
    int d[n];
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    
    bool flag=1;
    for(i=0;flag;i++){
        flag=0;
        for(j=n-1;j>=i+1;j--){
            if(d[j]<d[j-1]){
                swap(d[j],d[j-1]);
                flag=1;
            }
        }
    }
    
    int cnt=1;
    for(i=0;i<n-1;i++){
        if(d[i]!=d[i+1]){
            cnt++;
        }
    }
    
    printf("%d",cnt);
    /*for(i=0;i<n;i++){
        printf("%d ",d[i]);
    }
    //printf("%d",max);*/
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <list>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
int in;

int main(){
    list<int> ans;
    cin >> n;
    if(n % 2 == 0){
        rep(i,n){
            cin >> in;
            if(i % 2 == 0){
                ans.push_back(in);
            }
            else{
                ans.push_front(in);
            }
        }
    }
    else{
        rep(i,n){
            cin >> in;
            if(i % 2 == 1){
                ans.push_back(in);
            }
            else{
                ans.push_front(in);
            }
        }
    }
    for(auto ou: ans){
        cout << ou << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
int f(int x){
    if(x<=1)return x;
    return x*f(x-1);
}
int n;
vector<int>p,q;
int a=0,b=0;
bool ab=true,bb=true;
vector<int>v;
signed main(){
    cin>>n;
    rep(i,n){
        int x;cin>>x;
        p.push_back(x);
    }
    rep(i,n){
        int x;cin>>x;
        q.push_back(x);
    }
    rep(i,n)v.push_back(i+1);
    do{
        if(ab)a++;
        if(bb)b++;
        if(v==p)ab=false;
        if(v==q)bb=false;
    }while(next_permutation(v.begin(),v.end()));
    int ans=abs(b-a);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#define DICE_FACES 6
#define DICE_ROLL 7

typedef struct dice {
  int label[DICE_FACES];
  int top, front, right;
} Dice;
void roll(Dice *d, char direction) {
  int tmp = d->top;
  switch (direction) {
    case 'E' :
      d->top = DICE_ROLL - d->right;
      d->right = tmp;
      break;
    case 'W' :
      d->top = d->right;
      d->right = DICE_ROLL - tmp;
      break;
    case 'S' :
      d->top = DICE_ROLL - d->front;
      d->front = tmp;
      break;
    case 'N' :
      d->top = d->front;
      d->front = DICE_ROLL - tmp;
      break;
  }
}
void dice_init(Dice *d, int n[]) {
  int i;
  for (i = 0; i < DICE_FACES; i++) {
    d->label[i] = n[i];
  }
  d->top = 1;
  d->front = 2;
  d->right = 3;
}
int getRight(Dice *d, int t, int f) {
  int t_l = getLabel(d, t);
  int f_l = getLabel(d, f);
  char ch_s[] = {"SSSS"};
  char ch_e[] = {"EEEE"};
  int i, j, flag, ans;
  flag = 0;
  j = 0;
  while(ch_e[j]) {
    i = 0;
    while(ch_s[i]) {
      if (d->top == t_l && d->front == f_l) {
        ans = d->right;
        flag = 1;
        break;
      }
      roll(d, ch_s[i]);
      i++;
    }
    if (flag == 1) break;
    roll(d, ch_e[j]);
    j++;
  }
  if (flag == 0) {
    roll(d, 'S');
    roll(d, 'E');
    i = 0;
    while(ch_s[i]) {
      if (d->top == t_l && d->front == f_l) {
        ans = d->right;
        flag = 1;
        break;
      }
      roll(d, ch_s[i]);
      i++;
    }
  }
  if (flag == 0) {
    roll(d, 'E');
    roll(d, 'E');
    i = 0;
    while(ch_s[i]) {
      if (d->top == t_l && d->front == f_l) {
        ans = d->right;
        flag = 1;
        break;
      }
      roll(d, ch_s[i]);
      i++;
    }
  }
  return d->label[ans - 1];
}
int getLabel(Dice *d, int x) {
  int i;
  int ans = -1;
  for (i = 0; i < DICE_FACES; i++) {
    if (d->label[i] == x) {
      ans = i + 1;
      break;
    }
  }
  return ans;
}
int main(void) {
  int n[DICE_FACES];
  int q, i, j, k;
  for (i = 0; i < DICE_FACES; i++) scanf("%d", &n[i]);
  scanf("%d", &q);

  Dice dice;
  dice_init(&dice, n);

  for (i = 0; i < q; i++) {
	scanf("%d %d", &j, &k);
    printf("%d\n", getRight(&dice, j, k));
  }
  return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

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

    if(a*a+b*b+c*c < (a-b)*(a-b) + (b-c)*(b-c) + (c-a)*(c-a) && c-a-b>0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
     
int main() {
     
int N, M;
  cin >> N >> M;
  
  vector<int> L(M);
  vector<int> R(M);
  for(int i = 0; i < M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  int maxl = 0;
  for(int i = 0; i < M; i++) {
  maxl = max(maxl, L.at(i));
  }
  int minr = 10000000;
  for(int i = 0; i < M; i++) {
    minr = min(minr, R.at(i));
  }
 if(minr - maxl >= 0) { 
 cout << minr - maxl + 1 << endl;
 }
  else { 
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    LCIN(N);LCIN(A);LCIN(B);
    LL ans = 0;
    I vec;
    LCIN(M);
    LL ins = M;
    REP(a,N-1){
        LCIN(b);
        vec.pb(b-ins);
        ins = b;
    }
    REP(a,N-1){
       // COUT(vec.at(a));
        ans += min(vec.at(a)*A,B);
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 892
H, W = map(int, input().split())

count = {}
for _ in range(H):
    for s in input().strip():
        count[s] = count.get(s, 0) + 1

req = [0] * 4

for h in range(H//2+H%2):
    if h < H // 2:
        c = 2
    else:
        c = 1
    for w in range(W//2+W%2):
        if w < W // 2:
            cc = c * 2
        else:
            cc = c
        req[cc - 1] += 1

for r in [4, 2, 1]:
    for i in range(req[r-1]):
        for s in count:
            if count[s] >= r:
                count[s] -= r
                break
        else:
            print('No')
            exit(0)
print('Yes')


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << c-(d-b) << " " << d+(c-a) << " " << a-(d-b) << " " << b+(c-a) << endl;
}

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const ull Max = 1e18 ;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


int main()
{

    fastread();

    ll j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

    bool flag=false;

    cin>>n;

       vector<pll>v;

     while(n%2==0)
     {
         n/=2;
         cnt++;
     }

    if(cnt)
        v.eb(2,cnt);

    cnt=0;

    ll i;

     for(ll i=3; i<=sqrt(n); i+=2)
     {
         cnt=0;

         while(n%i==0)
         {
             n/=i;
             cnt++;
         }

         if(cnt)
            v.eb(i,cnt);
     }
     if(n>1)
        v.eb(n,1);
        cnt=0;

     for(auto x : v)
     {
         j=2;


         for(i=1; i<=x.S; )
         {
             cnt++;

             i+=j;
             j++;
         }
     }

     cout<<cnt<<endl;
}



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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &x : a) cin >> x;
	reverse(a.begin(), a.end());
	for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' ');
}


Measured memory_bytes: 3068
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

if N % 2 == 0:
    print (N - 1) / 2
else:
    print N / 2

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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))


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

template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }

using namespace std;

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

	int poss = a + b;
	poss = max(poss, a+a-1);
	poss = max(poss, b+b - 1);
   
	cout << poss << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
using vc = vector<char>; using vvc = vector<vc>;
using vp = vector<pair<int,int>>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main(){
  string n;cin >> n;
  int ans = 0;
  vl num(n.size());
  rep(i,n.size()) num[i] = n[i] - '0';
  rep(i,n.size()) {
    ans += num[i];
    if(ans >= 9) ans -= 9;
  }
  if(ans) cout << "No" << endl;
  if(!ans) cout << "Yes" << endl;
}

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

//素因数分解する。
vector<pair<long long, long long>> prime_factorize(long long n){
    vector<pair<long long,long long>> res;
    for(long long p = 2; p*p <= n; p++){
        if(n % p != 0)continue;
        int num = 0;
        while(n%p == 0){n /= p; num++;}
        res.push_back(make_pair(p,num));
    }
    if(n != 1) res.push_back(make_pair(n,1));
    return res;
}

//最大公約数を求める
long long GCD(long long x, long long y){
    return y ? GCD(y, x%y) : x;
}



int main(){
    long long A,B;
    cin >> A >> B;
    long long G = GCD(A,B);
    auto pf = prime_factorize(G);
    cout << pf.size() + 1 << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<bits/stdc++.h>
#define LL long long int
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	
		LL n;
		cin>>n;
		if(n%1000==0)
		cout<<0<<"\n";
		else
		cout<<1000-(n%1000)<<"\n";	
	
	

}


Measured memory_bytes: 3632
N, K = map(int, input().split())
S = input()
max_happy = N-1
init_happy = 0
for i in range(1, N-1):
  if S[i]=="L" and S[i-1]=="L":
    init_happy += 1
  elif S[i]=="R" and S[i+1]=="R":
    init_happy += 1

if N>1:
  if S[0]=="R" and S[1]=="R":
    init_happy += 1

  if S[-1]=="L" and S[-2]=="L":
    init_happy += 1

ans = min(max_happy, init_happy+K*2)

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<string> ss(n);
  for(int i = 0; i < n; ++i) cin >> ss[i];
  vvi nblue, nb_tate, nb_yoko;
  vi vzero(m+1, 0);
  nblue.push_back(vzero);
  nb_tate.push_back(vzero);
  nb_yoko.push_back(vzero);
  for(int i = 1; i < (n+1); ++i){
    nblue.push_back(nblue[i-1]);
    nb_tate.push_back(nb_tate[i-1]);
    nb_yoko.push_back(nb_yoko[i-1]);
    for(int j = 1; j < (m+1); ++j){
      nblue[i][j] += nblue[i][j-1];
      nb_tate[i][j] += nb_tate[i][j-1];
      nb_yoko[i][j] += nb_yoko[i][j-1];
      nblue[i][j] -= nblue[i-1][j-1];
      nb_tate[i][j] -= nb_tate[i-1][j-1];
      nb_yoko[i][j] -= nb_yoko[i-1][j-1];
      if(ss[i-1][j-1] == '1'){
        nblue[i][j] += 1;
        if(i != 1 and ss[i-2][j-1] == '1') nb_tate[i][j] += 1;
        if(j != 1 and ss[i-1][j-2] == '1') nb_yoko[i][j] += 1;
      }
    }
  }
  for(int i=0; i < q; ++i){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int node = nblue[x2][y2] - nblue[x1-1][y2] - nblue[x2][y1-1] + nblue[x1-1][y1-1];
    int edge = (nb_yoko[x2][y2] - nb_yoko[x1-1][y2] - nb_yoko[x2][y1] + nb_yoko[x1-1][y1]);
    edge += (nb_tate[x2][y2] - nb_tate[x1][y2] - nb_tate[x2][y1-1] + nb_tate[x1][y1-1]);
    cout << (node - edge) << endl;
  }
  return 0;
}


Measured memory_bytes: 55288
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val p = sc.nextInt()
    val q = sc.nextInt()
    val r = sc.nextInt()
    println(problem129a(p, q, r))
}

fun problem129a(p: Int, q: Int, r: Int): Int {
    return Math.min(Math.min(p + q, p + r), q + r)
}

Measured memory_bytes: 29348
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct LazySegmentTree {
  ll identity = -1e18;

  ll merge(const ll& lhs, const ll& rhs) {
    return max(lhs, rhs);
  }

  int N;
  vector<ll> node, span;
  vector<bool> pend;

  LazySegmentTree() {}
  LazySegmentTree(int n) { init(vector<ll>(n, 0)); }
  LazySegmentTree(const vector<ll>& vec) { init(vec); }

  void init(const vector<ll>& vec) {
    int sz = vec.size();
    N = 1;
    while(N < sz) N *= 2;
    node.assign(2*N-1, identity);
    span.assign(2*N-1, 0);
    pend.assign(2*N-1, false);
    for(int i = 0; i < sz; i++) node[i+N-1] = vec[i];
    for(int i = N-2; i >= 0; i--) node[i] = merge(node[2*i+1], node[2*i+2]);
  }

  void propagate(int k, int l, int r) {
    if(!pend[k]) return;
    node[k] += span[k] / (r-l);
    if(r-l>1) {
      pend[2*k+1] = pend[2*k+2] = true;
      span[2*k+1] += span[k] / 2;
      span[2*k+2] += span[k] / 2;
    }
    pend[k] = false;
    span[k] = 0;
  }

  void update(int s, int t, ll x) {
    rec_update(s, t, x, 0, 0, N);
  }

  void rec_update(int s, int t, ll x, int k, int l, int r) {
    propagate(k, l, r);
    if(r <= s || t <= l) return;
    if(s <= l && r <= t) {
      pend[k] = true;
      span[k] += (r - l) * x;
      propagate(k, l, r);
      return;
    }
    rec_update(s, t, x, 2*k+1, l, (l+r)/2);
    rec_update(s, t, x, 2*k+2, (l+r)/2, r);
    node[k] = merge(node[2*k+1], node[2*k+2]);
  }

  ll query(int s, int t) {
    return rec_query(s, t, 0, 0, N);
  }

  ll rec_query(int s, int t, int k, int l, int r) {
    if(r <= s || t <= l) return identity;
    propagate(k, l, r);
    if(s <= l && r <= t) return node[k];
    ll lhs = rec_query(s, t, 2*k+1, l, (l+r)/2);
    ll rhs = rec_query(s, t, 2*k+2, (l+r)/2, r);
    return merge(lhs, rhs);
  }
};

void answer() {
  ll n, m; cin >> n >> m;
  struct Q {
    ll l, r, a;
    Q(ll l_, ll r_, ll a_) : l(l_), r(r_), a(a_) {}
    bool operator<(const Q& rhs) const { return r < rhs.r; }
  };
  vector<Q> qs;
  rep(i,m) {
    ll l, r, a; cin >> l >> r >> a;
    qs.emplace_back(Q(l, r, a));
  }
  sort(ALL(qs));
  LazySegmentTree st(n+1);
  auto itr = qs.begin();
  REPC(i,1,n) {
    st.update(i, i+1, st.query(0, i));
    while(itr != qs.end() && itr->r == i) {
      st.update(itr->l, itr->r+1, itr->a);
      itr++;
    }
  }
  cout << st.query(0, n+1) << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 17772
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      char[] array = f.readLine().toCharArray();
      
      long r = 0L;
      long g = 0L;
      long b = 0L;
      
      for(int k = 0; k < n; k++){
         if(array[k] == 'R') r++;
         if(array[k] == 'G') g++;
         if(array[k] == 'B') b++;
      }
      
      long answer = r*g*b;
      
      for(int k = 1; k <= n/2; k++){
         for(int i = 0; i+2*k < n; i++){
            if(array[i] != array[i+k] && array[i] != array[i+2*k] && array[i+k] != array[i+2*k]) answer--;
         }
      }
      
      out.println(answer);
      
      

      
      
      
      
      
      out.close();
   }
   
      
}

Measured memory_bytes: 32856
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M; string S;
	cin >> N >> M >> S;
	vector<vector<int> > G(N);
	vector<int> ca(N), cb(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
		if (S[a] == 'A') ++ca[b]; else ++cb[b];
		if (S[b] == 'A') ++ca[a]; else ++cb[a];
	}
	queue<int> que;
	for (int i = 0; i < N; ++i) {
		if (ca[i] == 0 || cb[i] == 0) {
			que.push(i);
		}
	}
	int cnt = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		++cnt;
		for (int i : G[u]) {
			bool notyet = (ca[i] != 0 && cb[i] != 0);
			if (S[u] == 'A') --ca[i]; else --cb[i];
			if (notyet && (ca[i] == 0 || cb[i] == 0)) {
				que.push(i);
			}
		}
	}
	cout << (cnt != N ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 12164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int a, b;
    cin >> a >> b;
    int y = 0;
    int fl = 0;
    for (int i = 0; i < a; i++) {
        y += b + i;
        if (b + i == 0)fl = 1;
    }
    if (fl == 0) {
        if (b > 0)y -= b;
        else y -= a + b - 1;
    }
    cout << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


bool solve(string s){
    string k = "keyence";
    if(s.substr(s.size() - k.size(), k.size()) == k){
        return true;
    }else if(s.substr(0, k.size()) == k){
        return true;
    }
    for(int i = 0; i < k.size() && i < s.size(); ++i){
        if(s.substr(0, i) + s.substr(s.size() - (k.size() - i)) == k){
            return true;
        }
    }
    return false;
}

int main(){
    string s;
    cin >> s;
    LL cur = 0;
    if(solve(s)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
n = int(input())
S = []
H = []
C = []
D = []
for i in range(n):
    a, b = input().split()
    if a == "S":
        S.append(int(b))
    if a == "H":
        H.append(int(b))
    if a == "C":
        C.append(int(b))
    if a == "D":
        D.append(int(b))
S.sort()
C.sort()
H.sort()
D.sort()

check = [0 for i in range(14)]

for i in S:
    check[i] = 1

for i in range(1, 14):
    if (check[i] == 0):
        print("S ", end = "")
        print(i)

check = [0 for i in range(14)]

for i in H:
    check[i] = 1

for i in range(1, 14):
    if (check[i] == 0):
        print("H ", end = "")
        print(i)

check = [0 for i in range(14)]

for i in C:
    check[i] = 1

for i in range(1, 14):
    if (check[i] == 0):
        print("C ", end = "")
        print(i)

check = [0 for i in range(14)]

for i in D:
    check[i] = 1

for i in range(1, 14):
    if (check[i] == 0):
        print("D ", end = "")
        print(i)


Measured memory_bytes: 5624
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
namespace std{
    bool operator < (const P& a, const P& b){
        return (a.X!=b.X) ? a.X<b.X : a.Y<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
VP convex(VP v){
    VP ret;
    int n = v.size();
    sort(v.begin(), v.end());
    for(int i=0; i<n; i++){
        while((int)ret.size()>1 && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    int t = ret.size();
    for(int i=n-2; i>=0; i--){
        while((int)ret.size()>t && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    if(!ret.empty()) ret.pop_back();
    return ret;
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		VP v(n);
		for(int i=0; i<n; i++){
			double x,y;
			scanf("%lf,%lf", &x, &y);
			v[i] = P(x,y);
		}
		VP ret = convex(v);
		cout << n -(int)ret.size() << endl;
	}
	return 0;
}


Measured memory_bytes: 3216
import bisect
n=int(input())
lists=list(map(int,input().split()))
lists=sorted(lists)

cnt=0
import math
for i in range(n):
    for j in range(i+1,n):
        #i<j 
        x=lists[i]
        y=lists[j]
        left=i 
        right=j 
        index=bisect.bisect_right(lists,y-x)
        cnt+=min(j-i-1,j-index)

print(cnt)


Measured memory_bytes: 44892
#include <iostream>

int group(int a) {
    if (a == 2) return 1;
    if (a == 4 || a == 6 || a == 9 || a == 11) return 2;
    return 3;
}

int main() {
    int a, b; std::cin >> a >> b;
    bool r = group(a) == group(b);
    std::cout << (r ? "Yes" : "No") << std::endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>

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

class BTripleDots {
public:
	void solve(std::istream& cin, std::ostream& cout) {
	    string s;
	    int k ;
	    cin>>k>>s;
	    string ans ="";
	    if(s.size()>k){
	        rep(i,k) {
                ans += s.at(i);
            }
	        ans += "...";
	    }
	    else ans = s;
	    cout<<ans<<endl;

	}
};


int main() {
	BTripleDots solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3628