akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int L[2001][2001], R[2001][2001], U[2001][2001], D[2001][2001];

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  rep(i, h){
    rep(j, w){
      if(s[i][j] == '#') L[i][j] = 0;
      else{
        if(j==0) L[i][j] = 1;
        else L[i][j] = L[i][j-1] + 1;
      }
    }
  }
  rep(i, h){
    for(int j = w-1; j >= 0; --j){
      if(s[i][j] == '#') R[i][j] = 0;
      else{
        if(j==w-1) R[i][j] = 1;
        else R[i][j] = R[i][j+1] + 1;
      }
    }
  }
  rep(j, w){
    rep(i, h){
      if(s[i][j] == '#') U[i][j] = 0;
      else{
        if(i==0) U[i][j] = 1;
        else U[i][j] = U[i-1][j] + 1;
      }
    }
  }
  rep(j, w){
    for(int i = h-1; i >= 0; --i){
      if(s[i][j] == '#') D[i][j] = 0;
      else{
        if(i==h-1) D[i][j] = 1;
        else D[i][j] = D[i+1][j] + 1;
      }
    }
  }

  int ans = 0;
  rep(i, h){
    rep(j, w){
      ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
    }
  }

  out(ans);
  return 0;
}


Measured memory_bytes: 67072
import java.util.Scanner;

public class Main {

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

		int x1 = scan.nextInt();
		int y1 = scan.nextInt();
		int x2 = scan.nextInt();
		int y2 = scan.nextInt();

		int x3 = x2 - (y2 - y1);
		int y3 = y2 + (x2 - x1);
		int x4 = x3 - (y3 - y2);
		int y4 = y3 + (x3 - x2);
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}

}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int s(int x) { return x * x; }
int v(int x, int y, int z) {
  return s(x) + s(y) + s(z) + x * y + y * z + z * x;
}

int main() {
  in(int, n);
  for (int i = 1; i <= n; ++i) {
    int ans = 0;
    for (int x = 1; v(x, 1, 1) <= i; ++x) {
      for (int y = 1; v(x, y, 1) <= i; ++y) {
        for (int z = 1; v(x, y, z) <= i; ++z) {
          if (v(x, y, z) == i) ++ans;
        }
      }
    }
    out(ans);
  }
}


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

class node {
   public:
	int k;
	int parents_node;
	int parents_color;
};
stack<class node> st;

void paint_node(int k, int parents_node, int parents_color,
                vector<vector<pair<int, int>>> *edge, vector<int> *c) {
	// std::cout << k << "\n";
	st.pop();
	int color = 0;
	for (auto a : (*edge)[k]) {
		// cout << "for " << k + 1 << ": " << a.first + 1 << " ";
		if (a.first == parents_node) {
			// cout << "is parent\n";
			continue;
		}
		if (color == parents_color) {
			color++;
		}
		(*c)[a.second] = color;
		// cout << "connect color is " << color + 1 << "\n";
		// cout << "c[" << a.second + 1 << "] is " << color + 1 << "\n";

		// paint_node(a.first, k, color, edge, c);

		class node next_node;
		next_node.k = a.first;
		next_node.parents_node = k;
		next_node.parents_color = color;
		st.push(next_node);
		color++;
	}
	return;
}

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

	int N;
	scanf("%d", &N);

	vector<vector<pair<int, int>>> edge(N, vector<pair<int, int>>());
	vector<int> a(N), b(N), c(N, -1);
	for (int i = 0; i < N - 1; i++) {
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		// cout << a[i] + 1 << " " << b[i] + 1 << "\n";
		edge[a[i]].insert(edge[a[i]].end(), make_pair(b[i], i));
		edge[b[i]].insert(edge[b[i]].end(), make_pair(a[i], i));
	}

	int max_node = 0;
	int max_edge = 0;
	for (int i = 0; i < N; i++) {
		if (edge[i].size() > max_edge) {
			max_edge = edge[i].size();
			max_node = i;
		}
	}
	// cout << max_node + 1 << ": " << max_edge << "\n";

	// for (auto a : edge[max_node]) {
	// cout << a.first << "\n";
	// }
	// paint_node(max_node, -1, -1, edge, &c);

	class node root_node;
	root_node.k = max_node;
	root_node.parents_node = -1;
	root_node.parents_color = -1;

	st.push(root_node);
	while (st.size() > 0) {
		paint_node(st.top().k, st.top().parents_node, st.top().parents_color,
		           &edge, &c);
	}

	std::cout << max_edge << "\n";
	for (int i = 0; i < N - 1; i++) {
		std::cout << c[i] + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 7680
a,b = map(int, input().split())
v = round(a*12.5+0.1)
w = round(a*12.5+11.6)
x = int(b*10)
y = int(b*10+9)
if(max(v,x) <= min(w,y)):
    print(max(v,x))
else:
    print(-1)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = "";
		try {
			while(true) {
				String s2 = sc.nextLine();
				s += s2;
			}
		}catch(Exception e){}
		char[] chars = s.toCharArray();
		int[] alphabets = new int[26];
		for(char c : chars){
			int unicode = ((int) c);
			if(unicode < 6 * 16){
				unicode += 2 * 16;
			}
			if(96 < unicode && unicode <= 96 + 26){
				alphabets[unicode - 97]++;
			}
		}
		for(int i = 0; i < 26; i++){
			System.out.println((char)(i + 97) + " : " + alphabets[i]);
		}
	}
}



