akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, K;
int h[100010];
int dp[100010];


signed main(){
    cin >> N >> K;
    rep(i, 0, N) cin >> h[i];

    fill(dp, dp+N, INF32);
    dp[0] = 0;
    rep(i, 0, N) repe(j, 1, K) if(i+j < N) chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j]));

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
s_li = []
k = []
for i in range(m):
    ks = list(map(int, input().split()))
    k.append(ks[0])
    ks.pop(0)
    s_li.append(ks)
p = list(map(int, input().split()))

bit_li = []
for i in range(2**n):
    bit = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            bit[j] = 1
    bit_li.append(bit)

count = 0
for i in range(2 ** n):
    flag = 0
    for j in range(m):
        elem_sum = 0
        for l in range(k[j]):
            elem_sum += bit_li[i][s_li[j][l] - 1]
        if elem_sum % 2 == p[j]:
            flag += 1
    if flag == m:
        count += 1

print(count)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
 
int main() {
  int N; cin >> N;
  vector<int> t(N+1),x(N+1),y(N+1);
  t[0] = 0; x[0] = 0; y[0] = 0;
  for (int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];
  
  bool can = true;
  for (int i = 1; i <= N; i++) {
    int tt = t[i] - t[i-1];
    int xx = x[i] - x[i-1];
    int yy = y[i] - y[i-1];
    if (tt % 2 != abs(xx + yy) % 2) can = false;
    else if (tt < abs(xx) + abs(yy)) can = false;
  }
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int x = parseInt(sc.next());
		sc.close();
		int mx = 0;
		if(x<4) {
			mx=1;
		} else {
			int sq = (int) floor(sqrt(x));
			int jo=0;
			for (i = 2; i <= sq; i++) {
				jo=(int)pow((double)i,floor(log10((double)x)/log10((double)i)));
//				out.printf("%d:%f:%f:%f%n",i,log10((double)x),log10((double)i),floor(log10((double)x)/log10((double)i)));
//				out.printf("%d:%d%n",i,jo);
				if(jo>mx)mx=jo;
			}
		}
		out.println(mx);
	}
}


Measured memory_bytes: 23764
import sys

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n, m, l = list(map(int, input().split()))
lines = sys.stdin.readlines()
INF = 10 ** 18

dists = [[INF] * n for _ in range(n)]

for i in range(n):
    dists[i][i] = 0

for line in lines[:m]:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dists[a][b] = c
    dists[b][a] = c

dists = floyd_warshall(csr_matrix(dists))
refuels = np.ones((n, n), dtype=np.int64)
refuels[dists > l] = INF
refuels = floyd_warshall(csr_matrix(refuels)).astype(np.int64)
refuels[refuels == INF] = 0
refuels -= 1

buf = []

for line in lines[m + 1:]:
    s, t = map(int, line.split())
    buf.append(refuels[s - 1][t - 1])

print('\n'.join(map(str, buf)))


Measured memory_bytes: 34888
#include<functional>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
  int a,b;
  char s[10],t[10],u[10];
  cin>>s;
  cin>>t;
  cin>>a>>b;
  cin>>u;
  if(strcmp(u,s)==0){
    a--;
  }
  if(strcmp(u,t)==0){
  	b--;
  }
  cout<<a<<" "<<b;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Text;

namespace Contest
{
    struct R
    {
        public string S;
        public int P;
        public int Index;
        public R(string s, int p,int i)
        {
            S = s;
            P = p;
            Index = i;
        }
    }
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();
            int N = sc.NextInt();
            R[]r = new R[N];
            for (int i = 0; i < N; i++)
            {
                r[i] = new R(sc.Next(),sc.NextInt(),i+1);
            }
            Array.Sort(r, (a, b) =>
            {
                if (a.S == b.S)
                {
                    return -a.P.CompareTo(b.P);
                }
                else
                {
                    return a.S.CompareTo(b.S);
                }
            });
            var sb = new StringBuilder();
            for (int i = 0; i < N; i++)
            {
                sb.AppendLine(r[i].Index.ToString());
            }
            Console.Write(sb.ToString());
        }
        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private char _separator;
    private StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

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

bool visited[100001] = {false};
int h[100001] = {0};
int memo[100001] = {0};

