akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<bool> del(n);
    ll sum[2] = {};
    rep(i,n){
        cin>>a[i];
        if(a[i]>0) sum[i%2] += a[i];
        else del[i] = true;
    }

    ll Sum = max(sum[0],sum[1]);
    if(Sum == 0LL){
        int pos = max_element(all(a)) - a.begin();
        del[pos] = false;
        cout<<a[pos]<<endl;
    }else{
        rep(i,n) if(sum[i%2] < sum[(i+1)%2]){
            del[i] = true;
        }
        cout<<Sum<<endl;
    }

    vector<int> pos;
 
    int r = n-1;
    while(del[r]) pos.push_back(r--);

    int l = 0;
    while(del[l]) pos.push_back(0), l++;

    for(l+=2; l<=r; l+=2){
        pos.push_back(del[l] ? 2 : 1);
    }
 
    cout<<pos.size()<<endl;
    for(int i : pos){
        cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto tmp = readln.split.to!(ulong[]);
    auto N = tmp[0];
    auto M = tmp[1];
    auto R = tmp[2];
    auto r = readln.split.to!(ulong[]);
    ulong[][] distance = new ulong[][](N,N);
    foreach (i; 0..N) {
        foreach (j; 0..N) {
            distance[i][j] = ulong.max / 2;
        }
    }
    foreach (i; 0..M) {
        tmp = readln.split.to!(ulong[]);
        distance[tmp[0]-1][tmp[1]-1] = tmp[2];
        distance[tmp[1]-1][tmp[0]-1] = tmp[2];
    }
    foreach (k; 0..N) {
        foreach (i; 0..N) {
            foreach (j; 0..N) {
                distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j]);
            }
        }
    }
    auto perm = sort(r);
    ulong res = ulong.max;
    do {
        res = min(res, iota(R-1).map!(i => distance[perm[i]-1][perm[i+1]-1]).sum);
    } while (nextPermutation(perm));
    writeln(res);
}


Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int[] x = new int[3];
		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();
		java.util.Arrays.sort(x);
		System.out.println(x[0]+" "+x[1]+" "+x[2]);
	}
}



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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var hn = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var h = hn[0];
        var n = hn[1];
        var magics = new Magic[n];
        for (int i = 0; i < magics.Length; ++i)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            magics[i] = new Magic(ab[0], ab[1]);
        }

        var dp = new Transitive<int>[h + 1];
        for (int i = 1; i < dp.Length; ++i)
        {
            dp[i] = int.MaxValue;
        }
        for (int i = 0; i < magics.Length; ++i)
        {
            var t = Math.Min(dp.Length, magics[i].Power);
            for (int j = 1; j < t; ++j)
            {
                dp[j] -= magics[i].Cost;
            }
            for (int j = magics[i].Power; j < dp.Length; ++j)
            {
                var x = dp[j - magics[i].Power];
                x.Value += magics[i].Cost;
                dp[j] -= x;
            }
        }

        Console.WriteLine(dp[h]);
    }

    struct Transitive<T>
    where T : IComparable<T>
    {
        public T Value;
        public Transitive(T value)
        {
            Value = value;
        }

        public override string ToString() => Value.ToString();

        public static implicit operator Transitive<T>(T value) => new Transitive<T>(value);
        public static Transitive<T> operator -(Transitive<T> x, Transitive<T> y) => x.Value.CompareTo(y.Value) < 0 ? x : y;
        public static Transitive<T> operator +(Transitive<T> x, Transitive<T> y) => x.Value.CompareTo(y.Value) > 0 ? x : y;
    }

    struct Magic
    {
        public readonly int Power;
        public readonly int Cost;

        public Magic(int p, int c)
        {
            Power = p;
            Cost = c;
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, M;
//    
map<long long, long long> num;
//
map<long long, long long> modnum;
//
map<long long, set<long long> > modset;

int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		num[tmp]++;
		modnum[tmp%M]++;
		modset[tmp%M].insert(tmp);
	}

	long long ans = 0;
	set<long long> done;
	for(auto mod: modnum){
		long long f = mod.first;
		long long s = (M - mod.first)%M;
		if(done.count(f) != 0){
			continue;
		}
		done.insert(f);
		done.insert(s);
		if(f == s){
			ans += modnum[f]/2;
		}else{
			if(modnum[f] > modnum[s]){
				swap(f, s);
			}
			for(auto inter: modset[s]){
				while(num[inter] > 1 && modnum[f] <= modnum[s] - 2){
					num[inter] -= 2;
					modnum[s] -= 2;
					ans++;
					//cout << "make pair with " << inter << endl;
				}
			}
			long long nn = min(modnum[f], modnum[s]);
			//cout << "make " << f << " and " << s << " num = " << nn<< endl;
			ans += nn;
			modnum[f] -= nn;
			modnum[s] -= nn;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 31488
class Vertex
  @@index = 0
  def initialize(adjacent)
    @index = @@index += 1
    @adjacent = adjacent
    @distance = -1
  end

  def to_s
    "#{index} #{distance}"
  end

  attr_reader :index
  attr_accessor :adjacent, :distance
end

def breadth_first_search(vertex)
  vertex.distance = 0
  queue = [vertex]
  until queue.empty?
    current = queue.shift
      current.adjacent.each do |x|
        if x.distance == -1
          x.distance = current.distance + 1
          queue << current.adjacent
          queue.flatten!
        end
      end
  end
end

n = gets.to_i
array = Array.new(n).map { Vertex.new([]) }
n.times do
  adjacent = []
  input = gets.split(' ').map(&:to_i)
  unless input[1].zero?
    input[2..-1].each do |index|
      adjacent << array.find { |vertex| vertex.index == index }
    end
    array[input[0] - 1].adjacent = adjacent
  end
end

breadth_first_search array[0]
puts array.map(&:to_s)


Measured memory_bytes: 6916
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

typedef pair<int, int> P;
typedef long long ll;

const int MOD = 998244353;
const int MAX = 1<<21;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}

int mul(int a, int b) {
  return (int) (((ll) a * b) % MOD);
}

int eksp(int b, int e) {
  int r=1;
  for (; e; e/=2, b=mul(b, b))
    if (e & 1)
      r = mul(r, b);
  return r;
}

int invv(int x) {
  return eksp(x, MOD-2);
}

int divv(int a, int b) { return mul(a, invv(b)); } 

int fak[MAX], invfak[MAX];

void gen() {
  fak[0] = invfak[0] = 1;
  FOR(i, 1, MAX) {
    fak[i] = mul(fak[i-1], i);
    invfak[i] = invv(fak[i]);
  }
}

int povrh(int a, int b) {
  if (b < 0 || a < b) return 0;
  return mul(fak[a], mul(invfak[b], invfak[a-b]));
}

int main()
{
  gen();

  int n, m;
  scanf("%d%d", &n, &m);
  int rje = max(n, m);
  int pola = invv(2);
  
  REP(pos, n+m) {
    int ostalo = n+m - pos;
    if (ostalo % 2) continue;
    int jed = ostalo / 2;

    int dod = divv(mul(povrh(ostalo, jed), povrh(pos, n-jed)), povrh(n+m, n));
    dod = mul(dod, pola);
    rje = add(rje, dod);
  }    

  printf("%d\n", rje);
  
  return 0;
}


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

int n, m;
bool path[8][8];
 
int dfs(int c, bool visited[]) {
    bool allVisited = true;

    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            allVisited = false;
        }
    }

    if (allVisited) {
        return 1;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (path[c][i] && !visited[i]) {
            visited[i] = true;
            ans += dfs(i, visited);
            visited[i] = false;
        }
    }
    return ans;
}
 
