akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long[N+1];
    long B[] = new long[N];
    long out = 0;
    for (int i=0; i<N+1; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      B[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(A[i] > B[i]){
        out += B[i];
        A[i] -= B[i];
        B[i] = 0;
      } else {
        out += A[i];
        B[i] -= A[i];
        A[i] = 0;
      }
      if(A[i+1] > B[i]){
        out += B[i];
        A[i+1] -= B[i];
        B[i] = 0;
      } else {
        out += A[i+1];
        B[i] -= A[i+1];
        A[i+1] = 0;
      }
    }
    System.out.println(out);
  }
}

Measured memory_bytes: 88512
import qualified Data.ByteString.Char8 as BS

uo=1000000007
h l k |k==1   =mod l uo
      |even k =h(mod(l*l)uo)(quot k 2)
      |odd k  =mod((h l (k-1))*l)uo

main=do
 n<-readLn;a<-map (read.BS.unpack).BS.words<$>BS.getLine
 print(f n a (g n a 1) 0)
  where g 0 _ l = l
        g n (k:a) l = g (n-1) a (lcm k l)
        f 0 _ _ i = i
        f n (k:a) l i = f (n-1) a l (mod(i+(quot l k))uo)

Measured memory_bytes: 6524
# coding=utf-8

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ret = 0
for a in range(0,A+1):
    for b in range(0,B+1):
        for c in range(0,C+1):
            s = 500*a+100*b+c*50
            if s==X:
                ret += 1

print(ret)


Measured memory_bytes: 3316
H, W = map(int, raw_input().split())
best = H * W
S = [0, 0, 0]
for h in range(H):
    S[0] = h * W

    S[1] = (H - h) * (W / 2)
    S[2] = (H - h) * (W - W / 2)

    if best > max(S) - min(S):
        best = max(S) - min(S)

    S[1] = (H - h) / 2 * W
    S[2] = (H - h - (H - h) / 2) * W

    if best > max(S) - min(S):
        best = max(S) - min(S)
H, W = W, H
for h in range(H):
    S[0] = h * W

    S[1] = (H - h) * (W / 2)
    S[2] = (H - h) * (W - W / 2)

    if best > max(S) - min(S):
        best = max(S) - min(S)

    S[1] = (H - h) / 2 * W
    S[2] = (H - h - (H - h) / 2) * W

    if best > max(S) - min(S):
        best = max(S) - min(S)

print best


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

int main()
{
  int n, k, cnt = 0;
  cin >> n >> k;
  vector<ll> a(200005, 0);

  for (int i = 0; i < n; i++)
  {
    ll x;
    cin >> x;
    a.at(x)++;
  }
  for (int i = 0; i < 200005; i++)
  {
    if (a.at(i) != 0)
    {
      cnt++;
    }
  }

  if (cnt <= k)
  {
    cout << 0 << endl;
  }
  else
  {
    sort(a.begin(), a.end());
    ll ans = 0;
    int e = cnt - k;
    for (int i = 0; i < 200005; i++)
    {
      if (a.at(i) > 0)
      {
        ans += a.at(i);
        e--;
      }
      if (e == 0)
      {
        break;
      }
    }
    cout << ans << endl;
  }
}


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

 int main(){
  int N;
  string s;


  cin >> N >> s;

  int i=0, r=0, b=0;
  while (i< N) {
   if (s.at(i) == 'R') r++, i++;   
   else b++, i++;    
  }

  if (r > b) cout << "Yes" << endl;
  else cout << "No" << endl;

  
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>

map <int, int> deg;
ll cnt[45];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for(ll i = 1; i <= 43; ++i) cnt[i] = i * (i + 1) / 2;
	ll n;
	cin >> n;
    for(ll i = 2; i * i <= n; ++i) {
        while(n % i == 0) {
            n /= i;
            deg[i]++;
        }
    }
    if(n > 1) deg[n]++;
    ll ans = 0;
    for(auto x : deg) {
        ans += upper_bound(cnt + 1, cnt + 43 + 1, x.s) - cnt - 1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n),sum(n+1,0);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    for(ll i=n;i>0;i--){
        sum[i-1]+=sum[i]+a[i-1];
        sum[i]%=MOD;
    }
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        ans+=((a[i]*sum[i+1])%MOD);
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main() {
    ll H, W, m;
    cin >> H >> W >> m;

    vector<ll> h(m), hcnt(H, 0);
    vector<ll> w(m), wcnt(W, 0);
    for(int i = 0; i < m; i++){
        cin >> h[i] >> w[i];
        h[i]--; w[i]--;
        hcnt[h[i]]++; wcnt[w[i]]++;
    }
    ll hmax = 0;
    ll wmax = 0;
    for(int i = 0; i < H; i++){
        hmax = max(hmax, hcnt[i]);
    }
    for(int i = 0; i < W; i++){
        wmax = max(wmax, wcnt[i]);
    }
    vector<ll> hmax_index;
    vector<ll> wmax_index;
    for(int i = 0; i < H; i++){
        if(hmax == hcnt[i]){hmax_index.push_back(i);}
    }
    for(int i = 0; i < W; i++){
        if(wmax == wcnt[i]){wmax_index.push_back(i);}
    }
    ll hcandidate_num = hmax_index.size();
    ll wcandidate_num = wmax_index.size();

    if(hcandidate_num * wcandidate_num > m){
        cout << hmax + wmax << endl;
    }else{
        set<pll> st;
        for(int i = 0; i < m; i++){
            st.insert({h[i],w[i]});
        }
        bool is_cross = true;
        for(auto eh: hmax_index){
            for(auto ew: wmax_index){
                if(st.find({eh, ew}) == st.end()){
                    is_cross = false;
                }
            }
        }
        if(is_cross){
            cout << hmax + wmax - 1 << endl;
        }else{
            cout << hmax + wmax << endl;
        }
    }



    return 0;
}


Measured memory_bytes: 33568
#include <iostream> 
#include <iomanip> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <functional> 
#include <cmath> 
#include <queue> 
#include <stack> 

#define Ford(i,a,b) for (int i=(a);i<(b);i++) 
#define For(i,n) Ford(i,0,n) 
typedef long long ll; 

using namespace std;

int main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  cout<<(H-h)*(W-w)<<endl;
  return 0;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)