Measured memory_bytes: 26140
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cassert>
#include<climits>
#include<map>
#include<set>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_V 1010000
 
using namespace std;
 
typedef pair<int,int> ii;
 
//RMQ
 
int rn;
ii dat[2*MAX_V-1];
void init(int n_){
  rn = 1;
  while(rn<n_)rn*=2;
  for(int i=0;i<2*rn-1;i++)dat[i] = ii(IINF,IINF);//ii(depth,index)
}
  
// k????????????(0-indexed)???a????????´
void update(int k,ii a){
  k += rn-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = (dat[k*2+1].first>dat[k*2+2].first?dat[k*2+2]:dat[k*2+1]);
  }
}
 
ii _query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return ii(IINF,-1);
  else if(a<=l && r<=b)return dat[k];
   
  ii vl = _query(a,b,k*2+1,l,(l+r)/2);
  ii vr = _query(a,b,k*2+2,(l+r)/2,r);
   
  return min(vl,vr);
}
 
//n???????????§?????????????????????????\?????????£???????????¨ 
ii query(int a,int b){
  return _query(a,b,0,0,rn);
}
 
//
 
int V;
vector<int> G[MAX_V];
int root;
 
int vs[MAX_V*2-1];
int depth[MAX_V*2-1];
int id[MAX_V];
 
void dfs(int v,int p,int d,int &k){
  id[v] = k;
  vs[k] = v;
  depth[k++] = d;
  for(int i=0;i<G[v].size();i++){
    if(G[v][i] != p){
      dfs(G[v][i],v,d+1,k);
      vs[k] = v;
      depth[k++] = d;
    }
  }
}
 
void RQMinit(){
  int k = 0;
  dfs(root,-1,0,k);
   
  init(k+1);  
  rep(i,k)update(i,ii(depth[i],vs[i]));
}
 
int lca(int u,int v){
  return query(min(id[u],id[v]),max(id[u],id[v])+1).second;
}
 
 
int main(){
  int n;
  cin >> n;
  V = n;
  rep(i,V){
    int k,c;
    cin >> k;
    rep(j,k){
      cin >> c;
      G[i].push_back(c);
      G[c].push_back(i);
    }
  }
 
  RQMinit();
  int q,u,v;
  cin >> q;
  rep(i,q){
    cin >> u >> v;
    cout << lca(u,v) << endl;
  }
 
  return 0;
}

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

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1,0);
    for(int i=1 ;i<=n;i++){
        cin>>v[i];
    }
    if(n==2){
        cout<<abs(v[2]-v[1])<<"\n";
        return 0;
    } 
    vector<int> dp(n+1,INT_MAX);
    dp[1]=0;
    dp[0]=0;
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++){
        for(int j=min(i-1,k);j>=1;j--){
                dp[i]=min(dp[i],abs(v[i]-v[i-j])+dp[i-j]);
        }
    }
    cout<<dp[n]<<"\n";
	return 0;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define N1 16
