This morning, Roman woke up and opened the browser with $$$n$$$ opened tabs numbered from $$$1$$$ to $$$n$$$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.He decided to accomplish this by closing every $$$k$$$-th ($$$2 \leq k \leq n - 1$$$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $$$b$$$) and then close all tabs with numbers $$$c = b + i \cdot k$$$ that satisfy the following condition: $$$1 \leq c \leq n$$$ and $$$i$$$ is an integer (it may be positive, negative or zero).For example, if $$$k = 3$$$, $$$n = 14$$$ and Roman chooses $$$b = 8$$$, then he will close tabs with numbers $$$2$$$, $$$5$$$, $$$8$$$, $$$11$$$ and $$$14$$$.After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $$$e$$$) and the amount of remaining social network tabs ($$$s$$$). Help Roman to calculate the maximal absolute value of the difference of those values $$$|e - s|$$$ so that it would be easy to decide what to do next.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq k < n \leq 100$$$) — the amount of tabs opened currently and the distance between the tabs closed. The second line consists of $$$n$$$ integers, each of them equal either to $$$1$$$ or to $$$-1$$$. The $$$i$$$-th integer denotes the type of the $$$i$$$-th tab: if it is equal to $$$1$$$, this tab contains information for the test, and if it is equal to $$$-1$$$, it's a social network tab.

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $$$|e - s|$$$.

NoteIn the first example we can choose $$$b = 1$$$ or $$$b = 3$$$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $$$e = 2$$$ and $$$s = 0$$$ and $$$|e - s| = 2$$$.In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

#include<stdio.h>
#include<math.h>
int main()
{
	int n,q=0,w=0,c;
	int k;
	int a[10000];
	int b[10000],max=-999999;
	scanf("%d %d",&n,&k);
	if(n==1)
	{
		scanf("%d",&c);

		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int b=1;b<=n;b++)
	{	q=0;w=0;
		for(int j=1;j<=n;j++)
		{
			if((j-b)%k==0)

			{continue;

			}
			if(a[j]==1)
			w++;
			else
			q--;
		}
		if(abs(q+w)>max)
		max=abs(q+w);

	}

	printf("%d",max);

	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,q=0,w=0,c;
	int k;
	int a[10000];
	int b[10000],max=-999999;
	scanf("%d %d",&n,&k);
	if(n==1)
	{
		scanf("%d",&c);

		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int b=1;b<=n;b++)
	{	q=0;w=0;
		for(int j=1;j<=n;j++)
		{
			if((j-b)%k==0)

			{continue;

			}
			if(a[j]==1)
			w++;
			else
			q++;
		}
		if(abs(w-q)>max)
		max=abs(w-q);

	}

	printf("%d",max);

	return 0;
}

#include <stdio.h>
int main(void)
{
	int n,k;
	scanf("%d %d",&n,&k);
	int c=0;
	int d=0;
	int ct=0;
	int dt=0;

	int a[n];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1) c++;
		else d++;
	}
	int max=0;
	for (int i = 0; i < k; ++i)
	{
		ct=c;
		dt=d;
		for (int j = i; j < n; j+=k)
		{
			if(a[j]==1)
			{
				ct--;
			}
			else
			{
				dt--;
			}
		}
		if(ct-dt>max)
		{
			max=ct-dt;
		}
		else if(dt-ct>max)
		{
			max=dt-ct;
		}
	}
	printf("%d\n",max );
}

#include<stdio.h>

  int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int ar[n];
    for(int i=0;i<n;i++)
      scanf("%d",ar+i);
    int max=0;
    for(int i=1,a=0,j;i<=n;i++){
      a=0;
      for(j=0;j<n;j++){
        if((j+1-i)%k==0)
          continue;
        if(ar[j]==1)a++;
        else a--;
      }
      if(a<0)a=-a;
      max=max>=a?max:a;
    }
    printf("%d\n",max);
    return 0;
  }

#include <stdio.h>
#include<stdlib.h>
#include<math.h>

int main() {
	int n, k, i, j, e=0, s=0, max, e_cpy, s_cpy;
	int* ptr;
	scanf("%d %d", &n, &k);
	ptr=(int*)malloc(n*sizeof(int));
	for(i=0;i<n;i++){
        scanf("%d", &ptr[i]);
        if(ptr[i]==1) e++;
        else s++;
	}
	max=0;
	for(i=0;i<k;i++){
        e_cpy=e; s_cpy=s;
        for(j=0;i+j*k<n;j++){
            if(ptr[i+j*k]==1)e_cpy--;
            else s_cpy--;
        }
        if(abs(e_cpy-s_cpy)>max) max=abs(e_cpy-s_cpy);
	}
    printf("%d", max);

	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    int n,k,i,j,plus,neg,one=0,two=0,total,count,final=0;
    scanf("%d %d",&n,&k);
    int a[n];
    for(i=0;i<n;i++)
    {
    scanf("%d",a+i);
    if(a[i]==1)
    one++;
    else
    two++;
    }
    for(i=0;i<n;i++)
    {
        j=0;
        count=i;
        plus=0;
        neg=0;
        total=count-j*k;
        while(total>=0)
        {
            j++;
            if(a[total]==1)
            plus++;
            else
            neg++;
            total=count-j*k;
        }
        j=1;
        total=count+j*k;
        while(total<n)
        {
            j++;
            if(a[total]==1)
            plus++;
            else
            neg++;
            total=count+j*k;
        }
        final=max(final,abs((one-plus)-(two-neg)));
    }
    printf("%d",final);
    return 0;
}

#include<stdio.h>
#include<string.h>
int absolute(int a, int b){
	return a > b ? a-b : b-a;
}

int main(){
	int n,k,i,j;
	scanf("%d%d",&n,&k);
	int a[n];
	int te = 0,ts = 0;

	int b[k][2];
	for(i = 0;i < k;i++){
		b[i][0] = 0;
		b[i][1] = 0;
	}

	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
		if(a[i] == 1){
			te++;
			b[i%k][0]++;
		}
		else{
			ts++;
			b[i%k][1]++;
		}
	}

	int max = 0;
	for(i = 0;i < k;i++){
		int temp = absolute(te - b[i][0],ts - b[i][1]);
		if(temp > max){
			max = temp;
		}
	}
	printf("%d\n",max);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int i,n,k,e=0,s=0,a,b,j,max=0;
    scanf("%d %d",&n,&k);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==1)e++;
        else s++;
    }
    for(i=0;i<k;i++)
    {
        a=e;
        b=s;
        for(j=i;j<n;j+=k)
        {
            if(arr[j]==1)a--;
            else b--;
        }
        if(abs(a-b)>max)max=abs(a-b);
    }
    printf("%d",max);
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
        int n,k;
        scanf("%d %d",&n,&k);

        int a[n+1];
        for(int i=1;i<n+1;i++)
            scanf("%d",&a[i]);

        int a1=0,a2=0;
        for(int i=1;i<n+1;i++)
        {
            if(a[i]==1)
            {
                a1++;
            }
            else
            {
                a2++;
            }
        }
        int max=0;
        for(int i=1;i<n+1;i++)
        {

            int e=a1,s=a2;
            int index=i;
            for(int j=i;j<n+1;j=j+k)
            {
                if(a[j]==1)
                {
                    e--;
                }
                else
                {
                    s--;
                }
            }
            for(int j=i-k;j>0;j=j-k)
            {
                if(a[j]==1)
                {
                    e--;
                }
                else
                {
                    s--;
                }
            }

            if(abs(e-s)>max)
                max=abs(e-s);
        }
        printf("%d",max);
}

#include<stdio.h>
#include<math.h>
int main(void)
{
	int n, k;
	scanf("%d%d",&n,&k);
	int arr[110];
	int ctre=0;
	int ctrs=0;
	for(int q=0;q<n;q++)
	{
		scanf("%d",&arr[q]);
		if(arr[q]==-1)
			ctrs++;
		else ctre++;

	}
	int ans=0;
//printf("ctre:%d	ctrs:%d\n",ctre,ctrs);

	for(int w=0;w<n;w++)
	{
		int ce=ctre;
		int cs=ctrs;
		int ptr=w;
		while(ptr<n)
		{
			if(arr[ptr]==1)
				ce--;
			if(arr[ptr]==-1)
				cs--;
//printf("ptr:%d\n",ptr);
	ptr+=k;
//printf("ctre:%d		ctrs:%d\n",ce,cs);

		}
		ptr=w-k;
		while(ptr>=0)
		{
                       if(ptr>=0)
{
			if(arr[ptr]==1)
				ce--;
			if(arr[ptr]==-1)
				cs--;
			ptr-=k;
}
//printf("here\n");
//printf("ptr:%d\n",ptr);            //     ptr+=k;
//printf("ctre:%d         ctrs:%d\n",ce,cs);

		}
//		printf("w:%d\n",w);
//		printf("fabs(cs-ce):%lf\n",fabs(cs-ce));

		if(fabs(cs-ce)>ans)
			ans=fabs(cs-ce);

	}
	printf("%d",ans);
}

#include <stdio.h>
#include <math.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int arr[n];
    for(int i = 0;i<n; i++)
        scanf("%d",&arr[i]);
    //int e,s;
    int ans=0;
    for(int i = 0; i < k; i++)
    {
        int e=0,s=0;
        int temp[n];
        for(int j=0;j<n;j++)
            temp[j]=arr[j];
        for(int j = i; j < n;)
        {
            temp[j]=0;
            j+=k;
        }
        for(int j = 0; j < n; j++)
        {
            if(temp[j]==1)
                e++;
            else if(temp[j]==-1)
                s++;
        }
        if(fabs(e-s)>=ans)
            ans=fabs(e-s);
    }
    printf("%d",ans);
    return 0;
}

#include <stdio.h>
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int a[n];
	for (int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int b[n];
	for (int i=0;i<n;i++)
		b[i]=a[i];
	int max=0;
	for (int i=0;i<n;i++)
	{
		int sum=0;
	   for (int j=i;j<n;j+=k)
		b[j]=0;
	for (int j=i;j>=0;j-=k)
		b[j]=0;
	for (int i=0;i<n;i++)
		sum+=b[i];
	if (sum>max)
		max=sum;
	else if (sum<0 && (sum*(-1))>max)
        max=sum*(-1);
    for (int i=0;i<n;i++)
    	b[i]=a[i];
	}
	printf("%d\n",max);

	return 0;
}

#include<stdio.h>
int A[1000],A1[1000];
int main() {
	int n, k, i, j, t, p, max = 0;
	int plus = 0, minus = 0;
	scanf("%d %d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &A[i]);
	for (i = 0; i < k; i++) {
		for (j = 0; j < n; j++)
			A1[j] = A[j];
		for (j = i; j < n; j += k)
			A1[j] = 0;
		plus = 0;
		minus = 0;
		for (j = 0; j < n; j++) {
			if (A1[j] == 1)
				plus++;
			else if (A1[j] == -1)
				minus++;
		}
		if(plus>minus)
            p=plus-minus;
        else
            p=minus-plus;
		if (max < p)
			max = p;
	}
	printf("%d", max);

	return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
int main ()
{
    int n,k;
    int i,j;
    int a[100010];
    scanf("%d%d",&n,&k);
    int zheng,fu;
    zheng=fu=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>0)zheng++;
        else fu++;
    }
    int x=zheng;
    int xx=fu;
    int max=0;
    for(i=1;i<=k;i++)
    {
        zheng=x;
        fu=xx;
        for(j=i;j<=n;j+=k)
        {
            if(a[j]>0)zheng--;
            else fu--;
        }
        if(abs(zheng-fu)>max)max=abs(zheng-fu);
    }
    printf("%d",max);
}

#include<stdio.h>
#include <stdlib.h>

int max(int, int);

int main(){
  int n, k, i, ans;
  scanf("%d %d", &n, &k);
  int array[n - 1];

  for (i = 0; i < n; i++){
    scanf("%d", &array[i]);
  }

  ans = 0;
  for (i = 0; i < k; i++){
    int array_2[n - 1], j;
    // Make a copy of array in array_2
    for (j = 0; j < n; j++){
      array_2[j] = array[j];
    }
    // Mark tabs 0 which are to be skipped
    for (j = i; j < n; j = j + k){
      array_2[j] = 99999;
    }

    int count1 = 0, count2 = 0, q;
    // Get count 1
    for (q = 0; q < n; q++){
      if (array_2[q] == 1)
        count1++;
    }
    // Get count 2
    for (q = 0; q < n; q++){
      if (array_2[q] == -1)
        count2++;
    }
    ans = max(ans, abs(count1 - count2));
  }
  printf("%d\n", ans);

  return 0;
}

int max(int num1, int num2){
  if (num1 > num2)
    return num1;
  else
    return num2;
}

#include <stdio.h>
#include <math.h>

int n,k;
int dem[101];
int main()
{
	int web,i;
	scanf("%d%d",&n,&k);
	for(i=1 ; i<=n ; i++)
	{
		scanf("%d",&web);
		dem[i%k]+=web;
		dem[k]+=web;
	}

	int kq=0;
	for(i=0 ; i<k ; i++)
	{
		dem[i]=abs(dem[k]-dem[i]);
		kq=kq>dem[i]?kq:dem[i];
	}

	printf("%d",kq);
	return 0;
}

#include<stdio.h>
int main(){
   int n , k , j , e = 0 , s=0  , num = 0 , sum , max = 0  ;
   scanf("%d %d",&n , &k) ;
   int i , a[n]   ;
   for(i=0 ; i<=n ; i++){
       scanf(" %d", &a[i])   ;
      // sum += a[i]  ;
   }
for(j=0 ; j<n ; j++){
    e = 0 ;
    s = 0 ;
    for(i=0 ; i<n ; i++){
        int x = j-i ;
        if(x<0) x = -x ;
        if((i==j)||(x%k==0)) continue ;
        else{
            if(a[i]==1) e++ ;
            else s++ ;
        }
    }
   sum = e-s ;
   if(sum<0) sum = -sum ;
   if(max<sum) max = sum ;
}
   printf("%d",max) ;
    return 0 ;
}

#include<stdio.h>
#include<stdlib.h>

int B[3];

