The first line contains two integers $$$n$$$ and $$$m$$$, separated by spaces ($$$1 \leq n,m \leq 10^9$$$) — the number of kinds of presents and the number of boxes that Alice has.

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const ll p = 1e9 + 7;
ll n,m,ans;
ll qp(ll a,ll b){
	ll ans = 1,base = a;
	while(b != 0){
		if(b & 1)ans = ans * base % p;
		base = base * base % p;
		b >>= 1;
	}
	return ans;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	ans = qp((qp(2,m)%p - 1 + p)%p,n)%p;
	cout<<ans<<endl;
	return 0;
}
/*
long long
线段树四倍
写代码时请注意:
	1.是否要开Long Long?数组边界处理好了么?
	2.实数精度有没有处理?
	3.特殊情况处理好了么?
	4.做一些总比不做好.
思考提醒:
	1.最大值和最小值问题可不可以用二分答案?
	2.有没有贪心策略?否则能不能dp?
*/

Print one integer  — the number of ways to pack the presents with Alice's rules, calculated by modulo $$$10^9+7$$$

Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.There are $$$n$$$ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.Also, there are $$$m$$$ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of $$$m$$$ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.Alice wants to pack presents with the following rules:  She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of $$$n$$$ kinds, empty boxes are allowed);  For each kind at least one present should be packed into some box. Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo $$$10^9+7$$$.See examples and their notes for clarification.

Input: 1 3

Output: 7

Input: 2 2

Output: 9

Input: 1000000000 1000000000

Output: 751201557

Input: 489132389 96

Output: 496937

Input: 462817723 208

Output: 886407548

Input: 10 415749054

Output: 763222305

Input: 185182737 683516583

Output: 568113155

Input: 1 1

Output: 1

Input: 67 445057511

Output: 687331027

Input: 53 710974288

Output: 739543572

Input: 766313215 146

Output: 577417399

Input: 483378560 249

Output: 400296687

Input: 294440070 297

Output: 391755258

Input: 22 346212760

Output: 70690719

Input: 214 70

Output: 57768876

Input: 498 36

Output: 238608733

Input: 243 155

Output: 872572138

Input: 911 144

Output: 588180251

Input: 1208 1429

Output: 809533438

Input: 362 1464

Output: 76973162

Input: 1956 1933

Output: 376783113

Input: 958 1712

Output: 555561716

Input: 1737 2760

Output: 702877932

Input: 297 2221

Output: 118273419

Input: 851963022 4

Output: 843890746

Input: 242811857 22

Output: 658352132

Input: 943226362 45

Output: 326355794

Input: 744891088 118

Output: 857670894

Input: 607778684 18

Output: 241523454

Input: 69 553612861

Output: 343253715

Input: 39 884188112

Output: 485799965

Input: 208 898957748

Output: 590505163

Input: 204 697134196

Output: 878017912

Input: 311 619805019

Output: 357441166

Input: 75 511331377

Output: 891361754

Input: 798664260 289720442

Output: 405748370

Input: 118448079 385479325

Output: 929397040

Input: 122681800 592225969

Output: 849919410

Input: 411520242 339446102

Output: 69858832

Input: 248755287 144691387

Output: 666866415

Input: 617282691 956569994

Output: 407582988

Input: 565315457 718194150

Output: 180672585

Input: 330332097 730084442

Output: 536919158

Input: 534571158 222043261

Output: 212941625

Input: 807153816 542148359

Output: 452817189

Input: 35785771 557468706

Output: 763956563

Input: 199108316 823003436

Output: 650559775

Input: 592582684 738223068

Output: 830809744

Input: 840387185 768322358

Output: 364216881

Input: 294176817 643050540

Output: 425282882

Input: 651139198 572383165

Output: 362206900

Input: 314697041 784667526

Output: 579388817

Input: 188186551 379116090

Output: 655244255

Input: 922338645 900544285

Output: 187784871

Input: 117909304 588342759

Output: 852741659

Input: 426452433 106792

Output: 740748981

Input: 686898624 980111485

Output: 805355123

Input: 169231047 790996597

Output: 442732671

Input: 393454015 42675288

Output: 221958294

Input: 955475387 410847984

Output: 544061679

Input: 290496089 820810891

Output: 707906935

Input: 635994662 423804127

Output: 831152709

Input: 33727662 414901164

Output: 529262173

Input: 886792224 998690495

Output: 183247773

Input: 31 112

Output: 626643854

Input: 71 106

Output: 603494283

Input: 100 474

Output: 180274936

Input: 14 469

Output: 14294519

Input: 18 290

Output: 544261782

Input: 172 39

Output: 222650110

Input: 139 415

Output: 639620853

Input: 117 2553

Output: 906570878

Input: 156 342

Output: 306076272

Input: 260 2998

Output: 573924479

Input: 184 7

Output: 715075794

Input: 428 71

Output: 677189841

Input: 1046 34

Output: 92349932

Input: 560 27

Output: 179196390

Input: 732 137

Output: 596791767

Input: 1730 39

Output: 352860620

Input: 1335 185

Output: 596600489

Input: 175 59

Output: 315527995

Input: 900 32

Output: 832035237

Input: 2998 38

Output: 63403329

Input: 1 1000000000

Output: 140625000

Input: 1000000000 1

Output: 1

Input: 5 2

Output: 243

Input: 2 5

Output: 961

Input: 7 6

Output: 980611601

Input: 5 8

Output: 203901829


The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

#include<iostream>
using namespace std;
int i,x,y,n,f,ff;
int main(){
    f=0;
    cin>>n;
    cin>>y;
    for(i=2;i<=n;i++){
        cin>>x;
        if(x>y)ff=0;
        if(x==y)ff=1;
        if(x<y)ff=2;
        if(ff<f){
            cout<<"NO";
            return 0;
        }
        f=ff;
        y=x;
    }
    cout<<"YES";
}

NoteIn the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).

Array of integers is unimodal, if:  it is strictly increasing in the beginning;  after that it is constant;  after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].Write a program that checks if an array is unimodal.

Input:
6
1 5 5 5 4 2

Output: YES

Input:
5
10 20 30 20 10

Output: YES

Input:
4
1 2 1 2

Output: NO

Input:
7
3 3 3 3 3 3 3

Output: YES

Input:
6
5 7 11 11 2 1

Output: YES

Input:
1
7

Output: YES

Input:
100
527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527

Output: YES

Input:
5
5 5 6 6 1

Output: NO

Input:
3
4 4 2

Output: YES

Input:
4
4 5 5 6

Output: NO

Input:
3
516 516 515

Output: YES

Input:
5
502 503 508 508 507

Output: YES

Input:
10
538 538 538 538 538 538 538 538 538 538

Output: YES

Input:
15
452 454 455 455 450 448 443 442 439 436 433 432 431 428 426

Output: YES

Input:
20
497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513

Output: YES

Input:
50
462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337

Output: YES

Input:
70
290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479

Output: YES

Input:
99
433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393

Output: YES

Input:
100
537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543

Output: YES

Input:
100
524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521

Output: YES

Input:
100
235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504

Output: YES

Input:
100
191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496

Output: YES

Input:
100
466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173

Output: YES

Input:
100
360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333

Output: YES

Input:
1
1000

Output: YES

Input:
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: YES

Input:
100
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Output: YES

Input:
100
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1

Output: YES

Input:
100
1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Output: YES

Input:
100
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Output: NO

Input:
100
998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999

Output: NO

Input:
100
537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543

Output: NO

Input:
100
527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527

Output: NO

Input:
100
524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521

Output: NO

Input:
100
235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504

Output: NO

Input:
100
191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496

Output: NO

Input:
100
466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173

Output: NO

Input:
100
360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333

Output: NO

Input:
3
1 2 3

Output: YES

Input:
3
3 2 1

Output: YES

Input:
3
1 1 2

Output: NO

Input:
3
2 1 1

Output: NO

Input:
3
2 1 2

Output: NO

Input:
3
3 1 2

Output: NO

Input:
3
1 3 2

Output: YES

Input:
100
395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346

Output: YES

Input:
100
263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475

Output: YES

Input:
100
482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271

Output: YES

Input:
100
395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346

Output: NO

Input:
100
263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475

Output: NO

Input:
100
482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271

Output: YES

Input:
2
1 3

Output: YES

Input:
2
1 2

Output: YES

Input:
5
2 2 1 1 1

Output: NO

Input:
4
1 3 2 2

Output: NO

Input:
6
1 2 1 2 2 1

Output: NO

Input:
2
4 2

Output: YES

Input:
3
3 2 2

Output: NO

Input:
9
1 2 2 3 3 4 3 2 1

Output: NO

Input:
4
5 5 4 4

Output: NO

Input:
2
2 1

Output: YES

Input:
5
5 4 3 2 1

Output: YES

Input:
7
4 3 3 3 3 3 3

Output: NO

Input:
5
1 2 3 4 5

Output: YES

Input:
3
2 2 1

Output: YES

Input:
3
4 3 3

Output: NO

Input:
7
1 5 5 4 3 3 1

Output: NO

Input:
6
3 3 1 2 2 1

Output: NO

Input:
5
1 2 1 2 1

Output: NO

Input:
2
5 1

Output: YES

Input:
9
1 2 3 4 4 3 2 2 1

Output: NO

Input:
3
2 2 3

Output: NO

Input:
2
5 4

Output: YES

Input:
5
1 3 3 2 2

Output: NO

Input:
10
1 2 3 4 5 6 7 8 9 99

Output: YES

Input:
4
1 2 3 4

Output: YES

Input:
3
5 5 2

Output: YES

Input:
4
1 4 2 3

Output: NO

Input:
2
3 2

Output: YES

Input:
5
1 2 2 1 1

Output: NO

Input:
4
3 3 2 2

Output: NO

Input:
5
1 2 3 2 2

Output: NO

Input:
5
5 6 6 5 5

Output: NO

Input:
4
2 2 1 1

Output: NO

Input:
5
5 4 3 3 2

Output: NO

Input:
7
1 3 3 3 2 1 1

Output: NO

Input:
9
5 6 6 5 5 4 4 3 3

Output: NO

Input:
6
1 5 5 3 2 2

Output: NO

Input:
5
2 1 3 3 1

Output: NO

Input:
2
4 3

Output: YES

Input:
5
3 2 2 1 1

Output: NO

Input:
4
5 4 3 2

Output: YES

Input:
4
4 4 1 1

Output: NO

Input:
4
3 3 1 1

Output: NO

Input:
4
4 4 2 2

Output: NO

Input:
5
4 4 3 2 2

Output: NO

Input:
8
4 4 4 4 5 6 7 8

Output: NO

Input:
5
3 5 4 4 3

Output: NO

Input:
6
2 5 3 3 2 2

Output: NO

Input:
4
5 5 2 2

Output: NO

