akhauriyash/Code-Regression huggingface dataset:
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 100000;

int v[1 + MAXN];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    int answer = 0;
    for (int i = 1, j; i <= n; i = j) {
        answer++;
        while (i < n && v[i] == v[i + 1])
            i++;
        j = i + 2;
        while (j <= n) {
            if (v[i] > v[i + 1] && v[j] > v[j - 1])
                break;
            if (v[i] < v[i + 1] && v[j] < v[j - 1])
                break;
            j++;
        }
    }
    cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> dp(K+1);
    for(long long i=1; i<=K; i++){
        long long d = K / i;
        dp[i] = bipow(d, N);
    }
    long long ans = 0;
    for(long long i=K; i>=1; i--){
        for(long long j=2*i; j<=K; j+=i){
            dp[i] += (MOD - dp[j]) % MOD;
            dp[i] %= MOD;
        }
        ans += (dp[i] * i) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  printf("%.10f %d\n", (double)w*h/2, w == x*2 && h == y*2 ? 1 : 0);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <sstream>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());

    ll ans = 0;
    if(n % 2 == 1){
        for(int i=0;i<n/2;i++){
            ans += 2*a[i];
        }
        ans += a[n/2];
    }
    else{
        for(int i=0;i<n/2;i++){
            ans += 2*a[i];
        }
    }
    ans -= a[0];

    cout<<ans<<endl;
}

Measured memory_bytes: 4844
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))

D = ini()
C = inl()
assert len(C) == 26
S = [None] * D
for i in range(D):
    S[i] = inl()
    assert len(S[i]) == 26
T = [ini() - 1 for _ in range(D)]


def solve():
    ans = 0
    last = [-1] * 26
    for d in range(D):
        ct = T[d]
        ans += S[d][ct]
        last[ct] = d
        for i in range(26):
            ans -= C[i] * (d - last[i])
        print(ans)


solve()


Measured memory_bytes: 9432
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;
using ll = long long int;

#define rep(i, v) for(ll i = 0; i < (v); ++i)

int num(ll n){
    int i = 0;
    while(true){
        if(!n) break;
        i++;
        n /= 10;
    }
    return i;
}

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

    ll count = 0;
    for(ll i = 0; i <= N; ++i){
        if(num(i) % 2 == 1) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
/*
	https://www.youtube.com/watch?v=766qmHTc2ro
*/
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define ull unsigned long long
#define ll long long
#define ss string
#define vt vector
#define pii pair <int,int>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define pll pair <ll,ll>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define sz(x) (int) x.size()
#define bcc __builtin_popcount
#define bll __builtin_popcountll
void ___(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void data(){
	freopen("name.in","r",stdin);
	freopen("name.out","w",stdout);
}
const int N = 3e5 + 500;
const ll INF = 1e18;
const int mod = 1e9 + 7;





int main()
{
	//data();
	___();
	
	
	int n;
	cin >> n;
	vt<int> a(1 + n);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int rs = 0;
	sort(all(a));
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			for(int k = j + 1; k <= n; k++){
				if(a[i] != a[j] and a[j] != a[k] and a[i] + a[j] > a[k]){
					rs++;
				}
			}
		}
	}
	cout << rs;
	
	return 0;
}




