akhauriyash/Code-Regression huggingface dataset:
/*
 * あなたが散歩していると、突然一体の魔物が出現しました。幸い、あなたは N 本の刀、刀 1、刀 2、…、刀 N を持っていて、次の二種類の攻撃を自由な順番で行うことができます。
 * 
 *     持っている刀のうち一本を振る。刀 i (1≤i≤N) を振ると、魔物は ai ポイントのダメージを受ける。同じ刀を何度振ることもできる。
 *     持っている刀のうち一本を投げつける。刀 i (1≤i≤N) を投げつけると、魔物は bi ポイントのダメージを受け、あなたはその刀を失う。すなわち、あなたは以後その刀を振ることも投げつけることもできなくなる。
 * 
 * 魔物は、受けたダメージの合計が H ポイント以上になると消滅します。魔物を消滅させるには、最小で合計何回の攻撃が必要でしょうか。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int h = Integer.parseInt(sc.next());
            int maxSlash = 0;
            Integer[] damageThrow = new Integer[n];
            int count = 0;
            int a = 0;
            int b = 0;
            
            for(int i=0; i<n; i++){
            	a = Integer.parseInt(sc.next());
                b = Integer.parseInt(sc.next());
                
                if(a>maxSlash){
                	maxSlash = a;
                }
                damageThrow[i] = b;
            }
            Arrays.sort(damageThrow);
            
            while(h>0){
            	if(count < n && maxSlash < damageThrow[n-count-1]){
            		h -= damageThrow[n-count-1];
            		count++;
            	}else{
            		count += (int)Math.ceil(h*1.0/maxSlash);
            		h = 0;
            	}
            }
            
            //出力
            System.out.println(count);
            sc.close();
        }
    }
	

Measured memory_bytes: 63204
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    int k,num = 0;
    int counter[26]={};
    while(getline(cin,S)){
        for(k=0;k<S.size();k++){
            if(S[k]>='a'&&S[k]<='z')counter[S[k]-'a']++;
            else if(S[k]>='A'&&S[k]<='Z')counter[S[k]-'A']++;
        }
    }
    for(k=0;k<26;k++){
        printf("%c",'a'+k);
        cout << " : " << counter[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
import copy
import random

D1 = list(map(int, input().split()))
D2 = list(map(int, input().split()))

for x in range(1000):
    r = random.randint(0,3)
    if r == 0:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[4]
        Dt[4] = Dt[5]
        Dt[5] = Dt[1]
        Dt[1] = temp
    elif r== 1:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[2]
        Dt[2] = Dt[5]
        Dt[5] = Dt[3]
        Dt[3] = temp
    elif r== 2:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[3]
        Dt[3] = Dt[5]
        Dt[5] = Dt[2]
        Dt[2] = temp
    elif r == 3:
        Dt = copy.copy(D2)
        temp = Dt[0]
        Dt[0] = Dt[1]
        Dt[1] = Dt[5]
        Dt[5] = Dt[4]
        Dt[4] = temp

    D2 = copy.copy(Dt)
        
    flag = 0
    for y in range(6):
        if D1[y] == D2[y]:
            flag += 1
    if flag == 6:
        break

if flag == 6:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

int main(void) {
  int N, M;
  cin >> N >> M;
  priority_queue<llong> A;

  llong a;
  for(int i=0;i<N;i++) {
    cin >> a;
    A.push(a);
  }

  for(int i=0;i<M;i++) {
    a = A.top(); A.pop();
    a /= 2;
    A.push(a);
  }

  llong ans=0;
  while(!A.empty()) {
    ans += A.top();
    A.pop();
  }

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

//keyword:priority queue


Measured memory_bytes: 1400
using System;
using System.Linq;

namespace _168_c
{
    internal class Colon
    {
        private static void Main(string[] args)
        {
            var abhm = Console.ReadLine()?.Split(" ").Select(double.Parse).ToArray();
            if (abhm == null) return;

            var a = abhm[0];
            var b = abhm[1];
            var h = abhm[2];
            var m = abhm[3];

            // 短針
            var aRad = (h / 12 + m / 60 * 1 / 12) * 360 * Math.PI / 180;
            var aX = a * Math.Sin(aRad);
            var aY = a * Math.Cos(aRad);

            // 長針
            var bRad = m / 60 * 360 * Math.PI / 180;
            var bX = b * Math.Sin(bRad);
            var bY = b * Math.Cos(bRad);

            var length = Math.Sqrt((aX - bX) * (aX - bX) + (aY - bY) * (aY - bY));
            Console.WriteLine(length);
        }
    }
}

Measured memory_bytes: 28688
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	R := sc.NextInt()
	G := sc.NextInt()
	B := sc.NextInt()
	N := sc.NextInt()
	ans := 0
	for r := 0; r <= 3000; r++ {
		for g := 0; g <= 3000; g++ {
			if N-r*R-g*G < 0 {
				break
			}
			if (N-r*R-g*G)%B == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
require "prime"
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class SegTree
  attr_accessor:node,:n
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    @node=array(2*@n-1,1,0)
  end

  def update(i,x)
    i=i+@n-1
    @node[i]=((x%2)==1 and Prime.prime?(x) and Prime.prime?((x+1)/2)) ? 1 : 0
    while i>0
      i=(i-1)/2
      @node[i]=@node[i*2+1]+@node[i*2+2]
    end
  end

  def find(s,t,i,l,r)
    return 0 if (r<=s or t<=l)
    return @node[i] if (s<=l and r<=t)
    mid=(l+r)/2
    val1=find(s,t,i*2+1,l,mid)
    val2=find(s,t,i*2+2,mid,r)
    return val1+val2
  end
end

q=gets.to_i
st=SegTree.new(10**5)
for i in 1..10**5
  st.update(i,i) 
end
q.times do|i|
  l,r=get_i
  puts st.find(l,r+1,0,0,st.n)
end

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n, m, a,b;
    cin >> n >> m;
    vec<vec<i32>> tree(n);
    rep(i, m) {
        cin >> a >> b;
        --a, --b;
        tree[a].push_back(b);
        tree[b].push_back(a);
//        debug(a);
//        debug(b);
    }

    queue<i32> que;
    vi seen(n), sign(n);
    seen[0] = 1;
    que.push(0);
    while(que.size()) {
        int v = que.front(); que.pop();
        for(auto nv : tree[v]) {
            if(seen[nv]) continue;
            seen[nv] = 1;
            sign[nv] = v+1;
            que.push(nv);
        }
    }

    cout << "Yes" << '\n';
    rep1(i,n-1) {
        cout << sign[i] << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 13672
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    map<ll,ll>m;
    for(ll i=0;i<n;i++)
        m[arr[i]]++;
    map<ll,ll>::iterator itr;
    ll ans = 0;
    for(itr = m.begin();itr!=m.end();itr++)
    {
        ll a = itr->second;
        a = a*(a-1);
        a/=2;
        ans += a;
    }
    for(ll i=0;i<n;i++)
    {
        ll a = m[arr[i]];
        ll b = a*(a-1);
        b /= 2;
        ll ans1 = ans-b;
        a--;
        b = 0;
        if(a)
        {
            b = b+(a*(a-1))/2;
        }
        cout<<ans1+b<<endl;
    }
}


Measured memory_bytes: 13184
N=int(input())
s=[0]*N
for _ in[0]*(N*~-N//2):
 a,b,c,d=map(int,input().split())
 s[a-1]+=3*(c>d)+(c==d)
 s[b-1]+=3*(d>c)+(d==c)
b=[[]for _ in[0]*N*3]
for i in range(N):
 b[s[i]]+=[i]
r=1
for x in b[::-1]:
 for y in x:
  s[y]=r
 if x:r+=len(x)
print(*s,sep='\n')


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

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

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << ' ' << 2*a+2*b << endl;
}



Measured memory_bytes: 3044
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let a = read::<i32>();
  let b = read::<i32>();

  if (a > b + 1) {
    println!("{:?}", a * 2 - 1);
  } else if (b > a + 1) {
    println!("{:?}", b * 2 - 1);
  } else if (b == a) {
    println!("{:?}", b * 2);
  } else {
    println!("{:?}", b + a);
  }

}



Measured memory_bytes: 4352
from math import sqrt
n = int(input())
m = int(sqrt(n))
lst = []
for i in range(2, m + 1):
    if n % i == 0:
        j = 0
        while True:
            if n % i == 0:
                n //= i
                j += 1
            else:
                for k in range(j):
                    lst.append(i)
                break

lst.append(n)

ans = float("INF")
for i in range(2 ** len(lst)):
    num1 = 1
    num2 = 1
    for j in range(len(lst)):
        if (i >> j) & 1:
            num1 *= lst[j]
        else:
            num2 *= lst[j]
    ans = min(ans, max(len(str(num1)), len(str(num2))))
    
print(ans)
            
            


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

int n, m, k;

int main() {
	cin >> n >> m >> k;

	bool flag = false;
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i*m - i*j + j*(n - i) == k)flag = true;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long lucas[90];
int main()
{
  int n;
  scanf("%d",&n);
  lucas[0]=2;
  lucas[1]=1;
  for(int i=2;i<=n;i++)
    lucas[i]=lucas[i-1]+lucas[i-2];
  printf("%lld",lucas[n]);
  return 0;
}

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

int main() {
    int n, t;
    cin >> n >> t;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    unordered_map<int, int> mp;
    int left = 0, right = 0, left_count = 1;
    for (int i = 1; i < n; i++) {
        if (a[i] < a[left]) {
            left = i;
            right = i;
            left_count = 1;
        } else if (a[i] > a[right]) {
            right = i;
            mp[a[i] - a[left]]++;
        } else if (a[i] == a[left]) {
            right = i;
            left_count++;
        } else if (a[i] == a[right]) {
            if (left_count > 0) {
                mp[a[i] - a[left]]++;
                left_count--;
            }
        }
    }
    int max_diff = 0, count = 0;
    for (auto p: mp) {
        if (max_diff < p.first) {
            max_diff = p.first;
            count = p.second;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


lint sign(lint x)
{
    if (x >= 0) return 1;
    else return -1;
}

int main()
{
    lint K, X, Y;
    cin >> K >> X >> Y;
    lint U = X + Y, V = X - Y;

    if (K % 2 == 0 and abs(X + Y) % 2)
    {
        puts("-1");
        return 0;
    }

    vector<plint> ret;
    lint kd = K % 2;

    while (U or V)
    {
        lint u, v;
        if (abs(U) <= K and abs(V) <= K)
        {
            if (abs(U) == K and abs(V) % 2 == kd) u = U, v = V;
            else if (abs(V) == K and abs(U) % 2 == kd) u = U, v = V;
            else if ((K - abs(U)) % 2 == kd)
            {
                u = U - K * sign(U);
                v = K * sign(V);
            }
            else if ((K - abs(V)) % 2 == kd)
            {
                u = K * sign(U);
                v = V - K * sign(V);
            }
            else
            {
                u = K * sign(U);
                v = K * sign(V);
            }
        }
        else
        {
            u = K * sign(U), v = K * sign(V);

            if (abs(K - abs(U)) % 2 == kd and abs(U) < K * 2)
            {
                u = U - K * sign(U);
                v = K * sign(V);
            }
            else if (abs(K - abs(V)) % 2 == kd and abs(V) < K * 2)
            {
                u = K * sign(U);
                v = V - K * sign(V);
            }
        }
        ret.emplace_back(u, v);
        U -= u;
        V -= v;
    }

    printf("%d\n", (int)ret.size());
    lint xn = 0, yn = 0;
    for (auto pa : ret)
    {
        lint d1 = (pa.first + pa.second) / 2;
        lint d2 = (pa.first - pa.second) / 2;
        if (abs(d1) + abs(d2) != K) exit(8);
        xn += d1;
        yn += d2;
        printf("%lld %lld\n", xn, yn);
    }
    if (xn != X or yn != Y) exit(8);
}


Measured memory_bytes: 5868
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};
struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}



int main(){
    IOS;
    make2(ll,n,k);
    makevec(ll,vec,n);
    ll c=0;
    sort(vec.begin(),vec.end());
    fr(i,k) c+=vec[i];
    cout<<c<<endl;

    return 0;
}


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

int main(void){
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    for (int i=0; i<N; i++) {
      if (i == K-1) {
        cout << (char) tolower(S[i]);
      } else {
        cout << S[i];
      }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;
	if (N / 100 == N % 10) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import numpy as np
N, C = map(int,input().split())
D = np.array(list(list(map(int,input().split()))for i in range(C)))
c = list(list(map(int,input().split()))for i in range(N))
A = [np.array([0]*C) for i in range(3)]
for i in range(N):
    for j in range(N):
        A[(i+j)%3][c[i][j]-1] += 1
H = [[[(A[j]*D[:,i]).sum(),i] for i in range(C)] for j in range(3)]
X = [[]for i in range(3)]
for i in range(3):
    X[i] = sorted(H[i])[:3]
ans = float('inf')
for a,i in X[0]:
    for b,j in X[1]:
        for c,k in X[2]:
            if i != j != k != i:
                ans = min(ans,a+b+c)
print(ans)

Measured memory_bytes: 14696
s = input()
if s == "SUN":
  print(7)
elif s == "MON":
  print(6) 
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
else:
  print(1)

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

ll arr[20][20];
ll C[20];
const int INF = 1001001001;

int main(void){
    int N,M,X;
    cin >> N >> M >> X;

    rep(i, N){
        cin >> C[i];
        rep(j, M){
            cin >> arr[i][j];
        }
    }
    
    
    int ans = INF;
    rep(s, 1<<N){
        ll A[20] = {0};
        int sum = 0;
        rep(i, N){
            if(s>>i&1){
                sum += C[i];
                rep(j,M){
                    A[j] += arr[i][j];
                }
            }
        }
        int flag = 1;
        rep(j,M){
            if(A[j] < X){
                flag = 0;
            }
        }
        if(flag == 1){
            ans = min(ans, sum);
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
	int n,x,count=0,ans=0;
	cin>>n>>x;
	int l[n];
	for(int i=0;i<n;i++)
	    cin>>l[i];
	for(int i=0;i<n;i++)
	{
	    ans=ans+l[i];
	    count++;
	    if(ans>x)
	    break;
	}
	if(ans<=x)
	count++;
	cout<<count<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct town
{
    double x,y;
} t[10];
int main()
{
    int n;
    int x=1;
    double sum=0;
    scanf("%d",&n);
    int a[20]= {0,1,2,3,4,5,6,7,8,9,10};
    for(int i=0; i<n; i++)
        scanf("%lf%lf",&t[i].x,&t[i].y);
    for(int i=1; i<n; i++)
    {
        double dx,dy;
        dx=(t[a[i]].x-t[a[i-1]].x);
        dy=(t[a[i]].y-t[a[i-1]].y);
        sum+=sqrt(dx*dx+dy*dy);
    }
    while(next_permutation(a,a+n))
    {
        x++;
        for(int i=1; i<n; i++)
        {
            double dx,dy;
            dx=(t[a[i]].x-t[a[i-1]].x);
            dy=(t[a[i]].y-t[a[i-1]].y);
            sum+=sqrt(dx*dx+dy*dy);
        }
    }
    printf("%.10lf\n",sum/x);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		String s = in.next();
		int k = 0, u = 0, p = 0, c = 0;

		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'K') k++;
			else if(s.charAt(i) == 'U') u++;
			else if(s.charAt(i) == 'P') p++;
			else if(s.charAt(i) == 'C') c++;
		}

		System.out.println(Math.min(k, Math.min(u, Math.min(p, c))));
	}
	
}

// while(in.hasNext()){
		// 	int n = in.nextInt();
		// 	if(n == 0) return;
			
		// }

Measured memory_bytes: 26228
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            WriteLine("ABC" + N);
        }

        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
int dist(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); }
int n, a, b, c, d, xp, yp;
signed main() {
	while (cin >> n, n) {
		cin >> a >> b >> c >> d >> xp >> yp;
		int ans = 0;
		for1(i, n) {
			int x, y; cin >> x >> y;
			int xp1 = xp, yp1 = yp, x1 = x, y1 = y;
			if (xp1 < a)xp1 = a;
			if (x1 < a)x1 = a;
			if (xp1 > c)xp1 = c;
			if (x1 > c)x1 = c;
			if (yp1 < b)yp1 = b;
			if (y1 < b)y1 = b;
			if (yp1 > d)yp1 = d;
			if (y1 > d)y1 = d;
			ans += min(dist(xp, yp, x, y), max(dist(xp, yp, xp1, yp1) - 1, 0) + dist(x, y, x1, y1));
			xp = x; yp = y;
		}
		cout << ans << endl;
	}
}


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

int main(){
	int n; cin >> n;
	vector<int> a(n);
	map<int,int> mp;
	rep(i,n){
		cin >> a[i];
		mp[a[i]]++;
	}
	int ans = 0;
	rep(i,100001){
		int count = mp[i] + mp[i+1] + mp[i-1];
		ans = max(ans, count);
	}
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,c,f;
	cin>>i>>j>>k;
	f=0;
	if(i==0)f=1;
	i=i>0?i-1:i;
	cout<<((j/k)-(i/k))+f;
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/

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


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,t=0,ans=LLONG_MAX;
    cin>>n;
    vector<ll>a(n),sum(n,0);
    rep(i,0,n){
        cin>>a[i];
        t+=a[i];
        sum[i]=t;
    }
    rep(i,0,n-1){
        ans=min(ans,abs(sum[n-1]-sum[i]-sum[i]));
    }
    cout<<ans<<endl;


    
}


Measured memory_bytes: 3328
#include<cstdio>
int P,f[307][307][307];
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int main()
{
    int n,m;scanf("%d%d%d",&n,&m,&P),f[0][1][0]=1;
    for(int i=0;i<=n;++i) for(int j=1;j<=m;++j) for(int k=i;~k;--k) k? inc(f[i][j][k-1],f[i][j][k]):inc(f[i][j+1][i],f[i][j][k]),inc(f[i+1][j][k],(k+1ll)*f[i][j][k]%P);
    printf("%d",f[n][m][0]);
}


Measured memory_bytes: 112768
#include <stdio.h>

typedef struct _grade {
	int number;
	int tyouka;
} grade_t;

int main()
{
	int n, max = 0, minnum = 1;
	grade_t g[20];

	scanf( "%d", &n );
	for ( int i = 0 ; i < n ; i++ ) {
		scanf( "%d %d", &g[i].number, &g[i].tyouka );
		if ( max < g[i].tyouka ) {
			max = g[i].tyouka;
			minnum = g[i].number;
		} else if ( max == g[i].tyouka ) {
			if ( minnum > g[i].number ) {
				minnum = g[i].number;
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 2104
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	var cnt int
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a == b {
			cnt++
		} else if cnt < 3 {
			cnt = 0
		}
	}

	if cnt >= 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int n, m;

int main() {
    cin >> n >> m;
    UnionFindTree g;
    g.init(n);
    REP(i,m){
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        g.unite(x,y);
    }
    set<int> st;
    REP(i,n){
        st.insert(g.find(i));
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 6144
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 1; i <= n; i++){
            if(i % 3 == 0 || Integer.toString(i).contains("3")){
                System.out.printf(" %d",i);
            }
        }
        System.out.printf("\n");
    }
}



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

int main(){
	int K, S;
	cin >> K >> S;
	int i, j;
	int res = 0;
	for (i = 0;i <= K; i++) {
		for (j = 0;j <= K; j++) {
			if (i + j <= S && i + j >= S - K) res++;
			if (i + j > S) break;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
N = $stdin.gets.chomp.to_i
a = $stdin.gets.chomp.split(' ').map(&:to_i)
b = $stdin.gets.chomp.split(' ').map(&:to_i)

N.times do |i|
    if a[i] < b[i]
        print '-1'
        exit
    end
end

max_a = a.max

#dp[i][j]: procedures for i -> j (i>=j)
dp = Array.new(max_a+1){Array.new(max_a+1)}

(0..max_a).each do |i|
    dp[i][i] = [[]]
end

(1..max_a).each do |i|
    (0..i-1).each do |j|
        (1..i).each do |k|
            if dp[i%k][j]
                dp[i][j] ||= []
                dp[i%k][j].each do |pro|
                    dp[i][j].push([k] + pro) unless dp[i][j].include?(pro)
                end
            end
        end
    end
end

arr_of_procs = N.times.map{|i| dp[a[i]][b[i]]}

if arr_of_procs.include?(nil)
    print '-1'
    exit
end

cost = 0

loop do
    arr_of_procs.length.times do |i|
        arr_of_procs[i] = nil if arr_of_procs[i].include?([])
    end
    arr_of_procs.compact!
    break if arr_of_procs.length == 0

    use = 0
    arr_of_procs.each do |procs|
        need = procs.map{|pro| pro.max}.min
        use = [need, use].max
    end
    if use > 0
        cost += 2**use
        arr_of_procs.each do |procs|
            procs.each do |pro|
                pro.delete(use)
            end
        end
    end
end

print cost

Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 110;
const int maxk = 100100;
const ll mod = 1e9 + 7;

ll n, k;
ll a[maxn];

ll dp[maxk];
ll pref[maxk];

int main() {
	cin>>n>>k;
	
	cin>>a[1];
	for(int i=0;i<=a[1];i++) {
		dp[i] = 1LL;
	}

	pref[0] = dp[0];
	for(int i=1;i<=k;i++) {
		pref[i] = pref[i-1] + dp[i];
	}
	for(int i=2;i<=n;i++) {
		cin>>a[i];

		memset(dp, 0, sizeof(dp));

		for(int j=k;j>=0;j--) {
			if(j - a[i] <= 0) {
				//cout<<j<<": "<<pref[j]<<"\n";
				dp[j] += pref[j];
				dp[j] %= mod;
			}
			else 
				dp[j] += (pref[j] + mod - pref[j-a[i]-1]) % mod;
				dp[j] %= mod;
		}

		pref[0] = dp[0];
		for(int j=1;j<=k;j++) {
			pref[j] = pref[j-1] + dp[j];
			pref[j] %= mod;
		}
	}
	cout<<dp[k]<<"\n";
}

Measured memory_bytes: 1792
#include <stdio.h>

int sosuu(int a){
  int i;
  if(a==2)return 1;
  else if(a%2==0)return 0;
  for(i=3;i*i<=a;i++){
    if(a%i==0)return 0;
  }
  return 1;
}

int main(){
  int a,b,k=0,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b);
    if(sosuu(b)==1)k++;
  }
  printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

using Graph = vector<vector<int>>;
int main(){
  int N, M; cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H[i];

  Graph G(N);
  for (int i = 0; i < M; ++i){
    int a, b; cin >> a >> b;
    a--; b--;
    if (!vector_finder(G[a], b)) G[a].push_back(b);
    if (!vector_finder(G[b], a)) G[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i){
    int now = H[i];
    bool flag = true;
    for (auto nv: G[i]){
      if (H[nv] >= now) flag = false;
    }
    if (flag) ans++;
  }
  cout << ans << endl;
}


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> v;
    vector<int> vmi;
    REP(i, N) {
        int tmp; cin >> tmp;
        v.push_back(tmp);
        if (i == 0) {
            vmi.push_back(tmp);
        }
        else {
            vmi.push_back(min(tmp,vmi[i-1]));
        }
    }
    int res = 0;
    REP(i, N) {
        if (vmi[i] == v[i]) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int x1,x2,x3,x4,x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if(!x1) cout << 1;
	if(!x2) cout << 2;
	if(!x3) cout << 3;
	if(!x4) cout << 4;
	if(!x5) cout << 5;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>

using namespace std;
typedef long long ll;

int main()
{
	ll N, K;
	scanf("%lld %lld", &N, &K);
	
	if (N > K){
		N = N - (N / K) * K;
	}
	
	ll min = N;
	for(int i = 0; i < 100; i++){
		N = abs(N-K);
		if(min > N){
			min = N;
		}
	}
	
	printf("%lld\n", min);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N,M,C[16],x[20010];
int dp[20010][256];

void solve(){
  rep(i,20010) fill(dp[i], dp[i]+256, INF);
  dp[0][128] = 0;

  rep(i,N){
    rep(j,256){
      if(dp[i][j]==INF) continue;
      rep(k,M){
	int next = max(0, min(j+C[k], 255));
	dp[i+1][next] = min(dp[i+1][next], dp[i][j] + SQ(x[i]-next));
      }
    }
  }
  int res = INF;
  rep(i,256) res = min(res, dp[N][i]);
  printf("%d\n", res);
}

int main(){
  while(scanf("%d%d", &N,&M) && N||M){
    rep(i,M) scanf("%d",&C[i]);
    rep(i,N) scanf("%d",&x[i]);
    
    solve();		   
  }
  return 0;
}

Measured memory_bytes: 21272
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string s; cin >> s;
    bool res = false;
    bool even = s.size() % 2 == 0;
    res = (s.at(0) == s.at(s.size() - 1)) ^ even;
    
    if (res) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
}


Measured memory_bytes: 512
import math
n = int(input())
a = [int(x) for x in input().split()]

bit = int(math.log2(max(a+[1])))+1
key = [0]*bit
ans = 0
ans_bef = 0
for i in range(n):
  value = a[i]
  max_len = ans_bef
  for j in range(bit):
    if value%2 == 1:
      if max_len > key[j]:
        max_len = key[j]
      key[j] = 0
    else:
      key[j] += 1
    value //= 2
  ans_bef = max_len+1
  ans += max_len
      
ans += n
print(ans)

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

using namespace std;

#define int long long int
#define fi first
#define so second
#define ps push_back

signed main()
{
    int n,m;
    cin>>n>>m;
    int i,j,b,k;
    int cost[m];
    vector<int> v[m];
    for(i=0;i<m;i++)
    {
        cin>>cost[i]>>b;
        for(j=0;j<b;j++) {cin>>k;v[i].ps(k);}
    }
    int dp[m+1][1<<n];
    for(i=0;i<=m;i++) for(j=0;j<(1<<n);j++) dp[i][j]=1e9;
    for(i=0;i<=m;i++)
    {
        b=0;
        if(i==0) {dp[i][0] = 0;for(j=1;j<(1<<n);j++) dp[i][j] = 1e9;}
        else
        {
            for(j=0;j<v[i-1].size();j++) b|=1<<(v[i-1][j]-1);
            dp[i][0]=0;
            for(j=0;j<(1<<n);j++) {
            dp[i][(j | b)] = min(min(dp[i-1][(j | b)],dp[i-1][j] + cost[i-1]),dp[i][(j|b)]);
            }
            for(j=0;j<(1<<n);j++) dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }
    //for(i=0;i<=m;i++) {for(j=0;j<(1<<n);j++) cout<<dp[i][j]<<" ";cout<<endl;}
    cout<<(dp[m][(1<<n)-1]!=1e9?dp[m][(1<<n)-1]:-1);

}


Measured memory_bytes: 32384
s=input()
n=len(s)
S=[]
mod = 10**9+7
M = [[0 for i in range(10)] for j in range(n)]

for i in range(10):
    M[0][i] = i
for i in range(1, n):
    for j in range(10):
        M[i][j] = (M[i-1][j] * 10) % 13

#print(M)

for i in range(n):
    if s[-i-1]=="?":
        S.append("?")
    else:
        S.append(int(s[-i-1]))

#print(S)

DP = [[0 for i in range(13)] for j in range(n)]

if S[0]=="?":
    for i in range(10):
        DP[0][i] += 1
else :
    DP[0][S[0]] += 1



for i in range(1, n):
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                DP[i][(k+M[i][j])%13] += DP[i-1][k]%mod
    else:
        j=S[i]
        for k in range(13):
            DP[i][(k+M[i][j])%13] += DP[i-1][k]%mod

    #print(DP)

print(DP[-1][5]%mod)


Measured memory_bytes: 94504
// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

using ll = long long;
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(5000000);

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

    int N = S.size();

    mint ans = 0;

    rep(i, K+1) {
        ans += mint(26).pow(i) * comb(N+K-i-1, N-1) * mint(25).pow(K-i);
    }

    cout << ans.x << endl;
}

Measured memory_bytes: 83364
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 998244353;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    vector<string> retu(N);
    for(int i = 0;i<N;i++)cin >> retu.at(i);
    map<int,long long> M;
    for(int i = 0;i<N;i++){
        string now = retu.at(i);
        if(now.front() == 'M') M[0]++;
        if(now.front() == 'A') M[1]++;
        if(now.front() == 'R') M[2]++;
        if(now.front() == 'C') M[3]++;
        if(now.front() == 'H') M[4]++;
    }
    long long ans = 0;
    for(int i = 0;i<=4;i++){
        for(int j = 0;j<=4;j++){
            for(int k = 0;k<=4;k++){
                if(i == j || j == k || i == k){
                    continue;
                }
                ans += M[i]*M[j]*M[k];
            }
        }
    }
    cout << ans/6 << endl;
}


Measured memory_bytes: 6144