akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()){
			int n = sc.nextInt();
			if(n == 0){ break; }
			int[] score = new int[n];
			for(int i=0; i<n; i++){ score[i] = sc.nextInt(); }

			int max = score[0];
			int min = score[0];
			for(int i=0; i<n; i++){
				if(max <= score[i]){ max = score[i]; }
				if(min >= score[i]){ min = score[i]; }
			}

			int average = 0;
			for(int i=0; i<n; i++){ average += score[i]; }
			average = (average - max - min) / (n - 2);
			System.out.println(average);
		}
	}
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
// https://www.youtube.com/watch?v=hh97LmRSjeY 37:40
const ll mod = 1e9 + 7;

map<pair<ll,ll>,ll> dp;

ll f(ll x, ll y) {
  if (x<0 || y<0) return 0;
  if (dp.count({x,y})) return dp[{x,y}];
  if (x==0 && y==0) return 1;

  ll res = 0;
  if (x>=2 && y>=2) res += f((x-2)/2, (y-2)/2); //1, 1
  if (x>=1) res += f((x-1)/2, y/2); //1, 0
  res += f(x/2, y/2);
  res %= mod;
  res += mod;
  res %= mod;

  return dp[{x,y}] = res;
}

ll n;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;
  ll res = f(n,n);
  res %= mod;
  res += mod;
  res %= mod;
  cout<<res<<endl;
  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  
  rep(i,10) {
  c = a*c-b;
  cout << c << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	X -= A;
	X -= X / B * B;
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    int H,W,N;
    int a[10000];
    int ans[100][100];
    int now[2] = {};
    int dir = 1;
    cin >> H >> W >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<a[i];j++){
            ans[now[0]][now[1]] = i+1;
            if(now[1]+dir < 0 || now[1]+dir >= W){
                dir *= -1;
                now[0]++;
            }
            else now[1] += dir;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()

	sc.Scan()
	list := strings.Split(sc.Text(), " ")

	sc.Scan()

	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")
		begin, _ := strconv.Atoi(inputs[0])
		end, _ := strconv.Atoi(inputs[1])
		end--

		for {
			if begin == end || begin > end {
				break
			}
			tmp := list[begin]
			list[begin] = list[end]
			list[end] = tmp
			begin++
			end--
		}
	}

	fmt.Println(strings.Trim(fmt.Sprint(list), "[]"))
}



Measured memory_bytes: 1316
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define all(a) (a).begin(),(a).end()
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define N 100005
    #define fs first
    #define sc second
    using namespace std;

    typedef  long long int ll;
    typedef pair<ll,ll> ii;
    typedef vector <ii> vii;
    typedef vector <ll> vi;


    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios;
ll a,b,c,x,cnt=0;
cin>>a>>b>>c>>x;
for(int i=0;i<=a;i++)
{
    for(int j=0;j<=b;j++)
    {
        for(int k=0;k<=c;k++)
        {
            if(500*i+100*j+50*k==x)
                cnt++;
        }
    }
}
    
cout<<cnt<<endl;








    return 0;


    }

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int main()
{
	int n,m,a,b;
	int x[101]={},i,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;++i)
	{
		scanf("%d%d",&a,&b);
		for(j=a;j<=b;++j)
			x[j]=std::max(x[j],b);
	}
	int res=0;
	for(i=1;i<=n;)
	{
		if(x[i])
		{
			i=x[i]+1;
			++res;
		}
		else
		{
			res=-1;
			break;
		}
	}
	if(res>=0)
		printf("%d\n",res);
	else
		puts("Impossible");
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool dfs(int v, vector<int> &memo, vector<vector<int>> &G, vector<int> &order){
	memo[v] = 1;
	for(auto nv : G[v]){
		if(memo[nv] == 2) continue;
		if(memo[nv] == 1) return false;
		if(!dfs(nv, memo, G, order)) return false;
	}
	memo[v] = 2;
	order.push_back(v);
	return true;
}

bool tsort(vector<vector<int>> &G, vector<int> &order){
	vector<int> memo(G.size(), 0);
	rep(i,G.size()){
		if(memo[i] != 0) continue;
		if(!dfs(i, memo, G, order)) return false;
	}
	reverse(order.begin(), order.end());
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> G(n), RG(n);
	rep(i,n+m-1){
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		RG[b].push_back(a);
	}
	vector<int> order;
	tsort(G, order);
	
	map<int, int> zip;
	rep(i,order.size()) zip[order[i]] = i;

	int root = order[0];
	vector<int> par(n, -1);
	par[root] = 0;
	for(int i = 1; i < order.size(); ++i){
		int p = -1, hoge = -1;
		for(int nex : RG[order[i]]){
			if(par[nex] == -1) continue;
			if(hoge < zip[nex]){
				hoge = zip[nex];
				p = nex;
			}
		}
		par[order[i]] = p + 1;
	}

	rep(i,n) cout << par[i] << endl;
	return 0;
}

Measured memory_bytes: 21492
use std::io::BufRead;
use std::str::FromStr;

