akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...

int N;
void test_case(){
	cin >> N;
	if(N == 1) {cout << 0 << endl;return;}
	vector<int> v(N);
	for(auto & el  : v)	
		cin >> el;
	sort(all(v),greater<int>());
		
	ll ans = v[0];
	vector<int> circle;
	circle.push_back(v[1]);
	circle.push_back(v[1]);
	int pos = 0;
	
	for(int i = 2;i<N;++i){
		circle.push_back(v[i]);
		circle.push_back(v[i]);
		ans += circle[pos++];
	}
	cout << ans;
		
	
	
}
	
	


	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 6040
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,k;
  
  int H,W;
  
  scanf("%d %d",&H,&W);
  
  char str[H][W];
  int w[W],h[H];
  for(i = 0;i < H;i++){
    scanf("%s",str[i]);
    h[i] = 0;
  }
  
  for(i=0;i<W;i++)
    w[i]=0;
  
  
  for(i=0;i<W;i++){
    for(j=0;j<H;j++){
      if(str[j][i] == '#'){
        w[i] = 1;
        break;
      }
    }
  }
  
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(str[i][j] == '#'){
        h[i] = 1;
        break;
      }
    }
  }
      
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(w[j] == 1 && h[i] == 1)
        printf("%c",str[i][j]);
    }
    if(h[i] != 0)
    puts("");
  }
  
  return 0;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dp[301][301];

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

    int n;
    while(cin >> n, n) {
        int w[n];
        rep(i, n) cin >> w[i];
        memset(dp, 0, sizeof(dp));
        for(int i = n - 1; i >= 0; --i) {
            FOR(j, i + 1, n + 1) {
                if(i + 1 < j && abs(w[i] - w[j - 1]) <= 1 && dp[i + 1][j - 1] == j - i - 2) {
                    dp[i][j] = j - i;
                }
                FOR(k, j + 1, n + 1) {
                    chmax(dp[i][k], dp[i][j] + dp[j][k]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}

Measured memory_bytes: 3476
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
from math import gcd
from functools import reduce
from typing import Iterable
M = 10**6
def main(N, A):
    g = reduce(gcd, A)
    if g > 1:
        print('not coprime')
        return

    s = EratosthenesSieve(M)
    u = [False] * (M + 1)
    for a in A:
        for f in set(s.factor(a)):
            if u[f]:
                print('setwise coprime')
                return
            u[f] = True
    print('pairwise coprime')

class EratosthenesSieve:
    def __init__(self, max_n: int):
        f = list(range(max_n + 1))
        for i in range(2, int(max_n**0.5) + 1):
            if f[i] < i: continue
            for j in range(i * i, max_n + 1, i):
                if f[j] == j: f[j] = i
        self.f = f

    def is_prime(self, n: int) -> bool:
        return self.f[n] == n

    def factor(self, n: int) -> Iterable[int]:
        r, f = [], self.f
        while n > 1:
            m = f[n]
            r.append(m)
            n //= m
        return r

    def primes(self) -> Iterable[int]:
        return [x for i, x in enumerate(self.f) if i == x]

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n, k) ((n>>k)&1)

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


ll dp[2100000];


int main(){

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

    int n;
    cin >> n;
    int comp[n][n];
    rep(i, n){
        rep(j, n){
            cin >> comp[i][j];
        }
    }

    dp[0] = 1;
    for(int s = 1; s < 1<<n; ++s){
        int i = __builtin_popcount(s);
        for(int j = 0; j < n; ++j){
            if(bit(s, j) == 1 and comp[i-1][j] == 1){
                dp[s] += dp[s^(1<<j)];
                dp[s] %= MOD;
            }
        }
    }

    rep(i, n){
        cerr << dp[i] << endl;
    }


    ppp(dp[(1<<n)-1]);



    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[200100];
std::map<int, int> ma1, ma2;

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> A[i];
  }

  for(int i=1;i<N;++i){
      ma2[i-A[i]] += 1;
  }

  ll res = 0;

  for(int i=0;i<N;++i){
      res += ma1[i-A[i]];
      res += ma2[i+A[i]];
      ma1[i+A[i]] += 1;
      ma2[(i+1)-A[i+1]] -= 1;
  }

  res /= 2;

  std::cout << res << std::endl;
}


Measured memory_bytes: 38436
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val Bs = readLine()!!.split(" ").map(String::toInt)

    val As = Array(n) { Int.MAX_VALUE }

    Bs.withIndex().forEach { b ->
        if (b.value < As[b.index]) As[b.index] = b.value
        As[b.index + 1] = b.value
    }

    println(As.sum())
}

Measured memory_bytes: 37928
N = int(input())

count = [0, 0, 0, 0]
char = ["AC", "WA", "TLE", "RE"]
for i in range(N):
    get = input()

    for j in range(4):
        if get == char[j]:
            count[j] += 1

for k in range(4):
    print(char[k] + " x " + str(count[k]))

Measured memory_bytes: 9172
///////////////////////////////////////////////////////////////////////////
/*Dis = size of the program || TLE. */
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("unroll-loops") /* D = Too many loops */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d)                                                              \
  for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
       blockTime.second;                                                       \
       debug("%s: %lld ms\n", d,                                               \
             chrono::duration_cast<chrono::milliseconds>(                      \
                 chrono::high_resolution_clock::now() - blockTime.first)       \
                 .count()),                                                    \
            blockTime.second = false)