#define INF (1e9);
using namespace std;
int main(){
  int N,data[N1][N1+1],dp[1<<N1],mintime;
  while(1){
    cin >> N;
    if(N==0) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N+1;j++)
	cin >> data[i][j];
    for(int i=0;i<(1<<N);i++) dp[i]=INF;
    dp[0]=0;
    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<N;j++){
	if((i>>j&1)==0){
	  mintime=data[j][0];
	  for(int k=0;k<N;k++)
	    if((i>>k&1)==1)
	      mintime=min(mintime,data[j][k+1]);
	  dp[(i|1<<j)]=min(dp[(i|(1<<j))],dp[i]+mintime);
	}
      }
    }
    cout << dp[(1<<N)-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1416
# 20191127
# 2*(2**5000兆)>Kなので左から1以外の文字を探せばよい

def solve():
    S = input()
    K = int(input())
    ret = 1
    for i in range(K):
        if S[i] != '1':
            ret = S[i]
            break
            
    print(ret)
    
solve()

Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    ull N, A, B; cin >> N >> A >> B;
    if(!A){
        cout << 0 << endl;
        return 0;
    }
    if(!B){
        cout << N << endl;
        return 0;
    }
    cout << N/(A+B) * A + min(N%(A+B), A) << endl;
    return 0;
}


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

int main() {
    int n, k, c;
    while (scanf("%d %d %d", &n, &k, &c) == 3) {
        string s;
        cin >> s;

        vector<int> ls;
        for (int i = 0; i < n && ls.size() < k; i++) {
            if (s[i] == 'o' && 
                (ls.empty() || i - ls.back() > c)) ls.push_back(i);
        }

        
        vector<int> res;
        int r = n - 1;
        for (int i = 0; i < k; i++) {
            while (r >= 0 && s[r] != 'o') r--;
            if (ls.back() == r) res.push_back(r);
            r -= c + 1;
            ls.pop_back();
        }
        
        reverse(res.begin(), res.end());
        for (auto &x : res) printf("%d\n", x + 1);
        printf("\n");
    }
}


Measured memory_bytes: 3448
def main():
    N = int(input())
    array = [int(input()) for _ in range(N)]
    array.sort()

    div, mod = divmod(N, 2)
    if mod == 0:
        fore, last_in_fore, first_in_rear, rear = array[:div-1], array[div-1], array[div], array[div+1:]
        a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
        print(a)
        return
    else:
        #mode1 (mfrfm):(1,-2,2,-2,1)
        fore1, mid1, rear1 = array[:div], array[div:div+2], array[div+2:]
        a1 = -2 * sum(fore1) + sum(mid1) + 2 * sum(rear1)
        #mode2 (mrfrm):(1,2,-2,2,1)
        fore2, mid2, rear2 = array[:div-1], array[div-1:div+1], array[div+1:]
        a2 = -2 * sum(fore2) - sum(mid2) + 2 * sum(rear2)

        print(max(a1, a2))
        return
    return


main()

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

template <typename T> T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T> T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

void solve() {
    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var m1 = vals[0];
        var d1 = vals[1];
        vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var m2 = vals[0];
        var d2 = vals[1];

        if (m1 + 1 == m2 && d2 == 1)
        {
            Console.WriteLine(1);
        }
        else
        {
            Console.WriteLine(0);
        }
    }
}

Measured memory_bytes: 13268
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	ans := []int{}
	S := make([]int, N)
	for i := N; i >= 1; i-- {
		if S[i-1]%2 != A[i-1] {
			ans = append(ans, i)
		} else {
			continue
		}
		for j := 1; j*j <= i; j++ {
			if i%j == 0 {
				S[j-1]++
				if j*j != i {
					S[i/j-1]++
				}
			}
		}
	}

	fmt.Fprintln(wtr, len(ans))
	if len(ans) == 0 {
		return
	}
	first := true
	for _, num := range ans {
		if !first {
			fmt.Fprint(wtr, " ")
		} else {
			first = false
		}
		fmt.Fprint(wtr, num)
	}
	fmt.Fprintln(wtr)
	//fmt.Fprintln(wtr, S)
}