int main() {
    cin >> n >> m;
 
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        path[a-1][b-1] = path[b-1][a-1] = true;
    }

    bool visited[8];
    for (int i = 0; i < n; i++) {
        visited[i] = false;
    }
    visited[0] = true;
  
    cout << dfs(0, visited) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x,y,i,n;

  scanf("%d %d",&x,&y);

 if(x<y){
   i = x;
   x = y;
   y = i;
  }
  n = x % y;
  while(n != 0){
    x = y;
    y = n;
    n = x % y;
  }
  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2072
#include<stdio.h>
int main(){
    int H,W;
    for(;;){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0) break;
        
        for(int i =0;i<H;i++){
            for(int h = 0;h<W;h++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2624
#ABC066B

s=raw_input()
if len(s)%2:
 s1=s[:-1]
else:
 s1=s[:-2]
while len(s1)>0:
 l=len(s1)
 if s1[:l/2]==s1[l/2:]:
  print l
  break
 s1=s1[:-2]


Measured memory_bytes: 2568
# Not so Diverse
from collections import Counter
n, k = map(int, input().split())
a = map(int, input().split())
count = Counter(a)
c = sorted(count, key=lambda x: count[x], reverse=True)
ans = 0
while len(c) - k > 0:
    ans += count[c.pop()]
print(ans)


Measured memory_bytes: 41500
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      vi b(105);
      int x,n;
      cin >> x>>n;
      vi a;
      in(a,n);
      for(int i=0;i<n;i++){
            b[a[i]]=1;
      }

      int s = INT_MAX, se = 0;
      for(int i=0;i<=104;i++){
            if(b[i]==0){
                  if(abs(x-i)<s) {
                        s = abs(x-i);
                        se = i;
                  }
            }
      }
      cout << se;

      
}


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

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

using namespace std;



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

    ll b = a[0];
    bool up = (a[0] < a[1])? true:false;
    
    [&]{
        ll j = 1;
        while(j < n){
            if(a[0] != a[j]){
                up = (a[0] < a[j])? true:false;
                break;
            }
            else    j++;
        }
    }();


    ll cnt = 1;
    rep(i, n){
        if(b <= a[i] && up){

        }
        else if(b >= a[i] && !up){

        }
        else{
            if(i+1 < n){
                ll j = i+1;
                while(j < n){
                    if(a[i] != a[j]){
                        up = (a[i] < a[j])? true:false;
                        break;
                    }
                    else    j++;
                }
            }
            cnt++;
        }
        b = a[i];
    }

    cout << cnt << endl;





    return 0;
}


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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        s: i64,
    }

    const MAX: i64 = 1_000_000_000;

    let mut ans = vec![0; n];

    for i in 0..k {
        ans[i] = s;
    }
    for i in k..n {
        ans[i] = if s == MAX {1} else {MAX};
    }

    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define endl '\n'