int main() {
  time__("Total Execution time is: ") {
    /*Code STARTS here */
    int size;
    cin >> size;

    char str[size];
    cin >> str;
    int count{};
    for (int i = 0; i <= (size-1)-2; i++)
    {
      if(str [i] == 'A' && str [i+1] == 'B' && str [i+2] == 'C')
      {
        count++;
      }

    }
    cout << count << endl;
    
    /*Code ENDS here */
  }
}


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

int main() {
    int *a = malloc(sizeof(int)), *b = malloc(sizeof(int));
    scanf("%d %d", a, b);
    int *z = malloc(sizeof(int));
    *z = 2*(*b) - *a;
    printf("%d\n", *z);
    return 0;
}


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

int main() {
  int n = 0;
  cin >> n;
  for(int i = 9; i > 0; --i) {
    if(n%i == 0 && n/i > 0 && n/i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

public class Main {
	
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	private Integer[] distance;
	private LinkedList<Integer> visited;
	//adjacency list of edges
	public Main() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		distance = new Integer[totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			distance[i] = -1;
		}
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt();
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public void getBFS(int s) {
		visited = new LinkedList<Integer>();
		distance[s-1] = 0;
		LinkedList<Integer> toVisit = new LinkedList<Integer>();
		toVisit.add(s);
		while (toVisit.size() > 0) {
			int v = toVisit.remove(0);
			visited.add(v);
			LinkedList<Integer> neighbors = adjList.get(v-1);
			for (int i = 0; i < neighbors.size(); i++) {
				int v1 = neighbors.get(i);
				if (visited.contains(v1) == false && toVisit.contains(v1) == false) {
					distance[v1-1] = distance[v-1] + 1;
					toVisit.add(v1);
				}
			}
		}
	}
	
	public static void main(String args[]) {
		Main b = new Main();
		b.loadAdjList();
		b.getBFS(1);
		for (int i = 0; i < b.distance.length; i++) {
			System.out.println(i+1 + " " + b.distance[i]);
		}
	}
}



Measured memory_bytes: 28488
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const int N=2e5+5;
int n,k,c,sum[N],f[N],g[N];
string s;

bool check(int l,int r)
{
    return (s[r]-s[l-1]==r-l+1);
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k>>c>>s;
    s=" "+s;
    for(int i=1;i<=n;i++)
    {
        f[i]=f[i-1];
        if(s[i]=='o') f[i]=max(f[i],f[max(i-1-c,0ll)]+1);
    }
    for(int i=n;i>=1;i--)
    {
        g[i]=g[i+1];
        if(s[i]=='o') g[i]=max(g[i],g[i+1+c]+1);
    }
    vector<int>res;
    for(int i=1;i<=n;i++)
    {
        if(f[i-1]+g[i+1]==k-1) cout<<i<<'\n';
    }
}


Measured memory_bytes: 5968
package main

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

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	e := make([]int, n*3) // e[3*i+j]
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			sc.Scan()
			e[3*i+j], _ = strconv.Atoi(sc.Text())
		}
	}
	dp := make([]int, (n+1)*3) // dp[3 * i + j]
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				dp[3*(i+1)+j] = max(dp[3*(i+1)+j], dp[3*i+k]+e[3*i+j])
			}
		}
	}
	ans := max(max(dp[3*n+0], dp[3*n+1]), dp[3*n+2])
	fmt.Println(ans)
}


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

