akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	int arr[101];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}	
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=2*min(arr[i],k-arr[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

co = 0

po = a[0]

fl = 0

for i in range(1,n):
    if fl != 0:
        if fl == 1:
            if po > a[i]:
                co += 1
                fl = 0
            po = a[i]
        else:
            if po < a[i]:
                co += 1
                fl = 0
            po = a[i]


    else:
        if po > a[i]:
            fl = -1
        elif po < a[i]:
            fl = 1
        else:
            fl = 0
        po = a[i]

print(co+1)










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

int main() {
  string S;
  cin >> S;
  
  if (S.at(0)==S.at(1) && S.at(0)==S.at(2)){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3620
<?php
$num_cards = trim(fgets(STDIN));

$arr = [];
while ($num_cards-- > 0) {
  $input = trim(fgets(STDIN));
  List($suit, $num) = explode(" ", $input);
  $arr[$suit.$num] = 1;
}

$suits = ["S", "H", "C", "D"];
foreach( $suits as $suit ) {
  for ($num=1; $num<=13; $num++) {
    if (! array_key_exists($suit.$num, $arr)) {
      echo "{$suit} {$num}" . PHP_EOL;
    }
  }
}

Measured memory_bytes: 15424
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {     
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> v[i][j];
        }
    }
    long long int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) {
                if (v[i][j] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            if (i < j) {
                res += v[i][j];
                for (int k = 0; k < n; k++) {
                    if (k == i || k == j) continue;
                    if (v[i][k] + v[k][j] == v[i][j]) {
                        res -= v[i][j];
                        break;
                    }
                }
                for (int k = 0; k < n; k++) {
                    if (k == i || k == j) continue;
                    if (v[i][k] + v[k][j] < v[i][j]) {
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 4000
n = int(input())

def cnt(x):
    c = 0
    for i in range(1, x+1, 2):
        if x % i == 0:
            c += 1
    return c

def ans(x):
    c = 0
    for i in range(1, x+1):
        if cnt(i) == 8:
            c += 1
    return c

print(ans(n))



Measured memory_bytes: 2940
#include <stdio.h>
int main (void){
	int a;
	char b[100000];
	int i=1;
	int count=0;
	scanf("%d %s",&a,b);
	do{
		if(b[i-1]=='O'&&b[i]=='X'||b[i-1]=='X'&&b[i]=='O'){
			count++;
			i+=2;
		}
		else i++;
	}while(i<=a);
	printf("%d\n",count);
	return 0;
}



Measured memory_bytes: 2000
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*n
    for i,h_ele in enumerate(h):
        if i > 0:
            p = max(i-k,0)
            dp[i] = min(k+abs(l-h_ele) for k,l in zip(dp[p:i],h[p:i]))

    print(dp[n-1])
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 79004
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
K = lines[0][1]

exp = []
for i in 1..N do
  exp[i-1] = lines[1][i-1].to_f * 0.5 + 0.5
end

sum = 0
for i in 1..K do
  sum += exp[i-1]
end

max = sum
for i in 1..(N-K) do
  sum = sum - exp[i-1] + exp[i+K-1]
  if sum > max then
    max = sum
  end
end
  
print max

Measured memory_bytes: 17620
N = int(input())
A = list(map(int, input().split()))
ans = 0
d = {}
d[1 - A[0]] = 1
base1 = 0
base2 = 1
for a in A[1:]:
    _a = a - base1
    _a_ = 1 - a - base2
    if _a in d:
        ans += d[_a]
    if _a_ in d:
        d[_a_] += 1
    else:
        d[_a_] = 1
    base1 += 1
    base2 += 1

print(ans)

Measured memory_bytes: 41500
import java.util.Scanner;
 
class Main {
    	public static void main(String[] args) {
        	Scanner sc = new Scanner(System.in);
        	int[] x = new int[7];
        	for(int i = 1; i < 7; i++) {
            		x[i] = sc.nextInt();
        	}

        	char[] y = sc.next().toCharArray();
        	for(int i = 0; i < y.length; i++) {
            		if (y[i] == 'N') {
                		x[0] = x[1];
                		x[1] = x[2];
                		x[2] = x[6];
                		x[6] = x[5];
                		x[5] = x[0];
            		}else if (y[i] == 'S') {
                		x[0] = x[1];
                		x[1] = x[5];
                		x[5] = x[6];
               	 		x[6] = x[2];
                		x[2] = x[0];
            		}else if (y[i] == 'E') {
		                x[0] = x[1];
		                x[1] = x[4];
		                x[4] = x[6];
		                x[6] = x[3];
		                x[3] = x[0];
            		}else {
		                x[0] = x[1];
		                x[1] = x[3];
		                x[3] = x[6];
		                x[6] = x[4];
		                x[4] = x[0];
            		}
        	}
        	System.out.println(x[1]);
    	}
}

Measured memory_bytes: 17360
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	int n;
	vi childs[310];
	bool visit[310];
	int deep[310][2];
	int dep = 0;
	void dfs(int x){

		visit[x] = 1;
		deep[x][0] = dep;
		FORR(x1,childs[x])if(!visit[x1]){
			dep++;
			dfs(x1);
		}
		dep++;
		deep[x][1] = dep;
	}




	void solve(){
		
		in(n);
		FOR(i,0,n){
			ini(x);
			ini(x1);
			FOR(i1,0,x1){
				ini(tmp1);
				childs[x].push_back(tmp1);
			}
		}
		int tmp = 0;
		while(tmp!=n){
			FOR(i,1,n+1){if(visit[i])tmp++;else{
				tmp = 0;
				dep++;
				dfs(i);
				i = 0;
			}}
		}
		FOR(i,1,n+1){
			out(i,deep[i][0],deep[i][1]);
		}








		
		
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



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

int main()
{
    int N, M;
    cin >> N >> M;
    
    priority_queue<long long> que;
    for (int i = 0; i < N; i++) {
        long long A;
        cin >> A;
        que.push(A);
    }

    for (int i = 0; i < M; i++) {
        long long t = que.top();
        que.pop();
        que.push(t/2);
    }
    long long res = 0;
    while (!que.empty()) res += que.top(), que.pop();
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using d = double;
 
int main(){
  string s;
  cin >> s;
  rep(i,(s.size()+1)/4){
    if(s[i]!=s[(s.size()-1)/2-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i,(s.size()+1)/4){
    if(s[i+(s.size()+3)/2-1]!=s[s.size()-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
	int a,b,i,j;
	scanf("%d %d",&a,&b);
	while(1)
	{
	 if(a == 0 && b == 0)
	 {
		 break;
	 }
	 for(i = 0;i < a;i++)
	 {
		 for(j = 0;j < b;j++)
		 {
			 if((i + j) % 2 == 0)
			 {
				printf("#");
			 }
			 else
			 {
				 printf(".");
			 }
		 }
		 printf("\n");
	 }
	 printf("\n");
	 scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 572
import sys
input = sys.stdin.readline

M, MOD = 3005, 998244353

dp = [[0 for i in range(M)] for j in range(M)]
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp[0][0] = 1
for i in range(n):
    for j in range(s + 1):
        dp[i + 1][j] += dp[i][j] * 2
        dp[i + 1][j] %= MOD
        if s >= j + a[i]:
            dp[i + 1][j + a[i]] += dp[i][j]
            dp[i + 1][j + a[i]] %= MOD
print(dp[n][s])

Measured memory_bytes: 148188
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
set<int> nums[200001];
int main(){
  prep();
  long long n, k;
  cin >> n >> k;
  int arr[n];
 
  for (int i=0; i<n; i++){
      cin >> arr[i];
      nums[arr[i]].insert(i);
  }
  if (n == 1){
      if (k%2 == 1){
          cout << arr[0];
      }
      return 0;
  }
  int graph[200001];
  int graph2[200001];
  memset(graph, -1, sizeof(int)*200001);
  memset(graph2, -1, sizeof(int)*200001);
  for (int i=0; i<n; i++){
      set<int> mine = nums[arr[i]];
      set<int>::iterator it = mine.upper_bound(i);
      if (it == mine.end()){
          graph[i] = *(mine.begin());
      }else{
          graph[i] = *it;
          graph2[i] = *it;
      }
  }
  
  int cur = (graph[0]+1)%n;
  int times = 1+(cur == 1);
  while (cur != 0){
      int before = cur;
      if (graph[cur] <= before){
          //cout << graph[cur] << " " << before << endl;
          times++;
      }
      cur = (graph[cur]+1)%n;
  }
  //cout << times << endl;
  if (k%times == 0){
      return 0;
  }
  int other = k%times;
  cur = 0;
  times = 0;
  while (times < other-1){
      int before = cur;
      if (graph[cur] <= before){
          times++;
      }
      cur = (graph[cur]+1)%n;
      
  }
  vector<int> res;
  while (cur < n){
      int next = graph2[cur];
      if (next == -1){
          res.push_back(arr[cur]);
          cur++;
      }else{
          cur = graph2[cur]+1;
      }
  }
  for (int i=0; i<res.size(); i++){
      cout << res[i] << " ";
  }
  return 0; 
}

Measured memory_bytes: 23540
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	long long cnt=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++){
				int mi=min(i,j);
				mi=min(mi,k);
				for(int t=mi;t>=1;t--){
					if(i%t==0&&j%t==0&&k%t==0){
						cnt+=t;
						break;
					}
				}
			}
	cout<<cnt<<endl;  
	return 0; 
}


Measured memory_bytes: 3644
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
ll test(ll i, string &s, vector<char> &t, vector<char> &d) {
    ll q = t.size(), n = s.size();
    REP(j, q) {
        if (s[i] == t[j]) {
            switch (d[j]) {
                case 'L':
                    i--;
                    break;
                case 'R':
                    i++;
                    break;
            }
        }
        if (i < 0 || n <= i) break;
    }
    return i;
}

// 処理内容
int main() {
    
    ll n, q;
    string s;
    cin >> n >> q >> s;
    vector<char> t(q), d(q);
    REP(i, q) cin >> t[i] >> d[i];

    ll lng = -1, lok = n;
    while (abs(lok - lng) > 1) {
        ll lmd = (lng + lok) / 2;
        if (test(lmd, s, t, d) < 0) {
            lng = lmd;
        } else {
            lok = lmd;
        }
    }
    ll rng = n, rok = -1;
    while (abs(rok - rng) > 1) {
        ll rmd = (rng + rok) / 2;
        if (test(rmd, s, t, d) >= n) {
            rng = rmd;
        } else {
            rok = rmd;
        }
    }

    cout << max(0LL, rok - lok + 1) << endl;
    
}

Measured memory_bytes: 900
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int K = sc.nextInt();
        Set<String> set = new HashSet<String>();
        for(int i=0;i<K;i++){
          for(int j=0;j<S.length()-i;j++){
            set.add(S.substring(j,j+i+1));
          }
        }
        List<String> list = new ArrayList<>(set);
        Collections.sort(list);
        System.out.println(list.get(K-1));
    }
}

Measured memory_bytes: 26196
module Main where

import Data.Functor
import Data.Char

main :: IO ()
main =  do
 { [n] <- getIntegers
 ; if n == 0 then done
   else print (sum (map digitToInt (show n))) >> main
 }

done :: IO ()
done = return ()

getIntegers :: IO [Integer]
getIntegers = map read . words <$> getLine

Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=100010;
ll a,b,d,c,e,x,y,z,k,m,n,l,q,ans=0;
double aa,bb;
vl v1,v2,v3;
vp vp1,vp2;
string s1,s2;
ll solve(void){
    a=0;
}
int main(){
    cin>>a>>b>>c>>n;
    rep(i,n/a+1){
        rep(j,n/b+1){
            if((n-i*a-j*b)%c==0&&n-i*a-j*b>-1)ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, a, b; cin >> n >> a >> b;

	int ans = INF;

	ans = min(ans, n*a);
	ans = min(ans, b);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


const int N = 200005;
int cc, n, A[N], B[N], sz[N], par[N], edges[N];
map<int, int> compress;
vector<int> v1, v2;

int root(int v){
    if(v == par[v]) return v;
    return par[v] = root(par[v]);
}


void unite(int a, int b){
    a = root(a), b = root(b);
    if(a == b){
        edges[a]++;
        return;
    }
    if(sz[a] < sz[b])   swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
    edges[a] += 1+edges[b];
}



int main(){
 
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);

    scanf("%d", &n);
    int xorval = 0;
    for(int i=0;i<n;i++){
        scanf("%d", &A[i]);
        compress[A[i]];
        xorval ^= A[i];
        v1.pb(A[i]);
    }
    A[n] = xorval;
    compress[A[n]];
    v1.pb(xorval);

    xorval = 0;
    for(int i=0;i<n;i++){
        scanf("%d", &B[i]);
        compress[B[i]];
        xorval ^= B[i];
        v2.pb(B[i]);
    }
    B[n] = xorval;
    compress[B[n]];
    n++;
    v2.pb(xorval);

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    if(v1 != v2){
        printf("-1\n");
        return 0;
    }


// for(int i=0;i<n;i++)    cout<<A[i]<<" ";cout<<endl;
// for(int i=0;i<n;i++)    cout<<B[i]<<" ";cout<<endl;

    cc = 0;
    for(auto &it : compress)
        it.ss = ++cc;
    for(int i=0;i<n;i++){
        A[i] = compress[A[i]];
        B[i] = compress[B[i]];
    }

// for(int i=0;i<n;i++)    cout<<A[i]<<" ";cout<<endl;
// for(int i=0;i<n;i++)    cout<<B[i]<<" ";cout<<endl;

    for(int i=1;i<=cc;i++){
        sz[i] = 1;  par[i] = i; edges[i] = 0;
    }

    for(int i=0;i<n;i++)
        if(A[i] != B[i])
            unite(A[i], B[i]);

// for(int i=1;i<=cc;i++)  cout<<sz[i]<<" ";cout<<endl;
// for(int i=1;i<=cc;i++)  cout<<par[i]<<" ";cout<<endl;
// for(int i=1;i<=cc;i++)  cout<<edges[i]<<" ";cout<<endl;

    int ans = edges[root(A[n-1])] - (A[n-1] != B[n-1]);
    for(int i=1;i<=cc;i++)
        if(root(i) == i && sz[i] > 1 && root(i) != root(A[n-1]))
            ans += edges[i]+1;

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







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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

int main(){
    ii3(a,b,c);
    if(a > b) swap(a, b); if(b > c) swap(b, c); if(a > b) swap(a, b);
    int ans = 0;
    ans += (c-a)/2 + (c-b)/2;
    a = (c-a)%2; b = (c-b)%2;
    if(a == 1 && b == 1) ans += 1;
    else if(a + b == 1) ans += 2;
    out(ans);
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    cout << min(N % K, K - N % K);
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    long long n,m,num,s,rec,ans=0;
    cin>>n>>m;
    vector<long long>x(m),d(m-1);
    rep(i,m)cin>>x[i];
    sort(x.begin(),x.end());
    rep(i,m-1)d[i]=abs(x[i]-x[i+1]);
    sort(d.begin(),d.end());
    rep(k,n-1)d.pop_back();
    s=d.size();
    rep(h,s)ans+=d[h];
    cout<<ans;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef vector<pair<int , int>> vpii;
    typedef pair<int , int> pii;
    typedef pair<long long  , long long> pll;
    typedef pair<double , double> pdd;
    #define eb emplace_back;
    #define mp make_pair;
     
    int main(){
        int n , m;
        cin>>n>>m;
        cout<<(n*(n-1))/2 + (m*(m-1))/2;
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int n,k; cin >> n >> k;
  vector<int> p(n); rep(i,n) cin >> p.at(i);
  sort(p.begin(),p.end());
  ll sum = 0;
  rep(i,k) {
    sum += p.at(i);
  }
  cout << sum << endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll a,b,c,i,n,r;
   cin>>n;
   ll arr[n+1]={0},arr1[n+1]={0},arr2[n+1]={0};
   for(i=1;i<=n;i++)
    cin>>arr[i];
   c=inf;
   for(i=1;i<=n;i++)
    arr1[i]=arr1[i-1]+arr[i];
   arr2[n]=arr[n];
   for(i=n-1;i>=1;i--)
    arr2[i]=arr2[i+1]+arr[i];
   for(i=1;i<n;i++)
   {
       r=abs(arr1[i]-arr2[i+1]);
       c=min(c,r);
   }
   cout<<c<<endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {

	int N, ans = 0;
	double D;
	cin >> N >> D;
	long int X[200000], Y[200000];
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
	}

	for (int i = 0; i < N; i++) {
		if (sqrt(X[i] * X[i] + Y[i] * Y[i]) <= D) {
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[]=br.readLine().split(" ");
		int n =Integer.parseInt(line[0]);
		String [] sort =new String[n];

		for (int i = 0; i < sort.length; i++) {
			sort[i] = br.readLine();
		}

		Arrays.sort(sort);

		StringBuilder answer =new StringBuilder();

		for(int i=0;i<sort.length;i++) {
		answer.append(sort[i]);
		}

		System.out.println(answer);
	}

}


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

using namespace std;
#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main ()
{
  vector<int> p;
  int K,N,b,res;

  cin >> N >> K;

  REPI(N)
  {
    cin >> b;
    p.push_back (b);
  }

  sort (p.begin (), p.end ());

  res = 0;
  
  REPI(K)
  {
    res += p[i];
  }

  cout << res << endl;
  return 0; 
}

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

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

	int n;
	cin >> n;

	int cnt = 0;
	bool ok = true;

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

		if(p == '(')
			cnt += x;

		else {
			cnt -= x;
			if(cnt < 0)
				ok = false;
		}
	}

	if(cnt)
		ok = false;

	cout << (ok ? "YES" : "NO") << endl;


	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
  ll N, W;
  vector<ll> vec[4];
  cin >> N >> W;
  ll w, v;
  cin >> w >> v;
  vec[0].push_back(v);
  ll w1 = w;
  for(int i = 2; i <= N; i++){
    cin >> w >> v;
    vec[w - w1].push_back(v);
  }
  for(int i = 0; i < 4; i++){
    sort(vec[i].begin(), vec[i].end());
    reverse(vec[i].begin(), vec[i].end());
  }
  ll max_v = 0;
  for(int i = 0; i <= vec[0].size(); i++){
    for(int j = 0; j <= vec[1].size(); j++){
      for(int k = 0; k <= vec[2].size(); k++){
	for(int l = 0; l <= vec[3].size(); l++){
	  if(w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l > W) continue;
	  ll sum = 0;
	  for(int i_ = 0; i_ < i; i_++){
	    sum += vec[0][i_];
	  }
	  for(int j_ = 0; j_ < j; j_++){
	    sum += vec[1][j_];
	  }
	  for(int k_ = 0; k_ < k; k_++){
	    sum += vec[2][k_];
	  }
	  for(int l_ = 0; l_ < l; l_++){
	    sum += vec[3][l_];
	  }
	  if(sum > max_v) max_v = sum;
	}
      }
    }
  }
  cout << max_v << endl;
  return 0;
}


Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
#あまりの体積を求める
y=a*a*b-x
#辺cを求める
c=(2*y)/(a*a)
#c>bなら台形
if c<=b:
    print(math.degrees(math.atan(c/a)))
else:
    c=(2*x)/(a*b)
    print(math.degrees(math.atan(b/c)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	string str;
	bool n=0,w=0,s=0,e=0;
	cin>>str;
	each(it,str){
		if((*it)=='N')n=true;
		if((*it)=='W')w=true;
		if((*it)=='S')s=true;
		if((*it)=='E')e=true;
	}
	cout<<(n==s&&w==e?"Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        mp[tmp] = (mp.count(tmp) != 0) ? mp[tmp] + 1 : 1;
    }
    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if (itr->second > itr->first) ans += itr->second - itr->first;
        else if (itr->second < itr->first) ans += itr->second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,j) for(int i=0;i<j;i++)

int main(){

	int dai[5][4][11] = {};
	int n;
	cin >> n;

	rep(i,n){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		dai[b][f][r] += v;
	}

	for(int j = 1; j < 5; j++){
		if(j != 1) cout << "####################" << "\n";
		for(int k = 1; k < 4; k++){
			for(int l = 1; l < 11; l++){
				cout << " ";
				cout << dai[j][k][l];
			}
			cout << "\n";
		}
	}

	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll k;
  cin >> k;
  vector<ll> a(50);
  rep(i, 50) a[i] = i;

  rep(i, k % 50) rep(j, 50) {
    if (i == j)
      a[j] += 50;
    else
      a[j]--;
  }

  rep(i, 50) a[i] += k / 50;

  cout << 50 << endl;
  rep(i, 50) cout << a[i] << ' ';
  cout << endl;
}


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

int main(){
  string s;
  int i;
  cin >> s;
  int n = s.size();
  int count_1 = 0;
  int count_0 = 0;
  rep(i,n,0){
    if(s[i] == '1') count_1++;
    else if(s[i] == '0') count_0++;
  }
  if(count_1 > count_0) cout << count_0 * 2 << endl;
  else if(count_0 > count_1) cout << count_1 * 2 << endl;
  else cout << count_1 * 2 << endl;
  return 0;
}


Measured memory_bytes: 512
n = int(input())
A = [int(i) for i in input().split()]

if n % 2 != 0:
    r = A[1::2]
    l = A[::2]
else:
    r = A[::2]
    l = A[1::2]
l.reverse()
print(" ".join(map(str, l + r)))

Measured memory_bytes: 30404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll NINF = -1e18;

// THINK: INT vs LONG LONG?

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

	int n; cin >> n;
	vector<pair<long long, long long>> a(n);
	vector<ll> sums(n);
	vector<ll> diffs(n);
	ll mxS = NINF;
	ll mxD = NINF;
	ll mnD = INF;
	ll mnS = INF;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
		ll s = a[i].first + a[i].second;
		ll d = a[i].first - a[i].second;
		mxS = max(mxS, s);
		mnS = min(mnS, s);
		mxD = max(mxD, d);
		mnD = min(mnD, d);
	}
	// sort(sums.begin(), sums.end());
	// sort(diffs.begin(), diffs.end());
	ll ans = 0;
	for (auto point: a) {
		ll x = point.first;
		ll y = point.second;
		ll d1 = abs(x + y - mxS);
		ll d2 = abs(x - y - mxD);
		ll d3 = abs(x + y - mnS);
		ll d4 = abs(x - y - mnD);
		ans = max({ans, d1, d2, d3, d4});
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9540
#include<iostream>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

map <int, bool> a;

int main(){
        int N;
        cin>>N;
        ll res[2]={0};
        for(int i=0;i<N;i++){
                int aa;
                cin>>aa;
                if(a[aa]==false)
                        a[aa]=true;
                else if(a[aa]==true)
                        a[aa]=false;
                if(a[aa]==false){
                        if(res[0]<aa){
                                if(res[1]<aa){
                                        res[0]=res[1];
                                        res[1]=aa;
                                }
                                else{
                                        res[0]=aa;
                                }
                        }
                }
        }
        cout<<res[0]*res[1]<<endl;
        return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define N int(2e5+5)
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    if((n-1)%(k-1)) cout << (n-1)/(k-1)+1;
    else cout << (n-1)/(k-1);
    return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(){
	kaijo[0]=1;
	for(int i=1;i<=2000000;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}

int comb(int a,int b){
	if(!kaijo[0])init_fact();
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}

double dist(double ax,double ay,double bx,double by){
	return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}

signed main(){
	string s;
	cin>>s;
	if(s=="SAT")cout<<1<<endl;
	if(s=="FRI")cout<<2<<endl;
	if(s=="THU")cout<<3<<endl;
	if(s=="WED")cout<<4<<endl;
	if(s=="TUE")cout<<5<<endl;
	if(s=="MON")cout<<6<<endl;
	if(s=="SUN")cout<<7<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  vector<ll> ps(n+1,0),s(n+1,0);
  rep(i,n){
    s[i+1] = s[i]+a[i];
    if(a[i] > 0)ps[i+1] = ps[i]+a[i];
    else ps[i+1] = ps[i];
  }
  ll res = -(1ll << 60);
  for(int i = 0;i+k <= n;i++){
    ll sum = 0;
    sum = ps[i]-ps[0]+ps[n]-ps[i+k];
    sum += max(s[i+k]-s[i],0ll);
    res = max(res,sum);
  }
  cout << res << endl;




  return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,s,i;cin >> n >> k >> s;
  int a[n];
  for(i=0;i<k;i++) a[i] = s;
  if(s==1000000000){
    for(i=k;i<n;i++) a[i] = 3;
  } else {
    for(i=k;i<n;i++) a[i] = 1000000000;
  }
  for(i=0;i<n;i++) cout << a[i] << " ";
  cout << endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int f(ll a, ll b) {
  int res = 0;
  while (a > 0 || b > 0) {
    a /= 10;
    b /= 10;
    ++res;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = INT_MAX;
  for(ll i = 1; i * i <= n; ++i) {
    if(n % i) continue;
    ans = min(ans, f(i, n / i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	x := getNextInt(scanner)
	fmt.Fprintln(writer, lcm(x, 360)/x)
}
func gcd(m, n int) int {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}
func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 1816
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
int N,M,L,w;
vector<int> cs[3];
int p3[8];
ll C[421][421];
bool acc(int id,int* mycnt){
	if(id>60) return false;
	mycnt[id]++;
	return true;
}
int main(){
	p3[0]=1;
	rep(i,7) p3[i+1]=p3[i]*3;
	rep(i,421){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<min(i,8);j++) C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
	while(true){
		cin>>N>>M>>L;
		if(N==0) break;
		rep(i,3) cs[i].clear();
		w=0;
		rep(i,L){
			string s;
			cin>>s;
			if(s[0]=='*') w++;
			else cs[s[0]-'a'].pb(s.size()-1);
		}
		if(cs[0].empty()&&!cs[1].empty()) swap(cs[0],cs[1]);
		if(cs[1].empty()&&!cs[2].empty()) swap(cs[1],cs[2]);
		if(cs[0].empty()&&!cs[2].empty()) swap(cs[0],cs[2]);
		int n=3;
		if(cs[2].empty()) n=2;
		if(cs[1].empty()) n=1;
		if(cs[0].empty()) n=3;
		ll ans=0;
		rep(i,p3[L-1]){
			int a[8]={},e[8]={},tmp=i,cnt[61]={};
			int gap=0,eq=0;
			rep(j,L-1){
				a[j]=tmp%3;
				tmp/=3;
				if(a[j]==2) gap++;
				if(a[j]==0) eq++;
			}
//			if(gap>=n) continue;
			rep(j,L-1){
				if(a[j]==2){
					e[j+1]=(e[j]/10+1)*10;
				}else{
					e[j+1]=e[j]+a[j];
				}
			}
			rep(j,L) cnt[e[j]]++;
			bool can=0;
			rep(j,61) if(cnt[j]>N) goto hoge;
			rep(j,L) rep(k,L) rep(h,L){
				int mycnt[61]={};
				bool ok=1;
				rep(jj,cs[0].size()) if(!acc(e[j]+cs[0][jj],mycnt)) ok=0;
				rep(kk,cs[1].size()) if(!acc(e[k]+cs[1][kk],mycnt)) ok=0;
				rep(hh,cs[2].size()) if(!acc(e[h]+cs[2][hh],mycnt)) ok=0;
				ll co=1;
				rep(p,61){
					if(cnt[p]<mycnt[p]) ok=0;
				}
				if(ok){
					can=1;
					goto hoge;
				}
			}
			hoge:
			if(can){
				ll co=1;
				rep(p,61) co*=C[N][cnt[p]];
//				printf("%d,%d,%d  ->  co=%lld\n",a[2],a[1],a[0],co);
//				show(M-(L-1-eq));
//				show(gap+1);
				if(M-(L-1-eq)<0||M-(L-1-eq)<gap+1) continue;
//				printf("%d,%d,%d  ->  narabe=%lld\n",a[0],a[1],a[2],C[M-(L-1-eq)][gap+1]);
				co*=C[M-(L-1-eq)][gap+1];
				ans+=co;
//				printf("%d,  %lld\n",i,co);
			}else{
//				printf("%d,no\n",i);
			}
		}
//		printf("ans=%lld\nC[][]=%lld\n",ans,C[N*M][L]);
		printf("%.12f\n",(double)ans/C[N*M][L]);
	}
}

Measured memory_bytes: 2648