Measured memory_bytes: 3664
#include<iostream>
#include<queue>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
    	cin>>v[i];
    }
    int ans=0;
    int mi=1e9;
    for(int i=0;i<n;i++){
    	mi=min(mi,v[i]);
    	if(mi==v[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
def test():
    s = input()
    divide = ["dream", "dreamer", "erase", "eraser"]
    dp = [0 for i in range(100010)]

    dp[0] = 1
    for i in range(len(dp)):
        if dp[len(s)] == 1:
            print('YES')
            return 0
        if dp[i] == 0:
            continue
        for d in divide:
            if s[i:i+len(d)] == d:
                dp[i+len(d)] = 1
    print('NO')

test()

Measured memory_bytes: 3956
#include <stdio.h>
 
int main(){
 
  int c[4][4];
  for(int i = 1; i <= 3 ; ++i){
    for(int j = 1; j <= 3 ; ++j){
      scanf("%d",&c[i][j]);
    }
  }
 
  if(c[1][1] - c[2][1] != c[1][2] - c[2][2] ){
    printf("No"); return 0;
  }
  if(c[2][1] - c[3][1] != c[2][2] - c[3][2] ){
    printf("No"); return 0;
  }
  if(c[1][1] - c[1][2] != c[2][1] - c[2][2] ){
    printf("No"); return 0;
  }
  if(c[1][2] - c[1][3] != c[2][2] - c[2][3] ){
    printf("No"); return 0;
  }
  if(c[2][2] - c[2][3] != c[3][2] - c[3][3] ){
    printf("No"); return 0;
  }
  if(c[2][2] - c[3][2] != c[2][3] - c[3][3] ){
    printf("No"); return 0;
  }
 
  printf("Yes");
 
  return 0;
 
}

Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)1000000007
#define pb push_back
#define endl "\n"
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repo(i,b) for(int i=(int)0;i<b;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed solve(){
	string a,b;
	cin>>a>>b;
	int cnt=0;
	for(int i=0;i<a.size();i++) if(a[i]!=b[i]) cnt++;
		cout<<cnt<<endl;
	return 0;
}

signed main(){
	fast;
	int tests=1;
	// cin>>tests;
	while(tests--){
		solve();
	}
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

int main()
{
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==b||b==c||c==d)cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

Measured memory_bytes: 764
def main():
    N = int(input())
    S = input()
    ans = []
    A = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
    for i in S:
        for j in range(27):
            if i == A[j]:
                j += N
                if j >= 26:
                    j -= 26
                ans.append(A[j])
                break
    for i in range(len(ans)):
        print(ans[i], end="")
    print()


if __name__ == "__main__":
    main()


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

int main() {
    int N; cin >> N;
    cout << N << ":";
    while(N != 1) {
        bool f = false;
        for(int i = 2; i * i <= N; i++) {
            if(N % i == 0) {
                cout << " " << i;
                N /= i;
                f = true;
                break;
            }
        }
        if(f == false) {
            cout << " " << N;
            break;
        }
    }
    cout << endl;
}

Measured memory_bytes: 1164
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		System.out.println(gInt()==gInt()?"Yes":"No");
	}

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

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

Measured memory_bytes: 23764
// ACM-ICPCà\I2008 D. ¿åë¿åë{bg

#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

class Node{
public:
	int x, y, d, cost;
	Node(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
	bool operator < (const Node &n) const { return cost > n.cost; }
};

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

int main(){
	int w, h;
	int op[4];
	int b[30][30];
	int c[30][30][4];
	while(cin >> w >> h, w){
		memset(c, -1, sizeof(c));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++) cin >> b[i][j];
		}
		for(int i=0;i<4;i++) cin >> op[i];
		priority_queue<Node> qu;
		qu.push(Node(0,0,0,0));
		int ans = 9999999;
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			int x = nd.x, y = nd.y, d = nd.d, cost = nd.cost;
			if(c[x][y][d]!=-1) continue;
			if(x==h-1&&y==w-1) { ans = cost; break; }
			c[x][y][d] = cost;
			for(int i=0;i<4;i++){
				int nx = x + dx[i], ny = y + dy[i];
				if(nx<0||nx>=h||ny<0||ny>=w) continue;
				if(b[x][y]!=4&&(b[x][y]+d)%4==i)
					qu.push(Node(nx,ny,i,cost));
				else
					qu.push(Node(nx,ny,i,cost+op[(4+i-d)%4]));
			}
		}
		cout << ans << endl;
	}
}

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

int A[111][111];
int R[111][111];
int N;

int main(){
  cin >> N;
  for(int i=1;i<=N;i++)
    for(int j=1;j<=N;j++) cin >> A[j][i];

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

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

  int res = -(1<<30);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=i+1;k<=N;k++)
	for(int l=j+1;l<=N;l++)
	  res = max( R[l][k] + R[j][i] - R[j][k] - R[l][i], res );	
      
    
  
  cout << res << endl;
  
}

Measured memory_bytes: 1252
s=input()
acgt = ['A','C','G','T']
l=[0]

for i in range(len(s)):
    if s[i] in acgt:
        moji=s[i]
        cnt=1
        l.append(len(moji))
        while i+cnt < len(s):
            if s[i+cnt] in acgt:
                moji=s[i:i+cnt+1]
                # print(moji)
                cnt+=1
                l.append(len(moji))
            else:
                break
print(max(l))