#define pi acos(-1)
#define pque priority_queue
#define N 1000000
#define lmax LONG_LONG_MAX
typedef pair < int, int > ii;
typedef vector < int > vi;
typedef vector < vi > vii;
int mod = 1000000007;
int n, l, d[100009], sum;
deque < int > dq;
vi ans;
signed main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> l;
	for(int i = 1; i <= n; i++)
		cin >> d[i], dq.pb(i), sum += d[i];
	while(dq.size() > 2)
	{
		int a = dq.front();
		int b = dq.back();
		if(d[a] + d[a + 1] < d[b] + d[b - 1])
		{
			dq.pop_front();
			ans.pb(a);
			sum -= d[a];
		}
		else
		{
			dq.pop_back();
			ans.pb(b - 1);
			sum -= d[b];
		}
	}
	if(sum < l)
		cout << "Impossible";
	else
	{
		cout << "Possible\n";
		for(int i = 0; i < ans.size(); i++)
			cout << ans[i] << endl;
		cout << dq.front();
	}
}


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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double v1 = h*30+m*0.5;
  double v2 = m*6;
  double deg = abs(v1-v2);
  double PI = acos(-1);
  double rad = deg*2*PI/360;
  double ans = a*a + b*b - 2*a*b*cos(rad);
  ans = pow(ans, 0.5);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 4244
using System;

