akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  string S;
  cin >>S;
  vector<int> A(N,0),B(N,0);
  int count=0;
  for(int i=0; i<N; i++){
    if(S[i]=='W') count++;
    A[i]=count;
  }
  count=0;
  for(int i=N-1; i>=0; i--){
    if(S[i]=='E') count++;
    B[i]=count;
  }
  count=0;
  int ans=N;
  for(int i=0; i<N; i++){
    if(i==0) count=B[i+1];
    if(i==N-1) count=A[i-1];
    else count=A[i-1]+B[i+1];
//    cout<<"i:"<<i<<" A[i-1]:"<<A[i-1]<<" B[i+1]:"<<B[i+1]<<" count:"<<count<<endl;
    ans=min(ans,count);
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>
#include <string.h>


using namespace std;

int A[402][402];
int dx[] = {1, -1, 0 ,0};
int dy[] = {0 ,0, 1, -1};
long d;
long p;

void dfs (int x, int y, int c){
	if(c == 1){
		d++;
	} else {
		p++;
	}
	A[x][y] = 0;
	for(int i = 0;i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(A[nx][ny] == -c) dfs(nx, ny, -c);
	}
}

int main(){

	int H, W;
	cin >> H >>  W;

	int x=0, y=0;

	for(int i = 0; i < 404; i++)
		for(int j = 0 ; j < 404; j++)
			A[i][j]=0;

	for(int i = 1; i<=H; i++){
		string S;
		cin >> S;
		for(int j = 1;j<=W;j++){
			if(S[j-1] == '#'){
				A[i][j] = 1;
				x++;
			} else {
				A[i][j] = -1;
				y++;
			}
		}
	}

	long long sum = 0;
	for(int i = 1; i<=H; i++){
		for(int j = 1;j <=W;j++){
			if(A[i][j] != 1) continue;
			d=0; p=0;
			dfs(i, j, 1);
			sum += d * p;
		}
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 8320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace クリスマスイヴイヴイヴ
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;
            D=int.Parse(Console.ReadLine());
             if ( D < 26&&D>24 )
            {
                Console.WriteLine ("Christmas");
            }
            else if(D<25&&D>23)
            {
                Console.WriteLine("Christmas Eve");
            }
            else if (D>22&&D<24)
            {
                Console.WriteLine("Christmas Eve Eve");
            }
            else if (D<23&&D>21)
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n
    
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def same(self,x,y):
        return self.find(x)==self.find(y)
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x ==y: return 
        if self.parents[x]>self.parents[y]:
            x,y = y,x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

N,M = map(int,input().split())
edge = []
uf = UnionFind(N)
for i in range(M):
    a,b = map(int,input().split())
    edge.append((a-1,b-1))
ans = N*(N-1)//2
l = []
for i in range(M)[::-1]:
    l.append(ans)
    if not uf.same(edge[i][0],edge[i][1]):
        ans -= uf.size(edge[i][0])*uf.size(edge[i][1])
    uf.union(edge[i][0],edge[i][1])
print(*l[::-1], sep="\n")

Measured memory_bytes: 95432
N, M = [int(i) for i in input().split()]
PY = []
for i in range(M):
    PY.append([int(j) for j in input().split()] + [i] + [str(0) * 12])

PY.sort(key=lambda x: x[1] + x[0] * 10 ** 10)

count = 0
pre = PY[0][0]
for i in PY:
    count += 1
    if pre != i[0]:
        count = 1
        pre = i[0]
    i[3] = str(pre).zfill(6) + str(count).zfill(6)

PY.sort(key=lambda x: x[2])
for i in PY:
    print(i[3])

Measured memory_bytes: 36404
#include<iostream>
#include<cstdio>

using namespace std;

int n,r;

int c1[1001],c2[1001];

int main(void){
	while(1){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		for(int i=0;i<n;i++)c1[i]=c2[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			scanf("%d%d",&p,&c);
			for(int j=0;j<c;j++)c2[j]=c1[j+p-1];
			for(int j=c;j<c+p-1;j++)c2[j]=c1[j-c];
			for(int j=c+p;j<n;j++)c2[j]=c1[j];
			for(int j=0;j<n;j++){
				c1[j]=c2[j];
				//printf("%d\n",c1[j]);
			}
		}
		printf("%d\n",c1[0]);
	}
	return 0;
}

Measured memory_bytes: 1196
s=input()
kisu = s[::2]
gusu = s[1::2]
for i in range(len(kisu)):
  if kisu[i] == "L":
    print("No")
    exit()
for i in range(len(gusu)):
  if gusu[i] == "R":
    print("No")
    exit()
print("Yes")
    

Measured memory_bytes: 3060
inf = input().split()
W = int(inf[0])
H = int(inf[1])
x = int(inf[2])
y = int(inf[3])
 
s=W*H
if not s%2==0:
  s = s//2+0.5
else:
  s = s/2
st = "{0:.9f}".format(s)
if W%2==0 and H%2==0:
  gx = W//2
  gy = H//2
  if gx==x and gy==y:
    print(st, 1)
  else:
    print(st, 0)
else:
  print(st, 0)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int H, A;
  cin >> H >> A;
  int ans = H / A;
  int k = H % A;
  if(k > 0)
	cout << ans+1 << endl;
  else
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
typedef long long int ll;
int main()
{
   char ch[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
   ll n;
   cin>>n;
   string s="";
   while(1)
   {
       int idx=n%26;
       if(!idx)
       {
           s+='z';
       }
       else
       {
           s+=ch[idx-1];
       }
       if(idx==0)
       {
           n=(n-26)/26;
       }
       else
        n=(n-idx+1)/26;
       if(n==0)
        break;
   }
   reverse(s.begin(),s.end());
   cout<<s<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);

    int a = stdIn.nextInt();
    int b = stdIn.nextInt();
    int c = stdIn.nextInt();
    int k = stdIn.nextInt();

    int max = a;
    if (max < b) max = b;
    if (max < c) max = c;

    int other = 0;
    if (max == a) other = b + c;
    if (max == b) other = c + a;
    if (max == c) other = a + b;

    for (int i = 0; i < k; i++) {
      max*=2;
    }

    System.out.println(max + other);
  }
}

Measured memory_bytes: 21844
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
char a[1010];
char b[1010];
int max(int a, int b) { return a > b ? a : b; }
int main()
{
	scanf("%s", a);
	scanf("%s", b);
	int lena = strlen(a);
	int lenb = strlen(b);
	int ans = 0;
	for (int i = 0; i <= lena-lenb; i++)
	{
		int cnt = 0;
		for (int j = 0; j < lenb; j++)
		{
			if (a[i+j] == b[j]) cnt++;
		}
		ans = max(ans, cnt);
	}
	printf("%d", lenb - ans);
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
 
#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)
 
ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}
 
int main()
{
  ll X, t;
  cin >> X >> t;
  if (X - t < 0){
    cout << 0 << endl;
  }else{
    cout << X - t << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Queue<String> keys = new LinkedList<>();
        Queue<Integer> values = new LinkedList<>();
        Integer timestamp = 0;

        int ceiling = in.nextInt();
        int quantum = in.nextInt();
        while (ceiling > 0) {
            keys.add(in.next());
            values.add(in.nextInt());
            --ceiling;
        }

        while (!values.isEmpty()) {
                if (values.peek() <= quantum) {
                    timestamp += values.poll();
                    System.out.println(keys.poll() + " " + timestamp);
                } else {
                    int temp = values.poll() - quantum;
                    String tempo = keys.poll();
                    keys.add(tempo);
                    values.add(temp);
                    timestamp += quantum;
            }
        }
    }
}







Measured memory_bytes: 77392
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    long long res = 0; map <int, int> mp;
    mp[0] = 1; int x, all = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x; all = (all + x) % m;
        res += mp[all];
        mp[all]++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  int n,m;
  cin>>n>>m;
  int ans=0;
  while(n>0){
    ans++;
    n-=m;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
N, M = map(int, input().split())
S = input()

index = N
count = 0
history = []
while index > 0:
    start = max(0, index - M)
    for i, c in enumerate(S[start:index], start=start):
        if c == '0':
            history.append(index - i)
            index = i
            count += 1
            break
    else:
        print(-1)
        exit()

print(*history[::-1])

Measured memory_bytes: 84428
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


A_sum = sum(A)
ans_candidates = []
for n in range(1, int(A_sum ** 0.5) + 1):
    if A_sum % n == 0:
        ans_candidates.append(n)
        ans_candidates.append(A_sum // n)
ans_candidates.sort(reverse=True)


for z in ans_candidates:
    need_add = [(z - a % z) % z for a in A]
    need_add.sort()
    need_minus = [z - na for na in need_add]

    need_add = list(accumulate(need_add))
    need_minus = list(accumulate(need_minus))

    for i in range(N):
        if (need_add[i] == need_minus[-1] - need_minus[i]) and (need_add[i] <= K):
            print(z)
            exit()


Measured memory_bytes: 3188
//AtCoder ABC081 C - Not so Diverse
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N,K;
    cin>>N>>K;
    vector<ll> atbl(N);
    unordered_map<ll,ll> vnum;
    for(auto&& a:atbl){
        cin>>a;
        ++vnum[a];
    }
    vector<ll> sl(vnum.size());
    ll i=0;
    for(auto&& v:vnum){
        sl[i++]=v.first;
    }
    sort(sl.begin(),sl.end(),[&](auto& a,auto& b){
        return (vnum[a] < vnum[b]);
    });
    ll ans=0;
    for(ll i=0;i<((ll)vnum.size()-K);++i){
        ans+=vnum[sl[i]];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11592
#include <iostream>
#include <vector>

#if defined(__GNUC__) && !defined(__clang__)
#  pragma GCC optimize("Ofast")
#  pragma GCC target("sse4.2", "tune=native")
#endif


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

  int n, m, c;
  std::cin >> n >> m >> c;

  std::vector<int> bs(m);
  for (auto&& b : bs) {
    std::cin >> b;
  }

  int cnt = 0;
  std::vector<int> as(m);
  for (int i = 0; i < n; i++) {
    for (auto&& a : as) {
      std::cin >> a;
    }
    int sum = c;
    for (int j = 0; j < m; j++) {
      sum += as[j] * bs[j];
    }
    if (sum > 0) {
      cnt++;
    }
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
import numpy as np

n= int(input())
a= [int(i) for i in input().split(' ')]

if abs(max(a)) >= abs(min(a)):
  ma  = max(a)
  ma_i= np.argmax(a)
  mi  = 0
  mi_i= 0
else:
  mi  = min(a)
  mi_i= np.argmin(a)
  ma  = 0
  ma_i= 0

xa=[]
if ma == 0:
  for i in range(n):
    if a[i] > 0:
      a[i] = a[i] + mi
      xa.append([mi_i+1, i+1])
  for i in reversed(range(1,n)):
    if a[i-1] > a[i]:
      a[i-1] = a[i-1] + a[i]
      xa.append([i+1, i-1+1])
else:
  for i in range(n):
    if a[i] < 0:
      a[i] = a[i] + ma
      xa.append([ma_i+1, i+1])
  for i in range(1,n):
    if a[i-1] > a[i]:
      a[i] = a[i] + a[i-1]
      xa.append([i-1+1,i+1])

print(len(xa))
for i in range(len(xa)):
  print(xa[i][0],xa[i][1])

Measured memory_bytes: 12524
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * 2019/06/09
 * AtCoder Beginner Contest 129
 * 
 * C - Typical Stairs
 * 
 * @author rued97
 */
public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int MOD = 1000000007;
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> as = new HashSet<>();
		for(int i = 0; i < M; i++) {
			as.add(sc.nextInt());
		}
		
		long pre1 = 0;
		long pre2 = 1;
		long now = 0;
		
		for(int i = 1; i <= N; i++) {
			if(as.contains(i)) {
				now = 0;
			} else {
				now = (pre1 + pre2) % MOD;
			}
			pre1 = pre2;
			pre2 = now;
			if(pre1 == 0 && pre2 == 0) {
				break;
			}
		}
		
		System.out.println(now);
	}
	
}

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

using namespace std;

int h, w;

long long min_parallel(long long x, long long y) {
    long long res = LLONG_MAX;
    for (long long a = 1; a < y - 1; a++) {
        long long sa = x * a;
        long long sb, sc;
        if ((y - a) % 2 == 1) {
            sb = x * (y - a + 1) / 2;
            sc = x * (y - a - 1) / 2;
        } else {
            sb = x * (y - a) / 2;
            sc = x * (y - a) / 2;
        }
        long long ma = max(sa, max(sb, sc));
        long long mi = min(sa, min(sb, sc));
        res = min(res, ma - mi);
    }
    return res;
}

long long min_orthogonal(long long x, long long y) {
    long long res = INT_MAX;
    for (long long a = 1; a < y; a++) {
        long long sa = x * a;
        long long sb, sc;
        if (x % 2 == 1) {
            sb = (y - a) * (x + 1) / 2;
            sc = (y - a) * (x - 1) / 2;
        } else {
            sb = (y - a) * x / 2;
            sc = (y - a) * x / 2;
        }
        long long ma = max(sa, max(sb, sc));
        long long mi = min(sa, min(sb, sc));
        res = min(res, ma - mi);
    }
    return res;
}

int main(void) {
    cin >> h >> w;
    // cout << h << w;
    long long res = LLONG_MAX;
    res = min(res, min_parallel(h, w));
    res = min(res, min_parallel(w, h));
    res = min(res, min_orthogonal(h, w));
    res = min(res, min_orthogonal(w, h));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n;
    cin>>n;
    int minsum = 200, j, k, sum;
    for(int i=1; i<n; i++){
        j = i;
        k = n-i;
        sum = 0;
        while(j){
            sum += j%10;
            j /= 10;
        }
        while(k){
            sum += k%10;
            k /= 10;
        }
        minsum = min(minsum, sum);
    }
    
    cout << minsum << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(float, input().split())

#点2のベクトルを求める（base）
c -= a
d -= b

for _ in [0] * int(input()):
  #x,yの座標を入力する
  x, y = map(float, input().split())

  #x,yのベクトルを入力する（hypo）
  x -= a
  y -= b

  #zとbaseの比率
  z = (c*x + d*y) / (c*c + d*d)
  print(a+c*z, b+d*z)




Measured memory_bytes: 5628
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 1000003
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
    int n,i,j,k;
    scanf("%d",&n);
    int A[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }
    sort(A,A+n);
    int ans=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(A[j]==A[i]) continue;
            for(k=j+1;k<n;k++)
            {
                if(A[j]==A[k]) continue;
                ans=ans+(A[k]<A[i]+A[j]);
            }
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int a,b,c,d,e,f;
   cin>>a>>b>>c;
   d=max(a,b);
   e=max(b,c);
   f=max(d,e);
   cout<<a+b+c-f<<endl;
   

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
}

Measured memory_bytes: 35828
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	vector<int> vec(n, 1);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (h[a] <= h[b]) vec[a] = 0;
		if (h[b] <= h[a]) vec[b] = 0;
	}
	int ans = 0;
	for (int c : vec) ans += c;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3996
n,m = map(int,input().split())
a = [[0,0] for i in range(m)]
for i in range(m) :
  a0,a1 = map(int,input().split())
  a[i][:] = a0-1,a1-1

a.sort(key=lambda x: x[1])

ans = [0 for i in range(n-1)]
ans[a[0][1]-1] = 1
right = a[0][1]-1
for i in range(1,m) :
  if right < a[i][0] :
    ans[a[i][1]-1] = 1
    right = a[i][1]-1
    
print(sum(ans))

Measured memory_bytes: 21288
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int kazu = Integer.parseInt(line);
		line = br.readLine();

		String[] keisanStr = line.split("[\\s]+");
		int[] keisanInt = new int[kazu];
		for (int i = 0; i < kazu; i++) {
			keisanInt[i] = Integer.parseInt(keisanStr[i]);
			// System.out.println(keisanInt[i]);
		}

		int min = keisanInt[0];
		int max = keisanInt[0];
		long sum = keisanInt[0];

		for (int q = 1; q < kazu; q++) {
			sum += keisanInt[q];

			if (min > keisanInt[q]) {
				min = keisanInt[q];
			} else if (max < keisanInt[q]) {
				max = keisanInt[q];
			}
		}
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 31512
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ansc = 0, ansd = 0, anscd = 0,ans = 0;
    if (a % c == 0)ansc++;
    ansc += b / c - a / c;
    
    if (a % d == 0)ansd++;
    ansd += b / d - a / d;

    if (a % d == 0 && a % c == 0)anscd++;
    ll tmp = lcm(c, d);
    anscd += b / tmp - a / tmp;;

    ans = (b - a + 1) - (ansc + ansd - anscd);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i= 0;i<(int)c;i++)
int main() {
 int A,P;
 int count;
 cin >> A >> P ;
 count = 3*A;
 cout << (P+count)/2 << endl;
 return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut a = a;
    a.sort(); a.reverse();
    let mut tot = a[0];
    let mut rem = n - 2;
    for i in 1..n {
        let c = min(2, rem);
        tot += a[i] * c as i64;
        rem -= c;
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
    long long n,m;
    cin >> n >> m;
    
    if(n==1&&m==1){
        cout << 1 << endl;
    }
    else if(n==1||m==1){
        cout << max(n,m)-2 << endl;
    }
    else if(n==2||m==2){
        cout << 0 << endl;
    }
    else{
        cout << (n-2)*(m-2) << endl;
    }
}



Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t w, h; cin >> h >> w;
	if (w == 1 || h == 1) {
		cout << 1 << endl;
		return 0;
	}
	int64_t ans = (w * (h / 2));
	if (h & 1) ans += (w + 1) / 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}

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

  int n;
  cin >> n;
  vt<double> a(n);
  rep(i, 0, n) cin >> a[i];

  double sum = 0;
  rep(i, 0, n) sum += a[i];
  double tmp = sum / n;

  int num = 0;
  rep(i, 1, n) {
    if(abs(tmp - a[num]) > abs(tmp - a[i])) num = i;
  }
  cout << num << endl;
}


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

int div_m2(int n)
{
  if (n < 0)
    return (n - 1) / -2;
  else
    return -(n / 2);
}

int main()
{
  int N;
  cin >> N;
  vector<int> a;
  if (N == 0)
    a.push_back(0);
  while (N != 0)
  {
    a.push_back(abs(N % 2));
    N = div_m2(N);
  }
  for (int i = a.size() - 1; i >= 0; i--)
    cout << a[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<string>

#define maxn 400005
#define MOD 924844033

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n;
int fir[maxn],nxt[maxn],to[maxn],cnt;
int rev[maxn<<2];
int sz[maxn],a[maxn<<2],b[maxn<<2];
int fac[maxn],inv[maxn];

inline void newnode(int u,int v)
{to[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;}
inline void dfs(int u,int fa)
{
	sz[u]=1;
	for(int i=fir[u];i;i=nxt[i])if(to[i]!=fa)
	{
		dfs(to[i],u),sz[u]+=sz[to[i]];
		a[sz[to[i]]]++;
	}
	a[n-sz[u]]++;
}

inline int ksm(int num,int k)
{
	int ret=1;
	for(;k;k>>=1,num=1ll*num*num%MOD)if(k&1)ret=1ll*ret*num%MOD;
	return ret;
}
inline void getrev(int N)
{for(int i=0;i<N;i++)rev[i]=(rev[i>>1]>>1)|(i&1?N>>1:0);}
inline void NTT(int *a,int opt,int N)
{
	for(int i=0;i<N;i++)if(rev[i]<i)swap(a[i],a[rev[i]]);
	for(int i=1;i<N;i<<=1)
	{
		int wn=ksm(5,(MOD-1)/(i<<1));
		if(!~opt)wn=ksm(wn,MOD-2);
		for(int j=0;j<N;j+=(i<<1))for(int k=0,w=1;k<i;k++,w=1ll*w*wn%MOD)
		{
			int x=a[j+k],y=1ll*a[i+j+k]*w%MOD;
			a[j+k]=(x+y)%MOD,a[i+j+k]=(x-y+MOD)%MOD;
		}
	}
	if(!~opt)for(int i=0,Inv=ksm(N,MOD-2);i<N;i++)a[i]=1ll*a[i]*Inv%MOD;
}

int main()
{
	n=getint();
	for(int i=1;i<n;i++)
	{
		int u=getint(),v=getint();
		newnode(u,v),newnode(v,u);
	}
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n;i++)fac[i]=1ll*fac[i-1]*i%MOD;
	for(int i=2;i<=n;i++)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=2;i<=n;i++)inv[i]=1ll*inv[i]*inv[i-1]%MOD;
	dfs(1,0);a[0]=0;
	for(int i=0;i<=n;i++)a[i]=1ll*a[i]*fac[i]%MOD;
	for(int i=0;i<=n;i++)b[i]=inv[n-i];
	int len=1;
	while(len<=2*n)len<<=1;
	getrev(len);
	NTT(a,1,len),NTT(b,1,len);
	for(int i=0;i<len;i++)a[i]=1ll*a[i]*b[i]%MOD;
	NTT(a,-1,len);
	for(int i=1;i<=n;i++)
	{
		int ans=1ll*fac[n]*inv[i]%MOD*inv[n-i]%MOD*n%MOD;
		printf("%lld\n",(ans-1ll*a[i+n]*inv[i]%MOD+MOD)%MOD);
	}
}

Measured memory_bytes: 29444
import java.math.BigInteger

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map(String::toInt)
    val aSum = aList.sum()
    var dpTable = BigInteger.ONE
    for (a in aList) {
        dpTable = dpTable.or(dpTable.shiftLeft(a))
    }
    val ans = (((aSum + 1) / 2)..aSum).filter { dpTable.testBit(it) }.first()
    println(ans)
}

Measured memory_bytes: 145216
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > Pi;
int main()
{
    int N, M, H, K;
    int point[1005], num[1005], np[1005];
    Pi edge[100005];
    while(cin >> N >> M >> H >> K, N || M || H || K) {
        vector < int > G[1005];
        for(int i = 0; i < N; i++) {
            num[i] = i;
            cin >> point[i];
        }
        for(int i = 0; i < M; i++) cin >> edge[i].second >> edge[i].first;
        sort(edge, edge + M);
        for(int i = 0; i < M; i++) {
            int a = edge[i].second - 1, b = edge[i].second;
            swap(num[a], num[b]);
            G[num[a]].push_back(num[b]);
            G[num[b]].push_back(num[a]);
        }
        for(int i = 0; i < N; i++) np[num[i]] = point[i];
        int sum = 0, minv = 0;
        for(int i = 0; i < K; i++) {
            for(int j = 0; j < G[i].size(); j++) {
                int u = G[i][j];
                if(u >= K) {
                    minv = min(np[u] - np[i], minv);
                }
            }
            sum += np[i];
        }
        cout << sum + minv << endl;
    }
    return (0);
}


Measured memory_bytes: 4872
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    vector<double>V(n);
    rep(i,n)cin>>V[i];
    sort(all(V));
    double ans=V[0];
    rep(i,n-1){
        ans=(ans+V[i+1])/2;
    }
    cout<<ans;
}



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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    string s; cin >> s;
    ll ans = 0;
    for(auto x:s){
        ans += x-'0';
    }

    cout << (ans%9==0?"Yes":"No") << endl;

    return 0;
}

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

