akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int N;
	int i;
	
	cin >> N >> i;

	cout << N - i + 1 << endl;

}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  double m;
  cin>>n>>m;
  vector<double> a(n);
  double sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  double x=1/(4*m);
  double ans=0;
  rep(i,n){
    if(a[i]>=sum*x){
      ans++;
    }
  }
  if(ans>=m) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3708
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    string s,t;
    cin >> s>>t;
    int ans = 0;
    rep(i,s.length()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3860
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()

h = []
ans = 10**10

for _ in range(n):
    h.append(inint())

h.sort()

for i in range(n-k+1):
    if h[i+k-1] - h[i] < ans:
        ans = h[i+k-1] - h[i]

print(ans)

Measured memory_bytes: 76580
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cmath>

using namespace std;
bool bs(vector<int>::iterator b, vector<int>::iterator e, int target)
{
    int d = distance(b, e);
    while (d)
    {
        auto m = next(b, d / 2);
        if (target == *m)
            return true;
        if (target < *m)
            e = m;
        else
            b = m + 1;
        d = distance(b, e);
    }
    return false;
}
int main()
{
    int n;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i < n; i++)
    {
        cin >> S[i];
    }
    int c = 0;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        c += bs(S.begin(), S.end(), t);
    }
    cout << c << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int>v;
    int n,j = 1;
    cin >> n;
    int A[n] = {0};
    for(int i=0;i<n;i++)
    {
      cin >> A[i];
      if(A[i] == j)
      {  
        v.push_back(A[i]);
        j++;
      }
    }
    if((int)v.size() == 0)
    {
      cout << -1;
    }
    else
    {
      cout << n - (int)v.size();
    }
  return 0;
}

