text
stringlengths 291
465k
|
---|
### Prompt
Your task is to create a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,k;
while(cin >> n >> k, n&k){
int num[n],total=0;
for(int i=0;i<n;i++) cin>>num[i];
for(int i=0;i<k;i++) total+=num[i];
int ans=total;
for(int i=0;i<n-k;i++){
total+=num[i+k]-num[i];
ans=max(ans,total);
}
cout<<ans<<endl;
}
return 0;
}
``` |
### Prompt
In CPP, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = (1 << 29);
int main()
{
while (1)
{
int n, k;
cin >> n >> k;
if (n == 0 && k == 0)
break;
int a[n];
rep(i, n) cin >> a[i];
int s[n + 1];
s[0] = 0;
rep(i, n + 1) s[i + 1] = s[i] + a[i];
int ans = -INF;
rep(i, n - k) ans = max(ans, s[i + k] - s[i]);
cout << ans << endl;
}
}
``` |
### Prompt
Develop a solution in JAVA to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
class Main {
public static void main( final String[] args ) {
final Scanner stdin = new Scanner( System.in );
while ( true ) {
final int n = stdin.nextInt();
final int k = stdin.nextInt();
if ( n == 0 && k == 0 ) {
break;
}
final Queue<Integer> q = new LinkedList<Integer>();
int maxVal = Integer.MIN_VALUE;
int sum = 0;
for ( int i = 0; i < k; i++ ) {
final int elem = stdin.nextInt();
q.offer( elem );
sum += elem;
}
maxVal = max( maxVal, sum );
for ( int i = k; i < n; i++ ) {
final int elem = stdin.nextInt();
sum -= q.poll();
sum += elem;
q.offer( elem );
maxVal = max( maxVal, sum );
}
System.out.println( maxVal );
}
}
}
``` |
### Prompt
Please create a solution in Cpp to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
int a,b;
while(cin>>a>>b,a||b){
vector<int>in(a);
rep(i,a)cin>>in[i];
int sum=0;
rep(i,b)sum+=in[i];
int ma=sum;
rep(i,a-b){
sum-=in[i];
sum+=in[i+b];
ma=max(ma,sum);
}
cout<<ma<<endl;
}
}
``` |
### Prompt
Your task is to create a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <queue>
using namespace std;
int main(){
int n,k,a,s;
while(cin>>n>>k,n||k){
int m=-10001;a=0;
queue<int> q;
n-=k;
while(k--){
cin>>s;
a+=s;q.push(s);
}
m=max(m,a);
while(n--){
cin>>s;
q.push(s);
a=a+s-q.front();
q.pop();
m=(m>a)?m:a;
}
cout<<m<<endl;
}
return 0;
}
``` |
### Prompt
In PYTHON3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k = map(int,input().split())
if n==0 and k==0:
break
a = []
for i in range(1,n+1):
a.append(int(input()))
i += 1
max = sum(a[0:k])
b = sum(a[0:k])
for j in range(0,n-k):
c = b-a[j]+a[j+k]
b = c
if c > max:
max = c
print(max)
``` |
### Prompt
Create a solution in Python3 for the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def main():
while True:
a = []
n, k = [int(x) for x in input().split()]
if n == 0 and k == 0: break
for i in range(n): a.append(int(input()))
l = [0]
for i in range(1, n - k + 1): l.append(a[i + k - 1] - a[i - 1])
maxsum = 0
maxi = 0
s = 0
for i, x in enumerate(l):
s += x
if s >= maxsum:
maxsum = s
maxi = i
print(sum(a[maxi:maxi + k]))
main()
``` |
### Prompt
Please provide a JAVA coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.Scanner;
public class Main {
private int[] a;
public static void main(String[] args) {
new Main().run();
}
private void run(){
Scanner scan = new Scanner(System.in);
while (true) {
int n = scan.nextInt();
int k = scan.nextInt();
if ((n | k) == 0) break;
a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scan.nextInt();
}
int max = -100000;
for (int i = 0; i < n - k + 1; i++) {
int sum = 0;
for (int j = i; j < i + k; j++) {
sum += a[j];
//System.out.println(a[j]);
}
if (sum > max) {
max = sum;
}
}
System.out.println(max);
}
}
}
``` |
### Prompt
Please formulate a Python solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python
while(1):
[n,k]=[int(x) for x in raw_input().split()]
if n==0:
break
else:
a=[]
for i in range(n):
a.append(int(raw_input()))
sumnow=sum(a[0:k])
M=sumnow
for top in range(1,n-k+1):
sumnow=sumnow-a[top-1]+a[top-1+k]
M=max(sumnow,M)
print M
``` |
### Prompt
Create a solution in cpp for the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<stdio.h>
int main(void)
{
int n,k,max=0,s,i,j,a[100001];
while(1){
scanf("%d%d",&n,&k);
if(n==0&&k==0) break;
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++){
s=0;
if(i+k<=n){
for(j=i;j<i+k;j++) s+=a[j];
if(max<s) max=s;
}
}
printf("%d\n",max);
}
return 0;
}
``` |
### Prompt
Please formulate a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def main():
while True:
n,k = map(int,input().split())
if n == 0 and k == 0:
break
lst = []
for i in range(n):
lst.append(int(input()))
count = 0
for i in range(k):
count += lst[i]
ans = count
for i in range(k, n):
count += lst[i]
count -= lst[i - k]
ans = max(ans,count)
print(ans)
if __name__ == '__main__':
main()
``` |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int k;
int b;
int c;//現在の和
int d;//最高値
while(cin>>n){
if(n==0){break;}
cin>>k;
int a[n];
b=0;
while(b<n){
cin >>a[b];
b=b+1;}
c=0;
b=0;
while(b<k){
c=c+a[b];
b=b+1;}
d=c;
while(b<n){
c=c-a[b-k]+a[b];
if(c>d){d=c;}
b=b+1;}
cout << d<<endl;}
}
``` |
### Prompt
Generate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<stdio.h>
int main(void)
{
int n,k,sum,max=0,i,j,a[100001];
while(1){
scanf("%d%d",&n,&k);
if(n==0&&k==0) break;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++){
sum=0;
if(i+k<=n){
for(j=i;j<i+k;j++){
sum+=a[j];
}
if(max<sum){
max=sum;
}
}
}
printf("%d\n",max);
}
return 0;
}
``` |
### Prompt
Please formulate a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
while(1){
int n, k; cin >> n >> k;
if(n==0) break;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
int ans=0;
for(int i=0; i<k; i++) ans += a[i];
int mx=ans;
for(int i=1; i<n-k+1; i++){
mx=mx+a[k-1+i]-a[i-1];
ans=max(ans, mx);
}
cout << ans << endl;
}
}
``` |
### Prompt
Your challenge is to write a python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
for v in range(5):
n, k = map(int, input().split())
if n == 0 and k == 0:
break
a = [int(input()) for i in range(n)]
sum = []
s = [0] * (n+1)
for i in range(n):
s[i+1] = s[i] + a[i]
for i in range(n-k):
sum.append(s[i+k] - s[i])
print(max(sum))
``` |
### Prompt
Please provide a PYTHON3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def solve():
while 1:
n, k = [int(_) for _ in input().split()]
if n == 0: return
A = [int(input()) for _ in range(n)]
s = [0] * (len(A) + 1)
for i in range(n):
s[i + 1] = s[i] + A[i]
ans = -1
for l in range(n):
r = l + k
if r > n: break
ans = max(ans, s[r] - s[l])
print(ans)
if __name__ == '__main__':
solve()
``` |
### Prompt
Please formulate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<vector>
using namespace std;
int main() {
int n,k;
while(cin>>n>>k, n|k) {
vector<int> v(n);
for(int i=0; i<n; ++i)
cin>>v[i];
int maxsum = 0,nsum = 0;
for(int i=0; i<k; ++i) {
maxsum += v[i];
nsum += v[i];
}
for(int i=k; i<n; i++) {
maxsum = max(nsum-v[i-k]+v[i], maxsum);
nsum = nsum-v[i-k]+v[i];
}
cout<<maxsum<<endl;
}
}
``` |
### Prompt
In cpp, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int a[100000],n,k,s,ans;
int main(){
while(true){
cin>>n>>k;
if(!n&&!k)break;
s=0,ans;
for(int i=0;i<n;i++){
cin>>a[i];
if(i<k)s+=a[i];
}
ans=s;
for(int i=k;i<n;i++)s+=a[i]-a[i-k],ans=max(s,ans);
cout<<ans<<endl;
}
return 0;
}
``` |
### Prompt
Construct a Cpp code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
using namespace std;
int main(){
int n,k;
while(cin>>n>>k && n && k){
int s[200000];
s[0]=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
s[i]=s[i-1]+x;
}
int ans=s[k];
for(int i=0;i+k<=n;i++){
ans=max(ans,s[i+k]-s[i]);
}
cout<<ans<<endl;
}
}
``` |
### Prompt
In PYTHON3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def resolve():
N, M = [int(i) for i in input().split()]
while N + M != 0:
A = [int(input()) for _ in range(N)]
preSum = [0] * (N + 1)
for i in range(N):
preSum[i + 1] = preSum[i] + A[i]
maxA = -10000 * M - 1
for i in range(M, N):
maxA = max(maxA, preSum[i] - preSum[i - M])
print(maxA)
N, M = [int(i) for i in input().split()]
resolve()
``` |
### Prompt
In python3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,m=map(int,input().split())
if n==0 and m==0:
break
A=[]
for i in range(n):
B=int(input())
A.append(B)
C=sum(A[0:m])
D=C
for i in range(m,n):
C=C+A[i]-A[i-m]
if C>D:
D=C
print(D)
``` |
### Prompt
Develop a solution in JAVA to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class Main{
public static void main(String[] args)throws IOException{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr);
String string;
int n, m, max, hoge, array[];
while(!(string = reader.readLine()).equals("0 0")){
n = Integer.valueOf(string.split(" ")[0]);
m = Integer.valueOf(string.split(" ")[1]);
array = new int[n];
for(int i = 0; i < n; i++) array[i] = Integer.valueOf(reader.readLine());
max = 0;
for(int i = 0; i < n - m + 1; i++){
hoge = 0;
for(int j = i; j < i + m; j++) hoge += array[j];
if(hoge > max) max = hoge;
}
System.out.println(max);
}
reader.readLine();
}
}
``` |
### Prompt
Construct a python3 code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
s=0
while True:
n,k = map(int, input().split())
list = [int(input()) for i in range(n)]
if n==0 and k==0:
break
a=sum(list[0:k])
b=[a]
for i in range(n-k):
a += list[i+k]-list[i]
b.append(a)
print(max(b))
``` |
### Prompt
Create a solution in Java for the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Maximum Sum
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = "";
int n, k, sum = 0, max = 0;
int[] list;
while (!(line = br.readLine()).equals("0 0")) {
n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
list = new int[n];
for (int i = 0; i < n; i++) {
list[i] = Integer.parseInt(br.readLine());
}
max = 0;
for (int i = 0; i < k; i++) {
max += list[i];
}
sum = max;
for (int i = k; i < n; i++) {
sum = sum - list[i - k] + list[i];
if (sum > max)
max = sum;
}
System.out.println(max);
}
}
}
``` |
### Prompt
Please create a solution in Python3 to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k=map(int,input().split())
if n==0 and k==0:
break
a=[int(input()) for i in range(n)]
s=sum(a[0:k])
ss=[s]
for i in range(k,n):
s=s+a[i]-a[i-k]
ss.append(s)
print(max(ss))
``` |
### Prompt
Please formulate a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, k, a[100000], i, S[100000], m=0;
while (cin >> n >> k, n, k) {
for (i = 0; i < n; i++) {
cin >> a[i];
}
S[0] = 0;
for (i = 0; i < k; i++) {
S[0] += a[i];
}
for (i = 1; i < n - k + 1; i++) {
S[i] = S[i - 1] - a[i - 1] + a[i + k - 1];
m = max(m, S[i]);
}
cout << m << endl;
}
}
``` |
### Prompt
Please formulate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int a,b=0,t,j,k,n,i,s[100000+1],v,c[100000+1]={0};
while(1)
{
cin>>n>>k;
if(n==0&&k==0)
{
break;
}
for(i=0;i<n;i++)
{
cin>>s[i];
}
v=n-k+1;
for(i=0;i<v;i++)
{
for(a=i;a<k+i;a++)
{
c[i]=c[i]+s[a];
}
}
for(i=0;i<v;i++)
{
if(b<c[i])
{
b=c[i];
}
}
cout<<b<<endl;
}
return 0;
}
``` |
### Prompt
In CPP, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
using namespace std;
int n2[100001];
int main() {
int n, k;
int cnt = 0, cnt_max = -10001;
while (1) {
cin >> n >> k;
if (n == 0 && k == 0)return 0;
for (int i = 1; i <= n; i++) {
cin >> n2[i];
}
for (int i = 1; i <= n - k + 1; i++) {
cnt = n2[i];
for (int j = 1; j < k; j++) {
cnt += n2[i + j];
}
if (cnt_max < cnt) {
cnt_max = cnt;
}
}
cout << cnt_max << endl;
cnt_max = 0;
}
}
``` |
### Prompt
Construct a Cpp code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int a[100001],b[100001];
int f(int i,int j){
return b[i] - b[j+1];
}
int main(){
int n,k;
while( cin >> n >> k , n||k ){
b[0] = 0;
for(int i=0 ; i < n ; i++ ){
cin >> a[i];
b[0] += a[i];
}
for(int i=1 ; i <= n ; i++ ){
b[i] = b[i-1] - a[i-1];
}
int s = f(0,k-1);
for(int i=1 ; i+k < n ; i++ ){
s = max( s , f(i,i+k-1) );
}
cout << s << endl;
}
}
``` |
### Prompt
Please formulate a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<stdio.h>
int main()
{
int a[100000],n,k,r,s,i;
while(scanf("%d%d",&n,&k),n)
{
for(i=0;i<n;++i)scanf("%d",&a[i]);
for(s=r=i=0;i<k;++i)s+=a[i];
for(i=k;i<n;++i)s=s-a[i-k]+a[i],r<s?r=s:0;
printf("%d\n",r);
}
}
``` |
### Prompt
Please create a solution in CPP to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
int main()
{
int k,n;
int a[100000];
while (cin>>n>>k,n!=0&&k!=0) {
long long sum=0,max;
for (int i=0; i<n; i++) cin>>a[i];
for (int i=0; i<k; i++) sum+=a[i];
max=sum;
for (int i=k; i<n; i++) {
sum=sum+a[i]-a[i-k];
if (sum>max) max=sum;
}
cout<<max<<endl;
}
}
``` |
### Prompt
Please formulate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
using namespace std;
int main(){
int n,k,s,ans;
int a[100001];
while(cin>>n>>k){
if(n==0&&k==0)break;
for(int i=0;i<n;i++)cin>>a[i];
s=0;
for(int i=0;i<n-k+1;i++){
if(i==0)for(int j=i;j<i+k;j++)s+=a[j];
if(i!=0){s-=a[i-1]; s+=a[i+k-1];}
if(i==0)ans=s;
if(s>ans)ans=s;}
cout<<ans<<endl;}}
``` |
### Prompt
Please formulate a JAVA solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main {
int INF = 1 << 28;
void run() {
Scanner sc = new Scanner(System.in);
for(;;) {
int n = sc.nextInt();
int k = sc.nextInt();
if( (n|k) == 0 ) break;
int[] a = new int[n];
for(int i=0;i<n;i++) a[i] = Integer.parseInt(sc.next());
int sum = 0;
int max = 0;
for(int i=0;i<k;i++) sum += a[i];
max = sum;
for(int i=k;i<n;i++) {
sum += a[i] - a[i-k];
max = max(max, sum);
}
System.out.println(max);
}
}
public static void main(String[] args) {
new Main().run();
}
void debug(Object... os) {
System.err.println(Arrays.deepToString(os));
}
}
``` |
### Prompt
Please formulate a Java solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cnt = -9;
int range = -9;
String line;
List<Integer> inputs = new ArrayList<>();
while ((line = br.readLine().trim()) != null && !line.isEmpty() && !"0 0".equals(line)) {
if(cnt < 0) {
List<Integer> list = Arrays.stream(line.split(" ")).map(Integer::valueOf).collect(Collectors.toList());
cnt = list.get(0);
range = list.get(1);
} else {
inputs.add(Integer.valueOf(line));
if(--cnt==0) {
output(inputs, range);
inputs.clear();
cnt = -9;
}
}
}
}
public static void output(List<Integer> list, int range) {
int sum = IntStream.range(0,range).map(j->list.get(j)).sum();
int max = sum;
for(int i=range; i<list.size(); i++) {
sum = sum - list.get(i-range) + list.get(i);
if(max<sum) max=sum;
}
System.out.println(max);
}
}
``` |
### Prompt
Please provide a Python3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
def solve():
N, K = map(int, input().split())
if N == 0:
exit()
A = [int(input()) for _ in range(N)]
S = sum(A[:K])
ans = S
for i in range(K, N):
S = S-A[i-K]+A[i]
ans = max(ans, S)
print(ans)
def solve2():
N, K = map(int, input().split())
if N == 0:
exit()
else:
A = [int(input()) for _ in range(N)]
A = [0]+list(accumulate(A))
ans = max([A[i+K]-A[i] for i in range(N-K)])
print(ans)
while True:
solve2()
``` |
### Prompt
Develop a solution in JAVA to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.maximumSumCalculation();
return;
}
//数値の列の中から、連続して並ぶk個の整数の和の最大値を求める
private void maximumSumCalculation() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
while (true) {
try {
String inputStr = bufferedReader.readLine();
String[] inputStrs = inputStr.split(" ");
int sequenceNum = Integer.parseInt(inputStrs[0]); //数列全体の数
int integerColumnNum = Integer.parseInt(inputStrs[1]); //kの数
if ((sequenceNum + integerColumnNum) == 0) {
break;
}
int[] sequenceArray = new int[sequenceNum]; //数列
LinkedList<Integer> integerColumnList = new LinkedList<Integer>(); //k個の整数の和のリスト
for (int i = 0; i < sequenceNum; i++) {
String inputNumStr = bufferedReader.readLine();
sequenceArray[i] = Integer.parseInt(inputNumStr);
}
for (int i = 0; i < sequenceNum; i++) {
int tmp = 0;
try {
for (int j = 0; j < integerColumnNum; j++) {
tmp += sequenceArray[j + i];
}
integerColumnList.add(tmp);
} catch (ArrayIndexOutOfBoundsException e) {
break;
}
}
Collections.sort(integerColumnList);
Collections.reverse(integerColumnList);
System.out.println(integerColumnList.get(0));
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
}
``` |
### Prompt
In cpp, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int i,j,n,k,a[100000],b[100000],s,max;
while(1){
cin >> n >> k;
if(n == 0 && k == 0) break;
max = 0;
s = 0;
for(i=0;i<n;i++){
cin >> a[i];
s += a[i];
b[i] = a[i];
if(i >= k-1){
if(max < s) max = s;
s -= b[i-(k-1)];
}
}
cout << max << endl;
}
return 0;
}
``` |
### Prompt
Your task is to create a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
for i in range(5):
n,k = map(int,input().split())
if n == 0 and k == 0:
break
else:
ruiseki = [0]*(n+1)
total = 0
maximum = -(10**9+7)
for i in range(n):
p = int(input())
total += p
ruiseki[i+1] = total
for i in range(n-k+1):
if ruiseki[i+k]-ruiseki[i]>maximum:
maximum = ruiseki[i+k]-ruiseki[i]
print(maximum)
``` |
### Prompt
In cpp, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <stdio.h>
int main()
{
int max,a[100000],sum,k,n;
while(scanf("%d %d",&n,&k) && n || k ){
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
}
sum = 0;
for(int i = 0; i < k; i++){
sum += a[i];
}
max = sum;
for(int i = k; i < n; i++){
sum += a[i]-a[i-k];
if(sum > max){
max = sum;
}
}
printf("%d\n",max);
}
return 0;
}
``` |
### Prompt
Please provide a cpp coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <stdio.h>
int main(){
int n,k,a[1000000],top,sum;
while(1){
scanf("%d%d",&n,&k);
if(n==0)return 0;
sum=0;
for(int i=0;i<k;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
top=sum;
for(int i=k;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
sum-=a[i-k];
if(sum>top)top=sum;
}
printf("%d\n",top);
}
}
``` |
### Prompt
Please formulate a python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
if __name__ == '__main__':
while True:
[n, k] = [int(i) for i in input().split()]
if n == 0 and k == 0:
break
a = []
for i in range(n):
a.append(int(input()))
old = sum(a[0:k])
ans = old
for i in range(1, n-k+1):
new = old - a[i-1] + a[i+k-1]
ans = max(ans, new)
old = new
print(ans)
``` |
### Prompt
Your challenge is to write a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k=map(int,input().split())
if k==0 and n==0:break
a=[int(input()) for i in range(n)]
s=sum(a[0:k])
max=s
for i in range(k,n):
s=s+a[i]-a[i-k]
if s>max:max=s
print(max)
``` |
### Prompt
Develop a solution in cpp to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int n, k;
int a[100000];
int s, m;
int main(void) {
while(cin >> n >> k, !(n == 0 && k == 0)) {
REP(i, 0, n) {
cin >> a[i];
}
s = 0;
REP(i, 0, k) {
s += a[i];
}
m = s;
REP(i, k, n) {
s += a[i] - a[i - k];
if(s > m) m = s;
}
cout << m << endl;
}
return 0;
}
``` |
### Prompt
Create a solution in java for the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.*;
import static java.lang.System.*;
public class Main {
Scanner sc = new Scanner(in);
void run() {
int[] a = new int[100001];
while (true) {
int n = sc.nextInt(), k = sc.nextInt();
if (n == 0 && k == 0) break;
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
int max = 0;
for (int i = 0; i < k; i++)
max += a[i];
int sum = max;
for (int i = 0; i < n-k; i++) {
sum = sum - a[i] + a[i+k];
max = Math.max(max, sum);
}
out.println(max);
}
}
public static void main(String[] args) {
new Main().run();
}
}
``` |
### Prompt
Please provide a cpp coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
int main()
{
int k,n;
int a[100000];
while (cin>>n>>k,n!=0&&k!=0) {
long long sum=0,max;
for (int i=0; i<k; i++) {
cin>>a[i];
sum+=a[i];
}
max=sum;
for (int i=k; i<n; i++) cin>>a[i];
for (int i=k; i<n; i++) {
sum=sum+a[i]-a[i-k];
max=sum>max?sum:max;
}
cout<<max<<endl;
}
}
``` |
### Prompt
Your task is to create a Python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def fun(n, k):
A = []
total = 0
for _ in range(n):
a = int(input())
total += a
A.append(total)
maximam = A[k-1]
for num, a in zip(range(k,n), A[k:]):
maximam = max(maximam, A[num] - A[num - k])
print(maximam)
for _ in range(5):
n, k = map(int, input().split())
if n == 0 and k == 0:
break
else:
fun(n, k)
``` |
### Prompt
Generate a python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k = map(int,input().split())
if n == 0 and k == 0:break
a = [int(input())for _ in range(n)]
s = sum(a[0:k])
ss = [s]
for i in range(k,n):
s = s+a[i]-a[i-k]
ss.append(s)
print(max(ss))
``` |
### Prompt
Your task is to create a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;
int a[MAX];
int main(void){
int n,k;
while(cin >> n >> k,n|k){
int ans=-1000000000;
int cmax=0;
for(int i=0;i<k;i++){
cin >> a[i];
cmax+=a[i];
}
ans=max(ans,cmax);
for(int i=k;i<n;i++){
cin >> a[i];
cmax+=a[i];
cmax-=a[i-k];
ans=max(ans,cmax);
}
cout << ans << endl;
}
return 0;
}
``` |
### Prompt
Generate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
int n, k;
int a[100000];
for(;;){
cin >> n >> k;
if(n == 0 && k == 0) break;
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
ll ans = 0;
for(int i = 0; i < k; i++){
ans += a[i];
}
ll sum = ans;
for(int i = k; i < n; i++){
sum -= a[i - k];
sum += a[i];
if(sum > ans) ans = sum;
}
cout << ans << endl;
}
return 0;
}
``` |
### Prompt
Please formulate a Python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
# coding: utf-8
# Your code here!
while True:
n,k=map(int,input().split())
if n+k==0:
break
a=[int(input()) for i in range(n)]
s=sum(a[0:k])
ss=[s]
for i in range(k,n):
s=s+a[i]-a[i-k]
ss.append(s)
print(max(ss))
``` |
### Prompt
Your task is to create a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
int N,K;
int A[100002];
int main(){
while(1){
scanf("%d %d",&N,&K);
if(N==0&&K==0)break;
rep(i,N)scanf("%d",&A[i]);
long long int ans=0;
long long int sans=0;
rep(i,K)sans+=A[i];
ans=sans;
rep(i,N-K){
sans-=A[i];
sans+=A[i+K];
ans=max(ans,sans);
}
printf("%lld\n",ans);
}
}
``` |
### Prompt
Please provide a Python3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
for p in range(5):
n, k = map(int, input().split())
if n == 0 and k == 0:
break
a = []
for i in range(n):
a_ = int(input())
a.append(a_)
s = [0 for i in range(n+1)]
for i in range(n):
s[i+1] = s[i] + a[i]
ans = -10*18
for i in range(n-k+1):
if s[i+k] - s[i] > ans:
ans = s[i+k] - s[i]
print(ans)
``` |
### Prompt
Your task is to create a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <vector>
using namespace std;
int main() {
while(true){
int n,k;
cin >> n >> k;
if(n==0&&k==0)break;
vector<int> s(n);
for(int i=0;i<n;i++){
cin >> s[i];
}
int sum=0;
for(int i=0;i<k;i++){
sum+=s[i];
}
int ans = sum;
for(int i=0;i+k<n;i++){
sum+=s[i+k]-s[i];
if(sum>ans)ans=sum;
}
cout << ans << endl;
}
return 0;
}
``` |
### Prompt
Please formulate a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<cstdio>
using namespace std;
int a[100010];
long long ans,maxx;
int main()
{
int i,n,m;
while(cin>>n>>m&&n!=0&&m!=0)
{
ans=-9999999,maxx=0;
for(i=1;i<=n;i++)
{
cin>>a[i];
if(i<m)maxx+=a[i];
else if(i>=m)
{
maxx+=a[i];
if(maxx>ans)ans=maxx;
maxx-=a[i-m+1];
}
}
cout<<ans<<endl;
}
return 0;
}
``` |
### Prompt
Please provide a Cpp coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<stdio.h>
int main(void){
int n,k,a[100000],i,j,sum,max;
while(1){
scanf("%d %d",&n,&k);
if(n==0)break;
for(i=0;i<n;i++) scanf("%d",&a[i]);
max=-1;
for(i=0;i<n;i++){
sum=0;
if(i+k<n){
for(j=i;j<i+k;j++) sum+=a[j];
}
if(max<sum) max=sum;
}
printf("%d\n",max);
}
return 0;
}
``` |
### Prompt
Construct a java code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
int N,K;
int[] a;
public void solve() {
a = new int[100000+1];
while(true){
N = nextInt();
K = nextInt();
if(N + K == 0)break;
for(int i = 0;i < N;i++){
a[i] = nextInt();
}
int sum = 0;
int ans = Integer.MIN_VALUE;
int left = 0,right = 0;
while(left < N){
while(right < N && right - left < K){
sum += a[right++];
}
if(right-left==K)ans = Math.max(ans, sum);
sum -= a[left++];
}
out.println(ans);
}
}
public static void main(String[] args) {
out.flush();
new Main().solve();
out.close();
}
/* Input */
private static final InputStream in = System.in;
private static final PrintWriter out = new PrintWriter(System.out);
private final byte[] buffer = new byte[2048];
private int p = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (p < buflen)
return true;
p = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0)
return false;
return true;
}
public boolean hasNext() {
while (hasNextByte() && !isPrint(buffer[p])) {
p++;
}
return hasNextByte();
}
private boolean isPrint(int ch) {
if (ch >= '!' && ch <= '~')
return true;
return false;
}
private int nextByte() {
if (!hasNextByte())
return -1;
return buffer[p++];
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = -1;
while (isPrint((b = nextByte()))) {
sb.appendCodePoint(b);
}
return sb.toString();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
``` |
### Prompt
Please provide a Python3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k=map(int,(input().split()))
if n==0 and k==0:
break
a,b,s=[],[],0
for i in range(n):
a.append(int(input()))
if i==k-1:
s=sum(a[0:k])
elif i>=k:
s=s+a[i]-a[i-k]
b.append(s)
print(max(b))
``` |
### Prompt
Please create a solution in Cpp to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int a,b;
while(cin>>a>>b,a){
int c[a],w=0;
r(i,a)cin>>c[i];
r(i,a-b){
int cc=0;
for(int j=i;j<i+b;j++)cc+=c[j];
w=max(w,cc);
}
cout<<w<<endl;
}
}
``` |
### Prompt
Please create a solution in Cpp to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,k;
while(cin>>n>>k){
if(n==0&&k==0)
break;
int a[n];
for(int i = 0;i<n;i++){
cin>>a[i];
}
int sum[n+1];
sum[0] = a[0];
for(int i = 1;i<n;i++){
sum[i] = sum[i-1]+a[i];
}
int ans = sum[k-1];
for(int i = k;i<n;i++){
ans = max(ans,sum[i]-sum[i-k]);
}
cout<<ans<<endl;
}
return 0;
}
``` |
### Prompt
Construct a PYTHON3 code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile
def read(
*shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
def read_word():
w = lambda c: c in whitespaces
nw = lambda c: c not in whitespaces
return f("".join(takewhile(nw, dropwhile(w, it))))
if not shape:
return read_word()
elif len(shape) == 1:
return [read_word() for _ in range(shape[0])]
elif len(shape) == 2:
return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]
def readi(*shape):
return read(*shape)
def readi1(*shape):
return [i - 1 for i in read(*shape)]
def readf(*shape):
return read(*shape, f=float)
def reads(*shape):
return read(*shape, f=str)
def arr(*shape, fill_value=0):
if len(shape) == 1:
return [fill_value] * shape[fill_value]
elif len(shape) == 2:
return [[fill_value] * shape[1] for _ in range(shape[0])]
def dbg(**kwargs):
print(
", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
file=sys.stderr,
)
def main():
while True:
n, k = readi(2)
if n == 0:
return
a = readi(n)
tmp = sum(a[:k])
ans = tmp
for i in range(k, len(a)):
tmp += a[i] - a[i - k]
ans = max(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
``` |
### Prompt
Generate a PYTHON solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python
#!/usr/bin/python
import sys
def readints():
return map(int, sys.stdin.readline().split())
n, k = readints()
while n and k:
data = [readints()[0] for i in range(n)]
window = sum(data[:k])
L = window
for i in range(k, n):
window = window + data[i] - data[i-k]
if window > L:
L = window
print L
n, k = readints()
``` |
### Prompt
Develop a solution in Java to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.Scanner;
//Maximum Sum
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
int n = sc.nextInt();
int k = sc.nextInt();
if(n==0&&k==0)break;
int a[] = new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
int s = 0;
int t = 0;
int tmp = 0;
while(t < k){
tmp += a[t];
t++;
}
int max = tmp;
while(t < n){
tmp -= a[s++];
tmp += a[t++];
max = Math.max(max, tmp);
}
System.out.println(max);
}
}
}
``` |
### Prompt
Create a solution in cpp for the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n, k;
while (cin >> n >> k, n, k) {
int s[114514] = {};
for (int i = 1; i <= n; i++) {
int a; cin >> a;
s[i] = s[i - 1] + a;
}
long long ans = 0;
for (int i = 1; i <= n - k; i++) {
ans = max(ans, (long long)(s[i + k] - s[i]));
}
cout << ans << endl;
}
}
``` |
### Prompt
Your task is to create a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
int k;
int temp;
while(cin>>n>>k,n,k){
vector<int> data;
int max=0;
for(int i=0;i<n;++i){
cin>>temp;
data.push_back(temp);
}
for(int i=0;i<n-k+1;++i){
int total=0;
for(int j=i;j<k+i;++j){
total+=data[j];
}
if(max<total)
max=total;
}
cout<<max<<endl;
}
}
``` |
### Prompt
In JAVA, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
for(;;)
{
int n=in.nextInt(),k=in.nextInt();
int a[]=new int[n];
int pre=0;
if((n|k)==0)
return;
for(int i=0;i<n;i++)
a[i]=in.nextInt();
for(int i=0;i<k;i++)
pre+=a[i];
int max=pre;
for(int i=0;i<n-k;i++)
{
pre=pre-a[i]+a[k+i];
max=Math.max(max, pre);
}
System.out.println(max);
}
}
}
``` |
### Prompt
Your challenge is to write a python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
import itertools
while True:
N, K = map(int, input().split())
if N==K==0:
break
S = [int(input()) for _ in range(N)]
Scum = [0] + list(itertools.accumulate(S))
reg = -10**9
for i in range(N-K+1):
partial_sum = Scum[i+K] - Scum[i]
reg = max(reg, partial_sum)
print(reg)
``` |
### Prompt
In python3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
from itertools import accumulate
while True:
n, k = [int(x) for x in input().split()]
if n == 0 and k == 0:
break
L = []
for _ in range(n):
L.append(int(input()))
M = list(accumulate(L))
S = []
S.append(M[k-1])
for i in range(k,n):
S.append(M[i] - M[i-k])
print(max(S))
``` |
### Prompt
Please formulate a python3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while 1:
n, k = [int(i) for i in input().split()]
if n == 0 and k == 0:
break
a = [int(input()) for i in range(n)]
s = sum(a[0:k])
M = s
for i in range(k, n):
s = s + a[i] - a[i - k]
if s > M:
M = s
print(M)
``` |
### Prompt
Please create a solution in cpp to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long n,k;
while(1) {
long long ans=-1000000000;
cin>>n>>k;
if(n == 0 and k == 0) break;
long long a[n];for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n-k+1;i++){
long long temp=0;
for(int j=i;j<i+k;j++){
temp+=a[j];
}
ans=max(temp,ans);
}
cout<<ans<<endl;
}
}
``` |
### Prompt
Your challenge is to write a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
int kk[100000];
int main(){
while(1){
int s=0;
int n,k;
std::cin>>n>>k;
if(n==0&&k==0)
break;
for(int i=0;i<k;i++){
std::cin>>kk[i];
s+=kk[i];
}
int st=s;
for(int i=k;i<n;i++){
std::cin>>kk[i];
s+=kk[i]-kk[i-k];
if(s>st)
st=s;
}
std::cout<<st<<std::endl;
}
}
``` |
### Prompt
Please create a solution in Java to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-9;
int n, k;
int[] a;
void run(){
for(;;){
n=sc.nextInt();
k=sc.nextInt();
if((n|k)==0){
break;
}
a=new int[n];
for(int i=0; i<n; i++){
a[i]=sc.nextInt();
}
solve();
}
}
void solve(){
int[] sum=new int[n];
sum[0]=a[0];
for(int i=1; i<n; i++){
sum[i]=sum[i-1]+a[i];
}
int max=Integer.MIN_VALUE;
for(int i=0; i+k<n; i++){
max=max(max, sum[i+k-1]-(i>0?sum[i-1]:0));
}
println(max+"");
}
void debug(Object... os){
System.err.println(Arrays.deepToString(os));
}
void print(String s){
System.out.print(s);
}
void println(String s){
System.out.println(s);
}
public static void main(String[] args){
// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
new Main().run();
}
}
``` |
### Prompt
Please formulate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<vector>
int main(){
int n,k;
long long int ans=-1000000000;
while(true){
std::cin>>n>>k;
if(n==0&&k==0)break;
std::vector<long long int>vec(n+1,0);
long long int sub;
for(int i=1;i<=n;i++){
std::cin>>sub;
vec.at(i)=vec.at(i-1)+sub;
}
for(int i=n;i>=k;i--){
ans=std::max(vec.at(i)-vec.at(i-k),ans);
}
std::cout<<ans<<std::endl;
}
return 0;
}
``` |
### Prompt
In python3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np # Pythonのみ!
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components # Pythonのみ!
# ↑cf. https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
while True:
n, m = map(int, input().split())
if [n, m] == [0, 0]:
break
else:
A = [int(input()) for i in range(n)]
B = [0] + A
# 累積和を格納したリスト.A[l:r]の総和はB[r] - B[l]
B = list(accumulate(B))
val = max([B[i + m] - B[i] for i in range(n - m + 1)])
print(val)
resolve()
``` |
### Prompt
Your challenge is to write a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
for x in range (5):
a,k = map(int, input().strip().split())
if a==k==0 : break
lst=[int(input()) for i in range(a)]
s = sum(lst[0:k])
mx = s
for i in range (k,a):
s = s + lst[i] -lst[i-k]
if s > mx :
mx = s
print(mx)
``` |
### Prompt
In cpp, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
int main()
{
int n, m, a[100000], t, s;
while(1){
cin >> n >> m;
if(n == 0 && m == 0){
break;
}
for(int i = 0; i < n; i++){
cin >> a[i];
}
t = s = 0;
for(int i = 0; i < m; i++){
t += a[i];
}
s = t;
for(int i = m; i < n; i++){
t += (a[i] - a[i-m]);
if(s < t){
s = t;
}
}
cout << s << endl;
}
return 0;
}
``` |
### Prompt
Your task is to create a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
while(true) {
int n, k;
vector<int> x;
scanf("%d%d", &n, &k);
if(n == 0)
break;
x.resize(n);
for(int i = 0; i < n; ++i)
scanf("%d", &x[i]);
int cur = 0, ans;
for(int i = 0; i < k; ++i)
cur += x[i];
ans = cur;
for(int i = k; i < n; ++i) {
cur += x[i];
cur -= x[i - k];
ans = max(ans, cur);
}
printf("%d\n", ans);
}
return 0;
}
``` |
### Prompt
Your challenge is to write a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <climits>
int main() {
using namespace std;
int n, k;
while(cin >> n >> k, (n|k)) {
int arr[n]; cin >> arr[0]; for(int i=1; i<n; i++) { cin >> arr[i]; arr[i] += arr[i-1]; }
int res = INT_MIN/4;
for(int i=0; i<n-k; i++) {
res = max(res, arr[i+k]-arr[i]);
}
cout << res << endl;
}
return 0;
}
``` |
### Prompt
Your challenge is to write a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
def main():
while True:
a,b=map(int,input().split())
if a==0 and b==0:
break
l=[]
for i in range(a):
l.append(int(input()))
count=0
for i in range(b):
count+=l[i]
anser=count
for i in range(b,a):
count+=l[i]
count-=l[i-b]
anser=max(anser,count)
print(anser)
if __name__ == '__main__':
main()
``` |
### Prompt
Please create a solution in java to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
int N = sc.nextInt();
int K = sc.nextInt();
if (N == 0) break;
int[] v = new int[N];
for (int i = 0; i < N; ++i) {
v[i] = sc.nextInt();
}
int sum = 0;
for (int i = 0; i < K; ++i) {
sum += v[i];
}
int ans = sum;
for (int i = K; i < N; ++i) {
sum += v[i] - v[i - K];
ans = Math.max(ans, sum);
}
System.out.println(ans);
}
}
}
``` |
### Prompt
Construct a cpp code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,k;
int num[100005];
while(cin >> n >> k && n && k){
for(int i=0;i<n;i++) cin >> num[i];
int ans = 0;
for(int i=0;i<k;i++) ans += num[i];
int sum = ans;
for(int i=1;i<n-k+1;i++){
sum -= num[i-1];
sum += num[i+k-1];
ans = max(ans,sum);
}
cout << ans << endl;
}
}
``` |
### Prompt
Please formulate a cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int n,k;
while(cin >> n >> k , n){
int d[100001] = {0};
for(int i=1;i<=n;i++){
int t;cin >> t;
d[i] = d[i-1] + t;
}
int ans = 0;
for(int i=1;i+k-1<=n;i++){
ans = max(ans,d[i+k-1]-d[i-1]);
}
cout << ans << endl;
}
}
``` |
### Prompt
Please create a solution in Cpp to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin >> n >> k;
while(n!=0 || k!=0){
vector<int> a(n);
for(int i=0;i<n;i++){
cin >> a.at(i);
}
vector<int> s(n);
s.at(0) = 0;
for(int i=1;i<n;i++){
s.at(i) = s.at(i-1)+a.at(i-1);
}
int ans=0;
for(int i=0;i<n-k;i++){
ans = max(s.at(i+k)-s.at(i),ans);
}
cout << ans << endl;
cin >> n >> k;
}
}
``` |
### Prompt
Construct a CPP code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
int main()
{
while(1)
{
int n,k; cin >> n >> k ;
if(n==0 && k==0) break;
int* a=new int[n]; int sum=0; int max=0;
for(int i=0;i<n;i++) cin >> a[i] ;
for(int i=0;i<k;i++) sum+=a[i];
max=sum;
for(int i=k;i<n;i++)
{
sum=sum+a[i]-a[i-k];
if(sum>max) max=sum;
}
cout << max << '\n';
}
}
``` |
### Prompt
Your challenge is to write a java solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```java
import java.util.Scanner;
public class Main {
public static class BIT{
int[] dat;
public BIT(int n){
dat = new int[n + 1];
}
public void add(int k, int a){
for(int i = k + 1; i < dat.length; i += i & -i){
dat[i] += a;
}
}
public int sum(int s, int t){
if(s > 0) return sum(0, t) - sum(0, s);
int ret = 0;
for(int i = t; i > 0; i -= i & -i) {
ret += dat[i];
}
return ret;
}
public int get(int k){
int p = Integer.highestOneBit(dat.length - 1);
for(int q = p; q > 0; q >>= 1, p |= q){
if( p >= dat.length || k < dat[p]) p ^= q;
else k -= dat[p];
}
return p;
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
final int n = sc.nextInt();
final int k = sc.nextInt();
if(n == 0 && k == 0){
break;
}
BIT bit = new BIT(n);
for(int i = 0; i < n; i++){
bit.add(i, sc.nextInt());
}
int max = Integer.MIN_VALUE;
for(int start = 0; start < n - k + 1; start++){
max = Math.max(max, bit.sum(start, start + k));
//System.out.println("[" + start + " " + (start + k) + ") = " + bit.sum(start, start + k));
}
System.out.println(max);
}
}
}
``` |
### Prompt
Please formulate a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n, k;
while (~scanf("%d %d", &n, &k)) {
if ((n|k) == 0)
break;
vector<int> a(n);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i < n; ++i)
a[i] += a[i-1];
int ans = a[k-1];
for (int i = k; i < n; ++i)
ans = max(ans, a[i]-a[i-k]);
printf("%d\n", ans);
}
return 0;
}
``` |
### Prompt
Your task is to create a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
using namespace std;
int a[100002];
int main(void){
int n,k;
while(cin>>n>>k,n){
for(int i=0;i<n;i++) cin>>a[i];
int left=0, right=0, sum=0, ans=-999999999;
while(right<n){
while(right-left<k) sum += a[right++];
ans = max(ans,sum);
sum -= a[left++];
}
cout<<ans<<endl;
}
return 0;
}
``` |
### Prompt
Please provide a python3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
# coding: utf-8
# Your code here!
while True:
n,k=map(int,input().split())
if n==0 and k==0:
break
a=[int(input()) for _ in range(n)]
s=sum(a[0:k])
ss=[s]
for i in range(k,n):
s=s+a[i]-a[i-k]
ss.append(s)
print(max(ss))
``` |
### Prompt
Please create a solution in CPP to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include<iostream>
int main(){
for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))
for(M=1<<31,i=s=0;i<n;s+=a[i],k<++i&&(s-=a[i-k-1])&&M<s&&(M=s))
{
std::cin>>a[i];
}
}
``` |
### Prompt
Your challenge is to write a CPP solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <iostream>
#include <queue>
using namespace std;
int main(){
int n,k,a,s,m;
while(cin>>n>>k,n||k){
a=0;
queue<int> q;
n-=k;
while(k--){
cin>>s;
a+=s;q.push(s);
}
m=a;
while(n--){
cin>>s;
q.push(s);
a=a+s-q.front();
q.pop();
m=max(m,a);
}
cout<<m<<endl;
}
return 0;
}
``` |
### Prompt
Your challenge is to write a Cpp solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```cpp
#include <stdio.h>
int n,k,x[100005],cur,ret;
int main(){
for(;;){
ret=-2000000000;cur=0;
scanf("%d%d",&n,&k);if(!n)return 0;
for(int i=0;i<n;i++){
scanf("%d",&x[i]);
cur+=x[i];
if(i>=k) cur-=x[i-k];
if(i>=k-1&&ret<cur) ret=cur;
}
printf("%d\n",ret);
}
}
``` |
### Prompt
Construct a python3 code solution to the problem outlined:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while True:
n,k = map(int,input().split())
if n == 0:
break
a = [int(input()) for i in range(n)]
s = [0]
for i in range(n):
s.append(a[i]+s[i])
ans = 0
for i in range(len(s) - k):
if ans < s[i + k] - s[i]:
ans = s[i + k] - s[i]
print(ans)
``` |
### Prompt
Please provide a python3 coded solution to the problem described below:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
import sys
def mips():
return map(int,input().split())
def ii():
return int(input())
#AOJ_maximum sum
def procedure():
N,K = mips()
if N == 0:
sys.exit(0)
A = []
res = -(10**100)
for _ in range(N):
a = ii()
A.append(a)
S = [0]
for i in range(N):
s = S[i] + A[i]
S.append(s)
for i in range(N-K):
res = max(res,S[i+K]-S[i])
print(res)
while True:
procedure()
``` |
### Prompt
Your task is to create a PYTHON3 solution to the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
while 1:
n , o = map(int, input().split())
if n == 0 and o == 0:break
else:
k = [0]
for i in range(n):
k.append(k[-1]+int(input()))
m = -float("INF")
for i,l in zip(k,k[o:]):
m = max(m,l-i)
print(m)
``` |
### Prompt
In Python3, your task is to solve the following problem:
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
### Response
```python3
#aとbが0のとき処理を終わる
while True:
a,b = map(int,input().split())
if a == 0 and b == 0:break
#カラリストの作成と変数のリセット
line = []
kei = []
i = 0
#標準入力
for _ in range(a):line.append(int(input()))
#しゃくとり法の最初の数を変数に代入する
for j in range(0,b):i += line[j]
#しゃくとり法の更新
for l in range(b,a):
i += line[l] - line[l - b]
kei.append(i)
#出力
print(max(kei))
``` |
### Prompt
Please provide a Python3 coded solution to the problem described below:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```python3
while True:
name,typ = input().split()
if typ=="X": break
ans = []
if "_" in name:
ans = name.split("_")
else:
j = 0
for i in range(1,len(name)):
if name[i].isupper():
ans.append(name[j:i])
j = i
ans.append(name[j:])
if typ=="D":
ans = map(str.lower, ans)
print(*ans,sep="_")
else:
ans = "".join(map(str.capitalize, ans))
if typ=="L":
ans = ans[0].lower() + ans[1:]
print(ans)
``` |
### Prompt
Construct a cpp code solution to the problem outlined:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```cpp
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
using namespace std;
vector<string> decompose(string s){
vector<string> res;
string tmp;
tmp = s[0];
for(int i=1;i<s.size();i++){
if(isupper(s[i])){
res.push_back(tmp);
tmp = s[i];
}else if(s[i] == '_'){
res.push_back(tmp);
tmp = "";
}else{
tmp += s[i];
}
}
res.push_back(tmp);
return res;
}
string unite(vector<string> v,char c){
string res;
for(int i=0;i<v.size();i++){
if(c == 'D' || (c == 'L' && i==0)){
v[i][0] = tolower(v[i][0]);
}else{
v[i][0] = toupper(v[i][0]);
}
if(c == 'D' && i!=0)res += "_";
res += v[i];
}
return res;
}
int main(){
string s;
char c;
while(cin >> s >> c, c!='X'){
vector<string> v = decompose(s);
cout << unite(v,c) << endl;
}
}
``` |
### Prompt
Please provide a cpp coded solution to the problem described below:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;
typedef ostringstream OSS;
typedef istringstream ISS;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
#define X first
#define Y second
string toUpperCamelCase(string s) {
string res;
for (int i = 0; i < (int)s.size(); i++) {
if (i == 0) {
res += toupper(s[i]);
} else if (s[i] == '_') {
res += toupper(s[i + 1]);
i++;
} else {
res += s[i];
}
}
return res;
}
string toLowerCamelCase(string s) {
string res;
for (int i = 0; i < (int)s.size(); i++) {
if (i == 0) {
res += tolower(s[i]);
} else if (s[i] == '_') {
res += toupper(s[i + 1]);
i++;
} else {
res += s[i];
}
}
return res;
}
string toSnakeCase(string s) {
string res;
for (int i = 0; i < (int)s.size(); i++) {
if (i == 0) {
res += tolower(s[i]);
} else if (isupper(s[i])) {
res += '_';
res += tolower(s[i]);
} else {
res += s[i];
}
}
return res;
}
int main(void) {
string s;
char c;
while (true) {
cin >> s >> c;
if (c == 'X') break;
switch (c) {
case 'L':
s = toLowerCamelCase(s);
break;
case 'U':
s = toUpperCamelCase(s);
break;
case 'D':
s = toSnakeCase(s);
break;
}
cout << s << endl;
}
return 0;
}
``` |
### Prompt
Please formulate a Java solution to the following problem:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String var;
String type;
while (true) {
var = sc.next();
type = sc.next();
if (type.equals("X")) {
break;
}
int n = 0;
for (int i = 0; i < var.length(); i++) {
if (var.charAt(i) == '_') {
n = 3;
}
}
if (n != 3) {
if ('A' <= var.charAt(0) && var.charAt(0) <= 'Z') {
n = 1;
} else if ('a' <= var.charAt(0) && var.charAt(0) <= 'z') {
n = 2;
}
}
if (type.equals("U")) {
if (n == 1) {
} else if (n == 2) {
String v = var.substring(0, 1);
v = v.toUpperCase();
var = v + var.substring(1);
} else {
String v = var.substring(0, 1);
v = v.toUpperCase();
var = v + var.substring(1);
for (int i = 0; i < var.length(); i++) {
if (var.charAt(i) == '_') {
v = var.substring(i + 1, i + 2);
v = v.toUpperCase();
var = var.substring(0, i) + v + var.substring(i + 2);
i--;
}
}
}
} else if (type.equals("L")) {
if (n == 1) {
String v = var.substring(0, 1);
v = v.toLowerCase();
var = v + var.substring(1);
} else if (n == 2) {
} else {
for (int i = 0; i < var.length(); i++) {
if (var.charAt(i) == '_') {
String v = var.substring(i + 1, i + 2);
v = v.toUpperCase();
var = var.substring(0, i) + v + var.substring(i + 2);
i--;
}
}
}
} else if (type.equals("D")) {
if (n == 1) {
String v = var.substring(0, 1);
v = v.toLowerCase();
var = v + var.substring(1);
for (int i = 0; i < var.length(); i++) {
if ('A' <= var.charAt(i) && var.charAt(i) <= 'Z') {
v = var.substring(i, i + 1);
v = v.toLowerCase();
var = var.substring(0, i) + '_' + v + var.substring(i + 1);
}
}
} else if (n == 2) {
for (int i = 0; i < var.length(); i++) {
if ('A' <= var.charAt(i) && var.charAt(i) <= 'Z') {
String v = var.substring(i, i + 1);
v = v.toLowerCase();
var = var.substring(0, i) + '_' + v + var.substring(i + 1);
}
}
} else {
}
}
System.out.println(var);
}
}
}
``` |
### Prompt
Generate a Python3 solution to the following problem:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```python3
# coding: utf-8
# Your code here!
import re
while True:
name,type = input().split()
if type == "X":
break
if "_" in name:
X = name.split("_")
else:
tmp = name.upper()
name = tmp[0]+name[1:]
X = re.findall('[A-Z][^A-Z]*',name)
if type == "U":
for i in range(len(X)):
X[i] = X[i].capitalize()
elif type == "L":
X[0] = X[0].lower()
for i in range(1,len(X)):
X[i] = X[i].capitalize()
else:
X[0] = X[0].lower()
for i in range(1,len(X)):
X[i] = "_"+X[i].lower()
print("".join(X))
``` |
### Prompt
Please formulate a Java solution to the following problem:
When naming identifiers (variables and functions) in programming, compound words that concatenate words are used. However, if you concatenate them as they are, you will not be able to understand the word breaks, so in general, select and apply the one that is unified from the following naming conventions:
* Set to Upper CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word.
Example: GetUserName
* Set to Lower CamelCase
Connect words directly to form a compound word, and capitalize only the first letter of each word. However, the first letter of the compound word should be lowercase.
Example: getUserName
* Connect with underscore
Words are concatenated with underscores to form a compound word. Make all letters of the word lowercase.
Example: get_user_name
Create a program that outputs the given identifier by applying the specified naming convention. It is assumed that any of the above naming conventions has already been applied to the identifier given.
Input
Multiple datasets are given as input. Each dataset is given in the following format:
name type (identifier, naming convention: space-separated strings and characters)
type is a character indicating the naming convention and is as shown in the table below:
type | Naming convention
--- | ---
U | Upper CamelCase
L | Lower CamelCase
D | Connect with underscore
The number of characters in the given identifier is 1 or more and 100 or less.
End of input when type is'X'. Do not output to this input.
Output
For each dataset, print the identifier with the naming convention on one line.
Example
Input
get_user_name L
getUserName U
GetUserName D
EndOfInput X
Output
getUserName
GetUserName
get_user_name
### Response
```java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
String s = sc.next();
char type = sc.next().charAt(0);
if (type == 'X') {
break;
}
String[] words;
if (s.indexOf('_') > -1) {
words = s.split("_");
}
else {
int start = 0;
List<String> wordsTemp = new ArrayList<String>();
for (int i = 1; i < s.length(); i++) {
if (Character.isUpperCase(s.charAt(i))) {
wordsTemp.add(s.substring(start, i));
start = i;
}
}
wordsTemp.add(s.substring(start));
words = wordsTemp.toArray(new String[wordsTemp.size()]);
}
StringBuilder sb = new StringBuilder(s.length() + words.length);
if (type == 'D') {
sb.append(words[0].toLowerCase());
for (int i = 1; i < words.length; i++) {
sb.append('_').append(words[i].toLowerCase());
}
}
else {
if (type == 'L') {
sb.append(words[0].toLowerCase());
}
for (int i = (type == 'L' ? 1 : 0); i < words.length; i++) {
sb.append(Character.toUpperCase(words[i].charAt(0)));
if (words[i].length() > 1)
sb.append(words[i].substring(1));
}
}
System.out.println(sb);
}
}
}
``` |