Input:
5
1 2 2 3 5

Output: NO


The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.

NoteIn the first sample number 9 meets the requirements.In the second sample number 10 meets the requirements.In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total.

On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).

Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:  the number's length does not exceed n;  the number doesn't have leading zeroes;  digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.

Input:
1
0 0 0 0 0 0 0 0 0 1

Output: 1

Input:
2
1 1 0 0 0 0 0 0 0 0

Output: 1

Input:
3
1 1 0 0 0 0 0 0 0 0

Output: 36

Input:
4
0 1 0 1 2 0 0 0 0 0

Output: 12

Input:
5
2 1 2 0 0 0 0 0 0 0

Output: 18

Input:
6
1 1 0 1 2 1 0 0 0 0

Output: 300

Input:
7
0 0 2 2 1 0 1 0 0 0

Output: 9660

Input:
8
1 0 1 0 1 1 2 2 0 0

Output: 8820

Input:
9
1 1 1 2 1 0 0 2 0 1

Output: 80640

Input:
10
2 0 0 1 0 2 0 1 1 0

Output: 46501116

Input:
100
10 11 14 16 12 17 10 10 0 0

Output: 5806772

Input:
100
0 0 0 0 0 0 0 0 0 0

Output: 226732709

Input:
100
12 7 8 5 17 1 19 5 7 9

Output: 72317872

Input:
100
15 16 10 9 11 7 18 14 0 0

Output: 657295203

Input:
100
1 12 0 7 16 19 15 2 17 11

Output: 94324764

Input:
100
19 9 15 16 9 10 15 7 0 0

Output: 965593411

Input:
100
12 11 2 10 18 15 10 2 8 9

Output: 2861328

Input:
100
5 3 15 14 9 4 11 2 0 6

Output: 20742041

Input:
100
12 2 12 4 12 7 18 18 13 2

Output: 213099632

Input:
100
7 12 8 18 13 1 1 19 13 8

Output: 570613710

Input:
100
13 3 4 7 2 15 6 12 7 6

Output: 765010290

Input:
100
0 45 0 0 0 0 0 55 0 0

Output: 742404204

Input:
100
9 0 3 23 0 0 0 0 0 65

Output: 417270431

Input:
100
0 0 19 0 0 0 27 0 0 54

Output: 697702662

Input:
100
0 0 68 0 18 14 0 0 0 0

Output: 31893604

Input:
100
0 34 12 0 16 0 0 0 38 0

Output: 425145859

Input:
100
0 45 29 0 0 4 0 0 0 22

Output: 53914825

Input:
100
32 0 0 0 0 0 0 67 1 0

Output: 916165184

Input:
100
58 0 0 0 0 0 40 2 0 0

Output: 61389954

Input:
100
0 27 0 0 0 0 0 0 73 0

Output: 739250810

Input:
100
0 0 40 0 0 0 0 0 60 0

Output: 213157642

Input:
100
0 24 0 0 0 29 25 22 0 0

Output: 830465544

Input:
100
4 0 1 15 20 0 0 34 0 26

Output: 873619937

Input:
100
30 0 8 19 0 1 11 0 0 31

Output: 428927538

Input:
100
31 0 27 15 7 9 5 0 0 6

Output: 338317227

Input:
100
1 14 5 6 7 27 13 0 27 0

Output: 636666417

Input:
100
5 18 12 0 0 2 15 0 8 40

Output: 280146328

Input:
100
13 34 0 0 0 0 19 27 1 6

Output: 989464034

Input:
100
24 0 0 0 0 36 16 24 0 0

Output: 386276754

Input:
100
0 27 0 0 0 0 22 21 30 0

Output: 362638820

Input:
100
0 2 23 27 0 23 0 0 24 1

Output: 974134889

Input:
100
6 6 7 5 9 8 9 6 7 9

Output: 896625890

Input:
100
17 18 19 13 26 22 26 17 19 26

Output: 0

Input:
100
3 24 1 12 29 27 27 25 5 20

Output: 0

Input:
100
23 18 6 14 10 7 8 5 1 24

Output: 0

Input:
100
23 10 21 11 6 7 10 19 11 4

Output: 0

Input:
100
5 18 12 5 28 2 15 20 12 40

Output: 0

Input:
100
13 34 34 12 11 29 26 27 1 6

Output: 0

Input:
100
24 9 23 26 28 36 16 24 39 36

Output: 0

Input:
100
16 27 26 10 17 39 22 21 30 25

Output: 0

Input:
100
18 2 23 27 9 23 27 13 24 39

Output: 0

Input:
100
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
55
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
82
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
80
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
74
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
70
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
96
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
14
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
46
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
57
100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
100
100 0 0 0 0 0 0 0 0 0

Output: 0

Input:
100
0 100 0 0 0 0 0 0 0 0

Output: 1

Input:
100
0 0 100 0 0 0 0 0 0 0

Output: 1

Input:
100
0 0 0 0 0 100 0 0 0 0

Output: 1

Input:
100
0 0 0 0 0 0 100 0 0 0

Output: 1

Input:
100
0 0 0 0 0 0 0 100 0 0

Output: 1

Input:
100
0 0 0 0 0 0 0 0 100 0

Output: 1

Input:
100
0 0 0 0 0 0 0 0 0 100

Output: 1

Input:
100
50 0 0 0 0 50 0 0 0 0

Output: 769496025

Input:
100
2 2 2 3 2 3 2 3 1 2

Output: 962893731

Input:
100
2 2 2 3 2 3 2 3 1 2

Output: 962893731

Input:
100
2 1 1 1 3 0 3 1 1 1

Output: 824639681

Input:
100
3 3 2 1 2 1 3 3 0 1

Output: 824583946

Input:
100
0 2 0 1 3 3 3 0 3 3

Output: 714175595

Input:
100
3 1 3 3 1 2 3 2 0 2

Output: 230289012

Input:
100
2 2 0 2 3 3 2 0 1 1

Output: 40065169

Input:
100
1 0 3 2 1 0 2 0 0 1

Output: 366089372

Input:
100
2 0 2 0 2 1 3 3 2 1

Output: 40065169

Input:
100
1 2 1 3 2 0 0 3 2 2

Output: 886460596

Input:
100
2 0 0 1 0 3 1 2 1 1

Output: 93799192

Input:
6
1 1 1 1 1 1 0 0 0 0

Output: 600

Input:
4
0 0 1 0 1 0 0 0 1 1

Output: 24

Input:
6
0 1 0 1 1 0 0 0 1 0

Output: 23160

Input:
4
1 1 1 0 1 0 0 0 0 0

Output: 18

Input:
5
1 1 1 0 1 1 0 0 0 0

Output: 96

Input:
6
2 2 2 0 0 0 0 0 0 0

Output: 60

Input:
4
1 1 2 0 0 0 0 0 0 0

Output: 9

Input:
77
2 2 3 2 3 2 3 1 2 2

Output: 296754123

Input:
69
1 1 3 0 3 1 1 1 3 3

Output: 441116461

Input:
76
1 2 1 3 3 0 1 0 2 0

Output: 434673284


The first line contains the positive integer x (1 ≤ x ≤ 1018) — the integer which Anton has.

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>

using namespace std;

char s[32768];
char ans[32768];

int main() {
	ios_base::sync_with_stdio(0);
	cin.getline(s, sizeof(s));
	int n = (int)strlen(s);
	int def = 0;
	for (int i = 0; i < n; i++) def += (int)(s[i] - '0');
	int ret = def;
	strcpy(ans, s);
	//
	for (int i = n - 1; i >= 0; i--) {
		int cnt = 0;
		if (s[i] != '0') {
			cnt = def - 1;
			for (int j = i + 1; j < n; j++) {
				cnt += (int)('9' - s[j]);
			}
		}
		if (cnt > ret) {
			ret = cnt;
			ans[i] = s[i] - 1;
			for (int j = i + 1; j < n; j++) {
				ans[j] = '9';
			}
		}
	}
	int from = 0;
	while (ans[from] == '0') from++;
	cout << (ans + from) << "\n";
	//
	return 0;
}

Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.

Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.


The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;

int ans,l,r;

int main()
{
	cin>>l>>r;
	while(l!=r)
	{
		if(l>r)
		{
			r++;
		}
		else
		{
			if(r&1)//奇数
			{
				r++;
			}
			else
			{
				r/=2;
			}
		}
		ans++;
	}
	cout<<ans<<endl;
}

NoteIn the first example you need to push the blue button once, and then push the red button once.In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?

Input: 4 6

Output: 2

Input: 10 1

Output: 9

Input: 1 2

Output: 1

Input: 2 1

Output: 1

Input: 1 3

Output: 3

Input: 3 1

Output: 2

Input: 2 10

Output: 5

Input: 100 99

Output: 1

Input: 99 100

Output: 50

Input: 10 17

Output: 3

Input: 666 6666

Output: 255

Input: 6666 666

Output: 6000

Input: 1 8192

Output: 13

Input: 1 8193

Output: 27

Input: 9999 10000

Output: 5000

Input: 10000 9999

Output: 1

Input: 10000 1

Output: 9999

Input: 1234 5678

Output: 528

Input: 9102 9103

Output: 4552

Input: 8192 1

Output: 8191

Input: 9912 1023

Output: 8889

Input: 100 500

Output: 41

Input: 9997 9999

Output: 4999

Input: 5000 10000

Output: 1

Input: 4000 7997

Output: 3

Input: 1 10000

Output: 20

Input: 1 8191

Output: 14

Input: 9097 9998

Output: 4099

Input: 886 9383

Output: 305

Input: 1 9

Output: 7

Input: 1918 10000

Output: 671

Input: 1 4

Output: 2

Input: 2 10000

Output: 19

Input: 3 10000

Output: 17

Input: 4 10000

Output: 18

Input: 9998 10000

Output: 4999

Input: 5001 10000

Output: 2

Input: 1 9999

Output: 21

Input: 7777 9999

Output: 2779

Input: 2 100

Output: 9

Input: 10 8722

Output: 18

Input: 848 4561

Output: 283

Input: 9967 9973

Output: 4982

Input: 5555 10000

Output: 556

Input: 999 10000

Output: 378

Input: 3 6

Output: 1

Input: 9 38

Output: 8


The only line contains two integers $$$n$$$, $$$m$$$ ($$$1\le n, m\le 2021$$$).

