akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    };
    if n % 1000 == 0 {
        println!("{}", 0);
    } else {
        println!("{}", 1000 - (n % 1000));
    }
}


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

int main(){
	int n;
	int l[200];
	int sum = 0;

	cin >> n;

	for (int i = 0; i < 2 * n; i++){
		cin >> l[i];
	}

	sort(l, l + n * 2);

	for (int i = 0; i < 2 * n; i += 2){
		if (l[i + 1] - l[i] > 0){
			sum += l[i];
		}
		else {
			sum += l[i + 1];
		}
	}

	cout << sum << endl;

	return (0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>

int main()
{
    int m, n;
    std::cin >> n >> m;

    std::array<int, 100> a = {0};
    for (int i = 0; i < n; ++i) std::cin >> a[i];

    std::sort(a.begin(), a.end(), std::greater<int>());

    int sum = 0;
    for (int i = 0; i < n; ++i) sum += a[i];

    std::cout << (a[m - 1] * 4 * m < sum ? "No" : "Yes") << std::endl;

    return 0;
}


Measured memory_bytes: 256
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
using namespace std;


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

    bool has_answer = false;
    for(int i = 0, len1 = 100 / 4 + 1; i < len1; i++){
        for(int j = 0, len2 = 100 / 7 + 1; j < len2; j++){
            if(N == i*4 + j*7){
                has_answer = true;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

signed main() {
  int N, K; cin >> N >> K;
  vector<vector<pair<int, int>>> G(N);
  rep(i , N) {
    int t, d; cin >> t >> d;
    t--;
    if (G[t].empty()) {
      G[t].push_back(make_pair(d, 0));
    } else {
      G[t].push_back(make_pair(d, 0));
    }
  }

  auto ps = [](const pair<int, int> & l, const pair<int, int> & r) {
              return l.first > r.first;
            };

  vector<pair<int, int>> ALL;
  rep(i, N) {
    if (!G[i].empty()) {
      sort(G[i].begin(), G[i].end(), ps);
      G[i][0].second = 1;
      rep(j, G[i].size()) {
        ALL.emplace_back(G[i][j]);
      }
    }
  }

  sort(ALL.begin(), ALL.end(), ps);
  auto pqs1 = [](const pair<int, int> &l, const pair<int, int> & r) {
               if (l.second == r.second) {
                 return l.first > r.first;
               } else {
                 return l.second > r.second;
               }
             };

  auto pqs2 = [](const pair<int, int> &l, const pair<int, int> & r) {
               if (l.second == r.second) {
                 return l.first < r.first;
               } else {
                 return l.second < r.second;
               }
             };


  priority_queue<Pi, vector<Pi>, decltype(pqs1)> Using(pqs1);
  priority_queue<Pi, vector<Pi>, decltype(pqs2)> Unused(pqs2);


  // initialize
  int cnt = 0;
  int X = 0;
  int Y = 0;
  for (auto &p: ALL) {
    if (cnt < K) {
      X += p.first;
      Y += p.second;
      Using.push(p);
      cnt++;
    } else {
      Unused.push(p);
    }
  }

  int ans = X + Y*Y;

  while (!Unused.empty() && Unused.top().second == 1 && Using.top().second == 0) {
    Pi p1 = Unused.top(); Unused.pop();
    Pi p2 = Using.top(); Using.pop();
    X += p1.first - p2.first;
    Y += 1;
    ans = max(ans, X + Y*Y);
  }

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


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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


int main(void) {
    int n, m ,bx, by;
    cin >> n >> m >> bx >> by;

    vector<int> x(n);
    vector<int> y(m);
    for(int in=0;in<n;in++) {
        cin >> x.at(in);
    }
    for(int im=0;im<m;im++) {
        cin >> y.at(im);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int xmax = x.at(n-1), bz = y.at(0);

    if(bx<bz&&bz<=by&&xmax<bz) cout << "No War" << endl;
    else cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	S := next()

	if S == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1756
def answer(H,W,ans):

    for x in range(1,W):
        y1 = H // 2
        Sa1 = H * x
        Sb1 = (W - x) * y1
        Sc1 = (W - x) * (H - y1)
        M = max(Sa1,Sb1,Sc1)
        m = min(Sa1,Sb1,Sc1)

        y2 = (W - x) // 2
        Sa2 = H * x
        Sb2 = H * y2
        Sc2 = H * (W - x - y2)
        M2 = max(Sa2,Sb2,Sc2)
        m2 = min(Sa2,Sb2,Sc2)

        if ans > min(M-m,M2-m2):
            ans = min(M-m,M2-m2)

    return ans

if __name__ == '__main__':
    H,W = [int(i) for i in input().split()]
    ans = H * W
    ans = answer(H,W,ans)

    H,W = W,H

    if answer(H,W,ans) < ans:
        ans = answer(H,W,ans)

    print(ans)


Measured memory_bytes: 9100
function Main(input) {
  input = input.split("\n");
  var a = input[0].split('');
  var x = 0
  for(var i=0; i<a.length; i++) {
    x+=parseInt(a[i])
  }
  var ans = parseInt(input[0])%x === 0? "Yes" : "No"
  console.log(ans);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>
#include <stdlib.h>
int ordena( const void * a, const void * b){
  return (*(int *)a)-(*(int* )b);
}
int main (){
  int n,k, total=0;
  int prices[1001];

  scanf("%d%d", &n,&k);
  for (int i = 0; i < n; i++)
    scanf("%d", &prices[i] );

  qsort(prices,n,sizeof(int), ordena);

  for (int i = 0; i < k; i++)
    total+=prices[i];

  printf("%d",total);

  return 0;
}


Measured memory_bytes: 1732
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let n = input!(i64);
    let a_list = input!(i64; n);
    let mut cnt = 0;
    for a in a_list {
        let mut i = 1;
        loop {
            if a % 2i64.pow(i) != 0 {
                cnt += i - 1;
                break
            }
            i += 1;
        }
    }
    println!("{}", cnt);
}

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

int W, H;
char board[30][30];
bool visited[30][30];

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

void dfs(int x, int y) {
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (board[nx][ny] == '#') continue;
      if (visited[nx][ny]) continue;
      visited[nx][ny] = true;
      dfs(nx, ny);
   }
}

int main() {
   while (cin >> W >> H, W || H) {
      memset(visited, false, sizeof(visited));
      int sx = 0, sy = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            cin >> board[i][j];
            if (board[i][j] == '@') {
               sx = i, sy = j;
            }
         }
      }

      visited[sx][sy] = true;
      dfs(sx, sy);

      int cnt = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (visited[i][j]) cnt++;
         }
      }

      cout << cnt << endl;
   }

   return 0;
}


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

int main(){
    int N,K; cin >> N >> K;
    vector <int> H(N);
    rep(i,N) cin >> H[i];
    
    ll ans=0;
    sort(H.begin(),H.end());
    rep(i,N-K) ans+=H[i];
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int a,b;
	cin >> a >> b;
	if(a >= 13)
		cout << b << endl;
	else if(a >= 6)
		cout << b / 2 << endl;
	else
		cout << 0 << endl;
	
	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;
#define mod 1000000007

bool check(vector<bool> v, ll n)
{
	for (; n > 0; n /= 10)
		if (v[n % 10] )
			return false;

	return true;
}

void solve()
{
	ll n, k;
	cin >> n >> k;

	vector<bool> v(10);
	for (ll i = 0; i < k; i++)
	{
		ll index;
		cin >> index;
		v[index] = true;
	}

	while (!check(v, n))
		n++;

	cout << n;
}



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

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<tuple<int,int,int>> t(m);
    rep(i,m){
        int p,y;
        cin>>p>>y;
        t[i] = make_tuple(p,y,i);
    }
    sort(t.begin(),t.end());
    vector<tuple<int,int,int>>u(m);
    int cnt = 1;
    rep(i,m){
        if(get<0>(t[i])==get<0>(t[i-1])){
            cnt ++;
        }else{
            cnt = 1;
        }
        u[i]=make_tuple(get<2>(t[i]),get<0>(t[i]), cnt);
    }
    sort(u.begin(),u.end());
    rep(i,m){
        printf("%06d%06d\n",get<1>(u[i]),get<2>(u[i]));
    }
    return 0;
}




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

vector<vector<int>> calcCH(string A){
  int N =  A.size();
  vector<vector<int>> res(N+1, vector<int>(26,N));
  //res[i][j]で、i以降に初めて'a'+jが出る位置　ここで存在しなければNとする
  
  for(int i = N-1; i >= 0; i--){
    for(int j = 0; j < 26; j++){ 
      res[i][j] = res[i+1][j];
    }
     res[i][A[i]-'a'] = i;
  }
  
  return res;
}

int main(){
  string S; cin >> S;
  int N = (int) S.size();
  
  auto ch = calcCH(S);
  
  vector<int> dp(N+1, 1 << 29);
  
  vector<pair<char,int>> rec(N+1, {'?',N});
  
  dp[N] = 1;
  
  for(int i = N-1; i >= 0; i--){
     for(int j = 0; j < 26; j++){
      
      // 次の文字がないとき
      if( ch[i][j] == N){
        if( dp[i] > 1){
          rec[i] = {'a'+j, N};
          dp[i] = 1;
        }
      }
      
      //次の文字がある時
      else{
      if( dp[i] > dp[ch[i][j]+1]+1){
        rec[i] = {'a'+j, ch[i][j]+1};
        dp[i] = dp[ch[i][j]+1]+1;
      }
      }
     }
  }
    
    
    string ans = "";
    
    int index = 0;
    
    while( index < N){
      auto p = rec[index];
      
      ans += p.first;
      index = p.second;
    }
    
    cout << ans << endl; return 0;
  }

    
  

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

vector<pair<int, int>> g[100000];
int color[100000];
void dfs(int cur, int p) {
  for (auto e: g[cur]) {
    int to = e.first;
    int w = e.second;
    if (to == p) {
      continue;
    }
    if (w % 2 == 0) {
      color[to] = color[cur];
    } else {
      color[to] = 1 - color[cur];
    }
    dfs(to, cur);
  }
}

int main() {
  int n;
  cin>>n;
  for (int i=0; i<n-1; i++) {
    int u, v, w;
    cin>>u>>v>>w;
    --u;
    --v;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  color[0] = 0;;
  dfs(0, -1);
  for (int i=0; i<n; i++) {
    cout<<color[i]<<endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x  first
#define y  second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];

ll a[100002]={};
//ll b[100002]={};
ll n,m;

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ld n,x,tt;
        cin>>n>>x>>tt;
        cout<<fixed<<setprecision(0)<<ceil(n/x)*tt;
    }
    return 0;
}


Measured memory_bytes: 3800
import sys

N = int(input())
xyz = [list(map(int, input().split())) for _ in range(N)]

idx = 0
for i in range(N):
    if xyz[i][2] != 0:
        idx = i
        break

for cx in range(101):
    for cy in range(101):
        switch = 1
        distance = abs(xyz[idx][0] - cx) + abs(xyz[idx][1] - cy)
        H = xyz[idx][2] + distance
        
        for x,y,h in xyz:
            karidis = abs(x - cx) + abs(y - cy)
            if h == 0 and distance <= karidis:
                continue
            kari = h + karidis
            if H != kari:
                switch = 0
                break
        if switch == 1:
            print(cx, cy, H)
            sys.exit()
            

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    n += n;
    int l[n];
    for(int i=0; i<n; i++) cin >> l[i];
    sort(l, l+n);

    int sum=0;
    for(int i=0; i<n; i+=2) sum += l[i];
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

m = sum(a)//N

ans1 = 0
ans2 = 0
ans3 = 0
for k in range(N):
    ans1 += (a[k]-m)**2
    ans2 += (a[k]-m-1)**2
    ans3 += (a[k]-m+1)**2

print(min(ans1,ans2,ans3))

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        var T = scan.ArrayInt(N);
        var M = scan.NextInt();
        var sb = new StringBuilder();
        var t = new int[N];
        for (int i = 0; i < M; i++) {
            Array.Copy(T, t, N);
            int p = scan.NextInt() - 1, x = scan.NextInt();
            var sum = 0;
            t[p] = x;
            for (int j = 0; j < N; j++) {
                sum += t[j];
            }
            sb.Append(sum).AppendLine();
        }
        return sb.ToString();
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

Measured memory_bytes: 27492
function main()
  S = chomp(readline())
  n = 0
  a = 0
  for c in S
    if c == 'A' || c == 'T' || c == 'G' || c == 'C'
      n += 1
    else
      a = max(a, n)
      n = 0
    end
  end
  println(max(a, n))
end

main()

Measured memory_bytes: 129536
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, Q;
string s;

int main() {
    cin >> n >> s >> Q;
    vector< set<int> > alp(26);
    for(int i = 0; i < n; ++i) {
        alp.at(s.at(i)-'a').insert(i);
    }

    for(int i = 0; i < Q; ++i) {
        int ty; cin >> ty;
        if(ty == 1) {
            int ii; char cc;
            cin >> ii >> cc;
            ii--;
            alp.at(s.at(ii)-'a').erase(ii);
            s.at(ii) = cc;
            alp.at(s.at(ii)-'a').insert(ii);
        }else {
            int ll, rr; cin >> ll >> rr;
            ll--;
            int ans = 0;
            for(int j = 0; j < 26; ++j) {
                auto it = alp.at(j).lower_bound(ll);
                if(it != alp.at(j).end() && *it < rr) ++ans;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 24196
#include <iostream>
using namespace std;
#define AMAX 17
int a,b,n;
int r[AMAX][AMAX];
void solve(){
	for(int i=1;i<=b;i++){
		for(int j=1;j<=a;j++){
			if(r[i][j]==-1)continue;
			if(r[i-1][j]!=-1)r[i][j]+=r[i-1][j];
			if(r[i][j-1]!=-1)r[i][j]+=r[i][j-1];
		}
	}
	cout<<r[b][a]<<endl;
}
int main(){
	while(cin>>a>>b,a||b){
		for(int i=0;i<AMAX;i++)fill(r[i],r[i]+AMAX,0);
		r[1][1]=1;		
		cin>>n;
		int x,y;
		for(;n>0;--n){
			cin>>x>>y;
			r[y][x]=-1;
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
ll mp[100005]={0};
int main()
{
    ll n,sum=0,x,y;
    cin>>n;
    com(i,n)
    {
        cin>>x;
        mp[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
    com(i,q)
    {
        cin>>x>>y;
        mp[y]+=mp[x];
        sum-=(mp[x]*x);
        sum+=(mp[x]*y);
        mp[x]=0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 4376
import math as m

N = int(input())
li = [list(map(int, input().split())) for _ in range(N)]
xs,ys = list(zip(*li))

ans = 0
for i in range(N):
    for j in range(N):
        ans += m.sqrt((xs[i]-xs[j])**2 + (ys[i]-ys[j])**2)

print(ans/N)


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
  int n, m;
  int i;
  int tl[10000], tr[10000];
  int l, r;
  int max;
  int before, now;
  int temp;

  while(1) {
    scanf("%d %d", &n, &m);
    if(n == 0 && m == 0) break;
    for(i = 0; i < n; i++) {
      scanf("%d", &tl[i]);
    }
    for(i = 0; i < m; i++) {
      scanf("%d", &tr[i]);
    }
    l = r = 0;
    before = 0;
    max = -1;
    while(l < n || r < m) {
      if(l < n && r < m) {
	if(tl[l] == tr[r]) {
	  now = tl[l];
	  l++;
	  r++;
	} else if(tl[l] < tr[r]) {
	  now = tl[l];
	  l++;
	} else if(tl[l] > tr[r]) {
	  now = tr[r];
	  r++;
	}
      } else {
	if(l < n) {
	  now = tl[l];
	  l++;
	} else if(r < m) {
	  now = tr[r];
	  r++;
	}
      }

      temp = now - before;
      if(temp > max) max = temp;
      
      before = now;
    }
    printf("%d\n", max);

  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<pair<ll, ll>> AB;
  for(int i = 0; i < N; i++){
    ll a, b; cin >> a >> b;
    AB.push_back(make_pair(b, -a));
  }

  sort(AB.rbegin(), AB.rend());

 

  ll ans = 0;
  int cnt = 0;
  vector<ll> Msche(M+1, 0);
  vector<int> zeroSche(M+1);
  for(int i = 0; i < M+1; i++) zeroSche[i] = i;

  for(int i = 0; i < N; i++){
    ll b = AB[i].first;
    ll a = -AB[i].second;

    auto it = lower_bound(zeroSche.begin(), zeroSche.end(), a);
    int index = it - zeroSche.begin();
    if(index == zeroSche.size()) continue;
    Msche[zeroSche[index]] = b;
    zeroSche.erase(it);
    
  }

  for(int i = 0; i < M+1; i++) ans += Msche[i];
  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 2928
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
  int A,B,K;
  cin >> A >> B >> K;
  vector<int> ans;
  FOR(i,A,A+K){
    if(i <= B) ans.push_back(i);
  }
  FOR(i,B-K+1,B +1) {
    if(i >= A) ans.push_back(i);
  }
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()),ans.end());
  for(auto it = ans.begin();it != ans.end();++it){
    cout << *it << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    ll x;
    cin >> x;
    ll cnt = (x / 11) * 2;
    int tmp = x % 11;

    if(tmp == 0);
    else if(tmp <= 6)  cnt++;
    else cnt += 2;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 4) {
        for(; arr[1]+4 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 4) {
        for(; arr[0]+4 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      bfs(t);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        System.out.println(cur.step);
        return;
      }

      que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
      que.peekLast().step = cur.step + 1;

      que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
      que.peekLast().step = cur.step + 1;
      
    }
  }

  class Tuple3 {
    int[] e;
    int state;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      state = (a*10000) + (b*100) + c;
      step = 0;
    }

    @Override
    public boolean equals(Object obj) {
      if(obj == this) return true;
      if(obj == null) return false;
      if(!(obj instanceof Tuple3)) return false;

      Tuple3 ref = (Tuple3) obj;

      return this.state == ref.state ? true : false;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

Measured memory_bytes: 45140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (2147483647)
#define MOD (int)(1e9 + 7) 

bool isPal(string a) {
    for(int i = 0; i < ((int)a.size()/2); ++i) {
        if(a[i] != a[a.size() - 1 - i]) {
            return false;
        }
    }
    return true;
}

bool f(string s) {
    string res = "";
    int n = s.size();
    for(int i = 0; i < (n-1)/2; ++i) {
        res += s[i];
    }
    if(isPal(res)) {
        return true;
    }
    return false;
}

bool b(string s) {
    string res = "";
    int n = s.size();
    for(int i = ((n + 3) / 2)-1; i < n; ++i) {
        res += s[i];
    }
    if(isPal(res)) {
        return true;
    }
    return false;
}

bool isStrongPal(string s) {
    if(isPal(s) and f(s) and b(s)) {
        return true;
    } 
    return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    if(isStrongPal(s)) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}

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

int MOD = 10007;

int main(){
    int ans=0;
    int N,K;
    cin >> N >> K;
    int a_sub;
    vector<int> a;
    int i,j;
    a.push_back(0);
    for(i=1; i<=N; i++){
        cin >> a_sub;
        if(a_sub<K){
            a.push_back(a_sub);
        }
    }
    int M=a.size()-1;
    if(M<=0){
        cout << ans << endl;
        return 0;
    }
    int dp[2][2*K+1], dp_rev[K+1];
    dp[0][0]=1;
    for(j=1; j<=2*K; j++){
        dp[0][j]=0;
    }
    for(i=1; i<=M; i++){
        for(j=0; j<=2*K; j++){
            if(j-a[i]<0){
                dp[i%2][j]=dp[!(i%2)][j];
            }else{
                dp[i%2][j]=dp[!(i%2)][j]+dp[!(i%2)][j-a[i]];
                dp[i%2][j]%=MOD;
            }
        }
    }
    for(i=1; i<=M; i++){
        for(j=0; j<=K; j++){
            if(j-a[i]<0){
                dp_rev[j]=dp[M%2][j];
            }else{
                dp_rev[j]=dp[M%2][j]+(MOD-dp_rev[j-a[i]]);
                dp_rev[j]%=MOD;
            }
        }
        for(j=K; j<K+a[i]; j++){
            if((dp[M%2][j]>0)&&(dp_rev[j-a[i]]>0)){
                break;
            }
        }
        if(j>=K+a[i]){
            ans++;
        }
    }
    cout << ans <<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3700
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1155();
	}
	
	class AOJ1155{
		AOJ1155(){
			while(true){
				String str=sc.next();
				if(str.equals("."))	break;
				solve(str);
			}
		}
		void solve(String str){
			int cnt=0;
			str+="#";
			for(int p=0; p<=2; ++p)for(int q=0; q<=2; ++q)for(int r=0; r<=2; ++r){
				String tmp=str.replaceAll("P", ""+p).replaceAll("Q", ""+q).replaceAll("R", ""+r);
//				System.out.println(tmp);
				this.line=tmp.toCharArray();
				this.pos=0;
				int ret=expr();
//				System.out.println(ret);
				cnt += (ret==2?1:0);
			}
			System.out.println(cnt);
		}
		final int[][]	and={{0,0,0},{0,1,1},{0,1,2}},
				or={{0,1,2},{1,1,2},{2,2,2}};
		final int[] m={2,1,0};
		char[] line;
		int pos=0;
		private int expr(){
			int ret=term();
			while(true){
				char op=line[pos];
				if( op=='+' ){
					int old=ret;
					++pos;
					ret=term();
					ret=or[old][ret];
//					System.out.println(old+"+"+ret+" = "+or[old][ret]);
				}else	break;
			}
			return ret;
		}
		private int term(){
			int ret=fact();
			while(true){
				char op=line[pos];
				if( op=='*' ){
					int old=ret;
					++pos;
					ret=fact();
					ret=and[old][ret];
//					System.out.println(old+"*"+ret+" = "+and[old][ret]);
				}else	break;
			}
			return ret;
		}
		private int fact(){
			if(line[pos]=='-'){
				++pos;
				return m[fact()];
			}else if(Character.isDigit(line[pos])){
				int ret=line[pos]-'0';
				++pos;
				return ret;
			}else if(line[pos]=='('){
				++pos;
				int ret=expr();
				++pos;
				return ret;
			}
			return 0;
		}
	}
	
	class AOJ1153{
		AOJ1153(){
			while(true){
				int n=sc.nextInt(),m=sc.nextInt();
				if((n|m)==0)	break;
				solve(n,m);
			}
		}
		void solve(int n,int m){
			int[] nn=new int[n],
					mm=new int[m];
			int ns=0, ms=0;
			for(int i=0; i<n; ++i){
				nn[i]=sc.nextInt();
				ns+=nn[i];
			}
			for(int i=0; i<m; ++i){
				mm[i]=sc.nextInt();
				ms+=mm[i];
			}
			Arrays.sort(nn);
			Arrays.sort(mm);
			int cand1=-1,cand2=-1,sum=Integer.MAX_VALUE/4;
			for(int i=0; i<n; ++i){
				for(int j=0; j<m; ++j){
					if(ns-nn[i]+mm[j] == ms-mm[j]+nn[i] && sum>nn[i]+mm[j]){
						cand1=i;
						cand2=j;
						sum=nn[i]+mm[j];
					}
				}
			}
			System.out.println(cand1<0? "-1" : nn[cand1]+" "+mm[cand2]);
		}
	}
}

Measured memory_bytes: 35096
#include <iostream>
#define ll long long
using namespace std;

int main(){
    ll x, a, b;
    cin >> x >> a >> b;
    if(x < b - a) cout << "dangerous" << endl;
    else if (a >= b) cout << "delicious" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 256
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

def lcm_(x,y):
    return (x * y) // gcd_(x, y)

def lcm(l):
    ans = l[0]
    for i in l:  ans = lcm_(ans, i)
    return ans

N = cin()
a = [cin() for _ in range(N)]
print(lcm(a))

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

#define SIZE 200000

using namespace std;

int main() {
    long long int i,j,k,N,M,K,Q,X;
  //  long long int A[100][100];

 cin >> N;

 long c;
 c = N % 10;


  if (c == 3)
  cout << "bon" << endl;
  else if (( c < 2) || (c == 6) || (c==8))
  cout << "pon" << endl;
  else
  cout << "hon" << endl;


  return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
using Graph = vector<vector<ll>>;

struct UnionFind 
{
	vector<ll> d;
  UnionFind(ll n): d(n, -1) {}
  ll find(ll x) 
  {
  	if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(ll x, ll y)
  {
  	x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) {return find(x) == find(y);}
  ll size(ll x) {return -d[find(x)];}
};

ll deg[100005];
vector<ll> to[100005];

int main()
{
  ll N, M, K; cin >> N >> M >> K; 
  UnionFind uf(N);
  rep(i, 0, M) {
  	ll a, b; cin >> a >> b;
    a--; b--;
    deg[a]++; deg[b]++;
    uf.unite(a, b);
  }
  rep(i, 0, K) {
  	ll a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i, 0, N) {
  	ll ans = uf.size(i) - 1 - deg[i];
    for (ll u: to[i]) {
    	if (uf.same(i, u)) --ans;
    }
    cout << ans << " ";
  }  
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

template<class T>
void insertion_sort(vector<T>a,int n)
{
  for (int i = 1; i < n; ++i)
  {
    for (int i = 0; i < n; ++i)
    {
      if(i!=n-1) cout<<a[i]<<" ";
      else cout<<a[i]<<endl;
    }
    T v=a[i];
    int j=i-1;
    while(j>=0 && a[j]>v)
    {
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
  }
  for (int i = 0; i < n; ++i)
  {
    if(i!=n-1) cout<<a[i]<<" ";
    else cout<<a[i]<<endl;
  }
}

int main()
{
  int n;
  cin>>n;
  std::vector<int> a(n);
  for(auto&& e: a) 
  {
    cin>>e;
  }
  insertion_sort(a,n);
}


Measured memory_bytes: 3148
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Monoid
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Sequence as Seq

strictAppend :: (Monoid a, Monoid b) => (a, b) -> (a, b) -> (a, b)
strictAppend (x, y) (x', y') = let !xx = x <> x'
                                   !yy = y <> y'
                               in (xx, yy)

main = do
  [n,q] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM (n-1) $ do
    [a,b,c,d] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,c,d)
  let edges' :: V.Vector [(Int,Int,Int)]
      edges' = V.create $ do
        vec <- VM.replicate n []
        U.forM_ edges $ \(i,j,c,d) -> do
          VM.modify vec ((j,c,d) :) i
          VM.modify vec ((i,c,d) :) j
        return vec
  let routes :: V.Vector (Seq.Seq Int)
      distances :: U.Vector Int
      distancesMap :: V.Vector (IntMap.IntMap (Sum Int, Sum Int))
      (routes, distances, distancesMap) = runST $ do
        routes <- VM.new n
        distances <- UM.new n
        distancesMap <- VM.new n
        let go !i0 !i route !dt dtm = do
              VM.write routes i route
              UM.write distances i dt
              VM.write distancesMap i dtm
              forM_ (edges' V.! i) $ \(j,col,dist) -> do
                when (j /= i0) $ do
                  go i j (route Seq.|> j) (dt + dist) (IntMap.insertWith strictAppend col (Sum 1, Sum dist) dtm)
        go (-1) 0 (Seq.singleton 0) 0 IntMap.empty
        liftM3 (,,) (V.unsafeFreeze routes) (U.unsafeFreeze distances) (V.unsafeFreeze distancesMap)
      lowestCommonAncestor :: Int -> Int -> Int
      lowestCommonAncestor !i !j =
        let ri = routes V.! i
            rj = routes V.! j
            search !l !u | l + 1 == u = ri `Seq.index` l
            search !l !u = let d = (l + u) `quot` 2 -- l < d < u
                               pi = ri `Seq.index` d
                               pj = rj `Seq.index` d
                           in if pi == pj
                              then search d u
                              else search l d
        in search 0 (min (Seq.length ri) (Seq.length rj))
  forM_ [0..q-1] $ \_ -> do
    [x,y,up1,vp1] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let u = up1 - 1
        v = vp1 - 1
        w = lowestCommonAncestor u v
        modifiedDistanceFromRoot :: Int -> Int
        modifiedDistanceFromRoot !i = distances U.! i + case IntMap.lookup x (distancesMap V.! i) of
                                                          Just (Sum n, Sum origDist) -> y * n - origDist
                                                          Nothing -> 0
    print $ modifiedDistanceFromRoot u + modifiedDistanceFromRoot v - 2 * modifiedDistanceFromRoot w


Measured memory_bytes: 141564
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    string s;
    cin>>s;
    map<char,int>vis;
    for(auto ch:s)vis[ch]=1;
    if(vis.count('W') && vis.count('E') && vis.count('N') && vis.count('S'))
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    if(vis.count('W') && vis.count('E') && !vis.count('N') && !vis.count('S'))
    {
        cout<<"Yes"<<endl;
        return 0;
    }
     if(!vis.count('W') && !vis.count('E') && vis.count('N') && vis.count('S'))
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;

}













Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 

ll m = 1e9+7;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,w;
	cin >> h >> w;
	vector <vector<ll>> grid(h,vector<ll>(w,0));
	bool dp[h][w][6401];
	for (int z=0;z<h;z++){
		for (int x=0;x<w;x++){
			cin >> grid[z][x];
		}
	}
	for (int z=0;z<h;z++){
		for (int x=0;x<w;x++){
			ll temp; cin >> temp;
			grid[z][x] -= temp;
			grid[z][x] = abs(grid[z][x]);
		}
	}
	for (int z=0;z<h;z++){
		for (int x=0;x<w;x++){
			for (int y=0;y<=6400;y++){
				dp[z][x][y] = false;
			}
		}
	}
	dp[0][0][grid[0][0]] = 1;
	for (int z=0;z<h;z++){
		for (int x=0;x<w;x++){
			for (int y=0;y<=6400;y++){
				if (z+1 < h){
					if (y+grid[z+1][x] <= 6400)
					dp[z+1][x][y+grid[z+1][x]] |= dp[z][x][y];
					if (abs(y-grid[z+1][x]) <= 6400)
					dp[z+1][x][abs(y-grid[z+1][x])] |= dp[z][x][y];
				}
				if (x+1 < w){
					if (y+grid[z][x+1] <= 6400)
					dp[z][x+1][y+grid[z][x+1]] |= dp[z][x][y];
					if (abs(y-grid[z][x+1]) <= 6400)
					dp[z][x+1][abs(y-grid[z][x+1])] |= dp[z][x][y];
				}

			} 
		}
	}
	for (ll z=0;z<=6400;z++){
		if (dp[h-1][w-1][z]){
			cout << z << endl;
			return 0;
		} 
	} 
}


Measured memory_bytes: 40320
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer [] num = new Integer[3];
        for (int i = 0; i < 3; i ++) {
        	num[i] = sc.nextInt();
        }
        Arrays.sort(num, Comparator.reverseOrder()); 
        int n = Integer.parseInt(String.valueOf(num[0])+String.valueOf(num[1]))+num[2];
        System.out.println(n);
    }
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (N * A < B){
    cout << N * A << endl;
  }
  
  if (N * A > B){
    cout << B << endl;
  }
  
  if (N * A == B){
    cout << B << endl;
  }
  
}
  

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

int main()
{
  int a,b;
  char op;

  while(1){
  cin >> a >> op >> b;
  if(op == '?')
    break;

  if(op == '+')
    cout << a+b << endl;

  if(op == '-')
    cout << a-b << endl;

  if(op == '*')
    cout << a*b << endl;

  if(op == '/')
    cout << a/b << endl;
  }
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll H=in(),W=in(),D=in();
	vector<pair<ll,ll>> C(H*W);
	REP(i,H){
		REP(j,W){
			C[in()-1] = make_pair(j+1,i+1);
		}
	}
	vector<ll> M(H*W,0LL);
	for(ll i=0;i<H*W-D;i++){
		M[i+D] = M[i]+abs(C[i+D].first-C[i].first)+abs(C[i+D].second-C[i].second);
	}
	
	int Q=in();
	LOOP(Q){
		int R=in()-1,L=in()-1;
		out(M[L]-M[R]);
	}

	return 0;
}


Measured memory_bytes: 3200