Measured memory_bytes: 9344
#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 rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    string t;
    cin >> t;
    int ans = 0;
    rep(i,3) if(s[i] == t[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
   
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
} 
const int N = 1e6 + 200;
int main ()
{
    data();
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
    {
    	cin >> a[i];
    }
    sort(a + 1 , a + n + 1);
    int ans = 0;
    for (int i = 1; i <= k; i++)
    {
    	ans += a[i];
    }
    cout << ans;         
}

Measured memory_bytes: 3640
from collections import deque
N = int(input())
A = [int(a)-1 for a in input().split()]
M = N + 2
X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]
Y = [min(x, 0) + 1 for x in X]

def calc(i0):
    h = X[i0]
    if h < 0: return
    Q = deque([(i0, h)])
    X[i0] -= 1
    Y[i0] = 0
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))
ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    calc(aa)
print(ans)

Measured memory_bytes: 171704
n,m,r = map(int,input().split())
v = list(map(int,input().split()))
for i in range(r):
    v[i] -= 1
INF = float("inf")
g = [[INF]*n for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c
for i in range(n): g[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k]+g[k][j])


dp = [[INF]*r for i in range(2**r)]
for i in range(r):
    dp[2**i][i] = 0


for i in range(1,2**r):
    for j in range(r):
        if dp[i][j] == INF:
            continue
        for k in range(r):
            nxt = i | 2**k
            dp[nxt][k] = min(dp[nxt][k],dp[i][j]+g[v[j]][v[k]])

print(min(dp[-1]))


Measured memory_bytes: 71356
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[101];
bool win[100010];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n;j++)
			if(a[j]<=i)
				if(!win[i-a[j]])
					win[i]=true;
	if(win[k])
		cout<<"First";
	else cout<<"Second"; 
	return 0;
}


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

long long x[55],y[55],a[55],b[55];
int n, m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld",&x[i],&y[i]);
	}
	for(int i=0;i<m;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
	}
	for (int i=0;i<n;i++)
	{
		int ans = 0;	
		long long mmin = 0x3f3f3f3f;
		for (int j=0;j<m;j++)
		{
			long long sum=abs(x[i]-a[j])+abs(y[i]-b[j]);
			if (sum<mmin)
			{
				mmin=sum;
				ans=j;  
			}
		}
		printf("%d\n",ans+1);
	}
}

Measured memory_bytes: 256
from collections import Counter
import sys
N = int(input())
D = [int(i) for i in input().split()]
if D[0] != 0:
    print(0)
    sys.exit()
D.sort()
if D[1] == 0:
    print(0)
    sys.exit()
a = Counter(D)
a = dict(sorted(a.items(), key=lambda x:x[0]))
ans = 1
mod = 998244353
backnumber = 1
for i, (x, y) in enumerate(a.items()):
    if i != x:
        print(0)
        sys.exit()
    if i != 0:
        ans *= backnumber**y
        ans = ans % mod
    backnumber = y
print(ans)

