akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  if((a==2&&b==3)||(a==3&&b==2)) cout <<1<<endl;
  else if((a==1&&b==3)||(a==3&&b==1)) cout <<2<<endl;
  else cout << 3 << endl;
  return 0;
}

Measured memory_bytes: 256
import collections
cc = collections.Counter()
for _ in range(int(raw_input())): 
	s = raw_input()
	cc[s[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s):
		if k == 0:
			total[0] += cumul
		return 

	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print total[0]

Measured memory_bytes: 78812
class UnionFind():
    def __init__(self,n):
        # リンク情報　子→親の番号　親(根)→負のサイズ
        self.d=[-1 for i in range(n)]
    
    def find(self,x):
        if(self.d[x]<0):return x
        self.d[x]=self.find(self.d[x])
        return self.d[x]
 
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if(x==y):return False
        if(self.d[x]>self.d[y]):x,y=y,x
        self.d[x]+=self.d[y]
        self.d[y]=x
        return True
 
    def same(self,x,y):return self.find(x)==self.find(y)
    def size(self,x):return -1*self.d[self.find(x)]
n,m,k=map(int,input().split())
uf=UnionFind(n)
deg=[0 for i in range(n)]
to=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    uf.unite(a,b)
    deg[a]+=1
    deg[b]+=1
for i in range(k):
    a,b=map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
for i in range(n):
    ans=uf.size(i)-1-deg[i]
    for j in to[i]:
        if(uf.same(i,j)):ans-=1
    print(ans,end=" ")

Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int char_to_int(char c){
  switch(c){
    case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
  }
}


int main(){
  int N;
  cin >> N;
  
  vector <int> v(N);
  rep(i,N) cin >> v.at(i);
  
  sort(v.begin(), v.end(),greater<int>());
  long double res = v.at(N-1)/pow(2, N);
  
  for(int i=N-1; i>=0; i--){
    res+= v.at(i)/pow(2, i+1);
  }
  
  cout << res;

}

Measured memory_bytes: 256
from fractions import gcd

def prime_factor(n):
    factors = set()
    i = 2
    while i * i <= n:
        while n % i == 0:
            factors.add(i)
            n //= i
        i += 1
    if n != 1:
        factors.add(n)
    return factors

A, B = map(int, input().split())
print(len(prime_factor(gcd(A, B))) + 1)

Measured memory_bytes: 64108
#include<cstdio>
int main(){
	int N;scanf("%d",&N);
	int mx=0,mxc,mn=N,mnc;
	for(int i=0,a;i<N;i++){
		scanf("%d",&a);
		a>mx?mx=a,mxc=1:a==mx?mxc++:1;
		a<mn?mn=a,mnc=1:a==mn?mnc++:1;
	}
	puts(mx==mn&&(mx==N-1||mx<=N/2)||mx==mn+1&&mx-mnc>0&&mx-mnc<=mxc/2?"Yes":"No");
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int H,W;
	scanf("%d %d", &H, &W);
	char input[H+5][W+5];
	char output1[H+5][W+5];
	char output2[H+5][W+5];
	char output[H+5][W+5];
	for (int i = 0; i < H; ++i)
		scanf("%s",input[i]);
 
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if(i==H-1)
				output1[i][j]='.';
			else if (j%2==1 || input[i][j]=='#' || i==0)
				output1[i][j]='#';
			else 
				output1[i][j]='.';
		}
	}
 
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if(i==0)
				output2[i][j]='.';
			else if (j%2==0 || input[i][j]=='#' || i==H-1)
				output2[i][j]='#';
			else 
				output2[i][j]='.';
		}
	}
 
	printf("\n");
 
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
			printf("%c", output1[i][j]);
		printf("\n");
	}
	printf("\n");
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
			printf("%c", output2[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 1536
package main

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

const N = 1000000007

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	cntZeroZero := 0
	battles := make(map[PairInt][]int)

	for i := 0; i < n; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		ra, rb := Ratio(a, b)
		if ra == 0 && rb == 0 {
			cntZeroZero++
			continue
		}

		if rb <= 0 {
			ra, rb = ReverseRatio(ra, rb)
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][1]++
		} else {
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][0]++
		}
	}

	cnt := 1
	for _, battle := range battles {
		cntSub := Pow(2, uint(battle[0])) + Pow(2, uint(battle[1])) - 1
		cnt = cnt * cntSub % N
	}

	cnt = (cnt + cntZeroZero - 1) % N
	cnt = (cnt + N) % N

	fmt.Println(cnt)
}

type PairInt struct {
	A int
	B int
}

// util
// *   math/simple