int mc(int N)
{
    if (N == 1)
    {
        memo[1] = 0;
        visited[1] = true;
        return 0;
    }
    else if (N == 2)
    {
        memo[2] = abs(h[2] - h[1]);
        visited[2] = true;
        return memo[2];
    }
    else
    {
        if (visited[N])
        {
            return memo[N];
        }
        else
        {
            visited[N] = true;
            memo[N] = min(mc(N-1) + abs(h[N] - h[N-1]), mc(N-2) + abs(h[N] - h[N-2]));
            return memo[N];
        }
    }
}

int main()
{
	int n, i;
	cin>>n;
	
	for(i=1; i<=n; i++)
	{
	    cin>>h[i];
	}
	
	cout<<mc(n);
	return 0;
}


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

int main() {
    int A, B;
    
    cin >> A >> B;
    
    int plug = 1;
    int cnt = 0;
    
    while(plug < B){
        plug--;
        plug += A;
        cnt++;
    }
    
    cout << cnt;
    
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Xml.Schema;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N;
        private int[] A;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            A = sc.IntArray();
        }

        public void Solve()
        {
            Scan();
            int sum = A.Sum();
            int min = int.MaxValue;
            int ans = -1;
            for (int i = 0; i < N; i++)
            {
                int aa = A[i] * N;
                if (Math.Abs(sum - aa) < min)
                {
                    min = Math.Abs(sum - aa);
                    ans = i;
                }
            }
            Console.WriteLine(ans);
        }

        static void Main() => new Program().Solve();
    }


}

Measured memory_bytes: 13268
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val d = sc.nextInt()
    var x = sc.nextInt()

    repeat(n) {
        val a = sc.nextInt()
        x += 1 + (d - 1) / a
    }
    println(x)
}


Measured memory_bytes: 31640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int n;
cin >> n;
vector<int>dp(n+1,10e5);
dp[0]=0;
int money [3]={1,6,9};
for(int i=0;i<=n;i++){
  for(int j=0;j<3;j++){
    ll che = money[j],beki=1,chea=pow(che,beki);
    if(j==0)dp[i]=min(dp[i],dp[i-che]+1);
    while(chea<=i&&j!=0){
    dp[i]=min(dp[i],dp[i-chea]+1);
    beki++;
    chea=pow(che,beki);
    }
}
}
cout << dp[n]<<endl;
}
 


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[4][MAX],b[4],c[MAX],t[2];
void WA(){puts("No");exit(0);}
int main()
{
	n=read();
	for(int i=1;i<=3;++i)
		for(int j=1;j<=n;++j)
		{
			int p=read();
			int x=(p-1)%3+1,y=(p+2)/3;
			if((i==2&&x!=2)||(i!=2&&x==2))WA();
			if((y&1)^(j&1))WA();
			a[i][j]=p;
		}
	for(int j=1;j<=n;++j)
	{
		for(int i=1;i<=3;++i)b[i]=a[i][j];
		int y=(b[1]+2)/3,x=3*y-3;
		for(int i=1;i<=3;++i)if(b[i]!=x+i&&b[i]!=x+4-i)WA();
		t[j&1]^=(a[1][j]>a[2][j]);c[j]=y;
	}
	for(int i=1;i<=n;++i)
	{
		while(c[i]!=i)
		{
			t[i&1^1]^=1;
			swap(c[i],c[c[i]]);
		}
	}
	if(t[0]||t[1])WA();
	puts("Yes");return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int H,W,A,B; cin >> H>>W>>A>>B;
    vs grid(H, string(W, '0'));
    
    rep(i, H) {
        if (i < B) {
            for (int j = A; j < W; j++) {
                grid[i][j] = '1';
            }
        } else {
            rep(j, A) {
                grid[i][j] = '1';
            }
        }
        
    }
    
    rep(i, H) cout << grid[i] << endl;
}


Measured memory_bytes: 2304
use std::io;


