akhauriyash/Code-Regression huggingface dataset:
N,W=map(int,input().split())
w=[0]*N;v=[0]*N
for i in range(N):w[i],v[i]=map(int,input().split())
V=[[] for _ in [0]*4]
for i in range(N):V[w[i]-w[0]].append(v[i])
for i in range(4):
    V[i].sort(reverse=True)
    for j in range(len(V[i])-1):V[i][j+1]+=V[i][j]
    V[i].insert(0,0)

a=0
for i in range(len(V[0])):
    for j in range(len(V[1])):
            for k in range(len(V[2])):
                for l in range(len(V[3])):
                    if i*w[0]+j*-~w[0]+k*-~-~w[0]+l*-~-~-~w[0]<=W:a=max(a,V[0][i]+V[1][j]+V[2][k]+V[3][l])
print(a)

Measured memory_bytes: 3064
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 1e2 + 5;
const int V = 1e5 + 5; 
int dp[N][V] ;
int W[N], v[N] ;

void solve(int test) {
	int n, w; cin >> n >> w ;
	rep(i,0,n) cin >> W[i] >> v[i] ;

	for(int i = 0 ; i < N ; ++i ) for(int j = 0 ; j < V ; ++j) dp[i][j] = INF ;

	dp[0][v[0]] = W[0] ;

	rep(i,1,n) {
		for(int j = 0 ; j < V ; ++j) dp[i][j] = dp[i-1][j] ;
		for(int j = V - v[i]-1 ; j >=0 ; --j) dp[i][j + v[i]] =  min(dp[i][j + v[i]], dp[i][j] + W[i]);
		dp[i][v[i]] = min(dp[i][v[i]],W[i]);
		for(int j = 0 ; j < V ; ++j) if(dp[i][j] > w ) dp[i][j] = INF ;
	}

	for(int i = V-1 ; i>=0; --i ) if(dp[n-1][i] <= w ) {
		cout << i << nl ;return ;
	}
}
 