int main(void)
{
  std::string input;
  std::cin >> input;
  if('a' <= input[0] && input[0] <= 'z') std::cout << 'a';
  else if('A' <= input[0] && input[0] <= 'Z') std::cout << 'A';
  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n+1],b[n+1],c[n];
	for(int i = 1 ; i <= n ; i++ ){
		cin >> a[i];
	}
	for(int i = 1 ; i <= n ; i++ ){
		cin >> b[i];
	}
	for(int i = 1 ; i <= n-1 ; i++ ){
		cin >> c[i];
	}
	int sat = 0;
	for(int  i = 1 ; i <= n ; i++ ){
		sat+=b[a[i]];
	}
	for(int i = 2; i <=n ;i++){
		if(a[i]-1==a[i-1] && a[i-1]>=1){
			sat+=c[a[i-1]];
		}
	}
	cout<<sat;
}

Measured memory_bytes: 256
n=int(input())
a=list(str(input()))
b=list(str(input()))
c=list(str(input()))

ans=0
for i in range(n):
    l=set(list(a[i]+b[i]+c[i]))
    if len(l)==3:ans+=2
    elif len(l)==2:ans+=1
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main{
    public static void main(String[] args) throws IOException {
        	Scanner sc = new Scanner(System.in);
        	int n = sc.nextInt();
        	String s = sc.next();
        	long red =0, green =0, blue =0;
        	for(int i=1;i<=n;i++) {
        		if(s.charAt(i-1)=='R')
        			red++;
        		else if(s.charAt(i-1)=='G')
        			green++;
        		else
        			blue++;
        	}
        	long res=red*green*blue;
        	for(int i=0;i<n;i++) {
        		char a = s.charAt(i);
        		for(int j=i+1;j<n;j++) {
        			char b = s.charAt(j);
        			int k = j + (j-i);
        			if(k<n) {
        				char c = s.charAt(k);
            			if((a=='R' && b=='G' && c=='B') || (a=='R' && b=='B' && c=='G') || (a=='G' && b=='R' && c=='B') || (a=='G' && b=='B' && c=='R') || (a=='B' && b=='G' && c=='R') || (a=='B' && b=='R' && c=='G'))
            				res--;
        			}			
        		}
        	}
        	System.out.println(res);
    }
}