func Ratio(x, y int) (int, int) {
	if x == 0 {
		if y == 0 {
			return 0, 0
		}
		return 0, 1
	} else if y == 0 {
		return 1, 0
	}

	sign := 1
	if x > 0 && y < 0 {
		sign = -1
	} else if x < 0 && y > 0 {
		sign = -1
	}

	x = Abs(x)
	y = Abs(y)
	var small, big int
	if x < y {
		small, big = x, y
	} else {
		small, big = y, x
	}
	gcd := GCD(small, big)
	return x / gcd, sign * y / gcd
}

func ReverseRatio(x, y int) (int, int) {
	sign := -1
	if x == 0 || y <= 0 {
		sign = 1
	}

	return Abs(y), sign * Abs(x)
}

func GCD(smaller, bigger int) int {
	rem := bigger % smaller
	if rem == 0 {
		return smaller
	}
	return GCD(rem, smaller)
}

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

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer = answer * base % N
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 31184
#include <bits/stdc++.h>
#define maxN 100002
#define inf 1000000001
using namespace std;

//FILE *fin = freopen("d.in", "r", stdin);

int n;
struct Point
{
    int x, y;
    bool operator < (const Point &ot) const
    {
        if (y == ot.y)
            return x < ot.x;
        return y < ot.y;
    }
}v[maxN];

struct Edge
{
    int x, y, c;
    bool operator < (const Edge &ot) const
    {
            return c < ot.c;
    }
}edges[maxN * 2];
vector < Point > X, Y;
int f[maxN], E;

int ans;
int root(int x)
{
    if (!f[x])
        return x;
    return f[x] = root(f[x]);
}
void MST()
{
    sort(edges + 1, edges + E + 1);
    for (int i = 1; i <= E; ++ i)
        {
            int rx = root(edges[i].x), ry = root(edges[i].y);
            if (rx != ry)
            {
                f[rx] = ry;
                ans += edges[i].c;
            }
        }

}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
        {
            scanf("%d %d", &v[i].x, &v[i].y);
            X.push_back({i, v[i].x});
            Y.push_back({i, v[i].y});
        }
        sort(X.begin(), X.end());
        sort(Y.begin(), Y.end());
        for (int i = 0; i < n - 1; ++ i)
        {
            edges[++ E] = {X[i].x, X[i + 1].x, X[i + 1].y - X[i].y};
            edges[++ E] = {Y[i].x, Y[i + 1].x, Y[i + 1].y - Y[i].y};
        }
        MST();
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 5612
#include<cstdio>

int n,a,gcd;

