akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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




int main(){
    std::string K; std::cin >> K;
    int N(K.length()), D; std::cin >> D;
    //dpn[i][j] := 上からi桁(0o)でmodD = j の数(n:0 小さい確定)
    std::vector<std::vector<int>> dp0(N+1, std::vector<int>(D, 0));
    std::vector<std::vector<int>> dp1(N+1, std::vector<int>(D, 0));
    dp1[0][0] = 1;
    for(int i(0); i < N; ++i){
        int n(K[i]-'0');
        for(int j(0); j < D; ++j){
            for(int k(0); k < 10; ++k){
                dp0[i+1][(j+k)%D] = (dp0[i+1][(j+k)%D] + dp0[i][j]) % MOD;
            }
            for(int k(0); k < n; ++k){
                dp0[i+1][(j+k)%D] = (dp0[i+1][(j+k)%D] + dp1[i][j]) % MOD;
            }
            dp1[i+1][(j+n)%D] = (dp1[i+1][(j+n)%D] + dp1[i][j]) % MOD;
        }
    }
    std::cout << (dp0[N][0] + dp1[N][0] - 1 + MOD) % MOD << std::endl;
    return 0;
}


Measured memory_bytes: 8832
import itertools

def choice_lst(n, choice_number):
    n_lst = []
    for i in range(n):
        n_lst.append(i)
    lst = list(itertools.combinations(n_lst, choice_number))
    return lst


def main():
    n = int(input())
    l_lst = list(map(int, input().split()))
    count = 0

    choices = choice_lst(n, 3)
    for i in range(len(choices)):
        tmp_lst = []
        for j in range(3):
            choiced_number = choices[i][j]
            tmp_lst.append(l_lst[choiced_number])

        tmp_lst.sort()
        l1 = tmp_lst[0]
        l2 = tmp_lst[1]
        l3 = tmp_lst[2]
        if l1 + l2 > l3 and l1 != l2 and l2 != l3:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 20540
divider = "#" * 20
input = Hash.new {|h,k| k = 0}
gets.to_i.times do
  b, f, r, v = gets.split.map!(& :to_i)
  input["#{b} #{f} #{r}"] += v
end
1.upto(4) do |i|
  1.upto(3) do |j|
    1.upto(10) do |k|
      print " " + input["#{i} #{j} #{k}"].to_s 
    end
    puts
  end
  if (i != 4) then 
  	puts divider
  end 
end 

Measured memory_bytes: 8640
#include <iostream>

using namespace std;

int niz[1000000];
int dp[100020];

int main()
{
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>niz[i];
   }
   dp[0]=0;
   dp[1]=abs(niz[0]-niz[1]);
   for(int i=2;i<n;i++)
   {
       dp[i]=min(dp[i-1]+abs(niz[i-1]-niz[i]),dp[i-2]+abs(niz[i-2]-niz[i]));
   }
   cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    
    d = {}
    for i in a:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    m = max(d.values())
    for k, v in sorted(d.items()):
        if v == m:
            print(k)
    