Measured memory_bytes: 33116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String string;
		
		int n, x, y, hoge;
		char flag;
		while(true){
			n = Integer.valueOf(reader.readLine());
			if(n == 0) break;
			
			boolean map[][] = new boolean[21][21];
			for(int i = 0; i < n; i++){
				string = reader.readLine();
				x = Integer.valueOf(string.split(" ")[0]);
				y = 20 - Integer.valueOf(string.split(" ")[1]);
				
				map[y][x] = true;
			}
			
			n = Integer.valueOf(reader.readLine());
			x = y = 10;
			for(int i = 0;  i < n; i++){
				string = reader.readLine();
				flag = string.charAt(0);
				hoge = Integer.valueOf(string.split(" ")[1]);
				
				switch(flag){
				case 'N' : 
					for(int j = 0; j < hoge; j++){
						--y;
						if(map[y][x]) map[y][x] = false;
					}
					break;
				case 'E' : 
					for(int j = 0; j < hoge; j++){
						++x;
						if(map[y][x]) map[y][x] = false;
					}
					break;
				case 'S' : 
					for(int j = 0; j < hoge; j++){
						++y;
						if(map[y][x]) map[y][x] = false;
					}
					break;
				case 'W' :
					for(int j = 0; j < hoge; j++){
						--x;
						if(map[y][x]) map[y][x] = false;
					}
				}
			}
			if(app.judge(map)){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
		reader.close();
	}
	
	public boolean judge(boolean map[][]){
		boolean res = true;
		for(int i = 0; i < map.length; i++){
			for(int j = 0; j < map[i].length; j++){
				if(map[i][j]){
					res = false;
				}
			}
			if(!res) break;
		}
		return res;
	}
}

Measured memory_bytes: 30572
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

int a,b,h;

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



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int bit[11234567], bit_n;