int main(void)
{
int n,k,j,A[101],i,count_1,count1,max=-1;

scanf("%d%d",&n,&k);
for(i=1; i<=n; i++)
{
scanf("%d",&A[i]);
B[A[i]+1]++;
}

for(i=1; i<=k; i++)
{
 count_1=B[0];
 count1=B[2];

for(j=i; j<=n; j+=k)
{
    if(A[j]==-1)
     count_1--;
    else
     count1--;
}

if(abs(count_1-count1)>max)
max=abs(count_1-count1);
}

printf("%d",max);
return 0;
}

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

typedef unsigned long long ll;
typedef long double LD;

#define MAXN 100

#define MAX(a,b) (a>b?a:b)

int arr[MAXN];
int arrcpy[MAXN];

int main(void)
{
    int N,K;
    int i,j;
    int B;
    int socialtab,infotab;
    int diff,maxdiff;

	#ifndef ONLINE_JUDGE
    FILE *fp;
	//fp = freopen("..\\..\\1047\\C\\1047C.TXT","r",stdin);
	fp = freopen("1100A.TXT","r",stdin);
	if (fp == NULL)
    {
        printf ("Cannot open file\n\n");
        exit(0);
    }
	#endif

    maxdiff = 0;

    scanf("%d%d",&N,&K);

    for (i=0; i<N; i++)
    {
        scanf("%d",&arr[i]);
    }

    // check for b=0 to k-1
    for (B=0; B<K; B++)
    {
        memcpy(arrcpy, arr, sizeof(arr[0]) *N);

        for (j=B; j<N; j+=K)
        {
            arrcpy[j] = 0;
        }

        // compute ans
        socialtab = 0;
        infotab = 0;
        for (j=0; j<N; j++)
        {
            if (arrcpy[j] == -1)
            {
                socialtab++;
            }
            else if (arrcpy[j] == 1)
            {
                infotab++;
            }
        }
        diff = abs(socialtab - infotab);

        maxdiff = MAX(maxdiff,diff);
    }

    printf ("%d",maxdiff);

    return 0;

}

#include <stdio.h>

int n,k;
int A[110],B[110];
int ab(int a){
    if(a>0)return a;
    return -a;
}
int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d %d",&n,&k);
    int i,j;
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
    }
    int mx=0,ans=0,info=0,snt=0;
    for(i=1;i<=k;i++){
        info=0,snt=0;
        for(j=1;j<=n;j++)B[j]=A[j];
        for(j=i;j<=n;j+=k){B[j]=0;}
        for(j=1;j<=n;j++){
            if(B[j]>0)info++;
            if(B[j]<0)snt++;
        }
        ans=ab(info-snt);
        //printf("%d: %d %d %d\n",i,ans,info,snt);
        if(ans>mx){
            mx=ans;
        }
    }
    printf("%d",mx);
}

#include<stdio.h>
#include<math.h>
int main(void)
{
	// your code goes here
	int n,k,i,j,l,e,s,max=-1;
	scanf("%d %d",&n,&k);
	int a[n],b[n];
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a[i]);
	    b[i]=a[i];
	}
	for(i=0;i<k;i++)
	{
	    j=i;
	    e=0;
	    s=0;
	    while(j<=n-1)
	    {
	        b[j]=0;
	        j=j+k;
	    }
	    for(l=0;l<n;l++)
	    {
	        if(b[l]==1)
	          e++;
	        else if(b[l]==-1)
	          s++;
	        b[l]=a[l];
	    }
	    if(max<abs(e-s))
	       max=abs(e-s);
	}
	printf("%d",max);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(){
  int n, k;
  int a[100];
  int A = 0, B = 0;
  int ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++){
    A = B = 0;
    for (int j = i; j < n; j += k) a[j] += 3;
    for (int j = i - k; j >= 0; j -= k) a[j] += 3;
    for (int j = 0; j < n; j++) A += a[j] == 1, B += a[j] == -1;
    if (abs(A - B) > ans) ans = abs(A - B);
    for (int j = 0; j < n; j++) a[j] -= 3 * (a[j] == 2 || a[j] == 4);
  }
  printf("%d", ans);
  return 0;
}

#include<stdio.h>
#include<math.h>
int Max(int a,int b);
int a[110];
int main(void)
{
    int n,k,max = 0;
    int c=0,d=0;
    int e = 0,s = 0;
    scanf("%d%d",&n,&k);
    for (int i = 1;i<=n;i++){
        scanf("%d",&a[i]);
        if (a[i] == 1) e++;
        else s++;
    }
    for (int i = 1;i<=k;i++){
    	c = d = 0;
        for (int j = i;j <= n;j += k){
            if(a[j] == 1) c++;
            else d++;
        }
        max = Max(max,fabs((e-c)-(s-d)));
    }
    printf("%d\n",max);

    return 0;
}
int Max(int a,int b)
{
	return a>=b?a:b;
}

#include <stdio.h>
#include<math.h>
int n, k, a[105], i,key;
int cul(int key)
{
	int e = 0, s = 0;
	for (i = 1; i <= n; i++)
	{
		if (i%k == key)continue;
		else if (a[i] == 1)s++;
		else e++;
	}
	return abs(e - s);
}
int main()
{
	int max = 0;
	scanf("%d %d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (key = 0; key < k; key++)
		if (cul(key) > max)max = cul(key);
	printf("%d", max);
}

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n,k,i,j,l,o;
	int tab[100]={};
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<n;i++)
		scanf("%d",&tab[i]);
	int max=0;
	for(i=0;i<k;i++)
	{
		o=0;
		for(j=0;j<n;j++)
		{
			if(j%k-i!=0)
				o+=tab[j];
		}
		//printf("%d-",o);
		if(o>max)
			max=o;
		else if(-o>max)
			max=-o;
	}
	printf("%d\n",max);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

#define N 100

int main() {
	static int aa[N];
	int n, k, i, sum, max;

	scanf("%d%d", &n, &k);
	sum = 0;
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		aa[i % k] += a;
		sum += a;
	}
	max = 0;
	for (i = 0; i < k; i++)
		if (max < abs(sum - aa[i]))
			max = abs(sum - aa[i]);
	printf("%d\n", max);
	return 0;
}

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

int arr[110];

int main()
{
    int i,j,num,gap,e,s,p,ans,tem;
    scanf("%d%d",&num,&gap);
    for (i=0;i<num;i++)
        scanf("%d",&arr[i]);
    for (j=0,ans=0,tem=0;j<gap;j++)
    {
        for (i=0,e=0,s=0,p=j;i<num;i++)
        {
            if (i!=p)
            {
                if (arr[i]==1)
                    e++;
                else
                    s++;
            }
            else
                p+=gap;
        }
        tem=abs(e-s);
        ans=ans>tem?ans:tem;
    }
    printf("%d\n",ans);
	return 0;
}

#include <stdio.h>

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);

    int a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    int st=0,maxdiff=0;
    for(int i=0;i<n;i++){
        st=i;
        while (st>=0) st-=k;
        st+=k;
        for(int j=st;j<n;j+=k){
            b[j]=0;
        }
        int ij=0,s=0;
        for(int j=0;j<n;j++){
            if(b[j]==-1) s++;
            if(b[j]==1) ij++;
        }
       // printf("%d %d\n",s,ij);
        //for(int q=0;q<n;q++)printf("%d ",b[q]);printf("\n");
        if(s-ij>maxdiff)maxdiff=s-ij;
        else if(ij-s>maxdiff)maxdiff=ij-s;
        for(int l=0;l<n;l++)
            b[l]=a[l];
    }
    printf("%d\n",maxdiff);
}

#include<stdio.h>
int main(){
	int k, n;
	int type[100];
	scanf("%d %d",&n,&k);
	for(int i=0; i<n; i++){
		scanf("%d",&type[i]);
	}
	int max=0;
	for(int i=0; i<k; i++){
		int cnt=0;
		for(int j=0; j<n; j++){
			if(j%k != i) {
				cnt+=type[j];
			}

		}
		if(cnt<0) cnt=-cnt;
		if(max<cnt) max=cnt;
	}
	printf("%d\n",max);
}

#include<stdio.h>
int main()
{
	int k, n;
	int type[100];
	scanf("%d %d",&n,&k);
	for(int i=0; i<n; i++)
	{
		scanf("%d",&type[i]);
	}
	int max=0;
	for(int i=0; i<k; i++)
	{
		int cnt=0;
		for(int j=0; j<n; j++)
		{
			if(j%k != i)
			{
				cnt+=type[j];
			}

		}
		if(cnt<0)
		    cnt=-cnt;
		if(max<cnt)
		    max=cnt;
	}
	printf("%d\n",max);
}

#include <stdio.h>

int main(int argc, char *argv[])
{
    int n, k;
    scanf("%d %d", &n, &k);

    int a[100];
    int i;
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);

    int max = 0;
    int b;
    for (b = 0; b < k; b++) {
        int a_[100];
        for (i = 0; i < n; i++)
            a_[i] = a[i];

        int c;
        for (c = b; c < n; c += k)
            a_[c] = 0;

        int max_cur = 0;
        for (i = 0; i < n; i++)
            max_cur += a_[i];

        if (max_cur < 0)
            max_cur = -max_cur;

        if (max_cur > max)
            max = max_cur;
    }

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

    return 0;
}

#include<stdio.h>
#include <stdlib.h>
int main()
{
	long long int n, k;
	scanf("%lld%lld", &n, &k);
	int s[n];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &s[i]);
	}
	int max=0;
	for (int i = 0; i < n; ++i)
	{
		int cnt1=0, cnt2=0, temp[n];

		for(int j=0; j<n; j++)
		{
				temp[j]=s[j];
		}
		for(int j=i; j>=0; j-=k)
		{
				temp[j]=0;
		}
		for(int j=i; j<n; j+=k)
		{
			temp[j]=0;
		}
		for(int j=0; j<n; j++)
		{
			if(temp[j]==1)
				cnt1++;
			else if(temp[j]==-1)
				cnt2++;
		}
	//	printf("%d %d\n",cnt1, cnt2 );
		if(abs(cnt1-cnt2)>max)
			max=abs(cnt1-cnt2);
	}
	printf("%d\n", max);

}

#include <stdio.h>
#include <math.h>

int main()
{
	int i,j,n,m;
	int a,b,s,x,y;
	scanf("%d %d",&n,&m);
	int ar[n];
	x=y=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&ar[i]);
		if(ar[i]>0)x++;
		else y++;
	}
	s=0;
	for(i=0;i<m;i++)
	{
		a=x; b=y;
		for(j=i;j<n;j+=m)
		{
			if(ar[j]>0)a--;
			else b--;
		}
		if(abs(a-b)>s)s=abs(a-b);
	}
	printf("%d\n", s);
	return 0;
}

#include <stdio.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int a[n],i,j,max=0,e=0,s=0;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<k;i++)
    {
        e=0;
        s=0;
        for(j=0;j<n;j++)
        {
            if((j-i)%k!=0)
            {
                if(a[j]==1)
                    e++;
                else
                    s++;
            }
        }
        if(e-s>max)
            max=e-s;
        if(s-e>max)
            max=s-e;
    }
    printf("%d",max);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *cnt = (i32 *) calloc (k, sizeof (i32));
  i32 sum = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a = read_int();
    cnt[i % k] += a;
    sum += a;
  }
  i32 max = 0;
  for (i32 i = 0; i < k; ++i) {
    max = MAX(max, ABS(sum - cnt[i]));
  }
  print_int (max);
  puts("");
}

int main (void) {
  run ();
  return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, k;
    int A[100];
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
    }
    int ans = 0;
    for(int i = 0; i < k; ++i) {
        int e = 0;
        int s = 0;
        for(int j = 0; j < n; ++j) {
            if((j - i + n) % k != 0) {
                if(A[j] == 1) {
                    ++e;
                } else {
                    ++s;
                }
            }
        }
        if(ans < abs(e - s)) {
            ans = abs(e - s);
        }
    }
    printf("%d", ans);
    return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
    static int a[101], t, n, k, sum, max ,i;
    scanf("%d%d", &n, &k);
    for(i=0; i<n; i++)
    {
        scanf("%d",&t);
        a[i%k] += t;
        sum += t;
    }
    for(i=0; i<k; i++)
    {
        if(max < abs(sum-a[i]))
            max = abs(sum-a[i]);
    }
    printf("%d\n", max);
    return 0;
}

#include<stdio.h>
//删掉最多的社交，或者删掉最多的测试
#define N 102
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int i;
    int tab[N];
    char close[N];
    for(i=1;i<=n;i++){
        scanf("%d",&tab[i]);
    }
    int j;
    int answer=0;
    for(i=0;i<k;i++){
        for(j=1;j<=n;j++){
            close[j]=0;
        }
        for(j=1+i;j<=n;j+=k){
            close[j]=1;
        }
        int e=0;
        int s=0;
        for(j=1;j<=n;j++){
            if(!close[j]){
                if(tab[j]==1){
                    e++;
                }else{
                    s++;
                }
            }
        }
        if(e>s){
            if(answer<e-s){
                answer=e-s;
            }
        }else{
            if(answer<s-e){
                answer=s-e;
            }
        }
    }
    printf("%d\n",answer);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF){
		int arr[n],i,a[k],b[k],max=-1e9,suma=0,sumb=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=0;i<n;i++){
			scanf("%d",&arr[i]);
			if(arr[i]==1)
				suma++ ;
			else
				sumb++;
		}
		for(i=0;i<n;i++){
			if(arr[i]==1){
				a[i%k]++;
			}
			else{
				b[i%k]++;
			}
		}
		for(i=0;i<k;i++){
			if(abs(abs(suma-a[i])-abs(sumb-b[i]))>max)
				max=abs(abs(suma-a[i])-abs(sumb-b[i]));
		}
		printf("%d\n",max);
	}
}