int32_t main() {

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 85688
import sys
W=int(input().split()[1])
C=[0]*-~W
for e in sys.stdin:
 v,w=map(int,e.split())
 for i in range(W,w-1,-1):
  t=v+C[i-w]
  if t>C[i]:C[i]=t
print(C[W])


Measured memory_bytes: 5928
fun main(args: Array<String>) {
    val (a, b, x) = readInputLine().split(" ").map{it.toInt()}
    
    if (a <= x && x <= a + b) {
        println("YES")
    } else {
        println("NO")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;


int main() {
    ll n,tmp;
    cin >> n;
    tmp = n;
    for (ll i = 1; i*i <= n; ++i) {
        if(n%i == 0) tmp = min(tmp,n/i-1+i-1);
    }
    cout << tmp << endl;
    return 0;
}


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

using namespace std;

#define ROW 8
#define COLUMN 8

#define INSIDE_INDEX( x1 , y1 ) ( (x1 >= 0 && x1 < ROW) && (y1 >= 0 && y1 < COLUMN) )

void get_answer( string *matrix_str , char& ans );
bool get_ans( string *matrix_str , int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 );

int main(void)
{
	string matrix_str[ROW+3];
	char c;

	while(1)
	{
		char ans = '0';
		int flag = 0; // 二重ループ脱出用
		for( int i = 0 ; i < COLUMN ; i++ )
		{
			cin >> matrix_str[i];
			if( cin.eof() )
			{
				flag = 1;
				break;
			}
		}
		if( flag == 1 )
		{
			break;
		}
		get_answer( matrix_str , ans );
		cout << ans << endl;
	}

	return 0;
}

void get_answer( string *matrix_str , char& ans )
{
	for( int i = 0 ; i < ROW ; i++ )
	{
		for( int j = 0 ; j < COLUMN ; j++ )
		{
			if( get_ans( matrix_str ,  j ,  i ,  j+1 ,  i ,  j ,  i+1 ,  j+1 ,  i+1 ) )
			{
				ans = 'A';
			}

			if( get_ans( matrix_str , j , i , j , i+1 , j , i+2 , j , i+3 ) )
			{
				ans = 'B';
			}

			if( get_ans( matrix_str , j , i , j+1 , i , j+2 , i , j+3 , i ) )
			{
				ans = 'C';
			}

			if( get_ans( matrix_str , j , i , j-1 , i+1 , j , i+1 , j-1 , i+2 ) )
			{
				ans = 'D';
			}

			if( get_ans( matrix_str , j , i , j+1 , i ,  j+1 , i+1 , j+2 , i+1) )
			{
				ans = 'E';
			}

			if( get_ans( matrix_str , j , i , j , i+1 , j+1 , i+1 , j+1 , i+2) )
			{
				ans = 'F';
			}

			if( get_ans( matrix_str , j , i , j+1 , i , j-1 , i+1 , j , i+1 ) )
			{
				ans = 'G';
			}
		}
	}
}

bool get_ans( string *matrix_str , int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 )
{
	if( INSIDE_INDEX( x1 , y1 ) && INSIDE_INDEX( x2 , y2 ) && INSIDE_INDEX( x3 , y3 ) && INSIDE_INDEX( x4 , y4 ) )
	{
		if( matrix_str[y1].at(x1) == '1' &&
			matrix_str[y2].at(x2) == '1' &&
			matrix_str[y3].at(x3) == '1' &&
			matrix_str[y4].at(x4) == '1' )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

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

int w, h, c;

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}
int gcd(int a, int b) {
	if (a == 0) return b;
	if (a < b) {
		swap(a, b);
	}
	return gcd(a%b, b);
}

int main(){
	scanf("%d%d%d", &w, &h, &c);
	int g = gcd(h, w);
	printf("%d\n", w*h / g / g*c);

	return 0;
}

Measured memory_bytes: 2728
"use strict";

function Main(input) {
  var inputArr = input.split("\n");
  var nm = inputArr[0].split(" ");
  var as = inputArr[1].split(" ").map(function (e) {
    return Number(e);
  });
  var sum_a = as.reduce(function (pre, cur) {
    return pre += cur;
  });
  var i = 0;
  var count = 0;

  while (i < as.length) {
    if (as[i] >= sum_a * (1 / (4 * nm[1]))) {
      count++;
    }

    i++;
  }

  console.log(count >= nm[1] ? 'Yes' : 'No');
} // Main(`12 3
// 4 56 78 901 2 345 67 890 123 45 6 789`)


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

Measured memory_bytes: 21064
import math

while True:
    n = input()
    
    if n == "0":
        break
    else:
        score = list(map(float, input().split()))
        m = sum(score)/len(score)
        for i in range(len(score)):
            score[i] = (score[i]-m)**2
    answer = math.sqrt(sum(score)/len(score))
    print(answer)

Measured memory_bytes: 7596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B;
    cin >>A>>B;
    ll ans = (A+B)/2;
    if((A+B)%2==0){
        cout<<ans<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }

    


    return 0;
    

}

Measured memory_bytes: 3580
#include <cstdio>
#include <stack>
#include <cstdlib>
#include <string>

using namespace std;

// ??¬???

int main(){

    char s[1000000];

    int result, i, a, b;
    stack<int> S;

    while( scanf("%s", &s) != EOF ){

        if( s[0] == '+' ){

            a = S.top();
            S.pop();
            b = S.top();
            S.pop();

            S.push( a + b );

        } else if( s[0] == '-' ){

            a = S.top();
            S.pop();
            b = S.top();
            S.pop();

            S.push( b - a );

        } else if( s[0] == '*' ){

            a = S.top();
            S.pop();
            b = S.top();
            S.pop();

            S.push( a * b );

        } else {

            S.push( atoi(s) );

        }

    }

    result = S.top();

    printf("%d\n", result);

    return 0;

}

Measured memory_bytes: 2772
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, o;
  cin >> o;
  for (int i = 1; i <= o; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      n = i;
      while (n > 0) {
        if (n % 10 == 3) {
          cout << " " << i;
          break;
        }
        n = n / 10;
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> hs(n);
    for(int i=0; i<n; ++i){
        cin >> hs[i];
    }
    bool ans=true;
    for(int i=n-2; i>=0; --i){
        if(hs[i]<=hs[i+1]){}
        else if(hs[i]-1==hs[i+1]){
            --hs[i];
        }else{
            ans=false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define N 2000011
using namespace std;
struct point{
	int l,r;
	point(){}
	point(int x,int y){l=x,r=y;}
}target[N];
int used[N],Lock[N],L[N],R[N],n,ans,que[N],head=1,tail=0;
char S[N],T[N],s[N];
int judge(){
	for(int i=1;i<=n;i++){
		if(S[i]!=T[i]) return 0;
	}
	return 1;
}
void init(){
	L[1]=1;R[n]=n;
	for(int i=2;i<=n;i++){
		if(T[i]==T[i-1]) L[i]=L[i-1];
		else L[i]=i;
	}
	for(int i=n-1;i>=1;i--){
		if(T[i]==T[i+1]) R[i]=R[i+1];
		else R[i]=i;
	}
}
void solve(){
	for(int i=n,j=n;i>=1;i=L[i]-1){
		j=min(j,L[i]);
		while(S[j]!=T[i] && j) j--;
		if(!j){
			printf("-1");
			exit(0);
		}
		while(head<=tail && que[head]-(tail-head)>i) head++;
		que[++tail]=j;
		ans=max(ans,tail-head+1);
	}
}
int main(){
	scanf("%d",&n);
	scanf("%s",S+1);
	scanf("%s",T+1);
	if(judge()){
		printf("0");
		return 0;
	}
	init();
	solve();
	printf("%d",ans);
	return 0;
}

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

const int MAX=15;
const ll MOD=1000000007;
char arr[MAX][MAX],build1[MAX][MAX],build2[MAX][MAX];
int arrh[MAX][26],arrw[MAX][26],chkh[MAX],chkw[MAX],cnth,cntw;
int h,w;
int mat_h(int x,int y){
    for(int i=0;i<26;i++) if(arrh[x][i]!=arrh[y][i]) return 0;
    return 1;
}
int coll_h(int x,int y){
    for(int j=0;j<w;j++) build1[cnth/2][j]=arr[x][j];
    for(int j=0;j<w;j++) build1[h-1-cnth/2][j]=arr[y][j];
}
int mat_w(int x,int y){
    for(int i=0;i<26;i++) if(arrw[x][i]!=arrw[y][i]) return 0;
    return 1;
}
int coll_w(int x,int y){
    for(int i=0;i<h;i++) build2[i][cntw/2]=build1[i][x];
    for(int i=0;i<h;i++) build2[i][w-1-cntw/2]=build1[i][y];
}
int main(){
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;i++) scanf(" %s",arr[i]);
    for(int i=0;i<h;i++) for(int j=0;j<w;j++){
        arrh[i][arr[i][j]-'a']++,arrw[j][arr[i][j]-'a']++;
    }
    for(int i=0;i<h;i++) for(int j=i+1;j<h;j++){
        if(chkh[i]==0&&chkh[j]==0) {
            if(mat_h(i,j)) coll_h(i,j),chkh[i]=1,chkh[j]=1,cnth+=2;
        }
    }
    if(cnth/2!=h/2){
        printf("NO\n");
        return 0;
    }
    else if(cnth%2){
        for(int i=0;i<h;i++) if(chkh[i]!=0) coll_h(i,i);
    }
    for(int i=0;i<w;i++) for(int j=i+1;j<w;j++){
        if(chkw[i]==0&&chkw[j]==0) {
            if(mat_w(i,j)) coll_w(i,j),chkw[i]=1,chkw[j]=1,cntw+=2;
        }
    }
    if(cntw/2!=w/2){
        printf("NO\n");
        return 0;
    }
    else if(cntw%2){
        for(int i=0;i<w;i++) if(chkw[i]!=0) coll_w(i,i);
    }
    for(int i=0;i<h;i++) for(int j=0;j<w;j++){
        //printf("%c",build2[i][j]);
        if(build2[i][j]!=build2[h-1-i][w-1-j]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        int comboN = (N*(N-1))/2;
        int comboM = (M*(M-1))/2;

        System.out.println(comboN+comboM);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String t = scan.next();
        int a = scan.nextInt();
        int b = scan.nextInt();
        String u = scan.next();

        if (s.equals(u)) {
            a--;
        } else {
            b--;
        }
        System.out.print(a);
        System.out.print(' ');
        System.out.println(b);
    }
}


Measured memory_bytes: 20820
list = input().split()
 
for i in range(0, len(list)):
	list[i] = int(list[i])
    
a = list[0]
b = list[1]
c = list[2]
 
if a == b:
  if a != c:
    print("Yes")
  else:
    print("No")
elif b == c:
  if a != b:
    print("Yes")
  else:
    print("No")
elif a == c:
  if a != b:
    print("Yes")
  else:
    print("No")
    
elif a != b:
  if a != c:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=1005;
int n,m,X[MN],Y[MN],v[MN];
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++){
		scanf("%d%d",X+i,Y+i);
		if(i>1&&(((X[i]+Y[i])&1)^((X[i-1]+Y[i-1])&1)))
			return 0*puts("-1");
	}
	reg int t=(X[1]+Y[1])&1;
	printf("%d\n",m=32-t);
	if(!t)v[m]=1;
	for(reg int i=1;i<=m-(!t);i++)v[i]=1<<(31-i);
	for(reg int i=1;i<=m;i++)printf("%d ",v[i]);
	puts("");
	for(reg int i=1;i<=n;i++,puts("")){
		reg ll dx=0,dy=0,xx,yy;
		for(reg int j=1;j<=m;j++){
			xx=X[i]-dx;yy=Y[i]-dy;
			if(llabs(xx)>llabs(yy)){
				if(xx>0)putchar('R'),dx+=v[j];
				else putchar('L'),dx-=v[j];
			}
			else{
				if(yy>0)putchar('U'),dy+=v[j];
				else putchar('D'),dy-=v[j];
			}
		}
	}
	return 0;
}

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

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int n; cin>>n;
	string s;
	cin >> s;
	vector<set<int>> poss(26);
	for (int i = 0; i < int(s.size()); ++i) {
		poss[s[i] - 'a'].insert(i);
	}
	
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int pos;
			char c;
			cin >> pos >> c;
			--pos;
			poss[s[pos] - 'a'].erase(pos);
			s[pos] = c;
			poss[s[pos] - 'a'].insert(pos);
		} else {
			int l, r;
			cin >> l >> r;
			--l, --r;
			int cnt = 0;
			for (int c = 0; c < 26; ++c) {
				auto it = poss[c].lower_bound(l);
				if (it != poss[c].end() && *it <= r) ++cnt;
			}
			cout << cnt << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 27200
#include <iostream>

using namespace std;

int main() {
    int k,a,b,v;
    cin>>k>>a>>b;
    for(v=0;v<=b;v=v+1){
        if(v%k==0){
            if(v>=a && v<=b){
                cout<<"OK"<<"\n";
                return 0;
            }
        }
    }
    cout<<"NG"<<"\n";
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


int main(void)
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll n;
	vector<ll> a;
	cin >> n;
	REP(i, n) {
		ll tmp;
		cin >> tmp;
		a.pb(tmp);
	}

	VRSORT(a);

	ll alice = 0;
	ll bob = 0;

	REP(i, n) {
		if (i % 2 == 0) alice += a[i]; else bob += a[i];
	}

	cout << alice - bob << endl;

}

Measured memory_bytes: 256
N = int(input())
A = [int(val) for val in input().split()]
B = [int(val) for val in input().split()]
C = [int(val) for val in input().split()]

ans = sum(B)

for i in range(1, N):
    if A[i - 1] == A[i] - 1:
        if len(C) - 1 >= A[i] - 2: 
          ans += C[A[i] - 2]
          # print('{}:{}'.format(i, C[i - 2]))

print('{}'.format(ans))



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

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll d1 = x * a + y * b;
    ll d2 = 2 * c * max(x, y);
    ll d3;
    if(x > y) d3 = 2 * c * y + a * (x - y);
    else d3  = 2 * c * x + b * (y - x);
    cout << min({d1, d2, d3}) << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;, i < n; i++)
#define rep_2(i,n) for(int i=n, i > 0; i--)
using namespace std;
using ln = long long;

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

    if(s=="AAA" || s=="BBB")
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3628
n,m=map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
x=make_divisors(m)
for i in range(len(x)):
	if x[i]>=n:
		print(x[-i-1])
		break

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

#include <iostream>
#include <string>

using namespace std;

static unsigned int K = 2019;
int R[2019] = {0};

int main(int argc, char* argv[]){
	char str[200000+1]={0};
	int L=0;

	scanf("%s", str);
	L = strlen(str);

	int u0 = atoi(&str[L-1]);
	R[u0]++;
	int r0=1, r1=1;
	int u1=0;
	for(int i=1; i<L; i++){
		char c[2]={0};
		c[0] = str[L-1-i];
		int a = atoi(c);
		//u1 = u0 + a*(10**i)i;
		r1 = (r0*10)%K;
		u1 = a*r1 + u0 ;
		u1 = u1%K;
		R[u1]++;
		r0 = r1;
		u0 = u1;
	}

	long long ans = R[0];
	for(int i=0; i<K; i++){
		int m = R[i];
		if( m>1 ){
			ans += (m*(m-1))/2; 
		}
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4028
#include <stdio.h>

typedef struct {
    char design; 
    char value;
} Data;

void Copy(Data Array1[],Data Array2[],int index) {
    int i; 
    for (i=0; i<index; i++) {
        Array2[i]=Array1[i];
    }
}
int ReadValue() {
    int value; 
    scanf("%d",&value); 
    return value;
}
void ReadStruct(Data Array[],int index) {
    int i; 
    for (i=0; i<index; i++) {
        scanf(" %c",&Array[i].design);
        scanf(" %c",&Array[i].value);
    }
}
void swap(Data *a,Data *b) {
    Data temp; 
    temp=*a; 
    *a=*b; 
    *b=temp;
}
void bubbleSort(Data Array[],int index) {
    int flag=1; 
    while (flag) {
        flag=0; 
        int j; 
        for (j=index-1; j>=1; j--) {
            if (Array[j].value<Array[j-1].value) {
                swap(&Array[j],&Array[j-1]);
                flag=1;
            }
        }
    }
}
void selectionSort(Data Array[],int index) {
    int i;
    for (i=0; i<index; i++) {
        int minj=i,j; 
        for (j=i; j<index; j++) {
            if (Array[j].value<Array[minj].value) {
                minj=j;
            }
        }
        swap(&Array[i],&Array[minj]);
    }
}
int CompareData(Data Array1[],Data Array2[],int index) {
    int i; 
    for (int i=0; i<index; i++) {
        if (Array1[i].design!=Array2[i].design) {
            return 0;
        }
    }
    return 1;
}
void Display(Data Array1[],Data Array2[],int index) {
    for (int i=0; i<index; i++) {
        if (i>0) {
            printf(" ");
        }
        printf("%c%c",Array1[i].design,Array1[i].value);
    }
    printf("\n");
    printf("Stable\n");
     for (int i=0; i<index; i++) {
        if (i>0) {
            printf(" ");
        }
        printf("%c%c",Array2[i].design,Array2[i].value);
    }
    printf("\n");
    if (CompareData(Array1,Array2,index)) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
}
int main() {
    int N=ReadValue();
    Data bubbleSortData[N]; ReadStruct(bubbleSortData,N);
    Data selectionSortData[N]; Copy(bubbleSortData,selectionSortData,N);
    bubbleSort(bubbleSortData,N); selectionSort(selectionSortData,N);
    Display(bubbleSortData,selectionSortData,N);
    return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>

int N;
struct edge{int to,nxt;}E[250];
int H[150],tot;
void add_edge(int a,int b){
	E[++tot]=(edge){b,H[a]};H[a]=tot;
	E[++tot]=(edge){a,H[b]};H[b]=tot;
}
int dep[150],Far,Dis,S,T;
int DD[150],Fa[150];

void getfar(int now,int fa){
	Fa[now]=fa;
	dep[now]=dep[fa]+1;
	if (dep[now]>Dis) Far=now,Dis=dep[now];
	for (int i=H[now];i;i=E[i].nxt)
		if (E[i].to!=fa) getfar(E[i].to,now);
}

long long ansmin=std::numeric_limits<long long>::max();

void calc(int now,int fa){
	int D=0;
	dep[now]=dep[fa]+1;
	for (int i=H[now];i;i=E[i].nxt){
		if (E[i].to==fa) continue;
		D++;
		calc(E[i].to,now);
	}
	DD[dep[now]]=std::max(DD[dep[now]],D);
}

int main(){
	scanf("%d",&N);
	for (int i=1,x,y;i<N;i++) scanf("%d%d",&x,&y),add_edge(x,y);
	getfar(1,0);
	S=Far;
	Far=Dis=0;
	getfar(S,0);
	T=Far;
	if (!(Dis&1)){
		for (int i=0;i<(Dis>>1)-1;i++) T=Fa[T];
		dep[T]=dep[Fa[T]]=0;
		calc(T,Fa[T]);
		dep[T]=dep[Fa[T]]=0;
		calc(Fa[T],T);
		ansmin=1;
		for (int i=1;i<Dis>>1;i++) ansmin*=DD[i];
		printf("%d %lld\n",Dis>>1,ansmin*2);
	}
	else{
		for (int i=0;i<=(Dis>>1)-1;i++) T=Fa[T];
		calc(T,0);
		long long nowans=1;
		for (int i=1;i<=(Dis>>1);i++) nowans*=DD[i];
		ansmin=std::min(ansmin,nowans);

		for (int i=H[T];i;i=E[i].nxt){
			memset(DD,0,sizeof(DD));
			dep[T]=dep[E[i].to]=0;
			calc(T,E[i].to);
			dep[T]=dep[E[i].to]=0;
			calc(E[i].to,T);
			long long nowans=1;
			for (int i=1;i<=(Dis>>1);i++) nowans*=DD[i];
			ansmin=std::min(ansmin,nowans*2);
		}
		printf("%d %lld\n",(Dis+1)>>1,ansmin);
	}
}


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

#define si(n) scanf("%d",&n)
#define MAX 100005
#define MOD 1000000007
#define ll long long

map<int,int>mp;
int arr[MAX],n,pos,val;
int fact[MAX];

void go()
{
    fact[0]=1;
    for(int i=1;i<MAX;i++){
        fact[i]=((ll)fact[i-1]*i)%MOD;
    }
}

int bigmod(long long a,long long p)
{
    long long ret = 1;
    while(p) {
        if(p & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        p >>= 1;
    }
    return ret;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int i,j;
    si(n);
    for(i=1;i<=n+1;i++){
        si(arr[i]);
        if(mp[arr[i]]){
            pos=i;
            val=arr[i];
        }
        else mp[arr[i]]=i;
    }
    go();

    printf("%d\n",n);
    for(i=2;i<=n;i++){
        int tot=mp[val]-1+(n+1-pos);
        ll a=fact[n+1];
        ll b=((ll)fact[i]*fact[n+1-i])%MOD;
        int ans=(a*bigmod(b,MOD-2))%MOD;
        if(tot<i-1){
            printf("%d\n",ans);
            continue;
        }
        a=fact[tot];
        b=((ll)fact[i-1]*fact[tot-(i-1)])%MOD;

        tot=(a*bigmod(b,MOD-2))%MOD;
        //cout<<ans<<' '<<tot<<endl;
        printf("%d\n",(ans-tot+MOD)%MOD);
    }
    printf("%d\n",1);



}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
long long N;
long long arr[200001];
int main(){
	cin>>N;
	long long ar[N];
	for(long long i=1; i<N; i++){
		cin>>ar[i];
		arr[ar[i]]++;
	}
	for(long long i=1; i<=N; i++){
		cout<<arr[i]<<'\n';
	}
}

Measured memory_bytes: 6716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  ll N, M = 0;
  cin >> N;

  M = N / 1.08;
  
  if (N <= M * 1.08 && M * 1.08 < N+1) {
    cout << M << endl;
    return 0;
  }
  else if (N <= (M+1) * 1.08 && (M+1) * 1.08 < N+1) {
    cout << M+1 << endl;
    return 0;
  }
  else {
    cout << ":(" << endl;
    return 0;
  }
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	int p = 0;
	while(N > 0){
		N /= K;
		p++;
	}
	cout << p << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    ll N,A,B,C,D;
    string S;
    cin >> N >> A >> B >> C >> D;
    cin >> S;
    --A; --B; --C; --D;
    ll minAB = min(A,B);
    ll maxCD = max(C,D);
    ll c = 0;
    // 2個以上 # が連続していれば No
    for2(i,minAB,maxCD+1) {
        if (S[i] == '#') {
            c++;
            if (c == 2) {
                cout << "No" << endl;
                return;
            }
        } else {
            c = 0;
        }
    }

    // 2個以上 # は連続していない

    // 追い抜かしが発生しなければ Yes
    // A B C D
    if (C < D) {
        cout << "Yes" << endl;
        return;
    }

    // A C B D
    if (C < B) {
        cout << "Yes" << endl;
        return;
    }

    // 追い抜かしが発生する
    // A B D C

    // Bの前後が岩でなければYes
    if (S[B-1] != '#' && S[B+1] != '#') {
        cout << "Yes" << endl;
        return;
    }
    // Dの前後が岩でなければYes
    if (S[D-1] != '#' && S[D+1] != '#') {
        cout << "Yes" << endl;
        return;
    }

    // [B,D]で3個以上 . が連続すれば追い抜き可能
    c = 0;
    for2(i,B,D+1) {
        if (S[i] != '#') {
            c++;
            if (c == 3) {
                cout << "Yes" << endl;
                return;
            }
        } else {
            c = 0;
        }
    }

    cout << "No" << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long int mod = 1000000007;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> vec (N);
    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
    }

    for(int i = N-1;i > -1;i -= 2){
        cout << vec.at(i) << " ";
    }
    for(int i = N % 2;i < N;i += 2){
        cout << vec.at(i) << " ";
    }
    cout << endl;
}


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

int main(){
    int first=0,second=0,third=0,now;

    for (int i=1;i<11;i++){
        cin >> now;
        if(now>first){
            third=second;
            second=first;
            first=now;
        }
        else if(now>second){
            third=second;
            second=now;
        }
        else if(now>third) third=now;
    }

    cout << first <<"\n";
    cout << second <<"\n";
    cout << third <<"\n";
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    uint32_t N;
    cin >> N;
    uint32_t ai;
    uint32_t ans(0);
    for (size_t i = 0; i < N; ++i)
    {
        cin >> ai;
        while (ai != 0)
        {
            if (ai % 2 != 0)
            {
                break;
            }
            ans++;
            ai = ai / 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3164
N, M = map(int, input().split())
Costs = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
A = sorted(list(map(int, input().split())), reverse=True)  # 大きい順に


# dp[i]:= マッチ棒をn本使って得られる最大桁数(-infはマッチ棒が使いきれないことを表す)
dp = [-float('inf')] * (N + 1)
dp[0] = 0

# 個数制限なしナップサックと同じ要領
for a in A:
    cost = Costs[a]
    for j in range(N + 1):
        if cost > j:
            continue
        dp[j] = max(dp[j], dp[j - cost] + 1)


# dpの復元
ans = ""
marker = N  # いま何本残っているか
while dp[marker]:  # 0本になるまで回す
    for a in A:  # 大きな数字から見ていく
        cost = Costs[a]
        
        # Python特有のバグ消し
        if marker - cost < 0:
            continue
        
        # marker本ある状態から、マッチ棒をcost本使う数字aを使わなければ、marker本使った場合の桁数-1になる場合、
        # 数字aを使ったことがわかる
        if dp[marker - cost] == dp[marker] - 1:
            ans += str(a)
            marker = marker - cost
            break

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX 100005
using namespace std;
const long long INF = LLONG_MAX/10;
int main() {
    int n, k;
    cin >> n >> k;
    int h[MAX];
    long long dp[MAX];
    rep(i, n) cin >> h[i];
    rep(i, MAX) dp[i] = INF;
    // for(int i = 0; i < n; i++) {
    //     cin >> h[i];
    //     dp[i] = INF;
    // }
    dp[0] = 0;
    // dp[1] = abs(h[1] - h[0]);
    // cout << dp[1] << " ";
    // for(int i = 1; i < n; i++) {
    //     for(int j = i - 1; j >= 0 && i - j <= k; j--) {
    //         dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    //     }
        // cout << dp[i] << " ";
    // }
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n)
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
        // cout << dp[i] << " ";
    }
    cout << dp[n - 1] << endl;
}
/*
5 3
10 30 40 50 20
30
*/
/*
3 1
10 20 10 
20
*/
/*
2 100
10 10
0
*/
/*
10 4
40 10 20 70 80 10 20 70 80 60
*/

Measured memory_bytes: 1408
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);
  int a_cnt = 0;
  bool yes = true;
  for (int i=0;i<N;i++) {
    char s[5];
    scanf("%s", s);
    if (s[0] == 'A') a_cnt++;
    else {
      if (a_cnt == 0) yes = false;
      a_cnt--;
    }
  }
  if (a_cnt > 0) yes = false;
  puts(yes ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 2692
#include <iostream>
#include <cmath>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;

int main() {
	long long N, A[2 * 100005] = { 0 }, B[2 * 100005] = { 0 };
	cin >> N;
	for (int i = 2; i <= N; i++) {
		cin >> A[i];
	}
	for (int i = 2; i <= N; i++) {
		B[A[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		cout << B[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6752
//# pragma GCC optimize("Ofast")
//# pragma GCC target("avx,avx2,fma")
//# pragma GCC optimization ("unroll-loops")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

int n,k;
int dp[70][55][55];
int a[55][55];
int ans[70][55][55];
int answer;

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> n >> k;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= n;j++)
		{
			cin >> a[i][j];
			if(a[i][j] == 1)
			{
				dp[0][i][j] = 1;
				if(k & 1) {
					ans[0][i][j] = 1;
				}
			}
		}
	}
	bool b = 0;
	if(k & 1) b = 1;
	for(int f = 1;f < 63;f++)
	{
		for(int l = 1;l <= n;l++)
		{
			for(int r = 1;r <= n;r++)
			{
				for(int mid = 1;mid <= n;mid++)
				{
					dp[f][l][r] += (dp[f - 1][l][mid] * dp[f - 1][mid][r]) % mod;
					dp[f][l][r] %= mod;
				}
			}
		}
		if(!b)
		{
			if(k & (1LL << f)){
				b = 1;
				for(int l = 1;l <= n;l++)
				{
					for(int r = 1;r <= n;r++)
					{
						ans[f][l][r] = dp[f][l][r];
					}
				}
			}
			else continue;
		}
		for(int l = 1;l <= n;l++)
		{
			for(int r = 1;r <= n;r++)
			{
				if(k & (1LL << f)) {
					for(int mid = 1;mid <= n;mid++)
					{
						ans[f][l][r] += (ans[f - 1][l][mid] * dp[f][mid][r]) % mod;
						ans[f][l][r] %= mod;
					}
				}
				else ans[f][l][r] = ans[f - 1][l][r];
				if(f == 62)
				{
					answer += ans[f][l][r];
					answer %= mod;
				}
			}
		}
	}
	rc(answer);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long int

const int MOD = 1000000007;


int add(int x, int y)
{
	return (x + y) % MOD;
}

int sub(int x, int y)
{
	return add(x, MOD - y);
}

int mul(int x, int y)
{
	return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
	int z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}

int inv(int x)
{
	return binpow(x, MOD - 2);
}

int fact[500005];
int ifact[500005];

int C(int n, int k)
{
	return mul(fact[n], (mul(ifact[k], ifact[n - k])));
}

int P(int n, int k)
{
	return mul(fact[n],  ifact[n - k]);
}

main() {
	fact[0]=1;
	for(int i=1; i<=500000; i++){
		fact[i]=(i*fact[i-1])%MOD;
	}
	for(int i=0; i<=500000; i++){
		ifact[i]=inv(fact[i]);
	}
	int n, m;
	cin>>n>>m;
	int ans=0;
	for(int i=0; i<=n; i++){
		if(i%2==0){
			ans=add(ans, mul(mul(C(n, i), P(m, i)), mul(P(m-i, n-i), P(m-i, n-i))));
		}
		else{
			ans=sub(ans, mul(mul(C(n, i), P(m, i)), mul(P(m-i, n-i), P(m-i, n-i))));
		}
	}
	cout<<ans;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto cmp = [&](int left, int right) {
        return b[left] < b[right];
    };
    priority_queue<int, vector<int>, decltype(cmp)> queue(cmp);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (b[i] != a[i]) {
            queue.emplace(i);
        }
    }
    long long result = 0;
    while (!queue.empty()) {
        auto top = queue.top();
        queue.pop();
        int sum = b[(top - 1 + n) % n] + b[(top + 1) % n];
        if ((b[top] - a[top]) % sum == 0) {
            result += (b[top] - a[top]) / sum;
            b[top] = a[top];
        } else if (b[top] > sum) {
            result += b[top] / sum;
            b[top] %= sum;
            if (b[top] < a[top]) {
                result = -1;
                break;
            }
            queue.emplace(top);
        } else {
            result = -1;
            break;
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 2680
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


def calc(a, b):
    return a ** 5 - b ** 5

def solve(x):
    for a in range(-120, 120):
        for b in range(-120, 120):
            if x == calc(a, b):
                print(a, b)
                return


if __name__ == '__main__':
    x = int(input())
    solve(x)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68652
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val dp = Array(n + 1) { LongArray(3) }

    for (i in 0 until n) {
        val xs = readLine()!!.split(' ').map { it.toLong() }
        for (j in 0 until 3) {
            dp[i + 1][j] = Math.max(dp[i][(j + 1) % 3] + xs[j], dp[i][(j + 2) % 3] + xs[j])
        }
    }

    println(dp[n].max())
}


Measured memory_bytes: 70264
ls=["AC","TLE","RE","WA"]
n=int(input())
a=b=c=d=0
for i in range(n):
  s=input()
  if s==ls[0]:
    a+=1
  elif s==ls[1]:
    b+=1
  elif s==ls[2]:
    c+=1
  else:
    d+=1
print(ls[0]+" x",a)
print(ls[3]+" x",d)
print(ls[1]+" x",b)
print(ls[2]+" x",c)

Measured memory_bytes: 9160
#include<stdio.h>

int main(){
	long long N,A,B;
	long long a[100000];
	long long l;
	long long res=0;
	scanf("%lld%lld%lld",&N,&A,&B);
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<N;i++){
		l=(a[i]-a[i-1])*A;
		if(l<=B){
			res+=l;
		}
		else{
			res+=B;
		}
	}
	printf("%lld",res);
}

Measured memory_bytes: 896
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
		string[] input = Console.ReadLine().Split(' ');
		int N = int.Parse(input[0]);
		int K = int.Parse(input[1]);

		int ans = N - K;
		if (K == 1) { ans = 0; }
		Console.WriteLine(ans);
    }
}



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

int main() {
  char s[5];
  scanf("%s", s);
  int a[4];
  rep(i, 4) a[i] = s[i] - '0';
  rep(bit, 1<<3) {
    int sm = a[0];
    rep(i, 3) {
      if (bit & 1<<i) sm += a[i + 1];
      else sm -= a[i + 1];
    }
    if (sm == 7) {
      char op[3];
      rep(i, 3) {
        if (bit & 1<<i) op[i] = '+';
        else op[i] = '-';
      }
      printf("%d%c%d%c%d%c%d=7\n", a[0], op[0], a[1], op[1], a[2], op[2], a[3]);
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};




int main(){
	int n, c;
	PP chanel[100000];
	cin >> n >> c;
	for(int i = 0; i < n; i++){
		cin >> chanel[i].first.first >> chanel[i].first.second >> chanel[i].second;
	}
	sort(chanel, chanel+n);

	vector<P> use;
	for(int i = 0; i < n; i++){
		P time = chanel[i].first;
		bool check = false;
		int index;
		for(int j = 0; j < use.size(); j++){
			int tm = inf;
			if(use[j].second == chanel[i].second){
				if(use[j].first <= time.first && tm >= use[j].first){
					index = j;
					tm = use[j].first;
					check++;
				}
			}else{
				if(use[j].first < time.first && tm > use[j].first){
					index = j;
					tm = use[j].first;
					check++;
				}
			}
		}

		if(check){
			use[index] = P(time.second, chanel[i].second);
		}else{
			use.pb(P(time.second, chanel[i].second));
		}
	}

	cout << use.size() << endl;

	return 0;
}

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

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

    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        if(s == "AC") ac += 1;
        if(s == "WA") wa += 1;
        if(s == "TLE") tle += 1;
        if(s == "RE") re += 1;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <vector>
using namespace std;

int main(){
	
//	freopen("input.txt","r",stdin);
	
	string instr;
	cin>>instr;
	
	cout<<instr[0]<<instr.size()-2<<instr[instr.size()-1]<<endl;
	
		
	return 0;
}

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

int pqueue_max=0;
int pqueue[128];

void pqueue_adjust(int pos) {
	while(1) {
		int max=pos;
		int pos2;
		pos2=pos*2+1;
		if(pos2<pqueue_max && pqueue[pos2]>pqueue[max])max=pos2;
		pos2=pos*2+2;
		if(pos2<pqueue_max && pqueue[pos2]>pqueue[max])max=pos2;
		if(max!=pos) {
			int temp;
			temp=pqueue[pos];
			pqueue[pos]=pqueue[max];
			pqueue[max]=temp;
			pos=max;
		} else {
			if(pos==0)break;
			pos=(pos-1)/2;
		}
	}
}

void pqueue_add(int num) {
	int pos=pqueue_max++;
	pqueue[pos]=num;
	pqueue_adjust(pos);
}

int pqueue_top(void) {
	if(pqueue_max<=0)return 0;
	return pqueue[0];
}

void pqueue_pop(void) {
	if(pqueue_max<=0)return;
	pqueue[0]=pqueue[--pqueue_max];
	pqueue_adjust(0);
}

typedef struct {
	int a,b;
} kyozyu_t;

int qsort_comp(const void* x,const void* y) {
	const kyozyu_t* a=(const kyozyu_t*)x;
	const kyozyu_t* b=(const kyozyu_t*)y;
	/* syozyun of a */
	if((a->a)>(b->a))return 1;
	if((a->a)<(b->a))return -1;
	/* kozyun of b */
	if((a->b)<(b->b))return 1;
	if((a->b)>(b->b))return -1;
	return 0;
}

int main(void) {
	int N,M;
	kyozyu_t kyozyu[100];
	int i;
	int now=0;
	int count=0;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++)scanf("%d%d",&kyozyu[i].a,&kyozyu[i].b);
	qsort(kyozyu,M,sizeof(kyozyu_t),qsort_comp);
	for(i=0;i<M;i++) {
		if(kyozyu[i].a<=now+1) {
			pqueue_add(kyozyu[i].b);
		} else {
			int next=pqueue_top();
			if(next<=now) {
				count=-1;
				break;
			}
			count++;
			now=next;
			pqueue_pop();
			i--;
			if(now>=N)break;
		}
	}
	if(now<N) {
		if(pqueue_top()<N)count=-1;
		else count++;
	}
	if(count<0)puts("Impossible"); else printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 600
from scipy.sparse.csgraph import floyd_warshall as fw
INF = float('inf')
N,M,L = map(int,input().split())
cost = [[INF]*N for _ in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

cost = fw(cost)

for i in range(N):
    for j in range(N):
        if cost[i][j] > L:
            cost[i][j] = INF
        else:
            cost[i][j] = 1

cost = fw(cost)

for i in range(N):
    for j in range(N):
        if cost[i][j] == INF:
            cost[i][j] = -1
        else:
            cost[i][j] -= 1

Q = int(input())

for i in range(Q):
    s,t = map(int,input().split())
    print(int(cost[s-1][t-1]))

Measured memory_bytes: 17964
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	int D[110] = {}, A[110] = {};
	for(int i = 0; i < N; i++){
		cin >> D[i];
	}
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	int sz = min(7, N);
	int a[8] = {1, 2, 3, 4, 5, 6, 7, 0};
	unordered_map<int, int> m;
	do{
		int S = 0;
		int pos = 0;
		for(int i = 0; i < sz; i++){
			for(int j = i + 1; j < sz; j++){
				if(a[i] > a[j] && j - i <= D[j]){
					S += A[j];
				}else if(a[j] > a[i] && j - i <= D[i]){
					S += A[i];
				}
			}
			pos *= 10;
			pos += a[i];
		}
		m[pos] = S;
	}while(next_permutation(a, a + sz));
	for(int i = 7; i < N; i++){
		unordered_map<int, int> m2;
		for(pair<int, int> p : m){
			//cout << p.first << " " << p.second << endl;
			for(int j = 6; j >= 0; j--){
				a[j] = p.first % 10;
				p.first /= 10;
			}
			for(int j = 0; j < 8; j++){
				int S = p.second;
				for(int k = 0; k < 7; k++){
					if(a[k] > j && 7 - k <= D[i]){
						S += A[i];
					}else if(a[k] <= j && 7 - k <= D[i - (7 - k)]){
						S += A[i - (7 - k)];
					}
				}
				int pos = 0;
				for(int k = 1; k < 7; k++){
					pos += a[k];
					if(a[0] < a[k]){
						pos -= 1;
					}
					if(j < a[k]){
						pos += 1;
					}
					pos *= 10;
				}
				pos += j;
				if(j < a[0]){
					pos += 1;
				}
				m2[pos] = max(m2[pos], S);
				//cout << "m2 " << pos << " " << S << endl;
			}
			//return 0;
		}
		m = m2;
	}
	int ans = 0;
	for(pair<int, int> p : m){
		ans = max(ans, p.second);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3516
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int a[10];
    for(int i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3,cmp);
    int ans=a[0]+a[1];
    cout <<ans << endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

time = [0]*(n-k+1)
time_rev = time
res = 10e9
for i in range(n-k+1) :
  time[i] = abs(x[i+k-1]-x[i]) + abs(x[i])
  if(res > time[i]) : res = time[i]
  time_rev[i] = abs(x[i+k-1]-x[i]) + abs(x[i+k-1])
  if(res > time_rev[i]) : res = time_rev[i]
print(res)

Measured memory_bytes: 14252
D, G=list(map(int, input().split()))
PC=[0]+[list(map(int, input().split())) for _ in range(D)]

def function(G, i):
	if i==0:
		return 1e9
	n=min(G//(i*100), PC[i][0])
	s=n*i*100
	if n==PC[i][0]:
		s+=PC[i][1]
	if s<G:
		n+=function(G-s, i-1)
	return min(n, function(G,i-1))
print(function(G, D))


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
int a[100000 + 5];
vector<int> v;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> a[i];
    bool check[n] = {};
    rep(i, n) {
        if (check[i]) continue;
        check[i] = true;
        int now = i;
        int len = 1;
        while (now < n - 1 && a[now] != a[now + 1]) {
            check[now + 1] = true;
            now++;
            len++;
        }
        v.push_back(len);
    }
    int ans = 0;
    if (v.size() <= 2) {
        cout << n << endl;
        return 0;
    }
    rep(i, v.size() - 2) ans = max(ans, v[i] + v[i + 1] + v[i + 2]);
    cout << ans << endl;
}

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

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

  int N; cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.rbegin(), A.rend());
  int a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) a += A[i];
    else b += A[i];
  }
  cout << (a - b) << '\n';
  return 0;
}

Measured memory_bytes: 384