int Gcd(int a,int b) {
	if(b==0) return a;
	return Gcd(b,a%b);
}
int main() {
	scanf("%d",&n);
	scanf("%d",&gcd);
	for(int i=2;i<=n;i++) {
		scanf("%d",&a);
		gcd=Gcd(gcd,a);
	}
	printf("%d\n",gcd);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k, x; cin >> k >> x;
    if (500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2124
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = Tuple{Int,Int}[]
	k = 0
	for i in 1:n
		x,y = readline() |> split |> parseMap
		push!(a,(x,y))
		k -= y
	end
	a = sort(a,by=x->-x[1]-x[2])
	for i in 1:n
		if i%2==1
			k += a[i][1]+a[i][2]
		end
	end
	println(k)
end

main()

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int a[2005];

int main()
{
  ios::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll a = n / 500;
  ll b = (n % 500) / 5;

  ll ans = a * 1000 + b * 5;


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
package main

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

type process struct {
	name string
	time int
}

type queue struct {
	proc [100000]process
	head int
	tail int
}

func (q *queue) Enqueue(x process) {
	q.proc[q.tail] = x
	q.tail = (q.tail + 1) % len(q.proc)
}

func (q *queue) Dequeue() process {
	x := q.proc[q.head]
	q.head = (q.head + 1) % len(q.proc)
	return x
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	que := queue{}

	// fmt.Println(n, q)
	for i := 0; i < n; i++ {
		p := process{}
		sc.Scan()
		p.name = sc.Text()
		sc.Scan()
		p.time, _ = strconv.Atoi(sc.Text())
		// fmt.Println(p)
		que.Enqueue(p)
	}

	elasp := 0
	for {
		if que.head == que.tail {
			break
		}

		u := que.Dequeue()
		c := min(q, u.time)
		u.time -= c
		elasp += c
		if u.time > 0 {
			que.Enqueue(u)
		} else {
			fmt.Printf("%s %d\n", u.name, elasp)
		}

	}

}



Measured memory_bytes: 5276
#include<iostream>
using namespace std;
int main()
{
	int x;
	cin>>x;
	if(x<=599)
	{
		cout<<"8"<<endl;
	}
	if(x>=600&&x<=799)
	{
		cout<<"7"<<endl;
	}
	if(x>=800&&x<=999)
	{
		cout<<"6"<<endl;
	}
	if(x>=1000&&x<=1199)
	{
		cout<<"5"<<endl;
	}
	if(x>=1200&&x<=1399)
	{
		cout<<"4"<<endl;
	}
	if(x>=1400&&x<=1599)
	{
		cout<<"3"<<endl;
	}
	if(x>=1600&&x<=1799)
	{
		cout<<"2"<<endl;
	}
	if(x>=1800&&x<=1999)
	{
		cout<<"1"<<endl;
	}
	return 0;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> h(N);
  ll dif = INF;
  for(int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  for(int i = 0; i < N - K + 1; i++) {
    chmin(dif, h.at(i + K - 1) - h.at(i));
  }
  cout << dif << endl;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

class mod_int{
    private:
        ull num;
        static ull pow_mod(ull x,ull y){x%=mod;return y==0?1:y%2==0?pow_mod(x*x,y/2):x*pow_mod(x,y-1)%mod;}
    public:
        static ull mod;
        mod_int()=default;
        mod_int(ull num):num(num%mod){}
        explicit operator ull()             const{return num;}
        bool    operator==(const mod_int&mi)const{return num==mi.num;}
        bool    operator!=(const mod_int&mi)const{return !operator==(mi);}
        mod_int operator~ ()                const{return pow_mod(num,mod-2);}
        mod_int operator+ (const mod_int&mi)const{return num+mi.num;}
        mod_int operator- (const mod_int&mi)const{return num-mi.num+mod;}
        mod_int operator* (const mod_int&mi)const{return num*mi.num;}
        mod_int operator/ (const mod_int&mi)const{return num*(~mi).num;}
        mod_int&operator+=(const mod_int&mi)     {return*this=operator+(mi);}
        mod_int&operator-=(const mod_int&mi)     {return*this=operator-(mi);}
        mod_int&operator*=(const mod_int&mi)     {return*this=operator*(mi);}
        mod_int&operator/=(const mod_int&mi)     {return*this=operator/(mi);}
};
ull mod_int::mod=1000000007;
mod_int factorial_mod(ull n)
{
    mod_int ret=1;
    for(ull i=1;i<=n;++i){
        ret*=i;
    }
    return ret;
}
int main()
{
    ll x=in(),y=in();
    if((2*y-x)%3!=0||(2*x-y)%3!=0){
        cout<<0<<endl;
    }else{
        ll a=(2*y-x)/3,b=(2*x-y)/3;
        if(a<0||b<0){
            cout<<0<<endl;
            return 0;
        }
        cout<<(ull)(factorial_mod(a+b)*~(factorial_mod(a)*factorial_mod(b)))<<endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e933
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    ll k;
    cin>>n>>k;
    vector<pair<int,ll>> p(n);
    rep(i,0,n){
        cin>>p[i].fi>>p[i].se;
    }
    Sort(p);
    ll count=0;
    rep(i,0,n){
        count+=p[i].se;
        if(count>=k){
            cout<<p[i].fi<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    private static StringBuilder appendString(StringBuilder sb, String str, int cnt) {
        for (int i = 0; i < cnt; i++) {
            sb.append(str);
        }
        return sb;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        StringBuilder ans = new StringBuilder();
        ans = appendString(ans, "U", ty - sy);
        ans = appendString(ans, "R", tx - sx);
        ans = appendString(ans, "D", ty - sy);
        ans = appendString(ans, "L", tx - sx);
        ans.append("L");
        ans = appendString(ans, "U", ty - sy + 1);
        ans = appendString(ans, "R", tx - sx + 1);
        ans.append("D");
        ans.append("R");
        ans = appendString(ans, "D", ty - sy + 1);
        ans = appendString(ans, "L", tx - sx + 1);
        ans.append("U");
        System.out.println(ans.toString());
    }

}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
  static int cnt;
  static List<Integer> g;

  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int n = sc.nextInt();
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = sc.nextInt();
      }

      cnt = 0;
      shellSort(arr);

      StringBuilder sb = new StringBuilder();
      sb.append(g.size() + "\n");
      for (int i = g.size() - 1; i >= 0; i--) {
        sb.append(g.get(i));
        if (i != 0) sb.append(' ');
      }
      sb.append("\n" + cnt + "\n");
      for (int i = 0; i < n; i++) {
        sb.append(arr[i] + "\n");
      }
      System.out.println(sb.toString());
    }
  }

  static void shellSort(int[] arr) {
    // generate g g+1 = 3gn+1
    g = new ArrayList<>();
    for (int i = 1; i <= arr.length; i = 3 * i + 1) {
      g.add(i);
    }

    for (int i = g.size() - 1; i >= 0; i--) {
      insertionSort(arr, g.get(i));
    }
  }

  static void insertionSort(int[] arr, int g) {
    for (int i = g; i < arr.length; i++) {
      int tmp = arr[i];
      int j = i - g;

      while (j >= 0 && arr[j] > tmp) {
        arr[j + g] = arr[j];
        j -= g;
        cnt++;
      }
      arr[j + g] = tmp;
    }
  }
}



Measured memory_bytes: 300960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(In));
        }

        public void Solve(ConsoleInput input)
        {
            long k = input.ReadInt;
            long a = input.ReadInt;
            long b = input.ReadInt;

            long c = 1;
            
            if (c < a && k >= a - 1)
            {
                c += a - 1;
                k -= a - 1;
            }

            if (a + 1 < b)
            {
                c += (b - a) * (k / 2);
                k = k % 2;
            }

            c += k;

            WriteLine($"{c}");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            _separator = separator;
            _stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define maxn 2005
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
using namespace std;

int n,m,Q,s[maxn][maxn],s1[maxn][maxn],s2[maxn][maxn];
int cal(int a,int b,int c,int d,int s[maxn][maxn]){
	return s[c][d]-s[a-1][d]-s[c][b-1]+s[a-1][b-1];
}
char ch[maxn];

int main(){
	scanf("%d%d%d",&n,&m,&Q);
	rep(i,1,n){ scanf("%s",ch+1);rep(j,1,m){
		s[i][j] = ch[j]-'0';
		if(s[i][j] && s[i-1][j]) s1[i][j]++;
		if(s[i][j] && s[i][j-1]) s2[i][j]++;
	}}
	rep(i,1,n) rep(j,1,m) 
		s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1],
		s1[i][j] += s1[i-1][j] + s1[i][j-1] - s1[i-1][j-1],
		s2[i][j] += s2[i-1][j] + s2[i][j-1] - s2[i-1][j-1];
	for(int a,b,c,d;Q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",cal(a,b,c,d,s)-cal(a+1,b,c,d,s1)-cal(a,b+1,c,d,s2));
	}
}

Measured memory_bytes: 48896
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		long x = scan.nextLong();
		long count = (x/11)*2;
		if((x%11)==0){System.out.println(count);}
		else if((x%11)<=6){count++; System.out.println(count);}
			else{count+=2; System.out.println(count);}
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#define MAX 10000
#define NIL -1
 
typedef struct {int parent, left , right;} Node;
 
Node T[MAX];
int n,D[MAX], H[MAX];
 
void setDepth(int u , int d) {
  if ( u == NIL) return ;
  D[u]  = d;
  setDepth(T[u].left , d + 1);
  setDepth(T[u].right, d + 1);
 
}
 
int setHeight(int u)  {
  int h1 = 0, h2 = 0;
  if( T[u].left != NIL)
  h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
  h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}
 
int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
  return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
  return T[T[u].parent].right;
  return NIL;
}
 
void print(int u) {
  int i,c;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
    int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg );
  printf("depth = %d, ", D[u] );
  printf("height = %d, ", H[u] );
 
  if(T[u].parent == NIL) printf("root\n");
  else if (T[u].left == NIL && T[u].right == NIL) printf("leaf\n");
  else printf("internal node\n");
 
}
 