Measured memory_bytes: 37360
local n, m = io.read("*n", "*n")
local edge = {}
local pcnt = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  pcnt[i] = 0
  len[i] = 0
end
local rawsrc, rawdst = {}, {}
for i = 1, n - 1 + m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  pcnt[b] = pcnt[b] + 1
  rawsrc[i], rawdst[i] = a, b
end
local tasks = {}
for i = 1, n do
  if pcnt[i] == 0 then
    tasks[1] = i
    break
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local l = len[src]
  local edgesrc = edge[src]
  for i = 1, #edgesrc do
    local dst = edgesrc[i]
    if len[dst] < len[src] + 1 then
      len[dst] = len[src] + 1
    end
    pcnt[dst] = pcnt[dst] - 1
    if pcnt[dst] == 0 then
      table.insert(tasks, dst)
    end
  end
end
local parent = {}
for i = 1, n do
  parent[i] = 0
end
for i = 1, n - 1 + m do
  local src, dst = rawsrc[i], rawdst[i]
  if len[src] + 1 == len[dst] then
    parent[dst] = src
  end
end
print(table.concat(parent, "\n"))


Measured memory_bytes: 33004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int s, w;
    cin >> s >> w;
    if (w >= s)
    {
        cout << "unsafe";
    }
    else
    {
        cout << "safe";
    }

    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	list = ql;
	return ql;
}
signed main() {
	int n, k; cin >> n >> k;
	vel v(n);
	rep(i, n) { cin >> v[i]; }
	int mx = 0;
	rep(i, n) {
		rep(j, n-i+1) {
			if (i + j <= k) {
				vel ans(i + j);
				int pr = 0;
				rep(ind, i) { ans[ind] = v[ind]; pr += v[ind]; }
				rep(in, j) { ans[i + in] = v[n - 1 - in]; pr += v[n - 1 - in]; }
				sor(ans);
				int mi = 0;
				rep(inde, min(i + j, k - i - j)) {
					int ze = 0;
					mi += min(ans[inde], ze);
				}
				mx = max(mx, pr - mi);
			}
		}
	}
	cout << mx << endl;
	return 0;
}



