akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string O,E,A;
int L,i;
inline void solve(){
  IN2(O,E);
  L=min(O.size(),E.size());
  REP(i,L){
    A=A+O[i]+E[i];
  }
  if(O.size()>E.size())A=A+O[i];
  OUT(A);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
  int H,W;
  cin >> H >> W;
  
  vector<string>grid(H);
  for(int i=0;i<H;i++){
    cin >> grid[i];
  }
  
  int n;
  for(int i=0;i<H;i++){
    n = 0;
    for(int j=0;j<W;j++){
      if(grid[i][j] == '#')
        n = 1;
    }
    if(n == 0){
      for(int j=0;j<W;j++){
        grid[i][j] = '0';
      }
    }
  }
  
  for(int i=0;i<W;i++){
    n = 0;
    for(int j=0;j<H;j++){
      if(grid[j][i] == '#')
        n = 1;
    }
    if(n == 0){
      for(int j = 0;j<H;j++){
        grid[j][i] = '0';
      }
    }
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(grid[i][j] != '0'){
        cout << grid[i][j];
      }
      
      if(j == W-1)
        cout << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int cnt[26];

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

	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		string s;
		cin >> s;
		cnt[s[0] - 'A']++;
	}

	priority_queue<P> q;
	for(int i = 0; i < 26; i++) {
		if(cnt[i]) q.push(P(cnt[i], i));
	}

	int ans = 0;
	while(q.size() >= K) {
		vector<P> ps;
		for(int i = 0; i < K; i++) {
			ps.push_back(q.top());
			q.pop();
		}
		for(int i = 0; i < K; i++) {
			ps[i].first--;
			if(ps[i].first) q.push(ps[i]);
		}
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	H := sc.nextIntSlice(N)
	dp := make([]int, N)
	for i := 1; i < N; i++ {
		if i < 2 {
			dp[i] = abs(H[i]-H[i-1]) + dp[i-1]
		} else {
			dp[i] = min(abs(H[i]-H[i-1])+dp[i-1], abs(H[i]-H[i-2])+dp[i-2])
		}
	}

	fmt.Fprintln(wtr, dp[N-1])
	wtr.Flush()
}


Measured memory_bytes: 2688
#pragma GCC optimize ("-O3")
    #include <bits/stdc++.h>  
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(int i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 1e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
     
    ll mpow(ll a, ll b){
        if(b >= (MOD-1)) b %= (MOD-1);
        if(b==0) return 1;
        ll t1 = mpow(a,b/2);
        t1 *= t1;
        t1 %= MOD;
        if(b%2) t1 *= a;
        t1 %= MOD;
        return t1;
    }
     
    ll mpow(ll a, ll b, ll p){
        if(b==0) return 1;
        ll t1 = mpow(a,b/2,p);   t1 *= t1;
        t1 %= p;
        if(b%2) t1 *= a;
        t1 %= p;
        return t1;
    }
    ll modinverse(ll a, ll m){
        ll m0 = m; 
        ll y = 0, x = 1; 
        if (m == 1) return 0; 
        while (a > 1){
            ll q = a / m; 
            ll t = m; 
            m = a % m, a = t; 
            t = y; 
            y = x - q * y; 
            x = t; 
        }
        if (x < 0) x += m0; 
        return x; 
    }
    ll range(ll l, ll r){
        return l + rand()%(r-l+1);
    }
    
    int main()
    {
        ll t=1;
        //cin>>t;
        while(t--)
        {
            ll n;cin>>n;
            ll arr[n];
            for(ll i=0;i<n;i++)
            {
                cin>>arr[i];
            }

            ll ans = 0;

            for(ll i=0;i<n;i++)
            {
                for(ll j=i+1;j<n;j++)
                {
                    for(ll k=j+1;k<n;k++)
                    {
                        if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[i]!=arr[k])
                        {
                            ll sum = arr[i]+arr[j]+arr[k];
                            ll mx = max({arr[i],arr[j],arr[k]});
                            if(sum-mx > mx)ans++;
                        }
                    }
                }
            }
            cout<<ans<<endl;
        }
    }

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

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int s,w;
    cin >> s >> w;
    if(s > w){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
  int n;
  int respuestas[100000];
  int h[100000];
int dp(int pos)
{
	
  if(pos>=n-1)return 0;
  if(respuestas[pos]!=-1)
	return respuestas[pos];
  if(n-1-pos==1)return abs(h[pos]-h[pos+1]) ;
  int ans=min(abs(h[pos]-h[pos+1])+dp(pos+1),abs(h[pos]-h[pos+2])+dp(pos+2));
  respuestas[pos]=ans;
  return ans;

}
int main() {
  cin>>n;

  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
	for(int i=0;i<n;i++)
	{
		respuestas[i]=-1;
		
	}
cout<<dp(0)<<endl;
	
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

typedef int INT;
set <INT> S;

inline INT get( char c ) {
    char T[5] = "ACGT";
    for ( INT i = 0; i < 4; ++ i ) {
        if ( c == T[i] ) return i + 1;
    }
    return 0;
}

inline INT get( char *s ) {
    INT n = strlen( s );
    INT sum = 0;
    INT t = 1;
    for ( INT i = 0; i < n; ++ i ) {
        sum += get( s[i] ) * t;
        t *= 4;
    }
    return sum;
}

inline void insert( char *s ) {
    S.insert( get( s ) );
}

inline bool find( char *s ) {
    return S.count( get( s ) ) > 0;
}

int main() {
    INT n;
    while ( scanf("%d", &n) != EOF ) {
        S.clear();
        char cmd[13], data[13];
        for ( register INT i = 0; i < n; ++ i ) {
            scanf( "%s%s", cmd, data );
            if ( cmd[0] == 'i' ) {
                insert( data );
            } else {
                puts( find( data ) ? "yes" : "no" );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 7252
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int l1=s.length(),l2=t.length();
    int i,j;
    int dp[l1+1][l2+1];
    std::fill(*dp,*dp + (l1+1)*(l2+1),0);
    for(i=1;i<=l1;i++)
    {
        for(j=1;j<=l2;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }

    }
   string st="";
    i=l1;j=l2;
   while(i>0 && j>0)
   {
        if(s[i-1]==t[j-1])
            {
            st=s[i-1]+st;
            i--;
            j--;
        }
        else if(dp[i][j]==dp[i][j-1])
            j--;
        else
            i--;
    }
   cout<<st<<"\n";
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 35456
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int a[101],b[101],c[101],d[101],gf[201],ans;
vector<int>e[101];
bool vis[201];
int dfs(int x){
	for(int i=0;i<e[x].size();++i)
		if(!vis[e[x][i]]){
			vis[e[x][i]]=1;
			if(gf[e[x][i]]==0||dfs(gf[e[x][i]]))
				return gf[e[x][i]]=x,1;
		}
	return 0;
}
int main(void){
	register int i,j;
	n=read();
	for(i=1;i<=n;++i)a[i]=read(),b[i]=read();
	for(i=1;i<=n;++i)c[i]=read(),d[i]=read();
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(a[i]<c[j]&&b[i]<d[j])
				e[i].push_back(n+j);
	for(i=1;i<=n;++i)
		memset(vis,0,sizeof(vis)),ans+=dfs(i);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x = int(input())
    print("ABC" if x < 1200 else "ARC")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
using System;
using System.Linq;

namespace _0579
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int day = x[0]; int n = x[1];
            int[] kion = new int[day];
            for (int i = 0; i < day; i++) kion[i] = int.Parse(Console.ReadLine());
            int[] min = new int[n]; int[] max = new int[n]; int[] hade = new int[n];
            for (int i = 0; i < n; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                min[i] = a[0]; max[i] = a[1]; hade[i] = a[2];
            }
            int[,] dp = new int[day,n];
            for (int i = 0; i < day; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (min[j] <= kion[i] && kion[i] <= max[j])
                    {
                        if (i != 0)
                        {
                            int now = -1000000;
                            for (int k = 0; k < n; k++)
                            {
                                now = Math.Max(now,dp[i - 1,k] + Math.Abs(hade[k] - hade[j]));
                            }
                            dp[i,j] = now;
                        }
                    }
                    else dp[i,j] = -100000;
                }
            }
            int ret = 0;
            for (int i = 0; i < n; i++)
            {
                ret = Math.Max(ret,dp[day - 1,i]);
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 9740
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define endl "\n"
    #define sz(x) (int)(x).size()
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    ll mod =(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) return 1;
    	if (p == 2 || (p & 1)) return mult(x, binpow(x, p - 1));
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    // bool check(ll x){}
    ll binsearch(ll l,ll r)
    {
        while(l<r)
        {
            ll mid=(l+r)/2;
            // if(check(mid))r=mid;
            // else l=mid+1;
        }
        return l;
    }
    const ll man=(ll)1005;
    vector<ll>adj[man];
    bool vis[man][man];
    ll d[man],depth[man],par[man];
    void addedge(ll u,ll v){adj[u].pb(v);adj[v].pb(u);}
    ll dx[4]={1,-1,0,0};ll dy[4]={0,0,1,-1};
/*........................................................................................................................*/

signed main()/*Check flow...question galat mat padhna */
{
    fast;  
    ll n;
    For(i,5)
    {
        read(x);
        if(x==0)n=i+1;
    }
    cout<<n<<endl;
}      


Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,k;
  cin>>n;
  cin>>k;
  int sum = 0; 
    int a[105];
      for(int i = 1; i<=n; i++){
          cin>>a[i];
      }
      
      for(int i = 1; i<=n; i++){
          sum = sum + min(abs(a[i]),abs(a[i]-k))*2;
      }
      
      cout<<sum<<endl;
      return 0;
}

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	char s;
	cin>>s;
	if(s == 'A'){
		cout<<"T"<<endl;
	}	else if(s == 'T'){
		cout<<'A'<<endl;
	}else if(s == 'G'){
		cout<<"C"<<endl;
	}else{
		cout<<"G"<<endl;
	}


	

	return 0;
}

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

int main(){

    int N,K;
    cin >> N >> K;
    vector<int> h(N+K,0);
    rep(i,N)cin >> h[i];
    vector<int> dp(N+K,INF);
    dp[0] = 0;
    rep(i,N-1){
        for(int k = 1; k <= K; k++){
            dp[i+k] = min(dp[i+k],dp[i] + abs(h[i+k] - h[i]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
A = int(input())
B = int(input())

if A == 1:
    if B == 2:
        ans = 3
    if B == 3:
        ans = 2
elif A == 2:
    if B == 1:
        ans = 3
    if B == 3:
        ans = 1
elif A == 3:
    if B == 1:
        ans = 2
    if B == 2:
        ans = 1

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    ll x,K,D; cin >> x >> K >> D;
    ll ans = 0;
    ll X = abs(x);
    if (X > 0){
        if ((X/K) >= D){
            ans = X - K * D;
        }
        else {
            ll tmp = X / D;
            //cout << tmp << endl;
            ll rest = K - tmp;
            if ((rest % 2) == 0){
                ans = X - tmp * D;
            }
            else{
                ans = X - (tmp + 1) * D;
            }
        }
    }
/*    else if (X < 0){
        if ((X + (K * D)) <= 0){
            ans = X + K * D;
        }
        else {
            ll tmp = (-1 * X) / D;
            ll rest = K - tmp;
            if ((rest % 2) == 0){
                ans = X + tmp * D;
            }
            else{
                ans = X + (tmp + 1) * D;
            }
        }
    }*/
    else{
        if ((K % 2) == 0){
            ans = 0;
        }
        else{
            ans = D;
        }
    }
    cout << abs(ans) << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <vector>

using i64 = long long;

int main() {
  i64 n;
  scanf("%lld", &n);
  std::vector<i64> a(n);
  for (auto &e : a) {
    scanf("%lld", &e);
  }

  std::vector<i64> pp(n), p(n), s(n), ss(n), st0, st1, temp;
  st0.reserve(n);
  st1.reserve(n);
  temp.reserve(n);
  {
    for (i64 i = 0; i != n; ++i) {
      while (!st1.empty() && a[st1.back()] < a[i]) {
        ss[st1.back()] = i;
        st1.pop_back();
      }
      while (!st0.empty() && a[st0.back()] < a[i]) {
        s[st0.back()] = i;
        temp.push_back(st0.back());
        st0.pop_back();
      }
      st0.push_back(i);
      while (!temp.empty()) {
        st1.push_back(temp.back());
        temp.pop_back();
      }
    }
    while (!st0.empty()) {
      s[st0.back()] = n;
      ss[st0.back()] = n;
      st0.pop_back();
    }
    while (!st1.empty()) {
      ss[st1.back()] = n;
      st1.pop_back();
    }
  }
  {
    for (i64 i = n; i != 0;) {
      --i;
      while (!st1.empty() && a[st1.back()] < a[i]) {
        pp[st1.back()] = i;
        st1.pop_back();
      }
      while (!st0.empty() && a[st0.back()] < a[i]) {
        p[st0.back()] = i;
        temp.push_back(st0.back());
        st0.pop_back();
      }
      st0.push_back(i);
      while (!temp.empty()) {
        st1.push_back(temp.back());
        temp.pop_back();
      }
    }
    while (!st0.empty()) {
      p[st0.back()] = -1;
      pp[st0.back()] = -1;
      st0.pop_back();
    }
    while (!st1.empty()) {
      pp[st1.back()] = -1;
      st1.pop_back();
    }
  }

  i64 ans = 0;
  for (i64 i = 0; i != n; ++i) {
    ans += a[i] * ((p[i] - pp[i]) * (s[i] - i) + (i - p[i]) * (ss[i] - s[i]));
  }
  printf("%lld\n", ans);

  return 0;
}


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

using namespace std;

int c[5][5];
int main(){
    for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    cin>>c[i][j];
    int b11,b12,b13,b21,b22,b23,b31,b32,b33;
    for(int a1=0;a1<=100;a1++)
    {
        b11=c[1][1]-a1;
        b21=c[1][2]-a1;
        b31=c[1][3]-a1;
        for(int a2=0;a2<=100;a2++)
        {
            b12=c[2][1]-a2;
            b22=c[2][2]-a2;
            b32=c[2][3]-a2;
            if(b11!=b12 || b21!=b22 || b31!=b32)
            continue;   
            for(int a3=0;a3<=100;a3++)
            {
            b13=c[3][1]-a3;
            b23=c[3][2]-a3;
            b33=c[3][3]-a3;
            if(b11==b13 && b21==b23 && b31==b33)
            {
            cout<<"Yes";
            return 0;
            }
            }
        }
    }
    cout<<"No";
    return 0;
}

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

const int  INF = 1e9+5;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    cin >> h[i];
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i=1;i<n;i++)
    {
        for(int j=max(i-2,0);j<i;j++)
        {
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1];
}

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

using namespace std;

int main()
{
  long long int n, k, i, j;

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

  i = n % k;

  j = (i - k) * -1;

  if (i < j)
  {
    printf("%lld", i);
  }
  else
  {
    printf("%lld", j);
  }
}

Measured memory_bytes: 256
function Main (input) {
  var inputs = input.split(/\s/g).map(function (num) { return parseInt(num) });
  var result = Math.min(
    Math.abs(inputs[0] - inputs[1]) + Math.abs(inputs[1] - inputs[2]),
    Math.abs(inputs[1] - inputs[2]) + Math.abs(inputs[2] - inputs[0]),
    Math.abs(inputs[2] - inputs[0]) + Math.abs(inputs[0] - inputs[1])
  )
  console.log('%s',result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
  int N,K;
  long long ans=0;
  cin>>N>>K;
  
  vector<int> H(N);
  
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  sort(H.begin(),H.end());
  
  if(K>=N){cout<<0;}
  else{
    for(int i=0;i<N-K;i++){
      ans+=H.at(i);
    }
    cout<<ans;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
using namespace std;

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

const int MAX_H = 50;
const int MAX_W = 50;
int h, w;
string grid[MAX_H + 1];


string solve() {
	string strinit = "";
	string paintgrid[MAX_H + 1];
	for (int i = 0; i < w; i++) {
		strinit += '.';
	}
	for (int i = 0; i < MAX_H + 1; i++) {
		paintgrid[i] = strinit;
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#') {
				for (int k = 0; k < 4; k++) {
					if (i + dy[k] < 0 || j + dx[k] < 0 || i + dy[k] >= h || j + dx[k] >= w) {
						continue;
					}
					if (grid[i + dy[k]][j + dx[k]] == '#') {
						paintgrid[i][j] = '#';
						paintgrid[i + dy[k]][j + dx[k]] = '#';
					}
				}
			}
		}
	}
	for (int i = 0; i < h; i++) {
		if (grid[i] != paintgrid[i]) {
			return "No";
		}
	}
	return "Yes";
}
int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 256
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e5+10, lg=22, mod=1e9+7, inf=1e18;

ll n,a[maxn];

bool rec(){
	if(n==1) return !(a[1]&1);
	ll tod=0,tev=0;
	for(int i=1;i<=n;i++) tod+=(a[i]&1);
	tev=n-tod;
	if(tev&1) return 1;
	if(tod>=2 || tod==0) return 0;
	ll gcc=0;
	for(int i=1;i<=n;i++){
		if(a[i]&1) a[i]--;
		if(a[i]==0) return 0;
		gcc=__gcd(gcc,a[i]);
	}
	for(int i=1;i<=n;i++) a[i]/=gcc;
	return !rec();
}

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

	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cout<<(rec() ? "First":"Second");

	return 0;
}












Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int i,j,k,k1,s,ans=0;
	cin>>k1>>s;
	for(i=0;i<=k1;i++){
		for(j=0;j<=k1;j++){
			k=s-i-j;
			if(k>=0&&k<=k1)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int selectionSort(int *,int);

int main() {
  
  int n,a[100],i,b[100],cnt=0;
  
  // input data
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  // sort
  cnt = selectionSort(a,n);
  
  // output sorted data
  for(i=0;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n",a[n-1]);
  printf("%d\n",cnt);
  
  return 0;
}

// Sort by selection sort and asc.
int selectionSort(int *a, int n) {
  
  int tmp,i,j,cnt=0,minj,bef;
  
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++) {
      if(a[j] < a[minj]) {
	minj = j;
      }
    }
    if(a[i] != a[minj]){
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      cnt++;
    }
  }
  
  
  return cnt;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;

    if (y % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    if ((0 <= 2 * x - y / 2) && (0 <= -x + y / 2))
    {
        cout << "Yes" << endl;
        return 0;
    }

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

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

using namespace std;

int main()
{
  int A, B, m; cin >> A >> B >> m;
  vector<int> a(A);
  vector<int> b(B);
  for(int i = 0; i < A; i++) cin >> a[i];
  for(int i = 0; i < B; i++) cin >> b[i];
  int ans = *min_element(a.begin(), a.end()) +
            *min_element(b.begin(), b.end());
  for(int i = 0; i < m; i++)
  {
    int x, y, c; cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        if(i==0){
            d[i] = a[i] + k - a[n-1];
        }else{
            d[i] = abs(a[i]-a[i-1]);
        }
    }
    int sum=0;
    int mx=0;
    for(int i=0; i<n; i++){
        sum = sum + d[i];
        mx = max(mx,d[i]);
    }
    int ans;
    ans = sum - mx;
    cout << ans << endl;
    return 0;
}




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

	
	int main() {
		
		ll a, b, k;
		cin >> a >> b >> k;
	if (k >= a) {
			k -= a;
			a = 0;
			b -= k;
			if (a <= 0 && b <= 0) {
				a = 0; b = 0;
			}
			cout << a << " " << b;
		}
		else if (k < a) {
			a -= k;
			k = 0;
			if (a <= 0 && b <= 0) {
				a = 0; b = 0;
			}
			cout << a << " " << b;
		}
				
	}
	
	

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> D;
    int tmp;
    for(int i=0;i<K;i++){
        cin >> tmp;
        D.push_back(tmp);
    }
    vector<int> use;
    int flag;
    for(int i=0;i<10;i++){
        flag = 0;
        for(int k=0;k<D.size();k++){
            if(i == D[k]){
                flag++;
                break;
            }
        }
        if(flag == 0) use.push_back(i);
    }
    int keta=1;
    tmp = N;
    while(tmp > 9){
        tmp /= 10;
        keta ++;
    }

    string s = to_string(N);
    string answer = "";
    for(int i=0;i<s.size();i++){
        tmp = s[i] - '0';
        flag = 0;
        for(int j=0;j<use.size();j++){
            if(tmp == use[j]){
                answer += use[j] + '0';
                flag ++;
                break;
            }else if(tmp < use[j]){
                answer += use[j] + '0';
                for(int k=0;k<s.size()-i-1;k++) answer += use[0] + '0';
                //cout << "a" << endl;
                cout << answer << endl;
                return 0;
            }
        }

        if(flag == 0){
            if(use[0] == 0){
                cout << use[1];
                for(int j=0;j<keta;j++) cout << use[0];
            }else{
                for(int j=0;j<keta+1;j++)cout << use[0];
            }
            cout << endl;
            return 0;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef double ld;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

int n, ans;
ll p[N]; 
ll pr[N];

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif	
	cin >> n;
	forn(i, 1, n){
		cin >> p[i];
	}
	sort(p + 1, p + n + 1);
	forn(i, 1, n){
		pr[i] = pr[i - 1] + p[i];
	}
	ans = n;
	for1(i, n, 2){
		if(p[i] > pr[i - 1] * 2){
			ans -= i - 1;
			break;
		}
	}
	cout << ans;
	return 0;
}

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) cout << 1 << endl;
  else if (a != b && b != c && a != c) cout << 3 << endl;
  else cout << 2 << endl;
}


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

int main(){
    long long n,m;
    cin>>n>>m;
    long long a[n];
    long long sum[n]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]%=m;
        if(i) sum[i]=sum[i-1]+a[i];
        if(!i) sum[i]=a[i];
        sum[i]%=m;
    }
    long long ans=0;
    map<long long,long long> mp;
    for(auto i:sum){
        mp[i]=mp[i]+1;
    }
    for(auto i:mp){
        long long k=(long long)i.second;
        cerr<<i.first<<" "<<i.second<<endl;
        if(i.first==0) ans+=k*(k+1)/2;
        else ans+=k*(k-1)/2;
    }
    
    cout<<ans<<endl;

}

Measured memory_bytes: 5760
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 5005;
char tmp[maxn];
int n, k;
string s;

bool read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  return true;
}

string ans;
string best;
char mn;

void check(string s, int k) {
  while (k) {
    if (s == best) {
      ans = min(ans, s);
      return;
    }
    int x = 0;
    while (x < n && s[n - 1 - x] == mn) {
      x++;
    }
    s = s.substr(x, n - x) + string(x, mn);
    k--;
  }
  reverse(s.begin(), s.end());
  ans = min(ans, s);
}

void solve() {
  ans = s;
  mn = s[0];
  for (int i = 1; i < n; i++) {
    mn = min(mn, s[i]);
  }
  best = string(n, mn);
  if (ans == best) {
    printf("%s\n", ans.c_str());
    return;
  }
  string t = s;
  reverse(t.begin(), t.end());
  string u = s + t;
  if (k == 1) {
    for (int i = 0; i <= n; i++) {
      ans = min(ans, u.substr(i, n));
    }
    printf("%s\n", ans.c_str());
    return;
  }
  for (int i = 0; i <= n; i++) {
    if (u[i + n - 1] != mn) {
      continue;
    }
    check(u.substr(i, n), (i == 0 ? k : k - 1));
    if (ans == best) {
      break;
    }
  }
  printf("%s\n", ans.c_str());
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX (ll)1e18

int main() {
    int N;
    cin>>N;
    ll ans=1;
    for (int i = 0; i < N; i++){
        ll A;
        cin >>A;
        if(A==0){
            cout<<0<<endl;
            return 0;
        }
        if(log(ans)+log(A)<log(2*MAX)){
            if(ans*A<=MAX){
                ans*=A;
                continue;
            }
        }
        ans=-1;
    }
    if(ans==-1)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3836
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    string S, T;
    cin >> S >> T;
    bool ans = true;
    int pos = -1;

    for(int i=0;i<S.length() - T.length()+1;i++){
        ans = true;
        for(int j=0;j<T.length();j++){
            if(S[i+j] == T[j] or S[i+j]=='?'){continue;}
            else{
                ans=false;
            }
        }
        if(ans){
            pos = i;
        }
    }
    if(pos < 0 or T.length() > S.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=pos;i<T.length()+pos;i++){
        S[i]= T[i - pos];
    }
    for(int i=0;i<S.length();i++){
        if(S[i]=='?'){
            S[i] = 'a'; 
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long N;
	//cin >> N;

	string s;
	cin >> s;

	//int A[5]
	//sort(A, A + 5);

	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
	{
		cout << "3" << endl;
	}
	else if (s[0] == 'R' && s[1] == 'R')
	{
		cout << "2" << endl;
	}
	else if (s[1] == 'R' && s[2] == 'R')
	{
		cout << "2" << endl;
	}
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
	{
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
void solution(){
    int n, k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    int sum=0;
    sort(a.begin(), a.end());
    for(int i=0; i<k; i++)
        sum+=a[i];
    cout<<sum<<'\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(); cout.tie();
    int t;
    t=1;
    while(t--) solution();
    return 0;
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int N, K;
  i64 L, R;
  cin >> N >> K >> L >> R;
  vi64 a(N);
  cin >> a;
  vector<vi64> sums(K + 1);
  int M = min(20, N);
  rep(i, bit32(M)) {
    int cnt = 0;
    i64 sum = 0;
    rep(j, M) {
      if (bit32(j) & i) {
        cnt++;
        sum += a[j];
      }
    }
    if (cnt > K) continue;
    sums[cnt].emplace_back(sum);
  }
  repc(i, K) sort(all(sums[i]));
  int O = N - M;
  i64 ans = 0;
  rep(i, bit32(O)) {
    int cnt = 0;
    i64 sum = 0;
    rep(j, O) {
      if (bit32(j) & i) {
        cnt++;
        sum += a[M + j];
      }
    }
    cnt = K - cnt;
    if (cnt < 0) continue;
    int l = lower_bound(all(sums[cnt]), L - sum) - sums[cnt].begin();
    int r = upper_bound(all(sums[cnt]), R - sum) - sums[cnt].begin();
    ans += r - l;
  }
  cout << ans << endl;
}



Measured memory_bytes: 12284
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  string S,T;
  cin >> S;
  cin >> T;
  for(int i=0;i<S.length();i++){
    if((S.substr(S.length()-i) + S.substr(0,S.length()-i)) == T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

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

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    S = list(map(int, input().split())) + [0]
    T = list(map(int, input().split())) + [0]
    dp0 = [[0] * (M + 5) for _ in range(N + 5)]
    dp1 = [[0] * (M + 5) for _ in range(N + 5)]
    MOD = 10 ** 9 + 7
    dp0[0][0] = 1
    for i in range(N + 1):
        for j in range(M + 1):
            dp0[i+1][j] += dp0[i][j]
            dp0[i+1][j] %= MOD
            dp1[i][j] += dp0[i][j]
            dp1[i][j] %= MOD
            dp1[i][j+1] += dp1[i][j]
            dp1[i][j+1] %= MOD
            if S[i] == T[j]:
                dp0[i+1][j+1] += dp1[i][j]
                dp0[i+1][j+1] %= MOD

    ans = dp1[N][M] % MOD
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 104156
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


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

    int a[10000];
    REP(i, n) {
        cin >> a[i];
    }

    int b[29];
    REP(i, 29) {
        b[i] = int(pow(2, i+1));
    }

    int res = 0;
    REP(i, n) {
        for (int j = 28; j >= 0; j--) {
            if (a[i] % b[j] == 0) {
                res += j + 1;
                break;
            }
        }
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
struct node {
  int key;
  node *lp,*rp;
 
  node(){}
  node(int z):key(z),lp(NULL),rp(NULL){}
 
} *root;
 
void insert(node* z){
  node *x=root,*y=NULL;
 
  while(x){
    y = x;
    x = (z->key < x->key) ? x->lp : x->rp;
  }
 
  if(!y)root = z;
  else (z->key < y->key ? y->lp : y->rp) = z;
}
 
bool find(node *t, int v){
  if(!t)return false;
  if(t->key == v)return true;
  return find((v < t->key)?t->lp:t->rp,v);
}
 
void erase(node *t,int v,node *p){
  if(!t)return;
  if(t->key == v){
    if(!t->lp && !t->rp){
      (p->lp==t? p->lp : p->rp) = NULL;
      delete t;
    }
    else if(t->lp && t->rp){
      node *c = t->rp,*cp = t;
      while(c->lp)cp=c,c=c->lp;
      t->key = c->key;
 
      if(!c->lp && !c->rp){
        (cp->lp==c?cp->lp:cp->rp)=NULL;
        delete c;
      }
      else {
        node *cc = (c->lp) ? c->lp : c->rp;
        (cp->lp==c ? cp->lp : cp->rp) = cc;
        delete c;
      }
    }
    else {
      node *c = (t->lp) ? t->lp : t->rp;
      (p->lp==t? p->lp : p->rp) = c;
      delete t;
    }
    return;
  }
  return erase((v < t->key ? t->lp : t->rp),v,t);
}
 
vector<int> preorder, inorder;
 
void dfs(node *t = root){
  preorder.push_back(t->key);
  if(t->lp)dfs(t->lp);
  inorder.push_back(t->key);
  if(t->rp)dfs(t->rp);
}
 
int main(void) {
 
  root = NULL;
 
  int n,v;
  string s;
  cin >> n;
 
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=="insert"){
      cin >> v;
      insert(new node(v));
    } else if(s=="find"){
      cin >> v;
      cout << (find(root,v)?"yes":"no") << endl;
    } else if(s=="delete"){
      cin >> v;
      erase(root,v,root);
    } else {
      dfs();
      for(int j=0;j<inorder.size();j++)cout << " " << inorder[j];
      cout << endl;
      for(int j=0;j<preorder.size();j++)cout << " " << preorder[j];
      cout << endl;
 
      preorder.clear();
      inorder.clear();
    }
  }
 
  return 0;
}


Measured memory_bytes: 18700
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

#define ll long long

using namespace std;

ll X, Y;

int main()
{
    cin >> X >> Y;
    if (X % Y == 0) {
        cout << -1;
    } else {
        cout << X;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int H = nextInt();
		int W = nextInt();

		boolean[][] map = new boolean[H+1][W+1];//false:障害物

		for(int i=0;i<H;i++) {
			char[]C = next().toCharArray();
			for(int j=0;j<W;j++) {
				map[i][j]=C[j]=='.'?true:false;
			}
		}
		sc.close();

		int[][] dp = new int [H][W];

		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				int tj = j;
				int cnt = 0;
				while(map[i][j]&&j<W) {
					cnt++;
					j++;
				}
				Arrays.fill(dp[i],tj,j,+cnt);
			}
		}
		int Max = 0;
		for(int j=0;j<W;j++) {
			for(int i=0;i<H;i++) {
				int ti = i;
				int cnt = 0;
				while(map[i][j]&&i<H) {
					cnt++;
					i++;
				}
				while(map[ti][j]&&ti<H) {
					dp[ti][j]+=cnt;
					Max = max(Max,dp[ti][j]);
					ti++;
				}
			}
		}

		out.println(Max-1);
	}

	private int max(int a, int b) {
		return Math.max(a, b);
	}

	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}

}

Measured memory_bytes: 50132
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int a,b,c;
  cin>>a>>b>>c;
  if(a == b && b == c){
    cout<<"No"<<endl;
  }else if(a == b){
    cout<<"Yes"<<endl;
  }else if(b == c){
    cout<<"Yes"<<endl;
  }else if(a == c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  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 rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n = s.size();
    vector<ll> v(n, 0);
    rep(i, n) {
        if (s[i] == 'W') ++v[i];
    }
    for (int i = n-2; i >= 0; i--) {
        v[i] += v[i+1];
    }

    ll ans = 0;
    rep(i, n) {
        if (s[i] == 'B') ans += v[i];
    }
    cout << ans << endl;
}


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

def selectionSort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            count += 1
    return count

c = selectionSort(A, N)
for i in range(len(A)):
    if i != len(A) - 1:
        print(A[i], end=" ")
    else:
        print(A[i])
print(c)


Measured memory_bytes: 5608