#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s);i<=(t);++i)
#define form(i,s,t) for(register int i=(s);i>=(t);--i)
using namespace std;
const int N = 2040, Mod = 998244353;
struct Mint {
	int res;
	Mint() {res = 0;}
	Mint(int a) : res(a) {}
	friend Mint operator + (Mint A, Mint B) {
		return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) : (A.res + B.res));
	}
	friend Mint& operator += (Mint& A, Mint B) {return A = A + B;}
	friend Mint operator - (Mint A, Mint B) {B.res = Mod - B.res; return A + B;}
	friend Mint operator - (Mint A) {return Mint(Mod - A.res);}
	friend Mint operator + (Mint A) {return A;}
	friend Mint& operator -= (Mint& A, Mint B) {return A = A - B;}
	friend Mint operator * (Mint A, Mint B) {return 1ll * A.res * B.res %Mod;}
	friend Mint& operator *= (Mint& A, Mint B) {return A = A * B;}
	friend Mint operator ~ (Mint A) {
		static Mint res; res = Mint(1);
		static int k; k = Mod - 2;
		for(;k;k>>=1, A*=A) (k&1) && (res = res * A, 0);
		return res;
	}
	friend Mint operator / (Mint A, Mint B) {return A * (~B);}
	friend Mint& operator /= (Mint& A, Mint B) {return A *= (~B);}
	friend Mint operator >> (Mint A, Mint B) {return Mint(A.res / B.res);}
	friend Mint& operator >>= (Mint& A, Mint B) {return A = A>>B;}
};
int n, m; Mint C[N << 1][N << 1];
inline Mint F(int n, int m) {return C[n + m][n];}
int main() {
	scanf("%d%d", &n, &m);
	forn(i,0,n + m) {
		C[i][0] = C[i][i] = Mint(1);
		forn(j,1,i - 1) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	}
	static Mint res, sum;
	forn(h,1,n - 1) {
		sum = Mint(0);
		forn(i,1,m - 1) {
			res += sum * F(i, h - 1) * F(m - i - 1, h);
			sum += F(n - h, i - 1) * F(n - h - 1, m - i);
		}
	}
	forn(h,1,m - 1) {
		sum = Mint(0);
		forn(i,1,n - 1) {
			sum += F(m - h, i - 1) * F(m - h - 1, n - i);
			res += sum * F(i, h - 1) * F(n - i - 1, h);
		}
	}
	res = res * Mint(2);
	printf("%d\n", res.res);
	return 0;
}// OJ:: LG

NoteIn the first test case, these are the only two stupid $$$2\times 2$$$ colorings.

Output a single integer — the number of stupid colorings modulo $$$998244353$$$.

There is a grid with $$$n$$$ rows and $$$m$$$ columns. Every cell of the grid should be colored either blue or yellow.A coloring of the grid is called stupid if every row has exactly one segment of blue cells and every column has exactly one segment of yellow cells.In other words, every row must have at least one blue cell, and all blue cells in a row must be consecutive. Similarly, every column must have at least one yellow cell, and all yellow cells in a column must be consecutive.  An example of a stupid coloring.   Examples of clever colorings. The first coloring is missing a blue cell in the second row, and the second coloring has two yellow segments in the second column. How many stupid colorings of the grid are there? Two colorings are considered different if there is some cell that is colored differently.

Input: 2 2

Output: 2

Output: 2

Output: 2

Output: 2

Input: 4 3

Output: 294

Output: 294

Output: 294

Output: 294

Input: 2020 2021

Output: 50657649

Output: 50657649

Output: 50657649

Input: 2021 2021

Output: 138387540

Output: 138387540

Output: 138387540

Input: 2021 1

Output: 0

Output: 0

Output: 0

Input: 1 2021

Output: 0

Output: 0

Output: 0

Input: 1 1

Output: 0

Output: 0

Output: 0

Input: 1 2

Output: 0

Output: 0

Output: 0

Input: 1 3

Output: 0

Output: 0

Output: 0

Input: 3 1

Output: 0

Output: 0

Output: 0

Input: 17 13

Output: 737338284

Output: 737338284

Output: 737338284

Input: 1848 1937

Output: 337952422

Output: 337952422

Output: 337952422

Input: 2019 2018

Output: 15395158

Output: 15395158

Output: 15395158

Input: 10 19

Output: 272254938

Output: 272254938

Output: 272254938

Input: 2021 2

Output: 44330628

Output: 44330628

Output: 44330628

Input: 2021 3

Output: 435157523

Output: 435157523

Output: 435157523

Input: 4 2021

Output: 102125833

Output: 102125833

Output: 102125833

Input: 5 2021

Output: 2872985

Output: 2872985

Output: 2872985

Input: 2000 2000

Output: 111024599

Output: 111024599

Output: 111024599

Input: 101 100

Output: 137902766

Output: 137902766

Output: 137902766

Input: 104 328

Output: 726939953

Output: 726939953

Output: 726939953

Input: 101 101

Output: 601990061

Output: 601990061

Output: 601990061

Input: 598 319

Output: 420237100

Output: 420237100

Output: 420237100

Input: 1 4

Output: 0

Output: 0

Output: 0

Input: 1 5

Output: 0

Output: 0

Output: 0

Input: 2 1

Output: 0

Output: 0

Output: 0

Input: 2 3

Output: 10

Output: 10

Output: 10

Input: 2 4

Output: 30

Output: 30

Output: 30

Input: 2 5

Output: 70

Output: 70

Output: 70

Input: 1000 1000

Output: 72199042

Output: 72199042

Output: 72199042

Input: 999 2013

Output: 879862853

Output: 879862853

Output: 879862853

Input: 3 2

Output: 10

Output: 10

Output: 10

Input: 3 3

Output: 72

Output: 72

Output: 72

Input: 3 4

Output: 294

Output: 294

Output: 294

Input: 3 5

Output: 896

Output: 896

Output: 896

Input: 4 1

Output: 0

Output: 0

Output: 0

Input: 4 2

Output: 30

Output: 30

Output: 30

Input: 1453 938

Output: 379270595

Output: 379270595

Output: 379270595

Input: 4 4

Output: 1570

Output: 1570

Output: 1570

Input: 4 5

Output: 6066

Output: 6066

Output: 6066

Input: 5 1

Output: 0

Output: 0

Output: 0

Input: 5 2

Output: 70

Output: 70

Output: 70

Input: 5 3

Output: 896

Output: 896

Output: 896

Input: 5 4

Output: 6066

Output: 6066

Output: 6066

Input: 5 5

Output: 29000

Output: 29000

Output: 29000

Input: 6 6

Output: 498764

Output: 498764

Output: 498764

Input: 7 7

Output: 8281392

Output: 8281392

Output: 8281392

Input: 8 8

Output: 134909730

Output: 134909730

Output: 134909730

Input: 9 9

Output: 177198854

Output: 177198854

Output: 177198854

Input: 10 10

Output: 848269250

Output: 848269250

Output: 848269250


The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

#include <bits/stdc++.h>

using namespace std;
long n, k, m, kq=0;
int main()
{
    cin>>n>>k;
    m=240-k;
    for(int i=1;i<=n;i++)
    {
        if(m-(i*5)>=0) kq++;
        else break;
        m-= i*5;
    }
    cout<<kq;
}

NoteIn the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.

Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.How many problems can Limak solve if he wants to make it to the party?

Input: 3 222

Output: 2

Input: 4 190

Output: 4

Input: 7 1

Output: 7

Input: 10 135

Output: 6

Input: 10 136

Output: 5

Input: 1 1

Output: 1

Input: 1 240

Output: 0

Input: 10 1

Output: 9

Input: 10 240

Output: 0

Input: 9 240

Output: 0

Input: 9 1

Output: 9

Input: 9 235

Output: 1

Input: 9 236

Output: 0

Input: 5 225

Output: 2

Input: 5 226

Output: 1

Input: 4 210

Output: 3

Input: 4 211

Output: 2

Input: 4 191

Output: 3

Input: 10 165

Output: 5

Input: 10 166

Output: 4

Input: 8 100

Output: 7

Input: 8 101

Output: 6

Input: 8 60

Output: 8

Input: 8 61

Output: 7

Input: 10 15

Output: 9

Input: 10 16

Output: 8

Input: 4 100

Output: 4

Input: 4 101

Output: 4

Input: 7 167

Output: 4

Input: 10 164

Output: 5

Input: 9 170

Output: 4

Input: 8 160

Output: 5

Input: 1 100

Output: 1

Input: 8 123

Output: 6

Input: 2 99

Output: 2

Input: 10 88

Output: 7

Input: 1 235

Output: 1

Input: 4 240

Output: 0

Input: 1 55

Output: 1

Input: 3 240

Output: 0

Input: 2 240

Output: 0

Input: 2 236

Output: 0

Input: 10 2

Output: 9

Input: 3 239

Output: 0

Input: 1 237

Output: 0

Input: 7 8

Output: 7

Input: 10 235

Output: 1


Input contains one integer number A (3 ≤ A ≤ 1000).

#include<bits/stdc++.h>
using namespace std;
long long int i,j=0,n,c,sum=0,x,a,b,f=0;
int base(int k,int l)
{
    sum=0;
    while(k!=0)
    {
        sum+=k%l;
        k/=l;

    }
    return sum;
}
int gcd(int a,int b)
{
    return(b==0?a:gcd(b,a%b));
}
int main()
{   f=0;
    cin>>n;
    for(i=2;i<n;i++)
        f+=base(n,i);
        j=gcd(f,n-2);
       cout<<(f/j)<<"/"<<(n-2)/j<<endl;
}

NoteIn the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.

Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.

Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A - 1.Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.


The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \le m \le 10\,000)$$$ — the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \le a_i \le 100)$$$ — the initial number of people on the $$$i$$$-th bench.

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

int n,m,a;

int main()
{
    int kmin, kmax;

    scanf("%d",&n);
    scanf("%d",&m);

    int cnt = 0,mx=0;

    for (int i=0; i<n; i++){
        scanf("%d",&a);
        cnt += a;
        if(a > mx) mx = a;
    }

    kmin = ceil((float)(cnt+m)/n);
    if(kmin<=mx) kmin = mx;
    kmax = m + mx;

    cout << kmin << " " << kmax << endl;

    return 0;
}

NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.

Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.

There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.

Input:
4
6
1
1
1
1

Output: 3 7

Input:
1
10
5

Output: 15 15

Input:
3
6
1
6
5

Output: 6 12

Input:
3
7
1
6
5

Output: 7 13

Input:
10
1000
100
100
100
100
100
100
100
100
100
100

Output: 200 1100

Input:
10
1
3
3
2
3
3
3
3
3
3
3

Output: 3 4

Input:
51
10000
54
23
93
86
57
68
42
33
47
18
78
41
35
92
32
97
74
93
27
59
90
23
79
96
77
29
88
83
83
46
94
61
56
68
43
15
79
26
36
99
36
55
77
23
15
12
84
57
82
33
14

Output: 254 10099

Input:
100
8000
88
40
39
88
33
2
60
93
62
18
44
53
79
55
34
71
45
82
97
96
96
25
83
83
54
45
47
59
94
84
12
33
97
24
71
28
81
89
52
87
96
35
34
31
45
42
14
74
8
68
61
36
65
87
31
18
38
84
28
74
98
77
15
85
82
64
2
93
31
78
64
35
6
77
55
70
83
42
98
38
59
99
27
66
10
54
22
94
21
21
89
86
73
12
86
1
98
94
48
51