if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n, m, sumInput = 0, a;
    cin >> n >> m;
    while (m--)
    {
        cin >> a;
        sumInput += a;
    }
    if (n - sumInput >= 0)
        cout << n - sumInput << "\n";
    else
        cout << -1 << "\n";
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int x;
  cin >> x;
  for (int i = 1; 100 * i <= x; i++){
    int y = x - 100 * i;
    if(y <= 5 * i){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

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

    int ind = 0;
    int ans;
    for(int i=max(a,b); i>=1; i--){
        if(a%i==0 and b%i==0){
            ind++;
            ans = i;
        }
        if(ind == k){
            cout << ans << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>
using namespace std;
int main(){
    string x;
    int a,b;
    while(1){
        cin >> x >> a;
        if(x == "-") break;
        for(int i=0;i<a;i++){
            cin >> b;
            x=x.substr(b,x.size()-b)+x.substr(0,b);
        }
        cout << x << endl;
  }
  
}
  
  
  
  



Measured memory_bytes: 3200
/***
**                      ALLAHU AKBAR
**
**     Author: Khairul Anam Mubin
**     Bangladesh University of Business and Technology,
**     Dept. of CSE.
***/
#include <bits/stdc++.h>
using namespace std;
 
#define F            first
#define S            second  
#define Fin          freopen("input.txt","r",stdin)
#define Fout         freopen("output.txt","w",stdout)
#define Precision(a) cout << fixed << setprecision(a)
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
#define Faster       cin.tie(0);cout.tie(0); 
#define Test         int test;cin >> test;for(int tc = 1; tc <= test; tc++)
#define dbg          int nnn = 1; cout << nnn++ << " : debug\n";
 
#define MOD          998244353
#define INF9         2147483647
#define INF18        9223372036854775806
#define eps          1e-8 
 
const double pi = 2 * acos(0.0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> void Print(T ar[] , int a , int b) {for (int i = a; i + 1 <= b ; i++)cout << ar[i] << " ";cout << ar[b] << "\n";}
template <typename T> void Print(T ar[] , int n) {for (int i = 0; i + 1 < n; i++)cout << ar[i] << " ";cout << ar[n - 1] << "\n";} 
template <typename T> void Print(const vector<T> &v) {for (int i = 0; i + 1 < v.size() ; i++) cout << v[i] << " ";cout << v.back() << "\n";}

int main(int argc, char const *argv[])
{
    FasterIO
    int n; cin >> n;
    if (n % 1000 == 0) {
        cout << "0\n";
    } else {
        cout << ((((n / 1000) + 1) * 1000) - n) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,a,b,c,d,i=0;
  cin>>A>>B;
  while(A<B+1){
    a=A/10000;
    b=(A-a*10000)/1000;
    if (A%100 == b*10+a){
      i++;
    }
    A++;
  }
  cout<<i<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int a[m];
    int sum = 0;
    for(int i = 0; i < m; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }

    if(n < sum){
        printf("-1");
        return 0;
    }

    sum = n - sum;
    printf("%d", sum);
    return 0;

}

Measured memory_bytes: 1728
#!/usr/bin/env python3
a,b,c,d = map(int,input().split())	
def my_gcd(i,j):
    if i > j: i,j = j,i
    while i != 0:
        if j % i != 0:
            i,j = j%i,i
        else: return i
def not_div(n):
    return b//n  - (a-1) //n
print(not_div(1)-not_div(c)-not_div(d)+not_div(c*d//my_gcd(c,d))) 

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

int32_t main()
{
    int n, m;
    cin >> n >> m;
    map<int, int> mapa;
    map<int, bool> vis;
    int pen = 0, pro = 0;
    while(m--)
    {
        string s;
        int p;
        cin >> p >> s;
        if(s == "WA")
            mapa[p]++;
        else if(!vis[p]) 
        {
            pro++;
            pen += mapa[p];
            vis[p] = true;
        }
    }
	cout << pro << ' ' << pen << '\n';
	
	return 0;
}

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

namespace A_ABC161
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            WriteLine("{0} {1} {2}",s[2],s[0],s[1]);
        }
    }
}


Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.Scanner;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static final long[] fal_rnd(int size){
		AtomicInteger l=new AtomicInteger(-1),r=new AtomicInteger(size);
		long[] res=new long[size];
		INS(size).unordered().parallel().mapToLong(Long::parseLong).forEach(v->res[ThreadLocalRandom.current().nextBoolean()?l.incrementAndGet():r.decrementAndGet()]=v);
		return res;
	}
	static final IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static final Stream<String> INS(long size){
		return StreamSupport.stream(Spliterators.spliterator(s,size,Spliterator.NONNULL&Spliterator.IMMUTABLE),false).limit(size);
	}
	public static void main(String[]__){
		int n=s.nextInt(),m=s.nextInt();
		int[][] ar=new int[n][n];
		for(int i=0;i<m;i++) {
			int a=s.nextInt()-1,b=s.nextInt()-1;
			ar[a][b]++;
			ar[b][a]++;
		}
		Arrays.stream(ar).mapToInt(i->Arrays.stream(i).sum()).forEach(System.out::println);
	}
}


Measured memory_bytes: 28240
#!/usr/bin/env python3
# CGL_2_A: Segments/Lines - Parallel/Orthogonal


def is_parallel(v1, v2):
    return dot(orthogonal(v1), v2) == 0


def is_orthogonal(v1, v2):
    return dot(v1, v2) == 0


def dot(v1, v2):
    x1, y1 = v1
    x2, y2 = v2
    return x1 * x2 + y1 * y2


def orthogonal(v):
    x, y = v
    return -y, x


def run():
    q = int(input())

    for _ in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()]

        v1 = (x1-x0, y1-y0)
        v2 = (x3-x2, y3-y2)

        if is_parallel(v1, v2):
            print(2)
        elif is_orthogonal(v1, v2):
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    run()



Measured memory_bytes: 5624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int sum(const vi& a)
{
	return accumulate(allof(a),0);
}

int main()
{
	for(int m;cin>>m,m;){
		int n;
		vvi dist;
		{
			vi a(m),b(m),w(m);
			rep(i,m) cin>>a[i]>>b[i]>>w[i];
			n=max(*max_element(allof(a)),*max_element(allof(b)))+1;
			dist.assign(n,vi(n,1<<29));
			rep(i,m)
				dist[a[i]][b[i]]=dist[b[i]][a[i]]=w[i];
			rep(i,n)
				dist[i][i]=0;
		}
		
		rep(k,n) rep(i,n) rep(j,n)
			dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
		
		int res=0;
		rep(i,n)
			if(sum(dist[i])<sum(dist[res]))
				res=i;
		cout<<res<<" "<<sum(dist[res])<<endl;
	}
	
	return 0;
}

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

long long gcd(long long a,long long b){
  return b ? gcd(b,a%b) : a;
}

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

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

  long long ans=lcm(a,b);
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N, M, cnt;
  cin >> N >> M;
char n[N][N] = {};
char m[M][M] = {};  
bool a = false;  
  
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
     cin >> n[i][j];  
    }
  }
 
  for(int i = 0;i < M;i++){
    for(int j = 0;j < M;j++){
     cin >> m[i][j]; 
    }
  }
  
  for(int i = 0;i <= N - M;i++){
    for(int j = 0;j <= N - M;j++){
      cnt = 0;
      for(int k = 0;k < M;k++){
        for(int l = 0;l < M;l++){ 
          if(n[i+k][j+l] == m[k][l]) cnt++;   
        }          
      }  
      if(cnt == M * M){ 
            a = true;
            break;
      }
   }
  }
  if(a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
    int n, k; cin >> n >> k; vector<int64_t> mx, px;
    for (auto i = 0; i < n; i++) {
        int x; cin >> x;
        if(x > 0) px.push_back(x);
        else if(x < 0) mx.push_back(abs(x));
        else k--;
    }
    reverse(mx.begin(), mx.end());
    if(k == 0) { cout << 0 << endl; return 0; }
    int64_t ans = min(((int)px.size() >= k ? px[k - 1] : INT64_MAX),
                       (int)mx.size() >= k ? mx[k - 1] : INT64_MAX);
    for (auto i = 1; i < k; i++) {
        if ((int) mx.size() < i) continue;
        if ((int) px.size() < k - i) continue;
        int64_t left = mx[i - 1] * 2 + px[k - i - 1],
                right = mx[i - 1] + px[k - i - 1] * 2;
        ans = min(ans, min(left, right));
//        cout << i << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4416
N,T=map(int,input().split())
L=[]
for i in range(N):
  a,b=map(int,input().split())
  L.append((a,b))
L.sort()

DP=[[0 for i in range(T)] for j in range(N)]

for i in range(N):
  a=L[i][0]
  b=L[i][1]
  for j in range(min(T,a)):
    DP[i][j]=DP[i-1][j]
  for j in range(min(T,a),T):
    DP[i][j]=max(DP[i-1][j-a]+b,DP[i-1][j])
    
ans=0
for i in range(N-1):
  ans=max(ans,DP[i][T-1]+L[i+1][1])
print(ans)

Measured memory_bytes: 149820
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.readline

def main():
    N = int(input())
    s = [list(map(str,input())) for _ in range(N)]
    s += s
    ans = 0
    for i in range(N):
        b = True
        for x in range(N):
            for y in range(x,N):
                if s[x+i][y] != s[y+i][x]:
                    b = False
        if b:
            ans += N
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 45164
import sys 
sys.setrecursionlimit(100000000)
n = int(input())
graph = [[] for _ in range(n)]
color = [-1]*n
dist = [-1]*n
dist[0] = 0
visited = [0]*n
for _ in range(n-1):
  u, v, w = map(int, input().split())
  u -= 1
  v -= 1 
  graph[u] += [[v, w]]
  graph[v] += [[u, w]]
  
def dfs(u, d):
  for v, w in graph[u]:
    if dist[v] == -1:
      dist[v] = (w + d) % 2
      dfs(v, d+w)
      
dfs(0, 0)
for i in dist:
  print(i)

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

const ll mod = 1e9 + 7;
const ll MAXX = 1e18;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	ll a, b;
	cin >> a >> b;
	if (a > 9 || b > 9) {
		cout << -1 << '\n';
	}
	else {
		cout << a * b << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
K =int(input())
l = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,194157,207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,10493367, 10611772,10813692]
print(l[K])

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

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		long[] dp = new long[n+1];
		int m = sc.nextInt();
		
		for (int i = 0; i< m; i++) {
			int a = sc.nextInt();
			dp[a] = -1;
		}
		
		dp[0] = (dp[0] == 0) ? 1 : -1;
		dp[1] = (dp[1] == 0) ? 1 : -1;
		
		for (int i = 2; i < dp.length;i++) {
			if (dp[i] != -1) {
				long step1 = (dp[i-1] == -1) ? 0 : dp[i-1];
				long step2 = (dp[i-2] == -1) ? 0 : dp[i-2];
				
				dp[i] = (step1 + step2) % MOD;
			}
			
		}
		
		System.out.println(dp[dp.length-1]);
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M; cin >> N >> M;
    vec p(M-1), X(M);
    rep(i, M) cin >> X[i];
    if(M == 1){
        cout << 0 << endl;
        return;
    }
    sort(all(X));
    rep(i, M-1){
        p[i] = X[i+1]-X[i];
    }
    sort(all(p));
    reverse(all(p));

    int res = 0;
    Rep(i, N-1, M-1){
        res += p[i];
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5120
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */

    int n = sc.nextInt();
    int k = sc.nextInt();

    if (k == 1) {
      os.println(0);
    } else {
      os.println(n - k);
    }
  }
}

Measured memory_bytes: 21588
#include<iostream>
using namespace std;
#include<stdio.h>

// Binary heap structure.
int *H;  // H[1], H[2], ... , H[n], H[n+1], H[n+2], ... , H[2n].

// keep on condition: H[x] = H[2x] + H[2x+1]. O(log(n)).
void add(int x, int y, int n)
{
    for(x += n, H[x] += y; x > 1; x >>= 1) // x >>= 1 means x /= 2.
        H[x >> 1] = H[x] + H[x ^ 1];       // x ^ 1: x = 2m then x + 1, x = 2m + 1 then x - 1.
    return;
}

// binary search. O(log(n)). very fast.
long long getSum(int x, int y, int n)
{
    long long sum = 0; // x, y starts from leaf, usually.

    for(x += n, y += n; y > x + 1; x = ((x + 1) >> 1), y = ((y - 1) >> 1)){
        if(x & 1){ sum += H[x]; }
        if(!(y & 1)){ sum += H[y]; }
    }
    if(x == y){ sum += H[x]; }else{ sum += H[x] + H[y]; }
    return sum;
}

int main()
{
    H = new int [1 << 18];
    int n, q;
    scanf("%d %d", &n, &q);
    int cmd, x, y;

    fill(H, H + 2 * n + 1, 0);

    while(q){
        scanf("%d %d %d", &cmd, &x, &y);
        if(cmd){
            printf("%lld\n", getSum(x, y, n));
        }else{
            add(x, y, n);
        }
        q--;
    };
    delete [] H;
    return 0;
}

Measured memory_bytes: 1800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.next();
		scan.close();
		char[] s_char =s.toCharArray();
		int check=0;
		//回文か調べる
		for(int i=0;i<s.length()/2;i++) {
			if(s_char[i]!=s_char[s.length()-1-i]) {
				check=1;
				break;
			}
		}

		for(int i=0;i<s.length()/4;i++) {
			if(s_char[i]!=s_char[s.length()/2-1-i]) {
				check=1;
				break;
			}
			if(s_char[s.length()/2+1+i]!=s_char[s.length()-1-i]) {
				check=1;
				break;
			}
		}
		System.out.println((check==1)? "No":"Yes");

	}
}


