akhauriyash/Code-Regression huggingface dataset:
package main

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

func nextInt(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("no more token")
	}

	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("not integer")
	}

	return r
}

func main() {
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)

	n := nextInt(s)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt(s)
		b[i] = nextInt(s)
		c[i] = nextInt(s)
	}

	fmt.Println(solve(n, a, b, c))
}

func solve(n int, a, b, c []int) int {
	x, y, z := 0, 0, 0

	for i := 0; i < n; i++ {
		x, y, z = max(y, z)+a[i], max(x, z)+b[i], max(x, y)+c[i]
	}

	return max(x, max(y, z))
}

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


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

int main() {
    string s;
    cin >> s;

    //yes or no
    bool ok = true;
        
    //奇数文字目がLであるまたは偶数文字目がRであるときok = falseにすればいい

    for(int i=0; i<s.size(); ++i) {
        if(i%2==0 && s[i] == 'L') {
            ok = false;
        }
        if(i%2==1 && s[i] == 'R') {
            ok = false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>

int main() {
  size_t n;
  intmax_t d;
  scanf("%zu %jd", &n, &d);

  intmax_t res = 0;
  for (size_t i = 0; i < n; ++i) {
    intmax_t a;
    scanf("%jd", &a);
    --a;
    a %= d+1;
    res ^= a;
  }

  puts(res? "First":"Second");
}



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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==0){
        cout << a-b << endl;
    }else{
        cout << b-a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, X = map(int,input().split()) # 複数の数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

count = 1
point = 0

while point <= X and count <= N:
    point += List[count-1]
    if point <= X:
        count += 1

print(count)

Measured memory_bytes: 2940
N,M = map(int,input().split())
K = []
L = []
for _ in range(N):
    k,*l = map(int,input().split())
    K.append(k)
    L.append(l)
    
graph = [[] for _ in range(N+M)]
for i in range(N):
    for l in L[i]:
        graph[i].append(N+l-1)
        graph[N+l-1].append(i)

visited = [0 for _ in range(N+M)]
visited[0] = 1
stack = [0]

while stack:
    node = stack.pop()
    for adj in graph[node]:
        if not visited[adj]:
            visited[adj] = 1
            stack.append(adj)
            
print('YES' if all(visited[:N]) else 'NO')

Measured memory_bytes: 48900
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vc vector<char>
void solve(){
    ll n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
    }
    else{
        cout<<(1000*(n/1000+1))-n<<endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   solve();
    return 0;
}

Measured memory_bytes: 3576
n, m = map(int, input().split())

if m == 1:
  l, r = map(int, input().split())
  print(r-l+1)
else:
  ls, rs = [], []
  for _ in range(m):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
  ans = min(rs) - max(ls) + 1
  if ans > 0:
    print(ans)
  else:
    print(0)

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int k, x;
	cin >> k >> x;
	for (int i = max(-1000000, x - k + 1); i <= min(1000000, x + k - 1); i++) {
		cout << i << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()
mod = 10 ** 9 + 7

dp = [1] + [0] * 12
for c in s:
  tmp = dp[:]
  if c == '?':
    dp = [0] * 13
    for n in range(10):
      for i in range(13):
        index = (10 * i + n) % 13
        dp[index] = (dp[index] + tmp[i]) % mod
  else:
    n = int(c)
    for i in range(13):
      dp[(10 * i + n) % 13] = tmp[i]
print(dp[5])

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

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] times = br.readLine().split(" ");
            int now = Integer.parseInt(times[0]);
            int contestStartFromNow = Integer.parseInt(times[1]);

            int contestStratTime = now + contestStartFromNow;

            // convert to 24-hour display
            if (contestStratTime < 24) {
                System.out.println(contestStratTime);
            } else {
                System.out.println(contestStratTime - 24);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22612
open System

let arr = Console.ReadLine().Split(' ')
let N = arr.[0] |> int
let A = arr.[1] |> int
let B = arr.[2] |> int

let sum (x:int) = 
    x
    |> string
    |> Seq.sumBy (fun c -> int c - int '0')
    
[1..N]
|> Seq.sumBy (fun x -> if (A <= sum x && sum x <= B) then x else 0)
|> printfn "%d"

Measured memory_bytes: 32008
#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;
    cin >> N;

    int t = N/100;
    int res = t*100 + t*10 + t;
    if(N > res) res += 111;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){

  int *a;
  int n,i,j;

  scanf("%d",&n);
  a = malloc(sizeof(int)*(n+1));

  for( i=1 ; i<n+1 ; i++ ){
    scanf("%d",&a[i]);
  }

  for( j=1 ; j<n+1 ; j++ ){
    printf("node %d: key = %d, ",j ,a[j]);
    if( j != 1 ){
      printf("parent key = %d, ",a[j/2]);
    }
    if( 2*j <= n ){
      printf("left key = %d, ",a[2*j]);
    }
    if( 2*j+1 <= n ){
      printf("right key = %d, ",a[2*j+1]);
    }
    printf("\n");
  }

  free(a);

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)

constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;

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

  int H,W,C_h,C_w,D_h,D_w;
  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  string S[H];
  rep(i,H)cin>>S[i];

  vector dist(H,vector(W,INF));
  bool seen[H][W] = {};
  dist[C_h][C_w] = 0;
  deque<pair<int,int>> deq;
  deq.emplace_front(C_h,C_w);
  while(!deq.empty()){
    auto [y,x] = deq.front();
    deq.pop_front();
    if(seen[y][x])continue;
    seen[y][x] = true;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]){
          dist[ny][nx] = dist[y][x];
          deq.emplace_front(ny,nx);
        }
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]+1){
          dist[ny][nx] = dist[y][x]+1;
          deq.emplace_back(ny,nx);
        }
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}