fn main() {
    let n = read_one::<usize>();
    println!("{}", n * (n + 1) / 2);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

int const MOD = 1e9 + 7;


ll pow_mod(ll a, ll x, const ll &mod) {
    if (x == 0) return 1;
    ll ans = pow_mod(a, x >> 1, mod);
    ans = ans * ans % mod;
    if (x & 1) 
        ans = ans * a % mod;
    return ans;
}

// n>=m>=0
ll C(ll n, ll m) {
    if (n - m < m) m = n - m;
    if (m < 0) return 0;
    ll ans = 1;
    for (int i = 1; i <= m; i++) {
        ans = ans * (n - m + i) % MOD * pow_mod(i, MOD - 2, MOD) % MOD;
    }
    return ans;
}
int main(void) {
    FAST_IO;
    
    ll n, a, b;
    cin >> n >> a >> b;
    cout << ((pow_mod(2, n, MOD) - C(n, a)+ MOD) - C(n, b) - 1+ MOD) % MOD << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner (System.in);
			int n = sc.nextInt();
			int mod = n%10;
			if(mod==3) {
				System.out.println("bon");
			}
			else if(mod==2||mod==4||mod==5||mod==7||mod==9) {
				System.out.println("hon");
			}
			else {
				System.out.println("pon");
			}
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;

int d[N];

int solve(int x)
{
    deque<int> q;
    q.push_back(1);
    for(int i = 1; i < x; ++i)
        d[i] = i;
    d[0] = x;
    while(!q.empty())
    {
        int u = q.back(); q.pop_back();
        int v = (u + 1) % x;
        if(d[v] > d[u] + 1)
        {
            d[v] = d[u] + 1;
            q.push_front(v);
        }
        v = (u * 10) % x;
        if(d[v] > d[u])
        {
            d[v] = d[u];
            q.push_back(v);
        }
    }
    return d[0];
}

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d\n", solve(n));
    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1564>
問題文============================================================
 アルファベットの小文字と数字からなる文字列 S が与えられる。次の手順で文字列 S の長さを圧縮する。
 
 1.文字列内の文字の順番を任意の順番に入れ替える。
     例: "0ig3he12fz99" → "efghiz012399"
 2.次の操作を任意の回数行う。
 文字列内にある、"abcdefghijklmnopqrstuvwxyz"の連続した部分文字列を選び、
 (先頭の文字)'-'(末尾の文字)に置き換える。
 例: "efghiz012399" → "e-iz012399"
 文字列内にある、公差が1であるような数字列("0123456789"の連続した部分文字列)を選び、
 (先頭の数字)'-'(末尾の数字)に置き換える。
 例: "e-iz012399" → "e-iz0-399"
 
 文字列 S を圧縮して得られる文字列の長さの最小値を求めよ。
=================================================================

解説=============================================================
文字の置き換えをすることによって得をするのは、対象文字が３つ以上並んでいるときである。
 よって、英語と数字それぞれにおいて、その個数を見て３つ以上の文字を短縮できるようであれば
 短縮するといった動作を繰り返して行えば良い
================================================================
*/

int ans;
int suuzi[10] = {0};
int alpha[26] = {0};

bool suuzi_check(int l){
    if(suuzi[l] != 0 && suuzi[l+1] != 0 && suuzi[l+2] != 0){
        int r = l + 2;
        for(;r < 10;){
            if(suuzi[r] == 0){
                break;
            }
            r++;
        }
        int minv = INF;
        for(int idx = l; idx < r;idx++) minv = min(minv,suuzi[idx]);
        ans = ans - (minv*(r-l)) + 3*minv;
        
        for(int idx = l; idx < r;idx++){
            suuzi[idx]-=minv;
        }
        return true;
    }else{
        return false;
    }
}

bool alpha_check(int l){
    if(l + 2 >= 26) return false;
    if(alpha[l] != 0 && alpha[l+1] != 0 && alpha[l+2] != 0){
        int r = l + 2;
        for(;r < 26;){
            if(alpha[r] == 0){
                break;
            }
            r++;
        }
        int minv = INF;
        for(int idx = l; idx < r;idx++) minv = min(minv,alpha[idx]);
        ans = ans - (minv*(r-l)) + minv*3;
        
        for(int idx = l; idx < r;idx++){
            alpha[idx]-=minv;
        }
        return true;
    }else{
        return false;
    }
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string S; cin >> S;
    ans = (int)S.length();
    for(int i = 0; i < S.length();i++){
        if(isdigit(S[i])){
            suuzi[S[i] - '0']++;
        }else{
            alpha[S[i] - 'a']++;
        }
    }
    for(int i = 0; i < 8;i++){ while(suuzi_check(i)){} }
    for(int j = 0; j < 26;j++){ while(alpha_check(j)){} }
    cout << ans << endl;
    
	return 0;
}



Measured memory_bytes: 3224
import Control.Applicative
import Control.Monad
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)
import Data.Sequence ((|>), ViewR(..), Seq)
import qualified Data.Sequence as Sq

main :: IO ()
main = do
  q <- readLn
  replicateM q f >>= solve
  where
    f = readil B.readInt <$> B.getLine

solve :: [[Int]] -> IO ()
solve qs = foldM f Sq.empty qs >> return ()
  where
    f sq [0, x] = pushBack sq x
    f sq [1, p] = do
      randomAccess sq p >>= print
      return sq
    f sq _ = popBack sq

pushBack :: Seq Int -> Int -> IO (Seq Int)
pushBack sq x = return $ sq |> x

randomAccess :: Seq Int -> Int -> IO Int
randomAccess sq p = return $ Sq.index sq p

popBack :: Seq Int -> IO (Seq Int)
popBack sq = let (sq' :> _) = Sq.viewr sq
             in return sq'

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')



Measured memory_bytes: 70780
class UnionFindWithSize
  def initialize(n)
    # 親の番号を格納
    # ただし、rootの位置には、-(その集合のサイズ)を格納
    @parent = Array.new(n, -1)
    @size = n
  end

  def root(x) # xのrootの番号を返す
    raise "UnionFindWithSize::IndexError" if x < 0 || @size <= x
    return x if @parent[x] < 0
    @parent[x] = root(@parent[x])
    return @parent[x]
  end

  def size(x) # xの属するグループのサイズを返す
    return -@parent[root(x)]
  end

  def merge(x, y)
    x, y = root(x), root(y)
    return false if x == y
    # 大きい方(x)に小さい方(y)をくっつけたい
    x, y = y, x if size(x) < size(y)
    @parent[x] += @parent[y]
    @parent[y] = x
    return true
  end

  def same?(x, y)
    root(x) == root(y)
  end
end

n, k, l = gets.split.map(&:to_i)
uf1 = UnionFindWithSize.new(n)
uf2 = UnionFindWithSize.new(n)
k.times do
  a, b = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  uf1.merge(a, b)
end
l.times do
  a, b = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  uf2.merge(a, b)
end
cnt = Hash.new(0)
n.times do |i|
  cnt[[uf1.root(i), uf2.root(i)].inspect] += 1
end
ans = []
n.times do |i|
  ans << cnt[[uf1.root(i), uf2.root(i)].inspect]
end
puts ans * " "


Measured memory_bytes: 38444
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
#define MAX_N 1000000
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int N; cin >> N;
  vector<int> v;
  v.push_back(1);
  for(int x = 6; x<=N; x*=6) v.push_back(x);
  for(int x = 9; x<=N; x*=9) v.push_back(x);
  sort(v.begin(),v.end(),greater<int>());
  v.erase( unique(v.begin(),v.end()), v.end() );
  int i,j,M = v.size();
  //dp[i+1][j]:i番目までの要素を見て，jになる最小個数
  int dp[M+1][N+1];
  REP(j,N+1) dp[0][j] = MAX_N;
  dp[0][0] = 0;
  REP(i,M){
    REP(j,N+1){
      dp[i+1][j] = dp[i][j];
      if(j-v[i]>=0) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-v[i]]+1);
    }
  }
  cout << dp[M][N] << endl;
  return 0;
}


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