Measured memory_bytes: 35744
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    int mi = P[0], res = 1;
    rep(i, N) {
        if(i == 0)
            continue;
        if(mi >= P[i])
            res++;
        mi = min(mi, P[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
N, M = map(int, input().split())
A = np.asarray(range(N+1), dtype=np.int64)
MOD = 10**9+7
S, E = (N/2) * (N+1), (N/2) * (N+1)
result = 1
for i, j in zip(range(N - M + 1), range(N, -1, -1)):
    S = S - i
    E = E - j
    # print(S, E)
    result += (S - E + 1) % MOD
    result %= MOD
    # print(result)
print(int(result))

Measured memory_bytes: 36240
n = int(input())
# print(n)
n_s = str(n)
len_n = len(n_s)
# print(len_n)
ans = n_s[len_n -1]
# print(ans)

if ans == "3":
    print("bon")
elif ans == "0" or ans == "1" or ans == "6" or ans == "8":
    print("pon")
else:
    print("hon")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    int a;
    int odd = 0;
    REP(i, n) {
        cin >> a;
        if (a % 2 == 1) odd++;
    }
    cout << (odd % 2 == 1 ? "NO" : "YES") << endl;
}



Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
vi vec;
int ans=0;

signed main(){
    io();

    in(n);
    resz(n,vec);
    in(vec);

    sort(all(vec));
    rep(i,(n-2)/2){
        ans+=(vec[n-1-i]-vec[i])*2;
    }
    if(n&1){
        ans+=vec[n/2+1]-vec[n/2-1];
        ans+=max(vec[n/2+1]-vec[n/2],vec[n/2]-vec[n/2-1]);
    }else{
        ans+=vec[n/2]-vec[n/2-1];
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 1656
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, b[100], ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &b[i]);
  }
  ans += b[0];
  for (int i = 0; i < n - 2; i++) {
    ans += min(b[i], b[i + 1]);
  }
  ans += b[n - 2];
  printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(long long n, long long k) {
        long long res = n;

        if (n >= k) {
            n %= k;
        }
        res = min(res, n);
        res = min(res, k - n);

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n, k;
    cin >> n >> k;

    Solution sol;
    cout << sol.solve(n, k) << "\n";
    return 0;
}

Measured memory_bytes: 256
import Data.List


main = do
    [a, b, c] <- map read . words <$> getLine
    putStrLn $ show $ ans a b c
    
ans :: Int -> Int -> Int -> Int
ans a b c = ret tmpsum
    where
        maxv = foldl1 max [a, b, c]
        acnt = (maxv - a) `div` 2
        bcnt = (maxv - b) `div` 2
        ccnt = (maxv - c) `div` 2
        newa = a + acnt * 2
        newb = b + bcnt * 2
        newc = c + ccnt * 2
        tmpsum = sum [newa, newb, newc]
        ret tmpsum
            | tmpsum == maxv * 3 = acnt + bcnt + ccnt
            | tmpsum == maxv * 3 - 1 = acnt + bcnt + ccnt + 2
            | otherwise = acnt + bcnt + ccnt + 1


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         0x3f3f3f3f
#define sc(n)       scanf("%d",&n);
#define ssc(n)      scanf("%s",n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define VI          vector<int>
#define MII         map<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define F(i,a,b)    for(i=a;i<b;i++)
#define IN(n,aa)    for(i=0;i<n;i++)scanf("%d",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         100009
#define NUM2        1000000000

LL BIGMOD(LL a,LL pow)
{
    if(pow==0)return 1;
    LL ret=BIGMOD(a,pow/2);
    ret=ret*ret%mod;
    if(pow%2)ret=ret*a%mod;
    return ret;
}

LL nCr(LL n,LL r)
{
    LL i,j,k=1,ans=1;
    for(i=0;i<r;i++)
    {
        ans=ans*(n-i)%mod;
    }
    for(i=1;i<=r;i++)
    {
        k=k*i%mod;
    }
    return ans*BIGMOD(k,mod-2)%mod;
}

LL solve(LL n,LL a,LL b)
{
    LL ans=BIGMOD(2,n)-1;
    ans-=nCr(n,a);
    ans-=nCr(n,b);
    while(ans<0)ans+=mod;
    return ans;
}

int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        LL n,a,b;
        lsc(n)lsc(a)lsc(b)
        cout << solve(n,a,b);
    }
}
//printf("Case %d: ",++QQ);