fn main() {
    let stdin = std::io::stdin();
    let mut t = Tokenizer::new(stdin.lock().lines().map(|x| x.unwrap()));

    let num: i32 = t.take();
    let mut nums: Vec<i32> = Vec::new();
    for _i in 0 .. num {
        nums.push( t.take() );
    }
    let result = problem( &mut nums);
    println!("{}", result);
}

fn problem( nums: &mut Vec<i32> ) -> i32 {
    nums.sort();
    let num = nums.len();
    if (num % 2) == 1 {
        // 奇数個の場合
        return 0;
    }
    nums[num/2] - nums[num/2 -1]
}


#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test1() {
        let mut nums: Vec<i32> = vec![9, 1, 4, 4, 6, 7];
        let result = problem( &mut nums );
        assert_eq!(result,2);
    }

    #[test]
    fn test2() {
        let mut nums: Vec<i32> = vec![9, 1, 14, 5, 5, 4, 4, 14];
        let result = problem( &mut nums );
        assert_eq!(result,0);
    }

    #[test]
    fn test3() {
        let mut nums: Vec<i32> = vec![99592, 10342, 29105, 78532, 83018, 11639, 92015, 77204, 30914, 21912, 34519, 80835, 100000, 1];
        let result = problem( &mut nums );
        assert_eq!(result,42685);
    }
}


struct Tokenizer<S: Iterator<Item = String>> {
    input: S,
    items: Vec<String>,
}

impl<S: Iterator<Item = String>> Tokenizer<S> {
    pub fn new(input: S) -> Self {
        Tokenizer {
            input: input,
            items: Vec::new(),
        }
    }

    pub fn take<T: FromStr>(&mut self) -> T {
        loop {
            if let Some(r) = self.items.pop() {
                return r.parse().ok().expect("parse failed");
            }
            let mut items = self
                .input
                .next()
                .unwrap()
                .split_whitespace()
                .map(|x| x.to_string())
                .collect::<Vec<String>>();
            items.reverse();
            self.items = items;
        }
    }
}


Measured memory_bytes: 10492
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

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

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

	int cnt = 0;

	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int T;
		scanf("%d", &T);

		int left = 0;
		int right = n;
		int mid = (left + right) / 2;

		while (left < right) {
			if (T == S[mid]) {
				cnt++;
				break;
			} else if (T < S[mid]) {
				right = mid;
			} else {
				left = mid + 1;
			}
			mid = (left + right) / 2;
		}

	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3456
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 
int dp[3001][3001];
pair<int,int> dp2[3001][3001];

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    for(int i=0;i<3001;++i)
    {
      for(int j=0;j<3001;++j)
      {
        dp2[i][j] = MP(-1, -1);
      }
    }
    for(int i=0;i<s.length();++i)
    {
      for(int j=0;j<t.length();++j)
      {
        if(s[i] == t[j])
        {
          if(dp[i+1][j+1] < dp[i][j] + 1)
          {
            dp[i+1][j+1] = dp[i][j] + 1;
            dp2[i+1][j+1] = MP(i, j);
          }
        }else{
          if(dp[i+1][j+1] < dp[i+1][j])
          {
            dp[i+1][j+1] = dp[i+1][j];
            dp2[i+1][j+1] = MP(i+1,j);
          }

          if(dp[i+1][j+1] < dp[i][j+1])
          {
            dp[i+1][j+1] = dp[i][j+1];
            dp2[i+1][j+1] = MP(i,j+1);
          }
        }
      }
    }
    int ii = s.length();
    int jj = t.length();
    vector<char> vec;
    while(true)
    {
      pair<int,int> cur = dp2[ii][jj];
      if(cur.first == -1 || cur.second == -1){
        break;
      }

      if(dp[ii][jj] != dp[cur.first][cur.second])
      {
        vec.push_back(s[ii-1]);
      }
      ii = cur.first;
      jj = cur.second;
    }

    for(auto it = vec.rbegin(); it != vec.rend(); ++it)
    {
      cout << *it;
    }
    cout << endl;
}

Measured memory_bytes: 105856
import sys


def s():
    n, k = map(int, input().split())
    w = list(map(int, sys.stdin.readlines()))

    def f():
        c = t = 0
        for j in w:
            t += j
            if t > m:
                t = j
                c += 1
                if c >= k:
                    return 0
        return 1

    l, r = max(w), sum(w)
    while l < r:
        m = (l + r) // 2
        if f():
            r = m
        else:
            l = m + 1
    print(r)


if '__main__' == __name__:
    s()



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

int m,a,b;
int p[205];