ll G(ll n,vector< ll >&v){
    if(v[n] != n){
        v[n] = G(v[n],v);
    }
    return v[n];
}


void doit(){
   ll n, i, q;
   cin >> n >> q;
   vector< ll >v(n+2);
   iota(all(v),0);
   vector< ll >C(n + 2, 1);
   ll x, y;
   while(q--){
    cin >> x >> y;
    if(x > y)swap(x,y);
    ll c1 = G(x,v), c2 = G(y,v);
    if(c1 != c2){
        C[c1] += C[c2];
        C[c2] = 0;
    }
    v[c2] = c1;
   }
   cout << *(max_element(all(C))) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 6356
def solve():
    N, X, Y = map(int, input().split())
    res = {}
    for i in range(N):
        res[i] = 0
    for i in range(1,N):
        for j in range(i,N+1):
            mdst = min(abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))
            res[mdst] += 1
    for i in range(1,N):
        print(res[i])
solve()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define len(x)           x.length()
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define M                 1000000007
#define MM                998244353
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define mem0(x)           memset(x, 0, sizeof (x))
#define mem1(x)           memset(x, -1, sizeof (x))
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

//coded by Avijit Mandal 

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
// Returns LCM of array elements 
ll findlcm(ll arr[], ll n) 
{ 
    // Initialize result 
    ll ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (ll i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
int main(){
   IOS;
   ll n,x,y,i,j;
   cin>>n>>x>>y;
   ll a[n+1];
   mem0(a);
   for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
         ll d=min(abs(j-i),abs(x-i)+1+abs(j-y));
         d=min(d,abs(i-y)+1+abs(x-j));
         a[d]++;
      }
   }
   for(i=1;i<n;i++)cout<<a[i]/2<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define ll  long long

int main(void){
    ll x, t;
    cin >> x >> t;
    ll r;
    if(x>=t) r=x-t;
    else r=0;
    pr(r);
}

Measured memory_bytes: 256
from collections import deque
k = int(input())

if k <= 9:
  print(k)
  exit()

que = deque([1,2,3,4,5,6,7,8,9])
cnt = len(que)
while cnt < k:
  x = que.popleft()
  m = x%10
  if m != 0:
    que.append(10*x+m-1)
    cnt+=1
    if cnt == k: print(que.pop()); exit();
  que.append(10*x+m)
  cnt+=1
  if cnt == k: print(que.pop()); exit();
  if m != 9:
    que.append(10*x+m+1)
    cnt+=1
    if cnt == k: print(que.pop()); exit();

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[110000];

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N, K;
  scanf("%lld %lld", &N, &K);

  vector<ll> list(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = v;
  }

  for (ll i = 0; i <= K; i++) {
    if (!dp[i]) {
      for (ll j = 0; j < N; j++) {
        if (i + list[j] <= K) {
          dp[i + list[j]] = 1;
        }
      }
    }
  }

  if (dp[K]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}


Measured memory_bytes: 4460
n=int(input())
l=list(map(int,input().split()))
count=0

for i in range(n):
  for j in range(i,n):
    for z in range(j,n):
      if l[i]!=l[j] and l[i]!=l[z] and l[j]!=l[z]:
        if l[i]+l[j]>l[z] and l[z]+l[j]>l[i] and l[i]+l[z]>l[j]:
          count+=1
          
print(count)

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

int main()
{
    int A1,A2,A3;
    cin >> A1 >> A2 >> A3;
    if(A1+A2+A3<22){
        cout << "win" <<endl;
    }else{
        cout << "bust" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<char,ll>;
int n,m;


int main(){
   cin >> n;
   auto a = vector<int>(n,0);
   for (int i = 0; i < n; i++)
   {
      cin >> a[i];
   }

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

   auto sum0=0;
   auto sum1=0;
   for (int i = 0; i < n; i++)
   {
      if(i%2){
         sum1+=a[i];
      }else{
         sum0+=a[i];
      }
   }
   
   cout << sum0-sum1;
   
}
  
  

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

int main(int argc, char const *argv[])
{
	int n,c;
	cin>>n>>c;
	pair<int,pair<int,int>> st[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>st[i].second.first>>st[i].second.second>>st[i].first;
	}
	sort(st,st+n);
	int imos[100005]={};
	for (int i = 0; i < n; ++i)
	{
		if (i!=0&&st[i].first==st[i-1].first&&st[i].second.first==st[i-1].second.second)
		{
			++imos[st[i].second.first+1];
			--imos[st[i].second.second+1];
		}
		else
		{
			++imos[st[i].second.first];
			--imos[st[i].second.second+1];
		}
	}
	for (int i = 0; i < 100004; ++i)
	{
		imos[i+1]+=imos[i];
	}
	int ans=0;
	for (int i = 0; i < 100005; ++i)
	{
		ans=max(ans,imos[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#D                 more faster method than above               see it ..........
l = lambda : list(map(int,input().strip().split()))
n = int(input())
a = l()
t = [0]*(10**5+1)
s = 0
for i in a:
    s += i
    t[i] += 1
q = int(input())
for _ in range(q):
    b,c = l()
    s += (c-b)*t[b]
    t[c] += t[b]
    t[b] = 0
    print(s)


Measured memory_bytes: 20732
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
int main(){
    string str;
    map<int,int>t1,t2;
    while(getline(cin,str),str!=""){
        int n,m;
        sscanf(str.c_str(),"%d,%d",&n,&m);
        t1[n]++;
    }
    while(getline(cin,str),str!=""){
        int n,m;
        sscanf(str.c_str(),"%d,%d",&n,&m);
        t2[n]++;
    }
    map<int,int>::iterator ite=t1.begin();
    for(;ite!=t1.end();ite++){
        if(t2.find(ite->first)!=t2.end()){
            cout<<(ite->first)<<" "<<ite->second+((t2.find(ite->first))->second)<<endl;
        }
    }
}

Measured memory_bytes: 1240
w,h,n=map(int,input().split())
xya=[list(map(int,input().split())) for i in range(n)]
xya1=[i[0] for i in xya if i[2]==1]+[0]
xya2=[i[0] for i in xya if i[2]==2]+[w]
xya3=[i[1] for i in xya if i[2]==3]+[0]
xya4=[i[1] for i in xya if i[2]==4]+[h]
left=max(xya1)
right=min(xya2)
lower=max(xya3)
upper=min(xya4)
if left>=right or lower>=upper:
  print(0)
else:
  print((right-left)*(upper-lower))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0359>
?????????============================================================
 ??????????????´???????????\???????????\??§????????????????????´??????????????\???????????\??§???????????????
 
 ??????????????´???????????\??????????????????????????¨??????????????\???????????\?????±?????????????????°????????????????????????
 
 ?????????????????\????????\???????????????????????????
 ????????????
 ????????\??? "mon"???????????\???"tue"????°´?????\??? "wed"?????¨?????\??? "thu"???
 ????????\??? "fri"???????????\??? "sat"?????\?????\??? "sun" ??¨???????????????
 

=================================================================

?§£??¬=============================================================
hai
================================================================
*/

string youbi[7] = {"fri","sat","sun","mon","tue","wed","thu"};
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int X; cin >> X;
    cout << youbi[(X-1)%7] << endl;
	return 0;
}

Measured memory_bytes: 3228
N = int(input())
res = set([0])
for _ in range(N):
    s = int(input())
    res |= set([r + s for r in res])
res = list(res)
res.sort()
n = len(res)
for i in range(n-1, -1, -1):
    if res[i] % 10 == 0:
        continue
    print(res[i])
    break
else:
    print(0)

Measured memory_bytes: 10412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	int n, m, a, b, c, d, e;
	string s, t;
	int k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a <= k) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}


	return 0;
}



Measured memory_bytes: 256
def p_f():
    t1, t2 = map(int, input().split())
    a1, a2 = map(int, input().split())
    b1, b2 = map(int, input().split())

    # aの方がt1のときに先行している
    if a1 < b1:
        a1, b1 = b1, a1
        a2, b2 = b2, a2

    dif1 = a1 * t1 - b1 * t1
    dif2 = (b1 * t1 + b2 * t2) - (a1 * t1 + a2 * t2)
    # print(dif1)
    # print(dif2)
    if dif2 < 0:
        print(0)
        exit()
    if dif2 == 0:
        print("infinity")
        exit()
    if dif1 % dif2 == 0:
        print(dif1 // dif2 * 2)
    else:
        print((dif1 + dif2) // dif2 * 2 - 1)
        
p_f()

Measured memory_bytes: 38384
n = int(input())
a={}
b=[]
for i in range(n):
    s=input()
    if s in a:
        a[s]=a[s]+1
    else:
        a[s]=int(1)
        b.append(s)
c=0
print()
for i in b:
    if c < a[i]:
        c=a[i]
b.sort()
for i in b:
    if a[i]==c:
        print(i)
# print(a)


Measured memory_bytes: 33416
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 H, W, N, s_r, s_c;
  std::string S, T;
  std::cin >> H >> W >> N >> s_r >> s_c >> S >> T;

  {
    i64 x = s_c;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] == 'L') {
        --x;
      }
      if (x < 1) {
        goto TAKAHASHI;
      }
      if (T[i] == 'R') {
        x = std::min<i64>(x + 1, W);
      }
    }
  }
  {
    i64 x = s_c;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] == 'R') {
        ++x;
      }
      if (x > W) {
        goto TAKAHASHI;
      }
      if (T[i] == 'L') {
        x = std::max<i64>(x - 1, 1);
      }
    }
  }
  {
    i64 y = s_r;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] == 'U') {
        --y;
      }
      if (y < 1) {
        goto TAKAHASHI;
      }
      if (T[i] == 'D') {
        y = std::min<i64>(y + 1, H);
      }
    }
  }
  {
    i64 y = s_r;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] == 'D') {
        ++y;
      }
      if (y > H) {
        goto TAKAHASHI;
      }
      if (T[i] == 'U') {
        y = std::max<i64>(y - 1, 1);
      }
    }
  }

  std::cout << "YES" << std::endl;
  return 0;

