akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+50;

int n, a[N];
ll dp[N];

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%d", a+i);
	//dp[i] = 前i个的最大匹配数
	REP(i,1,n) {
		int t = min(a[i-1],a[i]);
		a[i] -= t;
		dp[i] = dp[i-1]+t;
		t = a[i]/2;
		dp[i] += t;
		a[i] -= t*2;
	}
	printf("%lld\n", dp[n]);
}








Measured memory_bytes: 5120
N,M,C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for n in range(N):
    A = []
    A = list(map(int, input().split()))
    tmp = C
    for m in range(M):
        tmp += A[m] * B[m]

    if tmp > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	A := getInt()
	B := getInt()

	if A <= 9 && B <= 9 {
		fmt.Println(A * B)
	} else {
		fmt.Println("-1")
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      key = 0
      if i > 0 and s[i-1][j] == "#":key = 1
      if i < h-1 and s[i+1][j] == "#":key = 1
      if j > 0 and s[i][j-1] == "#":key = 1
      if j < w-1 and s[i][j+1] == "#":key = 1
      if key == 0:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 39536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vi a(n);
  vi buka(n, 0);
  for(int i = 1; i < n; i++){
    cin >> a[i];
    a[i]--;
    buka[a[i]]++;
  }
  for(int i = 0; i < n; i++){
    cout << buka[i] << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 4824
n = int(input())
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
 
if sum(a) < sum(b):
    print('-1')
    exit()
 
count = 0
sabun = [a[i]-b[i] for i, _ in enumerate(a)]
husoku = sum([x for x in sabun if x<0])
sabun.sort(reverse=True)

for i in sabun:
    if husoku >= 0:
        break
    husoku += i
    count += 1
 
print(len([x for x in sabun if x<0]) + count)        

Measured memory_bytes: 18292
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,0,1,-1,1,-1,0,1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int h,w; cin>>h>>w;
  vector<string> s(50);
  REP(i,h) cin>>s[i];
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='#') continue;
      int num=0;
      REP(k,8){
        int ni=i+dx[k];
        int nj=j+dy[k];
        if(ni<0 || h<=ni)continue;
        if(nj<0 || w<=nj)continue;
        if(s[ni][nj]=='#')num++;
      }
      s[i][j]=(char)(num+'0');
    }
  }
  REP(i,h){
    P(s[i]);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> X(N, 0);
  REP(i, N){
    cin >> X[i];
  }
  ll ans = 1e18;
  for(ll i = 1; i <= 100; i++){
    ll tmp = 0;
    REP(j, N){
      tmp += (i - X[j])*(i - X[j]);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AIZU {
	struct V
	{
		public int alpha;
		public int beta;
		public V(int a, int b) { alpha = a; beta = b; }
		public bool avail {
			get { return alpha >= 0 && beta >= 0; }
		}
	}
	class Program {
		static int cin() { return int.Parse(Console.ReadLine()); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins() {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(' ');
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		
		const int origin = 97;

		static void Main(string[] args)
		{
			int N0 = cin();
			string F;
			string[] FF;
			V map = new V(1, 0);
			IEnumerable<string> F4;
			Dictionary<char, char> decode = new Dictionary<char, char>();
			Func<int, int> fu = i => (map.alpha * i + map.beta) % 26;
			StringBuilder S = new StringBuilder(256);
			for (int j = 0; j< N0; j++) 
			{
				map = new V(1, 0);
				F = Console.ReadLine();
				FF = F.Split(' ');
				F4 = FF.Where(i => i.Length == 4);
				foreach (string f in F4) {
					map = THAT(f);
					if (map.avail) {
						break;
					}
					map = THIS(f);
					if (map.avail) {
						break;
					}
				}
				decode.Clear();
				decode.Add(' ', ' ');
				fu = i => (map.alpha * i + map.beta) % 26;
				for (int i = 0; i < 26; i++)
					decode.Add((char)(fu(i) + origin), (char)(i + origin));
				S.Remove(0, S.Length);
				foreach (char c in F)
					S.Append(decode[c]);
				print(S);
			}
		}

		static V THAT(string s) {
			if (s.Length != 4)
				return new V(-1,-1);
			if (s[0] != s[3])
				return new V(-1, -1);
			int beta = s[2]-origin;
			int alpha=-1;
			if (s == "that")
				return new V(1, 0);
			char h, t;
			for (int i = 1; i < 26; i+=2) {
				if (i == 13) continue;
				h =(char)( (i * 7 + beta) % 26 + origin);
				t = (char)((i * 19 + beta) % 26 + origin);
				if (h == s[1] && t == s[0]) { alpha = i; break; }
			}
			return new V(alpha, beta);
		}
		static V THIS(string s)
		{
			if (s.Length != 4)
				return new V(-1, -1);
			int alpha = (s[2]-s[1]+26)%26;
			if ((s[0] - s[3] + 26) % 26 != alpha)
				return new V(-1, -1);
			int beta = -1;
			if (s == "this")
				return new V(1, 0);
			char h, t;
			for (int j = 0; j < 26; j ++) {
				h = (char)((alpha * 7 + j) % 26 + origin);
				t = (char)((alpha * 19 + j) % 26 + origin);
				if (h == s[1] && t == s[0]) { beta = j; break; }
			}
			return new V(alpha, beta);
		}
	}
}

Measured memory_bytes: 9704
#include "bits/stdc++.h"

using namespace std;

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


    int i = 0;
    while (S[i] == '.') { ++i; }

    int j = N - 1;
    while (S[j] == '#') { --j; }

    int n = j - i + 1;
    string T = S.substr(i, n);
    vector<int> X(n), Sum(n + 1);
    S[0] = 0;
    for (int i = 0; i < n; ++i) {
        X[i] = T[i] == '#' ? 1 : 0;
        Sum[i + 1] = Sum[i] + X[i];
    }

    int ans = 200005;
    for(int i = 0; i <= n; ++i)
    {
        int left = Sum[i]; // 黒石=>白石
        int right = (n - i) - (Sum[n] - Sum[i]); // 白石=>黒石
        ans = min(ans, left + right);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2308
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n = int(input())
t,a = map(int, input().split())
l = np.array(list(map(int, input().split())))
# l = np.zeros(n, dtype = int)
# for i in range(n):
#     l[i] = int(input())
# # l = list(map(int, input().split()))
min=sys.maxsize
for i in range(len(l)):
    temp=abs(a-(t-0.006*l[i]))
    if temp<min:
        min=temp
        ans=i
print(ans+1)


Measured memory_bytes: 13536
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
  string s, t, u;
  int a, b;

  cin >> s >> t >> a >> b >> u;

  if (u == s){
    a -= 1;
  } else if (u == t) {
    b -= 1;
  }

  cout << a << " "<< b << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Measured memory_bytes: 34148
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;

using ll = long long;
const int nax = 10123;
char k[nax];

void add_self(int &a, int b) {
	a += b;
	if(a >= mod) {
		a -= mod;
	}
}

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

	int D;
	cin >> k >> D;
	int len = strlen(k);
	vector<vector<int>> dp(D, vector<int>(2));
	dp[0][0] = 1;
	for(int i=0; i<len; ++i) {
		vector<vector<int>> new_dp(D, vector<int>(2));
		for(int sum = 0; sum < D; ++sum) {
			for(bool sm_already : {false, true}) {
				for(int digit = 0; digit < 10; ++digit) {
					if(digit > k[i] - '0' && !sm_already)
						break;
					add_self(new_dp[(sum+digit)%D][sm_already || (digit < k[i] - '0')], dp[sum][sm_already]);
				}

			}
		}
		dp = new_dp;
	}
	int answer = (dp[0][false] + dp[0][true])%mod;
	--answer;
	if(answer == -1) {
		answer = mod - 1 ;
	}
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <map>

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

    int64_t N,C;
    std::cin >> N >> C;

    using sushi_vect_type = std::vector<std::pair<int64_t, int64_t>>;
    sushi_vect_type sushi_vect(N);
    for(auto& i : sushi_vect){
        std::cin >> i.first >> i.second;
    }

    //Accumulated val and Max value with Clock Wise route
    int64_t accumulated = 0;
    int64_t max_score = 0;
    std::vector<int64_t> accumulate_l(N,0);
    std::vector<int64_t> left_score(N,0);
    for(int32_t i = 0; i < N; i++){
       accumulated += sushi_vect[i].second;
       accumulate_l[i] = accumulated;
       left_score[i] = std::max(max_score, accumulated - sushi_vect[i].first);
       max_score = std::max(max_score, accumulated - sushi_vect[i].first);
    }
    //Accumulated val and Max value with Coutner Clock Wise route
    accumulated = 0;
    max_score = 0;
    std::vector<int64_t> accumulate_r(N,0);
    std::vector<int64_t> right_score(N,0);
    for(int32_t i = 0; i < N; i++){
       accumulated += sushi_vect[N-1-i].second;
       accumulate_r[i] = accumulated;
       right_score[i] = std::max(max_score, accumulated - C + sushi_vect[N-1-i].first);
       max_score = std::max(max_score, accumulated - C + sushi_vect[N-1-i].first);
    }

    //debug
    //for(auto& i : left_score){
    //    std::cout << "left_score : " << i << std::endl;
    //}
    //for(auto& i : right_score){
    //    std::cout << "right_score : " << i << std::endl;
    //}

    //Score start with left and then go right
    max_score = 0;
    for(int32_t i = 0; i < N - 1; i++){
        max_score = std::max(max_score, left_score[i]);
        max_score = std::max(max_score, accumulate_l[i] - 2*sushi_vect[i].first + right_score[N-2-i]);
    }
    max_score = std::max(max_score, left_score[N-1]);

    //Score start with right and then go left
    for(int32_t i = 0; i < N - 1; i++){
        max_score = std::max(max_score, right_score[i]);
        max_score = std::max(max_score, accumulate_r[i] - 2 * (C - sushi_vect[N-1-i].first) + left_score[N-2-i]);
    }
    max_score = std::max(max_score, right_score[N-1]);

    std::cout << max_score << std::endl;
    return 0;

}

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

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	ll 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{
		cout << (n-2) * (m-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from copy import deepcopy
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]

last = {}
for i in range(26):
    last[i] = -1

s = 0
for d in range(D):
    ret = 0
    sr = {}
    ll = {}
    for c in range(26):
        last_cp = deepcopy(last)
        s_cp = deepcopy(s)
        last_cp[c] = d
        s_cp += S[d][c]
        for i in range(26):
            s_cp -= C[i] * (d-last[i])
        sr[c] = s_cp
        ll[c] = last_cp
    sr = sorted(sr.items(), key=lambda x:x[1])
    ret = sr[-1][0]
    s += sr[-1][1]
    last = deepcopy(ll[ret])
    print(ret+1)


Measured memory_bytes: 74736
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int> ret(N);
	string pre;
	REP(i, N){
		string s;
		cin >> s;
		if(s == "AB"){
			if(A == 0 && B == 0){
				if(pre == "BC" && ret[i - 1] == 'C') { B += 2; C -= 2; ret[i - 1] = 'B'; }
				if(pre == "AC" && ret[i - 1] == 'C') { A += 2; C -= 2; ret[i - 1] = 'A'; }
			}
			if(A < B) { A++; B--; ret[i] = 'A'; }
			else 	  { A--; B++; ret[i] = 'B'; }
		}
		if(s == "BC"){
			if(B == 0 && C == 0){
				if(pre == "AB" && ret[i - 1] == 'A') { B += 2; A -= 2; ret[i - 1] = 'B'; }
				if(pre == "AC" && ret[i - 1] == 'A') { C += 2; A -= 2; ret[i - 1] = 'C'; }
			}
			if(B < C) { B++; C--; ret[i] = 'B'; }
			else      { B--; C++; ret[i] = 'C'; }
		}
		if(s == "AC"){
			if(A == 0 && C == 0){
				if(pre == "AB" && ret[i - 1] == 'B') { A += 2; B -= 2; ret[i - 1] = 'A'; }
				if(pre == "BC" && ret[i - 1] == 'B') { C += 2; B -= 2; ret[i - 1] = 'C'; }
			}
			if(A < C) { A++; C--; ret[i] = 'A'; }
			else      { A--; C++; ret[i] = 'C'; }
		}
		if(A < 0 || B < 0 || C < 0){
			cout << "No" << endl;
			return 0;
		}
		pre = s;
	}

	cout << "Yes" << endl;
	REP(i, N) cout << (char)ret[i] << endl;

	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 
  typedef pair<double,int> PDI;

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

typedef struct{
  double x,y,r;
}Coo;

const int MAX_V = 1e3+10;
int V;
vector<vector<double> > dp(MAX_V,vector<double>(MAX_V,0));
vector<double> d(MAX_V,DBL_MAX);

double dist(const Coo& s, const Coo& t){
  return sqrt((s.x-t.x)*(s.x-t.x) + (s.y-t.y)*(s.y-t.y));
}

void dijkstra(int s){
  priority_queue<PDI, vector<PDI>, greater<PDI> > pque;
  d[s] = 0;
  pque.push(PDI(0,s));
  while(!pque.empty()){
    PDI p = pque.top(); pque.pop();
    int v = p.second;
    if(d[v] < p.first)continue;
    rep(u,V){
      if(d[u] > d[v] + dp[v][u]){
        d[u] = d[v] + dp[v][u];
        pque.push(PDI(d[u],u));
      }
    }
  }
}


int main(void){
  SPEEDUP
  cout << setprecision(15);
  Coo s,t;cin >> s.x >> s.y >> t.x >> t.y;
  s.r = t.r = 0;
  cin >> V;
  vector<Coo> v(V+2);
  v[0] = s;
  rep(i,V)cin >> v[i+1].x >> v[i+1].y >> v[i+1].r;
  v[V+1] = t;
  V+=2;
  rep(i,V){
    repp(j,i+1,V) dp[i][j] = dp[j][i] = max(0.0,dist(v[i],v[j])- v[i].r - v[j].r);
  }
  dijkstra(0);
  cout << d[V-1] << endl;
  return 0;
}


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

int main(){
	
	for(int i = 1; i <= 9; i ++)
	{
		for(int j = 1; j <= 9; j ++)
		{
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}

	
    return 0;
}

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===


int main()
{
	int N, K;
	cin >> N >> K;
	cout << N - K + 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int T,P,R,tID,pID,time,i,j,tmp,rank[50];
  char mes[10];

  for(;;){
    scanf("%d %d %d", &T, &P, &R);
    if(!(T|P|R)) break;

    int jud[50][10]={0}; 
    int wro[50][10]={0}; int sum[50]={0}; int pen[50]={0};
    for(i=0;i<R;i++){
      scanf("%d %d %d %s", &tID, &pID, &time, &mes);
      if(!strcmp(mes,"CORRECT")){
	jud[tID-1][pID-1]=1; pen[tID-1]+=wro[tID-1][pID-1]*1200+time;
      } else {
	wro[tID-1][pID-1]++;
      }
    }
    for(i=0;i<T;i++){
      for(j=0;j<P;j++){
	sum[i]+=jud[i][j];
      }
      rank[i]=i;
    }
    for(i=1;i<T;i++){
      for(j=1;j<T;j++){
	if(sum[rank[j-1]]<sum[rank[j]]){
	  tmp=rank[j-1]; rank[j-1]=rank[j]; rank[j]=tmp;
	} else if(sum[rank[j-1]]==sum[rank[j]]&&pen[rank[j-1]]>pen[rank[j]]){
	  tmp=rank[j-1]; rank[j-1]=rank[j]; rank[j]=tmp;
	}
      }
    }
    for(i=0;i<T;i++){
      printf("%d %d %d\n", rank[i]+1, sum[rank[i]], pen[rank[i]]);
    }
  }
  
  return 0;
}


Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ctr1=0,ctr2=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='+') ctr1++;
        else ctr2++;
    }
    cout<<ctr1-ctr2;
}


Measured memory_bytes: 256
N = int(input().strip())
datas = []
for _ in range(N):
    A = int(input().strip())
    datas.append([[int(str) for str in input().strip().split()] for _ in range(A)])

def judge(bit):
    true_man = [(bit & (1 << d)) >> d for d in range(N)]

    for i in range(N):
        if true_man[i]:
            for data in datas[i]:
                if true_man[data[0] - 1] != data[1]:
                    return 0

    return sum(true_man)

ans = 0
for bit in range(2 ** N):
    ans = max(ans, judge(bit))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int gcd(int u,int v) {
    while ( v != 0) {
        int r = u % v;
        u = v;
        v = r;
    }
    return u;
}

int main(void){
    int x,y;
    cin>>x>>y;
    cout<<gcd(x,y)<<endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<long long>a(n);
  vector<long long>b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i) >> b.at(i);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(n%2==1){
    int cen=(n+1)/2;
    cout << b.at(cen-1)-a.at(cen-1)+1 << endl;
  }
  else{
    int cen=n/2;
    int low=a.at(cen)+a.at(cen-1);
    int high=b.at(cen)+b.at(cen-1);
    cout << high-low+1 << endl;
  }
}

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

int main() {
 int N,X,T; cin>>N>>X>>T;
 cout << ((N-1)/X+1)*T << endl;
 return 0;
}

Measured memory_bytes: 3624
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        // final int M = sc.nextInt();
        final int N = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        // final int D = sc.nextInt();

        // System.out.println();
        System.out.println(Math.min(N * A, B));

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

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

using namespace std;

typedef long long int ll;
#define f first
#define s second
#define Mp make_pair
#define pb push_back
#define Lb lower_bound
#define Ub upper_bound
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const ll Maxn = 100000+5, N = 100+5, Mod = 1000*1000*1000 + 7, inf = (ll)1000*1000*1000;
ll n, w, dp[N][Maxn];
pair < ll, ll > items[Maxn];

int main(){
    fast_io
    cin >> n >> w;
    for (int i = 0; i < n; i++){
        cin >> items[i].f >> items[i].s;
    }
    sort(items, items+n);
    ll ans = 0;
    for (int j = 1; j <= w; j++){
        if (items[0].f <= j){
            dp[0][j] = items[0].s;
            ans = max(ans, dp[0][j]);
        }
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= w; j++){
            if (items[i].f <= j){
                dp[i][j] = max(dp[i][j], dp[i-1][j-items[i].f]+items[i].s);
                ans = max(ans, dp[i][j]);
            }
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int W = abs(tx - sx);
    int H = abs(ty - sy);

    for (int i = 0; i < H; i++) {
        cout << "U";
    }
    for (int i = 0; i < W; i++) {
        cout << "R";
    }


    for (int i = 0; i < H; i++) {
        cout << "D";
    }
    for (int i = 0; i < W; i++) {
        cout << "L";
    }

    cout << "L";
    for (int i = 0; i < H + 1; i++) {
        cout << "U";
    }
    for (int i = 0; i < W + 1; i++) {
        cout << "R";
    }
    cout << "D";

    cout << "R";
    for (int i = 0; i < H + 1; i++) {
        cout << "D";
    }
    for (int i = 0; i < W + 1; i++) {
        cout << "L";
    }
    cout << "U" << endl;
}


Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_4-A: Linear Search

#include <cstdio>

static int linear_search(const int as[], const int target)
{
  auto i = 0;
  while (as[i] != target) {
    ++i;
  }
  return i;
}

int main()
{
  int n;
  std::scanf("%d", &n);
  int ss[n+1]; // n+1(sentinel)
  for (auto i = 0; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  int q;
  std::scanf("%d", &q);
  auto c = 0u;
  for (auto i = 0; i < q; ++i) {
    int t;
    std::scanf("%d", &t);
    ss[n] = t; // sentinel
    auto j = linear_search(ss, t);
    if (j != n) ++c;
  }

  std::printf("%u\n", c);
}

// eof

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

int i,j,k;

int main(){
    ll n;cin>>n;
    vector<ll> length(n);//棒の長さ
    for(i=0;i<n;i++){cin>>length[i];}
    
    sort(length.begin(),length.end());//降順sort

    ll ans=0;
    int number;
    for(i=n-1;i>=2;i--){
        for(j=i-1;j>=1;j--){
            //binary search
            number=length[i]-length[j];
            int key;
            vector<long long int>::iterator position;
            position=upper_bound(length.begin(),length.begin()+j,number);
            //他の2辺を固定して、最後の辺になり得る最小値を探す
            key=distance(length.begin(),position);//最小で可能な辺の位置
            ans+=(j-key);
        }
    }

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

Measured memory_bytes: 256
def main():
  h,w = map(int, input().split())
  ans = []
  p = []
  for _ in range(h):
    s = input()
    if '#' in s:
      ans.append(list(s))
  for i in range(len(ans[0])):
    for j in range(len(ans)):
      if ans[j][i] == '#':
        break
      if j == len(ans)-1:
        p.append(i)
  p.sort(reverse=True)
  for i in p:
    for j in range(len(ans)):
      ans[j].pop(i)
  for i in range(len(ans)):
    s = ''.join(ans[i])
    print(s)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll r,g,b,n,ans=0;
    cin >> r >> g >> b >> n;
    for (ll i=0;i<n/r+1;i++){
        for (ll j=0;j<(n-i*r)/g+1;j++){
            if ((n-(i*r)-(j*g))%b==0){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    //COMinit();
    ll N,K;
    cin >>N>>K;
    ll ans = 0; 
    for(ll i=K;i<=N+1;i++){
        ans =(ans + i*(N-i+N+2)/2 - i*(i)/2+ 1)%mod;
    }

    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a,b,c,d;
    IN(a,b,c,d);
    int ans,start,end;
    start = max(a,c);
    end = min(b,d);
    if(start < end) ans = end - start;
    else ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
using namespace std;
ll num[100005];
int main () {
	ll n;
	scanf("%lld", &n);
	num[0] = 0;
	FOR(i, 1, n, 1) {
		scanf("%lld", &num[i]);
	}
	num[n + 1] = 0;
	ll dist = 0;
	FOR(i, 0, n, 1) {
		dist += abs(num[i] - num[i + 1]);
	}
	FOR(i, 1, n, 1) {
		ll td = dist - abs(num[i - 1] - num[i]) - abs(num[i] - num[i + 1]) + abs(num[i - 1] - num[i + 1]);
		printf("%lld\n", td);
	}
	return 0;
}

Measured memory_bytes: 2048
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int x = scanInt(), n = scanInt();
        if (n == 0) {
            System.out.println(x);
            return;
        }

        boolean o = true;
        List<Integer> p = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            int t = scanInt();
            p.add(t);
            if (t == x) o = false;
        }

        if (o) {
            System.out.println(x);
            return;
        }

        int ans = x;
        for (int i = x-1; i >= 0; i--) {
            if (!p.contains(i)) {
                ans = i;
                break;
            }
        }

        for (int i = x+1; i < x+(x-ans); i++) {
            if (!p.contains(i)) {
                ans = i;
                break;
            }
        }

        System.out.println(ans);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

int main(){
  int n, k;	 cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  //期待値配列(整数で扱うため値は二倍)
  vector<int> a(n);
  rep(i,n)  a[i] = 1+p[i];
  //最大値を求める
  int mx = 0;
  int sum = 0;
  queue<int> q;
  rep(i,n){
    sum += a[i];
    q.push(a[i]);
    if(q.size() > k){
      sum -= q.front();
      q.pop();
    }
    if(q.size() == k){
      mx = max(sum, mx);
    }
  }
  double ans = (double)mx/2;
  printf("%.10f", ans);
  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define MOD 1e9+7
using namespace std;

int main() {
  int n;
  cin >> n;
  int w[110];
  rep(i,n) cin >> w[i];
  int ans = 100000010;
  for (int i = 0; i < n - 1; i++) {
    int w1 = 0;
    int w2 = 0;
    for (int j = 0; j <= i; j++) w1 += w[j];
    for (int j = i + 1; j < n; j++) w2 += w[j];
    ans = min(ans, abs(w1 - w2));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
------------------------
author : iiou16
time : 11/01/12:15
------------------------
'''


def main():
    N = int(input())
    org = N
    i = 2
    table = []
    while i * i <= N:
        if N % i == 0:
            j = org / i
            table.append(i + j - 2)
        i += 1
    table.append(org - 1)
    print(int(min(table)))


if __name__ == '__main__':
    main()


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

int dfs(int N,int a, int b, int c,int keta, int d) //3 5 7
{
	//cout << "Number:" << N << " a:" << a << " b:" << b << " c:" << c << " keta:" << keta << " d:" << d << endl;
	int ans = 0;
	if (keta == 1)
	{
		//cout << "a";
		if (d == 1)
		{
			if (N >= 7 && a == 1 && b == 1) ans++; //7
			if (N >= 3 && c == 1 && b == 1) ans++; //3
			if (N >= 5 && a == 1 && c == 1) ans++; //5
		}
		else
		{
			if (a == 1 && b == 1) ans++; //7
			if (c == 1 && b == 1) ans++; //3
			if (a == 1 && c == 1) ans++; //5
		}
		return ans;
	}

	int top; //一番上の位
	int div = 1;

	for (int i = 0; i < keta-1; ++i)
	{
		div *= 10;
	}

	top = N / div;
	//cout << " top: " << top << endl;
	int res1 = 0, res2 = 0, res3 = 0;

	if (d == 1)
	{
		if (top >= 3)
		{
			if (top == 3) res1 = dfs(N-div*top,1,b,c,keta-1,1);
			else res1 = dfs(N-div*top,1,b,c,keta-1,0);
		}

		if (top >= 5)
		{
			if (top == 5) res2 = dfs(N-div*top,a,1,c,keta-1,1);
			else res2 = dfs(N-div*top,a,1,c,keta-1,0);
		}

		if (top >= 7)
		{
			if (top == 7) res3 = dfs(N-div*top,a,b,1,keta-1,1);
			else res3 = dfs(N-div*top,a,b,1,keta-1,0);
		}
	}
	else
	{
		 res1 = dfs(N-div*top,1,b,c,keta-1,0);
		 res2 = dfs(N-div*top,a,1,c,keta-1,0);
		 res3 = dfs(N-div*top,a,b,1,keta-1,0);
	}

	ans = res1 + res2 + res3;
	return ans;
}

int main()
{
	int N;
	cin >> N;
	int ans = 0;
	
	/*
	int A[10]; //A[i] 桁数i+1の七五三数
	A[0] = 3;
	for (int i = 0; i < 9; ++i)
	{
	 	A[i+1] = A[i] * 3;
	}
	*/
	int keta = 0;
	int temp = N;
	while(temp > 0)
	{
		keta++;
		temp /= 10;
	}

	/*
	for (int i = 0; i < keta-1; ++i)
	{
		ans += A[i];
	}
	*/
	//cout << "keta: " << keta << endl;

	int tketa = keta;

	for (int i = 0; i < keta; ++i)
	{
		//cout << N;
		if (i == 0) ans += dfs(N,0,0,0,tketa,1);
		else ans += dfs(N,0,0,0,tketa,0);
		//cout << " ans:" << ans << endl;

		int top; //一番上の位
		int div = 1;

		for (int j = 0; j < tketa-1; ++j)
		{
			div *= 10;
		}

		top = N / div;
		N -= top*div;
		tketa--;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 

using namespace std;

int main() {
	string str;

	cin >> str;

	if (str.find("AC") != std::string::npos) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}





	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var n int
  var k int
  fmt.Scan(&n, &k)
  k2 := k*2
  // 0 ≦ x,y ≦ 2K に圧縮
  squares := make([][]int, k2)
  for i := range squares {
    squares[i] = make([]int, k2)
  }
  for i := 0; i < n; i++ {
    var x int
    var y int
    var color string
    fmt.Scan(&x, &y, &color)
    // 'W'はY方向にKずらした'B'と同値
    if color == "W" {
      y += k
    }
    squares[x % k2][y % k2]++ 
  }
  // 計算量削減のために累積和を事前算出
  for i := 0; i < k2; i++ {
    for j := 1; j < k2; j++ {
      squares[i][j] += squares[i][j-1]
    }      
  }
  for j := 0; j < k2; j++ {
    for i := 1; i < k2; i++ {
      squares[i][j] += squares[i-1][j]
    }
  }  
  max_ := 0
  end := k2-1
  for i := 0; i < k; i++ {
    for j := 0; j < k; j++ {
      // ex) k = 2
      //      ■ □ □ ■ 
      //  j+k □ ■ ■ □
      //      □ ■ ■ □
      //    j ■ □ □ ■
      //      i   i+k
      cnt :=
        (squares[i][j]) +
        (squares[end][j] - squares[i+k][j]) +
        (squares[i+k][j+k] - squares[i+k][j] - squares[i][j+k] + squares[i][j]) +
        (squares[i][end] - squares[i][j+k]) +
        (squares[end][end] - squares[end][j+k] - squares[i+k][end] + squares[i+k][j+k])
      max_ = max(max(cnt, n - cnt), max_)
    }
  }  
  fmt.Print(max_)
}

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

Measured memory_bytes: 45312
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

inline long long mod(long long a, long long m) {
  return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q) {
  if (b == 0) {
    p = 1;
    q = 0;
    return a;
  }
  long long d = extGcd(b, a % b, q, p);
  q -= a / b * p;
  return d;
}

pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q);  // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2 / d);  // lcm of (m1, m2)
  long long tmp = (b2 - b1) / d * p % (m2 / d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll M;
  while (cin >> N >> M) {
    vector<ll> A(N);
    for (ll &x : A) cin >> x;
    ll a = 0, m = 1;
    for (ll x : A) {
      auto sol = ChineseRem(a, m, x + x / 2, x);
      a = sol.fst;
      m = sol.snd;
      if (m < 0) break;
      if (a > M) break;
    }
    ll res = 0;
    if (m > 0 && a <= M) {
      res = (M - a) / m + 1;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
while(True):
    n = int(input())
    if n == 0:
        break
    c = 0
    l = []
    d = {}
    for i in range(n):
        num,x,y = map(int,input().split())
        if num in d:
            d[num] = d[num] + x*y
        else:
            d[num] = x*y
            l.append(num)
    for i in l:
        if d[i] >= 1000000:
            print(i)
            c += 1
    if c == 0:
        print('NA')

Measured memory_bytes: 7756
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int W,H,div_row[4] = {-1,0,0,1},div_col[5] = {0,-1,1,0};

struct Info{
	Info(){
		eat_after = row = col = hp = time = 0;
	}

	void set(int arg_row,int arg_col,int arg_hp,int arg_time,int arg_eat_after){
		row = arg_row;
		col = arg_col;
		hp = arg_hp;
		time = arg_time;
		eat_after = arg_eat_after;
	}

	int row,col,hp,time,eat_after;
	short check[8][8];
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){

	int map[H][W];
	int start_row,start_col,goal_row,goal_col;

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++){
			scanf("%d",&map[i][k]);
			if(map[i][k] == 2){
				start_row = i;
				start_col = k;
				map[i][k] = 1;
			}else if(map[i][k] == 3){
				goal_row = i;
				goal_col = k;
			}
		}
	}

	int ans = -1,limit = 2*H*W;
	queue<Info> Q;
	Info current;

	Info first;

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++)first.check[i][k] = 0;
	}

	first.check[start_row][start_col] = 1;
	first.set(start_row,start_col,6,0,3);

	Q.push(first);

	int debug = 0;
	while(!Q.empty()){
		current = Q.front();
		Q.pop();

		debug++;
		if(debug > 240000){ //I'm very sorry,I'm tired. I will submit an appropriate code someday.
			break;
		}

		if(current.hp == 0)continue;

		if(map[current.row][current.col] == 3){
			ans = current.time;
			break;
		}else if(map[current.row][current.col] == 4){
			current.hp = 6;
			current.eat_after = 0;
		}

		if(current.time + abs(current.row-goal_row)+abs(current.col-goal_col) > limit)continue;

		for(int i = 0; i < 4; i++){
			if(rangeCheck(current.row+div_row[i],current.col+div_col[i]) == true && map[current.row+div_row[i]][current.col+div_col[i]] != 0 &&
					((current.check[current.row+div_row[i]][current.col+div_col[i]] == 0) || (current.check[current.row+div_row[i]][current.col+div_col[i]] == 1 &&	current.eat_after <= 1))){
				Info new_info;
				for(int a = 0; a < H; a++){
					for(int b = 0; b < W; b++){
						new_info.check[a][b] = current.check[a][b];
					}
				}
				new_info.check[current.row+div_row[i]][current.col+div_col[i]]++;
				new_info.set(current.row+div_row[i],current.col+div_col[i],current.hp-1,current.time+1,current.eat_after+1);
				Q.push(new_info);
			}
		}
	}
	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 56652
N = int(input())
A_list = []
A_l = []
for i in range(N):
    A = int(input())
    A_list.append(A)
    A_l.append(A)
A_list.sort(reverse = True)

for j in range(N):
    if A_l[j] != A_list[0]:
        print(A_list[0])
    else:
        print(A_list[1])

Measured memory_bytes: 14120
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 100010
#define LL long long
int n, k, cnt, tot;
LL ans = 10000000000000000LL;
int s[AC];
LL l[AC], r[AC];

inline LL read()
{
	int x = 0;char c = getchar();bool z = false;
	while(c > '9' || c < '0') 
	{
		if(c == '-')  z = true;
		c = getchar();
	}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(!z) return x;
	else return -x;
}

void upmin(LL &a, LL b)
{
	if(b < a) a = b;
}

void pre()
{
	n = read(), k = read();
	int tmp = 0;
	for(R i = 1; i <= n; i ++)
	{
		s[i] = read();
		if(!tmp && s[i] >= 0) tmp = i;
	}
	if(tmp)
	{
		for(R i = tmp - 1; i ; i --) l[++cnt] = -s[i];
		for(R i = tmp; i <= n; i ++) r[++tot] = s[i];
	}
	else for(R i = n; i; i --) l[++cnt] = -s[i];
}

void work()
{
	int b = min(k, cnt);	
	for(R i = 0; i <= b; i ++)//枚举左边用几个
	{
		if(k - i <= tot) 
		{
			upmin(ans, l[i] + r[k - i] * 2);
			upmin(ans, l[i] * 2 + r[k - i]);
		}
	}
	printf("%lld\n", ans);
}

int main()
{
	pre();
	work();
	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    priority_queue<int> pq;
    int save;
    ll sum = 0;
    rep(i,N){
        cin >> save;
        pq.push(save);
        sum += save;
    }
    for(int i = M; i > 0; i--){
        int dis = pq.top()/2;
        sum -= (pq.top() - dis);
        pq.pop();
        pq.push(dis);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 892
# https://beta.atcoder.jp/contests/abc056/submissions/2924044
N, K, *AS = $stdin.read.split.map(&:to_i)
AS.sort!

sum_a = 0
ans = 0
(N-1).downto(0) do |i|
  if sum_a + AS[i] < K
    sum_a += AS[i]
    ans += 1
  else
    ans = 0
  end
end
p ans


Measured memory_bytes: 2044