int main() {
  int n;
  cin >> n;
  set<int> s;
  s.insert(n);
  
  int x = 0;
  for(int i=2; ; i++) {
    if(n%2 == 0) n /= 2;
    else n = 3*n + 1;
    x = s.size();
    s.insert(n);
    if(x == s.size()) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3644
var cnt;
function insertionSort(arr, n, g) {
  var j, v;
  for(let i = g; i < n; i++) {
    v = arr[i];
    j = i - g;
    while(j >= 0 && arr[j] > v) {
      arr[j + g] = arr[j];
      j -= g;
      cnt++;
    }
    arr[j + g] = v;
  }
}
function shellSort(arr, n) {
  cnt = 0;
  var m = 1;
  var g_arr = [];
  while(m <= n) {
    g_arr.unshift(m);
    m *= 2;
  }
  console.log(g_arr.length);
  console.log(g_arr.join(" "));
  for(let i = 0; i < m; i++) {
    insertionSort(arr, n, g_arr[i]);
  }
  console.log(cnt);
  console.log(arr.join("\n"));
  // Time comsuming
  /*
  for(let i = 0; i < n; i++) {
    console.log(arr[i]);
  }
  */
}
function Main(input) {
  input = input.split("\n").map(Number);
  var n = input[0];
  var arr = input.slice(1);
  shellSort(arr, n);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

const int M = 10;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> switches(n);
    for (int i=0; i<m; i++) {
        int k;
        cin >> k;
        for (int j=0; j<k; j++) {
            int s;
            cin >> s;
            s--;
            switches[s].push_back(i);
        }
    }
    vector<int> remainders(m);
    for (int i=0; i<m; i++) cin >> remainders[i];
    int ans = 0;
    for (int i=0; i < (1 << n); i++) {
        bitset<M> bit(i);
        vector<int> each_bulb(m);
        for (int j=0; j<n; j++) {
            if (bit[j]) {
                for (int k: switches[j]) each_bulb[k] = 1 - each_bulb[k];
            }
        }
        bool all = true;
        for (int i=0; i<m; i++) {
            if (each_bulb[i] != remainders[i]) all = false;
        }
        if (all) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define node0 -1
int depth(int);
int degree(int);
typedef struct{
  int p,r,l;
}Node;
Node T[N];


int main(){
  int i,n,k,id,j,c,keep;  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=node0;
    T[i].r=node0;
    T[i].l=node0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      T[c].p=id;
      if(j==0){
	T[id].l=c;
      }
      else{
	T[keep].r=c;
      }
      keep=c;   
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,depth(i));
    if(T[i].p==node0){
      printf("root, [");
    }
    else if(T[i].l==node0){
      printf("leaf, [");
    }
    else{
      printf("internal node, [");
    }
    degree(T[i].l);
    printf("]\n");
  }
  return 0;
}
int depth(int nodeNum){
  int count=0;
  if(T[nodeNum].p==node0){
    return 0;
  }
  else{
    count=depth(T[nodeNum].p)+1;
    return count;
  }
}
int degree(int treeNum){
  if(treeNum==node0){
    return 0;
  }
  else{
    if(T[treeNum].r==node0){
      printf("%d",treeNum);
    }
    else{
      printf("%d, ",treeNum);
      degree(T[treeNum].r);
    }
  }
}

Measured memory_bytes: 1784
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;

class DisjointSet{
 public:
  vector<int> rank, p, w;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size, 0);
    p.resize(size, 0);
    w.resize(size, 0);
    for(int i=0; i<size; i++) makeSet(i);
  }

  void makeSet(int x){
    p[x] = x;
    rank[x] = 0;
    w[x] = 0;
  }

  void unite(int x, int y){
    link(findSet(x).first, findSet(y).first);
  }

  void uniteW(int x, int y, int v){
    pair<int, int> px = findSet(x);
    pair<int, int> py = findSet(y);
    if ( px.first == py.first ) return;
    x = px.first;
    y = py.first;
    if ( rank[x] < rank[y] ){
      p[x] = y;
      w[x] = (v - px.second + py.second);
    } else {
      p[y] = x;
      w[y] = -(v - px.second + py.second);
      if ( rank[x] == rank[y] ) rank[x]++;
    }
  }

  bool same(int x, int y){
    return findSet(x).first == findSet(y).first;
  }
 int getDiff(int x, int y){
    return findSet(x).second - findSet(y).second;
  }

  void link(int x, int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]){
        rank[y] = rank[y] + 1;
      }
    }
  }

  pair<int, int> findSet(int x){
    if(x != p[x]){
      pair<int,int> tmp =  findSet(p[x]);
      p[x] = tmp.first;
      w[x] += tmp.second;
    }
    return make_pair(p[x], w[x]);
  }
};