Measured memory_bytes: 9712
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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














int main() {
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    REP(i, n + 1){
        cin >> a[i];
    }
    ll ans = 0;
    REP(i, n){
        ll b;
        cin >> b;
        ans += min(a[i], b);
        b -= min(a[i], b);
        ans += min(a[i + 1], b);
        a[i + 1] -= min(a[i + 1], b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
package main

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

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

func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()
	c := readInt()
	d := readInt()
	if abs(a-c) <= d {
		println("Yes")
		return
	}
	if abs(a-b) <= d && abs(b-c) <= d {
		println("Yes")
		return
	}
	println("No")
}

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}


Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int n; cin >>n;
  vector<vector<int>> a(n,vector<int>(3));
  rep(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];
  if(n==1){
    if(a[0][0]>=abs(a[0][1])+abs(a[0][2])){
      if((-abs(a[0][1])-abs(a[0][2])+a[0][0])%2==0){
        cout <<"Yes"<<endl;
        return 0;
      }
    }
    cout  <<"No"<<endl;
    return 0;
  }
  ll count=0;
  rep(i,n-1){
    if(a[i+1][0]-a[i][0]>=abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])){
      if((-abs(a[i+1][1]-a[i][1])-abs(a[i+1][2]-a[i][2])+a[i+1][0]-a[i][0])%2==0){
        count++;
      }
    }
  }
  if(count==n-1)cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 5760
