akhauriyash/Code-Regression huggingface dataset:
n, y = gets.strip.split.map(&:to_i)
_i, _j, _k = -1, -1, -1

(0..n).each do |i|
  (0..n - i).each do |j|
    if i * 10000 + j * 5000 + (n - i - j) * 1000 == y
      _i, _j, _k = i, j, n - i - j
    end
  end
end

puts "#{_i} #{_j} #{_k}"

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

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

signed main(void) {
	int n;

	cin >> n;

	vector<int> a(n), b(n);


	REP(i, n) {
		cin >> a[i];

	}

	REP(i, n) {
		cin >> b[i];
	}

	sort(ALL(a));
	sort(ALL(b));

	int ans = 0;

	REP(i, 29) {
		int cur = 0;
		REP(j, n) {
			cur ^= (n * bitcheck(a[j], i)) % 2;
			cur ^= (n * bitcheck(b[j], i)) % 2;
		}

		int base = pow(2, i);

		vector<int> bb(n);
		REP(j, n) {
			bb[j] = b[j] % base;
		}
		sort(ALL(bb));

		REP(j, n) {
			int ovcou = bb.end() - lower_bound(ALL(bb), base - a[j] % base);

			cur ^= ovcou % 2;
		}

		if(cur)
			bitset(ans, i);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

template<typename T>inline void check_min(T a,T &b){if(a<b)b=a;}

namespace diaoye_chicken_dinner
{
	typedef long long ll;
	const int N=101000,M=N*30,INF=2147483647;

	int n,m,K;
	
	struct segment_treeeeee
	{
#define lt (st[p][0])
#define rt (st[p][1])
#define mid ((L+R)>>1)
#define lts lt,L,mid
#define rts rt,mid+1,R
#define dog T.root
		int st[M][2];
		int w[M];
		int e,root;
		void init(){w[root=e=1]=INF;}
		void init_s(){w[root=e=1]=0;st[1][0]=st[1][1]=0;}
		int check(int &p){if(p)return p;p=++e;w[p]=INF;return p;}
		int check_s(int &p){if(p)return p;p=++e;w[p]=0;lt=rt=0;return p;}
		void modify(int s,int t,int x,int &p,int L=0,int R=K-1)
		{
			p=check(p);
			if(s<=L && t>=R){check_min(x,w[p]);return;}
			if(s<=mid)modify(s,t,x,lts);
			if(t>mid)modify(s,t,x,rts);
		}
		int query(int x,int &p,int L=0,int R=K-1)
		{
			p=check(p);
			if(L==R)return w[p];
			int ret=w[p];
			if(x<=mid)check_min(query(x,lts),ret);
			else check_min(query(x,rts),ret);
			return ret;
		}
		void inc(int s,int t,int &p,int L=0,int R=K-1)
		{
			p=check_s(p);
			if(s<=L && t>=R){w[p]++;return;}
			if(s<=mid)inc(s,t,lts);
			if(t>mid)inc(s,t,rts);
		}
		int query_s(int x,int &p,int L=0,int R=K-1)
		{
			p=check_s(p);
			if(L==R)return w[p];
			int ret=w[p];
			if(x<=mid)ret+=query_s(x,lts);
			else ret+=query_s(x,rts);
			return ret;
		}
	}T;

	ll tx[N],ty[N],ans;
	int A[N],B[N],L[N],R[N];

	bool initialize()
	{
		scanf("%d%d",&n,&K),ans=m=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",A+i,B+i),ans+=A[i];
			if(B[i]==1 && A[i]*2>K)return 0;
		}
		for(int i=1;i<=n;i++)tx[i+1]=tx[i]+A[i];
		for(int i=n-1;i;i--)ty[i]=ty[i+1]+A[i+1];

		for(int i=n;i;i--)
		{
			if(B[i]==2)continue;
			m++;
			ll tmp=ty[i],s,t;
			s=(tx[i]+A[i])%K;
			t=((tx[i]-A[i])%K+K)%K;
			L[m]=((s-tmp)%K+K)%K;
			R[m]=((t-tmp)%K+K)%K;
		}
		return 1;
	}
	ll fl[N],fr[N];
	bool check_in(int x,int l,int r)
	{
		if(l<=r)return x>=l && x<=r;
		return x<=r || x>=l;
	}
	void work()
	{
		T.init();
		for(int i=m,j;i;i--)
		{
			j=T.query(L[i],dog);
			fl[i]=(j==INF)?0:(fl[j]+(L[j]-L[i]+K)%K);
			j=T.query(R[i],dog);
			fr[i]=(j==INF)?0:(fl[j]+(L[j]-R[i]+K)%K);

			if(L[i]<=R[i])
			{
				if(L[i])T.modify(0,L[i]-1,i,dog);
				if(R[i]<K-1)T.modify(R[i]+1,K-1,i,dog);
			}
			else if(R[i]+1<=L[i]-1)T.modify(R[i]+1,L[i]-1,i,dog);
		}
	}
	void solve()
	{
		if(!initialize()){printf("-1\n");return;}

//		for(int i=1;i<=m;i++)printf("%d---%d\n",L[i],R[i]);

		work();

//		for(int i=1;i<=m;i++)printf("%lld , %lld\n",fl[i],fr[i]);

		ll ret=INF*100000000ll;

		T.init_s();
		for(int i=1;i<=m;i++)
		{
//			printf(":%d %d\n",T.query_s(L[i],dog),T.query_s(R[i],dog));
			if(T.query_s(L[i],dog)==i-1)check_min(fl[i],ret);
			if(T.query_s(R[i],dog)==i-1)check_min(fr[i],ret);

			if(L[i]<=R[i])T.inc(L[i],R[i],dog);
			else T.inc(0,R[i],dog),T.inc(L[i],K-1,dog);
		}
		printf("%lld\n",ans*2+ret);
	}
}

int main()
{
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
	diaoye_chicken_dinner::solve();
	return 0;
}


Measured memory_bytes: 39168
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int a, b, c, x, y;
  std::cin >> a >> b >> c >> x >> y;
  int sum;
  if (2 * c < a + b) {
    if (x < y) {
      sum = 2 * c * x;
      sum += (b < 2*c) ? b * (y - x) : 2 * c * (y - x);
    } else if (x == y) {
      sum = 2 * c * x;
    } else {
      sum = 2 * c * y;
      sum += (a < 2*c) ? a * (x - y) : 2 * c * (x - y);
    }
  } else {
    sum = a * x + b * y;
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 888
import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer

object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {

  @tailrec
  def gcd(a:Int,b:Int):Int = {
    if (b==0) {
      a
    } else {
      gcd (b,a%b)
    }
  }

  val n = Scanner.nextInt()
  val a = Array.fill(n)(Scanner.nextInt())

  var leftGcd = ArrayBuffer(a(0))
  var rightGcd = ArrayBuffer(a(n-1))

  (1 until (n-1)).foreach(i=>{
    leftGcd += gcd(a(i),leftGcd(i-1))
    rightGcd += gcd(a(n-i-1),rightGcd(i-1))
  })

  val result = ((0 until (n-2)).map(i=>{
    gcd(leftGcd(i),rightGcd(n-i-3))
  })++Seq(leftGcd(n-2),rightGcd(n-2))).max

  println(result)
}

Measured memory_bytes: 40844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<String> ad = new ArrayDeque<String>();
        String[] lines = br.readLine().split(" ");
        for (int i = 0; i < lines.length; i++) {
            if (isNumber(lines[i])) {
                ad.push(lines[i]);
            } else {
                if (lines[i].equals("+")) {
                    ad.push(String.valueOf(ip(ad.pop()) + ip(ad.pop())));
                } else if (lines[i].equals("-")) {
                    ad.push(String.valueOf(-ip(ad.pop()) + ip(ad.pop())));
                } else {
                    ad.push(String.valueOf(ip(ad.pop()) * ip(ad.pop())));
                }
            }
        }
        System.out.println(ad.pop());
    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

Measured memory_bytes: 26288
s = input().strip()

counts = [0] * len(s)

for i, c in enumerate(s):
    prev = counts[i - 1] if i > 0 else 0
    if c == 'B':
        counts[i] = prev + 1
    else:
        counts[i] = prev

allowable = 0
for i in range(len(s)):
    if s[i] == 'W' and i > 0:
        count = counts[i - 1]
        allowable += count

print(allowable)


Measured memory_bytes: 11240
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    long long ans;
    vector<int> h;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        int hp;
        cin >> hp;
        h.push_back(hp);
    }
    sort(h.begin(),h.end());
    
    for (int i = 0; i < n-k; i++)
    {
        ans += h[i];
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

const long long mod = 1e9 + 7;

void solve() {
	int n; cin >> n;
	int k; cin >> k;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	} 
	vector<long long> dp(k + 1, 1);
	for (int i = 1; i <= n; i++) {
		vector<long long> new_dp(k + 1);
		for (int j = 0; j <= k; j++) {
			int l = max(0, j - a[i]);
			if (l == 0) {
				new_dp[j] += dp[j];
				new_dp[j] %= mod;
			} else {
				new_dp[j] += (dp[j] - dp[l - 1] + mod) % mod;
				new_dp[j] %= mod;
			}
		}
		for (int j = 0; j <= k; j++) {
			dp[j] = new_dp[j];
			if (j > 0) {
				dp[j] += dp[j - 1];
				dp[j] %= mod;
			}
		}
	}
	cout << ((k == 0) ? 1 : (dp[k] - dp[k - 1] + mod) % mod) << endl;
}

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

Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
vector<bool> a(100005);
void bfs(vector<vector<pair<int,int>>> &v,vector<bool> &ans){
    queue<pair<int,int>> q;ans[1]=0;
    q.push({1,0});a[1]=1;
    while(!q.empty()){
        int m=q.front().first,n=q.front().second;
        q.pop();
        n%=2;
        ans[m]=n;
        for(auto i:v[m])
        if(!a[i.first]) 
        {a[i.first]=1;q.push({i.first,n+i.second});}
    }
}
int main(){
    int n,x,y,w;cin>>n;
    vector<bool> ans(n+1);
    vector<vector<pair<int,int>>> v(n+1);
    for(int i=1;i<n;i++){
        cin>>x>>y>>w;
        v[x].push_back({y,w});
        v[y].push_back({x,w});
    }
    bfs(v,ans);
    for(int i=1;i<=n;i++) cout<<ans[i]<<'\n';
}

Measured memory_bytes: 6400
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> 

using namespace std;

long long a[100100];

int main()
{
	long long n,c,k;
	scanf("%lld%lld%lld",&n,&c,&k);
	for(int i = 1;i <= n;i++)scanf("%lld",&a[i]);
	sort(a + 1,a + 1 + n);
	long long tmp = 1,ans = 0;
	while(tmp <= n)
	{
		long long be = a[tmp],en = a[tmp];
		for(int i = 1;i <= c;i++)
		{
			en = a[tmp];
			if(tmp > n)break;
			tmp ++;
			if(en - be > k)
			{
				tmp--;
				break;
			}
		}
		ans ++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 896
from collections import  Counter
a,b = map(int,input().split())
c,d = map(int,input().split())
e,f = map(int,input().split())

a = [a,b,c,d,e,f]
al = list(Counter(a))

if a.count(1)>2 or a.count(2)>2 or a.count(3)>2 or a.count(4)>2:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3316
/*input
0 0 0 1
2 3 6 6
31 -41 -59 26
*/
#include <bits/stdc++.h>
using namespace std;

int cal(int a, int b) {
    return abs(a - b);
}

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    while (cin >> x1 >> y1 >> x2 >> y2) {
        int dx = x2 - x1;
        int dy = y2 - y1;

        x3 = x2 - dy;
        y3 = y2 + dx;

        x4 = x3 - dx;
        y4 = y3 - dy;

        cout << x3 << ' ' << y3 << ' ';
        cout << x4 << ' ' << y4 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())

if int(a-k) <0:
  ans1 = 0
  
  if int(b+(a-k)) < 0:
    ans2 = 0
  else:
    ans2 = int(b+(a-k))
  
else :
  ans1 = int(a-k)
  ans2 = b

  
Lists=[ans1,ans2]
print(*Lists)

Measured memory_bytes: 3064
#include<stdio.h>
#define Z 100 
int main(){
  int n,i,j,x,y,z,X[Z][Z];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      X[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    x--;
    for(j=0;j<y;j++){
      scanf("%d",&z);
      z--;
      X[x][z]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==0)
	printf("%d",X[i][j]);
	  else
	    printf(" %d",X[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2144
#include<iostream>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        if(a==0&&b==0)
            break;
            
        for(int i=0;i<b;i++)
            cout<<"#";
            cout<<endl;
            
        for(int i=2;i<a;i++)
            {
                cout<<"#";
            for(int j=2;j<b;j++)
                cout<<".";
                cout<<"#"<<endl;
            }
        for(int i=0;i<b;i++)
            cout<<"#";
            cout<<endl<<endl;
    }
    return 0;
}



Measured memory_bytes: 3004
#include <stdio.h>

int main(void){
    int N;

    scanf("%d", &N);
    printf("0\n");
    fflush(stdout);

    char s[100];

    scanf("%s", s);
    
    char fc, tc;
    int fv = 0, tv = N;

    if(s[0] == 'V'){
        return 0;
    }else if(s[0] == 'M'){
        fc = tc = 'M';
    }else{
        fc = tc = 'F';
    }
    while(1){
        int mv = (fv + tv) / 2;

        printf("%d\n", mv);
        fflush(stdout);
        scanf("%s", s);

        if(s[0] == 'V'){
            return 0;
        }else{
            char mc = s[0];

            if(fc == mc){
                if((mv - fv) % 2 == 1){
                    tc = mc;
                    tv = mv;
                }else{
                    fc = mc;
                    fv = mv;
                }
            }else{
                if((mv - fv) % 2 == 1){
                    fc = mc;
                    fv = mv;
                }else{
                    tc = mc;
                    tv = mv;
                }
            }
        }
    }
}

Measured memory_bytes: 848
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Bits
import qualified Data.ByteString.Char8 as BS

readInt s = case BS.readInt s of
              Just (x, _) -> x

solve :: Int -> Int -> Int -> Int -> Int
solve !a !b !c !x
  | 500 * a + 100 * b + 50 * c < x = 0
  | c == 0 && x `rem` 100 == 50 = 0
  | otherwise = sum [ nb1 - nb0 + 1
                    | na <- [0..a]
                    , let nb0 = max 0 ((x - 500 * na - 50 * c + 50) `div` 100)
                          nb1 = min b ((x - 500 * na) `div` 100)
                    , nb0 <= nb1
                    -- nb <- [0..b]
                    -- nc <- [0..c]
                    -- 500 * na + 100 * nb + 50 * nc == x
                    -- nc = (x - 500 * na - 100 * nb) / 50
                    -- 0 <= x - 500 * na - 100 * nb, x - 500 * na - 100 * nb <= 50 * c
                    -- (x - 500 * na - 50 * c) / 100 <= nb, nb <= (x - 500 * na) / 100, nb is an integer
                    -- max 0 ((x - 500 * na - 50 * c + 50) / 100) <= nb <= min b ((x - 500 * na) / 100)
                    ]

main = do
  a <- readInt <$> BS.getLine
  b <- readInt <$> BS.getLine
  c <- readInt <$> BS.getLine
  x <- readInt <$> BS.getLine
  print $ solve a b c x


Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<functional>
#include<queue>
#include<map>
#include<algorithm>

using namespace std;

int main(void){

    int a, b, c;

    cin >> a >> b >> c;

    cout << (a+b+c >= 22? "bust": "win") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
//typedef pair<int, int> P;
//typedef pair<ll, ll> LP;
//typedef pair<int, P> PP;
//typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int P[10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
int Q[10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
int R[10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
ll m,a,r,c,h;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n;

    REP(i,n){
        cin>>s;
        if(s[0]=='M')m++;
        if(s[0]=='A')a++;
        if(s[0]=='R')r++;
        if(s[0]=='C')c++;
        if(s[0]=='H')h++;
    }
    ll D[5];
    D[0]=m,D[1]=a,D[2]=r,D[3]=c,D[4]=h;
    ll res = 0;
    REP(d,10){
        res += D[P[d]]*D[Q[d]]*D[R[d]];
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

H, W = map(int, input().split())
s = [[i == '.' for i in input()] for _ in range(H)]

dist = [[float('inf')] * W for _ in range(H)]
dist[0][0] = 0

h = [(0, 0, 0)]
while h :
  cc, cy, cx = heappop(h)
  for dy, dx in ((1, 0), (0, 1)) :
    ny, nx = cy + dy, cx + dx
    if 0 <= ny < H and 0 <= nx < W :
      nc = cc + (s[ny][nx] != s[cy][cx])
      if nc < dist[ny][nx] :
        heappush(h, (nc, ny, nx))
        dist[ny][nx] = nc
        
print((dist[H-1][W-1] + 2 - s[0][0] - s[-1][-1]) // 2)

Measured memory_bytes: 49116
#include<stdio.h>
int main()
{
	int n, m, Q;
	scanf("%d %d %d", &n, &m, &Q);
	int i, j;
	int l, r;
	int count[502][502];
	for (i = 0; i <= n; i++)
		for (j = 0; j <= n; j++)
			count[i][j] = 0;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &l, &r);
		count[l][r]++;
	}
	int sum[502][502];
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			sum[i][j] = sum[i][j - 1] + sum[i - 1][j] + count[i][j] - sum[i - 1][j - 1];
	int p, q;
	for (i = 0; i < Q; i++)
	{
		scanf("%d %d", &p, &q);
		printf("%d\n", sum[q][q] + sum[p - 1][p - 1] - sum[q][p - 1] - sum[p - 1][q]);
	}
	return 0;
}

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

int main(void) {
    int pst=114514, drink=114514;
    int pri;
    for(int i=0; i<3; i++) {
        cin >> pri;
        pst = min(pst, pri);
    }
    for(int i=0; i<2; i++) {
        cin >> pri;
        drink = min(drink, pri);
    }
    cout << pst + drink - 50 << endl;
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  }
  else {
    cout << b - a << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
t,a = map(int, input().split())
h = [int(x) for x in input().split()]

def temp(x):
    return t - x*0.006

ret = -1
diff = 10**5
for i in range(n):
    ht = temp(h[i])
    if abs(a-ht)<diff:
        diff = abs(a-ht)
        ret = i+1
print(ret)


Measured memory_bytes: 3060
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 07/01/2018 12:05:22
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	map<int, bool> mp;
	int n, x, res = 0;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>x;
		if(mp[x] == false){
			res ++;
			mp[x] = true;
		}
	}	
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,i,j,f=0;
    char s[100];
    scanf("%d",&n);
    scanf("%s",&s);
    if(n%2!=0)
        goto Jump;

    for(i=n/2,j=0;s[i]!='\0';i++,j++)
    {
        if(s[i]==s[j])
        {
            f=1;
            continue;
        }
        else
        {
            f=0;
            break;
        }
    }
    Jump:
    if (f==1)
        printf("Yes\n");
    else if(f==0)
        printf("No\n");
    return 0;
}


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

using ll = long long int;

bool check ( char c ) {
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}

int main() {
    #ifdef LU_SERIOUS
        freopen( "in.txt", "r", stdin );
    #endif // LU_SERIOUS
    char c;
    while( cin >> c ) {
        if( check( c ) ) cout << "vowel\n";
        else cout << "consonant\n";
    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int K;cin >> K;
    int A,B;cin >> A >> B;
    int tmp = 1;
    bool ok = false;
    int tmo = K;
    while(1){
        tmo = K*tmp;
        tmp++;
        if(tmo>=A && tmo<=B){
            ok = true;
            break;
        }else if(tmo>B)break;
    }
    if(ok)cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3612
n = int(input())
# seat = [0] * 10 ** 6
seat = [0] * 10 ** 5
for i in range(n):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        seat[j - 1] = 1

res = 0
# for i in range(10 ** 6):
for i in range(10 ** 5):
    if seat[i] == 1:
        res += 1
print(res)


Measured memory_bytes: 9436
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}



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

int main(void){

  int D,N,i,j,k;
  scanf("%d",&N);
  scanf("%d",&D);

  double X[N][D];
  int dis[N],cnt=0;
  double a;

  for(i=0;i<N;i++){
    for(j=0;j<D;j++){
      scanf("%lf",&X[i][j]);
    }
  }

  for(i=0;i<N;i++){
    for(k=1;k<N-i;k++){
      a=0.0;
      for(j=0;j<D;j++){
        a = a + pow((X[i][j]-X[i+k][j]),2.0);
      }
      if(sqrt(a) - (int)sqrt(a) == 0.0){
        cnt++;
      }
    }
  }

  printf("%d",cnt);

  return 0;
}


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

//int ans;
vector<int> num(4);
vector<char> ansv(3);

void dfs2(int x, char ch, vector<char> fct, int ans){
	if(x == 4){
      	if(ans == 7){
        	for(int i = 0; i < 3; i++){ansv.at(i) = fct.at(i);}}
    	return;}
  	
  	if(ch == '+'){
      	fct.push_back('+');
    	ans += num.at(x);
      	dfs2(x+1,'+',fct,ans);
      	dfs2(x+1,'-',fct,ans);
    	}
	if(ch == '-'){
      	fct.push_back('-');
    	ans -= num.at(x);
      	dfs2(x+1,'+',fct,ans);
      	dfs2(x+1,'-',fct,ans);
    	}
  
  	return;
}

void dfs(int x){
  	int ans = num.at(x);
	dfs2(x+1, '+', vector<char>(0),ans);
  	dfs2(x+1, '-',vector<char>(0),ans);
  	return;
}

int main(){
	vector<char> s(4);	for(int i = 0; i < 4; i++){
    	cin >> s.at(i);
    	num.at(i) = s.at(i) - '0';}
		dfs(0);
  	
  	for(int i = 0; i < 3; i++){
    	cout << num.at(i) << ansv.at(i);}
  	cout << num.at(3) << '=' << 7 << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	unsigned long long int a;
	string c;
	cin>>a>>c;
	long long int t=(c[0] - '0') * 100 + (c[2] - '0') * 10 + (c[3] - '0') * 1;
	cout<<(t*a)/100;
}

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

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long int> v1(n, 0), v2(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v1[i];
    }
    sort(v1.begin(), v1.end());
    v2[0] = v1[0];
    for (int i = 1; i < n; i++) {
        v2[i] = v2[i - 1] + v1[i];
    }
    for (int i = n - 2; i >= 0; i--) {
        if (2 * v2[i] < v1[i + 1]) {
            cout << n - i - 1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}




Measured memory_bytes: 4768
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++)cin >> A[i];
    int a=A[0];

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

        int tmp,r;

        if(a<A[i]){
            tmp=a;
            a=A[i];
            A[i]=tmp;
        }

        r=a%A[i];
        while(r!=0){
            a=A[i];
            A[i]=r;
            r = a % A[i];
        }

        a = A[i];
    }

    cout << a << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define FOR(n) for(int i=0;i<n;i++)
#define MOD 1e9+7
#define INF 1e9
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
int main(void){
  int n,c,ans=0;
  cin>>n>>c;
  VI a(c);
  FOR(c){
    cin>>a[i];
    ans+=a[i];
  }
  ans=(ans-1)/(n+1)+1;
  cout<<ans<<endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	map<int, int> mp[2];
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		mp[i&1][x]++;
	}
	vector<pair<int, int> > v[2];
	for(auto x : mp[0]){
		v[0].push_back({x.second, x.first});
	}
	for(auto x : mp[1]){
		v[1].push_back({x.second, x.first});
	}
	sort(v[0].rbegin(), v[0].rend());
	sort(v[1].rbegin(), v[1].rend());
	int ans;
	if(v[0][0].second != v[1][0].second){
		ans = n - v[0][0].first - v[1][0].first;
	}else if(v[0].size() == 1 && v[1].size()){
		ans = n/2;
	}else if(v[0].size() == 1){
		ans = n/2 - v[1][1].first;
	}else if(v[1].size() == 1){
		ans = n/2 - v[0][1].first;
	}else{
		ans = n - max(v[0][0].first + v[1][1].first, v[0][1].first + v[1][0].first);
	}
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;

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

	vector<int> h(N);
	for(int index = 0; index < N; index++)
		cin >> h[index];

	vector<long long int> DP(N, LLONG_MAX);
	DP[0] = 0;
	for(int index = 0; index < N; index++){
		if((index + 1) < N)
			DP[index + 1] = min(DP[index + 1], DP[index] + abs(h[index + 1] - h[index]));
		if((index + 2) < N)
			DP[index + 2] = min(DP[index + 2], DP[index] + abs(h[index + 2] - h[index]));
	}
	cout << DP[N - 1];
	return 0;
}


Measured memory_bytes: 1408
A,B,C=map(int,input().split())
K=int(input())

nax=2**K

if A<B and B<C:
    print('Yes')
else:
    count=0
    while B<=A:
        B=B*2
        count+=1
    C=C*(2**(K-count))
    if A<B and B<C:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9112
#include <stdio.h>
int main (void) {
    long long num,temp,sum=0,i;
    scanf("%lld\n",&num);
    for (i=0; i<num; i++) {
        scanf("%lld",&temp);
        sum+=temp;
    }
    printf("%lld\n",sum/num);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

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

  V<int> w(n + 1, 0);
  V<int> e(n + 1, 0);

  repf(i, 0, n) {
    w[i + 1] += w[i] + (s[i] == 'W' ? 1 : 0);
    e[i + 1] += e[i] + (s[i] == 'E' ? 1 : 0);
  }

  int min_reverse = n;
  rep(i, n) {
    int west_reverse_count = w[i] - w[0];
    int east_reverse_count = e[n] - e[i + 1];

    min_reverse = min(min_reverse, west_reverse_count + east_reverse_count);
  }

  cout << min_reverse << endl;
}


Measured memory_bytes: 6124
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];


ll root(ll* a,ll A)
{
    while(a[A]!=A)
    {
        a[A]=a[a[A]];
        A=a[A];    
    }
    return A;    
}
 
void WeightedUnion(ll* a,ll* s,ll x,ll y)
{
    ll root_x=root(a,x);
    ll root_y=root(a,y);
	if(root_x==root_y)
	return;
    if(s[root_x]<s[root_y])
    {
        a[root_x]=a[root_y];
        s[root_y]+=s[root_x];    
    }
    else
    {
        a[root_y]=a[root_x];
        s[root_x]+=s[root_y];    
    }    
}
 
bool Find(ll* a,ll x,ll y)
{
    if(root(a,x)==root(a,y))
    return true;
    
    return false;
}


int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
	cin>>n;
	
	//Forming set Array and size Array.
	ll a[n],s[n];
	for(i=0;i<n;i++)
	{
		a[i]=i;
		s[i]=1;
	}

	cin>>q;
	while(q--)
	{
		cin>>x>>y;
		x--;
		y--;
		WeightedUnion(a,s,x,y);
	}

	ll maxi=INT_MIN;
	Ff(i,0,n)
	{
		// cout<<s[i]<<" ";
		maxi=max(maxi,s[root(a,i)]);
	}
	cout<<maxi;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 13776
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define bg begin()
#define en end()
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
    return b;
    else
    return gcd(b%a,a);
}
ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = -1000000000000000, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 
ll countPairs(ll arr[], ll n) 
{ 
    map<ll, ll> map; 
    for (ll i = 0; i < n; i++) {
        if (map.find(arr[i]-i) == map.end()) { 
            map[arr[i]-i] = 1; 
        } 
        else { 
            map[arr[i]-i]++; 
        } 
    }
    ll res = 0; 
    for (auto x : map) { 
        ll cnt = x.second; 

        res += ((cnt * (cnt - 1)) / 2); 
    } 
  
    return res; 
} 
ll findSubarraySum(ll arr[], ll n, ll sum) 
{ 
    unordered_map<ll, ll> prevSum; 
  
    int res = 0; 
  
    int currsum = 0; 
  
    for (int i = 0; i < n; i++) { 
        currsum += arr[i]; 
        if (currsum == sum)  
            res++;         
  
        if (prevSum.find(currsum - sum) !=  
                                  prevSum.end())  
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++; 
    } 
  
    return res; 
} 
ll sod(ll x){
    ll r,sum=0;
    while(x>0){
        r=x%10;
        x/=10;
        sum+=r;
    }
    return sum;
}
long long modpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    fast
    ll n,i;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 5204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
const long long int MAX_N = 300000;

int main(int argc, char const *argv[]) {
  long long int n, ans = MAX_N;
  string s;
  cin >> n;
  cin >> s;
  vector<char> svec;

  for (size_t i = 0; i < n; i++) {
    svec.push_back(s[i]);
  }
  long long int cnt=count(svec.begin(), svec.end(), 'E');
  for (size_t i = 0; i < n; i++) {
    if (svec[i]=='E') cnt--;
    if (cnt <= ans) ans = cnt;
    if (svec[i]=='W') cnt++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
const int maxn = 2e5;
int n;
ll lim, a[maxn];
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> lim;
	for (int i = 1;i <= n;++i)
		cin >> a[i];
	for (int i = 1;i < n;++i) if (a[i] + a[i+1] >= lim) {
		cout << "Possible\n";
		for (int j = 1;j < i;++j)
			cout << j << '\n';
		for (int j = n-1;j > i;--j)
			cout << j << '\n';
		cout << i << '\n';
		return 0;
	}
	cout << "Impossible\n";
}



Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	
	static final int x = 1000000007;

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

		// nCr取得用テーブル作成
		int height = n - k + 1 > k - 1 ? n - k + 1 : k - 1;
		int width = k;
		long[][] tb = makePscalsTable(height + 1, width + 1);

		for ( int i = 1; i <= k; i++ ) {
			if ( n - k + 1 < i ) {
				System.out.println("0");
				continue;
			}
			// (n-k)個の赤玉の隙間＋両サイド (n-k+1)カ所から青のグループを差し込むiカ所を選ぶ
			long res2 = tb[n - k + 1 - i][i];   //nCr(n - k + 1, i);

			// k個の青ボールをi個のグループ順列に分ける（全グループに最低一つ配る） 
			// → (k-1)カ所の隙間から(i-1)カ所選んで仕切りを差し込む並べ方に等しい
			long res1 = tb[k - 1 - (i - 1)][i - 1];     //nCr(k - 1, i - 1);

			System.out.println((res1 * res2) % x);
		}
		in.close();
	}

	// nCr = tb[n-r][r]
	private static long[][] makePscalsTable(int height, int width) {
		long[][] tb = new long[height][width];
		tb[0][0] = 1;

		for ( int row = 0; row < height; row++ ) {
			for ( int col = 0; col < width; col++ ) {
				if ( 0 < col ) tb[row][col] += tb[row][col - 1]; // 左を加算
				if ( 0 < row ) tb[row][col] += tb[row - 1][col]; // 上を加算
				if ( tb[row][col] > x ) tb[row][col] %= x;
			}
		}
		return tb;
	}
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

#define X first
#define Y second

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

const double PI = 3.14159265358979;

P mp[90090];
ll ans[90090];

void solve()
{
  int h, w, d, inum;
  cin >> h >> w >> d;
  for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j)
  {
    cin >> inum;
    mp[inum] = P(j, i);
  }

  for(int i = 1; i <= d; ++i)
  {
    P now_p = mp[i];
    ll cost = 0;
    int now = i + d;
    while(now <= h * w)
    {
      P next_p = mp[now];
      cost += abs(now_p.X - next_p.X) + abs(now_p.Y - next_p.Y);
      ans[now] = cost;
      now_p = next_p;
      now += d;
    }
  }

  int q, l, r;
  cin >> q;
  for(int i = 0; i < q; ++i)
  {
    cin >> l >> r;
    cout << ans[r] - ans[l] << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 5024
#include<stdio.h>
int main()
{
  int h,n,a;
  int sum=0;
  scanf("%d %d",&h,&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    sum+=a;
  }
  if(h<=sum){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
var
	i,j,h,w,n,a,c,t:Longint;
	u:array[1..100]of Longint;
begin
	t:=1;
	read(h,w,n,a);
	for i:=1 to h do begin
		if i mod 2=1 then begin
			for j:=1 to w do begin
				writeln(t);
				inc(c);
				if a=c then begin
					read(a);
					c:=0;
					inc(t);
				end;
			end;
		end else begin
			for j:=w downto 1 do begin
				u[j]:=t;
				inc(c);
				if a=c then begin
					read(a);
					c:=0;
					inc(t);
				end;
			end;
			for j:=1 to w do writeln(u[j]);
		end;
	end;
end.


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

int main(){
	string s;
	cin >> s;
	int64_t a[26]{};
	for(char c:s) a[c - 'a']++;
	int64_t n = s.size(), ans = n * (n - 1) / 2 + 1;
	for(int i = 0; i < 26; i++){
		ans -= a[i] * (a[i] - 1) / 2;
	}
	cout << ans << endl;
}

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

int main() {
    int n, m, x;
    scanf("%d%d%d", &n, &m, &x);
    int pedagio[m+5];
    for(int i=0; i<m; ++i)
        scanf("%d", &pedagio[i]);
    int c1 = 0, c2 = 0;
    for(int i=0; i<=n; ++i) {
        if (i<x) {
            for (int j=0; j<m; ++j){
                if (i==pedagio[j])
                    ++c1;
            }
        } else {
            for (int j=0; j<m; ++j){
                if (i==pedagio[j])
                    ++c2;
            }
        }
    }
    int z;
    if (c1>c2)
        z = c2;
    else
        z = c1;
    printf("%d\n", z);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int i,n,a[100];
  int flag = 0;
 
  while(1){
  scanf("%d",&n); 
    if(0 < n <= 100)
      break;
  }
 
  for(i=0;i<n;i++){
    
    while(1){
     scanf("%d",&a[i]); 
      if(0 < a[i] <= 1000)
        break;
    }
    
    if (a[i] % 2 == 0 ){
    if( a[i] % 3 != 0 && a[i] % 5 != 0) 
    flag = 1;
    }
  }
       
  if(flag == 0)
    printf("APPROVED\n");
  else
    printf("DENIED\n");
  
  return 0;
}
   

Measured memory_bytes: 128
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;
    ll ans = 1;
    for (int i = 1; i <= n; ++i) {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long int64;
constexpr int p = 1e9+7;
constexpr long long M = 0x777777777777777777777777777777777777777LL;

int N;
int a[408];
int64 dp[408][408];

int64 solve(int begin, int end) {
    if(begin==end) {
        return 0;
    }
    if(!dp[begin][end]) {
        int64 ret = M;
        for(int i=begin; i<end; ++i) {
            ret = min(ret, solve(begin, i) + solve(i+1, end));
        }
        for(int i=begin; i<=end; ++i) {
            ret += a[i];
        }
        dp[begin][end] = ret ^ M;
    }
    return dp[begin][end] ^ M;
}

int main() {
	scanf("%d", &N);
    for(int n=0; n<N; ++n) {
        scanf("%d", &a[n]);
    }
    printf("%lld\n", solve(0, N-1));
	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
	int i,j,min,N,ans=0,memo[100001]={0};
	scanf("%d",&N);

	for(i=1;i<=N;i++){
		min=memo[i-1];
		if(i>=6 && min>memo[i-6])min=memo[i-6];
		if(i>=9 && min>memo[i-9])min=memo[i-9];
		if(i>=36 && min>memo[i-36])min=memo[i-36];
		if(i>=81 && min>memo[i-81])min=memo[i-81];
		if(i>=216 && min>memo[i-216])min=memo[i-216];
		if(i>=729 && min>memo[i-729])min=memo[i-729];
		if(i>=1296 && min>memo[i-1296])min=memo[i-1296];
		if(i>=6561 && min>memo[i-6561])min=memo[i-6561];
		if(i>=7776 && min>memo[i-7776])min=memo[i-7776];
		if(i>=46656 && min>memo[i-46656])min=memo[i-46656];
		if(i>=59049 && min>memo[i-59049])min=memo[i-59049];

		memo[i]=min+1;
	}

	printf("%d\n",memo[N]);
	return 0;
}

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

signed main() {
	string r,s,t;
	cin>>r; s=r+r;
	cin>>t;

	vector<vector<ll>> s_position(26,vector<ll>());
	vector<ll> t_num(26,0);
	rep(i,s.size()){
		ll ch=s[i]-'a';
		s_position[ch].push_back(i);
	}
	rep(i,t.size()){
		ll ch=t[i]-'a';
		t_num[ch]++;
	}
	rep(i,26){
		if(s_position[i].size()==0 && t_num[i]>0){
			cout<<-1<<endl;
			return 0;
		}
	}

	ll ans=0;
	ll position=0;
	rep(i,t.size()){
		ll ch=t[i]-'a';
		auto it=lower_bound(s_position[ch].begin(), s_position[ch].end(), position);
		ans+=*it-position+1;
		position=*it+1;
		if(position>=r.size())position-=r.size();
	}
	cout<<ans<<endl;
	return 0;
}


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

int main () {
  
  int num = 5, ans = 0;
  int dish[num], time[num] = {};
  for (int i = 0; i < num; i++) {
    cin >> dish[i];
    while (1) {
      if (time[i] - dish[i] >= 0) {
        break;
      }
      time[i] += 10;
    }
    ans += time[i];
  }
  
  int x[num], y = 0;
  for (int i = 0; i < num; i++) {
    x[i] = time[i] - dish[i];
    y = max(y, x[i]);
  }
  
  ans -= y;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int h, m, s, S;
  int min=60;
  int hour=min*min;
  
  scanf("%d", &S);
  h=S/hour;
  m=(S-h*hour)/min;
  s=S-h*hour-m*min;
  printf("%d:%d:%d\n", h, m, s);
  return(0);
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector> 
#include<algorithm> 
using namespace std;
int main(){
	long long num;
	cin>>num;
	vector<int>s;
	while(num){
		if(num%26){
			s.push_back(num%26);
		}else{
			s.push_back(26);
			num-=26;
		}
		num/=26;
	}
	reverse(s.begin(),s.end());
	string ans;
	for(int &n:s){
		char b='a'+n-1; 
		ans+=b;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3124
import sys
h,w = map(int,input().split())
ls = ["0"*(w+2)]
ls += ["0" + str(input()) + "0" for _ in range(h)]
ls += ["0"*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if ls[i][j] == "#":
            if ls[i-1][j] != "#" and ls[i+1][j] != "#" and ls[i][j-1] != "#" and ls[i][j+1] != "#":
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3064