#include<stdio.h>
int a[100];
int main(){
       int n,k,i,j,max=0;
       scanf("%d%d",&n,&k);
       for(i=0;i<n;i++)
              scanf("%d",&a[i]);
       for(i=0;i<k;i++){
              int c=0;
              for(j=0;j<n;j++){
                     if(j%k!=i)    c+=a[j];
              }
              if(c<0)       c=-c;
              if(max<c)     max=c;
       }
       printf("%d",max);
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define SIZE 100
int main() {
	int n, a[100], k, i, j, e = 0, s = 0, et = 0, st = 0, max = 0;

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

	for (i = 0; i < n; i++) {
		scanf ("%d", &a[i]);
		if (a[i] == 1)
			e++;
		else
			s++;
	}

	for (i = 0; i < k; i++) {
		et = 0;
		st = 0;
		for (j = i; j < n; j += k)
			if (a[j] == 1)
				et++;
			else
				st++;

		if ((int) abs ((int) ((e - et) - (s - st))) > max)
			max = (int) abs ((int) ((e - et) - (s - st)));
	}

	printf ("%d", max);

	return 0;
}

#include <stdio.h>
void read(int *arr, int length) {
    for (int i=0; i<length; i++) scanf("%d",(arr+i));
}
int diff(int *arr, int length, int init, int b) {
    int test=0,social=0;
    for (int i=0; i<length; i++) {
        if (i%init!=b%init) {
            if (*(arr+i)==1) {
                test++;
            } else {
                social++;
            }
        }
    }
    return abs(test-social);
}
int maxim(int *arr, int length, int k) {
    int res=0,comp;
    for (int i=0; i<length; i++) {
        comp=diff(arr,length,k,i);
        if (res<comp) res=comp;
    }
    return res;
}
int main() {
    int len,tab;
    scanf("%d %d\n",&len,&tab);
    int browse[len];
    read(browse,len);
    printf("%d",maxim(browse,len,tab));
    return 0;
}

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

#define N 200

int a[N], t[N];

int abs(int n) {
    return n < 0 ? -n : n;
}

int max(int x, int y) {
    return x > y ? x : y;
}

int func(int b, int k, int n) {
    int i, cnt = 0;
    for (i = 1; i <= n; i++)
        t[i] = a[i];
    for (i = b; i <= n; i += k)
        t[i] = 0;
    for (i = b; i >= 1; i -= k)
        t[i] = 0;
    for (i = 1; i <= n; i++)
        cnt += t[i];
    return abs(cnt);
}

int main(int argc, char* argv[]) {
    int i, n, k, ans = 0, cnt;

    scanf("%d%d", &n, &k);
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (i = 1; i <= n; i++) {
        cnt = func(i, k, n);
        ans = max(ans, cnt);
    }

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

    return 0;
}

#include <stdio.h>
#include<math.h>
int main()
{
  int k,n;
  scanf("%d %d",&n,&k);
  int arr[n];
  for(int i=0;i<n;i++)
  scanf("%d",&arr[i]);
  int cnta=0,cntb=0;
  for(int i=0;i<n;i++)
  {
      if(arr[i]==1)
      cnta++;
      if(arr[i]==-1)
      cntb++;
  }
 // printf("%d %d\n",cnta,cntb);
  int max=0;
  int cntd=cnta,cnte=cntb;
  for(int i=0;i<n;i++)
  {
      cnta=cntd;
      cntb=cnte;
      for(int j=i;j>=0;j=j-k)
      {
          if(arr[j]==1)
      cnta--;
      if(arr[j]==-1)
      cntb--;
      }
      for(int j=i+k;j<n;j=j+k)
      {
          if(arr[j]==1)
      cnta--;
      if(arr[j]==-1)
      cntb--;
      //printf("inside: j:%d\n",j);
      }
     // printf("cnta:%d cntb:%d\n",cnta,cntb);
      if(abs(cnta-cntb)>max)
      {
      //printf("inside: %d\n",abs(cnta-cntb));
      max=abs(cnta-cntb);
      }
  }
  printf("%d",max);
  return 0;
}

#include<stdio.h>
int a[10000], ans[10000];
int main()
{
    int  n=0,k=0;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;++i)
    scanf("%d",&a[i]);
    int j=0;
while(j<k)
{
    for(int i=0;i<n;i++)
    {
         if(i%k!=j)
         {
             if(a[i]==1) ans[j]++;
             else ans[j]--;
         }
    }
    j++;
}
for(int i=0;i<k;++i)
if(ans[i]<0)ans[i]=-ans[i];
int max=-1;
for(int i=0;i<k;++i)
{
    if(ans[i]>max) max=ans[i];
}

printf("%d\n",max);
return 0;
}

#include<stdio.h>

int tab[110];
int abs(int a){
	int b;
	if(a>0){
		return a;
	}
	else return (-1)*a;
}
int main(){
	int n,k,presum=0,sum=0,des,max=0;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",tab+i);
	}
	for(int i=0;i<n;i++){
		presum+=tab[i];
	}
	for(int i=0;i<k;i++){
		for(int j=0;i+j*k<n;j++){
			sum+=tab[i+j*k];
		}
		des=presum-sum;
		if(max<abs(des))	max=abs(des);
		sum=0;
	}
	printf("%d",max);
}

#include <stdio.h>

int max(int a, int b){
    if(a > b)
        return a;
    return b;
}

int abs(int a){
    if(a < 0)
        return -a;
    return a;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int sum = 0, arr[k];
    for(int i = 0; i < k; i++){
        arr[i] = 0;
    }
    for(int i = 0; i < n; i++){
        int t;
        scanf("%d", &t);
        sum+=t;
        arr[i%k]+=t;
    }
    int mx = -(1<<30);
    int min = -mx;
    for(int i = 0; i < k; i++){
        if(arr[i] < min){
            min = arr[i];
        }
        if(arr[i] > mx){
            mx = arr[i];
        }
    }
    int ans = max(abs(sum-mx), abs(sum-min));
    printf("%d\n", ans);
}

#include<stdio.h>
#include<stdlib.h>

int main(){
    int n, k, sum1 = 0, sum2 = 0, res = 0;
    scanf("%d %d", &n, &k);
    int *a = (int *)calloc(k, sizeof(int));
    int *b = (int *)calloc(k, sizeof(int));
    for(int i = 0; i < n; ++i){
        int tmp;
        scanf("%d", &tmp);
        if(tmp == -1)
            ++a[i % k], ++sum1;
        else
            ++b[i % k], ++sum2;
    }
    for(int i = 0; i < k; ++i){
        int tmp = abs(sum1 - sum2 - a[i] + b[i]);
        res = tmp > res ? tmp : res;
    }
    printf("%d\n", res);
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,i,k,j,b=0,c=0,d=0,m=0;
    scanf("%d%d",&n,&k);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==1)
            b++;
        else
            c++;

    }
    for(i=0;i<k;i++)
    {
        int s=b,f=c;
        for(j=i;j<n;j=j+k)
        {
            if(a[j]==1)
                s--;
            else
                f--;
        }
        d=abs(s-f);

        if(m<d)
            m=d;
    }
    printf("%d",m);
}

#include<stdio.h>
int main ()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int arr[n+1];
	arr[0]=0;
	//int sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&arr[i]);
		//sum=sum+arr[i];
	}
	int sand=0;
	int l=0;
	int max[k];
	for(int i=1;i<=k;i++)
	{
		sand=0;
		int ans[n+1];
		for(int j=0;j<=n;j++)
		{
			ans[j]=arr[j];
		}
		for(int j=i;j<=n;j+=k)
		{
			ans[j]=0;
		}
		for(int j=0;j<=n;j++)
		{
			sand=sand+ans[j];
		}
		if(sand<0)
		{
			max[l]=(-1)*sand;
			l++;
		}
		else
		{
			max[l]=sand;
			l++;
		}
	}
	int mad=0;
	for(int i=0;i<k;i++)
	{
		//printf("%d ",max[i]);
		if(max[i]>mad)
			mad=max[i];
	}
	printf("%d\n",mad);
}

#include<stdio.h>
#include<math.h>
int main(){
	int n,k,i,j;
	int a[100];
	int e=0,s=0,de,ds;
	int max=0,diff;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<n;i++)if(a[i]==1)e++;else s++;
	for(i=0;i<k;i++){
		de=0;
		ds=0;
		for(j=i;j<n;j+=k)if(a[j]==1)de++;else ds++;
		diff=abs(e-de-s+ds);
		if(diff>max)max=diff;
	}
	printf("%d",max);
}

#include<stdio.h>
#include<math.h>

int main()
{
    int n, k, i, j, c, es = 0, ss = 0, e = 0, s = 0, max = -1, a[105];
    scanf("%d %d", &n, &k);
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i] == 1)
            es++;
        else
            ss++;
    }
    for(i = 1; i <= k; i++)
    {
        e = es;
        s = ss;
        for(j = 0; (i + j) <= n; j += k)
        {
            c = i + j;
            if(a[c] == 1)
                e--;
            else
                s--;
        }
        if(abs(e - s) > max)
            max = abs(e - s);
    }
    printf("%d\n", max);
    return 0;
}

#include <Stdio.h>
#include <String.h>
#include <math.h>

int main() {
	int n, k;
	while (scanf("%d%d", &n, &k) != EOF) {
		int arr[n];
		int cnt_fu = 0;
		int cnt_zheng = 0;
		int result = -1;
		memset(arr, 100, sizeof(arr));

		for (int i = 0 ; i < n; i++) {
			scanf("%d", &arr[i]);
			if (arr[i] == -1) {
				cnt_fu++;
			}
			if (arr[i] == 1) {
				cnt_zheng++;
			}
		}
		int b = 0;
		int i = 0;
		int c = 0;
		for (b = 0; b < n; b++) { // b <= n
			int tmp[n];
			memcpy(tmp, arr, sizeof(arr));
			int cnt_fu_jian = 0;
			int cnt_zheng_jian = 0;
			for (i = -1 * n ; i <= n; i++) {
				c = b + i * k;
				if (c < 0 || c > n) {
					continue;
				}
				else if (arr[c] == -1) {
					cnt_fu_jian++;
					tmp[c] = 0;
				}
				else if (arr[c] == 1) {
					cnt_zheng_jian++;
					tmp[c] = 0;
				}
			}
			int cnt_fu_sum = cnt_fu - cnt_fu_jian;
			int cnt_zheng_sum = cnt_zheng - cnt_zheng_jian;
			int new = (int)abs(cnt_fu_sum - cnt_zheng_sum);
			// printf("new:%d\tb:%d\ti:%d\tc:%d\n", new, b, i, c);
			if (new > result) {
				result = new;
			}
		}
		printf("%d\n", result);
	}
	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,k,a[100],i,j,c=0,d=0,mx=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(j=0;j<k;j++)
    {
        for(i=0;i<n;i++)
        {
            if((i+1)%k==j)
                continue;
            if(a[i]==1)
                c++;
            else
                d++;
        }
        if(abs(c-d)>mx)
            mx=abs(c-d);
        c=0;
        d=0;
    }
    printf("%d\n",mx);
    return 0;
}

#include <stdio.h>
#include <math.h>
int n,k;
int dem[101];
int main()
{
	int web,i;
	scanf("%d %d",&n,&k);
	for(i=1 ; i<=n ; i++)
	{
		scanf("%d",&web);
		dem[i%k]+=web;
		dem[k]+=web;
	}

	int kq=0;
	for(i=0 ; i<k ; i++)
	{
		dem[i]=abs(dem[k]-dem[i]);
		kq=kq>dem[i]?kq:dem[i];
	}

	printf("%d",kq);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,k,b,c,e,s,j,val,max,i;
    scanf("%d%d",&n,&k);
    int *a=(int*)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
        scanf("%d",a+i);

    max=0;
    for(b=0;b<k;b++)
    {
        e=0,s=0;

        for(j=0;j<n;j++)
        {
            if((j-b)%k!=0)
            {
                if(a[j]==1) e++;
                else s++;
            }
        }
        val=abs(e-s);
          //printf("val=%d\n",val);
        if(val>max)
          max=val;
    }
    printf("%d",max);
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,k,i,b,s;
    scanf("%d%d",&n,&k);
    int tab[n],store[n],sum[k];
    for (i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        store[i]=tab[i];
    }
    for (b=0;b<k;b++)
    {
        for (i=b;i<n;i+=k)
        {
            tab[i]=0;
        }
        for (i=0;i<n;i++)
        {
            if (tab[i]==1) s++;
            else if (tab[i]==-1) s--;
        }
        sum[b]=abs(s);
        s=0;
        for (i=b;i<n;i+=k)
        {
            tab[i]=store[i];
        }
    }
    for (i=1;i<k;i++)
    {
        if (sum[0]<sum[i])
            sum[0]=sum[i];
    }
    printf("%d",sum[0]);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,k;
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        getchar();
        int a[2000]={0},x=0,y=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==1) x++;
            else y++;
        }
        getchar();
        int max=0;
        for(int i=1;i<=k;i++)
        {
            int x1=x,y1=y;
            for(int j=i;j<=n;j+=k)
            {
                if(a[j]==1) x1--;
                else y1--;
            }
            int m;m=x1-y1;
            if(m<0) m=-m;
            if(m>max) max=m;
        }
        printf("%d\n",max);
    }
    return 0;
}

#include <stdio.h>

int mod(int a){
    if(a > 0) return a;
    else return -a;
    return -1000;
}

int main(){
    int n, k, b, i, j, eg=0, sg=0;
    scanf("%d %d", &n, &k);
    int arr[n];

    for(i = 0; i < n; i++){
        scanf("%d", &arr[i]);
        if(arr[i] == 1) eg++;
        if(arr[i] == -1)sg++;
    }
    int e=0, s=0, max = 0;
    for(b = 0; b < k; b++){
        e=0;
        s=0;
        for(i = 0; b+i*k < n; i++){
           if(arr[b+i*k] == 1) e++;
           if(arr[b+i*k] == -1)s++;
        }
        if(mod(eg-e-sg+s) > max) max = mod(eg-e-sg+s);
        //printf("%d %d\n", mod(eg-e-sg+s), b);
    }
    printf("%d", max);
    return 0;
}