int main(){
  while(1){
    cin>>m>>a>>b;
    if(m==0&&a==0&&b==0)break;
    for(int i=1;i<=m;i++){
      cin>>p[i];
    }
    int maxm=0,id;
    for(int i=a;i<=b;i++){
      if(maxm<=p[i]-p[i+1]){
        maxm=p[i]-p[i+1];
        id=i;
      }
    }
    cout<<id<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,x = map(int,input().split())
a=list(map(int,input().split()))
ans = 0
now = a[0]
if a[0] > x:
    ans += a[0]-x
    now = x
for i in range(1,N):
    if now +a[i] > x:
        ans,now = ans+(a[i]-x+now),x-now
    else:
        now = a[i]
print(ans)

Measured memory_bytes: 14052
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout); 
	int x,y;
	cin>>x>>y;
	if(y%2==0&&2*x<=y&&4*x>=y)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3628
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    G = [set() for i in range(N)]
    G2 = [set() for i in range(N*3)]
    for i in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        G[u].add(v)
    S, T = map(int, input().split())
    S -= 1
    T -= 1

    import collections
    q = collections.deque()
    q.append((S, 0))
    D = [-1]*N*3
    D[3*S] = 0
    while(q):
        x, d = q.popleft()
        for y in G[x]:
            if D[y*3+(d+1) % 3] < 0:
                # G2[x*3 + d].add(y)
                q.append((y, d+1))
                D[y*3 + (d+1) % 3] = d+1

    if D[T*3] > 0:
        print(D[T*3] // 3)

    else:
        print(-1)


main()


Measured memory_bytes: 116324
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
double dp[610],d2[610];
bool ng[610];
bool gr[610][610];
int n;
double inf=1e9;
double cal(){
	dp[n]=0;
	memset(ng,false,sizeof(ng));
	for(int i=n-1;i>0;i--){
		double sum=0.0;int s=0;
		REP(j,i+1,n+1){
			if(gr[i][j]){
				s++;sum+=dp[j];
				if(ng[j]) ng[i]=true;
			}
		}
		if(!ng[i]) dp[i]=1+sum/s;
	}
	if(ng[1]) return inf;
	return dp[1];
}
int main()
{
	int m,a,b;
	memset(gr,false,sizeof(gr));
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;gr[a][b]=true;
	}
	double out=cal();
	rep(i,n+5) d2[i]=dp[i];
	rep(i,n+1){
		int x=0;
		REP(j,i+1,n+1){
			if(gr[i][j] && dp[j]>dp[x]) x=j;
		}
		gr[i][x]=false;
		out=min(out,cal());
		gr[i][x]=true;
	}
	printf("%.12f\n",out);
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[]p = new int[n];

		for (int i=0; i<n; i++) {
			p[i] = sc.nextInt();
		}

		int cnt=0;
		for (int i=1; i<n-1; i++) {
			if (p[i-1] < p[i] && p[i] < p[i+1]){
				cnt++;
			} else if(p[i-1] > p[i] && p[i] > p[i+1]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}


}

Measured memory_bytes: 21460
#include<iostream>
#include<string>
using namespace std;
int main(){
  string b;
  cin >> b;
  int i,j,ans=0,count=0;
  size_t n = b.size();
  for(i=0;i<n;i++){
    count=0;
    if(b[i]=='A'||b[i]=='T'||b[i]=='C'||b[i]=='G'){
      count=count+1;
      ans=max(ans,count);
      for(j=i+1;j<n;j++){
	if(b[j]=='A'||b[j]=='T'||b[j]=='C'||b[j]=='G'){
	  count=count+1;
	  ans=max(ans,count);
	}else{
	  break;
	}
      }
    }    
  }
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
n, c_max = map(int, input().split())
D = []
for _ in range(c_max):
    d = list(map(int, input().split()))
    D.append(d)
C = []
for _ in range(n):
    c = list(map(int, input().split()))
    C.append(c)

Res = [[] for _ in range(3)]
\
for i in range(n):
    for j in range(n):
        now = C[i][j]
        if (i+j) % 3 == 0:
            Res[0].append(now)
        elif (i+j) % 3 == 1:
            Res[1].append(now)
        else:
            Res[2].append(now)

Res_cost = [[0 for _ in range(c_max)] for _ in range(3)]

for i in range(3):    
    for color in range(c_max):
        cost = 0
        for now in Res[i]:
            cost += D[now-1][color-1]
        Res_cost[i][color-1] = cost

ans = 10**10
for i in range(c_max):
    for j in range(c_max):
        for k in range(c_max):
            if i == j or j == k or k == i:
                continue
            cost = Res_cost[0][i] + Res_cost[1][j] + Res_cost[2][k]
            ans = min(cost, ans)
# print(Res_cost)
# print(Res)
print(ans)   

Measured memory_bytes: 8516
from queue import Queue
import itertools
def solve():

    H, W = map(int, input().split())
    S = []
    for i in range(H):
        tmp = list(input())
        S.append(tmp)
    
    dw = (1,0,-1,0)
    dh = (0,1,0,-1)

    comb = itertools.permutations(tuple(range(20)), 2)
    mx = 0

    for c in comb:
        
        startH = c[0]
        startW = c[1]
        if startH >= H or startW >= W or S[startH][startW] == '#':
            continue

        q = Queue()
        cur = P(startH, startW)
        q.put(cur)

        time = [[float('inf')] * W for i in range(H)]
        time[startH][startW] = 0

        while not q.empty():
            p = q.get()
            
            for i in range(4):
                nh = p.H + dh[i]
                nw = p.W + dw[i] 
                if 0 <= nh and nh < H and 0 <= nw and nw < W and time[nh][nw] == float('inf') and S[nh][nw] != '#':
                    q.put(P(nh, nw))
                    time[nh][nw] = time[p.H][p.W] + 1
        
        flatten = list(itertools.chain.from_iterable(time))
        for i in range(len(flatten)):
            if flatten[i] == float('inf'):
                flatten[i] = -1 

        localmx = max(flatten)
        mx = max(localmx, mx)


    print(mx)

class P():
    def __init__(self, H, W):
        self.H = H
        self.W = W

if __name__ == '__main__':
    solve()


Measured memory_bytes: 66004
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int d=n%10;
	if(d==3) {
		cout<<"bon"<<endl;
	}
	else if(d==0 or d==1 or d==6 or d==8) {
		cout<<"pon"<<endl;
	}
	else{
		cout<<"hon"<<endl;
	}



	return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		String s=in.next();
		
		if(s.compareTo("SAT")==0) {
			System.out.println(1);
		}
		else if(s.compareTo("SUN")==0) {
			System.out.println(7);
		}
		else if(s.compareTo("MON")==0) {
			System.out.println(6);
		}
		else if(s.compareTo("TUE")==0) {
			System.out.println(5);
		}
		else if(s.compareTo("WED")==0) {
			System.out.println(4);
		}
		else if(s.compareTo("THU")==0) {
			System.out.println(3);
		}
		else  {
			System.out.println(2);
		}
	}

}


Measured memory_bytes: 26988
#include <stdio.h>

int main(void) {
  long long i, n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  if(2 * n > m) printf("%lld", m / 2);
  else printf("%lld", n + (m - 2 * n) / 4);
  return 0;
}

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

int main() {
  int vertical, side;
  
  vector<string> picture(vertical);
  
  cin >> vertical >> side;
  
  for(int i = 0; i < vertical; i++) {
    cin >> picture.at(i);
  }
  
  for(int i = 0; i < side + 2; i++){
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < vertical; i++){
    cout << "#" << picture.at(i) << "#" << endl;
  }
  
   for(int i = 0; i < side + 2; i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 33532
import java.util.*;
import java.io.*;
public class Main {
    void solve(BufferedReader in) throws Exception {
        String ss = in.readLine();
        int n = ss.length();
        int[] s = new int[n];
        for(int i = 0; i<n; i++) s[i] = ss.charAt(i) - 'a';
        int[][] dp = new int[26][n];
        dp[s[0]][0] = 1;
        for(int i = 1; i<n; i++) {
            for(int c = 0; c<26; c++) dp[c][i] = dp[c][i-1];
            dp[s[i]][i]++;
        }
        int[] sum = new int[26];
        for(int i = 0; i<26; i++) sum[i] = dp[i][n-1];
        long f = 0;
        for(int i = 0; i<n; i++) {
            f += sum[s[i]] - dp[s[i]][i] + 1;
        }
        System.out.println(n*(n+1L)/2 + 1 - f);
    }
    int toInt(String s) {return Integer.parseInt(s);}
    int[] toInts(String s) {
        String[] a = s.split(" ");
        int[] o = new int[a.length];
        for(int i = 0; i<a.length; i++) o[i] = toInt(a[i]);
        return o;
    }
    void e(Object o) {
        System.err.println(o);
    }
    public static void main(String[] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        (new Main()).solve(in);
    }
}


Measured memory_bytes: 52200
#include<bits/stdc++.h>
using namespace std;
string s,t;
int dp[3004][3002];

int rec(int sP, int tP) {
	if(sP==s.size() || tP==t.size()) {
		return 0;
	}
	if(dp[sP][tP] != -1) {
		return dp[sP][tP];
	}
	int ans = -1;
	if(s[sP] == t[tP]) {
		ans = 1 + rec(sP+1, tP+1);
	}
	ans = max(ans, rec(sP+1, tP+1));
	ans = max(ans, rec(sP+1, tP));
	ans = max(ans, rec(sP, tP+1));
	dp[sP][tP]=ans;
	return ans;
}

int main() {
	memset(dp, -1, sizeof(dp));
	cin>>s;
	cin>>t;
	rec(0, 0);
	int cnt = dp[0][0];
	for(int i=0; i<s.size() && cnt; ++i) {
		for(int j=0;j<t.size();++j) {
			if(dp[i][j] == cnt && s[i] == t[j]) {
				printf("%c", s[i]);
				--cnt;
				break;
			}
		}
	}
	return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {FIN;
   
    int n;cin>>n;
    int mat[n][3];
    ll dp[n][3]; fill(dp,0);
    fore(i,0,n){
        fore(j,0,3){
            cin>>mat[i][j];
        }
    }
    dp[0][0] = mat[0][0];
    dp[0][1] = mat[0][1];
    dp[0][2] = mat[0][2];
    fore(i,0,n-1){
        fore(j,0,3){
            fore(k,0,3){
                if(j!=k)
                    dp[i+1][k] = max(dp[i+1][k],dp[i][j]+mat[i+1][k]);
            }
        }
    }
    cout<<max3(dp[n-1][0],dp[n-1][1],dp[n-1][2]);
    return 0;
}




Measured memory_bytes: 3840
<?php 
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s %s", $s, $t);

$sarr = str_split($s);
$tarr = str_split($t);

$str = "";

for ($i=0; $i < $n; $i++) {
  $str .= $sarr[$i];
  $str .= $tarr[$i];
}

echo $str;

 ?>

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


int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) {
    cout << s;
  } else {
    s = s.erase(k);
    cout << s;
    cout << "...";
}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C, X, i, j, k, p = 0, ans;
  cin >> A >> B >> C >> X;
  for(i = 0;i <= A;i++)
  {
      for(j = 0;j <= B;j++)
      {
          for(k = 0;k <= C;k++)
          {
              ans = 500*i + 100*j + 50*k; 
              if(ans == X)
              {
                  p++;
              }
          }
      }
  }
  cout << p <<"\n";
  return 0;
}

Measured memory_bytes: 256
#n=input()
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import math
#li=list(map(int,input().split()))

n=int(input())
if n%2==0:
    ans=int((n**2)/2)-n
    print(ans)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i+j!=n+1:
                print(i,j)

else:
    ans=int(((n-1)**2)/2)
    print(ans)
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if i+j!=n:
                print(i,j)


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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

ll change(ll x,ll y){
    if(x == y)
        return 0;
    else if (x < abs(x - y))
        return x;
    else if(x > abs(x-y))
         return change(min(abs(x-y),x % y),y);
}

int main(void){

    ll n, k;
    cin >> n >> k;
   
    cout << change(n, k) << endl;

    return 0;
}


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

int main()
{
    int num;
    int cards[4][13];
    cin >> num;
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++)
            cards[i][j] = 0;
    }
    char al;
    int c;
    for(int b=0; b<num; b++){
        cin >> al >> c;
        if(al == 'S')
            cards[0][c-1] = 1;
        else if(al == 'H')
            cards[1][c-1] = 1;
        else if(al == 'C')
            cards[2][c-1] = 1;
        else if(al == 'D')
            cards[3][c-1] = 1;
    }
    for(int d=0; d<4; d++){
        for(int e=0; e<13; e++){
            if(cards[d][e] == 0){
                if(d==0)
                    cout << 'S' << ' ' << e+1 << endl;
                else if(d==1)
                    cout << 'H' << ' ' << e+1 << endl;
                else if(d==2)
                    cout << 'C' << ' ' << e+1 << endl;
                else if(d==3)
                    cout << 'D' << ' ' << e+1 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3088
# frozen_string_literal: true

# https://github.com/universato/ac-library-rb/blob/master/src/segtree.rb
# Segment Tree
class Segtree
  def initialize(arg, e, &block)
    case arg
    when Integer
      v = Array.new(arg) { e }
    when Array
      v = arg
    end

    @e  = e
    @op = block

    @n = v.size
    @log = @n.bit_length
    @leaf_size = 1 << @log
    @d = Array.new(@leaf_size * 2) { e }
    v.each_with_index { |v_i, i| @d[@leaf_size + i] = v_i }
    (@leaf_size - 1).downto(1) { |i| update(i) }
  end

  def set(q, x)
    q += @leaf_size
    @d[q] = x
    1.upto(@log) { |i| update(q >> i) }
  end

  def get(pos)
    @d[@leaf_size + pos]
  end

  def prod(l, r)
    sml = @e
    smr = @e
    l += @leaf_size
    r += @leaf_size

    while l < r
      if l[0] == 1
        sml = @op.call(sml, @d[l])
        l += 1
      end
      if r[0] == 1
        r -= 1
        smr = @op.call(@d[r], smr)
      end
      l /= 2
      r /= 2
    end

    @op.call(sml, smr)
  end

  def all_prod
    d[1]
  end

  def max_right(l, &block)
    return @n if l == @n

    f = proc(&block)

    l += @leaf_size
    sm = @e
    loop do
      l /= 2 while l.even?
      unless f.call(@op.call(sm, @d[l]))
        while l < @leaf_size
          l *= 2
          if f.call(@op.call(sm, @d[l]))
            sm = @op.call(sm, @d[l])
            l += 1
          end
        end
        return l - @leaf_size
      end
      sm = @op.call(sm, @d[l])
      l += 1
      break if (l & -l) == l
    end

    @n
  end

  def update(k)
    @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])
  end

  def inspect
    t = 0
    res = "SegmentTree\n  "
    a = @d[1, @d.size - 1]
    a.each_with_index do |e, i|
      res << e.to_s << ' '
      if t == i && i < @leaf_size
        res << "\n  "
        t = t * 2 + 2
      end
    end
    res
  end
end

SegTree     = Segtree
SegmentTree = Segtree

INF = (1 << 60) - 1
_, q = gets.to_s.split.map{ |t| t.to_i }
a    = gets.to_s.split.map{ |t| t.to_i }
st = Segtree.new(a, -INF) { [_1, _2].max }
ans = []
q.times do
  query = gets.to_s.split.map{ |t| t.to_i }
  if query[0] == 1
    _, x, v = query
    st.set(x - 1, v)
  elsif query[0] == 2
    _, l, r = query
    ans << st.prod(l - 1, r)
  else
    _, x, v = query
    ans << st.max_right(x - 1) { _1 < v } + 1
  end
end
puts ans


Measured memory_bytes: 40020
#include <bits/stdc++.h>
//#include "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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = max(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v(n);
	rep(i, m) {
		int a;
		cin >> a;
		rep(_, a) {
			int s;
			cin >> s;
			s--;
			v[s].push_back(i);
		}
	}
	vector<int> p(m);
	rep(i, m) cin >> p[i];
	int ans = 0;
	for (int b = 0; b < (1 << n); b++) {
		bitset<10> s(b);
		vector<int> l(m);
		rep(i, n) {
			if (s.test(i)) {
				for (int light : v[i])
					l[light]++;
			}
		}
		bool ok = true;
		rep(i, m) {
			if (l[i] % 2 != p[i])
				ok = false;
		}
		if (ok) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if((a+d-1)/d>=(c+b-1)/b) cout<<"Yes";
	else cout<<"No";
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const int MAX = 1000000;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

long long inverse[MAX+1];
long long factorial[MAX+1];
long long factorial_inverse[MAX+1];

void calc(int n) {
	inverse[1] = 1;
	factorial[0] = factorial[1] = 1;
	factorial_inverse[0] = factorial_inverse[1] = 1;
	for (int i = 2; i <= n; i++) {
		inverse[i] = MOD - inverse[MOD%i] * (MOD/i) % MOD;
		factorial[i] = i * factorial[i-1] % MOD;
		factorial_inverse[i] = inverse[i] * factorial_inverse[i-1] % MOD;
	}
}

long long comb(long long n, long long k) {
	return factorial[n] * (factorial_inverse[k] * factorial_inverse[n-k] % MOD) % MOD;
}

int main() {
	int x, y;
	cin >> x >> y;
	if ((x+y)%3 != 0 || y > 2*x || 2*y < x) {
		cout << 0 << endl;
		return 0;
	}
	int n = (x+y) / 3;
	int cx = x - n;
	calc(n);
	long long ans = comb(n, cx);
	cout << ans << endl;
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        Pair[] p = new Pair[n];
        for(int i = 0; i < n; i++){
            int x = Integer.parseInt(sc.next());
            int l = Integer.parseInt(sc.next());
            p[i] = new Pair(x-l, x+l);
        }
        
        Arrays.sort(p);
        int ans = 0;
        int right = Integer.MIN_VALUE;
        for(int i = 0; i < n; i++){
            if(p[i].left < right) continue;
            ans++;
            right = p[i].right;
        }
        
        System.out.println(ans);
    }
    
    static class Pair implements Comparable<Pair>{
        int left;
        int right;
        
        public Pair(int left, int right) {
            this.left = left;
            this.right = right;
        }
        
        @Override
        public int compareTo(Pair s) {
            
            if(this.right > s.right){
                return 1;
            }else{
                return -1;
            }
        }
    }
}

Measured memory_bytes: 62700
#include <iostream>
#include <string>
#include <cstdlib>
#include <list>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){

	int n,i,j,v,c;
	cin >> n;
	int a[n];

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

	for(i=0;i<n;i++){
		if(i!=n-1) cout << a[i] << " ";
		else cout << a[i] << endl;
	}

	for(i=1;i<n;i++){
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
			a[j+1]=v;
		}

		for(j=0;j<n;j++){
			if(j!=n-1) cout << a[j] << " ";
			else cout << a[j] << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 3096
#include<stdio.h>
#include<string.h>

char al[]="abcdefghijklmnopqrstuvwxyz";

int al_num(char a){
	int i;
	for(i=0;i<26;i++){
		if(al[i]==a){
			return i+1;
		}
	}
	return 0;
}

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

int main(){
	int i,j,num,taroumaru=0,hanako=0;
	char input[256],word_1[128],word_2[128],*p;
	
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&num);
	
	
	
	for(i=0;i<num;i++){
		fgets(input,sizeof input,stdin);
		p=strtok(input," ");
		sprintf(word_1,"%s",p);
		p=strtok(NULL," ");
		sprintf(word_2,"%s",p);
		
		
		//word_1[strlen(word_1)-1]='\0';
		word_2[strlen(word_2)-1]='\0';
		
		
		for(j=0;j<min(strlen(word_1),strlen(word_2));j++){
			if(al_num(word_1[j])>al_num(word_2[j])){
				taroumaru+=3;
				break;
			}else if(al_num(word_1[j])<al_num(word_2[j])){
				hanako+=3;
				break;
			}
			
			if(j==min(strlen(word_1),strlen(word_2))-1){
				if(strcmp(word_1,word_2)==0){
					taroumaru++;
					hanako++;
				}else{
					if(strlen(word_1)>strlen(word_2)){
						taroumaru+=3;
					}else{
						hanako+=3;
					}
				}
			}
			
		}
		
	}
	printf("%d %d\n",taroumaru,hanako);
	
	return 0;
}

Measured memory_bytes: 2740
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
p = [int(i) for i in input().split()]

ans = 0
f = False
for i in range(N):
    # print(p)
    if i+1==p[i]:
        if i == N-1:
            ans += 1
        else:
            p[i],p[i+1] = p[i+1],p[i]
            ans += 1


print(ans)


Measured memory_bytes: 23532
<?php
 
$NM = explode(" ", trim(fgets(STDIN))); 
$A = explode(" ", trim(fgets(STDIN)));
sort($A);
 
$total = 0;
foreach ($A as $a) {
  $total += $a;
}
 
if ($A[$NM[0]-$NM[1]] >= $total / 4 / $NM[1]) {
  echo "Yes";
} else {
  echo "No";
}
  
?>

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

int main() {
    int AsPoint, BsPoint, AsCard, BsCard;
    int key;
    while(true){
        cin >> key;
        AsPoint = BsPoint = 0;
        if(key == 0) return 0;
        while(key != 0) {
            cin >> AsCard;
            cin >> BsCard;
            if(AsCard == BsCard) {
                AsPoint += AsCard;
                BsPoint += BsCard;
            } else {
                AsPoint += (AsCard > BsCard) ? AsCard + BsCard : 0;
                BsPoint += (BsCard > AsCard) ? AsCard + BsCard : 0;
            }
            --key;
        }
        cout << AsPoint << " " << BsPoint << endl;
    }
}

Measured memory_bytes: 2976
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 2e9;

void init() {

}

int n,k,a[N],ans;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;

    ans = OO;

    for(int i=0;i<n;++i) {

        cin >> a[i];

    }

    sort(a,a+n);

    for(int i=0;i<n-k+1;++i) {

        ans = min(ans,a[i+k-1]-a[i]);

    }

    cout << ans << '\n';

    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl ("\n")
using namespace std;

#define deb(x) cout << (#x) << " -> " << (x) << endl;
#define mod (1000000007)

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n;
    cin >> n;
   	long long arr[n];
    for(int i = 0;i < n;i++)
    {
        cin >> arr[i];
    }
    long long m[n];
    m[n-1] = arr[n-1];
    for(int i = 0;i < n - 1;i++)
    {
        if(i%2 == 0)
        {
            m[n-1] -= arr[i];
        }
        else
        {
            m[n-1] += arr[i];
        }
    }
    for(int i = 0;i < n-1;i++)
    {
        m[i] = arr[(i - 1 + n)%n] - m[(i - 1 + n)%n]/2;
        m[i] *= 2;
    }
    for(int i = 0;i < n;i++)
        cout << m[i] << " ";
    return 0;
}

Measured memory_bytes: 2944
E = ["S","H","C","D"]
n=int(input())
c = [[0 for i in range(14)] for j in range(4)]
for i in range(n):
	a,b=input().split()
	a=E.index(a)
	b=int(b)
	c[a][b]=1
	
for z in range(4):
	for f in range(1,14):
		if c[z][f]==0:
			print(f"{E[z]} {f}")


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

#define x first
#define y second

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  ll c;
  cin >> n >> c;
  deque<pair<ll,ll>> deq;
  auto crossing = [&](pair<ll,ll> a, pair<ll,ll> b) {
    return -(a.y-b.y)*1./(a.x-b.x);
  };
  auto query = [&](ll x) {
    while (deq.size() > 1 && deq[1].x*x+deq[1].y <= deq[0].x*x+deq[0].y) deq.pop_front();
    return deq[0].x*x+deq[0].y;
  };
  auto insert = [&](ll x, ll y) {
    pair<ll,ll> n(x,y);
    while (deq.size() > 1) {
      auto a = deq[deq.size()-2], b = deq.back();
      if (crossing(a,n) <= crossing(a,b)) deq.pop_back();
      else break;
    }
    deq.push_back(n);
  };
  for (int i = 0; i < n; i++) {
    ll h;
    cin >> h;
    ll v = i ? query(h)+c+h*h : 0;
    if (i == n-1) {
      cout << v << endl;
      return 0;
    }
    insert(-2*h, v+h*h);
  }
}