int bit_sum(int i)
{
    int s = 0;
    while (i > 0)
    {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void bit_add(int i, int x)
{
    while (i <= bit_n)
    {
        bit[i] += x;
        i += i & -i;
    }
}

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

    int n, p[112345], q[112345];

    cin >> n;
    REP(i, n)
    {
        cin >> p[i];
        q[p[i]] = i;
    }

    multiset<int> s;

    ll res = 0;

    s.insert({-1, -1, q[n], n, n});

    for (int i = n - 1; i > 0; i--)
    {
        int pos = q[i];

        int l2 = *----s.lower_bound(pos);
        int l1 = *--s.lower_bound(pos);
        int r1 = *s.lower_bound(pos);
        int r2 = *++s.lower_bound(pos);

        res += (ll)(pos - l1) * (r2 - r1) * i;
        res += (ll)(r1 - pos) * (l1 - l2) * i;

        s.insert(pos);
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long h,w,K;
	cin>>h>>w>>K;
	vector<vector<char>> grid(h,vector<char>(w));

	for(long long i=0;i<h;i++){
		for(long long j=0;j<w;j++){
			cin>>grid.at(i).at(j);
		}
	}

	long long ans=0;

	for(long long i=0;i<(1<<h);i++){
		for(long long j=0;j<(1<<w);j++){
			bitset<6> tate=i,yoko=j;
			long long pre=0;

			for(long long k=0;k<h;k++){
				for(long long l=0;l<w;l++){
					if(grid.at(k).at(l)=='#' && (tate.test(k)==false && yoko.test(l)==false)) pre++;
				}
			}

			if(pre==K) ans++;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');
            int N = int.Parse(lines[0]);
            int K = int.Parse(lines[1]);

            lines = Console.ReadLine().Split(' ');
            var p = new List<int>();

            for (int i = 0; i < N; i++)
            {
                p.Add(int.Parse(lines[i]));
            }

            p.Sort();

            int ans = 0;
            for (int i = 0; i < K; i++)
            {
                ans += p[i];
            
            }

            Console.WriteLine(ans);


        }
    }
}


Measured memory_bytes: 28048
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

std::vector<long long> ans;
void dfs(long long now, int len = 1){
  if(len > 10)return;
  ans.push_back(now);
  int l = now % 10;
  long long temp;
  if(l - 1 >= 0){
    temp = now * 10 + (l - 1);
    dfs(temp, len + 1);
  }
  temp = now * 10 + l;
  dfs(temp, len + 1);
  if(l + 1 < 10){
    temp = now * 10 + (l + 1);
    dfs(temp, len + 1);
  }
  return;
}

int main(){
  using namespace std;
  int k;
  cin>>k;
  REPP(s, 9){
    dfs(s);
  }
  sort(ALL(ans));
  k--;
  cout<<ans[k]<<endl;
  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a;
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	ll ans=0;
	sort(a.begin(),a.end());
	for(ll i=n-1;i>=0;i--){
		for(ll j=i-1;j>=0;j--){
			ll now=a[i]-a[j]+1;
			auto itr=lower_bound(a.begin(),a.end(),now);
			ll k=itr-a.begin();
			if(k<j){
				ans+=j-k;
				//cout << i<<j<<k<<*itr<<endl;
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,i,count=0;
    cin>>a>>b>>c;
    for(i=1; ; i++)
    {
        if(i*c>=a)
        {
            count++;
            if(i*c>b)
                break;
        }
    }
    cout<<count-1;
    return 0;
}


Measured memory_bytes: 3568
x=[]#入力画面の二文字を別々の文字に格納
x=input().split(" ")
a1=int(x[0])
b1=int(x[1])
y=[]#入力画面の二文字を別々の文字に格納
y=input().split(" ")
a2=int(y[0])
b2=int(y[1])
z=[]#入力画面の二文字を別々の文字に格納
z=input().split(" ")
a3=int(z[0])
b3=int(z[1])
X=[]
X.append(a1)
X.append(a2)
X.append(a3)
X.append(b1)
X.append(b2)
X.append(b3)
import collections
c=len(collections.Counter(X)) #リスト内の要素の種類数cを調べる
x1=X.count(1)
x2=X.count(2)
x3=X.count(3)
x4=X.count(4)
Z=x1*x2*x3*x4
if Z==4 :
    print("YES")
else :
    print("NO")


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DSIZE 1024*1024*64

int dp[DSIZE];
int dp_val[200001];
string s;
int s_acm[200001];

int main(){
  cin >> s;
  
  REP(i,DSIZE){
    dp[i]=500000;
  }
  dp[0]=0;
  
  s_acm[0]=0;
  REP(i,s.size())
    s_acm[i+1]=s_acm[i] ^ (1<<(int)(s[i]-'a'));

  dp_val[0]=0;
  REP(i,s.size()){
    dp_val[i+1] = dp[s_acm[i+1]]+1;
    REP(j,26)
      dp_val[i+1] = min(dp_val[i+1],dp[s_acm[i+1]^(1<<j)]+1);
    dp[s_acm[i+1]] = min(dp[s_acm[i+1]],dp_val[i+1]);
  }
  cout << dp_val[s.size()] << endl;
  return 0;
}


Measured memory_bytes: 264324
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
res=[float('INF') for _ in range(n+1)]
res[0]=0
res[1]=0
res[2]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(k+1):
        if i+1-j<1:
            break
        res[i+1]=min(res[i+1],res[i+1-j]+abs(a[i]-a[i-j]))
print(res[n])

Measured memory_bytes: 56924
import static java.lang.System.out;
import static java.lang.Long.parseLong;
import java.io.File;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().printGCDLCM();
    }

    public void printGCDLCM() {
        try (Scanner scan = new Scanner(System.in)) {
            gcdLCM(scan);
        } catch (Exception e) {
            System.exit(0);
        }
    }

    public void printGCDLCM(String inputDataPath) {
        try (Scanner scan = new Scanner(new File(inputDataPath))) {
            gcdLCM(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gcdLCM(Scanner scan) {
        String inputData;
        while ((inputData = scan.nextLine()) != null && !"".equals(inputData)) {
            long[] data = getData(inputData);
            out.println(gcd(data) + " " + lcm(data));
        }
    }

    private long[] getData(String inputData) {
        String[] dataSplit = inputData.split(" ");
        long[] data = { parseLong(dataSplit[0]), parseLong(dataSplit[1]) };
        return data;
    }

    private long lcm(long[] data) {
        return (data[0] * data[1]) / gcd(data);
    }

    private long gcd(long[] data) {
        long[] tmpData = changeAB(data).clone();
        long mod = -1;
        while ((mod = tmpData[0] % tmpData[1]) != 0) {
            tmpData[0] = tmpData[1];
            tmpData[1] = mod;
        }
        return tmpData[1];
    }

    private long[] changeAB(long[] data) {
        if (data[0] < data[1]) {
            long tmp = data[0];
            data[0] = data[1];
            data[1] = tmp;
        }
        return data;
    }
}

Measured memory_bytes: 26036
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    int k, x;
    scanf("%d %d", &k, &x);

    int left = x - k +1;
    if (left < -1000000) {
        left = -1000000;
    }

    int right = x + k -1;
    if(right > 1000000) {
        right = 1000000;
    }

    for (int i = left; i<= right; i++) {
        printf("%d ", i);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var s = consoleReader.String();
            return Enumerable.Range(0, s.Length - 2).Select(i => int.Parse(s.Substring(i, 3))).Select(i => Math.Abs(753 - i)).Min();
        }


        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); }
        public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); }
        public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); }
        public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); }
        public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); }
    }
}