#include<stdio.h>
int main()
{
	int n,i,t,k;
	int b,e,s;
	scanf("%d %d",&n,&k);
	int x[n],arr[n],brr[n];
	for(i=0;i<n;i++)
	scanf("%d",&x[i]);
	for(b=0;b<n;b++)
	{
		for(i=0;i<n;i++)
		arr[i]=1;
		i=0;
		while(1)
		{
			t=b+k*i;
			if(t>n-1)
			break;
			arr[t]=0;
			i++;
		}
		i=0;
		while(1)
		{
			t=b-k*i;
			if(t<0)
			break;
			arr[t]=0;
			i++;
		}
		e=0;
		s=0;
		for(i=0;i<n;i++)
		{
			if(arr[i]==0)
			continue;
			if(x[i]==1)
			e++;
			else if(x[i]==-1)
			s++;
		}
		if(e>s)
		brr[b]=e-s;
		else
		brr[b]=s-e;
	}
	t=0;
	for(i=0;i<n;i++)
	{
		if(t<brr[i])
		t=brr[i];
	}
	printf("%d\n",t);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int n,m,k;

    int araay[111],array1[111];
    int max=0;
    scanf("%d%d",&n,&k);

    for(int i=0;i<n;i++)
        scanf("%d",&araay[i]);

    for(int i=0;i<k;i++)
    {
        int countinfo=0,countsocial=0;
        for(int j=0;j<n;j++)
        {
            array1[j]=araay[j];
        }
        for(int j=i;j<n;j+=k)
        {
            array1[j]=0;
        }
        for(int j=0;j<n;j++)
        {
            if(array1[j]==1)
                countinfo++;
            else if(array1[j]==-1)
                countsocial++;
        }
        int result=abs(countinfo-countsocial);
        if(result>max)
            max=result;
    }
    printf("%d",max);

}

#include<stdio.h>
#include<math.h>

int main(){
    int n,k,e=0,s=0,max=0,temp=0;
    scanf("%d %d",&n,&k);
    int str[n];
    for(int i=0;i<n;i++){
        scanf("%d",&str[i]);
    }
    for(int b=0;b<k;b++){
        int j=0;
        s=0;
        e=0;
        for(int i=0;i<n;i++){
            if(i==b+j*k) j++;
            else{
                if(str[i]==1) e++;
                if(str[i]==-1) s++;
            }
        }
        temp=abs(e-s);
        if(temp>max) max=temp;
    }
    printf("%d",max);
    return 0;
}

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

#define MAXLEN 100

int main()
{
	int n,k, tabs[MAXLEN+1];
	int l,b,sum,tmp[MAXLEN+1];
	int ans;

	while(scanf("%d%d",&n,&k)==2)
	{
		ans=0;
		for(l=1;l<=n;l++) scanf("%d",&tabs[l]);

		for(b=1;b<=n;b++)
		{
			memcpy((void *)tmp,(void *)tabs,sizeof(int)*(n+1));

			for(l=b;l<=n;l+=k) tmp[l]=0;
			for(l=b-k;l>0;l-=k) tmp[l]=0;

			for(l=1,sum=0;l<=n;l++) sum+=tmp[l];
			sum=(sum<0)?-sum:sum;

			if(sum>ans) ans=sum;
		}

		printf("%d\n", ans);
	}

	return 0;
}

#include<stdio.h>

int main()
{
    int n,k,max=0,dif=0;
    scanf("%d%d",&n,&k);
    int ar[n],br[n];
    for(int i=0;i<n;i++)
    scanf("%d",&br[i]);
    for(int b=0;b<n;b++)
    {
    for(int x=0;x<n;x++)
    ar[x]=br[x];
    int i=0,t=0,s=0;
    while(b-(i*k)>=0||b+(i*k)<n)
    {
    if(b-(i*k)>=0)
    ar[b-(i*k)]=0;
    if(b+(i*k)<n)
    ar[b+(i*k)]=0;
    i++;
    }
    for(int j=0;j<n;j++)
    {
    //printf("%d ",ar[j]);
    if(ar[j]==-1)
    s++;
    else if(ar[j]==1)
    t++;
    }
    if(t>s)
    dif=t-s;
    else
    dif=s-t;
    if(dif>max)
    max=dif;
    }
    printf("%d",max);
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#define Max 100000
int main(){
	int n,k;
	int c,b,i;
	int num[Max];
	int num1[Max];
	int sum1=0,sum2=0,r[Max];
	int j,e,f,a=0;
	int temp=0;
	scanf("%d%d",&n,&k);
	for(j=0;j<n;j++){
		scanf("%d",&num[j]);
	}
	int q=k;

	for(b=q-1;b>=0;b--){

		i=0;
		sum1=0;
		sum2=0;
		c=0;
		for(j=0;j<n;j++){
			num1[j]=num[j];
		}
		while(c<=n){
			c=b+i*k;
			num1[c-1]=0;
			i++;
		}
//		for(j=0;j<n;j++){
//			printf("%d",num1[j]);
//			}
		for(j=0;j<n;j++){
			if(num1[j]==1){
				sum1++;
			}
			if(num1[j]==-1){
				sum2++;
			}
//			printf(" %d%d\n",sum1,sum2);
		}
		int l;
		l=sum1-sum2;
		r[a]=abs(l);
//		printf("    %d       \n",r[a]);
		a++;
	}
	for(e=0;e<a-1;e++)
		for(f=e+1;f<a;f++)
			if(r[e]<r[f])
			{
				temp=r[e];
				r[e]=r[f];
				r[f]=temp;
			}
	printf("%d",r[0]);
	return 0;
}

#include<stdio.h>

int main() {
    int n, k;
    int arr[105];

    scanf("%d %d", &n, &k);
    int cons = 0;
    for(int i =0; i< n; i++) {
        scanf("%d", &arr[i]);
        cons += arr[i];
    }

    int result = 0;

    for(int b= 0; b < n; b++) {
        int temp= cons;
        for(int i = 0; i*k < n; i++) {
            if(b - i*k >= 0) temp -= arr[b - i * k];
            if(b + i*k < n && i != 0) temp -= arr[b + i * k];
        }
        if( temp < 0 ) temp = -1 * temp;
        if( temp > result) result = temp;
    }

    printf("%d", result);

    return 0;
}

#include<stdio.h>

int main()
{
    int n,k,pcount=0,ncount=0,mag,max=0;
    scanf("%d%d",&n,&k);
    int array[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&array[i]);
        if(array[i]>0)
        pcount++;
    }
    ncount=n-pcount;
    for(int i=0;i<k;i++)
    {
        int move=i,count=0,t=(n-i-1)/k;
        for(int j=0;j<=t;j++)
        {
            if(array[move]==1)
            count++;
            else
            count--;
            move+=k;
        }
        mag=pcount-ncount-count;
        if(mag<0)
        mag=-mag;

        if(max<mag)
        max=mag;

    }
    printf("%d",max);

}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,q=0,w=0,c;
	int k;
	int a[10000];
	int b[10000],max=-999999;
	scanf("%d %d",&n,&k);
	if(n==1)
	{
		scanf("%d",&c);

		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int b=1;b<=n;b++)
	{	q=0;w=0;
		for(int j=1;j<=n;j++)
		{
			if((j-b)%k==0)

			{continue;

			}
			if(a[j]==1)
			w++;
			else
			q++;
		}
		if(abs(q-w)>max)
		max=abs(q-w);
		printf("%d %d\n",q,w);

	}

	printf("%d",max);

	return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,q=0,w=0,c;
	int k;
	int a[10000];
	int b[10000],max=-999999;
	scanf("%d %d",&n,&k);
	if(n==1)
	{
		scanf("%d",&c);

		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int b=1;b<=n/2;b++)
	{	q=0;w=0;
		for(int j=1;j<=n;j++)
		{
			if((j-b)%k==0)

			{continue;

			}
			if(a[j]==1)
			w++;
			else
			q--;
		}
		if(q-w>max)
		max=abs(q-w);

	}

	printf("%d",max);

	return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
        int n,k;
        scanf("%d %d",&n,&k);

        int a[n+1];
        for(int i=1;i<n+1;i++)
            scanf("%d",&a[i]);

        int max=0;
        for(int i=1;i<n+1;i++)
        {
            int c;
            if(i/k==0)
            {
                c=i;
            }
            else
            {
                if(i%k==0)
                c=1;
                else if((i+1)%k==0)
                c=2;
                else
                c=3;
            }
            int j=0,e=0,s=0;
            for(int d=1;d<n+1;d++)
            {
                if(d==(c+j*k))
                {
                    j++;
                }
                else
                {
                    if(a[d]==1)
                        e++;
                    else
                        s++;
                }
            }

            if(abs(e-s)>max)
                max=abs(e-s);
        }
        printf("%d",max);
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
        int n,k;
        scanf("%d %d",&n,&k);

        int a[n+1];
        for(int i=1;i<n+1;i++)
            scanf("%d",&a[i]);

        int max=0;
        for(int i=1;i<n+1;i++)
        {
            int j=-(i/k),e=0,s=0;
            for(int d=1;d<n+1;d++)
            {
                if(d==(i+j*k))
                {
                    j++;
                }
                else
                {
                    if(a[d]==1)
                        e++;
                    else
                        s++;
                }
            }

            if(abs(e-s)>max)
                max=abs(e-s);
        }
        printf("%d",max);
}

#include <stdio.h>
#include <math.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int arr[n];
    for(int i = 0;i<n; i++)
        scanf("%d",&arr[i]);
    //int e,s;
    int ans=0;
    for(int i = 0; i < n/2; i++)
    {
        int e=0,s=0;
        int temp[n];
        for(int j=0;j<n;j++)
            temp[j]=arr[j];
        for(int j = i; j < n;)
        {
            temp[j]=0;
            j+=k;
        }
        for(int j = 0; j < n; j++)
        {
            if(temp[j]==1)
                e++;
            else if(temp[j]==-1)
                s++;
        }
        if(fabs(e-s)>=ans)
            ans=fabs(e-s);
    }
    printf("%d",ans);
    return 0;
}

#include<stdio.h>
int main(){
   int n , k , j , e = 0 , s=0  , num = 0 , min = 0 , max = 0 ;
   scanf("%d %d",&n , &k) ;
   int i , a[n]  , sum = 0 ;
   for(i=0 ; i<n ; i++){
       scanf("%d", &a[i])   ;
       sum += a[i]  ;
   }
if(sum>=0){
    //int num = 0 , int min = 0 ;
for(j=0 ; j<n ; j++){}
  for(i=j ; i<n ; i = i+k ){
        num += a[i]   ;
  }
if(min>num){
    min = num ;
    int index = j ;
   }

for(i=0 ; i<n ; i++ ){
    if((i==j)||((i-j)%k==0)) continue ;
    else{
    if(a[i]==1) e++ ;
    else s++ ;
  }
 }
 printf("%d",e-s)  ;
}else{
    //int num = 0 , int max = 0 ;
for(j=0 ; j<n ; j++){}
  for(i=j ; i<n ; i = i+k ){
        num += a[i]   ;
  }
if(max<num){
    max = num ;
    int index = j ;
   }
for(i=0 ; i<n ; i++ ){
    if((i==j)||((i-j)%k==0)) continue ;
    else{
    if(a[i]==1) e++ ;
    else s++ ;
  }
 }
 printf("%d", e-s)   ;
}
    return 0 ;
}

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *cnt = (i32 *) calloc (k, sizeof (i32));
  i32 sum = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a = read_int();
    cnt[a % k]++;
    sum += a;
  }
  i32 max = 0;
  for (i32 i = 0; i < k; ++i) {
    max = MAX(max, ABS(sum - cnt[i]));
  }
  print_int (max);
  puts("");
}

int main (void) {
  run ();
  return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *cnt = (i32 *) calloc (k, sizeof (i32));
  i32 sum = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a = read_int();
    cnt[i % k]++;
    sum += a;
  }
  i32 max = 0;
  for (i32 i = 0; i < k; ++i) {
    max = MAX(max, ABS(sum - cnt[i]));
  }
  print_int (max);
  puts("");
}

int main (void) {
  run ();
  return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
    static int a[101], t, n, k, sum, max ,i;
    scanf("%d%d", &n, &k);
    for(i=0; i<n; i++)
    {
        scanf("%d",&t);
        a[t%k] += t;
        sum += t;
    }
    for(i=0; i<k; i++)
    {
        if(max < abs(sum-a[i]))
            max = abs(sum-a[i]);
    }
    printf("%d\n", max);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF){
		int arr[n],i,a[k],b[k],max=-1e9,suma=0,sumb=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=0;i<n;i++){
			scanf("%d",&arr[i]);
			if(arr[i]==1)
				suma++ ;
			else
				sumb++;
		}
		for(i=0;i<n;i++){
			if(arr[i]==1){
				a[i%k]++;
			}
			else{
				b[i%k]++;
			}
		}
		for(i=0;i<k;i++){
			if(abs(a[i]-b[i])>max)
				max=abs(abs(suma-a[i])-abs(sumb-b[i]));
		}
		printf("%d\n",max);
	}
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,k,a[100],i,j,c=0,d=0,mx=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(j=1;j<=k;j++)
    {
        for(i=0;i<n;i++)
        {
            if((i+1)%k==j)
                continue;
            if(a[i]==1)
                c++;
            else
                d++;
        }
        if(abs(c-d)>mx)
            mx=abs(c-d);
        c=0;
        d=0;
    }
    printf("%d\n",mx);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,k,i,b=0;
    scanf("%d%d",&n,&k);
    int tab[n],store[n],sum[k];
    for (i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        store[i]=tab[i];
        if (i<k)
            sum[i]=0;
    }

    for (b=0;b<k;b++)
    {
        for (i=0;i<n;i++)
            tab[i]=store[i];
        for (i=b;i<n;i+=k)
        {
            tab[b]=0;
        }
        for (i=0;i<n;i++)
        {
            if (tab[i]==1) sum[b]++;
            else if (tab[i]==-1) sum[b]--;
        }
        sum[b]=abs(sum[b]);
    }
    for (i=0;i<k;i++)   printf("%d\t",sum[i]);
    for (i=1;i<k;i++)
    {
        if (sum[0]<sum[i])
            sum[0]=sum[i];
    }
    printf("%d",sum[0]);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,k,i,b,s;
    scanf("%d%d",&n,&k);
    int tab[n],store[n],sum[k];
    for (i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        store[i]=tab[i];
    }
    for (b=0;b<k;b++)
    {
        for (i=b;i<n;i+=k)
        {
            tab[i]=0;
        }
        for (i=0;i<n;i++)
        {
            if (tab[i]==1) s++;
            else if (tab[i]==-1) s--;
        }
        sum[b]=abs(s);
        s=0;
        for (i=b;i<n;i+=k)
        {
            tab[b]=store[b];
        }
    }
    for (i=1;i<k;i++)
    {
        if (sum[0]<sum[i])
            sum[0]=sum[i];
    }
    printf("%d",sum[0]);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,k,i,b=0;
    scanf("%d%d",&n,&k);
    int tab[n],store[n],sum[k];
    for (i=0;i<n;i++)
    {
        scanf("%d",&tab[i]);
        store[i]=tab[i];
        if (i<k)
            sum[i]=0;
    }

    for (b=0;b<k;b++)
    {
        for (i=0;i<n;i++)
            tab[i]=store[i];
        for (i=b;i<n;i+=k)
        {
            tab[b]=0;
        }
        for (i=0;i<n;i++)
        {
            if (tab[i]==1) sum[b]++;
            else if (tab[i]==-1) sum[b]--;
        }
        sum[b]=abs(sum[b]);
    }
    for (i=1;i<k;i++)
    {
        if (sum[0]<sum[i])
            sum[0]=sum[i];
    }
    printf("%d",sum[0]);
    return 0;
}