Measured memory_bytes: 38256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
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());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	public static void main(String[] args) {
		int W=stdIn.nextInt();
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		if(a<=b&&a+W>=b)
			System.out.println(0);
		else
			if(a<=b+W&&a+W>=b+W)
				System.out.println(0);
			else{
				System.out.println(Math.min(Math.abs(a-(b+W)),Math.abs(b-(a+W))));
			}
	}
}


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

  int main()
  {
	int n;
    cin >> n;
    double a[n];
    double sum = 0;
    rep(i, n) 
    {
      cin >> a[i];
      sum += 1/a[i];
    }
    cout << fixed << setprecision(5);
    cout << 1/sum << endl;
    return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int tower[1001]={0};
  tower[1]=1;
  for(int i=2;i<=999;i++)
  {
    tower[i]=i+tower[i-1];
  }
  for(int i=1;i<=998;i++)
  {
    if(b-a==tower[i+1]-tower[i])
    {
      cout<<tower[i]-a<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());
		
		int[] arr = new int[N];
		int sum = 0, count = 0;
		st = new StringTokenizer(br.readLine());
		
		for(int i=0; i<N; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
			sum += arr[i];
		}
		
		for(int i=0; i<N; i++) {
			if(arr[i] >= sum/(4.0 * M))
				count++;
		}
		
		StringBuilder sb = new StringBuilder();
		if(count >= M)
			sb.append("Yes\n");
		else
			sb.append("No\n");
		
		System.out.println(sb);
		
	}

}

Measured memory_bytes: 32764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int k[13];
int s[13][13];

int main()
{
    int n,m;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }

    vector<int> p(m);
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    int ans = 0;
    
    for(int bit = 0; bit < (1<<n); bit++){
        bool ok = true;
        for(int i = 0; i < m; i++){
            int tmp = 0;
            for(int j = 0; j < k[i]; j++){
                if(bit & (1 << s[i][j])){
                    tmp++;
                }
            }
            if(tmp % 2 != p[i]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    
}

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

double x[3],y[3];

double distance(int a,int b){
	return sqrt(pow(x[a]-x[b],2.0)+pow(y[a]-y[b],2.0));
}

int main(){
	int n,i,j;
	double xp,yp,R,S,s,s2,r,a,b,c,d,e,f;
	double len[3];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			scanf("%lf %lf",&x[j],&y[j]);
		}

		s = 0.0;
		for(j = 0;j < 3;j++){
			len[j] = distance((j+2)%3,(j+1)%3);
			s += len[j];
		}
		s /= 2.0;
		s2 = s;
		r = 1.0;
		for(j = 0;j < 3;j++){
			s2 *= (s-len[j]);
			r *= len[j];
		}
		S = sqrt(s2);
		R = r/(4.0*S);
		
		a = 2*(x[1] - x[0]);
		b = 2*(y[1] - y[0]);
		c = x[0]*x[0]-x[1]*x[1]+y[0]*y[0]-y[1]*y[1];
		d = 2*(x[2] - x[0]);
		e = 2*(y[2] - y[0]);
		f = x[0]*x[0]-x[2]*x[2]+y[0]*y[0]-y[2]*y[2];

		xp = (b*f-e*c)/(a*e-d*b);
		yp = (c*d-f*a)/(a*e-d*b);
	
		printf("%.3f %.3f %.3f\n",xp,yp,R);
	}
return 0;
}

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