var cnt int
var err error
var inputReader *bufio.Reader

func main(){
	inputReader = bufio.NewReader(os.Stdin)
	var temp int
	var input string
	input, err = inputReader.ReadString('\n')
	input = strings.Replace(input, "\n", "", -1)
	temp, err = strconv.Atoi(input)
	//fmt.Scanf("%d",&temp)
	A:=make([]int,temp,1000000)
	for i:=0;i<temp ;i++  {
		input, err = inputReader.ReadString('\n')
		input = strings.Replace(input, "\n", "", -1)
		A[i], err = strconv.Atoi(input)
		//fmt.Scanf("%d",&A[i])
	}
	//t1 := time.Now()
	shellSort(A,temp)
	//elapsed1 := time.Since(t1)
	//fmt.Println("loop: ", elapsed1)
}
func shellSort(A []int, n int){
	var m int
	G:=make([]int,n,1000000)
	G1:=make([]int,n,1000000)
	j:=0
	for m=1; ;m++  {
		temp:=(int(math.Pow(float64(3),float64(m)))-1)/2
		//fmt.Println(temp)
		if(temp>n){
			break
		}
		G1[j]=temp
		j++
	}
	for i:=0;i<j ;i++  {
		G[i]=G1[j-i-1]
	}
	m=m-1
	fmt.Println(m)
	for i:=0;i<m;i++ {
		fmt.Printf("%d ",G[i])
		insertionSort(A,n,G[i])
	}
	fmt.Println()
	fmt.Println(cnt)
	for i:=0;i<n ;i++ {
		fmt.Println(A[i])
	}
}
func insertionSort(A []int,n int,g int){
	for i:=g; i<n ; i++ {
		v:=A[i]
		j:=i-g
		for ;j>=0 && A[j]>v ;  {
			A[j+g]=A[j]
			j=j-g
			cnt++
		}
		A[j+g]=v
	}
}