TAKAHASHI:
  std::cout << "NO" << std::endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  long long input;
  map<long long,int> A;
  for(int i=0;i<N;i++){
    cin >> input;
    A[input] ++;
  }
  int ans =0;
  for(auto itr = A.begin(); itr != A.end(); ++itr) {
    ans += itr->second % 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const double pi = acos(-1);
double dist(double x, double y){
    return (x - y) * (x - y);
}
int main()
{
    Hello
    int n;
    cin >> n;
    int arr[n], cntr = 0;
    double av = 0;
    pair<double, double> pr[n];
    for(int i = 0; i < n; i++) arr[i] = i;
    for(int i = 0; i < n; i++) cin >> pr[i].first >> pr[i].second;
    do{
        cntr++;
        for(int i = 0; i < n - 1; i++)
            av += (sqrt(dist(pr[arr[i]].first, pr[arr[i + 1]].first) +
                       (dist(pr[arr[i]].second, pr[arr[i + 1]].second))));
    }while (next_permutation(arr, arr + n));
    cout << fixed << setprecision(6) << av/cntr;
    return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  ll n;
  cin>>n;
  ll s = sqrt(n);
  cout<<s*s;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

ll dp[55][6000];
ll x[MAX] = {};

int main() {
	int i, j, k, l;
	int N;
	int A;
	cin >> N >> A;
	rep(i, N) {
		cin >> x[i];
	}
	dp[0][3000] = 1;
	dp[0][3000+x[0]-A] += 1;
	rep(i, N - 1) {
		for (j = 6000; j > -1; j--) {
			if (dp[i][j] > 0) {
				dp[i+1][j + x[i+1] - A] += dp[i][j];
				dp[i + 1][j] += dp[i][j];
			}
		}
	}
	cout << dp[N-1][3000]-1 << endl;

	return 0;
}

Measured memory_bytes: 896
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int x[11][11];
int check(string s) {
	int ret = 0;
	for (int i = 0; i < s.size(); i++) ret = x[ret][s[i] - 48];
	return ret;
}
int main() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> x[i][j];
		}
	}
	int ret = 0;
	for (int i = 0; i < 10000; i++) {
		string s = to_string(i);
		while (s.size() < 4) s = '0' + s;
		int e = check(s);
		string t = s + (char)(e + 48);
		bool flag = true;
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 10; k++) {
				string r = t; r[j] = k + 48;
				if (r == t) continue;
				if (check(r) == 0) flag = false;
			}
		}
		for (int j = 0; j < 4; j++) {
			string r = t; swap(r[j], r[j + 1]);
			if (r == t) continue;
			if (check(r) == 0) flag = false;
		}
		if (!flag) ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3252
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>