Output: 137 8099

Input:
10
10
1
1
1
1
1
1
1
1
1
1

Output: 2 11

Input:
10
10
1
1
1
2
1
1
1
1
1
1

Output: 3 12

Input:
100
1000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Output: 11 1001

Input:
1
10000
57

Output: 10057 10057

Input:
1
1000
48

Output: 1048 1048

Input:
2
1000
1
7

Output: 504 1007

Input:
5
10
68
87
14
68
23

Output: 87 97

Input:
10
20
80
41
15
77
91
82
15
83
36
3

Output: 91 111

Input:
20
3303
25
14
77
85
66
97
9
60
79
39
47
2
97
71
45
36
92
54
62
53

Output: 221 3400

Input:
40
10000
54
5
23
10
10
77
15
84
92
63
34
21
12
56
25
32
28
50
50
86
3
26
39
69
43
99
71
38
15
33
50
79
54
84
33
47
14
66
99
25

Output: 296 10099

Input:
66
1000
27
10
63
17
28
89
34
86
27
62
26
18
25
31
45
44
92
56
47
18
53
56
79
3
9
32
88
52
21
57
97
84
50
12
6
52
21
37
24
84
44
81
41
47
7
67
93
43
100
64
82
46
28
48
1
34
28
82
15
47
1
19
34
12
48
48

Output: 100 1100

Input:
78
9909
63
38
36
74
56
3
27
99
71
95
81
39
45
75
32
42
5
23
45
46
63
69
75
80
89
48
86
74
18
87
4
55
54
8
15
91
39
13
89
95
75
38
31
27
48
81
47
91
62
88
53
45
73
79
42
57
72
99
16
52
15
52
95
98
26
84
4
88
31
26
9
86
29
45
62
18
99
78

Output: 182 10008

Input:
89
9080
29
88
62
50
63
91
24
3
93
76
73
50
26
32
87
93
48
52
97
68
100
84
42
93
59
68
46
19
53
30
53
20
65
43
22
98
46
45
38
37
45
31
2
24
56
74
93
48
40
68
7
4
68
44
31
63
32
21
94
92
99
93
17
18
18
48
71
38
67
67
29
87
38
66
73
61
59
98
91
33
22
56
75
91
73
83
61
41
70

Output: 158 9180

Input:
90
10000
43
85
87
11
50
66
30
90
23
22
16
20
2
60
8
26
56
89
50
40
3
23
9
66
36
85
19
49
87
97
20
23
75
32
3
38
71
54
79
46
62
27
16
2
24
55
76
83
55
47
46
41
63
30
22
84
70
81
59
44
56
23
67
9
60
54
95
36
73
60
33
20
18
67
20
18
7
65
55
54
45
32
38
52
15
15
88
44
47
88

Output: 157 10097

Input:
99
1092
28
89
65
40
96
47
76
2
62
59
60
90
91
12
10
71
57
97
18
52
82
32
71
77
39
16
84
89
26
95
45
15
93
73
63
32
33
3
64
12
92
12
92
80
3
80
47
26
69
84
96
40
86
95
55
13
64
73
52
37
13
98
86
95
43
67
18
98
100
66
5
25
87
25
37
10
29
43
84
72
17
70
31
96
27
38
1
40
74
17
58
39
18
5
41
15
95
53
77

Output: 100 1192

Input:
100
66
95
19
88
15
29
52
37
75
21
90
93
75
91
71
53
55
90
78
19
63
43
25
52
10
55
76
47
42
57
45
35
53
2
62
61
99
59
59
43
45
31
37
50
68
51
91
34
48
40
69
77
33
16
64
19
82
76
35
41
41
79
29
69
100
30
81
47
55
79
21
59
3
11
43
49
100
27
87
64
8
6
7
88
71
98
6
32
53
91
85
60
35
55
5
44
66
76
99
7
58

Output: 100 166

Input:
100
50
20
63
60
88
7
22
90
15
27
82
37
44
42
50
33
46
7
97
93
5
68
79
76
3
82
5
51
79
17
1
1
93
52
88
23
23
49
86
64
18
36
53
49
47
11
19
6
79
64
59
56
96
15
72
81
45
24
55
31
2
74
64
57
65
71
44
8
7
38
50
67
1
79
89
16
35
10
72
69
8
56
42
44
95
25
26
16
84
36
73
17
61
91
15
19
78
44
77
96
58

Output: 97 147

Input:
100
100
82
51
81
14
37
17
78
92
64
15
8
86
89
8
87
77
66
10
15
12
100
25
92
47
21
78
20
63
13
49
41
36
41
79
16
87
87
69
3
76
80
60
100
49
70
59
72
8
38
71
45
97
71
14
76
54
81
4
59
46
39
29
92
3
49
22
53
99
59
52
74
31
92
43
42
23
44
9
82
47
7
40
12
9
3
55
37
85
46
22
84
52
98
41
21
77
63
17
62
91

Output: 100 200

Input:
100
1000
91
17
88
51
92
47
85
3
82
61
2
48
55
56
71
1
12
78
80
31
42
33
85
99
25
25
37
18
29
53
84
88
4
55
24
3
53
53
1
95
36
84
65
5
40
52
49
77
48
5
77
50
31
80
100
46
28
29
34
83
26
3
100
63
100
23
76
4
70
57
10
58
7
20
84
44
86
54
2
11
85
3
35
83
96
97
55
75
39
39
39
61
19
86
76
72
29
69
20
17

Output: 100 1100

Input:
100
2000
77
39
49
44
85
10
28
49
92
64
67
39
65
53
81
58
63
80
74
27
10
45
9
26
31
98
55
61
51
43
2
95
77
52
79
42
89
99
68
6
29
71
63
96
11
10
77
32
89
28
12
19
84
34
22
69
86
24
35
40
5
100
55
35
69
60
74
72
37
44
82
83
91
1
68
24
79
39
47
57
16
76
64
34
72
3
48
35
15
70
33
78
31
48
10
30
55
43
6
93

Output: 100 2100

Input:
100
5000
30
90
42
18
55
6
50
65
31
89
47
48
76
58
10
18
2
79
39
9
7
89
100
1
44
23
99
12
23
15
55
16
95
40
23
37
87
42
54
51
11
57
44
61
32
74
44
5
1
96
32
30
21
13
77
48
62
6
28
7
49
87
33
60
72
64
88
86
34
13
23
59
46
39
5
45
81
88
75
97
40
88
46
100
87
30
37
13
68
43
9
32
48
28
100
14
28
67
73
26

Output: 100 5100

Input:
100
9990
22
89
54
55
92
20
84
12
93
6
73
50
23
62
97
88
59
87
4
14
49
28
47
93
5
36
50
78
83
99
100
27
24
23
27
84
67
72
45
51
53
32
60
9
77
63
15
98
17
49
58
77
50
31
10
6
16
74
50
99
100
36
51
71
89
65
17
62
32
3
25
39
19
2
25
75
25
89
87
13
96
91
10
1
94
39
10
64
26
28
32
7
16
34
96
28
24
35
82
99

Output: 150 10090

Input:
100
10000
25
90
88
97
71
24
53
4
32
69
53
93
80
14
30
65
9
56
3
23
70
25
31
6
13
19
49
58
95
40
26
72
75
44
86
13
94
11
83
75
26
64
100
84
82
35
80
41
40
8
5
28
3
98
1
22
73
33
44
22
2
72
68
80
39
92
75
67
61
26
89
59
19
29
7
60
91
34
73
53
22
2
85
22
47
92
90
99
100
44
82
19
1
49
100
13
67
32
75
98

Output: 151 10100

Input:
100
10000
45
35
50
78
28
97
37
92
91
51
93
33
70
43
53
78
31
14
29
67
11
7
41
85
70
27
74
15
15
10
52
50
66
81
95
25
28
86
17
89
19
87
85
38
79
19
92
85
62
71
18
72
92
18
93
56
64
54
3
38
18
77
3
54
70
49
56
91
60
56
34
54
42
41
75
90
43
21
18
69
76
51
24
50
82
56
62
45
50
67
20
31
12
10
10
7
75
84
17
18

Output: 151 10097

Input:
2
50
1
51

Output: 51 101

Input:
3
100
52
2
2

Output: 52 152

Input:
100
300
1
1
2
2
1
1
1
1
1
1
2
2
1
2
2
1
2
2
2
2
2
1
1
1
2
1
2
1
1
1
2
1
1
1
2
1
2
1
2
1
2
1
2
1
2
1
1
1
1
2
2
2
1
1
2
1
2
2
2
1
1
2
2
2
2
2
2
1
1
2
2
2
2
1
2
2
2
1
2
1
1
2
2
1
1
1
1
2
1
2
2
1
2
2
1
1
2
1
2
2

Output: 5 302

Input:
100
3000
99
100
99
99
100
99
100
99
99
100
99
100
100
99
100
100
99
99
99
100
100
100
100
100
99
100
100
99
100
100
99
99
99
99
100
100
99
99
99
100
99
100
100
99
99
100
100
100
99
99
99
100
99
99
99
100
99
99
100
99
100
100
100
99
99
100
100
100
99
100
100
99
99
100
100
99
100
100
100
99
99
100
100
99
100
99
99
100
99
99
99
100
99
100
100
100
99
100
99
100

Output: 130 3100

Input:
100
10000
54
54
50
52
55
51
50
53
50
56
50
51
51
52
54
50
54
52
53
56
55
51
52
55
56
52
52
56
51
56
51
51
55
54
52
55
51
55
56
54
55
54
56
56
51
52
52
56
51
52
52
55
53
51
55
51
54
52
56
51
50
52
52
55
53
52
53
53
51
52
54
50
53
53
56
52
52
54
54
52
55
53
54
53
54
55
56
51
54
55
50
56
52
50
55
55
54
55
50
50

Output: 154 10056

Input:
100
2325
78
78
80
78
79
80
79
80
79
80
78
80
79
80
78
78
79
80
80
80
79
79
79
79
80
80
79
80
79
80
79
79
79
79
80
80
80
78
80
80
80
78
80
80
80
80
78
78
79
79
79
79
80
78
80
78
80
80
80
79
78
79
80
80
78
78
80
78
80
79
78
80
78
78
80
80
78
78
79
78
78
79
79
78
80
78
78
80
80
80
78
80
78
79
80
78
80
79
78
79

Output: 103 2405

Input:
100
3241
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100

Output: 133 3341

Input:
100
9675
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Output: 98 9676