Measured memory_bytes: 11348
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn main() {
    let s = read_vec_char();
    let t = read_vec_char();
    let n = s.len();
    for i in 0..n {
        let mut f = true;
        for j in 0..n {
            if s[j] != t[(i + j) % n] {
                f = false;
                break;
            }
        }
        if f {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================

A=INPUT()
A.sort()

a=A[0]
b=A[1]
c=A[2]
if a==b==c:
    print("No")
elif a==b and b!=c:
    print("Yes")
elif (b==c and b!=a):
    print("Yes")
else:
    print("No")

    


Measured memory_bytes: 38256
#include <stdio.h>

int main(void)
{
	int n, i, num_i;

	scanf("%d", &n);

	int nums[n];

	for (i = 0; i < n; i++) {
		scanf("%d", &num_i);
		nums[i] = num_i;
	}

	for (i = n - 1; i > 0; i--) {
		printf("%d ", nums[i]);
	}

	printf("%d\n", nums[0]);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;
#define PI 3.14159265359

int divisor_count(int n)
{
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(n % i == 0) ans++;
    }

    return ans;
}

void common_divisor(int a, int b, int *array)
{
    int k = 0;
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            array[k] = i;
            k++;
        }
    }
}


int main()
{
    int A, B, K;
    int ans = 0;
    cin >> A >> B >> K;

    int div[10000];
    common_divisor(A, B, div);

    cout << div[K - 1] << endl;

    
    return 0;
}

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

int main() {
  ll n; cin >> n;
  vector<ll> a(n * 3); REP(i, n * 3) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  
  ll ans = 0; REP(i, n) ans += a[i * 2 + 1];
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int MAX = 2e5;
set<int> s[MAX];
int H, W;
int ans = inf;

void dfs(int x, int y, int flag){
    chmin(ans, *s[y].upper_bound(x));
    if(flag && y != W-1 && !s[y+1].count(x)) dfs(x, y+1, 0);
    elif(x != H-1 && !s[y].count(x)) dfs(x+1, y, 1);
}

int main(){
    int N;
    cin >> H >> W >> N;
    rep(i, N){
        int X, Y; cin >> X >> Y; X--, Y--;
        s[Y].insert(X);
    }
    rep(i, MAX) s[i].insert(H);
    dfs(0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 28416
#include <stdio.h>

int main(void)
{
	int n,p[100];
	int max=-1;
	int sum=0;
	
	scanf("%d",&n);
	
	int i=0;
	
	while(i<n){
		scanf("%d",&(p[i]));
		
		if(max<p[i]){
			max=p[i];
		}
		
		sum=sum+p[i];
		
		i++;
		
	}
	
	printf("%d\n",sum-max/2);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for(int i = 0; i < n - m + 1; i++) {
    for(int j = 0; j < n - m + 1; j++) {
      int num = 0;
      while(num + i < n && a[num + i].substr(j, m) == b[num]) {
        num++;
      }
      if(num == m) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

std::string N;

int Kt[4][101];

int K(int k, int n) {
    // n-k zeros
    if (k > n) return 0;
    if (k==0) return 1;
    return 9*Kt[k-1][n-1] + Kt[k][n-1];//9*K(k-1, n-1) + K(k, n-1);
}

int f(int k, int n) {
    if (k==0) return 1;
    if (n >= N.length()) return 0;
    if (N[n] == '0') return f(k, n+1);
    return (N[n]-'1')*K(k-1, N.length()-n-1) + K(k, N.length()-n-1) + f(k-1, n+1);
}

int main() {
    std::ios_base::sync_with_stdio(0);
    int k;
    std::cin >> N >> k;
    for (int kk=0;kk<=3;++kk)
        for (int n=0;n<=100;++n)
            Kt[kk][n] = K(kk,n);
    std::cout << f(k, 0);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
	public class Main {
		public static void main(String[] args){
			Scanner sc=new Scanner(System.in);
			int[] x=new int[1001];
			long all = (int)1e9+7;
			int n=sc.nextInt();
			for(int i=2;i<=n;i++){
				int j = 2;
				int t = i;
				while(t>1){
					if(t%j==0){
						x[j]++;
						t/=j;
					}
					else j++;
				}
			}
			Arrays.sort(x);
			long t = 1;
			for(int i=1000;i>=0;i--){
				t*=(x[i]+1);
				t%=all;
			}
			System.out.print(t);
		}
	}

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

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

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  string t = "CODEFESTIVAL2016";
  int count = 0;
  rep(i,s.length()){
    if(s[i] != t[i])++count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
### subroutines

def get_direc(pt0, pt1)
  dx = pt1[0] - pt0[0]
  dy = pt1[1] - pt0[1]

  return 0 if dx > 0
  return 1 if dy > 0
  return 2 if dx < 0
  return 3
end

def rot_n(pt, n)
  x, y = pt

  return [-y,  x] if n == 1
  return [-x, -y] if n == 2
  return [ y, -x] if n == 3
  [x, y]
end

def is_same?(pol0, pol1)
  return false if pol0.length != pol1.length

  d0 = get_direc(pol0[0], pol0[1])
  d1 = get_direc(pol1[0], pol1[1])
  rn = (d0 - d1 + 4) % 4

  pol2 = pol1.map{|pt| rot_n(pt, rn)}

  dx = pol0[0][0] - pol2[0][0] 
  dy = pol0[0][1] - pol2[0][1] 

  pol3 = pol2.map{|x, y| [x + dx, y + dy]}

  #p [pol0, pol3]
  pol0 == pol3
end

### main

loop do
  n = gets.to_i
  break if n == 0

  polys = []

  (n + 1).times do
    m = gets.to_i
    pol = m.times.map{gets.split.map(&:to_i)}
    polys << pol
  end

  tmpl = polys.shift
  #p tmpl
  #p polys

  for i in (0...n)
    poli = polys[i]
    if is_same?(tmpl, poli) || is_same?(tmpl, poli.reverse)
      puts (i + 1)
    end
  end
  puts '+++++'
end

Measured memory_bytes: 6124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	string S;
	cin >> S;
	if(S[0]==S[1] && S[0]!=S[2] && S[2]==S[3]){
	    cout << "Yes" << endl;
	}else if(S[0]!=S[1] && S[0]==S[2] && S[1]==S[3]){
	    cout << "Yes" << endl;
	}else if(S[0]!=S[1] && S[0]==S[3] && S[1]==S[2]){
	    cout << "Yes" << endl;
	}else{
	    cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	int minu=h*60+m;
	double hr=(double)minu*0.5;
	double mn=double(m)*6;
	double ang=max(hr,mn)-min(hr,mn);
	ang=cos(ang*PI/180.0);
	//cout<<ang<<
	double ans=2.0*a*b*ang;
	ans=a*a+b*b-ans;
	ans=sqrt(ans);
	cout<<fixed<<setprecision(20)<<ans<<endl;
}



Measured memory_bytes: 4260
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define endl "\n"
#define int long long
#define test int t; cin>>t; while(t--)
#define debug(x) cout<<#x<<" "<<(x)<<endl
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int N=1e5;
signed main()
{
	fastio
	//test
	{
        int s,w; cin>>s>>w;
        if(s>w)
        	cout<<"safe\n";
        else
        	cout<<"unsafe\n";
  	}
}

Measured memory_bytes: 3636
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()

    one = n % 10

    a = set([2, 4, 5, 7, 9])
    b = set([0, 1, 6, 8])
    if one in a:
        print('hon')
    elif one in b:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9720