namespace BeginnerContest051
{
    class Program
    {
        static void Main(string[] args)
        {
            int answer=0;

            string[] input = Console.ReadLine().Split(' ');
            int k = int.Parse(input[0]);
            int s = int.Parse(input[1]);

            for(int i=0; i<=k; i++)
            {
                    for(int j=0; j<=k; j++)
                    {
                        if(0<=s-i-j && s-i-j<=k) answer++;
                    }
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s.push_back('x');
  vector<pair<char, int>> vp;
  pair<char, int> p = make_pair(s.front(), 1);
  rep2(i, 1, n+1){
    if(p.first != s.at(i)){
      vp.push_back(p);
      p = make_pair(s.at(i), 1);
    }else p.second++;
  }
  // for(auto p : vp){
  //   cerr << p.first << p.second << " ";
  // }
  // cerr << endl;
  int ans = -1, sum = 0, l = 0, co = 0;
  rep(i, vp.size()){
    if(vp.at(i).first == '0') co++;
    if(co == k+1){
      ans = max(ans, sum);
      sum -= vp.at(l).second;
      co--;
      if(vp.at(l).first == '1'){
        l++;
        sum -= vp.at(l).second;
      }
      l++;
    }
    sum += vp.at(i).second;
  }
  ans = max(ans, sum);
  cout << ans << endl;
  return 0;
}

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


public class Main {
	private	static			BufferedReader	br  = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
	// TODO Auto-generated method stub
		int[]	params = null;
		String	out    = "";

		while ((params = parseParams()) != null) {
			if (params[0] == 0 && params[1] == 0) {
				break;
			}

			int		win   = 0;
			int		curr  = 0;
			int		count = 0;
			int		rest  = params[0];
			byte[]	check = new byte[rest];

			while(rest > 0) {
				if(check[curr] == 0) {
					count++;
					if (count == params[1]) {
						check[curr]++;
						rest--;
						win   = curr + 1;
						count = 0;
					}
				}
				curr = (curr + 1) % params[0];
			}

			out += String.format("%d\n", win);
		}

		System.out.print(out);
	}

	private static  int[] parseParams() {
		int[]		params = null;
		String[]	split  = null;
		String		strIn  = null;
 
		if ((strIn = parseStdin()) != null) {
			split = strIn.split(" ");
			params = new int[split.length];
			for (int n = 0; n < split.length; n++) {
				params[n] = Integer.parseInt(split[n]);
			}
		}
		 
		return params;
	}
 
	private static String parseStdin() {
		String	strNum = null;
 
		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}
 
		return strNum;
	}
}

Measured memory_bytes: 19300
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

int main()
{
	int H,W,biu;
	char lj,c[100][100];
	int a[100][100],ans;
	while(~scanf("%d %d",&H,&W))
	{
		a[1][1] = 1;
		ans = 0;
		for(int i = 1;i <= H;i++)
		{
			scanf("%c",&lj);
			for(int j = 1;j <= W;j++)
			{
				scanf("%c",&c[i][j]);
				if(c[i][j]=='.') ans++;
			}
		}
		for(int i = 0;i <= H+1;i++)
		{
			for(int j = 0;j <= W+1;j++)
			{
				a[i][j] = MaxN;
			}
		}
		for(int i = 1;i <= H;i++)
		{
			for(int j = 1;j <= W;j++)
			{
				if(c[i][j] == '.') 
				{
					a[i][j] = min(a[i-1][j]+1,a[i][j-1]+1);
					a[1][1] = 1;
				}
			}
		}
		for(int i = H;i >= 1;i--)
		{
			for(int j = W;j >= 1;j--)
			{
				if(c[i][j]=='.')
				{
					biu = min(a[i+1][j]+1,a[i][j+1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = 1;i <= H;i++)
		{
			for(int j = 1;j <= W;j++)
			{
				if(c[i][j] == '.') 
				{
					biu = min(a[i-1][j]+1,a[i][j-1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = H;i >= 1;i--)
		{
			for(int j = W;j >= 1;j--)
			{
				if(c[i][j]=='.')
				{
					biu = min(a[i+1][j]+1,a[i][j+1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = 1;i <= H;i++)
		{
			for(int j = 1;j <= W;j++)
			{
				if(c[i][j] == '.') 
				{
					biu = min(a[i-1][j]+1,a[i][j-1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = H;i >= 1;i--)
		{
			for(int j = W;j >= 1;j--)
			{
				if(c[i][j]=='.')
				{
					biu = min(a[i+1][j]+1,a[i][j+1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = 1;i <= H;i++)
		{
			for(int j = 1;j <= W;j++)
			{
				if(c[i][j] == '.') 
				{
					biu = min(a[i-1][j]+1,a[i][j-1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = H;i >= 1;i--)
		{
			for(int j = W;j >= 1;j--)
			{
				if(c[i][j]=='.')
				{
					biu = min(a[i+1][j]+1,a[i][j+1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}
		for(int i = 1;i <= H;i++)
		{
			for(int j = 1;j <= W;j++)
			{
				if(c[i][j] == '.') 
				{
					biu = min(a[i-1][j]+1,a[i][j-1]+1);
					a[i][j] = min(biu,a[i][j]);
				}
			}
		}

		ans = ans-a[H][W];
		if(a[H][W] >= 10000) printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef vector<vs> vvs;

typedef vector<pll> vvpl;
typedef vector<vpi> vvpi;

typedef queue<ll> ql;
typedef queue<int> qi;
typedef queue<pll> qpl;
typedef queue<pi> qpi;

template <typename T> void printv(const vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    printf("[%d] %d\n", i, v[i]);
  }
}

template <typename T> void printvv(const vector<T> &vv) {
  for (int i = 0; i < vv.size(); ++i) {
    for (int j = 0; j < vv[i].size(); ++j) {
      printf("[%d][%d] %d\n", i, j, vv[i][j]);
    }
  }
}

template <typename T, typename U> void printp(const pair<T, U> &p) {
  cout << p.first << " " << p.second << endl;
}

template <typename T> void printvp(const vector<pair<T, T>> &vp) {
  for (int i = 0; i < vp.size(); ++i) {
    printf("[%d] %d, %d\n", vp[i].first, vp[i].second);
  }
}

template <typename T> void printvvp(const vector<vector<pair<T, T>>> &vvp) {
  for (int i = 0; i < vvp.size(); ++i) {
    for (int j = 0; j < vvp[i].size(); ++j) {
      printf("[%d][%d] %d, %d\n", i, j, vvp[i][j].first, vvp[i][j].second);
    }
  }
}

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

  ll tmp = 0;
  for (int bit = 0; bit < (1 << (S.length() - 1)); ++bit) {
    tmp = S[0] - '0';
    for (int i = 1; i < S.length(); ++i) {
      if (bit & 1 << (i - 1)) {
        tmp += S[i] - '0';
      } else {
        tmp -= S[i] - '0';
      }
    }
    if (tmp == 7) {
      for (int i = 0; i < S.length(); ++i) {
        cout << S[i];
        if (i < S.length() - 1) {
          char op = (bit & (1 << i)) >= 1 ? '+' : '-';
          cout << op;
        }
      }
      cout << "=7" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2e3+5;
ll dp[N][N];
struct node
{
	int x,id;
};
node a[N];
int cmp(node a,node b)
{
	return a.x>b.x;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int k=1;k<=n;k++)
	{
		for(int i=0;i<k;i++)
		{
			int j=k-i-1;
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(ll)a[k].x*(a[k].id-(i+1)));
			dp[i][j+1]=max(dp[i][j+1],dp[i][j]+(ll)a[k].x*(n-j-a[k].id));
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
		ans=max(ans,dp[i][n-i]);
	cout<<ans;
	return 0; 
} 

Measured memory_bytes: 26296
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 100005;
vector<int> g[MAXN], b[MAXN], c[MAXN];
map<int, int> component, friends;
bool visited[MAXN];

void dfs(int src, int cmp) {
    visited[src] = true; // mark as visited
    component[src] = cmp; // set corresponding conected component
    c[cmp].pb(src); // getting all the nodes of the conected component

    for(int i = 0; i < g[src].size(); i++) {
        if (!visited[g[src][i]]){
            dfs(g[src][i], cmp);
        }
    }
}
int blocks(int src) {
    int ans = 0;
    for (auto x : b[src]){
        if (component[x] == component[src] && find(g[src].begin(), g[src].end(), x) == g[src].end())
            ans++;
    }

    return ans;
}
int main() {
    fastIO();
    int n, m, k;

    cin >> n >> m >> k;

    int n1, n2;
    REP(i, m) {
        cin >> n1 >> n2;
        g[n1].pb(n2);
        g[n2].pb(n1);
    }

    REP(i, k) {
        cin >> n1 >> n2;
        b[n1].pb(n2);
        b[n2].pb(n1);
    }

    int cmp = 0;
    memset(visited, 0, sizeof(visited));
    RE(i, n) {
        if (!visited[i]) {
            dfs(i, cmp);
            cmp++;
        }
    }

    RE(i, n) {
        friends[i] = c[component[i]].size() - g[i].size() - blocks(i) - 1;

        cout << friends[i] << " ";
    }

    cout << endl;


    return 0;
}

Measured memory_bytes: 25720
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int f(int x){
	return x*x*x*x*x;
}
signed main(){
	int X;cin>>X;
	for(int i=-3000;i<=3000;i++){
		for(int j=-3000;j<=3000;j++){
			if(f(i)-f(j)==X){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
}


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

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

    cout << a/b << ' ' << a%b << ' ';
    cout << fixed;
    cout << setprecision(5);
    cout << (double)a/b << endl;

    return 0;
}

Measured memory_bytes: 3268
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll k; cin>>k;
	vector<double> p(n);
	REP(i,n) cin>>p[i];

	vector<double> sum(n-k+1);
	REP(i,n) p[i]=(p[i]+1)/2;
	REP(i,k){
		sum[0]+=p[i];
	}
	FOR(i,1,n){
		if(i-1+k>=n)break;
		sum[i]=sum[i-1]-p[i-1]+p[i-1+k];
	}
	//cout << "sum: "; REP(i,(signed)sum.size()) cout<<sum[i]<<" "; cout << endl; //----------cout----------//

	double max=0;
	REP(i,sum.size()){
		if(sum[i]>max)max=sum[i];
	}
	printf("%.12lf\n",max);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod
 
 
 
signed main(){
 
    int N; cin >> N;
    string S; cin >> S;
 
    int ans = 1;
    REP(i, N - 1) if(S[i] != S[i + 1]) ans++;
    Out(ans); 
 
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vivi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vll = std::vector<ll>;
using vllvll = std::vector<std::vector<ll>>;


using namespace std;

#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll n; cin >> n;
	vll a(n); rep(i,n) cin >> a[i];
	vllvll dp(n+1,vll(n+1,0)); //dp[i][j]:[i,j)区間でのX-Y
	//dp[i][i]=0
	rep2(len,1,n+1){
		rep(i,n-len+1){
			ll j = i+len;
			if((n-len)/*とった数*/ %2)dp[i][j] = min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
			else dp[i][j] = max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
		}
	}
	out(dp[0][n]);
}




Measured memory_bytes: 70784
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int n,t;
  int i,j;
  int m=INF;
  int a[100000]={};
  int diff[100000]={};
  cin>>n>>t;
  rep(i,n){
    cin>>a[i];
    m=min(m,a[i]);
    diff[i]=a[i]-m;
  }

  sort(diff,diff+n);
  

  int ans=1;
  for(i=n-1;i>=0;i--)
    if(diff[i]==diff[i-1])ans++;
    else break;
  cout<<ans<<endl;

}


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

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

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define all(x) (x).begin(), (x).end()
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

struct Info {
    ll a,b;
};

bool cmp(Info a, Info b) {
    return a.a < b.a;
}

int main() {

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

    ll N,K; cin >> N >> K;

    vector<Info> v;
    F0R(i,N) {
        Info x; cin >> x.a >> x.b;
        v.pb(x);
    }

    sort(all(v),cmp);

    ll ac = 0;
    F0R(i,N) {
        if (ac+v[i].b >= K) {
            cout << v[i].a << "\n";
            exit(0);
        }
        ac += v[i].b;
    }

    cout << "-1\n";

}



Measured memory_bytes: 2420
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(string a, string b) {
  cout << "HD"[(a == "H") ^ (b == "H")] << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string b;
	string a;
	cin >> a;
	cin >> b;
	solve(a, b);
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7
import math

from functools import reduce

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

G = reduce(lcm, A)
ans = sum(map(lambda x:G // x, A))

print(ans % DIV)

Measured memory_bytes: 10008
#include<iostream>
 
using namespace std;
 
int main(){
 
  int a=0;
  int b=0;
  
  cin >> a >> b;
  
  int c=a*b;
  
  if(c%2==0){
  	cout << "Even" << endl;
  }else{
  	cout << "Odd" << endl;
  }
  
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val x = sc.nextInt()
    val size = 110000
    val isprime = Array(size) { true }
    for (i in 2 until size) {
        if (!isprime[i]) continue
        var j = 2
        while (i * j < size) {
            isprime[i * j] = false
            j++
        }
    }
    for (i in x until size) {
        if (isprime[i]) {
            println(i)
            return
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31516
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  string s;
  cin >> n;
  set<string> m;
  for(int i=0;i<n;i++)
  {
    cin >> s;
    m.insert(s);
  }
  cout << m.size();
  return 0;
}

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

int main(){
  int A, B, K;
  cin >> K >> A >> B;
  for(int i=A; i<=B; i++){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;



int main() {
    int n, a;
    cin >> n >> a;
    vint x(n);
    rep(i, n) cin >> x[i];
    rep(i, n) x[i] -= a;
    const int MAX = 5000;
    vvll dp(n+1, vll(MAX, 0));
    rep(i, n) {
        rep(j, MAX) {
            dp[i+1][j] += dp[i][j];
            if (j+x[i] >= 0 && j+x[i] < MAX) {
                dp[i+1][j+x[i]] += dp[i][j]; 
            }
        }
        dp[i+1][x[i] + MAX/2]++;
    }

    ll ans = dp[n][MAX/2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2304
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
ll COM(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;
}


void solve(){
    
}

ll dp[110][10010]={0};
ll weight[110],value[110];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,w;
    cin>>n>>w;
    rep(i,n) cin>>value[i]>>weight[i];
    
    for(ll a=0;a<=w;a++) dp[0][a]=0;
    
    
        for(ll j=0;j<=w;j++){
            rep(i,n){
                if(j>=weight[i]) {
                    dp[i+1][j]=max(dp[i+1][j-weight[i]]+value[i],dp[i][j]);
                }else{
                    dp[i+1][j]=dp[i][j];
                }
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}



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

typedef long long ll;

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

	ll n;
	cin>>n;

	ll d[60];
	ll ans = INT_MAX;
	for(ll i=0;i<n;i++) cin>>d[i];

	sort(d, d+n);
	ans = d[0];

	ll dd[60];
	ll maxmin = -1;

	ll temp = INT_MAX;
	for(ll i=1;i<n;i++) temp = min(temp, d[i] - d[i-1]);
	maxmin = max(maxmin, temp);

	for(ll j=0;j<n;j+=2) {
		for(ll i=0;i<n;i++) dd[i] = d[i];
		for(ll i=0;i<=j;i+=2) dd[i] = 24 - dd[i];
		sort(dd, dd+n);

		ll temp = INT_MAX;
		for(ll i=1;i<n;i++) temp = min(temp, dd[i] - dd[i-1]);
		maxmin = max(maxmin, temp);
	}

	cout<<min(maxmin, ans)<<endl;
	
}

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

int a[110];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += 2 * min(a[i], k - a[i]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
// コンパイルは $ g++ atcoder.cpp

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

int main() {
    string s;
    cin >> s;
    int count;
    for (int i=0; i < s.length(); i++) {
        if (s[i] == '1') count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
def main():
    import collections
    K = int(input())
    N = len(input())
    mod = 10**9 + 7

    def cmb(n, r, mod):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    n = N + K
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inverse = [0, 1]  # 逆元テーブル計算用テーブル

    for i in range(2, n + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    d = [0]*(K+1)
    d[0] = 1
    d2 = [0]*(K+1)
    d2[0] = 1

    for i in range(K):
        d[i+1] = d[i]*26
        d[i+1] %= mod

        d2[i+1] = d2[i]*25
        d2[i+1] %= mod

    ans = 0
    for i in range(K+1):
        ans += d2[K-i] * d[i] * cmb(N+K-i-1, N-1, mod)
        ans %= mod
    print(ans)


main()


Measured memory_bytes: 229188
def main():
  N, K = map(int, input().split())
  
  H = sorted(list(map(int, input().split())), reverse=True)
 
  n = sum(H)
  
  if K == 0:
    print(n)
  elif N > K:
    for i in range(K):
      n -= H[i]
    print(n)
  else:
    print(0)
    
  return 0
 
if __name__ == "__main__":
  main()

Measured memory_bytes: 26024
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    for (int i=b;i<=b+a;i++){
      if (i>c){
        break;
      }
      if (i % a == 0){
        System.out.println("OK");
        System.exit(0);
      }
    }
    System.out.println("NG");
  }
}
        


Measured memory_bytes: 35720
import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize
def combi(n, r):
    if r == 0 or n == r:
        return 1
    return combi(n - 1, r - 1) + combi(n - 1, r)


n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list) / len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
    print(1)
elif max_ave_list[0] != max_ave_list[-1]:
    print(combi(l, m))
else:
    print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //AtCoder Beginner Contest 175
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = Console.ReadLine();
            //int i1 = int.Parse(str[0]);
            //int i2 = int.Parse(str[1]);
            //int i3 = int.Parse(str[1]);
            var count = 0;

            if (s == "RRR")
            {
                count = 3;
                Console.WriteLine(count);
            }
            else if (s == "RRS" || s == "SRR")
            {
                count = 2;
                Console.WriteLine(count);
            }
            else if (s == "RSS" || s == "SSR" || s == "SRS" || s == "RSR")
            {
                count = 1;
                Console.WriteLine(count);
            }
            else
            {
                count = 0;
                Console.WriteLine(count);

            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25704