akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int dp[N];
int w[110];
int v[110];
int main()
{
	int n, sumw;
	scanf("%d%d", &n, &sumw);
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &w[i], &v[i]);
		sum += v[i];
	}
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = sum; j >= v[i]; j--)
		{
			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);
		}
	}
	for (int i = sum; i >= 0; i--)
	{
		if (dp[i] <= sumw)
		{
			printf("%d", i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 640
function main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10);
  const A = args[1].split("");
  const B = args[2].split("")
  const C = args[3].split("")
  var count = 0
  
  for(var i = 0; i<N; i++){
    count += add(A[i],B[i],C[i])
  }
  console.log(count)
}

function add (a,b,c){
  if(a == b && b == c){
    return 0
  }else if(a == b || b == c || c == a){
    return 1
  }else{
    return 2
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
s = input()

count = 0
block = 0
i = len(s) - 1
while i >= 0 :
    if s[i-1] == "B" and s[i] == "C":
        block += 1
        i -= 1
    elif s[i] == "A":
        count += block
    else:
        block = 0
    i -= 1
    
print(count)


Measured memory_bytes: 3500
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int[] ans = new int[5];
        int count = 0;
        for(int i = A;i <= B;i++){
            int j = 0;
            int x = i;
            while(x > 0){
                ans[j++] = x % 10;
                x /= 10;
                //System.out.println("i = " + x);
                //System.out.println("ans[] = " + ans[j]);
            }
            if(ans[0] == ans[4] && ans[1] == ans[3]){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;cin >> n;
  vector<ll> a(3*n),c(3*n),d(3*n);
  priority_queue<ll> pqr;
  priority_queue<ll,vector<ll>,greater<ll>> pql;
  ll suml=0,sumr=0;
  for(int i=0;i<3*n;i++){
    cin >> a[i];
    if(i<n){
      pql.push(a[i]);
      suml+=a[i];
    }
    if(i>=2*n){
      pqr.push(a[i]);
      sumr+=a[i];
    }
  }
  c[n-1]=suml;
  d[2*n]=sumr;
  for(int i=n;i<2*n;i++){
    if(pql.top()<a[i]){
      c[i]=c[i-1]+a[i]-pql.top();
      pql.pop();
      pql.push(a[i]);
    }
    else{
      c[i]=c[i-1];
    }
  }
  for(int i=2*n-1;i>=n;i--){
    if(pqr.top()>a[i]){
      d[i]=d[i+1]+a[i]-pqr.top();
      pqr.pop();
      pqr.push(a[i]);
    }
    else{
      d[i]=d[i+1];
    }
  }
  ll ans=-1e18;
  for(int i=n-1;i<2*n;i++){
    ans=max(ans,c[i]-d[i+1]);
  }
  cout << ans << endl;
}

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

int N, C;
vector<int>s(100005), t(100005), c(100005), sum(200005), tt(200005);

int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		cin >> s[i] >> t[i] >> c[i];
	}

	for (int i = 1; i <= C; i++) {
		for (int j = 0; j < 200005; j++)tt[j] = 0;
		for (int j = 0; j < N; j++)if (c[j] == i)tt[s[j] * 2 - 1]++, tt[t[j] * 2]--;
		for (int j = 1; j < 200005; j++)tt[j] += tt[j - 1];
		for (int j = 0; j < 200005; j++)if (tt[j] > 0)sum[j]++;
	}
	int maxNum = 0;
	for (int i = 0; i < 200005; i++)if (maxNum < sum[i])maxNum = sum[i];
	cout << maxNum << endl;

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

static const ll INF = 1e+9 + 7;

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

    reverse(begin(S), end(S));

    ll base = 1;

    vector<ll> ans(13);
    ans[0] = 1;

    for (int i = 0; i < S.size(); ++i) {
        base = base % 13;

        vector<ll> tmp(13);
        if (S[i] == '?') {
            for (int k = 0; k < 10; ++k) {
                ll r = (k * base) % 13;

                for (int j = 0; j < 13; ++j) {
                    tmp[(r + j) % 13] = (tmp[(r + j) % 13] + ans[j]) % INF;
                }
            }
        } else {
            ll r = ((S[i] - '0') * base) % 13;

            for (int j = 0; j < 13; ++j) {
                tmp[(r + j) % 13] = (tmp[(r + j) % 13] + ans[j]) % INF;
            }
        }

        swap(ans, tmp);
        base *= 10;
    }

    cout << ans[5] << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static long mod=1000000007;
    // static int dx[]={1,-1,0,0};
    // static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    //ArrayList<Integer> lis = new ArrayList<Integer>();
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt(),a=0;
        long ans=0,e[]=new long[n];
        for( int i=0; i<n; i++ ){
            e[i] = sc.nextLong();
        }
        while(true){
            sort(e);
            int x=-1;
                if(e[n-1]<n) break;
            long c=e[n-1]/n;
            //db(c,x,e,++a);
            ans+=c;
            for( int i=0; i<n-1; i++ ){
                e[i] += c;
            }
            e[n-1] -= c * n;
        }
        out.println(ans); 
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }
}

class Pair implements Comparable<Pair>{
    int x,y,id;
    Pair(int x, int y,int id) {
        this.x=x;
        this.y=y;
        this.id=id;
    } 
    public int compareTo(Pair p){
        return p.x -     x;
    } 
}

// class Pair implements Comparable<Pair>{
//     int x,y;
//     Pair(int x, int y) {
//         this.x=x;
//         this.y=y;
//     } 
//     public int compareTo(Pair p){//descend
//         return p.x - x;
//     } 

// }

class P implements Comparable<P>{
    int diff,id1,id2;
    P(int diff, int id1,int id2) {
        this.diff=diff;
        this.id1=id1;
        this.id2=id2;
    } 
      
    public int compareTo(P p){//ascend
        return diff - p.diff;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 24404
def leap_year?(y)
  y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)
end

answers = []

while line = gets
  a, b = line.chomp.split.map(&:to_i)
  break if a == 0 && b == 0

  leap_years = []
  (a..b).each do |year|
    leap_years << year if leap_year?(year)
  end

  answers << leap_years
end

out = []
answers.each do |answer|
  if answer.any?
    out << answer.join("\n")
  else
    out << :NA
  end
end

puts out.join("\n\n")

Measured memory_bytes: 8684
#include <stdio.h>
#include <math.h>

int main(){
	int p, q, r;
	scanf("%d %d %d",&p,&q,&r);
	/*
	int a1 = p+q;
	int a2 = r+q;
	int b1 = p+r;
	int b2 = q+r;
	int c1 = p+q;
	int c2 = r+p;
	int ans = a1;
	if(a1=>a2){ans=a2;}
	if(a2=>b1){ans=b1;}
	if(b1=>b2){ans=b2;}
	if(b2=>c1){ans=c1;}
	if(c1=>c2){ans=c2;}
	*/
	
	int tmp;
	
	if (p<=r){
		tmp=p;
		p=r;
		r=tmp;
	}
	
	if (p<=q){
		tmp=p;
		p=q;
		q=tmp;
	}
	
	if (q<=r){
		tmp=q;
		q=r;
		r=tmp;
	}
	
	int ans = q+r;
	printf("%d",ans);
	
	return 0;
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;


int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    rep(i,1000){
        string s = to_string(i);
        if(s.size()==1) s="00"+s;
        else if(s.size()==2) s="0"+s;
        int index = 0;
        for(auto e:S){
            if(s[index] == e) {
                ++index;
            }
            if(index==3) {
                ++ans;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    int N;
    cin>>N;
    int count=1;
    int High;
    cin>>High;
    int H;
    for(int i=2;i<=N;i++){
        cin>>H;
        if(H>=High){count++;High=H;}
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>






int main() {
	int n; std::cin >> n;
	std::cout << std::setprecision(15) << std::fixed << ((n - n / 2) / static_cast<double>(n)) << std::endl;
}


Measured memory_bytes: 256
def examA():
    S = SI()
    ans = 0
    if "R" in S:
        ans = 1
    if "RR" in S:
        ans = 2
    if "RRR" in S:
        ans = 3
    print(ans)
    return

def examB():
    N = I()
    L = LI()
    L.sort()
    cnt = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if L[i]==L[j]:
                    continue
                if L[j]==L[k]:
                    continue
                if L[i]+L[j]>L[k]:
                    cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    X, K, D = LI()
    if X<0:
        X = -X
    ans = inf
    if X>K*D:
        ans = X-K*D
        print(ans)
        return

    K -= X//D
    X -= D * (X//D)

    ans = X
    if K>0:
        if K%2==1:
            ans = abs(X-D)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 76992
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  loop(i,1,10000000) {
    if((a*i)%b == c) {
      cout << "YES" << endl;
      return;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int K, S;

    AtCoder(FastScanner sc) {
        K = sc.nextInt();
        S = sc.nextInt();
    }

    void solve(PrintWriter out) {
        int ans = 0;
        for (int x = 0; x <= K; x++) {
            for (int y = 0; y <= K; y++) {
                if (S - x - y <= K && S - x - y >= 0) ans++;
            }
        }
        out.println(ans);
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

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

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

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

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

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int h,w,n;
  cin >> h >> w >> n;
  vi a(n);
  vvi board(h, vi(w));
  rep(i, n) cin >> a[i];
  int cur = 0;
  rep(y, h){
    if(y % 2 == 0){
      rep(x, w){
        if(!a[cur]) cur++;
        a[cur]--;
        board[y][x] = cur + 1;
      }
    }else{
      for(int x = w - 1; x >= 0; x--){
        if(!a[cur]) cur++;
        a[cur]--;
        board[y][x] = cur + 1;
      }
    }
  }
  rep(y, h){
    rep(x, w){
      cout << board[y][x];
      if(x != w - 1) cout << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
C = [[0]*2 for i in range(40)]
for i in range(40):
  cc = 0
  for a in A:
    if (a>>(39-i))&1:
      cc += 1
  C[i][0] = cc * 2**(39-i)
  C[i][1] = (N-cc) * 2**(39-i)
INF = float("inf")
dp = [[-INF]*2 for i in range(41)]
dp[0][0] = 0
for i in range(40):
  d = (K>>(39-i))&1
  dp[i+1][0] = dp[i][0] + C[i][d]
  dp[i+1][1] = dp[i][1] + max(C[i])
  if d == 1:
    dp[i+1][1] = max(dp[i][0] + C[i][0], dp[i+1][1])
print(max(dp[40]))

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

int main(){
    std::string  W;
    std::cin >> W;
    
    std::string T;
    int n = 0;
    while(std::cin >> T){
        if(T=="END_OF_TEXT") break;
        for(int i=0; i<T.length(); i++)  	T[i] = std::towlower(T[i]);
        if(T==W) n++;
    }
    std::cout << n << std::endl;
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    ll x,y;
    cin >> x >> y;
    ll ans = 0;
    while(x<=y) {
        ans++;
        x *= 2;
    }
    cout << ans << endl;
}

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

using namespace std;
int main(){
    char num[6310];
    char out[1310];
    char d;
    int ar[257] = {0};
    int i, j, n, o = 0;
    int a = (int)'a';
    int A = (int)'A';
    while ( scanf("%c", num) != EOF ){
        i = 0;
        while(num[i] != '\0') {
            ar[num[i]] += 1;
            out[o++] = num[i];
            i +=5;

        }
    }
    out[o++] = '\0';
    for(n = 0;n <26; n++) {
        d = 'a' + (char)n;
        cout << d << " : " << ar[n+a] + ar[n+A] << endl;
    }
    return 0;
}




Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define ll long long int  

using namespace std;

void solve(){

	ll n,m;
	cin>>n>>m;

	vector<ll> a;
	ll nn = n;
	ll sum = 0;
	while(nn--){
		ll vl;
		cin>>vl;
		sum+=vl;
		a.push_back(vl);
	}

	sort(a.begin(), a.end(),greater<ll>());
	ll i=0;
	double frac = sum / (4 * m);
	while(i<m){

		if((a[i] * 4 * m) < sum){
			cout<<"No"<<endl;
			return;
		}
		i++;
	}

	cout<<"Yes"<<endl;
	return;
}

int main(){

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

	ll t;
	// cin>>t;
		t=1;

	while(t--){
		solve();
	}

}

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

int const MAXEK = 10000;
int const MAXD = 100;
int const MOD = 1000000007;

char K[MAXEK+1];
int D, L;

int dpK[2][MAXD], dpL[2][MAXD];

int main() {
  std::cin >> K >> D;
  L = std::strlen(K);

  for(int i = 0; i < D; ++i) dpK[0][i] = dpL[0][i] = 0;
  dpK[0][0] = 1; // 0
  int sum = MOD-1;  // exclude 0
  for(int i = 0; i < L; ++i) {
    int c = K[i] - '0';
    for(int j = 0; j < D; ++j) {
      dpK[(i+1)%2][j] = dpK[i%2][(j-c+D*9)%D];
      int tmp = 0;
      for(int k = 0; k < c; ++k) {
        tmp = (tmp + dpK[i%2][(j-k+D*8)%D])%MOD;
      }
      for(int k = 0; k < 10; ++k) {
        tmp = (tmp + dpL[i%2][(j-k+D*9)%D])%MOD;
      }
      dpL[(i+1)%2][j] = tmp;
    }
  }
  sum = (sum + dpK[L%2][0] + dpL[L%2][0])%MOD;
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int n, c[100005] = {};


int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            c[0]++;
            c[1]++;
        }
        else {
            c[t - 1]++;
            c[t]++;
            c[t + 1]++;
        }
    }
    sort(c, c + 100000, greater<int>());
    cout << c[0] << endl;
    return 0;
}

Measured memory_bytes: 640
// Create time: 2019-10-05  19:59:00
#include <bits/stdc++.h>
#define rint register int
using namespace std;

long long n, m;
char s[1000]; 
bool check() {
    for (rint i = 2; i <= n; ++i)
        if (s[i] != s[1]) return false;
    return true;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    scanf("%s", s + 1);
    n = strlen(s + 1);

    cin >> m;

    if (check()) {
        cout << n * m / 2 << endl;
        return 0;
    }

    int now = 1;
    while (s[now + 1] == s[1]) ++now;

    long long ans = 0;

    for (rint i = 2; i <= n; ++i)
        if (s[i] == s[i - 1]) ++ans, s[i] = '#';

    ans *= m;



    if (s[1] == s[n]) {
        if (now & 1) ans += m - 1;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int main() {

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

	int a[4];
	cin >> a[1] >> a[2] >> a[3];
	sort(a + 1, a + 4);
	if (a[1] == 5 && a[2] == 5 && a[3] == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

const V: usize = 26;

struct State {
    cc: Vec<i32>,
    ss: Vec<Vec<i32>>,
    tt: Vec<usize>,
}

impl State {
    fn new(cc: Vec<i32>, ss: Vec<Vec<i32>>, tt: Vec<usize>) -> State {
        State { cc, ss, tt }
    }

    fn calc_score(&self) -> i32 {
        let mut score = 0;
        let mut last = vec![0; V];
        for (d, &t) in self.tt.iter().enumerate() {
            let day = d as i32 + 1;
            last[t] = day;
            score += self.ss[d][t];
            score -= last
                .iter()
                .zip(self.cc.iter())
                .map(|(&l, &c)| c * (day - l))
                .sum::<i32>();
        }
        score
    }
}

fn main() {
    input! {
        d: usize,
        cc: [i32; V],
        ss: [[i32; V]; d],
        tt: [Usize1; d],
    }
    for i in 1..=tt.len() {
        let state = State::new(cc.clone(), ss.clone(), tt[..i].to_vec());
        println!("{}", state.calc_score());
    }
}


Measured memory_bytes: 2284
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
ll a[1002];
ll b[1002];
int dp[3000 + 5][3000 + 5];
 
int main() {
   /*
   Jab Bhi Koi Ladaki Dekhun Meraa Dil Divaanaa Bole
Ole Ole Ole, Ole Ole Ole
Gaao Taraanaa Yaaraa Jhum Jhum Ke Haule Haule
Ole Ole Ole, Ole Ole Ole
Mujhako Lubhaati Hai Javaaniya Masti Lutaati Zidagaani Yahaan
Maane Na Kahanaa Paagal Mast Pavan Saa Dil Ye Dole
Ole Ole Ole, Ole Ole Ole
Ole Ole Ole, Ole Ole Ole
Jab Bhi Koi Ladaki Dekhun Meraa Dil Divaanaa Bole
Ole Ole Ole, Ole Ole Ole
Gaao Taraanaa Yaaraa Jhum Jhum Ke Haule Haule
Ole Ole Ole, Ole Ole Ole
   */
    double n;
    cin>>n;
    double ans=n/(double)3*n/(double)3*n/(double)3;
  cout << fixed <<ans<<endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int pre = -999;
	rep(i,n)
	{
		if(pre <= a[i]-1)
		{
			pre = a[i] -1;
		}
		else if(pre <= a[i])
		{
			pre = a[i];
		}
		else
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
bool ok[maxn];
int a[maxn];
int main()
{
    memset(ok,1,sizeof(ok));
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]);
    for(int i = 1,c,b;i <= m;++i){
        scanf("%d%d",&c,&b);
        if(a[c]<=a[b]){
            ok[c]=0;
        }
        if(a[b]<=a[c])ok[b]=false;
    }
    int cnt = 0;
    for(int i = 1;i <= n;++i)cnt+=ok[i];
    cout<<cnt<<endl;
    return 0;

}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
	
    int N; cin >> N;
    vl A(N); rep(i,N) cin >> A[i];
    sort(all(A));
    rep(i,N-1) {
        if(A[i] == A[i+1]) NO
    }
    YES
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vi a(n);
    rep(i, n) cin >> a[i];
    // スコア上昇の上限はジャッジの人数
    sort(all(a), greater<ll>());
    map<ll, bool> isOK;
    ll pos = 0, sum = 0;
    for(; pos<n; pos++){
        // 上位p-1個は無条件にOK
        if(pos < p-1){
            isOK[a[pos]] = true;
            continue;
        }
        // 累積和の更新
        sum += a[pos];
        // 既にOKの数字なら飛ばす
        if(isOK[a[pos]]) continue;

        // 全員に投票させれば降順p番目の数字を超えられる場合
        if(a[pos]+m >= a[p-1]){
            // 先頭p-1個に投票した後、残りの票を自分を含む自分以下の数値に割り振ることが可能な場合
            if(pos <= n-v+p-1){
                isOK[a[pos]] = true;
                continue;
            }
            // 割り振り切れない場合、自分より大きい値にフラットになるように振れるか
            else{
                // 自分の最高値
                ll selfMax = a[pos]+m;
                // 自分を累積和に加えているので一旦取り除く
                sum -= a[pos];
                // 自分より大きな数の個数と残りの票
                ll num = pos - (p-1);
                ll leftVote = ((v-(p-1))-(n-pos))*m;
                // 自分の最高値を超えないように、自分より大きな数に割り振れるか
                if(num*selfMax-sum >= leftVote){
                    sum += a[pos];
                    isOK[a[pos]] = true;
                    continue;
                }
                else break;
            }
        }
        else break;
    }
    cout << pos << endl;
}

Measured memory_bytes: 10248
#include <iostream>
#include <string>
using namespace std;
string s;
long long sum,cnt;
int main(){
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            cnt++;
            sum+=i;
        }
    }
    cout<<sum-cnt*(cnt-1)/2;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += min(A.at(i) * 2, ((K - A.at(i)) * 2));
  }

  cout << ans << endl;
}

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

int main() {
    int N, i;
    scanf("%d",&N);
    int A[N];
    for (i=0; i<N; i++) {
        scanf("%d",&A[i]);
    }
    int end=0, ans=0;
    while(!end) {
        for (i=0; i<N; i++) {
            if (A[i] % 2 == 0) {
                A[i] /= 2;
            } else {
                end = 1;
                ans -= 1;
                break;
            }
        }
        ans += 1;
    }
    cout << ans << "\n";
}

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

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    vector<ll> s(n + 1), t(m + 1);
    for (ll i = 1; i <= n; ++i) scanf("%lld", &s.at(i));
    for (ll i = 1; i <= m; ++i) scanf("%lld", &t.at(i));
    vector< vector<ll> > dp(n + 1, vector<ll>(m + 1));
    for (ll i = 1; i <= n; ++i) for (ll j = 1; j <= m; ++j) dp.at(i).at(j) = dp.at(i - 1).at(j) + dp.at(i).at(j - 1) + (s.at(i) == t.at(j) ? 1 : -dp.at(i - 1).at(j - 1)), dp.at(i).at(j) += MOD, dp.at(i).at(j) %= MOD;
    printf("%lld\n", (dp.at(n).at(m) + 1) % MOD);
    return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
// #define mod 1000000007
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
using namespace std;

// long double memo[3001][1600];

// long double solve(vector<long double> a, int n, int k){
// 	if(n == 0)
// 		return 1;
// 	if(memo[n][k] != -1)
// 		return memo[n][k];
// 	long double q1 = 0;
// 	if(k>0)
// 		q1 = (1-a[n-1])*solve(a,n-1,k-1);
// 	return memo[n][k] = q1+(a[n-1]*solve(a,n-1,k));
// }

int main(){
	int n;
	cin>>n;
	vector<long double> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];

	long double memo[n+1][(n+1)/2];
	// for(int i=0;i<n+1;i++)
	// 	memo[i][0] = 1;
	for(int j=0;j<(n+1)/2;j++)
		memo[0][j] = 1;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<(n+1)/2;j++){
			memo[i][j] = a[i-1]*memo[i-1][j];
			if(j > 0)
				memo[i][j]+= (1-a[i-1])*memo[i-1][j-1];
			// cout<<memo[i][j]<<" ";
		}
	}
	prDouble(memo[n][(n-1)/2]);
	// for(int i=0;i<n+1;i++)
	// 	for(int j=0;j<=n/2;j++)
	// 		memo[i][j] = -1;
	// prDouble(solve(a,n,n/2));
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a,b,c) max(a,max(b,c))
const ll INF = 1 << 30;
typedef pair<double, double  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<double,payar  > > vpp;
vector < payar >  vp;
ll dp[105][100005];
ll cap;
ll w[1001];
ll val[1001];
ll a;
ll cal(ll ind, ll wt )
{
    if(ind==a+1)
        return 0 ;

    if(dp[ind][wt]!=-1)
        return dp[ind][wt];
    ll a =0,b=0;
    if(w[ind]+wt<=cap)
    {
        a =  val[ind]+cal(ind+1,wt+w[ind]);
    }
    if(1)
    {
        b =  cal(ind+1,wt);
    }
    return dp[ind][wt]=max(a,b);


}
int main()
{


    memset(dp,-1,sizeof dp);
    cin>>a>>cap;
    for(int i = 1 ; i<= a ; i++)
    {

        cin>>w[i]>>val[i];

    }
    cout<<cal(1,0);

    return  0 ;
}


Measured memory_bytes: 82304
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<typename T, class F, const T & I>
struct SegmentTree {
    const F op;
    int n; vector<T> dat;
    SegmentTree() : op() {}
    SegmentTree(F f) : op(f) {}
    T operator [](int i) const { return dat[n + i]; }
    void build(const vector<T>& v) {
        int n_ = v.size(); init(n_); for (int i = 0; i < n_; ++i) dat[n + i] = v[i];
        for (int i = n - 1; i; --i) dat[i] = op(dat[i * 2], dat[i * 2 + 1]);
    }
    void init(int n_) { n = 1; while (n < n_) n *= 2; dat.assign(n * 2, I); }
    template<class T_ = T, class SA = enable_if_t<is_same<remove_reference_t<T_>, T>::value>>
    void update(int k, T_&& v) { dat[k += n] = v; while (k /= 2) dat[k] = op(dat[k * 2], dat[k * 2 + 1]); }
    T query(int a, int b) {
        T vl = I, vr = I;
        for (int l = a + n, r = b + n; l < r; l /= 2, r /= 2) { if (l & 1) vl = op(vl, dat[l++]); if (r & 1) vr = op(dat[--r], vr); }
        return op(vl, vr);
    }
    template<class C> int find(int a, int b, C&& check) const { return find(a, b, check, 1, 0, n); }
private:
    template<class C> int find(int a, int b, C&& check, int k, int l, int r) const {
        if (!check(dat[k]) || r <= a || b <= l) return -1; else if (k >= n) return k - n;
        int m = (l + r) / 2; int vl = find(a, b, check, k * 2, l, m); if (~vl) return vl;
        else return find(a, b, check, k * 2 + 1, m, r);
    }
};

template<typename T> struct max_of {
    template<typename T_L = T, typename T_R = T>
    constexpr T operator ()(T_L&& lhs, T_R&& rhs) const { return max(lhs, rhs); }
};
extern constexpr int identity = 0;

using ST = SegmentTree<int, max_of<int>, identity>;

int main() {
    int N;
    cin >> N;
    vector<int> X(N + 1), L(N + 1);
    X[0] = -1e9; L[0] = 0;
    rep(i, 1, N + 1) cin >> X[i] >> L[i];

    vector<pair<int, int>> xl(N + 1);
    rep(i, N + 1) xl[i] = { X[i] + L[i], L[i] };
    sort(all(xl));

    ST st;
    st.build(vector<int>(N + 1));

    rep(i, 1, N + 1) {
        auto it = upper_bound(all(xl), pair<int, int>(xl[i].first - 2 * xl[i].second + 1, 0));
        //it = prev(it);
        int mx = st.query(0, it - xl.begin());
        st.update(i, mx + 1);
    }

    write(st.query(0, N + 1));
}

Measured memory_bytes: 3200
#include<stdio.h>

int main()
{
    int H,A,m,n;
    scanf("%d %d",&H,&A);
    m=H/A;
    n=H%A;
    if(n!=0)
    {
        printf("%d",m+1);
    }
    else
    {
        printf("%d",m);
    }
    return 0;

}


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N, M, X; cin >> N >> M >> X;
  vi C(N); mi A(N, vi(M));
  REP(i,N){
    cin >> C[i];
    REP(j,M) cin >> A[i][j];
  }
  int lim = (1 << N);
  int ans = -1;
  REP(i,lim){
    int m = 1;
    int cost = 0;
    vi skill(M);
    REP(j,N){
      if(m&i){ REP(k,M) skill[k] += A[j][k]; cost += C[j]; }
      m <<= 1;
    }
    FORE(i,skill)if(i<X) goto no;
    if(ans < 0 || cost < ans) ans = cost;
    no:;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ds = [-1 for _ in range(n)]
f = True
for _ in range(m):
    si, ci = map(int, input().split())
    si -= 1
    if ds[si] == -1:
        ds[si] = ci
    elif ds[si] == ci:
        continue
    else:
        f = False

if f:
    if len(ds) == 1:
        s = max(0, ds[0])
    elif ds[0] == 0:
        s = -1
    else:
        s = max(1, ds[0])
        for i in ds[1:]:
            s *= 10
            s += max(0, i)
    print(s)    
else:
    print(-1)


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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define int long long
#define ld long double
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mod 1000000007

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int32_t main(){
  int n;  cin>>n;
  int arr[n][3];
  for(int i=0;i<n;i++)
  for(int j=0;j<3;j++)
  cin>>arr[i][j];

  int dp[n][3];  fr(i,0,n)fr(j,0,3)dp[i][j]=0;
  fr(j,0,3) dp[0][j]=arr[0][j];

  for(int i=1;i<n;i++){
    //cout<<i<<" af "<<endl;
    dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
    dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
    dp[i][2] = arr[i][2] + max(dp[i-1][1],dp[i-1][0]);
  }
  //fr(i,0,n){ fr(j,0,3) cout<<dp[i][j]<<" "; cout<<endl;}
  cout<<max(dp[n-1][1],max(dp[n-1][0],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 4992
import bisect
import math

n = int(input())
As = list(map(int, input().split()))
As.sort()

cons = 10 ** 6
is_prime = [True] * (cons + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(cons**0.5) + 1):
    if not is_prime[i]:
        continue
    for j in range(i * 2, cons + 1, i):
        is_prime[j] = False
Ps = [i for i in range(cons + 1) if is_prime[i]]
# def eratosthenes(n):
#     is_prime = [0, 0] + [1] * (n - 1)
#     for i in range(int(n**0.5) + 1):
#         if is_prime[i] == 0:
#             continue
#         for j in range(i * 2, n + 1, i):
#             is_prime[j] = 0
#     return [i for i, pi in enumerate(is_prime) if pi == 1]
# Ps = eratosthenes(10 ** 6)

def factorize(n):
    primes = set()
    for p in Ps:
        if p * p > n:
            break
        while n % p == 0:
            n //= p
            primes.add(p)
    if n > 1:
        primes.add(n)
    return primes

gcd = As[0]
for a in As:
  gcd = math.gcd(gcd, a)
setwiseFlag = (gcd == 1)

pairwiseFlag = True
target = set()
for a in As:
  primes = factorize(a)
  if len(primes & target) > 0:
    pairwiseFlag = False
  target |= primes

if pairwiseFlag:
  print('pairwise coprime')
elif setwiseFlag:
  print('setwise coprime')
else:
  print('not coprime')


Measured memory_bytes: 189912
def c():
    S = input()
    T = input()
    start = [-1] * 26
    goal = [-1] * 26
    for i in range(len(S)):
        a = ord(S[i]) - ord("a")
        b = ord(T[i]) - ord("a")

        if not start[a] == -1 or not goal[b] == -1:
            if not start[a] == b or not goal[b] == a:
                print("No")
                return 0
        else:
            start[a] = b
            goal[b] = a

    print("Yes")


c()


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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<pair<int,int>> pairs(n);
  rep(i,n){
    int a,b;
    cin >> a >> b;
    pairs[i] = make_pair(a,b);
  }
  sort(pairs.begin(),pairs.end());
  /*rep(i,n){
    cout << pairs[i].first << " " << pairs[i].second << endl;
  }*/
  ll money = 0;
  rep(i,n){
    if(m>0){
      if(m-pairs[i].second>=0){
        money += (ll)pairs[i].first * pairs[i].second;
        m -= pairs[i].second;
        //cout << "条件１" << m << endl;
      }else if(m-pairs[i].second<0){
        money += (ll)pairs[i].first * m;
        m=0;
        //cout << m << endl;
      }
    }else{
      break;
    }
  }

   cout << money << endl;
  


  return 0;
}

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

// 各桁の和を計算する
int sumofdigits(int n){
    int sum = 0;
    while (n>0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int total = 0;
    for (int i=1; i<=N; i++){
        int sum=sumofdigits(i);
        if (sum>=A && sum<=B){
            total += i;
        }
    }

    cout << total << endl;


}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int n;
int main()
{
	fast;
	cin>>n;
	cout<<3*n*n<<endl;
	return 0;
}


Measured memory_bytes: 256
winner 'a' [] _ _ = "A"
winner 'b' _ [] _ = "B"
winner 'c' _ _ [] = "C"
winner 'a' (a:as) bs cs = winner a as bs cs
winner 'b' as (b:bs) cs = winner b as bs cs
winner 'c' as bs (c:cs) = winner c as bs cs

main = do
    sa <- getLine
    sb <- getLine
    sc <- getLine
    putStrLn $ winner (head sa) (tail sa) sb sc


Measured memory_bytes: 508
import sys
import itertools

cols = []
for line in sys.stdin:
  col = line.strip().split(' ')
  col = [int(c) for c in col]
  cols.append(col)

cols = cols[1:]
for cx,cy in itertools.product(list(range(101)), list(range(101))):
  H, H_max, flag = None, None, True
  for x,y,h in cols:
    if h <= 0:
      tmp_H_max = abs(x-cx) + abs(y-cy)
      if tmp_H_max < 1:
        flag = False
        break
      else:
        H_max = min(H_max, tmp_H_max) if H_max else tmp_H_max
      if H and H_max < H:
        flag = False
        break
    else:
      tmp_H = h + abs(x-cx) + abs(y-cy)
      if not H:
        H = tmp_H
      elif H and H != tmp_H:
        flag = False
        break
      if H_max and H_max < tmp_H:
        flag = False
        break
  if flag:
    print(cx,cy,H)


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a == b) {
        cout << "Draw";
    }
    else {
        if(a == 1) {
            cout << "Alice";
        }
        else if(b == 1) {
            cout << "Bob";
        }
        else if(a > b) {
            cout << "Alice";
        }
        else if(a < b) {
            cout << "Bob";
        }
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    from operator import itemgetter
    input = sys.stdin.readline

    mod = 1000000007
    # comb init
    nmax = 3 * 10 ** 5 + 1  # change here
    fac = [0] * (nmax + 1)
    finv = [0] * (nmax + 1)
    inv = [0] * (nmax + 1)
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    H, W, N = map(int, input().split())
    block = []
    for _ in range(N):
        r, c = map(int, input().split())
        block.append((r, c))
    block.sort(key=itemgetter(1))
    block.sort(key=itemgetter(0))
    block.insert(0, (1, 1))

    dp_p = [0] * (N+1)
    dp_n = [0] * (N+1)
    dp_p[0] = 1
    for i in range(1, N+1):
        ri, ci = block[i]
        for j in range(i):
            rj, cj = block[j]
            if ri >= rj and ci >= cj:
                dp_p[i] = (dp_p[i] + (dp_n[j] * comb(ri - rj + ci - cj, ri - rj))%mod)%mod
                dp_n[i] = (dp_n[i] + (dp_p[j] * comb(ri - rj + ci - cj, ri - rj))%mod)%mod
    ans = 0
    for i in range(N+1):
        ans = (ans + ((dp_p[i] - dp_n[i])%mod * comb(H - block[i][0] + W - block[i][1], H - block[i][0]))%mod)%mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49648
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


S = ins()


def is_even(s):
    if len(s) % 2 == 1:
        return False
    k = len(s) // 2
    for i in range(k):
        if s[i] != s[k + i]:
            return False
    return True


def solve():
    for i in range(len(S) - 1, 1, -1):
        s = S[:i]
        if is_even(s):
            return i
    return None


print(solve())


Measured memory_bytes: 8972
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

T, X = MAP()
print(T/X)

Measured memory_bytes: 3892
import numpy as np

list1 = list(map(int, input().split())) 
s = [list(map(int, input().split()))  for i in range(list1[0])]

dist = 0
num = 0

for a in range(list1[0]):
    for b in range(a+1,list1[0]):
        X = np.array(s[a])
        Y = np.array(s[b])
        dist = np.linalg.norm(X-Y, ord=2)
        if (dist.is_integer()):
            num = num + 1

print(num)

Measured memory_bytes: 12500