Input:
100
9435
36
37
36
36
37
34
35
37
36
34
37
35
34
35
35
36
36
37
37
36
37
34
36
35
37
36
34
35
35
35
34
36
37
36
35
34
35
34
34
34
36
37
37
34
37
34
37
36
35
36
37
35
37
35
36
34
36
35
35
35
37
37
36
34
35
35
36
35
34
35
35
35
37
36
34
35
37
36
36
36
36
35
34
37
35
34
37
37
36
37
37
34
36
35
36
35
34
37
34
35

Output: 130 9472

Input:
100
9999
4
5
1
8
8
2
9
5
8
6
10
8
2
10
5
10
10
3
3
1
9
7
1
5
3
7
1
3
7
3
7
8
8
8
10
3
9
9
5
9
4
7
3
8
8
6
9
4
4
8
3
6
3
3
7
10
4
2
4
3
9
10
2
4
3
1
3
4
4
4
5
8
6
3
9
10
7
7
10
2
6
10
7
7
10
6
2
9
8
1
6
7
3
5
8
6
1
3
8
5

Output: 106 10009

Input:
100
2344
42
40
69
62
79
43
36
55
44
13
48
69
46
61
70
75
51
67
57
35
5
19
6
92
78
59
42
3
81
41
70
90
99
93
44
22
80
62
69
95
12
63
99
42
12
9
72
8
19
33
81
33
66
32
10
50
98
83
11
25
81
13
56
60
4
89
75
59
92
7
55
84
48
85
82
18
29
68
60
25
26
37
12
15
27
17
85
20
16
47
76
55
75
66
47
98
90
32
47
9

Output: 99 2443

Input:
100
1
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100

Output: 101 101

Input:
100
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Output: 2 2

Input:
100
2
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50

Output: 51 52

Input:
100
300
1
1
2
2
1
2
2
2
1
2
2
2
1
2
1
1
2
2
1
1
2
1
1
2
1
2
2
2
2
2
2
1
1
1
2
2
2
2
1
1
1
2
1
1
2
2
2
1
2
2
2
1
2
2
1
2
1
1
2
2
2
2
1
2
2
2
1
1
2
1
1
1
1
2
2
2
2
2
1
2
1
1
1
1
2
1
1
2
2
1
2
1
1
1
2
2
93
1
2
2

Output: 93 393

Input:
100
3000
2
4
4
5
3
3
5
5
2
4
4
2
3
1
5
5
5
3
3
1
2
2
3
3
5
5
3
5
2
1
4
4
5
3
4
3
1
3
5
1
3
3
3
5
3
4
1
3
1
5
5
5
5
3
5
5
2
1
4
2
5
1
1
5
1
3
3
1
4
2
4
3
4
4
5
2
5
95
1
2
1
2
5
3
3
2
3
4
2
3
3
2
3
4
4
4
4
3
3
2

Output: 95 3095

Input:
100
10000
51
53
53
54
52
52
51
53
52
55
53
51
56
55
55
50
53
53
50
52
53
50
51
56
54
50
53
51
54
50
50
55
50
53
52
52
54
56
56
52
54
56
52
52
55
54
56
53
54
53
55
50
55
54
54
56
50
50
56
55
55
53
52
54
52
53
50
53
54
52
53
52
52
56
51
53
53
55
50
50
51
55
55
51
50
51
50
54
93
50
50
55
55
50
54
55
55
53
53
56

Output: 154 10093

Input:
100
2325
30
18
24
24
23
23
18
28
26
28
29
23
22
19
26
26
29
20
26
30
30
26
27
25
24
25
27
22
22
19
23
22
25
27
25
21
25
26
22
20
29
21
21
22
26
29
18
22
19
23
29
30
25
22
24
30
22
23
22
26
24
19
27
20
27
29
30
22
30
26
22
19
23
20
21
26
20
30
26
24
30
20
26
24
97
25
23
19
22
19
23
29
28
28
26
29
23
26
28
20

Output: 97 2422

Input:
100
3241
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
93
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10

Output: 93 3334

Input:
100
9675
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
99
1
1
1
1
1
1
1
1

Output: 99 9774

Input:
10
1
5
5
5
5
4
5
5
5
5
5

Output: 5 6

Input:
100
9435
15
16
21
24
22
27
24
18
26
25
17
25
14
26
15
20
17
21
17
24
26
26
27
21
24
20
26
25
25
20
22
19
14
16
17
27
16
21
16
27
21
14
24
27
24
19
25
23
21
19
16
14
25
18
96
25
24
15
20
21
22
15
24
23
14
22
26
26
16
17
23
17
25
22
21
27
26
19
25
25
23
16
25
19
15
19
18
27
17
21
25
20
27
14
26
15
27
15
24
18

Output: 117 9531

Input:
100
9999
1
10
5
2
9
2
10
10
9
6
10
8
10
2
10
8
5
4
8
6
3
4
8
6
1
3
8
8
7
7
5
3
2
8
4
3
7
9
9
10
7
1
10
6
2
8
7
4
3
5
9
1
10
3
4
10
1
7
1
91
10
4
7
6
4
3
2
6
3
5
5
2
3
3
1
10
10
7
10
7
8
4
6
6
1
10
2
9
6
5
1
10
8
2
10
7
8
5
3
6

Output: 107 10090

Input:
100
2344
23
10
18
15
32
22
10
38
32
31
39
8
26
16
22
10
23
11
25
36
24
40
7
27
43
28
23
25
7
23
22
7
43
6
22
38
7
32
35
12
41
43
97
3
37
29
27
36
17
2
27
35
16
10
3
19
12
20
29
7
14
5
31
26
10
4
3
15
32
42
24
36
41
43
36
23
14
32
3
32
21
30
32
25
32
8
27
11
19
15
34
12
41
11
39
20
14
23
7
43

Output: 97 2441

Input:
2
1
5
1

Output: 5 6

Input:
4
1
1
9
9
9

Output: 9 10

Input:
2
3
1
100

Output: 100 103

Input:
2
16
2
100

Output: 100 116

Input:
2
1
1
100

Output: 100 101

Input:
3
7
1
6
1

Output: 6 13

Input:
2
1
10
1

Output: 10 11

Input:
3
1
1
1
99

Output: 99 100

Input:
2
2
1
100

Output: 100 102


The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.

#include <iostream>
int main(){std::cout<<"25\n";return 0;}
//1534

Output the last two digits of 5n without spaces between them.

The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."Could you pass the interview in the machine vision company in IT City?


The first line of input will contain three integers n, k, p (1 ≤ n ≤ 250 000, 1 ≤ k ≤ 26, 108 ≤ p ≤ 109 + 100, p will be prime).

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n,k,p;
int fpow(int a,int b)
{
	int ans=1,t=a;
	while(b)
	{
		if(b&1)ans=1ll*ans*t%p;
		t=1ll*t*t%p;b>>=1;
	}
	return ans;
}
int lowbit(int x)
{
	return x&(-x);
}
int f[26][250010];
int fac[250010],inv[250010];
void init()
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%p;
	inv[n]=fpow(fac[n],p-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=1ll*inv[i]*i%p;
	return ;
}
int solve(int cur,int S)
{
	if(f[cur][S]!=-1)
		return f[cur][S];
	if(!S){
		f[cur][S]=fac[n];
		for(int i=1;i<=cur;i++)
			f[cur][S]=1ll*f[cur][S]*(k-i+1)%p;
		return f[cur][S];
	}
	f[cur][S]=0;
	int U=S-lowbit(S);
	for(int T=U;T;T=(T-1)&U)
		f[cur][S]=(f[cur][S]+1ll*inv[S-T]*solve(cur+1,T))%p;
	f[cur][S]=(f[cur][S]+1ll*inv[S]*solve(cur+1,0))%p;
	return f[cur][S];
}
int main()
{
	scanf("%d %d %d",&n,&k,&p);
	int ans=1;
	for(int i=1;i<=n;i++)
		ans=1ll*ans*k%p;
	if(n%2==0){
		init();
		memset(f,-1,sizeof(f));
		ans=(ans-solve(0,n)+p)%p;
	}
	printf("%d\n",ans);
	return 0;
}

NoteThere are 14 strings that that Alice can win with. For example, some strings are "bbaa" and "baaa". Alice will lose on strings like "aaaa" or "bbbb".

Print a single integer, the number of winning words for Alice, modulo p.

Alice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player’s turn, they can either arbitrarily permute the characters in the words, or delete exactly one character in the word (if there is at least one character). In addition, their resulting word cannot have appeared before throughout the entire game. The player unable to make a valid move loses the game.Given n, k, p, find the number of words with exactly n characters consisting of the first k letters of the alphabet such that Alice will win if both Alice and Bob play optimally. Return this number modulo the prime number p.

Input: 4 2 100000007

Output: 14

Input: 1 10 100000007

Output: 10

Input: 5 2 100000007

Output: 32

Input: 4 1 100000007

Output: 0

Input: 4 3 100000007

Output: 78

Input: 6 3 100000007

Output: 636

Input: 250000 26 419059819

Output: 246743278

Input: 250000 21 159237107

Output: 124744886

Input: 250000 16 690557993

Output: 30969019

Input: 123456 26 330502547

Output: 122021241

Input: 232154 3 893627789

Output: 492780692

Input: 1312 25 425538233

Output: 44177569

Input: 13132 14 457083337

Output: 445627280

Input: 13131 14 625308461

Output: 313277523

Input: 131070 26 550798649

Output: 290693777

Input: 131070 15 724141441

Output: 476164776

Input: 245758 26 147046169

Output: 128006699

Input: 245758 15 662045771

Output: 558307367

Input: 196606 21 576053623

Output: 269130197

Input: 249999 25 399293347

Output: 66102644

Input: 249998 22 318340733

Output: 293011292


The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

#include <bits/stdc++.h>
#define op cin.tie(0);ios_base::sync_with_stdio(0);
using namespace std;
int n;

bool lucky(int x)
{
    while(x)
    {
        if(x%10!= 4 && x%10!=7)
            return false;

        x/=10;

    }
    return true;
}

int main()
{
    op

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            if(lucky(i))
            {
                cout<<"YES";
                return 0;
            }

        }
    }

    cout<<"NO";
    return 0;
}

NoteNote that all lucky numbers are almost lucky as any number is evenly divisible by itself.In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

Output: YES

Output: YES

Output: NO

Output: YES

Output: YES

Output: NO

Output: YES

Output: YES

Output: YES

Output: NO

Output: NO

Output: YES

Output: YES

Output: YES

Output: YES

Output: YES

Output: NO

Output: NO

Output: NO

Output: NO

Output: YES

Output: YES

Output: YES

Output: YES

Output: YES

Output: YES

Output: NO

Output: YES

Output: YES

Output: NO

Output: NO

Output: YES

Output: YES

Output: YES

Output: YES


The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).

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

ll n, x, y, c;