template <class T>
using greater_queue=std::priority_queue<T, std::deque<T>, std::greater<T>>;

template <class T>
constexpr T inf=(T(1)<<(8*sizeof(T)-3));

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;

  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const Edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
struct Graph: public std::vector<std::vector<Edge<Weight>>> {
  Graph(size_t n): std::vector<std::vector<Edge<Weight>>>(n) {}

  void connect_with(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
    (*this)[dst].emplace_back(dst, src, cost);
  }

  void connect_to(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
  }
};

template <class Weight>
std::vector<Weight> dijkstra(const Graph<Weight> &g, size_t s) {
  std::vector<Weight> dist(g.size(), inf<Weight>);
  greater_queue<std::pair<Weight, size_t>> q;
  dist[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    auto p=q.top();
    q.pop();
    Weight w=p.first;
    size_t v=p.second;
    if (w > dist[v])
      continue;

    for (const Edge<Weight> &e: g[v]) {
      if (dist[e.dst] > w + e.cost) {
        dist[e.dst] = w + e.cost;
        q.emplace(dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}

int main() {
  size_t n, m, s, t;
  scanf("%zu %zu %zu %zu", &n, &m, &s, &t);
  --s, --t;

  Graph<intmax_t> gyen(n), gsnk(n);
  for (size_t i=0; i<m; ++i) {
    size_t u, v;
    intmax_t a, b;
    scanf("%zu %zu %jd %jd", &u, &v, &a, &b);
    --u, --v;

    gyen.connect_with(u, v, a);
    gsnk.connect_with(u, v, b);
  }

  intmax_t SNUKE=1000000000000000;
  std::vector<intmax_t> cyen=dijkstra(gyen, s), csnk=dijkstra(gsnk, t);
  std::vector<intmax_t> res;
  for (size_t i=0; i<n; ++i) {
    res.push_back(SNUKE-(cyen[i]+csnk[i]));
  }
  for (size_t i=n-1; i--;)
    res[i] = std::max(res[i], res[i+1]);
  for (auto d: res)
    printf("%jd\n", d);
}


Measured memory_bytes: 21876
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println(FORECAST.get(scan.nextLine()));
        scan.close();
    }

    private static final Map<String, String> FORECAST = Collections
            .unmodifiableMap(new LinkedHashMap<String, String>() {
                private static final long serialVersionUID = 8811606967577385220L;
                {
                    put("Sunny", "Cloudy");
                    put("Cloudy", "Rainy");
                    put("Rainy", "Sunny");
                }
            });
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, C[500], S[500], F[500];
    cin >> N;
    REP(i, N - 1) cin >> C[i] >> S[i] >> F[i];

    REP(i, N) {
        int ans = 0;
        FOR(j, i, N - 1) {
            ans = max(ans, S[j]);
            ans = (ans + F[j] - 1) / F[j] * F[j];
            ans += C[j];
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    rep(i, h) {
        cin >> A.at(i);
    }

    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;
    rep(i, h) {
        cout << "#" << A.at(i) << "#" << endl;
    }
    rep(i, w + 2) {
        cout << "#";
    }
    cout << endl;
}


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

int main(){
    string S, T;
    cin >> S >> T;
    for(int i = S.size() - T.size(); i >= 0; i--){
        bool if_ok = false;
        for(int j = 0; j < T.size(); j++){
            if(S[i + j] != '?' && S[i + j] != T[j]){
                if_ok = true;
                break;
            }
        }
        if(!if_ok){
            for(int j = 0; j < i; j++){
                if(S[j] == '?'){
                    S[j] = 'a';
                }
            }
            for(int j = i; j < i + T.size(); j++){
                S[j] = T[j - i];
            }
            for(int j = i + T.size(); j < S.size(); j++){
                if(S[j] == '?'){
                    S[j] = 'a';
                }
            }
            cout << S << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

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

int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << a[0] << " " << a[1] << " " << a[2] << endl;

	return 0;
}

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

int main(){
	long int i,j,N,M,ans=0,X,n_500,n_5;

	scanf("%ld",&X);
	n_500 = X/500;
	
	n_5 = (X%500)/5;
	
	printf("%ld\n",1000*n_500+n_5*5);

 return 0;
 }

Measured memory_bytes: 128