int main() {
    int n;
    string answer = "Three";

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        char c;
        cin >> c;

        if (c == 'Y')
        {
            answer = "Four";
            break;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
def resolve():
    l, P = map(int, input().split())
    S = input()

    ans = 0
    # 10^r: 2^r * 5^r の為、10と同じ素数
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += i + 1
        return print(ans)

    cnts = [0] * P
    cnts[0] = 1
    num, d = 0, 1
    for s in S[::-1]:
        s = int(s)
        num = (num + (s * d)) % P
        d = (10 * d) % P
        cnts[num] += 1

    for cnt in cnts:
        ans += cnt * (cnt - 1) // 2
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3500
#include <iostream>
#include <vector>

struct trump {
  std::string suite;
  uint32_t rank;

  trump() : suite(""), rank(0) {}
  trump(const std::string s, uint32_t r) : suite(s), rank(r) {}

  trump& operator=(uint32_t r) {
    rank = r;
    return *this;
  }
  bool operator<=(const trump& lhs) const { return rank <= lhs.rank; }
  bool operator==(const trump& lhs) const {
    return suite == lhs.suite && rank == lhs.rank;
  }
};

uint32_t partition(std::vector<trump>& A, uint32_t start, uint32_t end) {
  uint32_t pivot = end - 1, insert = start;
  for (size_t i = start; i < end; i++) {
    if (A[i] <= A[pivot]) {
      std::swap(A[insert], A[i]);
      insert++;
    }
  }
  return insert - 1;
}

void quick_sort(std::vector<trump>& A, uint32_t start, uint32_t end) {
  if (end - start <= 1) return;
  uint32_t base = partition(A, start, end);
  quick_sort(A, start, base);
  quick_sort(A, base + 1, end);
  return;
}

void merge_sort(std::vector<trump>& A, uint32_t start, uint32_t end) {
  if (end - start == 1) return;
  uint32_t mid = (end + start + 1) / 2;
  merge_sort(A, start, mid);
  merge_sort(A, mid, end);

  std::vector<trump> L(mid - start + 1);
  std::vector<trump> R(end - mid + 1);
  for (uint32_t i = 0; i < mid - start; i++) L[i] = A[start + i];
  for (uint32_t i = 0; i < end - mid; i++) R[i] = A[mid + i];
  L.back() = -1;
  R.back() = -1;

  auto iter_L = L.begin(), iter_R = R.begin();
  for (uint32_t i = 0; i < end - start; i++) {
    if (*iter_L <= *iter_R) {
      A[start + i] = *iter_L;
      iter_L++;
    } else {
      A[start + i] = *iter_R;
      iter_R++;
    }
  }
  return;
}

int main() {
  uint32_t n = 0;
  std::cin >> n;
  std::vector<trump> A(n);
  for (auto&& a : A) std::cin >> a.suite >> a.rank;
  std::vector<trump> B(A);

  quick_sort(A, 0, A.size());
  merge_sort(B, 0, B.size());

  std::cout << (A == B ? "Stable" : "Not stable") << std::endl;
  for (size_t i = 0; i < n; i++) {
    std::cout << A[i].suite << " " << A[i].rank << std::endl;
  }

  return 0;
}


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

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < n - 2; i++)
	for (int j = i + 1; j < n - 1; j++) {
		int dk1 = upper_bound(a.begin() + j + 1, a.end(), a[i] - a[j]) - a.begin();
		int dk2 = upper_bound(a.begin() + j + 1, a.end(), a[j] - a[i]) - a.begin();
		int dk3 = lower_bound(a.begin() + j + 1, a.end(), a[i] + a[j]) - a.begin();
		ans += dk3 - max(dk1, dk2);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [10 ** 18 for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    dp[i] = min(
        dp[i-1] + abs(h[i] - h[i-1]),
        dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])


Measured memory_bytes: 13976
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

a = sorted(a)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

temp = lcm_list(a) - 1

result = 0
for i in a:
    result += temp % i

print(result)

Measured memory_bytes: 5368
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    int re = 0;
    string front = "";
    string rear = "";

    rep(i,q){
        int t; cin >> t;
        if(t == 1){
            re ++;
            continue;
        }
        int f; char c;
        cin >> f >> c;

        if(re %2 == 0 && f == 1) front = c + front;
        if(re %2 == 0 && f == 2) rear = rear + c;
        if(re %2 == 1 && f == 1) rear = rear + c;
        if(re %2 == 1 && f == 2) front = c + front;
        
    }

    string ans = "";

    if(re %2 == 0){
        ans += front;
        ans += s;
        ans += rear;
    }

    if(re %2 == 1){
        reverse(front.begin(), front.end());
        reverse(rear.begin(), rear.end());
        reverse(s.begin(), s.end());
        ans += rear;
        ans += s;
        ans += front;
    }

    dunk(ans);
}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));
  rep(i, N) rep(j, 10) cin >> F[i][j];
  rep(i, N) rep(j, 11) cin >> P[i][j];
  
  priority_queue<int> q;
  
  bitset<10> x;
  rep(i, 1023) {
    x = i+1;
    int a = 0;
    rep(j, N) {
      int c = 0;
      rep(k, 10) if(x[k]*F[j][k] == 1) c++;
      a += P[j][c];
    }
    q.push(a);
  }
  

  cout << q.top() << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a{1};
  while ((int)a.size() < n - 1) {
    set<int> se(begin(a), end(a));
    for (int e : a) for (int f : a) if (e < f) {
      se.insert(e + f);
    }
    for (int x = a.back(); ; ++x) if (!se.count(x)) {
      bool ok = true;
      for (int e : a) {
        if (se.count(x + e)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        a.push_back(x);
        break;
      }
    }
  }
  auto fn = [&](const auto& fn, int n) -> VV<lint> {
    if (n == 2) {
      return {{0, 1}, {1, 0}};
    }
    auto res = fn(fn, n - 1);
    lint mx = 0;
    {
      V<> vs(n - 1);
      iota(begin(vs), end(vs), 0);
      do {
        lint curr = 0;
        int p = -1;
        for (int v : vs) {
          if (p != -1) curr += res[p][v];
          p = v;
        }
        mx = max(mx, curr);
      } while (next_permutation(begin(vs), end(vs)));
    }
    V<lint> v;
    for (int i = 0; i < n - 1; ++i) {
      res[i].push_back(a[i] * (mx + 1));
      v.push_back(res[i].back());
    }
    v.push_back(0);
    res.push_back(v);
    return res;
  };
  for (const auto& v : fn(fn, n)) {
    for (int i = 0; i < n; ++i) {
      cout << v[i] << " \n"[!(n + ~i)];
    }
  }
}