Measured memory_bytes: 256
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

bool solve( LL a, LL b, LL c, LL d ) {
    if ( a<b ) return 0;
    if ( d<b ) return 0;
    if ( c>=b-1 ) return 1;
    LL g=__gcd(b,d);
    LL l=c+1;
    a%=b;
    a+=(l-a)/g*g;
    while ( a<l ) a+=g;
    return a>=b;
}

void main() {
    int t;
    R(t);
    while ( t-- ) {
        LL a,b,c,d;
        R(a,b,c,d);
        bool ans=solve(a,b,c,d);
        W(ans?"Yes":"No");
    }
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


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

int main() {
    string s; cin >> s;
    int N = s.size(), K; cin >> K;
    long long ans = 0;
    int c = 1, cc = 0, a = 0, b = 0;
    for(int i=1; i<N; i++) {
        if(s[i] == s[i-1]) {
            ++c;
        }
        else {
            ++cc;
            if(cc == 1) {
                ans += c / 2;
                a = c;
            }
            else ans += 1LL * K * (c / 2);
            c = 1;
        }
        if(i+1 == N) {
            ans += c / 2;
            b = c;
        }
    }
    if(b == N || N == 1) return !printf("%lld", 1LL*K*N/2);
    if(s[0] == s[N-1]) ans += 1LL * (K-1) * ((a+b) / 2);
    else ans += 1LL * (K-1) * (a/2 + b/2);
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
using namespace std;
int  sum;
int a[200];
int main()
{
    IO;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i%2==1&&a[i]%2==1)
        {
            sum++;
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int sz[101];

int main() {
    int n,k;
    cin>>n>>k;
    while(k--) {
        int d,t;
        cin>>d;
        for(int i=0;i<d;i++) {
            cin>>t;
            sz[t]++;
        }
    }
    int s = 0;
    for(int i=1;i<=n;i++) {
        if(!sz[i]) {
            s++;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3552
n = int(input())
v = list(map(int,input().split()))
v.sort(reverse=True)
if n == 2:
    print((v[0]+v[1])/2)
else:
    for i in range(n-1):
        p = (v[-1] + v[-2])/2
        v.pop(-1)
        v.pop(-1)
        v.append(p)
        v.sort(reverse=True)
    print(v[0])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll H;
ll W;

ll v(ll i, ll j) {
	return (i - 1)*W + j;
}

int main() {

	cin >> H >> W;

	vector<vector<char>> c(H + 1, vector<char>(W + 1, '.'));

	repn(i, H)repn(j, W) cin >> c[i][j];

	ll N = H * W;

	vector<vector<ll>> g(N + 1);

	repn(i, H)repn(j, W) {
		if (i < H) {
			g[v(i, j)].push_back(v(i + 1, j));
			g[v(i + 1, j)].push_back(v(i, j));
		}

		if (j < W) {
			g[v(i, j)].push_back(v(i, j + 1));
			g[v(i, j + 1)].push_back(v(i, j));
		}
	}

	vector<ll> a(N + 1,0);

	queue<ll> q;
	vector<ll> dis(N + 1, -1);

	repn(i, H)repn(j, W) {
		if (c[i][j] == '#') {
			a[v(i, j)] = 1;
			dis[v(i, j)] = 0;
			q.push(v(i, j));
		}
	}

	while (!q.empty()) {
		ll v = q.front();
		q.pop();

		for (ll w : g[v]) {
			if (dis[w] > -1) { continue; }
			q.push(w);
			dis[w] = dis[v] + 1;
		}
	}

	ll ans = 0;
	repn(i, N) {
		ans = max(ans, dis[i]);
	}

	cout << ans;

	
	
	system("PAUSE");
}


Measured memory_bytes: 95632
for x in range(300):
    a, b = map(int, input().split())
    if a==0 and b==0 : break
    
    
    for i in range(a):
        for k in range (b):
            if (i+k)%2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
    



Measured memory_bytes: 7004
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << setprecision(7) << (x) << endl;

long double pi = 3.14159265359;
long long int ans;
int n;
long long int a[200000];
int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    sort(a,a+n,greater<int>());
    int cnt=1;
    ans = a[0];
    int x = 1;
    long long int y = 10000000;
    int i=1;    
    while(cnt<n){
            if(cnt == n-1) break;
            else if(cnt == n-2){
                ans += a[i];
                break;
            }
            else{
                ans += a[i]*2;
                i++;
                cnt += 2;
            }
        }
    cout << ans << endl;



return 0;
}

Measured memory_bytes: 5152
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template <class T>
class CuSum {
private:
	vector<T> cusum;
	int len = 0;
public:
	// Constructors 
	CuSum(vector<T> const &vec) : len(vec.size()), cusum(vec.size() + 1) {
		for (int i = 0; i < len; i++) cusum[i + 1] = cusum[i] + vec[i];
	}
	CuSum(int N) : len(N), cusum(N + 1) {}
	void add(int i, T x) { cusum[i + 1] += x; }
	void init() { for (int i = 0; i < len; i++) cusum[i + 1] += cusum[i]; }

	// partial sum of 0-indexed [l, r] 
	T operator()(int l, int r) {
		if (r < l || r < 0) {
			assert(0);
			return T(0);
		}
		else return cusum[r + 1] - cusum[l];
	}
	// 0-indexed
	T operator[](int i) { return cusum[i + 1]; }
	auto begin() { return cusum.begin(); }
	auto end() { return cusum.end(); }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, C;
	cin >> N >> C;

	vector<int> s(N), t(N), c(N);
	for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> c[i];

	vector<vector<int>> memo(30, vector<int>(100000));

	for (int i = 0; i < N; i++) {
		for (int j = s[i]; j <= t[i]; j++) {
			memo[c[i] - 1][j - 1] = 1;
		}
	}

	int ans = 0;
	for (int j = 0; j < 100000; j++) {
		int tmp = 0;
		for (int i = 0; i < 30; i++) {
			tmp += memo[i][j];
		}
		ans = max(ans, tmp);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 13568
import java.util.Scanner;
import java.math.BigDecimal;
 
class Main{
    public static void main(String[] args){
        Scanner scanline = new Scanner (System.in);
        while(scanline.hasNext()){
            String lines = scanline.nextLine();
            Scanner scan = new Scanner(lines);
            double a = scan.nextDouble();
            double b = scan.nextDouble();
            double c = scan.nextDouble();
            double d = scan.nextDouble();
            double e = scan.nextDouble();
            double f = scan.nextDouble();
            double ansx = (c*e-b*f)/(a*e-b*d);
            double ansy = (a*f-c*d)/(a*e-b*d);
            BigDecimal xx = new BigDecimal(String.valueOf(ansx));
            BigDecimal yy = new BigDecimal(String.valueOf(ansy));
            double x = xx.setScale(4,BigDecimal.ROUND_DOWN).doubleValue();
            double y = yy.setScale(4,BigDecimal.ROUND_DOWN).doubleValue();
            if (x == -0.000){
                x = 0.000;
            }
            if (y == -0.000){
                y = 0.000;
            }
            System.out.printf("%.3f %.3f\n",x,y);
        }
    }   
}

Measured memory_bytes: 26752
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define INF 1000000000;
#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);
/*比較函数の実装
int -32768 to 32767 (2**15-1)
long -2147483648 to 2147483648 (2**31-1)
*/
int intcmp(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}
//qsort(a,sizeof(a)/sizeof(int),sizeof(int),intcmp);
int longcmp(const void *a,const void *b){
  return *(long *)a - *(long *)b;
}
//qsort(a,sizeof(a)/sizeof(long),sizeof(long),longcmp);
int doublecmp(const void *a, const void *b){
  return *(double *)a - *(double *)b;
}
//qsort(a,sizeof(a)/sizeof(double),sizeof(double),doublecmp);
int main(void)
{
  int n;
  scanf("%d",&n);
  if(111*(n/100)>=n) printf("%d",111*(n/100));
  else printf("%d",111*(n/100+1));
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128