Measured memory_bytes: 2168
#include <iostream>
using namespace std;
int main() {
    string x;
    int ans,i;
    while (cin>>x && x != "0") {
        ans = 0;
        for (i=0;i<x.size();i++) {
            ans += x[i] - '0';
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
s = {}
t = {}
result = []
n = gets.to_i
n.times.each do |i|
  text = gets.chomp.to_s
  s[text] = s[text].nil? ? 1 : s[text] + 1
end
m = gets.to_i
m.times.each do |i|
  text = gets.chomp.to_s
  t[text] = t[text].nil? ? 1 : t[text] + 1
end

s.each do |key, value|
  result.push(value - t[key].to_i)
end

puts result.max >= 0 ? result.max : 0


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

void trace(const vector<int>& a) {
  for (auto it = a.begin() + 1; it < a.end(); ++it) {
    cout << *it << ((it + 1 != a.end())? " " : "\n");
  }
}

void countingSort(vector<int>& A, vector<int>& B, int k) {
  vector<int> C(k + 1, 0);

  size_t n = A.size() - 1;
  for (size_t j = 1; j <= n; ++j) ++C[A[j]];
  for (int i = 1; i <= k; ++i) C[i] += C[i - 1];

  for (size_t i = n; i != 0; --i) {
    B[C[A[i]]] = A[i];
    --C[A[i]];
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n + 1);
  for (int i = 1; i <= n; ++i) cin >> A[i];
  vector<int> B(n + 1);
  countingSort(A, B, 10000);
  trace(B);
}



Measured memory_bytes: 18300
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  if(b>c && d>a){
    ans = min(b,d) - max(a,c);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;
set<int> pr;
void SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          pr.insert(p); 
} 

int main(){
    FASTIO
    int n;
    cin >> n;
    SieveOfEratosthenes(1000000);
    cout << *(pr.lower_bound(n));
     return 0;
}


Measured memory_bytes: 4864
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        PriorityQueue<int> pqueue = new PriorityQueue<int>(true);
        while (true)
        {
            var query = Console.ReadLine().Split();
            if (query[0] == "extract") Console.WriteLine(pqueue.Pop());
            else if (query[0] == "insert") pqueue.Push(int.Parse(query[1]));
            else break;
        }
    }
}

class PriorityQueue<T> where T : IComparable<T>
{
    public int Count { get; private set; }
    private bool Descendance;
    private T[] data = new T[65536];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public PriorityQueue(bool descendance = false) { Descendance = descendance; }
    public T Top
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { ValidateNonEmpty(); return data[1]; }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Pop()
    {
        var top = Top;
        var elem = data[Count--];
        int index = 1;
        while (true)
        {
            if ((index << 1) >= Count)
            {
                if (index << 1 > Count) break;
                if (elem.CompareTo(data[index << 1]) > 0 ^ Descendance) data[index] = data[index <<= 1];
                else break;
            }
            else
            {
                var nextIndex = data[index << 1].CompareTo(data[(index << 1) + 1]) <= 0 ^ Descendance ? (index << 1) : (index << 1) + 1;
                if (elem.CompareTo(data[nextIndex]) > 0 ^ Descendance) data[index] = data[index = nextIndex];
                else break;
            }
        }
        data[index] = elem;
        return top;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Push(T value)
    {
        int index = ++Count;
        if (data.Length == Count) Extend(data.Length * 2);
        while ((index >> 1) != 0)
        {
            if (data[index >> 1].CompareTo(value) > 0 ^ Descendance) data[index] = data[index >>= 1];
            else break;
        }
        data[index] = value;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private void Extend(int newSize)
    {
        T[] newDatas = new T[newSize];
        data.CopyTo(newDatas, 0);
        data = newDatas;
    }
    private void ValidateNonEmpty() { if (Count == 0) throw new Exception(); }
}



Measured memory_bytes: 27300
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
using namespace std;
typedef long long s64;

const int ONE = 5005;
const int MOD = 1e9 + 7;

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

int n, m;
s64 sum[ONE];
int A[ONE][ONE];
s64 Ans;
int maxx;
set <int, greater<int> > S[ONE];

struct Seg
{
		struct power {int val;} Node[ONE * 4];
		void Update(int i, int l, int r, int L, int x)
		{
			if(L <= l && r <= L)
			{
				Node[i].val = max(Node[i].val, x);
				return;
			}
			int mid = l + r >> 1;
			if(L <= mid) Update(i << 1, l, mid, L, x);
			else Update(i << 1 | 1, mid + 1, r, L, x);
			Node[i].val = max(Node[i << 1].val, Node[i << 1 | 1].val);
		}
		void Query(int i, int l, int r, int L, int R)
		{
			if(L <= l && r <= R)
			{
				maxx = max(maxx, Node[i].val);
				return;
			}
			int mid = l + r >> 1;
			if(L <= mid) Query(i << 1, l, mid, L, R);
			if(mid + 1 <= R) Query(i << 1 | 1, mid + 1, r, L, R);
		}
}C[205];

void Deal(int l, int r, int L, int R) //j=l~r, from=L~R
{
		if(l > r) return;
		int mid = l + r >> 1, MidFrom;
		
		s64 val = 0;
		for(int from = L; from <= R; from++)
		{
			if(from > mid) break;

			s64 res = -(sum[mid] - sum[from]);
			for(int j = 1; j <= m; j++)
			{
				maxx = 0, C[j].Query(1, 1, n, from, mid);
				res += maxx;
			}

			if(res > val) val = res, MidFrom = from;
		}

		Ans = max(Ans, val);
		Deal(l, mid - 1, L, MidFrom);
		Deal(mid + 1, r, MidFrom, R);
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get(), m = get();
		for(int i = 2; i <= n; i++) sum[i] = sum[i - 1] + get();
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				C[j].Update(1, 1, n, i, get());

		Deal(1, n, 1, n);

		printf("%lld", Ans);
}

Measured memory_bytes: 16384
-- vim: set fdm=marker : -- {{{
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.Fix (fix)
import Data.Maybe
import Data.Array.Unboxed
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
-- }}}

-- Input functions with ByteString
-- {{{
tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

readInt :: Num a => BS.ByteString -> a
readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntTuple :: Num a => BS.ByteString -> (a, a)
readIntTuple = tuplify2 . map readInt . BS.words
readIntList :: Num a => BS.ByteString -> [a]
readIntList = map readInt . BS.words

getInt :: Num a => IO a
getInt = readInt <$> BS.getLine
getIntList :: Num a => IO [a]
getIntList = readIntList <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents
-- }}}

main = do
    [n,d] <- getIntList :: IO [Int]
    xss <- getIntNList n :: IO [[Int]]
    print $ solve n xss

solve :: Int -> [[Int]] -> Int
solve n xss = length [() | i <- [0..(n-1)], j <- [(i+1)..(n-1)], isInt (xss!!i) (xss!!j)]

isInt :: [Int] -> [Int] -> Bool
isInt xi xj = isSquare . sum $ zipWith sqMul xi xj where
  sqMul x y = (x - y) * (x - y)

isSquare :: (Integral a) => a -> Bool
isSquare n = (round . sqrt $ fromIntegral n) ^ 2 == n


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mod=1e9+7;
int n,a[21][21],dp[21][1<<21];
int go(int p,int s) {
	if(p==n) return 1;
	if(dp[p][s]!=-1) return dp[p][s];
	int& ret=dp[p][s]=0;
	int i;
	for(i=0;i<n;i++) {
		if(!a[p][i]) continue;
		if(s>>i&1) continue;
		ret=(ret+go(p+1,s|(1<<i)))%mod;
	}
	return ret;
}
int main() {
	memset(dp,-1,sizeof(dp));
	scanf("%d",&n);
	int i,j,k;
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);
	printf("%d",go(0,0));
	return 0;
}

Measured memory_bytes: 172288
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans;
long long fa[500100];
long long find(long long x)
{
    if (x!=fa[x])
    {
        fa[x]=find(fa[x]);
    }
    return fa[x];
}
void merge(long long x,long long y)
{
    x=find(x);
    y=find(y);
    if (x!=y)
    {
        fa[x]=y;
    }
    return;
}
void init()
{
    for (long long i=1;i<=n;i++)
    {
        fa[i]=i;
    }
    return;
}
int main()
{
    cin>>n>>m;
    init();
    for (long long i=1;i<=m;i++)
    {
        long long a,b;
        cin>>a>>b;
        merge(a,b);
    }
    for (long long i=1;i<=n;i++)
    {
        if (fa[i]==i)
        {
            ans++;
        }
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 4424
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int p[1111];

int main(void){
	int n,k,i,ans=0;
	std::cin >> n >> k;
	for(i=0; i<n; ++i){
		std::cin >> p[i];
	}
	std::sort(p,p+n);
	for(i=0; i<k; ++i){
		ans += p[i];
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int F[MAX_N];
int NS;
int NT;
int S[MAX_N];
int T[MAX_N];

bool flag;
int target;

void print(int F[], int N){
	rep(i, N){ cout << F[i] << " "; }
	cout << endl;
}

void Judge(int A[], int F[], int N){
	int ret = 0;
	rep(i, N){ ret += A[i] * F[i]; }
	if (ret == target) flag = true;
}

void rec(int A[], int F[], int N, int i){
	if (i == N) {
		Judge(A, F, N);
		return;
	}

	F[i] = 0;
	rec(A, F, N, i + 1);

	F[i] = 1;
	rec(A, F, N, i + 1);

};


int main() {

	cin >> NS;
	rep(i, NS){ cin >> S[i]; }
	cin >> NT;
	rep(i, NT){ cin >> T[i]; }

	rep(i, NT){
		flag = false;
		target = T[i];
		rec(S, F, NS, 0);
		cout << (flag ? "yes" : "no") << endl;
	}
}

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

//Contest
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int[]w = new int[10];
		int[]k = new int[10];
		for(int i=0;i<10;i++)w[i]=sc.nextInt();
		for(int i=0;i<10;i++)k[i]=sc.nextInt();
		Arrays.sort(w);
		Arrays.sort(k);
		System.out.println((w[7]+w[8]+w[9])+" "+(k[7]+k[8]+k[9]));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import sys
sys.setrecursionlimit(10**7)
import math
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def TWO(M):
  L=[0]*M
  R=[0]*M
  for i in range(M):
    L[i],R[i] = II()
  return L, R
N = I()
a = L()
ans = [-1]*(N)
for i in range(N)[::-1]:
  temp = N//(i+1)
  x = []
  for j in range(2,temp+1):
    x.append(ans[(i+1)*j-1])
  ans[i] = abs(a[i]-sum(x)%2)
  #print(i+1, x, ans)

print(ans.count(1))
ans_tmp = []
for i in range(N):
  if ans[i]==1:
    ans_tmp.append(i+1)
print(*ans_tmp)

Measured memory_bytes: 88040
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//Books
public class Main{

	List<Integer>[] b;
	int[][] sell, dp;
	int n, k, NOT = -2;
	
	int get(int g, int rest){
		if(rest<0)return -1;
		if(g==11)return rest==0?0:-1;
		if(dp[g][rest]!=NOT)return dp[g][rest];
		int res = -1;
		for(int v=0;v<=Math.min(rest, b[g].size());v++){
			int x = get(g+1, rest-v);
			if(x==-1)continue;
			res = Math.max(res, x+sell[g][v]);
		}
		return dp[g][rest] = res;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		b = new List[11];
		for(int i=1;i<11;i++)b[i]=new ArrayList<Integer>();
		sell = new int[11][2001];
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt(); k = sc.nextInt();
		while(n--!=0){
			int c = sc.nextInt(), g = sc.nextInt();
			b[g].add(c);
		}
		for(int i=1;i<11;i++){
			Collections.sort(b[i]);
			int s = 0;
			for(int j=1;j<=b[i].size();j++){
				s += b[i].get(b[i].size()-j);
				sell[i][j] = s + (j-1)*j;
			}
		}
		dp = new int[11][k+1];
		for(int[]a:dp)Arrays.fill(a, NOT);
		System.out.println(get(1, k));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n;
  cin >> n;
  map<string, int> s, t;
  rep(i, 0, n) {
    string tmp;
    cin >> tmp;
    s[tmp]++;
  }
  int m;
  cin >> m;
  rep(i, 0, m) {
    string tmp;
    cin >> tmp;
    t[tmp]++;
  }

  int rsl = 0;
  for(map<string, int>::iterator it = s.begin(); it != s.end(); ++it) {
    rsl = max(it->second - t[it->first], rsl);
  }
  cout << rsl << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mx 1e9
int main()
{
 ll n;
 cin>>n;
 for(int i=1;i<=10000;i++)
 {
   ll k=i*1000;
   if(k<n)
   {
    continue;
   }
   else
   {
       cout<<(i*1000)-n<<endl;
       break;
   }
  }
 }


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

int N;
int ll,rr;
string S;

int main()
{
    scanf("%d",&N);
    int l = 0,r = N - 1;
    printf("0\n");
    fflush(stdin);
    cin >> S;
    if(S == "Vacant")
    {
        printf("0\n");
        return 0;
    }
    if(S == "Male")ll = 0,rr = 1;
    else ll = 1,rr = 0;
    printf("%d\n",N - 1);
    fflush(stdin);
    cin >> S;
    if(S == "Vacant")
    {
        printf("%d\n",N);
        return 0;
    }

    while(1)
    {
        int m = (l + r) / 2,mm;
        printf("%d\n",m);
        fflush(stdin);
        cin >> S;
        if(S == "Vacant")
        {
            printf("%d\n",m);
            return 0;
        }
        if(S == "Male")mm = 0;
        else mm = 1;
        if((((m - l) % 2) && ll == mm) || (((m - l) % 2 == 0) && ll != mm))r = m,rr = mm;
        else l = m,ll = mm;
    }
    return 0;
}


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

int main(){
  int n, m, r, l, ans;
  cin >> n >> m;
  int amin = 0, amax = n;
  
  rep(i, m){
    cin >> l >> r;
    if(l > amin) amin = l;
	if(r < amax) amax = r;
  }
  ans = max((amax-amin+1), 0);
  cout << ans << endl;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    for(int i = 0; i < B; i++){
        if(A * i % B == C){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[]
for i in range(N):
    B=list(input().split())
    for j in range(1,int(B[0])+1):
        A.append(B[j])
count=0
for k in range(M+1):
    if A.count(str(k))==N:
        count+=1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  string s = stin(), p = stin();
  s += s;
  rep(i,s.size()) {
    if (s.find(p) != string::npos) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3168
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
    char a[5];
    cin>>a;
    for(int i=0;i<5;i++)
    if(a[i]=='A'&&a[i+1]=='C')
    {cout<<"Yes"<<endl; return 0;}
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def main():
    N, K = map(int, input().split())
    S = input()

    t = 0
    for i in range(N-1):
        if S[i] != S[i+1]:
            t += 1

    x = (N-1-t) + min(t//2, K)*2

    if t%2 == 1 and t//2 < K:
        x += 1

    print(x)



if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> A;
  int n;
  int a;
  cin >> n;
  REP(i,n){
      cin >> a;
      A.push_back(a);
  }
  SORT(A);
  REV(A);
  ll ans = 1;
  int cnt = 0;
  REP(i,n-1){
      if (A[i]==A[i+1]){
          cnt++;
          ans*=A[i];
          i++;
          if (cnt==2){
              cout << ans << endl;
              return 0;
          }
      }
  }
  cout << 0 << endl;
}


Measured memory_bytes: 892
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)




int main()
{
  // input & declare
  int n;
  cin >> n;
  std::vector<int> v;
  int tmp;
  for(int i = 0; i < n; i++)
  {
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  int ans = 0;
  for(int i = n-1; i >= 0; i-=2){
    ans += v[i];
    ans -= v[i-1];
  }

  std::cout << ans << '\n';
  // process


  // output

}


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

int main() {
  string S, T, X, Y;
  cin >> S >> T;

  vector<char> A(S.size());
  for (int i = 0; i < S.size() ; i++) A.at(i) = S.at(i);

  sort(A.begin(), A.end());

  for (int i = 0; i < A.size(); i++) X += A.at(i);

  vector<char> B(T.size() );
  for (int i = 0; i < T.size() ; i++) B.at(i) = T.at(i);

  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  for (int i = 0; i < B.size(); i++) Y += B.at(i);

  cout << (X < Y ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n,k=(int(i) for i in input().split())

e = [[int(i) for i in input().split()] for j in range(n)]
#print(e)

dp=[[0 for i in range(k+1)] for j in range(n)]

for j in range(k+1):
    if j >= e[0][0]:
      dp[0][j]=e[0][1]

for i in range(1,n):
  for j in range(k+1):
    if j < e[i][0]:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-e[i][0]]+e[i][1])

print(max(dp[n-1]))


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

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

    if(n==0)
      break;

    char c[100];
    for(int i=0;i<n;i++){
      cin >> c[i];
    }

    int cou[26]={0};
    for(int i=0;i<n;i++){
      cou[(int)(c[i]-'A')]++; //アスキーコードの差でアルファベットの何番目か算出する
      int top=-1;
      int top2=-1;

      for(int j=0;j<26;j++){
        if(cou[j]>top){
          top2=top;
          top=cou[j];
        }else if(cou[j]>top2){
          top2=cou[j];
        }
      }

      if((top-top2)>(n-(i+1))){
        for(int j=0;j<26;j++){
          if(cou[j]==top){
            cout << (char)(j+'A') << ' ';
            break;
          }
        }
        cout << i+1 << endl;
        break;
      }

      if(i==n-1){
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <cstdlib>
#include <array>
#include <list>
#include <math.h>
using namespace std;

int main()
{
    int n, a;
    cin >> n >> a;
    if(n % 500 <= a){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int cnt = 0;
	if (s[0] == s[1]) ++cnt;
	if (s[0] == s[2]) ++cnt;
	if (s[0] == s[3]) ++cnt;
	if (s[1] == s[2]) ++cnt;
	if (s[1] == s[3]) ++cnt;
	if (s[2] == s[3]) ++cnt;
	cout << (cnt == 2 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.trim().split(' ')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	const c = parseInt(args[2], 10)
	console.log(Math.min(Math.floor(b / a), c))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    string s;
    int l = 0, r = 0;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A'){
            l = i;
            break;
        }
    }
    for(int i = s.length() - 1; i >= 0; i--){
        if(s[i] == 'Z'){
            r = i;
            break;
        }
    }
    cout << r - l + 1 << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
pair <ll, ll> arr[MAXN];
ll hi, lo;

int main()
{
    ios_base::sync_with_stdio(0);
    
    hi = -1e12;
    lo = 1e12;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i].first >> arr[i].second;
        if (arr[i].first > arr[i].second)
            swap (arr[i].first, arr[i].second);

        lo = min (lo, arr[i].first);
        hi = max (hi, arr[i].second);
    }
    sort (arr, arr + N);

    ll hmin = hi;
    for (int i = 0; i < N; i++)
        hmin = min (hmin, arr[i].second);
    ll ans = (hi - hmin) * (arr[N-1].first - lo);

    ll nhi = -1e9, nlo = 1e9;
    for (int i = 0; i < N - 1; i++)
    {
        nhi = max (nhi, arr[i].second);
        nlo = min (nlo, arr[i].second);
        ans = min (ans, (max (nhi, arr[N-1].first) - min (nlo, arr[i+1].first)) * (hi - lo));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, x, a[100015], ans = INF;

int gcd(int l, int r)
{
    if(l < r){
        int c = l;
        l = r;
        r = c;
    }
    if(l % r == 0){
        return r;
    }
    else{
        return (r, l % r);
    }
}

signed main()
{
    cin >> n >> x;
    for(int i = 0; i < n ;i++){
        cin >> a[i];
    }
    ans = abs(a[0] - x);
    for(int i = 1; i < n; i++){
        ans = gcd(ans, abs(a[i] - x));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		assert solve(4, 4, 6) == 5;
		assert solve(5, 4, 3) == 0;
		assert solve(1, 7, 10) == 0;
		assert solve(1, 3, 3) == 1;

		long n = cin.nextInt();
		long a = cin.nextInt();
		long b = cin.nextInt();
		long ans = solve(n, a, b);
		cout.println(ans);
	}

	private static long solve(long n, long a, long b) {
		long min = a * (n - 1) + b;
		long max = b * (n - 1) + a;
		long ans = Math.max(max - min + 1, 0);
		return ans;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 23252
n, k= map(int, input().split())
num = list(range(1, n+1))
c = set()
num = set(num)
for i in range(k):
  a = input()
  b = set(list(map(int, input().split())))
  c = c.union(b)
num = list(num -c)
print(len(num))

Measured memory_bytes: 67236
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    int cards[4][13];
    int n,p;
    char r;
    cin >> n;
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            cards[i][j]=0;
        }
    }
    for(int i = 0; i < n; i++) {
        cin >> r;
        cin >> p;
        if(r == 'S'){
            cards[0][p-1] = 1;
        }else if(r == 'H'){
            cards[1][p-1] = 1;
        }else if(r == 'C'){
            cards[2][p-1] = 1;
        }else if(r == 'D'){
            cards[3][p-1] = 1;
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(cards[i][j] == 0 ){
                if(i == 0){
                    cout << "S " << j + 1 << endl;
                }else if(i == 1){
                    cout << "H " << j + 1 << endl;
                }else if(i == 2){
                    cout << "C " << j + 1 << endl;
                }else if(i == 3){
                    cout << "D " << j + 1 << endl;
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>

int main(void) {
	int n,m;
	int i;
	int flag = 0;
	int iki[200000];
	int kaeri[200000];
	int a,b;
	
	scanf("%d %d",&n,&m);
	
	for(i=0;i<n;i++){
		iki[i] = 0;
		kaeri[i] = 0;
	}
	
	for(i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		if(a==1) iki[b]=1;
		if(b==n) kaeri[a]=1;
	}
	for(i=0;i<n;i++){
		if((iki[i] == 1)&&(kaeri[i] == 1)){
			printf("POSSIBLE");
			flag = 1;
			break;
		}
	}
	if(flag == 0){
		printf("IMPOSSIBLE");
	}
	return 0;
}

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

string t(ll n, int d){
  if(n == 0)return "";

  ll a = abs(n)%10;
  if((n<0) ^ (d&1)){
    if(a) a = 10 - a;
    n += (n<0?-1:1) * a;
  }
  return t(n/10,d+1) + (char)('0'+a);
}

int main(){
  ll n;
  while(cin >> n, n){
    cout << t(n,0) << endl;
  }    
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
int vec[100];
int main() {
  int N;
  cin >> N;
  int Answer;
  for ( int i = 0 ; i < N ; i++ ) {
    cin >> vec[i];
    int X = 0;
    for ( int j = 0 ; j < i ; j++ ) {
      if ( vec[i] != vec[j] ) {
        X++;
      }
    }
    if ( X == i ) {
      Answer++;
    }
  }
  cout << Answer << endl;   
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include <deque>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
using namespace std;
typedef pair<int,int> pii;
#define f first
#define s second
bool skip[505];
int main() {
	int n; cin >> n;
	vector<pii> p(n),q(n);
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d %d",&p[i].f,&p[i].s);
	}
	for (int i = 0 ; i < n ; ++i) {
		scanf("%d %d",&q[i].f,&q[i].s);
	}
	int match = 0;
	sort(all(p)), sort(all(q));
	for (int i = sz(p) - 1 ; i >= 0; -- i) {
		int ans = 1 << 30, ind = -1;
		REP(j,q) {
			if (skip[j] || p[i].f >= q[j].f) {
				continue;
			}

			if (p[i].s < q[j].s) {
				if (q[j].s < ans) {
					ans = q[j].s, ind = j;
				}
			}
		}
		if (ind != -1) {
			skip[ind] = 1;
			++match;
		}
	}
	cout << match << "\n";


}


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

using namespace std;

int main()
{
    int N,a;
    cin >> N;
    map< int, vector<int> >  L,R;
    long long ans(0), tmp(0);
    int n,m;

    for(int i=0;i<N;++i){
        cin >> a;
        if(L.find(i+a)==L.end()){
            L[i+a] = {i};
        }else{
            L.at(i+a).push_back(i);
        }

        if(R.find(i-a)==R.end()){
            R[i-a] = {i};
        }else{
            R.at(i-a).push_back(i);
        }
    }

    // for(auto e:L){
    //     cout << e.first << " : ";
    //     for(auto x:e.second){
    //         cout << x << ", ";
    //     }
    //     cout << endl;
    // }
    // for(auto e:R){
    //     cout << e.first << " : ";
    //     for(auto x:e.second){
    //         cout << x << ", ";
    //     }
    //     cout << endl;
    // }

    for(auto e:L){
        if(R.find(e.first) == R.end()) continue;

        tmp = 0;
        auto itr = R.at(e.first).rbegin();
        for(auto itl=e.second.rbegin(); itl!=e.second.rend(); ++itl){
            while(*itr > *itl and itr!=R.at(e.first).rend() ){
                ++tmp;
                ++itr;
            }
            ans += tmp;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 44012
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
	int n; cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	vector<int> cnt(1000005);
	for(int x : v){
		if(cnt[x]){
			cnt[x] = 2;
			continue;
		}
		for (int j = x; j < 1000005; j += x){
			cnt[j]++;
		}
	}
	int res = 0;
	for(int x: v){
		if(cnt[x] == 1){
			res++;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const long long INF = 1LL<<60;
int H, W;
vector<string> fi;

long long solve() {
    vector<vector<long long>> dp(H, vector<long long>(W, INF));
    if (fi[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int dir = 0; dir < 2; ++dir) {
                int ni = i + dx[dir], nj = j + dy[dir];
                if (ni >= H || nj >= W) continue;
                int add = 0;
                if (fi[ni][nj] == '#' && fi[i][j] == '.') add = 1;
                chmin(dp[ni][nj], dp[i][j] + add);
            }
        }
    }
    return dp[H-1][W-1];
}

int main() {
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];
    cout << solve() << endl;
}

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

const int N_MAX = 100000;
vector<vector<pair<ll, ll>>> graph(N_MAX);
ll min_dist[N_MAX + 1] = {};

void calc_all_min_dist(int k)
{
    stack<int> st;
    st.push(k);
    while (!st.empty())
    {
        ll now = st.top();
        st.pop();

        for (auto p : graph[now])
        {
            if (p.first != k && min_dist[p.first] == 0)
            {
                min_dist[p.first] = min_dist[now] + p.second;
                st.push(p.first);
            }
        }
    }
}

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

    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }
    int q, k;
    cin >> q >> k;

    calc_all_min_dist(k);

    vector<long long> v;
    for (int i = 0; i < q; i++)
    {
        ll x, y;
        cin >> x >> y;
        ll dist = min_dist[x] + min_dist[y];
        v.push_back(dist);
    }

    for (auto item : v)
    {
        cout << item << endl;
    }

    return 0;
}

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

const ll INF = 1LL<<60;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<vector<ll>> dp(n+5, vector<ll>(n+5,0));
  for (int w = 1; w <= n; ++w) {
    for (int l = 0; l <= n-w; ++l) {
      int r = l + w;
      if ((n - (r-l)) % 2 == 0) {
        dp[l][r] = max(a[l] + dp[l+1][r], a[r-1] + dp[l][r-1]);
      }
      else {
        dp[l][r] = min(-a[l] + dp[l+1][r], -a[r-1] + dp[l][r-1]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 70912
import sys


n = int(input())
b = list(map(int, input().split()))
ope = []
i = n
while i > 0:
    flag = 0
    j = i
    while j > 0:
        if b[j - 1] == j:
            b.pop(j - 1)
            i -= 1
            ope.insert(0, j)
            flag = 1
            break
        j -= 1
    if flag == 0:
        print(-1)
        sys.exit()
for i in ope:
    print(i)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int main ()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(d>=(abs(a-c))){
        printf("Yes");
    }

   else if(d>=abs(a-b)&& d>=abs(b-c)){
            printf("Yes");
        }

        else{
            printf("No");
        }


}


Measured memory_bytes: 1724
import numpy as np
nmq = input()
[a, b, n] = [int(comp) for comp in nmq.split()]


def func(x):
  global a, b
  return int(a * x // b) - a * int(x // b)


if(n < b):
  print(func(n))
else:
  print(func(b - 1))

Measured memory_bytes: 27080
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


 
const int MAX = 510000;
 
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long PERM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n-k] % MOD) % MOD;
}
//FUNCTION
void solve(void)
{
  int N;
  cin>>N;
  COMinit();

  cout<<PERM(N,N)<<endl;

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 12160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 33836