Measured memory_bytes: 892
from collections import Counter
def main():
    N = int( input())
    t = 10**18
    A = list( map( int, input().split()))
    ans = 1
    if Counter(A)[0] > 0:
        print(0)
        return
    for a in A:
        ans *= a
        if ans > t:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 24556
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

//constexpr int MOD = 1000000007;

class Combination {
 public:
  constexpr Combination() {
    Build();
  }
  static constexpr int MOD = 1000000007;
  static constexpr int n_ = 800000;
  struct table {
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  table t {};
  constexpr int64 com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return t.factorial_[n] * (t.finverse_[k] * t.finverse_[n - k] % MOD) % MOD;
  }
 private:
  constexpr void Build() noexcept {
    //table t {};
    t.factorial_[0] = 1; t.factorial_[1] = 1;
    t.finverse_[0] = 1; t.finverse_[1] = 1;
    t.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      t.factorial_[i] = t.factorial_[i - 1] * i % MOD;
      t.inverse_[i] = MOD - t.inverse_[MOD % i] * (MOD / i) % MOD;
      t.finverse_[i] = t.finverse_[i - 1] * t.inverse_[i] % MOD;
    }
  }
};

Combination kyomukyomupurin;

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

  int x, y; cin >> x >> y;
  auto ok = [](int xx, int yy) -> bool {
    if (xx * 2 < yy || xx > yy * 2) return false;
    return (xx + yy) % 3 == 0;
  };

  if (!ok(x, y)) {
    cout << 0 << endl;
    return 0;
  }

  int nn = (x + y) / 3;
  int r = x - nn;

  cout << kyomukyomupurin.com(nn, r) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