int main()  {
  int i,a,b,c,root = 0;
  scanf("%d\n",  &n);
 
  for(i = 0; i < n;i++) T[i].parent = NIL;
 
  for(i = 0 ; i < n ; i++) {
    scanf("%d %d %d \n", &a, &b , &c);
    T[a].left = b;
    T[a].right = c;
    if ( b!= NIL) T[b].parent = a;
    if ( c!= NIL) T[c].parent = a;
  }
 
  for(i = 0; i < n ;i++) if ( T[i].parent == NIL) root = i;
 
  setDepth(root , 0);
  setHeight(root);
 
  for ( i = 0; i  < n; i++) print(i);
 
  return 0;
}




 
 

Measured memory_bytes: 628
#include <iostream>
#include <complex>
#include <vector>

using namespace std;

typedef complex<double> P;

const double EPS = 1e-9;
const double PI = acos(-1);

inline double cross(const P &a, const P &b) {
    return a.real()*b.imag() - a.imag()*b.real();
}

inline int sgn(double a) {
    return a<0 ? -1 : 1;
}

void solve() {
    double x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xk >> yk >> xs >> ys;
    P a(x1, y1), b(x2, y2), c(x3, y3);
    P k(xk, yk), s(xs, ys);
    const int ca = sgn(cross(a-k, b-k)) + sgn(cross(b-k, c-k)) + sgn(cross(c-k, a-k));
    const int cb = sgn(cross(a-s, b-s)) + sgn(cross(b-s, c-s)) + sgn(cross(c-s, a-s));
    if((abs(ca) == 3 && abs(cb) != 3) || (abs(ca) != 3 && abs(cb) == 3)) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

    int N;
    cin >> N;
    while(N--) solve();
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

char s[10];

int main() {
    scanf("%s", s + 1);
    if (s[1] == 'S') puts("Cloudy");
    if (s[1] == 'C') puts("Rainy");
    if (s[1] == 'R') puts("Sunny");
    return 0;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=jp
#include <iostream>
using namespace std;

int isState(int x, int y){
    if(x > y) return 1;
    else{
      if(x == y) return 0;
      else return -1;
    }
}

int gcd(int x, int y){
  int state = isState(x, y);
  if(state == 0) return x;
  else{
    if(state == 1) return gcd(x-y,y);
    else return gcd(x,y-x);
  }
}


int main(){
  int x,y;
  cin >> x >> y;
  /*
  int gcd = 1;
  int n = min(x,y);

  for(int i = 1; i <= n; i++){
    if(x % i == 0 && y % i ==0){
      gcd = i;
    }
  }*/
  cout << gcd(x,y) << endl;
}

Measured memory_bytes: 1160
N=int(input())
D=[list(map(int,input().split())) for i in range(N)]

T=0
for i in range(0,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]:
    T+=1
  else:
    continue
    
if T!=0:
  print ('Yes')
else:
  print ('No')

Measured memory_bytes: 9192
#include<iostream>
#include<string>
#include<algorithm>
#define INF 500050
#define Max 1e9
using namespace std;
int r,l,c;
int n,k,ans=0;
string s;
char ch;
bool flag = false;
int main()
{
	cin>>n>>k;
	cin>>s;
	int t = 0;
	for(int i=0; i<s.length()&&k; i++) {
		if(s[i]=='L'&&s[i+1] == 'R') {
			int pi = i+1;
			while(s[pi]=='R'&&pi<s.length()) 
			{
				s[pi]='L';
				pi++;
			}
				k--;
		}
		if(s[i]=='R'&&s[i+1] == 'L') {
			int pi = i+1;
			while(s[pi]=='L'&&pi<s.length()) 
			{
				s[pi]='R';
				pi++;
			}
			k--;
		}
	}
	
	
	for(int i=1; i<s.length(); i++) {
		if(s[i] == s[i-1])	ans++;
	}

	ans=min(ans,n-1);
	cout << ans <<endl; 
	
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int ball[10];
bool dfs(int n,int l,int r){
	if(n == 10)
		return true;
	if(ball[n]>l&&dfs(n+1,ball[n],r))
		return true;
	if(ball[n]>r&&dfs(n+1,l,ball[n]))
		return true;
	return false;
}


int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++)
			cin >> ball[j];
		if(dfs(0,0,0))
			cout <<"YES"<<endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>
#define SIZE 1000000
int prime[SIZE];

int sosu ( int n ) {
	int i , lim = (int)(sqrt(n));
	for ( i = 2; i <= lim; i++ ) {
		if ( n % i == 0 ) return 0;
	}
	return 1;
}

void tmp(void) {
	int i;
	prime[0] = prime[1] = 0;
	for ( i = 2; i < SIZE; i++ ) {
		prime[i] = sosu(i);
	}
	return;
}

int main (void) {
	int n , i;
	tmp();
	
	while ( 1 ) {
		int sum = 0;
		scanf("%d",&n);
		if ( n == 0 ) break;
		for ( i = 2; n > 0; i++ ) {
			if ( prime[i] ) {
				sum += i;
				n--;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

int main()
{
    int difference,i;
    char c[1200];

    fgets(c,sizeof(c),stdin); // ??\??????????????????
    c[strlen(c)-1]='\0';  //str?????????????°?????????????'\0'??????????????????

    difference='a'-'A';
    for(i=0;i<strlen(c);i++){
      if('a'<=c[i] && c[i]<='z') c[i]-=difference;
      else if('A'<=c[i] && c[i]<='Z') c[i]+=difference;
    }
    printf("%s\n",c);
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
using namespace std;
int main() {
  int N, M, T, a, t = 0, ans = 0;
  cin >> N >> M >> T;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    if (!i) {
      if (a > M) ans += a - M;
      t = a;
    } else {
      if (t + 2*M < a) ans += a - t - 2*M;
      t = a;
    }
  }
  if (t + M < T) ans += T - t - M;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;


int main() {

    int d;
    cin >> d;

    int sum = 0;
    int m = 0;
    rep(i, d) {
        int p;
        cin >> p;
        m = max(m, p);
        sum += p;
    }
    sum -= (m / 2);
    cout << sum << endl;

}

Measured memory_bytes: 256
pattern = Array.new(51, 0)
num1 = num2 = num3 = num4 = 10
num1.times {|a| num2.times {|b| num3.times {|c| num4.times {|d| pattern[a+b+c+d] += 1}}}}

while sum = gets
  puts pattern[sum.to_i]
end

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

int main(){
    string s,t; cin>>s>>t;
    string u=s;
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<s.size(); j++){
            u.at((i+j)%s.size()) = s.at(j);
        }
        if(u==t){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
typedef unsigned long long ull;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
vector<vector<int> > AB,A,B;
int Aidx[5],Bidx[5];

set<ull> S;
ull VtoH(const vector<vector<int> > &v){
  const ull B = 1777771;
  ull res = 0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res = res * B + (v[i][j]+'0');
  return res;
}

vector<int> rev(vector<int> a){reverse(a.begin(),a.end());return a;}
void mirror(vector<vector<int> > &res){for(int i=0;i<5;i++) res[i] = rev(res[i]);}

vector<vector<int> > rot(const vector<vector<int> > &a){
  vector<vector<int> > res(5,vector<int>(5));
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res[i][j] = a[4-j][i];
  return res;
}

void insert(vector<vector<int> > &v){
  S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
  mirror(v), S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
}

bool canPut(int idx,int j){
  int a = 1, b = 1;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][i]) a = 0;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][4-i]) b = 0;
  return a || b;
}

bool can(){
  int used = 0;
  for(int i=0;i<5;i++){
    for(int nx=0;nx<5;nx++){
      if((used>>nx&1) || !canPut(nx,i)) continue;
      Bidx[i] = nx;
      used |= (1<<nx);
      break;
    }
  }
  return used == (1<<5)-1;
}

int solve(){
  S.clear();
  int res = 0;
  for(int i=0;i<5;i++) Aidx[i] = i;
  for(int bit=0;bit<(1<<10);bit++){
    if(__builtin_popcount(bit) != 5) continue;    
    A.clear();B.clear();
    for(int i=0;i<10;i++) (bit>>i&1)? A.push_back(AB[i]):B.push_back(AB[i]);
    vector<vector<int> > tmp = A;
    do{
      for(int a=0;a<(1<<5);a++){
        for(int i=0;i<5;i++) A[Aidx[i]] = (a>>i&1)? rev(tmp[i]):tmp[i];
        if(!can() || S.count(VtoH(A))) continue;
        insert(A);
        res++;
      }
    } while(next_permutation(Aidx,Aidx+5));
  }
  return res/2;
}

signed main(){
  while(1){
    AB.clear();
    for(int i=0;i<10;i++){
      string str;
      cin>>str;
      if(str == "END") return 0;
      vector<int> tmp(5);
      for(int j=0;j<5;j++) tmp[j] = str[j] - '0';
      AB.push_back(tmp);
    }
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,a[200010];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int now=0,j=1;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		while (j<=n && (now+a[j])==(now^a[j]))
		{
			now^=a[j];
			j++;
		}
		ans+=(j-i);
		now^=a[i];
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = INF;
  for(int i = 0; i <= 2*max(X, Y); i += 2){
    int a = max(0, X - i/2);
    int b = max(0, Y - i/2);
    ans = min(ans, a*A + b*B + C*i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

long long int dp[100001][4];
const long long int MOD = 1e9 + 7;

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

	string s;

	cin >> s;
	
	int n = s.length();
	
	dp[0][0] = 1;
	
	for (int i = 1; i <= n; i++)
	{
		if (s[i-1] == '?')
		{
			for (int j = 0; j <= 3; j++)
			{
				dp[i][j] = ((dp[i][j] % MOD) + ((3*dp[i - 1][j]) % MOD) % MOD);
				dp[i][j] %= MOD;
			}
			dp[i][1] = ((dp[i][1] % MOD) + (dp[i-1][0] % MOD)) % MOD;
			dp[i][1] %= MOD;
			dp[i][2] = ((dp[i][2] % MOD + (dp[i - 1][1]) % MOD) % MOD);
			dp[i][2] %= MOD;
			dp[i][3] = ((dp[i][3] % MOD) + (dp[i - 1][2] % MOD)) % MOD;
			dp[i][3] %= MOD;
		}
		else
		{
			for (int j = 0; j <= 3; j++)
			{
				dp[i][j] = ((dp[i][j] % MOD) + (dp[i - 1][j] % MOD) % MOD);
				dp[i][j] %= MOD;
			}
			if (s[i-1] == 'A')
			{
				dp[i][1] = ((dp[i][1] % MOD) + (dp[i-1][0] % MOD)) % MOD;
				dp[i][1] %= MOD;
			}
			else if (s[i-1] == 'B')
			{
				dp[i][2] = ((dp[i][2] % MOD) + (dp[i-1][1] % MOD)) % MOD;
				dp[i][2] %= MOD;
			}
			else
			{
				dp[i][3] = ((dp[i][3] % MOD) + (dp[i-1][2] % MOD)) % MOD;
				dp[i][3] %= MOD;
			}
		}
	}

	cout << dp[n][3] << '\n';

	return 0;
}


Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
def cf(x1,x2):
    cf=[]
    cf.append(1)
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a, b = map(int, input().split())

result = factorization(gcd(a,b))
ans = len(result)
if not result[-1][0] == 1:
    ans += 1
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll kai(vector<ll> A, ll key) {
	ll an = 0;
	rep(i, A.size()) {
		an += (A.at(i) - 1) / key;
	}
	return an;
}
// index が条件を満たすかどうか
bool isOK(int index,vector<ll> A, int K) {
	if (kai(A,index) <= K) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(ll MA,vector<ll> A,ll K) {
	int left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = MA; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, A,K)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	if (n < 0 || k < 0){
		return 1;
	}
	else if (n < k) {
		return 0;
	}
	return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}

ll dp[51][51][2501];

int main() {
	string s;
	cin >> s;
	ll pa = 0;
	rep(i, s.size()) {
		if (s.at(i) == 'p')pa++;
	}
	cout << s.size() / 2 - pa << endl;
 }


Measured memory_bytes: 3760
inf = 1 << 60
N,A,B,C=map(int, input().split())
l = []
for i in range(N):
    l.append(int(input()))

def dfs(n, a, b, c):
    if n == N:
        if min(a,b,c) == 0:
            return inf
        return abs(A-a)+abs(B-b)+abs(C-c)-30

    a1 = dfs(n+1, a, b, c)
    a2 = dfs(n+1, a + l[n], b, c) + 10
    a3 = dfs(n+1, a, b + l[n], c) + 10
    a4 = dfs(n+1, a, b, c + l[n]) + 10
    return min(a1, a2, a3, a4)

ans = dfs(0, 0, 0, 0)
print(ans)


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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n,k;
    cin>>n>>k;
    vector<long long int> h(n);
    for(i=0;i<n;i++)
        cin>>h[i];
    vector<long long int> lcost(n,0); 
    lcost[0]=0;
    lcost[1]=abs(h[0]-h[1]);
    for(i=2;i<n;i++)
    {
        long long int ans=INT_MAX; 
        for(j=i-1;j>=i-k;j--)
        {
            if(j<0)
                break;
            ans=min(ans,abs(h[i]-h[j])+lcost[j]);
        }
        lcost[i]=ans;
    }
    cout<<lcost[n-1]<<endl;
    
}

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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a >= b) && (a >= c))
        cout << b + c << endl;
    else if ((b >= a) && (b >= c))
        cout << a + c << endl;
    else if ((c >= a) && (c >= b))
        cout << b + a << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = [list(map(lambda x:int(x)-1,input().split()))[::-1] for i in range(N)]

L = [0]*M
for p in A:
  L[p[-1]] += 1
best,i = max((l,i) for i,l in enumerate(L))

for r in range(M-1):
  L[i] = -1
  for p in A:
    L[p[-1]] -= 1
    while L[p[-1]] < 0:
      p.pop()
    L[p[-1]] += 1

  b,i = max((l,i) for i,l in enumerate(L))
  best = min(best,b)

print(best)

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

ll c[100002];

int main(){
    rep(i, 0, 100002) c[i] = 0;
    ll N;
    cin >> N;
    rep(i, 0, N){
        ll a;
        cin >> a;
        c[a]++;
    }
    ll ans = c[0] + c[1];
    rep(i, 1, 100001){
        ans = max(ans, c[i-1] + c[i] + c[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ARainySeason {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        int res = 0;
        int r = 0;
        REP(i, 3) {
            r = s[i] == 'R' ? r + 1 : 0;
            res = max(res, r);
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ARainySeason solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll sum = accumulate(a.begin(), a.end(), 0LL);
  sum %= mod;
  ll ans = sum * sum % mod;
  rep(i, n) ans = (ans + mod * mod - a[i] * a[i]) % mod;
  ans = ans * 500000004 % mod;
  cout << ans << '\n';

  
  return 0;
}

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

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

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

  int p, sum, ans = 1e7;
  for (int i = 0; i < 100; i++) {
    p = i + 1;
    sum = 0;
    for (int j = 0; j < n; j++) {
      sum += pow(p - x[j], 2);
    }
    ans = min(ans, sum);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: putc;
using io :: print;
const int N=305,mod=1e9+7;
int num[N<<1],vis[N<<1],g[N<<1],f[N<<1][N<<1];
// f[i][j] 表示考虑 $[i,j]$ 的连边情况，存在一个连通块最小值为 $i$ ，最大值为 $j$ 的方案数 
int main(){
	ri n,l,i,j,x,y,p,flag,ans;
	gi(n);gi(p);
	while(p--)
		gi(x),gi(y),
		vis[x]=y,
		vis[y]=x;
	for(i=1;i<=n<<1;++i) num[i]=num[i-1]+!vis[i];
	g[0]=1;
	for(i=2;i<=n<<1;i+=2)
		g[i]=(i-1ll)*g[i-2]%mod;
	for(l=2;l<=n<<1;l+=2)
		for(i=1;(j=i+l-1)<=n<<1;++i){
			flag=1;
			for(p=i;p<=j;++p)
				if(vis[p]&&vis[p]<i||vis[p]>j){
					flag=0;
					break;
				}
			if(!flag) continue;
			f[i][j]=g[num[j]-num[i-1]];
			for(p=i+1;p<j;p+=2)
				f[i][j]=(f[i][j]+(ll)(mod-f[i][p])*g[num[j]-num[p]])%mod;
		//	printf("f %d %d %d\n",i,j,f[i][j]);
		}
	ans=0;
	for(i=1;i<=n<<1;++i)
		for(j=i+1;j<=n<<1;j+=2)
			ans=(ans+(ll)f[i][j]*g[num[n<<1]-(num[j]-num[i-1])])%mod;
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

const int N = 2e5;
int n;
vector <int> g[N];
int col[N], cnt[2];
int ans[N];
int used[N];

void dfs(int u, int p, int c) {
	col[u] = c; cnt[c] ++;
	for (int i = 0; i < g[u].size(); ++ i) {
		int v = g[u][i];
		if (v != p) {
			dfs(v, u, c ^ 1);
		}
	}
}

int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i < n; ++ i) {
		int u, v; cin >> u >> v;
		-- u; -- v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1, 0);
	if (cnt[0] > cnt[1]) {
		swap(cnt[0], cnt[1]);
		for (int i = 0; i < n; ++ i) col[i] ^= 1;
	}
	int x = n / 3;
	if (cnt[0] <= x) {
		int nw = 0;
		for (int i = 0; i < n; ++ i) if (!col[i]) used[ans[i] = (nw += 3)] = 1;
		vector <int> v;
		for (int i = 0; i < n; ++ i) if (col[i]) v.push_back(i);
		for (int i = 1, j = 0; i <= n; ++ i) if (!used[i]) ans[v[j ++]] = i;
	} else {
		int nw0 = 1, nw1 = 2, nw2 = 0;
		for (int i = 0; i < n; ++ i) {
			if (!col[i]) {
				if (nw0 <= n) ans[i] = nw0, nw0 += 3;
				else ans[i] = (nw2 += 3);
			} else {
				if (nw1 <= n) ans[i] = nw1, nw1 += 3;
				else ans[i] = (nw2 += 3);
			}
		}
	}
	for (int i = 0; i < n; ++ i) cout << ans[i] << " \n"[i + 1 == n];
	return 0;
}


Measured memory_bytes: 21632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] res = new int[N + 1];

        for (int x = 1; x < 99; x++) {
            for (int y = 1; y < 99; y++) {
                for (int z = 1; z < 99; z++) {
                    int ans = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
                    if (ans <= N) {
                        res[ans]++;
                    }
                }
            }
        }
        for (int i = 1; i <= N; i++) {
            System.out.println(res[i]);
        }
    }
}

Measured memory_bytes: 38708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		double min = 100000000;
		for (int i = 0; i < n; i++) {
			double d = Math.abs(t - h[i] * 0.006 - a);
			if (d < min) {
				ans = i;
				min = d;
			}
		}
		System.out.println(ans + 1);
	}
}


Measured memory_bytes: 24276