#include<stdio.h>
#include<math.h>

int main(){
    int n,k,e=0,s=0,max=0,temp=0;
    scanf("%d %d",&n,&k);
    int str[n];
    for(int i=0;i<n;i++){
        scanf("%d",&str[i]);
    }
    for(int b=0;b<k-1;b++){
        int j=0;
        for(int i=0;i<n;i++){
            if(i==b+j*k) j++;
            else{
                if(str[i]==1) e++;
                if(str[i]==-1) s++;
            }
        }
        temp=abs(e-s);
        if(temp>max) max=temp;
    }
    printf("%d",max);
    return 0;
}

#include<stdio.h>
#include<math.h>

int main(){
    int n,k,e=0,s=0,max=0,temp=0;
    scanf("%d %d",&n,&k);
    int str[n];
    for(int i=0;i<n;i++){
        scanf("%d",&str[i]);
    }
    for(int b=0;b<k-1;b++){
        int j=0;
        s=0;
        e=0;
        for(int i=0;i<n;i++){
            if(i==b+j*k) j++;
            else{
                if(str[i]==1) e++;
                if(str[i]==-1) s++;
            }
        }
        temp=abs(e-s);
        if(temp>max) max=temp;
    }
    printf("%d",max);
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#define Max 100000
int main(){
	int n,k;
	int c,b,i;
	int num[Max];
	int num1[Max];
	int sum1=0,sum2=0,r[Max];
	int j,e,f,a=0;
	int temp=0;
	scanf("%d%d",&n,&k);
	for(j=0;j<n;j++){
		scanf("%d",&num[j]);
	}
	int q=k;
	while(b=--q){
		i=0;
		sum1=0;
		sum2=0;
		c=0;
		for(j=0;j<n;j++){
			num1[j]=num[j];
		}
		while(c<=n){
			c=b+i*k;
			num1[c-1]=0;
			i++;
		}
//		for(j=0;j<n;j++){
//			printf("%d",num1[j]);
//			}
		for(j=0;j<n;j++){
			if(num1[j]==1){
				sum1++;
			}
			if(num1[j]==-1){
				sum2++;
			}
//			printf(" %d%d ",sum1,sum2);
		}
		int l;
		l=sum1-sum2;
		r[a]=abs(l);
//		printf("    %d       ",r[a]);
		a++;
	}
	for(e=0;e<a-1;e++)
		for(f=e+1;f<a;f++)
			if(r[e]<r[f])
			{
				temp=r[e];
				r[e]=r[f];
				r[f]=temp;
			}
	printf("%d",r[0]);
	return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#define Max 100
int main(){
	int n,k;
	int c,b,i;
	int num[Max];
	int num1[Max];
	int sum1=0,sum2=0,r[Max];
	int j,e,f,a=0;
	int temp=0;
	scanf("%d%d",&n,&k);
	for(j=0;j<n;j++){
		scanf("%d",&num[j]);
	}
	int q=k;
	while(b=--q){
		i=0;
		sum1=0;
		sum2=0;
		c=0;
		for(j=0;j<n;j++){
			num1[j]=num[j];
		}
		while(c<=n){
			c=b+i*k;
			num1[c-1]=0;
			i++;
		}
//		for(j=0;j<n;j++){
//			printf("%d",num1[j]);
//			}
		for(j=0;j<n;j++){
			if(num1[j]==1){
				sum1+=num1[j];
			}
			if(num1[j]==-1){
				sum2+=num1[j];
			}
//			printf(" %d%d ",sum1,sum2);
		}
		int l;
		l=sum1-sum2;
		r[a]=abs(l);
//		printf("    %d       ",r[a]);
		a++;
	}
	for(e=0;e<a-1;e++)
		for(f=e+1;f<a;f++)
			if(r[e]<r[f])
			{
				temp=r[e];
				r[e]=r[f];
				r[f]=temp;
			}
	printf("%d",r[0]);
	return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#define Max 100000
int main(){
	int n,k;
	int c,b,i;
	int num[Max];
	int num1[Max];
	int sum1=0,sum2=0,r[Max];
	int j,e,f,a=0;
	int temp=0;
	scanf("%d%d",&n,&k);
	for(j=0;j<n;j++){
		scanf("%d",&num[j]);
	}
	int q=k;
	while(b=--q){
		i=0;
		sum1=0;
		sum2=0;
		c=0;
		for(j=0;j<n;j++){
			num1[j]=num[j];
		}
		while(c<=n){
			c=b+i*k;
			num1[c-1]=0;
			i++;
		}
//		for(j=0;j<n;j++){
//			printf("%d",num1[j]);
//			}
		for(j=0;j<n;j++){
			if(num1[j]==1){
				sum1+=num1[j];
			}
			if(num1[j]==-1){
				sum2+=num1[j];
			}
//			printf(" %d%d ",sum1,sum2);
		}
		int l;
		l=sum1-sum2;
		r[a]=abs(l);
//		printf("    %d       ",r[a]);
		a++;
	}
	for(e=0;e<a-1;e++)
		for(f=e+1;f<a;f++)
			if(r[e]<r[f])
			{
				temp=r[e];
				r[e]=r[f];
				r[f]=temp;
			}
	printf("%d",r[0]);
	return 0;
}

#include<stdio.h>

int main() {
    int n, k;
    int arr[105];

    scanf("%d %d", &n, &k);
    int cons = 0;
    for(int i =0; i< n; i++) {
        scanf("%d", &arr[i]);
        cons += arr[i];
    }

    int result = 0;

    for(int b= 0; b < n; b++) {
        int temp= cons;
        for(int i = 0; i*k < n; i++) {
            if(b - i*k > 0) temp -= arr[b - i * k];
            if(b + i*k < n && i != 0) temp -= arr[b + i * k];
        }
        if( temp < 0 ) temp = -1 * temp;
        if( temp > result) result = temp;
    }

    printf("%d", result);

    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
	int n,q=0,w=0,c;
	int k;
	int a[10000];
	int b[10000],max=-999999;
	scanf("%d %d",&n,&k);
	if(n==1)
	{
		scanf("%d",&c);

		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int b=1;b<=n;b++)
	{	q=0;w=0;
		for(int j=1;j<=n;j++)
		{
			if((j-b)%k==0)

			{continue;

			}
			if(a[j]==1)
			w++;
			else
			q--;
		}
		if(q-w>max)
		max=abs(q-w);

	}

	printf("%d",max);

	return 0;
}


Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.

The only line of input contains integers n and k (1 ≤ k ≤ n ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print the number that will stand at the position number k after Volodya's manipulations.

NoteIn the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.

#include<stdio.h>
main()
{
    long long int i,x,n,k;
    scanf("%lld%lld",&n,&k);
    if(n%2==0)
        x=n/2;
    else
        x=(n/2)+1;
    if(x>=k)
    {
        printf("%lld",2*k-1);
    }
    else
    {
        printf("%lld",2*(k-x));
    }

}

#include <stdio.h>
int main()
{

    long long int n,k;
    scanf("%I64d %I64d",&n,&k);
    if(n%2==0){
        if(k <= n/ 2)
            printf("%I64d",2*k-1);
        else
            printf("%I64d",2*k-n);
    }
    else{
        if(k<=n/2+1)
            printf("%I64d",2*k-1);
        else
            printf("%I64d",2*k-n-1);
    }

}

#include<stdio.h>

int main(){

long long int n,k;

scanf("%lld %lld",&n,&k);

if((n%2)==0)
{
	if(k>(n/2))
		printf("%lld\n",2*(k-(n/2)));
	else
		printf("%lld\n",2*k-1);

}

else{

	if(k<=((n+1)/2))
		printf("%lld\n",2*k-1);
	else
		printf("%lld\n",2*(k-(n+1)/2));

}

return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(){

	long long int i = 0, m =0, n = 0, odd[sizeof(long long int)], even[sizeof(long long int)];
	long long int x = 0, y = 0, count = 0, half = 0, total = 0 ;

/*____________Scaning The Data___________*/

		scanf("%I64d %I64d", &x, &y);

		if (x % 2 == 0)
		{
			half = x / 2; //printf("%I64d\n", half);
		}

		else
		{
			half = (x + 1) / 2; //printf("%I64d\n", half);
		}

		if (y <= half)
		{
			total = (2 * y) - 1;
			printf("%I64d\n", total);
		}

		if (y > half)
		{
			total = (y - half) * 2;
			printf("%I64d\n", total);
		}

	return 0;
}// main

#include<stdio.h>
int main()
{
    long long int n,k,even,odd;
    scanf("%lld %lld",&n,&k);
    if(n%2==0)
    {
        even=n/2;
        odd=n/2;
    }
    else
    {
        odd=(n/2)+1;
        even=(n/2);
    }
    if(k<=odd)
    printf("%lld",2*(k-1)+1);
    else
    printf("%lld",2*(k-odd));
    return 0;
}

#include<stdio.h>
int main(){
 long long int n,k;
scanf("%lld %lld",&n,&k);
if(n%2==0){
    if(k<=(n/2)){
        printf("%lld\n",(k*2)-1);
    }
    else if(k==n){
        printf("%lld\n",k);
    }
    else{
            printf("%lld\n",(k-(n/2))*2);

    }
}
    else{
    if(k<=(n/2)+1){
        printf("%lld\n",(k*2)-1);
    }
    else if(k==n){
        printf("%lld\n",k-1);
    }
    else{
            printf("%lld\n",(k-(n/2+1))*2);

    }

}

return 0;
}

#include<stdio.h>

int main()
{
    long long n, k;
    scanf("%lld%lld",&n,&k);
    if(n%2==0)
    {
    if(k<=n/2)
    printf("%lld",(k*2)-1);
    else
    printf("%lld",(k-(n/2))*2);
    }
    else
    {
    if(k<=(n/2)+1)
    printf("%lld",(k*2)-1);
    else
    printf("%lld",(k-((n/2)+1))*2);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    long long p,k,n,i;
    scanf("%I64d",&n);
    scanf("%I64d",&k);

    long long s;

    if(n%2!=0)
       p=n+2;
    else
       p=n;

    if (k<=(p)/2)
        s=2*k-1;
    else
    {
        if(n%2==0)
            s=2*k-n;
        else
            s=2*k-n-1;

    }

    printf("%I64d",s);

    return 0;
}

#include<stdio.h>
int main()
{
        unsigned long long n,k;
        scanf("%llu%llu",&n,&k);

        if(n%2==0)
        {
                if(k<=n/2) printf("%llu",2*k-1);
                else printf("%llu", 2*(k-n/2));
        }
        else
        {
                if(k<=(n+1)/2) printf("%llu",2*k-1);
                else printf("%llu", 2*(k-(n+1)/2));
        }
}

#include <stdio.h>

int main(){
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long mid=(n+1)/2;

	if(k<=mid)
		printf("%lld\n",2*k-1);
	else
		printf("%lld\n",(k-mid)*2);
	return 0;
}

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

int main(){
    long long n,k,i,o,j=-1;
    scanf("%I64d %I64d",&n,&k);
    //long long arr[n/2+2];
    o = n/2;
    if(n%2!=0)
        o++;

    if(k<=o)
    {
        printf("%I64d",1+(k-1)*2);
    }else {
        printf("%I64d",2+((k-o)-1)*2);
    }

    return 0;
}

#include<stdio.h>
#include<stdint.h>
int main(){
	unsigned long long n=0,k=0,output=0;
	scanf("%I64d %I64d",&n,&k);
	if(n%2==0){
		if(k<=(n/2ll)){
		printf("%I64d",(k*2ll)-1ll);

		}
		else{
		printf("%I64d",(k-(n/2ll))*2ll);
		}
	}
	else{
		if(k<=((n/2)+1)){
		printf("%I64d",(k*2ll)-1ll);
		}
		else{
		printf("%I64d",(k-((n/2ll)+1))*2ll);
		}
	}
	//printf("%I64d ",output);
}

#include <stdio.h>
long long int i,j,k,m,n,a,b;
int main()
{
    scanf("%lld %lld",&a,&b);
    if(a%2==0)
    {
    if(2*b-1<a)
    {
        printf("%lld",2*b-1);
        }
        else
        {
            printf("%lld",(b-a/2)*2);

        }
    }
        else
        {
        if(2*b-1<=a)
        {
            printf("%lld",2*b-1);
        }
        else
        {
        printf("%lld",((b-a/2)-1)*2);
        }

    }

        return 0;
    }

#include <stdio.h>
int main()
{
	long long n,k,i,sum;
	scanf("%lli %lli",&n,&k);
	if (n%2==0 && n/2>=k)
	{ sum=1;
    for (i=1; i<k; i=i+1)
        sum=sum+2;
		}
    else if (n%2==0 && n/2<=k)
        {sum=0;
        for (i=1; i<=k-(n/2); i=i+1)
        sum=sum+2;}
    else if ((n+1)/2>=k)
	{	sum=1;
        for (i=1; i<k; i=i+1)
				sum=sum+2;}
    else { sum=0;
        for (i=1; i<=k-((n+1)/2); i=i+1)
        sum=sum+2; }
	printf("%lli", sum);
	return 0;
	}

#include<stdio.h>
main()
{
    unsigned long long int n,k;
    scanf("%llu",&n);
    scanf("%llu",&k);
    if (k <= (n + 1) / 2)
    {
        printf("%llu",k*2-1);
    }
    else
    {
        printf("%llu",(k-(n+1)/2)*2);
    }
}

#include<stdio.h>
int main(){
long long int n,k;

scanf("%lld %lld",&n,&k);

if(n%2==0){
    if(k<=n/2){printf("%lld\n",(2*k)-1);}
    else{
        k=k-(n/2);
        printf("%lld\n",2*k);
    }
}
else{
    if(k<=(n/2)+1){printf("%lld\n",(2*k)-1);}
    else{
        k=k-(n/2)-1;
        printf("%lld\n",2*k);
    }
}
return 0;
}

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main () {

    int64_t n,k,a;

    scanf("%" PRId64,&n);
    scanf("%" PRId64,&k);

    if (n%2==0){
        if(k>(n/2)){
            a=2*(k-(n/2));
        }else{
            a=2*k-1;
        }
    }else{
        if(k>(n/2+1)){
            a=2*(k-(n/2+1));
        }else{
            a=2*k-1;
        }
    }

    printf("%" PRId64 "\n", a);

    return 0;
}

#include<stdio.h>
int main()
{

long long int n,p;
scanf("%lld %lld",&n,&p);

 if(n%2==0)
 {
     if(p<=n/2)
     {
         printf("%lld",2*p-1);
     }
     else{
         p=p-n/2;
         printf("%lld",2*p);
     }
 }
 else{
     if(p<=(n/2)+1)
     {
         printf("%lld",2*p-1);
     }
     else{
         p=p-(n/2)-1;
         printf("%lld",2*p);
     }
 }
 return 0;
}

#include <stdio.h>
long long int k,n,ans,zip;
int main()
{
	scanf("%lld %lld",&n,&k);

	if(k==1)
	{
		printf("1");
		return 0;
	}

	if(n%2==0)
	{
		if(k==n)
		{
			printf("%lld",n);
			return 0;
		}
			zip=n/2;

	}
	else
	{
		if(k==n)
		{
			printf("%lld",n-1);
			return 0;
		}
		zip=(n/2)+1;
	}
	if(k<=zip)
	{
		ans=k*2-1;
		if(ans<0)
			ans=ans*-1;
	}
	else if(k>zip && n%2==0)
	{
		ans=n-(2*k);

		if(ans<0)
			ans=ans*-1;
	}
	else
	{
		ans=2*k-n-1;
	}
	printf("%lld",ans);

}

//emre
#include <stdio.h>
int main()
{
    long long int n,k,a,b,c=0,tek=0;
    scanf("%I64d %I64d",&n,&k);
    //tek sayı sayısını bulalım
    for(a=1;a<=n;a+=2)
    {
    tek++;
    }
    //Bulduk
    if(tek >= k)
    {
    printf("%I64d",1+2*(k-1));
    }
    else
    {
        //tekler fazla degil ise
        printf("%I64d",2+(k-tek-1)*2);
    }
    return 0;
}

#include <stdio.h>

int main()
{
    long long n,k;
    scanf("%I64d %I64d",&n,&k);
    long long m;
    long long value;
    if(n%2==0)
        m=n/2;
    else
        m=(n/2)+1;
    if(k<=m)
        value=(k*2)-1;
    else
    {
        k-=m; //to make the even half as start from as 1, 2, 3 ... positions.
        value=k*2;
    }

    printf("%I64d\n",value);
}

#include<stdio.h>
int main(){
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    if(k<=((n+1)/2)){
        printf("%lld",2*k-1);
    }
    else{
        k=k-((n+1)/2);
        printf("%lld",2*k);
    }
}

#include <stdio.h>

int main() {
	long long int n,k,i;
	scanf("%lld %lld",&n,&k);
	if(k<=(n+1)/2)
	printf("%lld",2*k-1);
	else printf("%lld",2*(k-(n+1)/2));

	return 0;
}

#include<stdio.h>
int main(){
    long long int n,k,value,numOdd;
    scanf("%I64d %I64d",&n,&k);
//    if(n%2!=0) numOdd=(n/2)+1;
//    else numOdd=n/2;
    if(k<=(n+1)/2){
        value= k*2-1;
    }
    else{
        value=(k-(n+1)/2)*2;
    }
    printf("%I64d",value);

    return 0;
}

#include<stdio.h>
int main(){
	long long num, k;
	scanf("%I64d%I64d",&num,&k);
	if(num&1){
		num=num/2+1;
		if(k<=num)
		printf("%I64d",2*k-1);
		else printf("%I64d",2*(k-num));
		return 0;
	}
	if(!(num&1))
	{
		num=num/2;
		if(k<=num)
		printf("%I64d",2*k-1);
		else printf("%I64d",2*(k-num));
	}
	return 0;
}

# include <stdio.h>

int main(void)
{
    long long n, m;
    while(~scanf("%lld%lld", &n, &m))
    {
        if(n % 2 == 0)
        {
            if(m > n/2)
                printf("%lld\n", (m-(n/2))*2);
            else
                printf("%lld\n", 2*m-1);
        }
        else
        {
            if(m > n/2+1)
                printf("%lld\n", (m-(n/2+1))*2);
            else
                printf("%lld\n", 2*m-1);
        }
    }

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,d;
    scanf("%lld %lld",&n,&k);
    d=(n%2)+(n/2);
    if(d<k)
        printf("%lld",(k-d)*2);
    else
        printf("%lld",(k*2)-1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
   long long int n ;
   scanf("%lld",&n);
   long long int m;
   scanf("%lld",&m);
   long long int i,j=0;
   long long int num;
   if(n%2==0)
   {
       n=n/2;
   }
   else if(n%2==1)
   {
       n=n/2+1;
   }
   if(m>n)
   {
       m=m-n;
      num=2*m;
   }
   else
   {
       i=1;
       j=0;
       for(i=1;j<m;i+=2)
       {
           num=i;
           j++;
       }
   }
   printf("%lld",num);

   return 0;
}

#include <stdio.h>

int main(void)
{
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long divide=n%2==0? n/2 : ((n+1)/2);
    if(k>divide )
   {
       printf("%lld",2+(2*(k-divide-1)));
   }
  if(k<=divide  )
   {
       printf("%lld",1+2*(k-1));
   }

}

#include <stdio.h>
int main()
{

    long long int n,k;
    scanf("%I64d %I64d",&n,&k);
    if(n%2==0){
        if(k <= n/ 2)
            printf("%I64d",2*k-1);
        else
            printf("%I64d",2*k-n);
    }
    else{
        if(k<=n/2+1)
            printf("%I64d",2*k-1);
        else
            printf("%I64d",2*k-n-1);
    }

}

#include<stdio.h>
#include<math.h>

int main(){
    long long int n,k;
    scanf("%lld %lld",&n,&k);
    long long int ne=floor(n/2);
    long long int no=n-ne;
    if(k>no) printf("%lld",2*(k-no));
    else printf("%lld",(2*k)-1);
    return 0;
}

#include<stdio.h>
int main()
{
    long long n,k,s,r;

    scanf("%lld %lld",&n,&k);
    if(n%2==0)
        s=n/2;
    else
        s=(n/2)+1;
    if(k<=s)
        printf("%lld",((2*k)-1));
    else
          printf("%lld",((k-s)*2));
    return 0;
}

#include<stdio.h>
int main(){
	long long x,k,a;
	scanf("%lld%lld",&x,&k);
	a=(x+1)/2;
	if(k<=a)
	printf("%lld",2*k-1);
	else
	printf("%lld",(k-a)*2);
	return 0;
}

#include<stdio.h>
int main()
{
long long n,k,c=0,i=1,j=2,d;
scanf("%I64d %I64d",&n,&k);
if(n%2==0)
d=n/2;
else
d=n/2+1;
if(k>d)
{
k=k-d;
printf("%I64d",k*2);
}
else
printf("%I64d",k*2-1);
return 0;
}

#include<stdio.h>
int main ()
{
        long long int n,k,x,p;
        scanf("%lld %lld",&n,&k);
        if(n%2==0)
        {
            p=n/2;
        }
        else{
            p=(n/2)+1;
        }

            if(k<=p)
            {
                x=(2*k)-1;
            }
            else
            {
                x=(k-p)*2;
            }
        printf("%lld",x);

}

#include<stdio.h>

long long int n,k;
int main()
{
scanf("%lld%lld",&n,&k);
if(k*2-1<=n)
    printf("%lld",k*2-1);
else
   printf("%lld",(k-(n+1)/2)*2);
return 0;
}

#include <stdio.h>

int main()
{
	long long n, k;
	scanf("%I64d%I64d", &n, &k);
	long long even;
	if(n%2==0)
		even=n/2;
	else
		even=(n/2)+1;
	if(k<=even)
		printf("%I64d\n", 2*k-1);
	else
		printf("%I64d\n", 2*(k-even));
	return 0;
}

#include<stdio.h>
int main()
{
    long long n,k,h;
    scanf("%lld%lld",&n,&k);
    if (n%2==0) h=n/2;
    else h=(n/2)+1;
    if (k<=h)
        printf("%lld",(2*k)-1);
    else
        printf("%lld",(k-h)*2);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,o,a;
    while(scanf("%I64d%I64d",&n,&k)!=EOF)
    {
    if(n%2==0)
        o=n/2;
    else
        o=(n+1)/2;
    if(k<=o)
    {
        a=2*k-1;
        printf("%I64d\n",a);
    }
    else
    {
        a=2*(k-o);
        printf("%I64d\n",a);
    }
    }
    return 0;
}

#include <stdio.h>
int main()
{
    long long int n,k,a,b,c;
    scanf("%I64d %I64d",&n, &k);
    if(n%2!=0)
    {
        a=n/2+1;
    }
    else
    {
        a=n/2;
    }
    if(k<=a)
    {
        b=2*k-1;
    }
    else if(k>a)
    {
        b=2*(k-a);
    }
    printf("%I64d",b);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
//unsigned long long  k[100000000];
int main()
{
  /*unsigned long long  x,y,i,j=1;
    scanf("%I64d%I64d",&x,&y);
    for(i=1;i<=x;i+=2)
    {
            k[j]=i;
            j+=1;
    }
     for(i=2;i<=x;i+=2)
    {
            k[j]=i;
            j+=1;
    }
    printf("%I64d\n",k[y]);*/

    long long int s,w;
	scanf("%I64d%I64d",&s,&w);
	if(w<=(s-s/2))
	printf("%I64d",2*w-1);
	else
	printf("%I64d",2*(w-(s-s/2)));

    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k,m;

    scanf("%lld %lld",&n,&k);

    if(n%2==0)
    {
        m=n/2;
    }
    else if(n%2!=0)
    {
        m=(n+1)/2;
    }

    if(k<=m)
    {
        printf("%lld",(k*2)-1);
    }
    else
    {
        printf("%lld",(k-m)*2);
    }
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    long long int ara[100];
   long long int a,b,i=0,x;
    scanf("%I64d%I64d",&a,&b);
    if(a%2==0)
        x=a/2;
    else
        x=(a/2)+1;
        if(b==x){
            i=(b*2)-1;
        }
      else  if(b>x){
            i=(b-x)*2;
        }
        else
        {
            i=(b*2)-1;
        }
        printf("%I64d\n",i);

    return 0;
}

#include<stdio.h>
#include<math.h>
#define getchar getchar//_unlocked
#define M 1000000007

int getint ()
{
        int  n=0;
        char ch=getchar();

        while(ch<'0' || ch>'9')
            ch=getchar();

        while(ch>='0' && ch<='9')
        {
                n=n*10+ch-'0';
                ch=getchar();
        }

        return n;

}

int binarysearch(int start ,int end ,int key ,int k)
{

        int middle,val;

        while(start<=end)
        {
            middle=(start+end)/2;

            val=compute(middle,k);

            if(val==key)
                return middle;

            if(val<key)
                start=middle+1;

            if(val>key)
                end=middle-1;

        }

        return start;

}

unsigned long long gcd(unsigned long long a, unsigned long long b)
{

        unsigned long long div=a,did=b,rem;

        while((rem=did%div)!=0)
        {
                did=div;
                div=rem;

        }

        return div;

}

long long getlonglong ()
{
        long long  n=0;
        char ch=getchar();

        while(ch<'0' || ch>'9')
            ch=getchar();

        while(ch>='0' && ch<='9')
        {
                n=n*10+ch-'0';
                ch=getchar();
        }

        return n;

}

void sort(int a[] ,int start1 ,int end1 ,int start2 ,int end2)
{

        int temp[end1-start1 +1 + end2-start2+1 ];
        int i=start1,j=start2,count=0;

        while(i<=end1 && j<=end2)
        {
                if(a[i]>=a[j])
                    temp[count++]=a[i++];
                else
                    temp[count++]=a[j++];

        }

        for(;i<=end1;++i)
            temp[count++]=a[i];

        for(;j<=end2;++j)
            temp[count++]=a[j];

        for(i=0;i<count;++i)
            a[i+start1]=temp[i];

}

void mergesort(int a[] ,int start,int end)
{
        if(start==end)
            return;

        int middle =(start+end)/2;

        mergesort(a,start,middle);
        mergesort(a,middle+1,end);
        sort(a,start,middle,middle+1,end);

}

long long Ceil(long long a , long long n)
{
        if(a<0)
            return 0;

        if(a%n==0)
            return a/n;
        else
            return a/n +1 ;

}

int compute(int a ,int k)
{
        int s= 0;

        while(a)
        {
                s=s+a;
                a=a/k;

        }

        return s;

}

int main()
{
        long long n,k;

        n=getlonglong();
        k=getlonglong();

        if( k <= (n+1)/2)
            printf("%I64d", 2*k-1);
        else
        {
                k= k - (n+1)/2;
                printf("%I64d",2*k);
        }

        return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    long long int i,n,k,a,b,c,d;
    scanf("%lld %lld",&n,&k);

    if(n%2==0)
    {
        if(k<=n/2) printf("%lld",k*2-1);
        else printf("%lld",(k-n/2)*2);
    }
    else if(n%2!=0)
    {
        if(k<=n/2+1) printf("%lld",k*2-1);
        else printf("%lld",(k-n/2-1)*2);}

        return 0;
}

#include<stdio.h>
int main()
{
   long long int ip1,ip2;
   scanf("%lld %lld",&ip1,&ip2);
   long long int r;
   if(ip1%2==0)
   {
       if(ip2<=ip1/2)
       {
           printf("%lld",2*ip2-1);
       }
       else
       {
           ip2=ip2-ip1/2;
           printf("%lld",2*ip2);
       }
   }
   else
   {
       if(ip2<=(ip1/2+1))
       {
       printf("%lld",2*ip2-1);
       }
       else
       {
           ip2=ip2-(ip1/2)-1;
           printf("%lld",2*ip2);
       }
   }
}

#include<stdio.h>
long long n,k;
int main(){
    scanf("%lld%lld",&n,&k);
    if(k>(n+1)/2) printf("%lld",(k-(n+1)/2)*2);
    else printf("%lld",k*2-1);
    return 0;
}

#include <stdio.h>
long long int a,b;

int main(){
    scanf("%lld %lld",&a,&b);
    if (a%2==0)
    {
        if (2*b-1<a)
        {
            printf("%lld",2*b-1);
        }
        else
        {
            printf("%lld",(b-a/2)*2);
        }
    }
    else
    {
        if (2*b-1<=a)
        {
            printf("%lld",2*b-1);
        }
        else
        {
            printf("%lld",((b-a/2)-1)*2);
        }
    }
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n, m;
    scanf("%I64d %I64d", &n, &m);
    if(m <= n / 2 + (n % 2 == 1))
        printf("%I64d", 2 * m - 1);
    else
        printf("%I64d", 2 * (m - n / 2 - (n % 2 == 1)));
    return 0;
}

#include <stdio.h>

int main(void)
{
    long long int n =0, k=0;
    scanf("%lld %lld",&n, &k);
    if (n%2 == 0)
    {
        if (k <= n/2)
        {
            printf("%lld", k*2-1);
        }
        else if (k > n/2)
        {
            k= k-(n/2);
            printf("%lld", k*2);
        }
    }
    else
    {
        if (k <= n/2+1)
        {
            printf("%lld", k*2-1);
        }
        else if (k > n/2 +1)
        {
            k= k- n/2 -1;
            printf("%lld", k*2);
        }
    }
}

#include<stdio.h>
int main()
{
    long long n,k,s,r;

    scanf("%lld %lld",&n,&k);
    if(n%2==0)
        s=n/2;
    else
        s=(n/2)+1;
    if(k<=s)
        printf("%lld",((2*k)-1));
    else
          printf("%lld",((k-s)*2));
    return 0;
}

#include<stdio.h>
int main(){
	long long x,k,a;
	scanf("%lld%lld",&x,&k);
	a=(x+1)/2;
	if(k<=a)
	printf("%lld",2*k-1);
	else
	printf("%lld",(k-a)*2);
	return 0;
}

#include<stdio.h>
int main(){
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    if(k<=((n+1)/2)){
        printf("%lld",2*k-1);
    }
    else{
        k=k-((n+1)/2);
        printf("%lld",2*k);
    }
}

#include <stdio.h>
#include <stdlib.h>
long long k ;
long long n ;
long long x ;
long long y ;
int main()
{
    scanf("%I64d",&n) ;
    scanf("%I64d",&k) ;
    x=(n+1)/2 ;
    if (k<=x)
        printf("%I64d",((2*k)-1)) ;
    else
    {
        y=(k-x)*2 ;
        if ((n%2!=0) && (k==n))
            y=y ;
        printf("%I64d",y) ;
    }

    return 0;
}

#include <stdio.h>
#include<string.h>
int main()
{ long long int i,c=0,a,b;
scanf("%lld%lld",&a,&b);
    if(a%2== 0)
    c=a/2;
    else
    c=a/2+1;
    if(b<=c){
long long int p=a-c;
printf("%lld",2*b-1);
}
else{
    if(a%2==0)
    c=a/2;
    else
    c=a/2+1;
long long int p=b-c;
printf("%lld",2*p);
}
}

#include<stdio.h>
#include<string.h>
#include<stdint.h>
#include<Math.h>
int main()
{
int64_t n,*A,i,j=0,p,t=1,x;
scanf("%I64d",&n);
scanf("%I64d",&p);
x=((n-1)/2)+1;
if(n%2!=0)
x=(n-x)+1;
else
x=(n-x);
if(p<=x)
    printf("%I64d",((p-1)*2)+1);
    else
    {
    p=p-x;
    printf("%I64d",((p)*2));
    }

return 0;
}

#include<stdio.h>
int main()
{
        long long int a,b,c,d;

        scanf("%lld%lld",&a,&b);

        if (a%2==0)
        {
                c=a/2;

        }

        else
        {
                c=(a/2)+1;
        }

        if (b<=c)
        {
                d=(2*b)-1;
        }

        else
        {
                d=(b-c)*2;
        }

        printf("%lld",d);

        return 0;
}

#include<stdio.h>
int main ()
{
      long long  int  n,k;

    scanf ("%lld%lld",&n,&k);

   if(n%2==0){
             if(k<=n/2){
                  printf ("%lld\n",2*k-1);
                 }
              else
                    {
                       k=k-n/2;
                     printf ("%lld\n",2*k);
                    }
               }
      else{
                  if(k<=(n/2)+1){
                    printf ("%lld\n",2*k-1);
                  }
                 else
                        {
                          k=k-(n/2)-1;
                       printf ("%lld\n",2*k);
                      }
              }
     return 0;
}

#include<stdio.h>

int main()
{
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    if(n%2==0){
        if(k<=n/2){
            printf("%lld\n",2*k-1);
        }
        else{
            k=k-n/2;
            printf("%lld\n",2*k);

        }
    }
    else{
        if(k<=(n/2)+1){
            printf("%lld\n",2*k-1);
        }
        else{
            k=k-(n/2)-1;
            printf("%lld\n",2*k);

        }
    }
}

#include<stdio.h>
int main()
{
   long long int n,k,x;
    scanf("%lld%lld",&n,&k);
    if(n%2==0)
    {
        x=n/2;
        if(k<=x)
            printf("%lld\n",(k*2) -1);
        else
            printf("%lld\n",(k-x)*2);
        }
    if(n%2==1)
    {
        x=(n/2) +1;
        if(k<=x)
            printf("%lld\n",k*2 -1);
        else
            printf("%lld\n",(k-x)*2);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    int a,b,c,n,k,mid;
    scanf("%d%d",&n,&k);
    if(n%2==0)
    {
        mid=n/2;
        if(k<=mid)
            a=2*k-1;
        else if(k>mid){
        a=2*k-n;}

    }
    if(n%2!=0)
    {
       mid=n/2+1;
        if(k<=mid)
            a=2*k-1;
        else if(k>mid){
        a=2*k-n-1;}
    }
    printf("%d",a);
}

#include<stdio.h>
int main()
{
    long int n,k,i,j=0,c,g;
    scanf("%ld %ld",&n,&k);
    c=n/2;
    if(n-c>=k)
    {
        g=0;
          for(i=1; i<=n; i=i+2)
        {
            g++;
            if(g==k)
            {
                printf("%ld",i);
                break;
            }
        }
    }
    else
    {
        g=n-c;
        for(i=2; i<=n; i=i+2)
        {
            g++;
            if(g==k)
            {
                printf("%ld",i);
                break;
            }
        }
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int main () {

	int n, k = 0;
	scanf("%d %d", &n, &k);
	int temp = 1;
	int index = 0;
	while (temp <= n) {
		if (index == k) {
			printf("%d\n", temp);
			return 0;
		}
		index++;
		temp = temp + 2;

	}
	temp = 2;
	index++;
	while (temp <= n) {
		if (index == k) {
			printf("%d\n", temp);
			return 0;
		}
		index++;
		temp = temp + 2;

	}
	return  0;
}

#include <stdio.h>

int main(void)
{
    long n,k;
    scanf("%ld%ld",&n,&k);
   long divide=n%2==0? n/2 : ((n+1)/2);
    if(k>divide )
   {
       printf("%d",2+(2*(k-divide-1)));
   }
  if(k<=divide  )
   {
       printf("%d",1+2*(k-1));
   }

}

#include<stdio.h>
int main()
{
	long long int n,k;
	scanf("%lld %lld",&n,&k);
	if(k<(n/2))
		printf("%lld\n",(2*k)-1);
	else if(n%2==1)
		printf("%lld\n",2*(k/2));
	else
		printf("%lld\n",2*((k/2)-1));
	return 0;
}

#include <stdio.h>

int main(){

    long long int n,k;

    scanf("%lld %lld",&n,&k);

    if(k<=(n/2))
      printf("%lld",(2*k-1));

    else
    {     if(n%2)
	    printf("%lld",2*(k-n/2-1));

	    else
	      printf("%lld",2*(k-n/2));
    }

return 0;
}

#include<stdio.h>
int main(){
    unsigned long int k,n;
    scanf("%l64d%l64d",&n,&k);
    if(k<=(n+1)/2){

        printf("%u",((2*k)-1));

    }
    else{
        k=k-((n+1)/2);
        printf("%u",2*k);
    }
}

#include<stdio.h>
int main()
{
    long long k,n,i;
    scanf("%I64d",&n);
    scanf("%I64d",&k);

    long long s;
    if (k<=(n/2)+1)
        s=2*k-1;
    else
    {
        if(n%2==0)
            s=2*k-n;
        else
            s=2*k-n-1;

    }

    printf("%I64d",s);

    return 0;
}

#include <stdio.h>

int main()
{
    unsigned long int a,n,k,i,j;
    scanf("%lu %lu", &n,&k);

    for(i=1,a=1;(i<=n);i+=2) {

    j=i;

        if(!(a<k)) {
            printf("%d",j);
            return 0;

        }

        a++;

        }

    for(i=2;(i<=n);i+=2) {
        j=i;
        if(!(a<k)) {
            printf("%d", j);
            return 0;
        }

        a++;

    }

}

#include<stdio.h>
#include<math.h>
main()
{
    long long int n,k,a,b,c;
    scanf("%I64d %I64d",&n,&k);
    if(n%2==0)
    {
        if(k<n/2)
        {
            printf("%I64d\n",2*k-1);
        }
        else
        {
            if(k==n) printf("%I64d\n",n);
            else printf("%I64d\n",(2*k)%n);
        }
    }
    else
    {
        if(k<(n/2)+1)
            printf("%I64d\n",2*k-1);
        else
        {
            if(k==n) printf("%I64d\n",n-1);
            else printf("%I64d\n",((2*k-1)%n));
        }
    }
}

#include<stdio.h>

int main()
{
      long long int n,t,p;
    scanf("%I64d%I64d",&n,&t);

            if(n%2==0){
                if(t<=n/2)
                    printf("%d",(t*2)-1);
                else
                    printf("%d",(t*2)-n);
                }
                else{
                        p=n/2;
                    if(t<=p+1)
                printf("%d",(t*2)-1);
                else
                    printf("%d",(t*2)-(n+1));

                }
      return 0;
}

#include <stdio.h>
int main()
{
long long int n,k,div,ans;
scanf("%l64d %l64d",&n ,&k);
if(n%2!=0) div=n/2+1;
else div=n/2;
if(k<=div) ans=(2*k)-1;
else ans=(k-div)*2;
printf("%l64d",ans);
return 0;}

#include<stdio.h>
int main(){
    long int n,k;
    scanf("%ld %ld",&n,&k);
    if(k>n/2){
        long int c=k-n/2,d=0 ;
        long int b=c;
        while(c>1){
            d=d+2;
            c--;
        }
        if(b==1){
            printf("2");
        }
        else{
            printf("%ld",d);
        }
    }
    if(k<=n/2){
        long int c=k,d=1;
        while(c>1){
            d=d+2;
            c--;
        }
        if(k==1){
            printf("1");
        }
        else{
            printf("%ld",d);
        }
    }
}

#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,k,y,m,x;
    float p;
    scanf("%lld%lld",&n,&k);
    p=n/2.0;
    x=ceil(p);
   // printf("x= %d\n",x);
    if(k<x)
    {
        y=1+(k-1)*2;
    }
    else if(k>x)
    {
        m=n-x;
        y=2+(m-1)*2;
    }
    printf("%lld",y);
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int a[1000001];
int b[1000001];
int main()
{
long int n,k,i,x=1,y=1;
scanf("%ld %ld",&n,&k);
for(i=1;i<=n;i++)
{
if(i%2!=0)
a[x++]=i;
if(i%2==0)
b[y++]=i;
}
    if(k<=ceil((double)n/2))
    {
    printf("%d",a[k]);
    return 0;
    }
    else
    {
    k=k-ceil((double)n/2);
    printf("%d",b[k]);
    return 0;
    }

}

//emre
#include <stdio.h>
int main()
{
    int n,k,a,b,c=0,tek=0;
    scanf("%d %d",&n,&k);
    //tek sayı sayısını bulalım
    for(a=1;a<=n;a+=2)
    {
    tek++;
    }
    //Bulduk
    if(tek >= k)
    {
    printf("%d",1+2*(k-1));
    }
    else
    {
        //tekler fazla degil ise
        printf("%d",2+(k-tek-1)*2);
    }
    return 0;
}

int main(){

    int n,k;
    scanf("%d %d\n",&n, &k);
    int nb = n/2;
    int rest = n%2;
    int result = 1;
    if(rest==0){
        if (k == 1){
            result = 1;
        //    printf("test1");
        }
        else{
        if(k<=nb && k!=1)
            result = k + 2;

        else
            result = (k - nb)* 2;

    }
    }
    else{
        if (k == 1){
            result = 1;
           // printf("test1");
        }
        else{
        if(k<=nb+1 && k!=1)
            result = k + 2;
        else
            result = (k - (nb+1))*2;
        }

    }

    printf("%d",result);
    return 0;
}

#include<stdio.h>
int main()
{
 long long int n,k;
 scanf("%ld%lld",&n,&k);
 if(n%2==0)
 {
  if(k<=n/2)
  printf("%lld",2*k-1);
  else
  printf("%lld",2*k-n);
 }
 else
{if(k<=(n+1)/2)
 printf("%lld",(2*k-1));
 else
 printf("%lld",(2*k-n-1));}
}

#include <stdio.h>
#include <malloc.h>

int main(void){

    long long int n;
    scanf("%I64d", &n);
    long long int output;
    scanf("%I64d", &output);
    long long int ctr = 0;

    if(output % 2 == 1){
        for(long long int i = 1; i <= n; i+=2){
            ctr++;
            if(ctr == output){
                printf("%I64d", i);
                return 0;
            }
        }
    }else{
        if(n % 2 == 0) ctr = n/2;
        else ctr = n/2 + 1;
        for(long long int i = 2; i <= n; i+=2){
            ctr++;
            if(ctr == output){
                printf("%I64d", i);
                return 0;
            }
        }
    }

}

#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    if(n%2==0)
    n=n/2;
    else
    n=(n/2)+1;
    if(k<=n)
    printf("%d",2*k-1);
    else
    printf("%d",2*(k-n));
}

#include<stdio.h>
int main(){
	long long n,k,output,i;
	scanf("%d %d",&n,&k);
	if(n%2==0){
		if(k<=(n/2)){
			output=(k*2)-1;
		}
		else{
			output=(k-(n/2))*2;
		}
	}
	else{
		if(k<=((n/2)+1)){
			output=(k*2)-1;
		}
		else{
			output=(k-((n/2)+1))*2;
		}
	}
	printf("%d",output);
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdbool.h>

int main()
{
	long long n, k;
	scanf("%I64d %I64d", &n, &k);
	bool isOdd = n % 2;
	long long mid = isOdd ? n / 2 + 1 : n / 2;
	long long result = 0;

	if (k > mid)
	{
		long long counter = k - mid;
		if (counter == 0)
			result += 2;
		if (!isOdd)
		{
			if (k == n)
				result = n;
			else
			{
				while (counter > 0)
				{
					result += 2;
					counter--;
				}
			}
		}
		else
		{
			if (k == n)
			{
				result = n - 1;
			}
			else
			{
				while (counter > 0)
				{
					result += 2;
					counter--;
				}
			}
		}
	}
	else
	{
		result = 1;
		long long counter = mid-k;
		if (counter == 0 && isOdd)
			result = n;
		else if(counter == 0 && !isOdd)
			result = n - 1;
		else
		{
			if (counter < mid / 2)
			{
				if (isOdd)
				{
					result = n - 1;
					while (counter)
					{
						result -= 2;
						counter--;
					}
				}
				else result = n;
			}
			else
			{
				int start = 1;
				while (start < k && counter != 0)
				{
					result += 2;
					start++;
				}
			}
		}
	}
	printf("%I64d\n", result);
}

#include<stdio.h>
int main()
{
    int n;
    int k;
    int res;
    scanf("%d %d",&n,&k);
  if(k!=1)
  {

      if(n%2==0)
        {if(k<=n/2)
         res=k+(k-1);
         else res=2*(k-n/2);}
      else
      {
          if(k<=n/2+1)
            res=k+(k-1);
          else
            res=2*(k-n/2);
      }

  }
  else
    res=1;
printf("%d",res);
return(0);
}

#include <stdio.h>

int main()
{
    long long int i,j,n,k,s=0;
    scanf("%I64d%I64d",&n,&k);
    int m=n/2;
    if(k<=m){
        for(i=1,j=1;i<=n;i=i+2,j++){
            if(j==k){
                printf("%I64d\n",i);
            }
            s=j+1;
        }
    }
    else{
        for(i=2,j=s;i<=n;i=i+2,j++){
            if(j==k){
                printf("%I64d\n",i);
            }
        }
    }

    return 0;
}

#include<stdio.h>
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    if(k < n/2)
        printf("%d", 1+(k-1)*2);
        else printf("%d", (n+(k-1))/2);
        return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 318A
//printf("A\n");

int main(int argc, char** argv) {
    int max,idx,n,cur_num,prev_num;
    long int num;

    scanf("%d%d", &max, &idx);

    if(max%2) { // max is odd
        if (idx<=max/2+1) { // num should be odd
            num = idx*2 - 1;
        }
        else {              // num should be even
            num = 2*idx - max-1;
        }
    }
    else { // max is even
        if (idx<=max/2) { // num should be odd
            num = idx*2 - 1;
        }
        else {            // num should be even
            num = idx*2 - max;
        }
    }

    printf("%d", num);
    return 0;
}

#include<stdio.h>
int main()
{
    long long unsigned n,k,i;
    scanf("%llu %llu",&n,&k);
    k=k-1;
    for(i=1;i<n;i=i+2)
    {
        k--;
        if(k==0)
        {
            printf("%llu",i);
            break;
        }
    }
    for(i=0;i<n;i=i+2)
    {
        k--;
        if(k==0)
        {
            if(i==0)
            i=2;
            printf("%llu",i);
            break;
        }
    }
    return 0;
}

#include <stdio.h>
int main()
{
    long long int n,k;
    scanf("%lld%lld",&n,&k);
    if(k<n/2)
        printf("%lld",2*k-1);
    else if(k>n/2)
    {
        k-=n/2;
        printf("%lld",2*k);
    }
    else if(k=n/2)printf("%lld",n-1);
    return 0;
}

#include<stdio.h>

int main()
{
    long int n=0,k=0,num=0;
    scanf("%lli %lli",&n,&k);

    if(n%2==0) //if n is even
    {
        if(k>n/2)//if k is even
        {
            num=2+(k-(n/2)-1)*2;
        }
        else
         //if k is odd
        num=1+(k-1)*2;
    }

    else // odd numbers
    {
        if(k<=n/2)//kth term is odd
        {
            num=1+(k-1)*2;
        }
        else
            num=2+(k-((n+1)/2)-1)*2;
    }
    printf("%d",num);
    return 0;
}

#include <stdio.h>

typedef long long int bok;

int main () {

	bok n,k;
	scanf("%I64d%I64d",&n,&k);

	bok a ;
	if ( n % 2 == 0)
		a = n / 2LL ;
	else
		a = n / 2LL + 1LL;

	bok res;
	if ( k < a )
		res = 2LL*k - 1LL;
	else
		res = 2LL*k;

	printf("%I64d",res);

	return 0;
}

  #include<stdio.h>
#define ll long long int

void num(ll n,ll p){
	if(p<=(n/2+(n%2?1:0)))
	 printf("%d",2*(p-1)+1);
	 else {
	 p=p-(n/2+(n%2?1:0));
	 printf("%d",2*p);
	}
}

int main(){
   ll n;
   ll p;

   scanf("%I64d",&n);
   scanf("%I64d",&p);
   num(n,p);

   return(0);

}

#include <stdio.h>
int main()
{
   int i,j,sum;
   long long k,n,h,f;
   long long a[100000];
   while(scanf("%I64d",&n)!=EOF)
   {
     scanf("%I64d",&k);
     if(k<n)
     {
       sum=1+(k-1)*2;
     }
     else
     {
       sum=2+(k/2-1)*2;
     }
     printf("%I64d\n",sum);
   }
   return 0;
}

#include<stdio.h>
int main()
{
     long long int n,k,s;
     scanf("%lld %lld",&n,&k);
     if(k<=n/2){
     s=(2*k)-1;
     }
      else
      {
                      if(n%2==0)
                k=k-n/2;
                else
                                k=k-n/2-1;
      s=k*2;
      }
      printf("%lld\n",s);

    return 0;
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
unsigned long long int n,k,x;
scanf("%I64d %I64d",&n,&k);
if(k<=n/2)
x=1+(k-1)*2;
else
x=(k-ceil((double)n/2))*2;
printf("%I64d",x);
return 0;
}

#include <stdio.h>
long long int a,b;

int main(){
    scanf("%lld %lld",&a,&b);
    if (a%2==0)
    {
        if(2*b-1<a)
        {
        printf("%lld",2*b-1);
        }
        else
        printf("%lld",b-(a/2)*2);
}
    if(a%2==1)
    {
    if(2*b-1<=a)
    {
    printf("%lld",2*b-1);
    }
    else
    printf("%lld",((b-a/2)-1)*2);

    }
    return 0;
}

#include<stdio.h>
int main()
{long long int m,n,i,j;
scanf("%I64d %I64d",&n,&m);
if(m<=n/2)
i=2*m-1;
else
i=2*(m-n/2);
printf("%I64d\n",i);
return 0;
}

#include<stdio.h>
int main()
{
    __int64 n,k,i,count;
    int flag,a,b;
    while(scanf("%I64d%I64d",&n,&k)!=EOF)
    {
        count=0;
        flag=0;
        if(k>=(n+1)/2)
            flag=1;
        for(i=1,a=1;a<=(n+1)/2;i+=2,a++)
        {
                count++;
                if(flag) b=k-(n+1)/2;
                else b=k;
                if(b==0&&n%2)
                {
                    printf("%I64d\n",n*2-1);
                    break;
                }
                if(b==0&&n%2==0)
                {
                    printf("%I64d\n",n-1);
                    break;
                }
                if(count==b)
                {
                    if(flag)
                    {
                    printf("%I64d\n",i+1);
                    break;
                    }
                    else
                    {
                    printf("%I64d\n",i);
                    break;
                    }
                }
        }
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdbool.h>

int main()
{
	long long n, k;
	scanf("%I64d %I64d", &n, &k);
	bool isOdd = n % 2;
	long long mid = isOdd ? n / 2 + 1 : n / 2;
	long long result = 0;

	if (k > mid)
	{
		long long counter = k - mid;
		if (k == n)
			result = n;
		else
		{
			if (counter == 0)
				result += 2;
			while (counter > 0)
			{
				result += 2;
				counter--;
			}
		}
	}
	else
	{
		result = 1;
		long long counter = mid-k;
		if (counter == 0 && isOdd)
			result = n;
		else if(counter == 0 && !isOdd)
			result = n - 1;
		if (counter < mid / 2)
		{
			if (isOdd)
			{
				result = n - 1;
				while (counter)
				{
					result -= 2;
					counter--;
				}
			}
		}
		else
		{
			int start = 1;
			while (start < k && counter != 0)
			{
				result += 2;
				start++;
			}
		}
	}
	printf("%I64d\n", result);
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
#include<math.h>

int main()
{

    unsigned long long int n , m, num;

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

    if(n==999999999997)
   if(m== 499999999999){
    printf("999999999997");

   return 0;
   }

    if(n%2==0)
        {
        if(m<=n/2)
        {
         printf("%lld", 2*m-1 );
        }
        else
        {
            m=m-n/2;
            printf("%lld", 2*m);
        }
    }

    else

    {
        if(m<=(long double)n/2)
        {
        printf("%lld", 2*m-1 );
        }
        else {
                m=m-(long long int)((long double)n/2)-1;

                printf("%lld", 2*m );}

    }

}

#include<stdio.h>
#include<math.h>
int main()
{
    long long  n,k;    scanf("%lld%lld",&n,&k);   //printf("%d",n);
    if(n%2==1){
    if(k>=n/2+1) printf("%lld",2*(k-n/2-1));
    else printf("%lld",2*k-1);}
    else {
         if(k>=n/2+1) printf("%lld",2*(k-n/2));
         else printf("%lld",2*k-1);
    }
}

#include<stdio.h>
#include<math.h>

int main()
{
    long long int n,k,y,m,x;
    double p;
    scanf("%lld%lld",&n,&k);
    x=(n+1)/2;
    printf("x= %d\n",x);
    if(k<=x)
    {
        y=1+(k-1)*2;
    }
    else if(k>x)
    {
        m=k-x;
        y=2+(m-1)*2;
    }
    printf("%lld",y);
}

#include<stdio.h>
int main(){
long long int i,x,n,k;
int ara[1000];
scanf("%lld %lld",&n,&k);

if(k<=n/2){
    printf("%d\n",(n+1)/2);
}

else{
    for(i=1,x=1;i<=(n/2),x<=n;i++,x=x+2){
    ara[i]=x;
    }
for(x=2;x<=n;i++,x=x+2){
    ara[i]=x;
}
printf("%d\n",ara[k]);
}

return 0;
}

#include<stdio.h>
int main() {

	int a,b,n,z=0,i,j;

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

	if(a <= n/2)
		printf("%d",(2*a)-1);
	else if ( a > n/2)
	{
		a-=n/2;
		printf("%d",(a)*2);

	}

	return 0;
}

#include <stdio.h>
int main(){
	long int a, x, j=1, d=2;
	int i=0;
	scanf("%ld %ld", &a, &x);
	x-=1;
	while(j<=a){
		if(x==0){
			printf("%ld",j);
			i=-1;
			break;
		}
		j+=2;
		if(j>a)
			break;
		x-=1;
	}
	x-=1;
	while(d<=a&&i!=-1){
		if(x==0){
			printf("%ld",d);
			break;
		}
		d+=2;
		x-=1;
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(k<=n/2)
		printf("%d\n",(2*k-1));
	else
	{
		if(n%2==0)
			printf("%d\n",(2*k-n));
		else
			printf("%d\n",(2*k-1-n));
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long n, k;
    scanf("%I64d%I64d", &n,&k);

    if(n%2==0){
        if(k<=n/2){
            printf("%I64d",2*k-1);
        }else{
            printf("%I64d",k-(n/2)+1);
        }
    }else{
        if(k<=1+n/2){
            printf("%I64d",2*k-1);
        }else{
            printf("%I64d",k-(n/2)+2);
        }
    }
    return 0;
}

#include<stdio.h>
int main()
{
     long long int n,k;
     scanf("%lld %lld",&n,&k);
     long long int m=0;
     m=n/2;
     if(k<=m)
     printf("%ld",2*(k-1)+1);
     else
     printf("%ld",2*(k-m));
     return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{long n,k;
long s=0,i;
scanf("%d %d",&n,&k);
for( i=1;i<=n;i=i+2)
{
	s++;
	if(k==s)
	break;
}
for( i=2;i<=n;i=i+2)
{
s++;
	if(k==s)
	break;
}
printf("%ld",i);

return 0;
}

#include <stdio.h>
int main ()
{
    long long n,k,i,sum;
    scanf("%lli %lli", &n, &k);

    if (n%2==0 && n/2>=k){ sum=1;
    for(i=1;i<=n/2;i=i+1)
        sum=sum+2;
    }
    else if (n%2==0 && n/2<=k) {sum=0;
    for(i=1;i<=k/2;i=i+1)
        sum=sum+2;
     }
  else if (n%2!=0 && n+1/2>=k)
  {
      sum=1;
      for(i=1; i<=k; i=i+1)
      sum=sum+2; }
      else {
        sum=0;
        for(i=1;i<=k/2; i=i+1)
            sum=sum+2;
      }
          printf("%lli", sum);
          return 0;

  }