Measured memory_bytes: 256
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K):
    ans3 = 0
    dx = d- i
    ex = e - (K - i - 1)
    ans3 += 1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += dx//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Measured memory_bytes: 14008
def main(str)
  x = str.to_i % 1000
  x > 0 ? 1000 - x : 0
end

unless ENV["TEST"]
  puts(main($stdin.read.chomp))
  exit(0)
end

require 'minitest/autorun'

class TestA < Minitest::Test
  def test_main
    assert_equal(100, main("1900"))
    assert_equal(0, main("3000"))
  end
end




Measured memory_bytes: 14376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<tuple<int,int,int>> vec(N - 1);
    for(int i = 0;i < N - 1;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        vec.at(i) = make_tuple(A, B, C);
    }
    for (int i = 0; i < N;i++) {
        ll ret = 0;
        for(int j = i;j < N - 1;j++) {
            int A = get<0>(vec.at(j));
            int B = get<1>(vec.at(j));
            int C = get<2>(vec.at(j));
            if(ret <= B) {
                ret = A + B;
            }
            else {
                ret = (ret + C - 1) / C * C + A;
            }
        }
        cout << ret << endl;
    }
}

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

int read() {
  int x = 0 , f = 1 ; char c = getchar() ;
  while(c < '0' || c > '9') { if(c == '-') f = -1 ; c = getchar() ; }
  while(c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c & 15) ; c = getchar() ; }
  return x * f ;
}