Measured memory_bytes: 2560
#include<stdio.h>


int main(){
  char s[110];
  long long int k,n,p,a;
  int i;
  scanf("%s",s);
  scanf("%lld",&k);
  n=strlen(s);
  i=0;
  while(s[i]=='1'&&i<k-1)
    i++;
  printf("%c\n",s[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;
int n;
ll a[MAXN], pos[MAXN], ans;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = n; i >= 1; i--) pos[i] = (pos[i + 1] + a[i]) % MOD;
    for (int i = 1; i <= n - 1; i++) ans += a[i] * pos[i + 1] % MOD, ans %= MOD;
    cout << ans;
    return 0;
}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    if (n != 1 && a == 1 && b == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (num.at(a-1) == -1) {
      num.at(a-1) = b;
    } else if (num.at(a-1) != b) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i=0; i<n; i++) {
  	if (num.at(i) != -1) {
      cout << num.at(i);
    } else if (i == 0) {
      if (n == 1) cout << 0;
      else cout << 1;
    } else {
      cout << 0;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy
# sys.setrecursionlimit(1000000)

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b, c, k = map(int, input().split())

    su = a + b + c
    a += su * (k // 2)
    b += su * (k // 2)
    c += su * (k // 2)

    if k % 2 == 1:
        an = b + c
        bn = c + a
        cn = a + b
        a, b, c = an, bn, cn

    print(a - b if abs(a - b) <= 10 ** 18 else "Unfair")

main()


Measured memory_bytes: 3572
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    long MOD = 924844033L;

    long[] pns;
    int n, k;

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); k = sc.nextInt();
        int len = 2 * (n - k);
        long[][][] dp = new long[2][len + 1][2];

        long[] ss = new long[2000];
        int idx = 0;

        for (int i = 1; i <= k; i++) {
            int size = 0;
            for (int j = i; j <= n; j += k) size++;
            if (size == 1) continue;
            ss[idx++] = size - 1;
            ss[idx++] = size - 1;
        }

        calc();

        for (int i = 0; i <= len; i++) dp[0][i][0] = 1;

        int x = 1;

        long ans = pns[n];

        for (int i = 1; i <= n; i++) {
            int l = 1;
            for (int j = 0; ss[j] != 0; j++) {
                dp[x][l][0] = (dp[x][l - 1][0] + dp[x][l - 1][1]) % MOD;
                dp[x][l][1] = (dp[1 - x][l - 1][0] + dp[1 - x][l - 1][1]) % MOD;
                for (int k = 1; k < ss[j]; k++) {
                    dp[x][l + k][0] = (dp[x][l + k - 1][0] + dp[x][l + k - 1][1]) % MOD;
                    dp[x][l + k][1] = (dp[1 - x][l + k - 1][0]) % MOD;
                }
                l += ss[j];
            }
            long f = i % 2 == 0 ? 1 : -1;
            long sum = (dp[x][len][0] + dp[x][len][1]) % MOD;
            sum = (sum * pns[n - i]) % MOD;
            ans = (ans + MOD + f * sum) % MOD;
            x = 1 - x;
            dp[x][0][0] = dp[x][0][1] = dp[1 - x][0][0] = dp[1 - x][0][1] = 0;
        }

        System.out.println(ans);
    }

    void calc() {
        pns = new long[n + 1];
        pns[0] = 1;
        for (int i = 1; i <= n; i++) {
            pns[i] = (pns[i - 1] * i) % MOD;
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23296
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        int hai = 0;
        int cha = 0;
        int midori = 0;
        int mizu = 0;
        int ao = 0;
        int ki = 0;
        int daidai = 0;
        int aka = 0;
        int free = 0;
        
        for(int i = 0; i < N; i++){
          int a = sc.nextInt();
          if(a >= 1 && a <= 399 && hai == 0){
            hai++;
          }else if(a >= 400 && a <= 799 && cha == 0){
            cha++;
          }else if(a >= 800 && a <= 1199 && midori == 0){
            midori++;
          }else if(a >= 1200 && a <= 1599 && mizu == 0){
            mizu++;
          }else if(a >= 1600 && a <= 1999 && ao == 0){
            ao++;
          }else if(a >= 2000 && a <= 2399 && ki == 0){
            ki++;
          }else if(a >= 2400 && a <= 2799 && daidai == 0){
            daidai++;
          }else if(a >= 2800 && a <= 3199 && aka == 0){
            aka++;
          }else if(a >= 3200){
            free++;
          }  
        }
         
         int Min = hai + cha + midori + mizu + ao + ki + daidai + aka;
         int Max = 0;
         if(Min != 0){
           Max = Min + free;
         }else{
           Min = 1;
           Max = N;
         }
          System.out.println(Min + " " + Max);
        
	}
}

Measured memory_bytes: 38804
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double t, x;
    cin >> t >> x;

    long double ans = t / x;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
int n,k;
int a[200100];
map<int,int>mapp;
priority_queue<int, vector<int>, greater<int> > P;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);read(k);
	for(int i=1;i<=n;i++)read(a[i]),mapp[a[i]]++;
	map<int,int>::iterator it=mapp.begin();
	for(;it!=mapp.end();it++)
		P.push(it->second);
	long long ans = 0;
	while ((int)P.size() > k)
		ans += P.top(), P.pop();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11516
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

#define MAX 100007
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void fact() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓


int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll N;
    cin >> N;
    vector<ll> a(N+1,0);
    for(ll i=0;i<N+1;i++)cin>>a[i];
    ll A=INF,B=INF;
    Map M;
    for(ll i=0;i<N+1;i++)M[a[i]]++;
    ll mark;
    for(auto p: M)if(p.second==2){mark=p.first;}
    for(ll i=0;i<N+1;i++){
        if(a[i]==mark&&A==INF)A=i;
        else if(a[i]==mark)B=i;
    }
    print(N)
    for(ll i=2;i<=N+1;i++){
        ll ans=0;
        ans+=comb(N-1,i);
        ans+=comb(N-1,i-2);
        ans-=comb(N+A-B,i-1);
        ans+=comb(N-1,i-1)*2;
        print((ans+MOD)%MOD)
    }

    return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n, k;
	while(cin >> n >> k, n || k)
	{
		int max = 0;
		int sum = 0;
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		for(int i = 0; i < k; ++i)
		{
			sum += Vec[i];
		}
		if(max < sum)
		{
			max = sum;
		}
		for(int i = 1; i + k - 1 < n; ++i)
		{
			sum -= Vec[i - 1];
			sum += Vec[i + k - 1];
			if(max < sum)
			{
				max = sum;
			}	
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1532
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-11;
const double pi = acos(-1.0); 
using namespace std;
#define ma = 2147483647;
#define mi = -2147483647;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	string s; int k;
	cin >> k >> s;
	int len = s.length();
	string ans;
	if (len <= k)
		ans = s;
	if (len > k)
	{
		for (int i = 0; i < k; i++)
		{
			ans += s[i];
		}
		ans += "...";
	}

	cout << ans;



	return 0;
}

Measured memory_bytes: 3612