Measured memory_bytes: 27272
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int[] abcde = new int[5];
		for (int i = 0; i < 5; i++) {
			abcde[i] = sc.nextInt();
		}

		Permutation np = new Permutation(5);
		int min = Integer.MAX_VALUE;
		for (List<Integer> perm : np) {
			int tmp = 0;
			for (int i = 0; i < 4; i++) {
				tmp += (abcde[perm.get(i)] + 9) / 10 * 10;
			}
			
			tmp += abcde[perm.get(4)];
			min = Math.min(min, tmp);
		}

		pr.println(min);
	}

	private static class Permutation implements Iterable<List<Integer>>{
		int n;
		long nn;

		Permutation(int n) {
			this.n = n;

			nn = 1;
			for (int i = 2; i <= n; i++) {
				nn *= i;
			}
		}

		@Override
		public Iterator<List<Integer>> iterator() {
			return new PermutationIterator();
		}

		private class PermutationIterator implements Iterator<List<Integer>> {
			boolean[] used;
			List<Integer> perm;
			Deque<Integer> ist;
			long cnt = 0;

			PermutationIterator() {
				used = new boolean[n];
				perm = new ArrayList<Integer>(n);
				ist = new ArrayDeque<Integer>();
				ist.add(-1);
			}

			@Override
			public boolean hasNext() {
				return cnt < nn;
			}

			@Override
			public List<Integer> next() {
				out:
				while (!ist.isEmpty()) {
					int k = ist.pop();

					if (k != -1) {
						// ループ途中での戻り
						used[k] = false;
						perm.remove(perm.size() - 1);
					} else {
						// 最初から
						int pos = perm.size();

						if (pos == n) {
							cnt++;
							// perm に対する操作 =========================
							return perm;
							// perm に対する操作 =========================
						}
					}

					for (int i = k + 1; i < n; i++) {
						if (!used[i]) {
							ist.push(i);

							used[i] = true;
							perm.add(i);
							ist.push(-1);
							continue out;
						}
					}
				}

				return null;
			}

		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main()
{
  int R, G;
  cin >> R >> G;
  
  cout << 2 * G - R << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

int main(){
    int n;
    std::cin >> n;

    int val;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        ans += (val - 1);
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

int main(void){
    int x, y;
    cin >> x >> y;
    auto f = [](int a){
        switch(a){
            case 1: case 3: case 5: case 7: case 8: case 10: case 12:
                return 0;
            case 4: case 6: case 9: case 11:
                return 1;
            case 2:
                return 2;
        }
        return -1;
    };
    cout << (f(x) == f(y) ? "Yes" : "No") << endl;
    return 0;
}

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

int main(){
    int N;
    std::cin >> N;
    
    int cnt = 0;
    int find = 1;
    for(int i=0; i<N; i++){
        int in;
        std::cin >> in;
        if(in == find){
            find++;
        }else{
            cnt++;
        }
    }
    if(cnt == N){
        cnt = -1;
    }
    std::cout << cnt << std::endl;
    
    return 0;
}
    



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;


int main(void)
{
	int N, K; cin >> N >> K;
	vector<int> H(N); rep(i, 0, N)cin >> H[i];
	sort(H.begin(), H.end()); 
	lli ans = 0;
	rep(i, 0, N - K)ans += H[i];
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 110
int n,i,h,w;
char mp[N][N];
int r[N],c[N];
int main(){
    while (scanf("%d %d",&h,&w)!=EOF){
        for (int i=0;i<h;i++)
            scanf("%s",mp[i]);

        memset(r,0,sizeof r);
        memset(c,0,sizeof c);
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++)
            {
                if (mp[i][j]=='.'){
                    r[i]++;
                    c[j]++;
                }
            }
        }
        for (int i=0;i<h;i++)
        {
            bool flag = false;
            for (int j=0;j<w;j++)
                if (r[i]!=w&&c[j]!=h)
                {
                    flag = true;
                    printf("%c",mp[i][j]);
                }
            if (flag)
                printf("\n");
        }

    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int xc = sc.nextInt();
        int yc = sc.nextInt();
        boolean ans = false;
        int[] x = new int[n+1];
        int[] y = new int[m+1];
        for(int i=0; i<n; i++){
            x[i] = sc.nextInt();
        }
        x[n] = xc;
        for(int i=0; i<m; i++){
            y[i] = sc.nextInt();
        }
        y[m] = yc;
        
        int xmax = -100;
        int ymin = 100;
        
        for(int i=0; i<n+1; i++){
            if(x[i]>xmax){
                xmax = x[i];
            }
        }
        for(int i=0; i<m+1; i++){
            if(y[i]<ymin){
                ymin = y[i];
            }
        }

        if(xmax >= ymin){
            ans = true;
        }

        System.out.println(ans?"War":"No War");
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
string s;
cin>>s;int ans=0,t=1;
for(int i=1;i<s.size();i++){t*=3;ans+=t;}
for(int i=0;i<s.size();i++){
    if(s[i]>'3')ans+=t;
    if(s[i]>'5')ans+=t;
    if(s[i]>'7')ans+=t;
    if(s[i]!='3'&&s[i]!='5'&&s[i]!='7')break;
    t/=3;
}
ans++;
for(int i=0;i<s.size();i++)if(s[i]!='3'&&s[i]!='5'&&s[i]!='7'){ans--;break;}
//cerr<<ans<<endl;
t=1;for(int i=1;i<s.size();i++){t*=2;ans-=t;}
for(int i=0;i<s.size();i++){
    if(s[i]>'3')ans-=t;
    if(s[i]>'5')ans-=t;
    
    if(s[i]!='3'&&s[i]!='5')break;
    t/=2;
}
ans--;
for(int i=0;i<s.size();i++)if(s[i]!='3'&&s[i]!='5'){ans++;break;}
//cerr<<ans<<endl;

t=1;for(int i=1;i<s.size();i++){t*=2;ans-=t;}
for(int i=0;i<s.size();i++){
    if(s[i]>'7')ans-=t;
    if(s[i]>'5')ans-=t;
    
    if(s[i]!='7'&&s[i]!='5')break;
    t/=2;
}
ans--;
for(int i=0;i<s.size();i++)if(s[i]!='3'&&s[i]!='7'){ans++;break;}
//cerr<<ans<<endl;
t=1;for(int i=1;i<s.size();i++){t*=2;ans-=t;}
for(int i=0;i<s.size();i++){
    if(s[i]>'3')ans-=t;
    if(s[i]>'7')ans-=t;
    
    if(s[i]!='3'&&s[i]!='7')break;
    t/=2;
}
ans--;
for(int i=0;i<s.size();i++)if(s[i]!='7'&&s[i]!='5'){ans++;break;}
cerr<<ans<<endl;
for(int i=1;i<s.size();i++){ans+=3;}
for(int i=0;i<s.size();i++){
    if(s[i]>'3')ans++;
   
    
    if(s[i]!='3')break;

}
ans++;
for(int i=0;i<s.size();i++)if(s[i]!='3'){ans--;break;}
for(int i=0;i<s.size();i++){
    if(s[i]>'5')ans++;
   
    
    if(s[i]!='5')break;

}
ans++;
for(int i=0;i<s.size();i++)if(s[i]!='5'){ans--;break;}
for(int i=0;i<s.size();i++){
    if(s[i]>'7')ans++;
   
    
    if(s[i]!='7')break;

}
ans++;
for(int i=0;i<s.size();i++)if(s[i]!='7'){ans--;break;}
cout<<ans;
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int l;
int a[200005];
int cost[200005][5];
int dp[200005][5];

signed main(){
	scanf("%ld", &l);
	for(int i = 1; i <= l; i++){
		scanf("%ld", &a[i]);
		cost[i][0] = cost[i][4] = a[i];
		cost[i][1] = cost[i][3] = (a[i] == 0) ? 2 : (a[i] % 2);
		cost[i][2] = (a[i]+1) % 2;
	}
	for(int i = 1; i <= l; i++){
		for(int j = 0; j < 5; j++){
			dp[i][j] = LINF;
			for(int k = 0; k <= j; k++){
				dp[i][j] = std::min(dp[i][j], dp[i-1][k] + cost[i][j]);
			}
		}
	}
	int ans = LINF;
	for(int i = 0; i < 5; i++){
		ans = std::min(ans, dp[l][i]);
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 17408
from collections import deque
import itertools

H , W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
acu = [0] + list(itertools.accumulate(a))
ans = [[0] * W for _ in range(H)]
cnt = 1
jdg = 1

for h in range(H):
    if h % 2 == 1:
        for w in range(W):
            #print(jdg)
            ans[h][w] = jdg
            if cnt >= acu[jdg]:
                jdg += 1
            cnt += 1
    if h % 2 == 0:
        for w in reversed(range(W)):
            #print(jdg)
            ans[h][w] = jdg
            if cnt >= acu[jdg]:
                jdg += 1
            cnt += 1
for i in range(H):
    print(*ans[i])

Measured memory_bytes: 4596
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -----------------------------------------------------------------------

// -----------------------------------------------------------------------

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int r=0,b=0;
	for(int i=0;i<n;++i)
	if(s[i]=='R')
	r++;
	else
	b++;
	if(r>b)
	cout<<"Yes";
	else
	cout<<"No";
		
	
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

lcm = reduce(lambda x,y: y//gcd(x,y)*x, A)

answer = sum(lcm//x for x in A)
answer %= MOD
print(answer)


Measured memory_bytes: 6008
#include <stdio.h>

int main(void)
{
  int N,i,j,n[1001][6];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    for(j=0;j<3;j++){
      scanf("%d",&n[i][j]);
      n[i][j+3] = n[i][j];
    }
    for(j=0;j<3;j++)
      if(n[i][j]*n[i][j]==n[i][j+1]*n[i][j+1]+n[i][j+2]*n[i][j+2])
	break;
    if(j==3) puts("NO");
    else puts("YES");
  }
  return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S, T; cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < 3; ++i) {
    if (S[i] == T[i]) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3604
from heapq import heappush ,heappop
n,k=map(int,input().split())
p=list(map(int,input().split()))
cnt=1
flag=[1]*n
for i in range(1,n):
    if p[i]>p[i-1]:
        cnt+=1
        flag[i]=cnt
    else:
        cnt=1
h=flag.count(k)
if h!=0:
    h-=1
lst_m=[]
lst_M=[]
for i in range(k):
    heappush(lst_m,p[i])
    heappush(lst_M,-p[i])
data_m=[]
data_M=[]
count=0
for i in range(n-k):
    m=lst_m[0]
    M=lst_M[0]
    heappush(lst_m,p[k+i])
    heappush(lst_M,-p[k+i])
    heappush(data_m,p[i])
    heappush(data_M,-p[i])
    if p[i]==lst_m[0]:
        while data_m[0]==lst_m[0]:
            heappop(data_m)
            heappop(lst_m)
            if not data_m:
                break
        if -p[k+i]==lst_M[0]:
            count+=1
    if -p[i]==lst_M[0]:
        while data_M[0]==lst_M[0]:
            heappop(data_M)
            heappop(lst_M)
            if not data_M:
                break
print(n-k+1-count-h)

Measured memory_bytes: 120272
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vll l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll count=0;
    rep(i,n){
        repi(j,i+1,n){
            repi(k,j+1,n){
                if(l[i]!=l[j]&&l[j]!=l[k]&&l[k]<l[i]+l[j]) count++;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define m 1000000007
#define N 50
using namespace std;
int n;
struct M{
    int adj[N][N];
    M operator*(const M&b) const{
        M c = M();
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                long long su=0LL;
                for(int k=0;k<n;k++){
                    su = (su+(adj[i][k]*1LL*b.adj[k][j])%m)%m;
                }
                c.adj[i][j]=su;
            }
        }
        return c;
    }
    int sum(){
        long long ans = 0LL;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                ans+=adj[i][j];
                ans%=m;
            }
        }
        return ans;
    }

};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long k;
    cin>>n>>k;
    M a = M();
    M res = M();
    for(int i=0;i<n;i++)res.adj[i][i] = 1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a.adj[i][j];
    while(k){
        if(k%2)res=res*a;
        a = a*a;
        k>>=1;
    }   
    cout<<res.sum()<<"\n";
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn point(p: i32, xs: &Vec<i32>) -> i32 {
    let it = xs.iter();
    it.map(|x| (p - *x).pow(2)).sum()
}

fn solve(xs: &Vec<i32>) -> i32 {
    (1..101).map(|x| point(x, xs)).min().unwrap()
}

#[test]
fn test_solve() {
    assert_eq!(solve(&vec![1, 4]), 5);
    assert_eq!(solve(&vec![14, 14, 2, 13, 56, 2, 37]), 2354);
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let xs: Vec<i32> = (0..n).map(|_| { iter.next().unwrap().parse().unwrap() }).collect();
    println!("{}", solve(&xs));
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,m,k;
    string ans="No";
    vector<lli> gvec,kvec;
    lli i,j;
    cin>>n>>m>>k;
    rep(i,0,n+1){
        rep(j,0,m+1){
            if(k==(i*(m-j)+j*(n-i))){
                ans="Yes";
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 998244353 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s;
int dp[MAX];
int h[MAX];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//   freopen("test.in","r",stdin);

    cin>>n;

    for(int i = 0 ; i < n ; ++i)
        cin>>h[i];

    dp[0] = 0 ;
    dp[1] = abs(h[1] - h[0]);

    for(int i = 2 ; i < n ; ++i)
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));

    cout<<dp[n - 1]<<'\n';

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<sstream>
#include<iomanip>

using namespace std;

#define INF 999999999

int in[100002];

int main(){
	long long int ans=0, ins=0;
	int N, L, i, j;
	cin >> N >> L;
	in[0] = 0;
	for(i=1;i<=N;i++)cin >> in[i];
	in[N+1] = 0;
	for(i=1;i<=N;i++){
		if(in[i-1] < in[i]) ins = L - in[i];
		else ins += L - in[i];
		if(ins > ans) ans = ins;
	}
	for(i=N;i>=1;i--){
		if(in[i] > in[i+1]) ins = L - in[i];
		else ins += L - in[i];
		if(ins > ans) ans = ins;
	}
	
	cout << ans << endl;
	return 0;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

#define INF 1000000000000000

using namespace std;

int n, m;
ll cost[1010];
ll open[1010];

ll DP[1010][9195];

ll solve(int i, int mask) {
    if(i > m) {
        if(__builtin_popcount(mask) == n) return 0;
        else return INF;
    }
    if(DP[i][mask] != -1) return DP[i][mask];
    return DP[i][mask] = min(solve(i+1, mask), cost[i] + solve(i+1, mask | open[i]));
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(DP, -1, sizeof DP);

    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        cost[i] = a;
        ll op = 0;
        for(int j = 0; j < b; j++) {
            int x;
            cin >> x;
            op = op | (1 << (x-1));
        }
        open[i] = op;
    }
    ll ans = solve(0, 0);
    if(ans >= INF) {
        cout << -1 << endl;
    }else {
        cout << ans << endl;
    }
}


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

typedef long long ll;


int main(void){
    int N;
    char S[110];
    scanf("%d",&N);
    if(N%2==1){
        printf("No");
        return 0;
    }
    int i;
    scanf("%s", &S);
    for(i=0; i < N/2; i++){
        if(S[i]!=S[i+N/2]){
            printf("No");
            return 0;
        }
    }

    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
n = int(input())
H = list(map(int,input().split()))

ans = 0
tmp = 0
max_h = max(H)
for i in range(max_h,0,-1):
    H_c = H.copy()
    if H[0]==i:
        ans+=1
        H_c[0]-=1
    for j in range(1,n):
        if H[j]==i:
            if H[j-1]!=H[j]:
                ans+=1
                H_c[j]-=1
            else:
                H_c[j]-=1
    H = H_c
print(ans)

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    string S;
    cin >> S;

    int K;
    cin >> K;

    for (int i = 0; i < K; i++) {
        if (S[i] != '1') {
            cout << S[i];
            return 0;
        }
    }

    cout << S[K-1] << endl;

}






















































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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << max(max(a+b, a-b), a*b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, b = 0, c = 1, d = 0, e = 0;
	cin >> n;
	int a[123456];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int h = 1; h <= n / 2; h++) {
		c = c * 2 % 1000000007;
	}
	if (n % 2 == 0) {
		for (int h = 0; h < n - 1; h++) {
			if (h % 2 == 0) {
				if (a[h] == a[h + 1]) {
					if (h == 0) {
						if (a[h] == 1) {
							b++;
						}
					}
					else {
						b++;
					}
				}
			}
			else {
				if (a[h] + 2 == a[h + 1]) {
					b++;
				}
			}
		}
		if (b == n - 1) {
			cout << c << endl;
			d++;
		}
	}
	else {
		for (int h = 0; h < n - 1; h++) {
			if (h % 2 == 1) {
				if (a[h] == a[h + 1]) {
						e++;
				}
			}
			else {
				if (a[h] + 2 == a[h + 1]) {
					if (h == 0) {
						if (a[h] == 0) {
							e++;
						}
					}
					else {
						e++;
					}
				}
			}
		}
		if (e == n - 1) {
			cout << c << endl;
			d++;
		}
	}
	if (d == 0) {
		cout << '0' << endl;
	}
	cin >> e;
}

Measured memory_bytes: 640
N, K = [int(_) for _ in input().split()]
P = [int(_) - 1 for _ in input().split()]
C = [int(_) for _ in input().split()]


X = [False for _ in range(N)]

V = []
for i in range(N):
    if X[i]:
        continue
    t = i
    v = []
    while X[t] is False:
        X[t] = True
        v.append(C[t])
        t = P[t]
    V.append(tuple(v))

def f(v, K):
    if K == 0:
        return 0
    if max(v) < 0:
        return max(v)
    n = len(v)

    X = [0]
    for i in range(n):
        X.append(X[-1] + v[i])
    ans = -100000000000
    for i in range(n + 1):
        for j in range(i):
            if i - j > K:
                continue
            ans = max(ans, X[i] - X[j])
    return(ans)

ans = -100000000000
for v in V:
    n = len(v)
    if K > n:
        s = sum(v)
        if s > 0:
            x = s * (K // n) + f(v * 2, K % n)
            y = s * (K // n - 1) + f(v * 2, n)
            a = max(x, y)
        else:
            a = f(v * 2, n)
    else:
        a = f(v * 2, K)
    ans = max(a, ans)

print(ans)


Measured memory_bytes: 74792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='0')ans++;
    }
    ans=min(ans,(ll)Size(s)-ans);
    Cout(ans*2);
    return 0;
}

Measured memory_bytes: 512
n=int(input())
a=(n*(n+1))//2
z=n%3
x=n-z
x=x//3
s1=((x*(x+1))//2)*3
z=n%5
x=n-z
x=x//5
s2=((x*(x+1))//2)*5
z=n%15
x=n-z
x=x//15
s3=((x*(x+1))//2)*15
print (a-s1-s2+s3)

Measured memory_bytes: 8996
n = int(input())
a = [int(i) for i in input().split()]
num,answer1= a[0],0
if a[0]==0:
	num,answer1 = 1,1
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer1 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
if a[0]==0: num,answer2 = -1,1
else: num,answer2 = -a[0]//abs(a[0]),abs(a[0]-(-a[0]//abs(a[0])))
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer2 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
print(min(answer1,answer2))


Measured memory_bytes: 14468
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

/* ------------------------------ TEMPLATE BEGIN ------------------------------ */

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

/* ----------------- ORDERED SET (POLICY BASED DS) ----------------- */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree
    <T, null_type, less<T>, rb_tree_tag, 
    tree_order_statistics_node_update>;

/* -------------- BETTER RANDOM (RAND() IS DANGEROUS) -------------- */
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

/* ----------------- CUSTOM HASH FUNCTION FOR UMAP ----------------- */
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = 
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/* ----------------------- DEBUGGING UTILITY ----------------------- */
#define cerr cout
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {
    cerr << t; if(sizeof...(v)) cerr << ", "; _print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define rrep(i, x, n) for (ll i = (ll)(x); i >= (ll)(n); i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define bs binary_search
#define minSelf(a, b) a = min(a, b)
#define maxSelf(a, b) a = max(a, b)
#define mem(arr, x) memset(arr, x, sizeof(arr))
using ll = long long int;
using ld = long double;
template <typename T, typename V> using P = pair<T, V>;
template <typename T> using V = vector<T>;
const ll MOD = 998244353;
const ll INF = 0x3f3f3f3f; // ~1e9 (1061109567)
const ld PI = 3.1415926535897932384626;
const ld EPS = 1e-9;
#define endl '\n' // REMOVE FOR INTERACTIVE TASKS
const ll MAX = 3e5+5;

/* ------------------------------- TEMPLATE END ------------------------------- */

void solve() {
    ll n, ans = 0;
    cin >> n;
    V<ll> v(n), m(n+1, 0);
    rep(i, 0, n) cin >> v[i], m[v[i]]++;
    rep(i, 1, n+1) ans += m[i]*(m[i]-1)/2;
    rep(i, 0, n) cout << ans-m[v[i]]+1 << endl;
}

int main() {
    boost
    ll t = 1;
    // cin >> t;
    while(t--) solve();
}


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int h,w,k;
    cin>>h>>w>>k;
    int cnt = 0;
    string s[h];
    rep(i,h)cin>>s[i];
    int c = 1;
    vector<vector<int>> ans(h,vector<int>(w));
    int mi = h+1;
    rep(i,h){
        bool ok = false;
        rep(j,w)if(s[i][j]=='#')ok=true;
        if(!ok)continue;
        int j = 0;
        while(s[i][j]!='#')ans[i][j++]=c;
        --c;
        while(j<w){
            if(s[i][j]=='#')++c;
            ans[i][j]=c;
            ++j;
        }
        ++c;
        mi = min(i,mi);
    }
    int la = -1;
    rep(i,h){
        if(i<mi){
            rep(j,w)cout<<ans[mi][j]<<" ";
            cout<<endl;
        }
        else if(ans[i][0]==0){
            rep(j,w)cout<<ans[la][j]<<" ";
            cout<<endl;
        }
        else {
            rep(j,w)cout<<ans[i][j]<<" ";
            cout<<endl;
            la=i;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int x;
    cin >> x;
    if(x < 30) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    double d;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        d += 1.0 / a;
    }
    cout << setprecision(7) << 1.0 / d << endl;
}


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

int main() {
	int n, x = 0, ans = 0;
	char c;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> c;
		if (c == 'D') x--;
		else x++;

		ans = max(x, ans);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <string>

#define YES "YES"
#define NO "NO"
#define space ' '

using namespace std;

void func();

int main(void)
{
	
	func();

	return 0;
}


void func()
{
	

	int n, cnt;
	
	while (cin >> n, !cin.eof()){
		cnt = 0;

		for (int i = 0; i < 10; i++)
		{
			for (int ii = 0; ii < 10;ii++)
			{
				for (int iii = 0; iii < 10;iii++)
				{
					for (int iiii = 0; iiii < 10;iiii++)
					{
						if ((i + ii + iii + iiii) == n)
						{
							cnt++;
							break;
						}

					}
				}
			}
		}

		cout << cnt << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax = 210000;

ll N;
ll a[Nmax], b[Nmax], c[Nmax];
ll ans = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) if (i < N) cin >> a[i];
	for (int i = 0; i < N; i++) if (i < N) cin >> b[i];
	
	for (ll k = 0; k < 30; k++) {
		ll T = (1ll << k);
		for (int i = 0; i < N; i++) c[i] = b[i] % (2 * T);
		sort(c, c + N);

		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			ll a_k = a[i] % (2 * T);
			cnt += lower_bound(c, c + N, 2 * T - a_k) - lower_bound(c, c + N, T - a_k);
			cnt += lower_bound(c, c + N, 4 * T - a_k) - lower_bound(c, c + N, 3 * T - a_k);
		}
		if (cnt % 2 == 1) ans += T;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
string s, t;
int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a % b);
}
int main(){
    cin >> n >> m;
    cin >> s >> t;
    int g = gcd(n, m);
    ll ans = 1ll * n * m / g;
    ll a = ans / n;
    ll b = ans / m;
    for (int i = 0, j = 0; i < n && j < m; i += b, j += a){
        if( s[i] != t[j] ){
            puts("-1");
            return 0;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

const int MOD = 1e5;

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> list(n);
    for(int i = 0; i < n; i++)
    {
        cin >> list[i];
    }
    vector<int> s;
    vector<int> ord(n + 1, -1);
    int c = 1, l = 0;
    {
        int v = 1;
        while (ord[v] == -1)
        {
            ord[v] = s.size();
            s.push_back(v);
            v = list[v - 1];
        }
        c = s.size() - ord[v];
        // cout << s.size() << " " <<  ord[v] << endl;
        l = ord[v];
    }

    if (k < l)
        cout << s[k] << endl;
    else
    {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5824
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        long[] ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var a = ab[0];
        var b = ab[1];
        long ans = 0;

        IEnumerable<long> alist = PrimeFactors(a);
        IEnumerable<long> blist = PrimeFactors(b);
        var set1 = new HashSet<long>(alist);
        var set2 = new HashSet<long>(blist);

        ans = set1.Intersect(set2).Count() + 1;
        // 出力
        Console.WriteLine(ans);
    }

    //素因数分解
    public static IEnumerable<long> PrimeFactors(long n)
    {
        long i = 2;
        long tmp = n;

        while (i * i <= n)
        {
            if (tmp % i == 0)
            {
                tmp /= i;
                yield return i;
            }
            else
            {
                i++;
            }
        }
        if (tmp != 1) yield return tmp;//最後の素数も返す
    }
}

Measured memory_bytes: 28292
# -*- coding: utf-8 -*-

def main():
    list1 = [1, 3, 5, 7, 8, 10, 12]
    list2 = [4, 6, 9, 11]
    list3 = [2]
    x, y = map(int, input().split())
    print('Yes' if x in list1 and y in list1 or x in list2 and y in list2 else 'No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (l) < (x) && (x) < (r)

int main() {
    int N;
    cin >> N;
    map<int,int> A;
    int max_A = 0;
    rep(i,0,N) {
        int a;
        cin >> a;
        max_A = a > max_A ? a : max_A;
        if (A.count(a)) A[a]++;
        else A[a] = 1;
    }
    vector<bool> sat(max_A+1,true);
    sat[0] = false;
    for (auto v : A) {
        auto key = v.first;
        auto value = v.second;
        if (!sat[key]) continue;
        key *= 2;
        while (key <= max_A) {
            sat[key] = false;
            key += v.first;
        }
    }

    int ans = 0;
    for (auto v : A) {
        auto key = v.first;
        if (v.second > 1) continue;
        if (sat[key]) ans++;
    }
    cout << ans << endl;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

#define N 500010
#define MOD 1000000007

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n, k;
    cin >> n >> k;

    int ans = INT_MAX, pos = 0;
    int a[n] = {};
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] == 1)
            pos = i;
    }    

    for (int i = 0; i < k; ++i)
    {
        int le = max(pos - i, 0ll);
        int ri = max(0ll, (n - 1 - (pos + k - i  - 1)));
        int k1 = (le + k - 2) / (k - 1);
        k1 += (ri + k - 2) / (k - 1);
        k1 += 1;
        ans = min(ans, k1);
    }

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

Measured memory_bytes: 4368
#include<iostream>

using namespace std;

struct Point{
  int x;
  int y;
};

const int MAX_M = 201;
const int MAX_N = 1001;

Point wanted[MAX_M];
Point input[MAX_N];
int m,n;


bool find(int px, int py){

  for(int i = 0; i < n; i++)
    if(input[i].x == px && input[i].y == py) return true;

  return false;
}

bool isStar(Point base){
  for(int i = 1; i < m; i++)
    if(!find(base.x+wanted[i].x-wanted[0].x,base.y+wanted[i].y-wanted[0].y)) return false;

  return true;
}

void solve(){
  Point ans;
  
  for(int i = 0; i < n; i++)
    if(isStar(input[i])) ans = input[i];

  cout << ans.x-wanted[0].x << " " << ans.y-wanted[0].y << endl;
}

int main(){
  while(cin >> m && m){
    
    for(int i = 0; i < m; i++)
      cin >> wanted[i].x >> wanted[i].y;
    
    cin >> n;
    for(int i = 0; i < n; i++)
      cin >> input[i].x >> input[i].y;
    
    solve();
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007�
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(5)<<fixed;
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	float tot = a[0];
	for(ll i=1;i<n;i++)
	{
		tot += a[i];
		tot/=2;
	}
 
	cout<<tot<<"\n";
	
	
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define MAXL 8005

char S[MAXL];
vector<int> v[2];
bool dp[MAXL][MAXL];

int main() {
	int L;
	int x[2];

	scanf("%s%d%d", S, x, x + 1);

	for(L = 0; S[L]; L++);
	int c = 0, lt = L;
	for(int i = L - 1; i >= 0; i--) if(S[i] == 'T') {
		v[c].push_back(lt - i - 1);
		c ^= 1;
		lt = i;
	}
	for(int i = 0; S[i] == 'F' && i < L; i++) x[0]--;
	if(c == 1) swap(x[0], x[1]);
	x[0] = abs(x[0]);
	x[1] = abs(x[1]);

	bool ans = true;
	for(int i = 0; i < 2; i++) {
		dp[0][0] = true;
		for(int j = 1; j <= L; j++) dp[0][j] = false;
		for(int j = 1; j <= v[i].size(); j++) for(int k = 0; k <= L; k++) {
			dp[j][k] = (k >= v[i][j - 1] && dp[j - 1][k - v[i][j - 1]]) || (k + v[i][j - 1] <= L && dp[j - 1][k + v[i][j - 1]]);
		}
		ans &= dp[v[i].size()][x[i]];
	}

	if(ans) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define MOD 1000000007
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n){
    cin >> a[i];
  }
  vector<ll> r(63);
  for(ll i = 1; i < n; i++){
    REP(j, 63){
      if(a[i] & (1LL << j)){
        r[j]++;
      }
    }
  }
  ll ans = 0;
  REP(i, n - 1){
    REP(j, 63){
      if(a[i] & (1LL << j)){
        ans += ((1LL << j) % MOD) * (n - 1 - i - r[j]) % MOD;
      }
      else{
        ans += ((1LL << j) % MOD) * r[j] % MOD;
      }
      ans %= MOD;
    }
    REP(j, 63){
      if(a[i + 1] & (1LL << j)){
        r[j]--;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n; cin >> n;
    string S; cin >> S;
    int idx;
    string ans = "";
    string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i = 0; i < S.size(); i++){
        //cout << S[i] << endl;
        idx = ALP.find(S[i]) + n;
        if(idx > 25) idx = idx - 26;
        ans += ALP[idx];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int A, B, ans;
    cin >> A >> B;

    ans = (A + B) / 2;

    if(abs(A-ans) == abs(B-ans)) {
        cout << ans << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256