template < class T > void print(T x , char c = '\n') {
  static char _st[100] ; int _stp = 0 ;
  if(x == 0) { putchar('0') ; }
  if(x < 0) { putchar('-') ; x = -x ; }
  while(x) { _st[++ _stp] = (x % 10) ^ 48 ; x /= 10 ; }
  while(_stp) { putchar(_st[_stp --]) ; }
  putchar(c) ;
}

int main() {
  string s ;
  cin >> s ;
  if(s == "SUN") print(7) ;
  if(s == "MON") print(6) ;
  if(s == "TUE") print(5) ;
  if(s == "WED") print(4) ;
  if(s == "THU") print(3) ;
  if(s == "FRI") print(2) ;
  if(s == "SAT") print(1) ;

  return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    scanf("%d", &n);
    vector<string> A;
    for(int i = 0; i < n; i++){
        char x[1001];
        scanf("%s", &x);
        A.push_back(x);
    }
    scanf("%d", &m);
    vector<string> B;
    for(int i = 0; i < m; i++){
        char x[1001];
        scanf("%s", &x);
        B.push_back(x);
    }
    vector<int> cnResults;
    for(int i = 0; i < n; i++){
        int cn = 0;
        for(string j : A){
            if(j == A[i]){
                cn++;
            }
        }
        for(string k : B){
            if(k == A[i]){
                cn--;
            }
        }
        cnResults.push_back(cn); // ??
    }
    sort(cnResults.begin(), cnResults.end(), greater<int>());
    printf("%d\n", (cnResults[0] < 0) ? 0 : cnResults[0]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
int main(){
	string s;
	cin >> s;
	int a=ctoi(s[0]);
	int b=ctoi(s[1]);
	int c=ctoi(s[2]);
	int d=ctoi(s[3]);
	char op1,op2,op3;
	int tmp;
	int ans=-1;
	for(int i=0;i<8;i++){
		if(i>>2&1) tmp=a+b;
		else tmp=a-b;
		if(i>>1&1) tmp=tmp+c;
		else tmp=tmp-c;
		if(i&1) tmp=tmp+d;
		else tmp=tmp-d;

		if(tmp==7){
			ans=i;
			break;
		}
	}
	op1=ans>>2&1?'+':'-';
	op2=ans>>1&1?'+':'-';
	op3=ans&1?'+':'-';
	cout << a << op1 << b << op2 << c << op3 << d << "=7";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,m;
    long long an=0;
    cin>>n;
    int a[n];
    map<int,int>mp;
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
        mp[a[i]]++;

    }


    for(int i=1; i<=n; i++)
    {
        cout<<mp[i]<<endl;

    }




    return 0;
}



Measured memory_bytes: 13756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> c;
	int sum = 0;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		if (a % 10 != 0) {
			c.push_back(a);
		}
	}
	sort(c.begin(), c.end());
	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else if (c.size() > 0) {
		cout << sum - c[0] << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    string S;
    cin >> S;

    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    if (!( ('a' <= S[1] && S[1] <= 'z') && ('a' <= S.back() && S.back() <= 'z') )) {
        cout << "WA" << endl;
        return 0;
    }

    int count_C = 0;
    for (int i = 2; i < (int) S.size() - 1; i++) {
        if (S[i] == 'C') {
            count_C++;
        } else if ('A' <= S[i] && S[i] <= 'Z') {
            cout << "WA" << endl;
            return 0;
        }
    }

    if (count_C == 1) {
        cout << "AC" << endl;
        return 0;
    } else {
        cout << "WA" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
n = int(input())
divs = make_divisors(n)

def judge(d):
  if n // (d-1) == n % (d-1):
    return True
  else:
    return False

ans = 0
for d in divs:
  if d > 1 and judge(d):
    ans += d-1
print(ans)



Measured memory_bytes: 67336