int main(){
  int N, M;
  char com;
  int  a, b, w;

  while(1){
    cin >> N >> M;
    if ( N == 0 && M == 0 ) break;

    DisjointSet ds = DisjointSet(N);

    for ( int i = 0; i < M; i++ ){
      cin >> com;
      if ( com == '!' ){
        cin >>  a >> b >> w; a--; b--;
        ds.uniteW(a, b, w);
      } else if ( com == '?' ){
        cin >> a >> b; a--; b--;
        if ( ds.same(a, b) ) {
          cout << ds.getDiff(a, b) << endl;
        } else {
          cout << "UNKNOWN" << endl;
        }
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  ll n;
  cin >> n;
  if(n%2==1)cout << 0 << endl;
  else if(n%2==0){
    ll a=5;
    vector<ll>b;
    b.push_back(0);
    for(int i=1;a<n;i++){
      b.push_back(n/a/2);
      a*=5;
    }
    int N=b.size();
    for(int i=1;i<N-1;i++)b[i]-=b[i+1];
    ll sum=0;
    rep(i,N)sum+=(ll)i*b[i];
    cout << sum << endl;
  }
}
   




Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){ 
	int count = 0 ,i,kakunin;
	char w[11],t[1001];
	scanf("%s",w);
	//kakunin = strlen(w);
	//printf("%s",kakunin);
	for(i = 0;i < strlen(w);i++){
		if(islower(w[i])){
			w[i] = toupper(w[i]);
		}
	}
	//printf("%s\n",w);
	while(1){
		scanf("%s",t);
		if(strstr(t,"END_OF_TEXT") != NULL)break;
		for(i = 0;i < strlen(t);i++){
			if(islower(t[i])){
				t[i] = toupper(t[i]);
			}
		}
		//printf("%s\n",t);
		if(strcmp(t,w) == 0){
			count++;
		}
	}
	//kakunin = strcmp("AIU","aiu");
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 556
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=1000;
int main()
{
  int n,k,i,res=0;
  int p[N_MAX];
  cin >> n >> k;
  for(i=0;i<n;i++)
    cin >> p[i];
  sort(p,p+n);
  for(i=0;i<k;i++)
    res+=p[i];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3636
import math

n = int(input())
minresult = 0

def gen(num):
   if num < 10:
      return(num)
   else:
      data_size = int(math.log10(num) + 1)
      sum = 0
      for i in range(data_size):
         digit = num // 10**(data_size - i - 1)
         sum += digit
         num -= digit * 10**(data_size - i - 1)
      return(sum)

for j in range(n - 1):
   A = gen(j + 1)
   B = gen(n - j - 1)
   result = A + B
   if minresult == 0 or result < minresult:
      minresult = result

print(minresult)
   
   

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

ll RS(ll x,ll y,ll mod){
    if(y==0) return 1;
    else if(y&1) return x*RS(x,y-1,mod)%mod;
    else{
        ll p=RS(x,y/2,mod);
        return p*p%mod;
    }
}

int main(){
    ll n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll si=s.size();
    if(p==2||p==5){
        ll ans=0;
        rp(i,si){
            if((s.at(i)-'0')%p==0)
            ans+=i+1;
        }
        cout << ans << endl;
        return 0;
    }
    reverse(s.begin(),s.end());
    vector<ll> summod(si+1,0);
    for(ll i=1; i<=n; i++){
        summod.at(i)=summod.at(i-1)+(s.at(i-1)-'0')*RS(10,i-1,p);
        summod.at(i)%=p;
    }
    
    sort(summod.begin(),summod.end());
    
    ll ctr=1;
    ll ans=0;
    rp(i,si){
        if(summod.at(i)==summod.at(i+1)) ctr++;
        else{
            ans += ctr*(ctr-1)/2;
            ctr=1;
        }
    }
    ans+=ctr*(ctr-1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple


void solve(vector<pair<int,int>>& ans, vector<ll>& A, int N) {
    // 全部に最大値を足して、全部+にする
    auto mxItr = max_element(ALL(A));
    auto mxIdx = mxItr - A.begin();
    REP(i, N) {
        if (i != mxIdx) {
            ans.pb(mp(mxIdx, i));
        }
    }
    FOR(i, 1, N) {
        ans.pb(mp(i-1, i));
    }
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    ll mn = 1e9;
    ll mx = -1e9;
    REP(n,N) {
        cin >> A[n];
        mn = min(mn, A[n]);
        mx = max(mx, A[n]);
    }

    vector<pair<int,int>> ans;
    if (abs(mx) > abs(mn)) {
        solve(ans, A, N);

        cout << SIZE(ans) << endl;
        for(auto a: ans) {
            cout << (a.first + 1) << " " << (a.second + 1) << endl;
        }
    }
    else {
        vector<ll> B(N);
        REP(n,N) {
            B[n] = -A[N-n-1];
        }
        solve(ans, B, N);

        cout << SIZE(ans) << endl;
        for(auto a: ans) {
            auto f = a.first;
            auto s = a.second;
            f = N - f - 1;
            s = N - s - 1;
            cout << (f + 1) << " " << (s + 1) << endl;
        }
    }

    return 0;
}


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

int main(void){

    long long A,B,C;
    cin >> A >> B >> C;
    long long D = C - A - B; 
    string ans ="No";
    if(D > 0 && D*D > 4 * A * B)ans = "Yes";

    cout << ans <<endl;
}

Measured memory_bytes: 3620
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	fmt.Fprintln(writer, fmt.Sprintf("%d %d", minint(a, b), maxint(a+b-n, 0)))
}

func minint(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func maxint(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 640
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){ 
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_set<string> w;
  unordered_set<string> a;
  unordered_set<string> ans;
  for (char cur: s){
    w = a;
    for (auto c: w){
      if (len(c) < 2){
        a.insert(c+cur);
      } else {
        ans.insert(c+cur);
      }
    }
    string t;
    t += cur;
    a.insert(t);
  }

  cout << len(ans);
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 



9 8 7 10 5 6 3 4 2 1 * 9 8 7 10 5 6 3 4 2 1 * 9 8 7 10 5 6 3 4 2 1

 */

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q;
  cin >> N >> Q;
  dsu d(N);
  for (ll i = 0; i < Q; ++i) {
    ll t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    }
    else {
      if (d.same(u, v)) {
        cout << 1 << "\n";
      }
      else {
        cout << 0 << "\n";
      }
    }
  }
}


Measured memory_bytes: 3864
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
    int N;int K;cin>>N>>K;
    vector <int>  x(0);
    for(int i=0;i<N;i++){
        int aaa; cin>>aaa;
        x.push_back(aaa);
    }

    int ans = 990000000;

    for(int i=0;i+K-1 <= N-1 ; i++){

        
        if(x[i+K-1] <=0){
            ans = min(ans,abs(x[i]));
            continue;
        }

        if(x[i] >=0){
            ans = min(ans,x[i+K-1]);
            continue;
        }

        int pre = min(abs(x[i]*2) + x[i+K-1],abs(x[i]) + x[i+K-1]*2 );
        ans = min(ans,pre);

    }
    
    cout<<ans<<endl;
 


    return 0;
}

 



Measured memory_bytes: 892
N = int(input())
H = list(map(int,input().split()))
tot = 0
while True:
    if H[0]>0:
        cnt = 1
    else:
        cnt = 0
    for i in range(1,N):
        if H[i]>0 and H[i-1]==0:
            cnt += 1
    tot += cnt
    for i in range(N):
        if H[i]>0:
            H[i] -= 1
    flag = 0
    for i in range(N):
        if H[i]>0:
            flag = 1
            break
    if flag==0:break
print(tot)    

Measured memory_bytes: 67152
#include<stdio.h>
int main()
{
    int k,a,b,i,cnt=0;
    scanf("%d\n %d %d",&k,&a,&b);
    for(i=a;i<=b;i++){
        if(i%k==0)cnt++;
    }
    if(cnt>0){
        printf("OK\n");
    }
    else {
        printf("NG\n");
    }
    return 0;
}


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

lint k;

// a^nを計算　O(log n)
long long int powint(long long int a, long long int n) {
    if (n == 0) {
        return 1;
    } else {
        long long int temp = powint(a, n / 2);
        if (n % 2 == 0) {
            return temp * temp;
        } else {
            return temp * temp * a;
        }
    }
}

int main() {
    cin >> k;
    //[i][j]:iけた先頭jのルンルン数小さい順
    vector<vector<vector<lint>>> lunlun(11, vector<vector<lint>>(10));
    for (int i = 0; i < 10; i++) {
        lunlun[1][i].push_back(i);
    }
    set<lint> ans;
    // i桁
    for (int i = 2; i <= 10; i++) {
        //先頭j
        for (int j = 0; j < 10; j++) {
            if (j - 1 >= 0) {
                for (auto e : lunlun[i - 1][j - 1]) {
                    lunlun[i][j].push_back(powint(10, i - 1) * j + e);
                }
            }
            for (auto e : lunlun[i - 1][j]) {
                lunlun[i][j].push_back(powint(10, i - 1) * j + e);
            }
            if (j + 1 <= 9) {
                for (auto e : lunlun[i - 1][j + 1]) {
                    lunlun[i][j].push_back(powint(10, i - 1) * j + e);
                }
            }
        }
    }
    for (int i = 1; i <= 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (auto e : lunlun[i][j]) {
                ans.insert(e);
                if (ans.size() == k + 1) {
                    cout << e << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 6652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        if(n==100) {
            System.out.println((int)(Math.pow(100, d)*n+Math.pow(100, d)));
            return;
        }
        System.out.println((int)(Math.pow(100, d)*n));
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    int n,m,i,x,y,z;
    cin>>n>>m;
    int ans=(n*(n-1))/2 + (m*(m-1))/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

ll N;
vector<double> stable(4),upper(4),lower(4);
double score(double t){
    double xmax=max({stable[0],upper[0]+t,lower[0]-t});
    double xmin=min({stable[1],upper[1]+t,lower[1]-t});
    double ymax=max({stable[2],upper[2]+t,lower[2]-t});
    double ymin=min({stable[3],upper[3]+t,lower[3]-t});
    return (double)(xmax-xmin)*(ymax-ymin);
}

int main(){
    cout << fixed << setprecision(10);
    cin >> N;
    rep(i,4){
        if (i%2==0) stable[i]=-MOD,upper[i]=-MOD,lower[i]=-MOD;
        else stable[i]=MOD,upper[i]=MOD,lower[i]=MOD;
    }
    rep(i,N){
        double x,y;
        char d;
        cin >> x >> y >> d;
        if (d=='R'){
            chmax(upper[0],x),chmin(upper[1],x);
            chmax(stable[2],y),chmin(stable[3],y);
        }
        if (d=='L'){
            chmax(lower[0],x),chmin(lower[1],x);
            chmax(stable[2],y),chmin(stable[3],y);
        }
        if (d=='U'){
            chmax(stable[0],x),chmin(stable[1],x);
            chmax(upper[2],y),chmin(upper[3],y);
        }
        if (d=='D'){
            chmax(stable[0],x),chmin(stable[1],x);
            chmax(lower[2],y),chmin(lower[3],y);
        }
    }
    double ans=score(0);
    rep(i,2){
        rep(j,6){
            rep(k,2){
                double t;
                if (j<=1){
                    if (abs(stable[2*i+j])==MOD||abs(upper[2*i+k])==MOD) continue;
                    t=stable[2*i+j]-upper[2*i+k];
                }
                else if (j<=3){
                    if (abs(lower[2*i+j-2])==MOD||abs(upper[2*i+k])==MOD) continue;
                    t=(double)(lower[2*i+j-2]-upper[2*i+k])/2.0;
                }
                else if (j<=5){
                    if (abs(lower[2*i+k])==MOD||abs(stable[2*i+j-4])==MOD) continue;
                    t=(double)lower[2*i+k]-stable[2*i+j-4];
                }
                if (t<0) continue;
                chmin(ans,score(t));
            }
        }
    }
    cout << ans << endl;
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n; cin >> n;
	int m = n%10;
	if(m==3){
		cout << "bon" << endl;
		return 0;
	}
	else if(m==0 || m==1 || m==6 || m==8){
		cout << "pon" << endl;
		return 0;
	}else{
		cout << "hon" << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k;
	while (cin >> n && n)
	{
		cin >> k;
		vector<LL> sums(n);
		rep(i, n)
		{
			cin >> sums[i];
			if (i != 0)
				sums[i] += sums[i - 1];
		}
		LL ans = sums[k];
		for (int i = 0; i + k < n; i++)
		{
			ans = max(ans, sums[i + k - 1] - sums[i - 1]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1788
import java.util.*;

public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static class Triple implements Comparable<Triple> {
	// 	public int A, B, C;
	// 	Triple(int A, int B, int C) {
	// 		this.A = A;
	// 		this.B = B;
	// 		this.C = C;
	// 	}

	// 	@Override
	// 	public String toString() {
	// 		return String.format("(%d, %d, %d)", A, B, C);
	// 	}

	// 	@Override
	// 	public int compareTo(Triple o) {
	// 		int a = this.A - o.A;
	// 		if (a != 0) return a;
	// 		int b = this.B - o.B;
	// 		if (b != 0) return b;
	// 		return this.C - o.C;
	// 	}
	// }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		double A = 1.0 * W * H / 2;
		int B = (x * 2 == W && y * 2 == H) ? 1 : 0;
		System.out.println(A + " " + B);
	}
}


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

int main(){
   string s,t;
   cin >> s >> t;
   sort(s.begin(),s.end());
   sort(t.begin(),t.end());
   reverse(t.begin(),t.end());
   for (int i=0;i<min(s.size(),t.size());i++){
      if (s.at(i)<t.at(i)){
          	cout << "Yes" << endl;
          	return 0;
      }
    	else if (s.at(i)>t.at(i)) {
          	cout << "No" << endl;
            return 0;
      }
      if (i==t.size()-1) {
         cout << "No" << endl;
         return 0;
      }
      if (i==s.size()-1){
         cout << "Yes" << endl;
         return 0;
      }
   }
}


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

struct Solver {
	void solve() {
		long double A, B;
		cin >> A >> B;
		cout << (long long)(A*B) << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (N * A > B) {
    cout << B << endl;
  } else {
    cout << N * A << endl;
  }
  return 0;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = read_vec();

    a.sort();

    let maxa = a[n - 1];

    let mut dp: Vec<bool> = vec![false; maxa + 1];

    let mut rem: Vec<usize> = vec![];

    for i in 1..n {
        if a[i] == a[i - 1] {
            rem.push(a[i]);
        }
    }

    for i in 0..n {
        dp[a[i]] = true;
    }

    for i in 1..maxa {
        if dp[i] {
            for j in 2..maxa / i + 1 {
                dp[j * i] = false;
            }
        }
    }

    for r in rem {
        dp[r] = false;
    }

    let mut ans = 0;
    for b in dp {
        if b {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 7732
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
long long MAX(long long a,long long b){
    return a>b?a:b;
}
int main()
{   char s[4];
    scanf("%s",s);
    if(s[0]==s[1]&&s[1]==s[2]){
        printf("No");
    }else{
        printf("Yes");
    }
    
    
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Integer Cards
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            List<Card> cards = new ArrayList<>();

            for (int i = 0; i < N; i++) {
                long A = sc.nextLong();
                cards.add(new Card(A, 1));
            }

            for (int i = 0; i < M; i++) {
                int B = sc.nextInt();
                long C = sc.nextLong();
                cards.add(new Card(C, B));
            }

            Collections.sort(cards, (o1, o2) -> Long.compare(o2.number, o1.number));

            long sum = 0;
            long count = 0;

            for (Card card : cards) {
                if (count + card.count >= N) {
                    sum += card.number * (N - count);
                    break;
                }

                sum += card.number * card.count;
                count += card.count;
            }

            System.out.println(sum);
        }
    }

    static class Card {

        long number;

        int count;

        public Card(long number, int count) {
            this.number = number;
            this.count = count;
        }

    }

}


Measured memory_bytes: 102364
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void solve();

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

bool is_valid(int K, string S) {
  char a = S[K-1];
  for (int i = K-1; i < S.size(); i++) {
    S[i] = a;
  }

  a = S[S.size()-K];
  for (int i = 0; i <= S.size()-K; i++) {
    S[i] = a;
  }

  bool o1 = true, o2 = true;
  for (int i = 0; i < K; i++) {
    if (S[0] != S[i]) {
      o1 = false;
    }

    if (S.back() != S[S.size()-1-i]) {
      o2 = false;
    }
  }

  return o1 || o2;
}

void solve() {
  string S; cin >> S;

  int ok = 1;
  int ng = S.size() + 1;

  while (ng - ok > 1) {
    int piv = (ng - ok)/2 + ok;
    if (is_valid(piv, S)) {
      ok = piv;
    } else {
      ng = piv;
    }
  }

  cout << ok << endl;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

using P = pair<i64, i64>;
signed main() {
  i64 N, Q;
  cin >> N >> Q;
  vector<vector<i64>> G(N);
  REP(_, N - 1) {
    i64 a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<i64> cnt(N);
  REP(_, Q) {
    i64 p, x;
    cin >> p >> x;
    p -= 1;
    cnt[p] += x;
  }
  vector<i64> ans(N);
  vector<bool> used(N, false);
  stack<P> st;
  st.push({0, 0});
  while (st.size()) {
    P a = st.top();
    st.pop();
    i64 v = cnt[a.first] + a.second;
    ans[a.first] = v;
    used[a.first] = true;
    for (i64 b : G[a.first]) {
      if (!used[b]) {
        st.push({b, v});
      }
    }
  }
  REP(i, N) {
    cout << ans[i] << " ";
  }
}


Measured memory_bytes: 21104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    cin >> N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout << "Yes" << endl;
                return 0;
                
            }
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int fa[200005],num[200005];
int find(int x){
	if(x==fa[x])
	    return fa[x];
	return fa[x]=find(fa[x]);
}
void add(int x,int y){
	x=find(x);
	y=find(y);
	if(x!=y){
		fa[y]=x;
		num[x]+=num[y];
	}
}
int main(){
	int n,m,x,y,ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		fa[i]=i;
		num[i]=1;
	}
	for(int i=0;i<m;i++){
		cin>>x>>y;
		add(x,y);
	}
	for(int i=0;i<n;i++){
		ans=max(ans,num[i]);
	}
	cout<<ans;
	return 0;
}

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

const int MAX = 50;

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int N,K;
  string S,T;
  char t;
  cin >> N >> S >> K;
  T=S;
  t=S.at(K-1);
  for (int i=0; i<N ;i++){
    if(S.at(i)==t){
      T.at(i)=S.at(i);
    }
    else{
      T.at(i)='*';
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 256