bool ok(ll t) {
	ll res = 0;
	ll rowl = max(1ll, y - t), rowh = min(n, y + t);
	for (ll row = rowl; row <= rowh; row++) {
		ll tt = t - abs(y - row);
		ll coll = max(1ll, x - tt), colh = min(n, x + tt);
		res += colh - coll + 1;
		if (res >= c) return 1;
	}
	return 0;
}

int main() {
	cin >> n >> x >> y >> c;
	ll lo = 0, hi = 2 * n, mid;
	while (lo <= hi) {
		mid = (lo + hi) / 2;
		if (ok(mid)) hi = mid - 1;
		else lo = mid + 1;
	}
	cout << lo << endl;
	return 0;
}

NoteInitially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. .

In a single line print a single integer — the answer to the problem.

Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).In how many seconds will Mr. Bender get happy?

Input: 6 4 3 1

Output: 0

Input: 9 3 8 10

Output: 2

Input: 9 4 3 10

Output: 2

Input: 9 8 2 10

Output: 2

Input: 1 1 1 1

Output: 0

Input: 10 7 2 7

Output: 2

Input: 8 2 6 10

Output: 2

Input: 8 1 2 10

Output: 3

Input: 6 1 4 10

Output: 3

Input: 1000000 951981 612086 60277

Output: 174

Input: 1000000 587964 232616 62357

Output: 177

Input: 1000000 948438 69861 89178

Output: 211

Input: 1000000000 504951981 646612086 602763371

Output: 17360

Input: 1000000000 81587964 595232616 623563697

Output: 17657

Input: 1000000000 55 60 715189365

Output: 37707

Input: 1000000000 85 61 857945620

Output: 41279

Input: 1000000000 55 85 423654797

Output: 28970

Input: 1000000000 63 65 384381709

Output: 27600

Input: 1000000000 44 30 891773002

Output: 42159

Input: 1000000000 6 97 272656295

Output: 23250

Input: 1000000000 999999946 999999941 715189365

Output: 37707

Input: 1000000000 999999916 999999940 857945620

Output: 41279

Input: 1000000000 999999946 999999916 423654797

Output: 28970

Input: 1000000000 999999938 999999936 384381709

Output: 27600

Input: 1000000000 55 999999941 715189365

Output: 37707

Input: 1000000000 85 999999940 857945620

Output: 41279

Input: 1000000000 55 999999916 423654797

Output: 28970

Input: 1000000000 63 999999936 384381709

Output: 27600

Input: 1000000000 44 999999971 891773002

Output: 42159

Input: 1000000000 6 999999904 272656295

Output: 23250

Input: 1000000000 999999946 60 715189365

Output: 37707

Input: 1000000000 999999916 61 857945620

Output: 41279

Input: 1000000000 999999946 85 423654797

Output: 28970

Input: 1000000000 999999938 65 384381709

Output: 27600

Input: 1000000000 999999957 30 891773002

Output: 42159

Input: 548813503 532288332 26800940 350552333

Output: 13239

Input: 847251738 695702891 698306947 648440371

Output: 18006

Input: 891773002 152235342 682786380 386554406

Output: 13902

Input: 812168727 57791401 772019566 644719499

Output: 17954

Input: 71036059 25478942 38920202 19135721

Output: 3093

Input: 549 198 8 262611

Output: 635

Input: 848 409 661 620581

Output: 771

Input: 892 364 824 53858

Output: 183

Input: 813 154 643 141422

Output: 299

Input: 72 40 68 849

Output: 25

Input: 958 768 649 298927

Output: 431

Input: 800 305 317 414868

Output: 489

Input: 721 112 687 232556

Output: 556

Input: 522 228 495 74535

Output: 249

Input: 737 231 246 79279

Output: 199

Input: 6 4 3 36

Output: 6

Input: 9 3 8 55

Output: 7

Input: 9 4 3 73

Output: 8

Input: 9 8 2 50

Output: 7

Input: 1 1 1 1

Output: 0

Input: 10 7 2 7

Output: 2

Input: 8 2 6 20

Output: 3

Input: 8 1 2 64

Output: 13

Input: 6 1 4 15

Output: 3

Input: 8 8 3 1

Output: 0


The only line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$).

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using pii = pair<int, int>;
using vi = vector <int>;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define ook order_of_key
#define fbo find_by_order
#define sq(x) (x) * (x)
#define N 2005

ll n, dp[N][N], ans, mod = 1e9 + 7, sum[N];
int main (){
	cin >> n;
	n *= 2;
	dp[0][0] = 1;
	for (int i = 0;i < n;i++)
		for (int j = 0;j <= n - i;j++){
			sum[i] = (sum[i] + dp[i][j]) % mod;
			if (j) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % mod;
			dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
		}
	for (int i = n - 1;i >= 0;i -= 2)
		ans = (ans + sum[i]) % mod;
	cout << ans;
}

NoteThe pictures below illustrate tries in the first two examples (for clarity, the round brackets are replaced with angle brackets). The maximum matching is highlighted with blue.

Print exactly one integer — the size of the maximum matching in the trie. Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.

Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys...It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of weird things, including a trie of all correct bracket sequences of length $$$2n$$$.The definition of correct bracket sequence is as follows:  The empty sequence is a correct bracket sequence,  If $$$s$$$ is a correct bracket sequence, then $$$(\,s\,)$$$ is a correct bracket sequence,  If $$$s$$$ and $$$t$$$ are a correct bracket sequence, then $$$st$$$ is also a correct bracket sequence. For example, the strings "(())", "()()" form a correct bracket sequence, while ")(" and "((" not.Aki then came up with an interesting problem: What is the size of the maximum matching (the largest set of edges such that there are no two edges with a common vertex) in this trie? Since the answer can be quite large, print it modulo $$$10^9 + 7$$$.


The first line contains one integer $$$a_1$$$ $$$(1 \le a_1 \le 1\,000)$$$ — the number of players in the first team. The second line contains one integer $$$a_2$$$ $$$(1 \le a_2 \le 1\,000)$$$ — the number of players in the second team. The third line contains one integer $$$k_1$$$ $$$(1 \le k_1 \le 1\,000)$$$ — the maximum number of yellow cards a player from the first team can receive (after receiving that many yellow cards, he leaves the game). The fourth line contains one integer $$$k_2$$$ $$$(1 \le k_2 \le 1\,000)$$$ — the maximum number of yellow cards a player from the second team can receive (after receiving that many yellow cards, he leaves the game). The fifth line contains one integer $$$n$$$ $$$(1 \le n \le a_1 \cdot k_1 + a_2 \cdot k_2)$$$ — the number of yellow cards that have been shown during the match.

#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define mp(x, y) make_pair(x, y)
#define forn(i, a, b) for(size_t i=a; i<b; ++i)
#define ford(i, a, b) for(size_t i=b-1; i>=a; --i)
#define all(a) a.begin(), a.end()
#define sz(a) (size_t)(a).size()
#define X first
#define Y second
#define sqr(x) 1ll*(x)*(x)
#define pb push_back
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using vint = vector<int>;
using vll = vector<ll>;
using v2int = vector<vint>;
using v2ll = vector<vll>;

int main()
{
    fio;
    int a1,a2,k1,k2,n;
    int MAX=0;
    cin >>a1>>a2>>k1>>k2>>n;

    if (k2<k1)
    {
        swap(k1,k2);
        swap(a1,a2);
    }

    int t1=a1,t2=a2,nn=n;

    while (a1>0 && n>=k1)
    {
        n-=k1;
        a1--;
    }

    while (a2>0 && n>=k2)
    {
        n-=k2;
        a2--;
    }

    MAX=(t1-a1)+(t2-a2);
    ///////////////////

    a1=t1;
    a2=t2;
    n=nn;

    int tmp=a1*(k1-1)+a2*(k2-1);

    cout<<(tmp>=n?0:n-tmp)<<" "<<MAX<<endl;

}

NoteIn the first example it could be possible that no player left the game, so the first number in the output is $$$0$$$. The maximum possible number of players that could have been forced to leave the game is $$$4$$$ — one player from the first team, and three players from the second.In the second example the maximum possible number of yellow cards has been shown $$$(3 \cdot 6 + 1 \cdot 7 = 25)$$$, so in any case all players were sent off.

Print two integers — the minimum and the maximum number of players that could have been thrown out of the game.

The final match of the Berland Football Cup has been held recently. The referee has shown $$$n$$$ yellow cards throughout the match. At the beginning of the match there were $$$a_1$$$ players in the first team and $$$a_2$$$ players in the second team.The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives $$$k_1$$$ yellow cards throughout the match, he can no longer participate in the match — he's sent off. And if a player from the second team receives $$$k_2$$$ yellow cards, he's sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of $$$n$$$ yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.

Input:
2
3
5
1
8

Output: 0 4

Output: 0 4

Output:
0
4

Output: 0   4

Output: 0 4

Output: 0 4

Output:
0
4

Input:
3
1
6
7
25

Output: 4   4

Output:
4
4

Output: 4 4

Output: 4 4

Output:
4
4

Output: 4 4

Output: 4 4

Input:
6
4
9
10
89

Output: 5 9

Output: 5 9

Output: 5 9

Output:
5
9

Output: 5   9

Output:
5
9

Output: 5 9

Input:
10
6
5
3
56

Output:
4
13

Output: 4 13

Output: 4 13

Output: 4 13

Output:
4
13

Output: 4 13

Output: 4   13

Input:
1
8
6
1
11

Output:
6
8

Output: 6 8

Output: 6 8

Output:
6
8

Output: 6 8

Output: 6   8

Output: 6 8

Input:
8
4
1
2
9

Output: 5 8

Output: 5 8

Output: 5 8

Output:
5
8

Output: 5 8

Output: 5   8

Output:
5
8

Input:
1000
1000
1000
1000
1456999

Output: 0   1456

Output: 0 1456

Output: 0 1456

Output: 0 1456

Output:
0
1456

Output: 0 1456

Output:
0
1456

Input:
8
2
6
7
34

Output: 0   5

Output: 0 5

Output: 0 5

Output: 0 5

Output:
0
5

Output: 0 5

Output:
0
5

Input:
7
6
2
6
11

Output: 0   5

Output: 0 5

Output: 0 5

Output: 0 5

Output:
0
5

Output: 0 5

Output:
0
5

Input:
621
739
132
209
236198

Output: 1135 1358

Output:
1135
1358

Output:
1135
1358

Output: 1135 1358

Output: 1135 1358

Output: 1135 1358

Output: 1135   1358

Input:
998
967
976
961
1902359

Output: 989 1964

Output: 989   1964

Output: 989 1964

Output:
989
1964

Output: 989 1964

Output:
989
1964

Output: 989 1964

Input:
8
8
3
7
61

Output: 0 13

Output: 0   13

Output:
0
13

Output:
0
13

Output: 0 13

Output: 0 13

Output: 0 13

Input:
5
8
7
1
38