template <typename Container> void P(const Container &c) {
    for (const auto& x : c) cout << x << ' '; cout << '\n';
}
const int MOD = 1000000007;
int ADD(int x, int y) { return (x + y) % MOD; }
int MUL(int x, int y) { return ((Int)x * y) % MOD; }
int FACT(int x) {
    if (x == 0) return 1;
    static int memo[100002];
    static bool init = false;
    if (!init) {
        REP(i, 100002) memo[i] = -1;
        init = true;
    }
    if (memo[x] != -1) return memo[x];
    else return memo[x] = MUL(x, FACT(x-1));
}
int POW(int x, int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1) res = MUL(res, x);
        x = MUL(x, x);
        y >>= 1;
    }
    return res;
}
int INV(int x) { return POW(x, MOD-2); }
int COMB(int n, int k) { return MUL(FACT(n), INV(MUL(FACT(n-k), FACT(k)))); }
int main()
{
    int N; cin >> N;
    vector<int> pos(N+1, -1);
    int dupidx, dupnum;
    REP(i, N+1) {
        int a; cin >> a;
        a--;
        if (pos[a] == -1) pos[a] = i;
        else dupidx = i, dupnum = a;
    }
    int M = dupidx - pos[dupnum] + 1;
    for (int k = 1; k <= N+1; k++) {
        int remove = N+1-M < k-1 ? 0 : COMB(N+1-M, k-1);
        cout << ADD(COMB(N+1, k), MOD-remove) << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
cnt = [0]*11
for _ in range(H):
  for a in map(int, input().split()):
    cnt[a] += 1
D = [[C[i][j] for j in range(10)] for i in range(10)]
k = 0
while k < 10:
  i = 0
  while i < 10:
    j = 0
    while j < 10:
      D[i][j] = min(D[i][j], D[i][k]+D[k][j])
      j += 1
    i += 1
  k += 1
print(sum([cnt[i]*D[i][1] for i in range(10)]))

Measured memory_bytes: 40684
K, A, B = gets.strip.split(/ /).collect{|n| n.to_i}

if B - A <= 2
	puts K + 1
else
	k = K - (A - 1)
	if k < 2
		puts K + 1
	else
		k2 = k / 2
		puts A + k2 * (B - A) + (k % 2)
	end
end



Measured memory_bytes: 1788
#coding:utf-8
#1_3_B
n, q = map(int, input().split())
total_time = 0
queue = [input().split() for i in range(n)]

while queue:
    ps = queue.pop(0)
    time = int(ps[1])

    if time <= q:
        total_time += time
        print(ps[0], total_time)
    else:
        total_time += q
        time -= q
        ps[1] = time
        queue.append(ps)

Measured memory_bytes: 19608
#include <stdio.h>
#include <string.h>

char s[101];

int main(void)
{
    int flag = 1;
    int i;
    int len;

    scanf("%s", s);

    len = strlen(s);

    for (i = 0; i < len; i++) {
        if ((i % 2) == 1) {
            if (s[i] == 'R') {
                flag = 0;
                break;
            }
        } else {
            if (s[i] == 'L') {
                flag = 0;
                break;
            }
        }
    }

    if (flag == 1) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
amax = 0
ind = -1
for i in range(N):
    if abs(A[i])>amax:
        amax = abs(A[i])
        ind = i
if amax==0:
    print(0)
else:
    m = 2*N-2
    B = []
    if A[ind]>=0:
        for i in range(N):
            if i!=ind:
                B.append((ind+1,i+1))
        for i in range(N-1):
            B.append((i+1,i+2))
    else:
        for i in range(N):
            if i!=ind:
                B.append((ind+1,i+1))
        for i in range(N,1,-1):
            B.append((i,i-1))
    print(m)
    for i in range(m):
        print(B[i][0],B[i][1])

Measured memory_bytes: 62528
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

int N,M;
string S;

signed main(){
  cin>>N>>M;
  if(M>=N)print("unsafe")
  else print("safe")
  
}


Measured memory_bytes: 3648
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(A: Long, B: Long, S: String){
    val a = A.toInt()
    if(S[a]!! != '-'){
        println(NO)
        return
    }
    if(S.count{ it in "0123456789" } == (A+B).toInt()){
        println(YES)
    }else println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val S = sc.next()
    solve(A, B, S)
}



Measured memory_bytes: 31384
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    s = "." + s + ".";

    string t(q, ' '), d(q, ' ');
    for(int i=0; i<q; ++i)
        cin >> t[i] >> d[i];

    int l = 1;
    int r = n;
    for(int i=q-1; i>=0; --i){
        if(d[i] == 'L'){
            if(s[l] == t[i])
                ++ l;
            if(s[r+1] == t[i])
                ++ r;
        }
        else{
            if(s[r] == t[i])
                -- r;
            if(s[l-1] == t[i])
                -- l;
        }
    }

    int ans = max(0, r - l + 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
/*1478932871*/
int n,a,b,c;
/*1478932871*/
main() {
	cin>>n>>b;
	/*1478932871*/
	for(int i=1; i<=n; i++) {
		cin>>c;
		if(c<=b/2) a+=c*2;
		else a+=(b-c)*2;
	}
	/*1478932871*/
	cout<<a<<"\n";
	/*1478932871*/
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;


int n, m;
int tmp [100003];


int main ()
{

     while (scanf ("%d",&n)!=EOF)
     {
         for (int i=0;i<n;i++)
            scanf ("%d",&tmp[i] ) ;
         sort (tmp , tmp +n ) ;
         int left ,right ;
         right = tmp [n-1] ;
         left = tmp [0] ;
         int index = lower_bound( tmp , tmp+n, right /2 ) -tmp  ;
         //printf ("%d\n",index );
         if (index  > 0) left =  min (right - tmp [index ] , tmp [index ]) >min (right - tmp [index-1 ] , tmp [index-1 ]) ?tmp [index ] : tmp [index-1 ] ;
         printf ("%d %d\n",right,left );

     }
    return 0;
}


Measured memory_bytes: 640
import bisect 
from itertools import accumulate

N = int(input())
a = sorted([int(i) for i in input().split()])  #;print(a)
b = sorted([int(i) for i in input().split()])  #;print(b)
c = sorted([int(i) for i in input().split()])  #;print(c)

bc = [0] * N 
for i in range(N):
    bc[i]= N - bisect.bisect_right(c, b[i])
bcA = [0] + list(accumulate(bc))               #; print(bc); print(bcA)

cnt = 0
for i in range(N):
    x = bisect.bisect_right(b, a[i])            
    cnt += bcA[-1] - bcA[x]                    #; print(a[i], x, bcA[-1] - bcA[x]) 

print(cnt)

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

P seito[60];
P check[60];


int main(){
    int n,m;
    cin >> n >> m;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        seito[i]={a,b};
    }
    rep(i,m){
        ll c,d;
        cin >> c >> d;
        check[i]={c,d};
    }
    rep(i,n){
        int ans=0;
        ll M = 1<<29;
        rep(j,m){
            ll kyori;
            kyori = abs(seito[i].first-check[j].first)+abs(seito[i].second-check[j].second);
            if (kyori<M){
                M=kyori;
                ans=j+1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>
#include <cassert>
using namespace std;
long long X, imax = 0;
inline long long sig(long long i) {
	return i >= 0 ? 1 : -1;
}
inline long long p5(long long i) {
	return i * i * i * i * i;
}
inline long long rev(long long i) {
	long long l = 0, u = imax, m;
	while (l != u) {
		m = (l + u) / 2;
		if (p5(m) >= llabs(i)) u = m;
		else l = m + 1;
	}
	return l * sig(i);
}
int main() {
	scanf("%lld", &X);
	set<long long> st;
	for (long long i = 0; p5(i) - p5(i - 1) <= X; ++i) st.insert(p5(i)), imax = i;
	for (long long i = -imax; i <= imax; ++i) {
		if (st.find(X + p5(i)) != st.end()) {
			printf("%lld %lld", rev(X + p5(i)), i);
			return 0;
		} else if (st.find(-X - p5(i)) != st.end()) {
			printf("%lld %lld", rev(X + p5(i)), i);
			return 0;
		}
	}
	assert(false);
	return 0;
}

Measured memory_bytes: 3300
#A
h = int(input())
w = int(input())
n = int(input())

cnt = 0
flg = True
if h > w:
    while flg:
        if h * cnt >= n:
            flg = False
            break
        cnt += 1
        
else:
    while flg:
        if w * cnt >= n:
            flg = False
            break
        cnt += 1
        
print(cnt)

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

    using namespace std;

    const int MOD=1e9+7;
    int n,m,x;
    long long cost=1e18;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cin>>n>>m>>x;
        vector<vector<int>>book(n,vector<int>(m+1));
        for(int i=0;i<n;i++){
            for(int j=0;j<=m;j++){
                cin>>book[i][j];
            }
        }
        for(int i=1;i<(1<<n);i++){
            long long total=0;
            vector<long long>val(m);
            for(int j=0;j<n;j++){
                if(i&(1<<j)){
                    total+=book[j][0];
                    for(int k=0;k<m;k++)
                        val[k]+=book[j][k+1];
                }
            }
            bool flag=1;
            for(int j=0;j<m;j++){
                if(val[j]<x){
                    flag=0;
                    break;
                }
            }
            if(flag)
                cost=min(cost,total);
        }
        if(cost==1e18)
            cout<<-1;
        else
            cout<<cost;
        return 0;
    }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
string str; set<string> s; char ss[N];
int main()
{
  scanf("%s",ss+1); int len = strlen(ss+1); int K; cin>>K;
  
  for(int i=1;i<=len;i++)
  {
  	str.clear();
  	for(int j=0;j<=K && i+j<=len;j++)
  	{
  	  str.push_back(ss[i+j]);
  	  s.insert(str);
  	}
  }
  while(K!=1){s.erase(s.begin()); K--;}
  cout<<(*s.begin())<<endl; 
  return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

  	int five =0;
   	int seven =0;
  	int number =0;
  
  for(int i = 0; i<3; i++){
    cin >> number; 
  	if(number==5){
		five++;    	
    }
    else if(number==7){
    	seven++;
    }
  }
 
    if(five==2 && seven==1){
    	cout << "YES" << endl;
    }
  	else{
    	cout << "NO" << endl;
    }
    
  	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()

  val mod = 1000000007

  def times(a: Long, b: Long): Long = (a * b) % mod

  val ans = (1 to n).map(_.toLong).reduceLeft(times)
  println(ans)
}


Measured memory_bytes: 58576
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N;
	int p[11];
	cin >> N;
	int ans = 0;

	for (int i = 0; i <= N - 1; i++) {
		cin >> p[i];
		ans += p[i];
	}
	sort(p, p + N);

	cout << ans - p[N - 1] / 2;

}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int divCount(int tmp) {
  int result = 0;
  while ((tmp / 100) > 0) {
    if ((tmp % 100) == 0) {
      result++;
    }
    tmp /= 100;
  }
  return result;
}

int main() {
  int d, n;
  cin >> d >> n;

  int a = pow(100, d);
  int result = -1;
  int count = 0;
  for (int i = 1; i <= 10000; ++i) {
    int tmp = a * i;
    if (divCount(tmp) == d) {
      count++;
    }
    if (count == n) {
      result = tmp;
      break;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
from itertools import combinations

def get_d_min(a, b, X, Y):

    d = abs(a - b)
    if a == X and b == Y:
        d = 1
    elif a <= X and b > X and b <= Y:
        dd = (X - a) + (Y - b) + 1
        d = min(d, dd)
    elif a >= X and a < Y and b >= Y:
        dd = (a - X) + (b - Y) + 1
        d = min(d, dd)
    elif a > X and b < Y:
        dd = (a - X) + (Y - b) + 1
        d = min(d, dd)
    elif a < X and b > Y:
        dd = (X - a) + (b - Y) + 1
        d = min(d, dd)
    return d

N, X, Y = map(int, input().split())

comb = combinations(range(1, N + 1), 2)

counts = [0] * N
for a, b in comb:
    a, b = min(a, b), max(a, b)
    d_min = get_d_min(a, b, X, Y)
    counts[d_min] += 1

for count in counts[1:]:
    print(count)

Measured memory_bytes: 50780
ops = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}

stack = []
for s in input().split():
    if s in ops:
        stack.append(ops[s](stack.pop(), stack.pop()))
    else:
        stack.append(int(s))
print(stack[-1])

Measured memory_bytes: 6724
n=int(input())
a=[]
rn=0
cnt=0
for i in range(n):
    b,c=map(int,input().split())
    a.append([b,c])
a=a[::-1]
  
for i in range(n):
    b,c=a[i]
    b+=cnt
    cnt+=(c-b%c)%c
print(cnt)


Measured memory_bytes: 20520
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end();
#define pp pair<ll,ll>
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
using namespace std;
vector<pp> pps[200010];
int main() {
	int a, b, c, x,ct=0;
	cin >> a >> b >> c >> x;
	rep(i, a+1)rep(j, b+1)rep(w, c+1) {
		if (500 * i + 100 * j + 50 * w == x)++ct;
	}
	cout << ct << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

typedef long long ll;

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

struct Data
{
	int x, y, cost;
	Data() {}
	Data(int _x, int _y, int _cost)
	{
		x = _x;
		y = _y;
		cost = _cost;
	}

	bool operator < (const Data &a) const
	{
		return cost > a.cost;
	}
};

int main(){
	int R, C;
	char fld[30][30];
	priority_queue<Data> q;
	cin >> R >> C;
	for (int i = 0; i < R; i++)
	{
		for (int j = 0; j < C; j++)
		{
			cin >> fld[i][j];
			if (fld[i][j] == 'S') q.push(Data(j, i, 0));
		}
	}
	
	Data t;
	bool memo[30][30] = {};
	while (!q.empty())
	{
		t = q.top();
		q.pop();

		//printf("%d, %d, %d\n", t.y, t.x, t.cost);

		if (fld[t.y][t.x] == 'G')
		{
			printf("%d\n", t.cost);
			return 0;
		}

		if (memo[t.y][t.x]) continue;
		memo[t.y][t.x] = true;

		for (int i = 0; i < 4; i++)
		{
			int nx = t.x, ny = t.y;
			for (int j = 1; j <= 3; j++)
			{
				nx += dx[i];
				ny += dy[i];
				if (nx < 0 || C <= nx || ny < 0 || R <= ny || fld[ny][nx] == '#') break;
				int cost = 0;
				if (j >= 2) cost = 2 + j;
				else
				{
					if(fld[ny][nx] == 'o') cost = 1;
					else if(fld[ny][nx] == 'x') cost = 3;
					else cost = 2;
				}

				q.push(Data(nx, ny, t.cost + cost));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1200