import java.util.*;
class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(),x=s.nextInt()/50,r=0;
		for(int i=0;i<=a;++i) {
			for(int j=0;j<=b;++j) {
				int v=x-10*i-2*j;
				if(0<=v&&v<=c)
					++r;
			}
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 23764
n,y=map(int,input().split())
flag=True
for i in range(n+1):
    for j in range(n+1):
        if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
            flag=False
            print(i,j,n-i-j)
            break
    else:
        continue
    break
if flag:
    print('-1 -1 -1')

Measured memory_bytes: 9140
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long int;

const ll mod = 1E+09 + 7;

int main(){
    ll n;
    cin >> n;

    ll ans = 1;
    ll sub = 1;
    for(int i = 0; i < n; i++){
        ans *= 10;
        ans %= mod;
        sub *= 9;
        sub %= mod;
    }
    sub *= 2;
    sub %= mod;
    ll sub2 = 1;
    for(int i = 0; i < n; i++){
        sub2 *= 8;
        sub2 %= mod;
    }
    ans += mod - sub + sub2;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>

int main(){

      int i,N,K;

      scanf("%d",&N);

      char moji[N],S;

      scanf("%s",moji);

      scanf("%d",&K);

      S = moji[K-1];
      for(i=0;moji[i] != '\0';i++){
            if(moji[i] != S)moji[i] = '*';
      }
      printf("%s",moji);
}


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

int main(){
  int a,b,c,diff;
  cin >> a >> b >> c >> diff;

  string ans= (abs(c-a) <= diff || (abs(b-a) <= diff && abs(c-b) <= diff)) ? "Yes" : "No";

  cout << ans << endl;
}

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

int main(){
  int A,B,C,X,sum=0;
  cin >> A >> B >> C >> X;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(500*i + 100*j + 50*k==X){
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main(){
	std::vector<int> vegetables;
	int num,cap,price,i;

	while(std::cin >> num >> cap){

		if(num == 0 && cap == 0){
			break;
		}

		int sum = 0;

		for(i=0; i<num; ++i){
			std::cin >> price;
			vegetables.push_back(price);
		}

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

		i = 0;

		while(i < num){

			if((i+1) % cap != 0){
				sum += vegetables.at(i);
			}

			++i;
		}

		std::cout << sum << std::endl;

		vegetables.clear();
	}

}

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

const int MOD = (int)1e9+7;

int main(){
	int H,W,A,B;
	cin >> H >> W >> A >> B;
	
	int count=0;
	for(int i=0;i<H;i++){
		int x=0;
		for(int j=0;j<W-1;j++){
			if(count<B && x<A)	cout << "0";
			else if(count<B && x>=A)	cout << "1";
			else if(count>=B && x<A)	cout << "1";
			else if(count>=B && x>=A)	cout << "0";
			x++;
		}
		if(count<B && x<A)	cout << "0" << endl;
		else if(count<B && x>=A)	cout << "1" << endl;
		else if(count>=B && x<A)	cout << "1" << endl;
		else if(count>=B && x>=A)	cout << "0" << endl;
		count++;
	}
	
	return 0;
}


Measured memory_bytes: 1280
#include <atcoder/fenwicktree>
#include <iostream>

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

int main(void) {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  atcoder::fenwick_tree<int64_t> ft(N);
  rep(i, N) {
    int64_t a;
    cin >> a;
    ft.add(i, a);
  }

  rep(i, Q) {
    int t;
    cin >> t;
    if (t == 0) {
      int p;
      int64_t x;
      cin >> p >> x;
      ft.add(p, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << ft.sum(l, r) << endl;
    }
  }
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    long N;
    cin >> N;
    long long ans = 0;
    for(int i = 1;i <= N;i++){
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }else{
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
N, T = map(int, input().split())
c = []
t = []
for i in range(N):
    tmp1, tmp2 = map(int, input().split())
    c.append(tmp1)
    t.append(tmp2)

tmp_min = float('inf')

for i in range(N):
    if t[i]<=T and tmp_min>c[i]:
        tmp_min = c[i]

if tmp_min == float('inf'):
    print('TLE')
else:
    print(int(tmp_min))


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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Pip;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n, k;
int cost[5000], r[5000];
bool used[5000][5010];
vector<Vi> e;

int main() {

  cin >> n >> k;
  e.resize( n );

  for(int i=0; i<n; i++) {
    cin >> cost[i] >> r[i];
  }

  for(int i=0; i<k; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb( b );
    e[b].pb( a );
  }

  priority_queue<Pip, vector<Pip>, greater<Pip> > q;

  q.push(Pip(0, Pii(0, 0)));

  while( !q.empty() ) {

    Pip p = q.top(); q.pop();
    int co = p.fr, re = p.sc.fr, cu = p.sc.sc;

    if( used[cu][re] ) continue;
    used[cu][re] = 1;

    if( cu == n-1 ) {
      cout << co << endl;
      return 0;
    }

    if( !used[cu][r[cu]] ) {
      q.push(Pip(co+cost[cu], Pii(r[cu], cu)));
    }

    if( re-1 >= 0 ) {
      for(int i=0; i<e[cu].size(); i++) {
	if( !used[e[cu][i]][re-1] ) {
	  q.push(Pip(co, Pii(re-1, e[cu][i])));
	}
      }
    }
  }
}

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
const ll r =998244353;

int main(){
  ll n;
  bool flag=true;
  ll ans=1;
  cin >> n;
  vector<ll> v(n);
  vector<ll> des(n+1);
  for(ll i=0; i < n; i++){
    cin >> v.at(i);
    des.at(i)=0;
  }
  des.at(n)=0;
  for(ll i=0; i<n; i++) des.at(v.at(i))++;
  if (v.at(0)!=0 || des.at(0)!=1){
      flag= false;
      cout << 0 << endl;
      return 0;
    }
  for (ll j=0; j < n-1; j++){
    if (des.at(j)==0 && des.at(j+1) != 0){
      flag =false;
      cout << 0 << endl;
      return 0;
    }
  }
  if (flag){
    for (ll j=2; des.at(j)!=0; j++){
      if (des.at(j-1) == 1) continue;
      for(ll h = 0; h<des.at(j); h++){
         ans = ans%r * (des.at(j-1))%r;
       }
    }
  }
  
  if (flag) cout << ans << endl;
  //rep(i,n) cout << des.at(i) << " " ;
  //cout << flag << endl;
  return 0;
}


Measured memory_bytes: 1792
import math
while 1:
    n=int(input())
    avg=0
    bun=0
    a=[0 for i in range(n)]
    if n==0:
        break
    s=list(map(int, input().split()))
    for i in range(n):
        avg+=s[i]
    avg=avg/n
    for i in range(n):
        a[i]+=(s[i]-avg)**2
    for i in range(n):
        bun+=a[i]
    bun=bun/n
    ans=math.sqrt(bun)
    print(ans)


Measured memory_bytes: 5712
#include <stdio.h>
int main(void){
  int n,a[100],max,min,i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  max=a[0];min=a[0];
  for(i=1;i<n;i++){
    if(max<a[i]) max=a[i];
    else if(min>a[i]) min=a[i];
  }
  printf("%d",max-min);
  return 0;
}

Measured memory_bytes: 128
#if 0
???????????????????\??????¨??¨????????????????????£????????????????????????
??????????????????????????¨??????????????????????????????????????????????????°????????????????????????????????????????????????????????£????????????????????§??????
?????????????????????????????´???????????????????????\????????????????´???´??????????????¨???????????????
while?????¨????????§??????
????????´???????????????????????????????????§??????
#endif
#include <iostream>
using namespace std;
int X, Y, S;
int tax(int rate,int value){
  int cost;
  cost = (rate + 100)*value/100;
  return cost;
}
int solve(){
  int maximum = 0;
  for(int i = 1; i < S; ++i)
    for(int j = 1; j < S; ++j)
      if(tax(X,i) + tax(X,j) == S)
	maximum = max(maximum, tax(Y,i) + tax(Y,j));
  return maximum;
}
int main(){
  while(cin >> X >> Y >> S && X > 0 ){
    cout << solve() << endl;
  }
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

ll cnt = 0;
vector<int> g;

void insertionSort(int a[], int n, int g) {
  for (int i = g; i < n; ++i) {
    int v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j = j - g;
      ++cnt;
    }
    a[j + g] = v;
  }
}

void shellSort(int a[], int n) {
  for (int h = 1; ;) {
    if (h > n) break;
    g.push_back(h);
    h = 3 * h + 1;
  }
  cout << g.size() << endl;
  for (int i = g.size() - 1; i >= 0; --i) {
    cout << g[i];
    if (i == 0) break;
    cout << " ";
  }
  cout << endl;
  for (int i = g.size() - 1; i >= 0; --i) {
    insertionSort(a, n, g[i]);
  }
}

int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
  }
  shellSort(arr, n);
  cout << cnt << endl;
  for (int i = 0; i < n; ++i) {
    cout << arr[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 7140
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
   long a=sc.nextInt();
    long b=sc.nextInt();
    long c=sc.nextInt();
    long d=sc.nextInt();
    long arr[]=new long[4];
    arr[0]=a*c;
    arr[1]=a*d;
    arr[2]=b*c;
    arr[3]=b*d;
    Arrays.sort(arr);
    System.out.println(arr[3]);
    
  }
}


Measured memory_bytes: 35876
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<int> c(m);
    for (int i = 0; i < m; i++){
        cin >> s.at(i) >> c.at(i);
    }
    
    bool check = true;
    
    if (n == 1){
        int z = 0;
        for (int i = 0; i < m; i++){
            if (z != 0){
                if (z != c.at(i)){
                    check = false;
                }
            }else{
                z = c.at(i);
            }
        }
        if (check) cout << z << endl;
        else cout << -1 << endl;
    }
    
    if (n == 2){
        int y = 1;
        int z = 0;
        for (int i = 0; i < m; i++){
            if (s.at(i) == 1){
                if (c.at(i) == 0){
                    check = false;
                }else if (y != 1 && y != c.at(i)){
                    check = false;
                }else{
                    y = c.at(i);
                }
            }
            
            if (s.at(i) == 2){
                if (z != 0){
                 if (z != c.at(i)){
                     check = false;
                 }
             }else{
                    z = c.at(i);
              }
            }
        }
        
        if(check) cout << y << z << endl;
        else cout << -1 << endl;
    }
    
    if (n == 3){
        int x = 1;
        int y = 0; 
        int z = 0;
        for (int i = 0; i < m; i++){
            if (s.at(i) == 1){
                if (c.at(i) == 0){
                    check = false;
                }else if (x != 1 && x != c.at(i)){
                    check = false;
                }else{
                    x = c.at(i);
                }
            }
            
            if (s.at(i) == 2){
                if (y != 0){
                 if (y != c.at(i)){
                     check = false;
                 }
             }else{
                    y = c.at(i);
              }
            }
            
            if (s.at(i) == 3){
                if (z != 0){
                 if (z != c.at(i)){
                     check = false;
                 }
             }else{
                    z = c.at(i);
              }
            }
            
            
            
        }
        
        if(check) cout << x << y << z << endl;
        else cout << -1 << endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(w: str):
    d = defaultdict(int)
    for c in w:
        d[c] += 1
    flag = True
    for k, v in d.items():
        if v % 2 == 1:
            flag = False
            break
    if flag:
        yes()
    else:
        no()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    w = next(tokens)  # type: str
    solve(w)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]

ans = b[a[0] - 1]

for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        ans += c[a[i] - 2]

print(ans)

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

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

fn main() {
    let s: String = read();
    let s: Vec<char> = s.chars().collect();
    let l = s.len();
    let mut ans = "Yes";
    let pattern = &s[0..(l - 1) / 2];
    let mut p1 = pattern.clone().iter().rev();
    for i in pattern {
        if i != p1.next().unwrap() {
            ans = "No";
            break;
        }
    }

    if pattern != &s[(l + 2) / 2..l] {
        ans = "No";
    }

    println!("{}", ans);
}

Measured memory_bytes: 2092
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 

char SWswap(char c){
    if (c == 'S') return 'W';
    else return 'S';
}

bool out(string S, string s){
    int N = S.size();
    if (s[N-1] == 'o'){
        if (S[N-1] == 'S' && S[0] == S[N-2]){
            return true;
        }
        else if (S[N-1] == 'W' && S[0] != S[N-2]){
            return true;
        }
    }
    else {
        if (S[N-1] == 'S' && S[0] != S[N-2]){
            return true;
        }
        else if (S[N-1] == 'W' && S[0] == S[N-2]){
            return true;
        }
    }
    return false;
}

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

int N;
string s;
cin >> N >> s;

VS ans{"SS", "SW", "WS", "WW"};
for(string S: ans){
    rep(i, 1, N-1){
        if (s[i] == 'o'){
            if (S[i] == 'S') S.push_back(S[i-1]);
            else S.push_back(SWswap(S[i-1]));
        }
        else { // s[i] == 'x'
            if (S[i] == 'S') S.push_back(SWswap(S[i-1]));
            else S.push_back(S[i-1]);
        }
    }

    if (s[0] == 'o'){
        if ((S[0] == 'S' && S[1] == S[N-1]) || (S[0] == 'W' && S[1] != S[N-1]))
            if (out(S, s)){
                cout << S + "\n";
                return 0;
            }
    }
    else {
        if ((S[0] == 'S' && S[1] != S[N-1]) || (S[0] == 'W' && S[1] == S[N-1]))
            if (out(S, s)){
                cout << S + "\n";
                return 0;
            }
    }

}


cout << "-1\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

int main() {
  char moji;
  cin>>moji;
  if(moji=='a'||moji=='i'||moji=='u'||moji=='e'||moji=='o'){
      cout<<"vowel"<<endl;
  }else{
      cout<<"consonant"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	string t = s;
	reverse(t.begin(),t.end());
	s += t;

	vector<string> kouho;
	for(int i=0; i<n; i++){
		kouho.push_back(s.substr(i,n));
	}
	sort(kouho.begin(),kouho.end());

	char a = kouho[0][0];
	string ans = "";
	int i = 0;
	while(ans.size() < n && kouho[0][i] == a){
		for(int j=0; j < pow(2,min(20, k-1)) && ans.size() < n; j++){
			ans.push_back(a);
		}
		i++;
	}
	while(ans.size() < n){
		ans.push_back(kouho[0][i]);
		i++;
	}

	cout<<ans<<endl;

	return 0;
}


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

int main()
{
	int l,r,n;
	cin>>l>>r>>n;
	int c=0;
	for(int i=l;i<=r;i++)
	{
		if(i%n==0)
		{
			c++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
ll ans=0;
int a[100001];
int x=100;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int main(void)
{
	int n;int k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i==1) x=a[1];
		else
		{
			x=gcd(x,a[i]);
		}
	}
	sort(a+1,a+1+n);

	if(k%x||k>a[n]) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 640
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

def lcm(a,b):
    return (a*b)//gcd(a, b)

N = int( input())
T = [ int( input()) for _ in range(N)]
ans = T[0]
for i in range(1,N):
    ans = lcm(ans,T[i])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MAX 1000006
#define MOD 1000000007
#define LL long long
#define NL '\n'
using namespace std;


int main(){
    std::ios_base::sync_with_stdio(0);
    string str;
    cin >> str;

    int cnt = 0;

    if( str[0] == '1' ) cnt++;
    if( str[1] == '1' ) cnt++;
    if( str[2] == '1' ) cnt++;

    cout << cnt << NL;

    return 0;
}



Measured memory_bytes: 256
mod = 1000000007

def mul(x, y):
    return x * y % mod

def f(n, arr):
    answer = 1
    count = [0 for _ in range(n + 1)]
    count[0] = 3
    for e in range(n):
        answer = mul(answer, count[arr[e] - 1] - count[arr[e]])
        count[arr[e]] = count[arr[e]] + 1
        # print("answer ", answer)
    return answer

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    for i in range(n):
        arr[i] = arr[i] + 1 
    print(f(n, arr))

Measured memory_bytes: 14364
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int ar[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
  ll h,w;
  cin>>h>>w;
  if(h==1||w==1) cout<<1<<endl;
  else cout<<((h*w+1)/2)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,m;
bool f1[200010],f2[200010];
int main(){
	scanf("%d%d",&n,&m);
	int a,b;
	for(int i=1;i<=m;++i){
		scanf("%d%d",&a,&b);
		if(a>b){int t=a;a=b;b=t;}
		if(a==1) f1[b]=true;
		if(b==n) f2[a]=true;
	}
	for(int i=1;i<=n;++i){
		if(f1[i]&&f2[i]){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll h,w,n;
   cin>>h>>w>>n;
   
   ll ans = inf;
   for(ll r=0;r<=h;r++)
        for(ll c=0;c<=w;c++)
        {
            ll cnt1 = r*w;
            ll cnt2 = c*h;
            ll tot = cnt1 + cnt2 - r*c;
            if(tot>=n)
                ans = min(ans, r+c);
        }
   
   cout<<ans;    
        
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include <iostream>

using namespace std;
double dp[3010][3010] = {},p[3010],ans = 0;
int main(){
	cout.precision(30);
	int i,j,n;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> p[i];
	}
	dp[0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<=i;j++){
			if(j==0) dp[i][j] = (1-p[i])*dp[i-1][0];
			dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])*dp[i-1][j];
		}
	}
	
	for(i=n/2+1;i<=n;i++){
		ans += dp[n][i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1145141919;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool etmin(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n, m; cin>>n>>m;
    vector <int> a(n);
    int ans = 0;
    rep(i,m){
        int p; cin>>p;
        string s; cin>>s;
        //cout<<p<<' '<<s<<endl;
        p--;
        if(a[p] == INF) continue;
        if(s == "WA") a[p]++;
        else{
            if(a[p] < INF) ans += a[p];
            a[p] = INF;
        }
    }
    int ac = 0;
    rep(i,n){

        if(a[i] >= INF) ac++;
    }
    //dump(a);
    cout<<ac <<' '<<ans<<endl;
}

Measured memory_bytes: 1024
N,x = map(int,input().split())
DP = [list(map(int,input().split()))]+[[float('inf')]*(N) for i in range(N-1)]
for i in range(N-1):
    for j in range(N):
        DP[i+1][j] = min(DP[i][j-1],DP[i][j])
ans = float('inf')
for i in range(N):
    ans = min(ans,sum(DP[i])+i*x)
print(ans)

Measured memory_bytes: 137308
/*;

THE BEST IS YET TO COME

*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i, s, l) for (int i = s; i >= l; i--)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<int, int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define vi vector<int>
#define vip vector<pair<int, int>>
#define endl "\n"
#define ln length()
#define sz size()
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{

    fast();
    int n;
    cin>>n;
    vi a(n),b(n),c(n);
    
    r(i,0,n)
    cin>>a[i]>>b[i]>>c[i];

    int dp[n][3];
    
    //r(i,0,n)
    //r(j,0,3)
    //dp[i][j] = 0;

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    
    r(i,1,n)
    {
        dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
    }

    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    return 0;
}


Measured memory_bytes: 7916
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    D = [LI() for _ in range(N)]

    ans = 'No'
    for i in range(N - 2):
        if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
            ans = 'Yes'
            break

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int a, b, c, ans = INF;
	scanf("%lld%lld%lld", &a, &b, &c);
	chmin(ans, llabs((a/2)*b*c-(a-a/2)*b*c));
	chmin(ans, llabs(a*(b/2)*c-a*(b-b/2)*c));
	chmin(ans, llabs(a*b*(c/2)-a*b*(c-c/2)));
	printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

ll s(ll v) {
	return (v*2)-1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	while(cin>>N>>M) {
		VI X(N), Y(N), Z(N);
		ll ans = 0;
		REP(i, N) cin>>X[i]>>Y[i]>>Z[i];
		REP(xs, 2) REP(ys, 2) REP(zs, 2) {
			VI w(N);
			REP(i, N) w[i] = s(xs)*X[i] + s(ys)*Y[i] + s(zs)*Z[i];
			sort(ALLR(w));
			ll lans = accumulate(&w[0], &w[M], 0LL);
//			DD(lans);
			ans = max(ans, lans);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
inp = list(map(lambda x: int(x), input().split(" ")))

dp = [0]*n

for i in range(n-1):
    if (i>0):
        dp[i+1] = min(dp[i-1]+abs(inp[i+1]-inp[i-1]), dp[i]+abs(inp[i+1]-inp[i]))
    else:
        dp[i+1] = abs(inp[1]-inp[0])
print(dp[-1])

Measured memory_bytes: 13980
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <string>

#define si pair<string, int>
#define sii pair<si, int>
#define mp make_pair

using namespace std;

int main() {
	int n, p;
	char s[15];
	string x;
	sii t[110];
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%s %d", s, &p);
		x = s;
		t[i - 1] = mp(mp(x, -p), i);
	}
	sort(t, t + n);
	for (int i = 0; i < n; i++)
		printf("%d\n", t[i].second);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 1003;

int main()
{
	//File("");
    string s;
    cin >> s;
    if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") puts("Yes");
    else puts("No");
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

n=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
c=0
for i in range(n):
    d[a[i]]+=1
    if d[a[i]]>2:d[a[i]]-=2;c+=1
e=[x[1] for x in sorted(d.items(),key=lambda x:x[0])]
c+=(e.count(2)+1)//2
print(n-c*2)

Measured memory_bytes: 21980
import java.util.Scanner;

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

    int N = scanner.nextInt();
    for (long h = 1; h <= 3500; h++) {
      for (long n = 1; n <= 3500; n++) {
        long a = N * h * n;
        long b = 4 * h * n - N * n - N * h;
        if (b <= 0) continue;
        if (a % b == 0) {
          System.out.printf("%d %d %d\n", h, n, a / b);
          return;
        }
      }
    }
  }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

vector<vector<int>> graph;

int bfs(int n, int st){
    queue<int> q;
    int start = st;
    vector<int> visited(n,-1);
    q.push(start);
    visited[start] = 1;
    int ret = 0;
    while(!q.empty()){
        int now = q.front();
        q.pop();

        for(int i = 0; i < graph[now].size(); i++){
            int next = graph[now][i];
            if(visited[next] == -1){
                q.push(next);
                visited[next] = visited[now] + 1;
                ret = max(ret, visited[now] + 1);
            }else{
                if(visited[next]%2 != (visited[now]+1)%2){
                    return -1;
                }
            }
        }
    }

    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    graph.resize(n);

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(s[i][j] == '1'){
                graph[i].push_back(j);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp = bfs(n, i);
        if(tmp == -1){
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512