Output: 8 12

Output: 8 12

Output:
8
12

Output: 8 12

Output: 8 12

Output: 8   12

Output:
8
12

Input:
4
7
1
10
60

Output:
0
9

Output: 0 9

Output: 0 9

Output: 0 9

Output: 0 9

Output:
0
9

Output: 0   9

Input:
1
7
2
3
5

Output: 0 2

Output: 0 2

Output:
0
2

Output: 0   2

Output: 0 2

Output: 0 2

Output:
0
2

Input:
4
5
8
5
54

Output:
6
8

Output: 6 8

Output: 6 8

Output:
6
8

Output: 6 8

Output: 6   8

Output: 6 8

Input:
9
9
6
4
28

Output:
0
7

Output: 0 7

Output:
0
7

Output: 0   7

Output: 0 7

Output: 0 7

Output: 0 7

Input:
1
1
1
1
1

Output:
1
1

Output: 1 1

Output: 1   1

Output:
1
1

Output: 1 1

Output: 1 1

Output: 1 1

Input:
1
1
1
1
2

Output: 2 2

Output:
2
2

Output: 2 2

Output: 2 2

Output: 2 2

Output:
2
2

Output: 2   2

Input:
1000
1000
1000
1000
1999999

Output:
1999
1999

Output: 1999   1999

Output: 1999 1999

Output: 1999 1999

Output:
1999
1999

Output: 1999 1999

Output: 1999 1999

Input:
1000
1000
1000
1000
2000000

Output: 2000   2000

Output: 2000 2000

Output: 2000 2000

Output: 2000 2000

Output:
2000
2000

Output:
2000
2000

Output: 2000 2000

Input:
1000
1000
1000
1000
234567

Output:
0
234

Output: 0 234

Output: 0 234

Output:
0
234

Output: 0   234

Output: 0 234

Output: 0 234

Input:
1000
1000
1000
1000
1542000

Output: 0 1542

Output: 0 1542

Output: 0   1542

Output:
0
1542

Output: 0 1542

Output:
0
1542

Output: 0 1542

Input:
645
910
871
584
1093020

Output: 1340 1554

Output: 1340 1554

Output: 1340 1554

Output: 1340 1554

Output:
1340
1554

Output: 1340   1554

Output:
1340
1554

Input:
69
50
425
358
47212

Output: 106 118

Output: 106 118

Output: 106 118

Output:
106
118

Output:
106
118

Output: 106   118

Output: 106 118

Input:
493
599
875
539
754094

Output: 950 1091

Output: 950   1091

Output:
950
1091

Output: 950 1091

Output:
950
1091

Output: 950 1091

Output: 950 1091

Input:
45
583
686
390
257651

Output: 39 627

Output: 39   627

Output:
39
627

Output: 39 627

Output: 39 627

Output: 39 627

Output:
39
627

Input:
469
236
432
868
407315

Output: 564 704

Output: 564 704

Output:
564
704

Output: 564 704

Output: 564   704

Output:
564
704

Output: 564 704

Input:
893
376
689
346
744309

Output: 205 1267

Output: 205 1267

Output: 205 1267

Output: 205 1267

Output:
205
1267

Output:
205
1267

Output: 205   1267

Input:
21
924
435
527
495557

Output: 419 944

Output: 419   944

Output: 419 944

Output: 419 944

Output: 419 944

Output:
419
944

Output:
419
944

Input:
445
65
989
197
452410

Output: 10 509

Output:
10
509

Output:
10
509

Output: 10 509

Output: 10 509

Output: 10   509

Output: 10 509

Input:
869
909
438
379
724194

Output: 839 1775

Output:
839
1775

Output: 839 1775

Output: 839 1775

Output:
839
1775

Output: 839   1775

Output: 839 1775

Input:
997
754
992
152
1103189

Output: 1308 1750

Output: 1308   1750

Output: 1308 1750

Output:
1308
1750

Output: 1308 1750

Output: 1308 1750

Output:
1308
1750

Input:
421
702
250
334
339096

Output: 501 1121

Output: 501   1121

Output:
501
1121

Output: 501 1121

Output: 501 1121

Output:
501
1121

Output: 501 1121

Input:
549
250
995
811
748917

Output:
711
798

Output: 711 798

Output: 711 798

Output: 711 798

Output: 711   798

Output:
711
798

Output: 711 798

Input:
269
95
253
185
85627

Output:
359
363

Output: 359 363

Output: 359 363

Output:
359
363

Output: 359 363

Output: 359 363

Output: 359   363

Input:
398
235
999
663
552924

Output: 150 632

Output: 150   632

Output: 150 632

Output: 150 632

Output:
150
632

Output:
150
632

Output: 150 632

Input:
1
1
7
1
2

Output: 0 1

Output:
0
1

Output: 0 1

Output: 0 1

Output: 0 1

Output: 0   1

Output:
0
1

Input:
254
771
827
760
693168

Output:
0
900

Output:
0
900

Output: 0 900

Output: 0   900

Output: 0 900

Output: 0 900

Output: 0 900

Input:
708
360
819
836
642301

Output:
0
782

Output: 0   782

Output: 0 782

Output:
0
782

Output: 0 782

Output: 0 782

Output: 0 782

Input:
1
1
1
3
4

Output: 2 2

Output:
2
2

Output: 2 2

Output: 2 2

Output: 2 2

Output:
2
2

Output: 2   2

Input:
998
967
976
961
1903335

Output: 1965 1965

Output:
1965
1965

Output: 1965 1965

Output: 1965 1965

Output: 1965 1965

Output:
1965
1965

Output: 1965   1965

Input:
998
967
976
961
1901392

Output: 22 1963

Output: 22   1963

Output:
22
1963

Output:
22
1963

Output: 22 1963

Output: 22 1963

Output: 22 1963

Input:
1000
1000
1000
1000
998

Output:
0
0

Output: 0   0

Output: 0 0

Output: 0 0

Output:
0
0

Output: 0 0

Output: 0 0


The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.

#include <bits/stdc++.h>

using namespace std;

int mx,b,c;
double arr[15000],a;
bool chek;

int main()
{

    for(int i=1; i<=3; i++){
        cin>>a;
        if(a==1)arr[1]+=(1/a);
        if(!((int)a%2))arr[2]+=(2/a);
        if(!((int)a%3))arr[3]+=(3/a);
    }
    if((arr[1]) || (arr[2]>=2) || (arr[3]>=3)){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    //chek= ((b*c)+(a*c)+(b*a))/(a*b*c);
    /*if(chek){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    mx=arr[2]-1;
    if(!mx){
        cout<<"YES\n";
        return 0;
    }
    chek = (mx/arr[0])+(mx/arr[1]);
    if(chek>=mx){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }*/
    return 0;
}

NoteIn the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.

If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.

Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.Help Mishka by telling him if it is possible to do this!

Input: 2 2 3

Output: YES

Input: 4 2 3

Output: NO

Input: 1499 1498 1500

Output: NO

Input: 1500 1500 1500

Output: NO

Input: 100 4 1

Output: YES

Input: 4 2 4

Output: YES

Input: 3 3 3

Output: YES

Input: 2 3 6

Output: NO

Input: 2 3 3

Output: NO

Input: 4 4 2

Output: YES

Input: 1 1 1

Output: YES

Input: 2 11 2

Output: YES

Input: 4 4 4

Output: NO

Input: 4 4 5

Output: NO

Input: 3 3 2

Output: NO

Input: 3 6 6

Output: NO

Input: 2 3 2

Output: YES

Input: 1 1 3

Output: YES

Input: 3 3 4

Output: NO

Input: 2 4 4

Output: YES

Input: 2 2 2

Output: YES

Input: 2 10 10

Output: NO

Input: 3 4 4

Output: NO

Input: 2 5 5

Output: NO

Input: 2 4 5

Output: NO

Input: 228 2 2

Output: YES

Input: 2 998 1000

Output: NO

Input: 2 6 6

Output: NO

Input: 6 4 7

Output: NO

Input: 2 5 2

Output: YES

Input: 2 100 100

Output: NO

Input: 7 7 2

Output: NO

Input: 3 3 6

Output: NO

Input: 82 3 82

Output: NO

Input: 2 3 5

Output: NO

Input: 1 218 924

Output: YES

Input: 4 4 123

Output: NO

Input: 4 4 3

Output: NO

Input: 3 4 2

Output: NO

Input: 2 2 5

Output: YES

Input: 2 10 2

Output: YES

Input: 5 2 2

Output: YES

Input: 3 3 9

Output: NO

Input: 1 5 5

Output: YES

Input: 2 4 6

Output: NO

Input: 15 3 3

Output: NO

Input: 1 5 10

Output: YES

Input: 2 3 14

Output: NO

Input: 1265 2 593

Output: NO

Input: 2 2 567

Output: YES

Input: 1 6 5

Output: YES

Input: 2 2 7

Output: YES

Input: 2 2 1500

Output: YES

Input: 3 6 9

Output: NO

Input: 1 46 79

Output: YES

Input: 4 3 3

Output: NO

Input: 2 4 8

Output: NO

Input: 1493 1489 1487

Output: NO

Input: 1 2 3

Output: YES

Input: 1 2 5

Output: YES

Input: 1 2 8

Output: YES

Input: 3 4 5

Output: NO

Input: 2 2 4

Output: YES

Input: 3 2 3

Output: NO

Input: 7 2 2

Output: YES

Input: 3 2 2

Output: YES

Input: 6 7 4

Output: NO


The first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents ci (1 ≤ ci ≤ n).

#include <bits/stdc++.h>
using namespace std;
int C[25],A[25];
int N;
int dfs(int idx,int rem)
{
	if(idx>N)
	{
		for(int i = 1;i<=N;i++)
		{
			if(C[i])
				return 0;
		}
		return 1;
	}
	if(!A[idx])
		return dfs(idx+1,A[idx+1]-1);
	for(int i = min(A[idx],rem);i>0;i--)
	{
		if(C[i])
		{
			C[i]-=1,A[idx]-=i;
			if(dfs(idx,i))
				return 1;
			A[idx]+=i,C[i]+=1;
		}
	}
	return 0;
}
int main()
{
	cin>>N;
	C[N] = -1;
	for(int i = 1;i<=N;i++)
	{
		cin>>A[i];
		C[A[i]]+=1;
		A[i]-=1;
	}
	puts(dfs(1,A[1] - 1)?"YES":"NO");
	return 0;
}

Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).

Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that  each internal node (a node with at least one son) has at least two sons;  node i has ci nodes in its subtree? Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.

Input:
4
1 1 1 4

Output: YES

Input:
5
1 1 5 2 1

Output: NO

Input:
13
1 1 1 1 1 1 1 1 1 4 4 4 13

Output: YES

Input:
4
1 1 1 3

Output: NO

Input:
24
1 1 1 1 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 1

Output: YES

Input:
24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Output: NO

Input:
10
1 1 1 1 7 1 1 1 4 10

Output: YES

Input:
24
1 1 3 1 1 10 2 9 13 1 8 1 4 1 3 24 1 1 1 1 4 1 3 1

Output: NO

Input:
24
2 3 20 1 4 9 1 3 1 2 1 3 1 2 1 1 1 2 1 2 4 24 2 1

Output: NO

Input:
24
8 5 3 1 1 5 10 1 1 1 1 5 1 2 7 3 4 1 1 24 1 1 2 8

Output: NO

Input:
24
1 1 1 3 4 1 24 1 1 3 1 1 1 5 14 2 17 1 2 2 5 1 1 6

Output: NO

Input:
1
1

Output: YES

Input:
17
6 1 1 1 3 1 1 17 6 1 4 1 1 1 3 1 1

Output: YES

Input:
23
1 1 1 1 3 7 3 1 1 1 3 7 1 3 1 15 1 3 7 3 23 1 1

Output: YES

Input:
24
1 24 1 1 1 3 8 1 1 3 1 1 6 1 1 1 1 3 5 1 3 7 13 1

Output: YES

Input:
16
1 1 1 1 1 1 1 1 1 1 1 1 16 1 1 1

Output: YES

Input:
21
1 1 1 6 1 1 13 21 1 1 3 1 8 1 19 3 3 1 1 1 1

Output: YES

Input:
22
1 1 1 6 1 1 13 21 1 1 2 1 8 1 19 3 3 1 1 1 1 2

Output: NO

Input:
19
9 7 1 8 1 1 1 13 1 1 3 3 19 1 1 1 1 1 1

Output: NO

Input:
18
6 1 1 3 1 1 1 1 1 1 4 1 8 1 1 18 1 5

Output: YES

Input:
14
4 1 1 1 3 1 1 1 1 14 1 5 1 3

Output: YES

Input:
2
1 2

Output: NO

Input:
24
3 3 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Output: NO

Input:
20
20 9 4 4 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: YES

Input:
12
12 7 4 3 3 1 1 1 1 1 1 1

Output: YES


The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.

#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const long long MAXN = 2000;
const long long mod = 1000000007;
long long C[MAXN][MAXN], nn[MAXN], f[MAXN];
long long a[MAXN];
long long n, k;
long long res = 0, s = 0;

long long next(long long a[], long long l, long long r, long long up)
{
	a[r + 1] = 0;
	a[l]++;
	for(long long i = l; i <= r; i++)
		if (a[i] > up)
		{
			a[i] = 1;
			a[i + 1]++;
		}
	if (a[r + 1])
		return 0;
	return 1;
}

long long pow(long long a, long long b)
{
	long long res = 1;
	for(long long i = 1; i <= b; i++)
		res = res * a % mod;
	return res;
}

int main()
{
	cin >> n >> k;
	for(long long i = 0; i <= n; i++)
		C[i][0] = 1;
	for(long long i = 1; i <= n; i++)
		for(long long j = 1; j <= n; j++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	nn[0] = 1;
	//for(long long i = 1; i <= n; i++, prlong longf("\n"))
	//	for(long long j = 1; j <= n; j++)
	//		prlong longf("%I64d ", C[i][j]);
	for(long long i = 1; i <= n; i++)
		nn[i] = nn[i - 1] * i % mod;
	res = pow(n - k, n - k);

	//prlong longf("%I64d\n", res);
	for(long long i = 1; i <= k; i++)
	{
		long long tmp = C[k - 1][i - 1] * nn[i - 1] % mod;
		long long left = k - i;
		for(long long j = i + 1; j <= k; j++)
			a[j] = 1;
		long long tmp2 = 0;
		while(1)
		{
			long long flag = 1;
			for(long long j = i + 1; j <= k; j++)
			{
				long long x = j, ok = 0;
				for(long long l = 1; l <= k; l++)
				{
					x = a[x];
					if (x <= i)
						ok = 1;
				}
				if (!ok)
				{
					flag = 0;
					break;
				}
			}
			tmp2 += flag;
			if (!next(a, i + 1, k, k))
				break;
		}
		s += tmp2 * tmp % mod;
		s %= mod;

	}
	cout << res * s % mod << endl;
	return 0;
}

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n).Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house px), then he goes to the house whose number is written on the plaque of house px (that is, to house ppx), and so on.We know that:  When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.  When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.  When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house. You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).

Input: 5 2

Output: 54

Input: 7 4

Output: 1728

Input: 8 5

Output: 16875

Input: 8 1

Output: 823543

Input: 10 7

Output: 3176523

Input: 12 8

Output: 536870912

Input: 50 2

Output: 628702797

Input: 100 8

Output: 331030906

Input: 1000 8

Output: 339760446

Input: 999 7

Output: 490075342

Input: 685 7

Output: 840866481

Input: 975 8

Output: 531455228

Input: 475 5

Output: 449471303

Input: 227 6

Output: 407444135

Input: 876 8

Output: 703293724

Input: 1000 1

Output: 760074701

Input: 1000 2

Output: 675678679

Input: 1000 3

Output: 330155123

Input: 1000 4

Output: 660270610

Input: 1000 5

Output: 583047503

Input: 1000 6

Output: 834332109

Input: 657 3

Output: 771999480

Input: 137 5

Output: 160909830

Input: 8 8

Output: 2097152

Input: 9 8

Output: 2097152

Input: 1 1

Output: 1

Input: 2 1

Output: 1

Input: 2 2

Output: 2

Input: 3 3

Output: 9

Input: 473 4

Output: 145141007


The first line contains three space-separated integers a, b and c (0 ≤ a, b, c ≤ 231; a + b + c > 0) — the number of red, green and blue pixels, correspondingly.

#include<bits/stdc++.h>
using namespace std;
long long a[3];
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if ((a[0]+a[1])%2==0) cout<<a[1]; else cout<<a[2];
}

NoteIn the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.

Print a single number — the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.

Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z ≠ x; z ≠ y). Pixels of the same color are friends, so they don't fight.The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.

Input: 1 1 1

Output: 1

Input: 3 1 0

Output: 3

Input: 1 4 4

Output: 4

Input: 5 10 6

Output: 10

Input: 6 8 10

Output: 8

Input: 1 10 2

Output: 10

Input: 10 6 8

Output: 8

Input: 18 67 5

Output: 67

Input: 67 81 1

Output: 67

Input: 51 10 91

Output: 91

Input: 48 6 7

Output: 48

Input: 8 97 83

Output: 97

Input: 2 7 95

Output: 95

Input: 772486757 1747374885 377299255

Output: 772486757

Input: 1358352906 27037371 1947040615

Output: 1947040615

Input: 1944219055 454183506 1369298327

Output: 1944219055

Input: 382601556 881329640 791556039

Output: 881329640

Input: 246543403 71853598 1504509195

Output: 1504509195

Input: 50606342 2 1134945035

Output: 50606342

Input: 9 530792195 6

Output: 530792195

Input: 1016450951 2 9

Output: 1016450951

Input: 3 10 1007169359

Output: 1007169359

Input: 0 1 0

Output: 0

Input: 1 0 0

Output: 0

Input: 0 0 1

Output: 0

Input: 3 2 0

Output: 2

Input: 0 3 2

Output: 2

Input: 3 0 2

Output: 2

Input: 10 10 0

Output: 10

Input: 0 0 10

Output: 0

Input: 2 2 0

Output: 2

Input: 0 2 10

Output: 2

Input: 5 0 5

Output: 5

Input: 5 9 0

Output: 9

Input: 2147483648 2147483648 2147483648

Output: 2147483648

Input: 2147483648 2147483647 2147483648

Output: 2147483648

Input: 2147483648 0 0

Output: 0

Input: 2147483648 2147483648 0

Output: 2147483648

Input: 2147483648 0 2147483647

Output: 2147483648

Input: 2147483630 2147483642 2147483610

Output: 2147483630

Input: 1 4 3

Output: 3

Input: 1 2 3

Output: 3

Input: 1 0 1

Output: 1

Input: 92134834 23742837 92374737

Output: 92374737

Input: 92134834 23742837 92374738

Output: 92374738

Input: 92134834 23742837 92374739

Output: 92374739

Input: 9214834 2742837 9234739

Output: 9234739

Input: 914835 2742837 9234739

Output: 2742837

Input: 1 2 2147483648

Output: 2147483648

Input: 0 0 58

Output: 0


The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.

#include <bits/stdc++.h>

using namespace std;

int k, a, v, b, st, dr, piv;

int check(int x){
	int nr = min(x * (k-1), b);
	return ((x + nr) * v);
}

int main(){
//	ifstream in("tst.in");
//	ofstream out("tst.out");
	cin >> k >> a >> b >> v;
	st = 1;
	dr = 10000;
	while(st <= dr){
		piv = (st + dr) / 2;
		if(check(piv) >= a) dr = piv - 1;
		else st = piv + 1;
	}
	cout << st;
	return 0;
}

NoteIn the first sample you can act like this:   Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.  Do not put any divisors into the second box. Thus, the second box has one section for the last nut. In the end we've put all the ten nuts into boxes.The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.

Print a single integer — the answer to the problem.

You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.

Input: 3 10 3 3

Output: 2

Input: 3 10 1 3

Output: 3

Input: 100 100 1 1000

Output: 1

Input: 5 347 20 1

Output: 327

Input: 6 978 10 5

Output: 186

Input: 6 856 50 35

Output: 5

Input: 8 399 13 36

Output: 2

Input: 4 787 48 4

Output: 149

Input: 4 714 7 6

Output: 112

Input: 7 915 12 24

Output: 27

Input: 8 995 3 28

Output: 33

Input: 10 267 4 48

Output: 2

Input: 10 697 1 34

Output: 20

Input: 7 897 49 42

Output: 4

Input: 10 849 3 28

Output: 28

Input: 477 492 438 690

Output: 1

Input: 461 790 518 105

Output: 1

Input: 510 996 830 417

Output: 1

Input: 763 193 388 346

Output: 1

Input: 958 380 405 434

Output: 1

Input: 346 991 4 4

Output: 244

Input: 648 990 5 2

Output: 490

Input: 810 1000 6 5

Output: 194

Input: 683 995 10 1

Output: 985

Input: 307 999 10 7

Output: 133

Input: 974 999 3 4

Output: 247

Input: 60 1000 2 2

Output: 498

Input: 634 993 9 3

Output: 322

Input: 579 990 8 9

Output: 102

Input: 306 993 9 9

Output: 102

Input: 845 996 1 1

Output: 995

Input: 872 997 1 1

Output: 996

Input: 2 990 1 1

Output: 989

Input: 489 992 1 1

Output: 991

Input: 638 1000 1 1

Output: 999

Input: 2 4 1000 1

Output: 2