akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>

using ldouble = long double;

const ldouble PI = std::acos(-1L);

void solve() {
    ldouble a, b, h, m;
    std::cin >> a >> b >> h >> m;

    ldouble t = h * 60 + m;
    ldouble x = t / 720 * (PI * 2);
    ldouble y = m / 60 * (PI * 2);

    std::cout << std::fixed << std::setprecision(20)
              << std::hypot(a * std::cos(x) - b * std::cos(y),
                            a * std::sin(x) - b * std::sin(y))
              << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4208
N=int(input())
lst = [int(s) for s in input().split()]
ans=[0]*N
result=[]
def now(num):
  res=0
  k=1
  while(k*num<=N):
    res=res+ans[k*num-1]
    k=k+1
  return res%2
for i in range(N):
  n=N-i
  x=lst[n-1]
  y=now(n)
  if(x!=y):
    ans[n-1]=1
    result.append(n)
result.sort()
print(len(result))
if (len(result)!=0):
  print(' '.join(map(str, result)))

Measured memory_bytes: 20548
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var ans int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	d := make([]int, k)
	for i := 0; i < k; i++ {
		d[i], _ = strconv.Atoi(stringLineScan())
	}
	for i := n; ; i++ {
		p := strconv.Itoa(i)
		f := true
		for _, j := range p {
			q, _ := strconv.Atoi(string(j))
			if match(q, d) == false {
				f = false
				break
			}
		}
		if f {
			fmt.Println(i)
			break
		}
	}
}
func match(x int, y []int) bool {
	for _, i := range y {
		if x == i {
			return false
		}
	}
	return true
}


Measured memory_bytes: 1920
A,B,C,D=(int(x) for x in input().split())
#N=int(input())
#A=list(map(int, input().split()))

if C%B !=0:
    a=C//B +1
else:
    a=C//B

if A%D !=0:
    b=A//D +1
else:
    b=A//D
    
if b<a:
    print('No')
else:
    print('Yes')

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x.at(i);
  vector<int> y(M);
  for (int i = 0; i < M; i++) cin >> y.at(i);

  int mx = *max_element(x.begin(), x.end());
  int mi = *min_element(y.begin(), y.end());
  
  for (int z = X + 1; z <= Y; z++) {
    if (z <= mx) continue;
    if (z > mi) continue;
    return cout << "No War" << "\n", 0;
  }
  cout << "War" << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;


int main(void) {
    ll N, M, Q;
    cin >> N >> M >> Q;
    ll i, j;
    ll L, R;
    ll G[501][501]={0};
    ll S[501][501]={0};
    ll p, q;
    for(i=0; i<M; i++) {
        cin >> L >> R;
        L--; R--;
        G[L][R]++;
    }
    S[0][0]=G[0][0];
    for(i=1; i<N; i++) {
        S[i][0]=S[i-1][0]+G[i][0];
    }
    for(i=1; i<N; i++) {
        S[0][i]=S[0][i-1]+G[0][i];
    }
    for(i=1; i<N; i++) {
        for(j=1; j<N; j++) {
            S[i][j]=S[i-1][j]+S[i][j-1]-S[i-1][j-1]+G[i][j];
        }
    }
    
    for(i=0; i<Q; i++) {
        cin >> p >> q;
        p--; q--;
        cout << S[q][q]-S[p-1][q]-S[q][p-1]+S[p-1][p-1] << endl;
    }
    
}


Measured memory_bytes: 4864
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e9+1;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli n, a, k;
    cin >> n >> k;
    vector<lli> v, dp;
    dp.resize(n + 5, -1);
    fr(i, 0, n) {
        cin >> a;
        v.pb(a);
    }
    dp[0] = 0;

    fr(i, 0, n) {
        for (lli j = i + 1; j <= i + k && j < n; j++) {
            lli val = abs(v[j] - v[i]);
            if (dp[j] == -1) {
                dp[j] = dp[i] + val;
            } else {
                dp[j] = min(dp[j], dp[i] + val);
            }
        }
    }

    cout << dp[n - 1] << endl;
    rt;
}


Measured memory_bytes: 2168
n = int(input())
a = [0] * n
s = [[]] * n

for i in range(n):
  a[i] = int(input())
  tmp = [[]] * a[i]
  for j in range(a[i]):
    tmp[j] = [num for num in map(int, input().split())]
  s[i] = tmp
# print(n)
# print(a)
# print(s)
ans = 0
for i in range(2 ** n):
  pattern = '{:0' + str(n) + 'b}'
  bin_str = pattern.format(i)
  # print(bin_str)
  all_ok = True # すべての人の証言に矛盾がない
  total_honesty = 0
  for j in range(n):
    shogen = s[j]
    if bin_str[j] == '1':
      total_honesty += 1
      # 正直者とした場合
      for k in range(len(shogen)):
        x, y = shogen[k]
        x -= 1
        if int(bin_str[x]) != y:
          all_ok = False
          break
  if all_ok:
    if ans < total_honesty:
      ans = total_honesty
print(ans)


Measured memory_bytes: 44380
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> M;
	vector<vector<int>>edge(N, vector<int>(N, 1));
	UnionFind uf(N);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L][R]--;
		edge[R][L]--;
	}
	for (int i = 0; i < N; i++)edge[i][i]--;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (edge[i][j])uf.Unite(i, j);
		}
	}
	vector<int>odd(N);
	vector<int>even(N);
	set<int>s;
	vector<int>dis(N, MOD);
	vector<bool>flag(N);
	for (int i = 0; i < N; i++)s.insert(uf.Find(i));
	for (auto i : s) {
		queue<int>Q;
		dis[i] = 0;
		Q.push(i);
		while (!Q.empty()) {
			int cn = Q.front();
			Q.pop();
			for (int j = 0; j < N; j++) {
				if (edge[cn][j]) {
					flag[i] = true;
					if (dis[j] > dis[cn] + 1) {
						dis[j] = dis[cn] + 1;
						Q.push(j);
					}
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (flag[uf.Find(i)]) {
			if (dis[i] % 2)odd[uf.Find(i)]++;
			else even[uf.Find(i)]++;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (edge[i][j]) {
				if (dis[i] % 2 == dis[j] % 2) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	vector<int>dp(N + 1, 0);
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		vector<int>ddp(N + 1, 0);
		if (flag[i]) {
			//cout << i << " " << odd[i] << " " << even[i] << endl;
			for (int j = N; j >= odd[i]; j--) {
				ddp[j] |= dp[j - odd[i]];
			}
			for (int j = N; j >= even[i]; j--) {
				ddp[j] |= dp[j - even[i]];
			}
			dp = ddp;
		}
	}
	int num = 0;
	for (int i = 0; i < N; i++) {
		if (dp[i])num = i;
	}
	for (int i = 0; i < N; i++) {
		if (dp[i]) {
			num += i;
			break;
		}
	}
	//cout << num << endl;
	int a = N, b = 0;
	for (int i = 0; i <= (N+1) / 2; i++) {
		if (dp[i]) {
			//cout << "dp" << i << endl;
			if (i + N - num >= (N + 1) / 2) {
				b = N / 2;
				a = N - b;
			}
			else {
				b = max(i +(int) N - num, b);
				a = N - b;
			}
		}
	}
	//cout << a << " " << b << endl;
	cout << (a - 1)*a / 2 + (b - 1)*b / 2 << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    string sa, sb;
    sa = string(b - '0', a);
    sb = string(a - '0', b);

    if(sa < sb) cout << sa << endl;
    else cout << sb << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=7,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n;
    x=7%n;
    a=n+1;
    while(a--)
    {
        c++;
        if(x==0)
        {
            cout<<c<<endl;
            return 0;
        }
        x*=10;
        x+=7;
        x%=n;
    }
    cout<<-1<<endl;
}



Measured memory_bytes: 3560
import math
import sys
K, N = [int(i) for i in input().split(' ')]
mod = 998244353
sys.setrecursionlimit(100000)

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

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

NNN = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

def EN(i):
    k2 = int((K - abs(K - int((i-1)/2) * 2) )/2)
    k1 = K - k2*2 - (1 if i % 2 == 0 else 0)
    result = 0
    for j in range(k2+1):
        if N < j:
            break
        result = (result + mul(mul(cmb_f(k2, j, mod) , cmb_f(N+k1-1, j+k1-1, mod)) , pow(2, j) % mod))% mod
    if i % 2 == 1:
        return result
    for j in range(k2+1):
        if N-1 < j:
            break
        result = (result + mul(mul(cmb_f(k2, j, mod), cmb_f(N+k1-2, j+k1-1, mod)), pow(2, j) % mod))% mod
    return result

if K == 1:
    print(0)
else:
    result = []
    for i in range(K):
        result.append(str(EN(i+2)))
    print("\n".join(result + result[:-1][::-1]))


Measured memory_bytes: 63704
//LCS但是得记录序列：https://blog.csdn.net/pjqooo/article/details/38425159
//涉及正逆序问题 
#include<bits/stdc++.h>
using namespace std;

int dp[3005][3005];//s1在i长度下和s2[j]在j长度最长序列长度 

signed main()
{
	string s1,s2;
	while(cin>>s1>>s2){
		int len1=s1.length(),len2=s2.length();
		
		for(int i=len1;i>=1;i--)
			for(int j=len2;j>=1;j--){
				if(s1[i-1]==s2[j-1])dp[i][j]=dp[i+1][j+1]+1;
				else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
			}
		
		//关键:用上面的dp去优化查找过程
		int i=0,j=0;
		while(i<len1&&j<len2){
			if(s1[i]==s2[j]){
				cout<<s1[i];
				i++;j++;
			}//不一样得看往后移动哪一个指针,没重复往后走 
			else if(dp[i+1][j+1]==dp[i+1+1][j+1])i++;
			else j++;
		} 
		cout<<endl;
	}
	return 0;
} 

Measured memory_bytes: 38860
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    int p = 0, q = 0;
    p = (s[0] - '0') * 10 + (s[1] - '0');
    q = (s[2] - '0') * 10 + (s[3] - '0');
    vll ng(2);
    if(p == 0 || p > 12) ng[0] = 1; //MMYYダメ
    if(q == 0 || q > 12) ng[1] = 1; //YYMMダメ

    if(ng[0] && ng[1]) cout << "NA" << endl;
    else if(ng[0] && ng[1] == 0) cout << "YYMM" << endl;
    else if(ng[0] == 0 && ng[1]) cout << "MMYY" << endl;
    else cout << "AMBIGUOUS" << endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var input  = input.split(' ');
    var n = input[0];
    var a = input[1];
    var b = input[2];
    var Sum = 0;
    for (j = 1; j <= n; j++) {
        var str = j.toString();
        var arr = str.split('').map(n => parseInt(n));
        var x = arr.reduce((a, b) => a + b);
        if(a <= x && x <= b) {
            Sum += j;
        }
    }
    console.log(Sum);
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10972
fun main() = Thread(null, ::abc169e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc169e() {
    val n = readLine()!!.toInt()
    val abList = Array(n) {
        val (a, b) = readLine()!!.split(' ').map { it.toLong() }
        a..b
    }

    val sortByFirst = abList.sortedBy { it.first }
    val sortByLast = abList.sortedBy { it.last }

    val answer = if (n % 2 == 0) {
        val leftMin = sortByFirst.take(n / 2).map { it.first }.max()!!
        val rightMin = sortByFirst.take(n / 2 + 1).map { it.first }.max()!!
        val leftMax = sortByLast.takeLast(n / 2 + 1).map { it.last }.min()!!
        val rightMax = sortByLast.takeLast(n / 2).map { it.last }.min()!!

        ((leftMax + rightMax) - (leftMin + rightMin) + 1).coerceAtLeast(0)
    } else {
        val max = sortByLast[n / 2]
        val min = sortByFirst[n / 2]
        max.last - min.first + 1
    }

    println(answer)
}


Measured memory_bytes: 75828
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int ans = (a * b) - ((a + b) - 1);
		out.print(ans);
		out.flush();
	}
	public static int gcd(int a, int b) {
		if(b == 0)
			return a;
		return gcd(b, a % b);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 22484
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int nn=0;
		int hit=0;
		int out=0;
		int ans=0;

		while(sc.hasNext())
		{
			String str = sc.next();

			if(str.compareTo("HIT")==0)
			{
				hit++;
				if(hit==4)
				{
					ans++;
					hit=3;
				}
			}
			else if(str.compareTo("OUT")==0)
			{
				out++;
				if(out==3)
				{
					nn++;
					out=0;
					hit=0;
					System.out.println(ans);
					ans=0;
				}
				if(nn==n)
					return;
			}
			else if(str.compareTo("HOMERUN")==0)
			{
				ans+=1+hit;
				hit=0;
			}
		}	
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    if(N==0||N==2) cout<<1<<endl;
    else if(N==1) cout<<2<<endl;
    else cout<<0<<endl;
}




Measured memory_bytes: 3168
#include<stdio.h>
int main(void){
	int i,N,a[100],mb,ms;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	mb=ms=a[0];
	for(i=1;i<N;i++){
		if(mb<a[i]){
			mb=a[i];
		}
	}
	for(i=1;i<N;i++){
		if(ms>a[i]){
			ms=a[i];
		}
	}
	printf("%d\n",mb-ms);
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>
#include <utility>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64 a, b;
  cin >> a >> b;
  if (a == b) {
    cout << "0\n";
  } else if (((a + b) & 1) == 0) {
    cout << (a + b) / 2 << '\n';
  } else {
    cout << "IMPOSSIBLE" << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string n_r = Console.ReadLine();
            string S_r = Console.ReadLine();
            string q_r = Console.ReadLine();
            string T_r = Console.ReadLine();

            int n = int.Parse(n_r);
            string[] S = S_r.Split();
            int q = int.Parse(q_r);
            string[] T = T_r.Split();

            int Count = 0;

            for (int i = 0; i < q; i++)
            {
                for (int ii = 0; ii < n; ii++)
                {
                    if (S[ii] == T[i])
                    {
                        Count++;
                        break;
                    }
                    
                }
            }
            Console.WriteLine(Count);
            Console.ReadLine();
        }
    }
}

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


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 100 * 1000 + 123;





int n, x, a[MAXN];
ll ans;


int main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		while (a[i] + a[i - 1] > x) {
			if (a[i]) {
				ans += min(a[i], a[i] + a[i - 1] - x);
				a[i] -= min(a[i], a[i] + a[i - 1] - x);
			}
			else {
				ans += min(a[i - 1], a[i] + a[i - 1] - x);
				a[i - 1] -= min(a[i - 1], a[i] + a[i - 1] - x);
			}
		}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include<queue>
#include <cmath>
#include <complex>
#include<map>
#include <string>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>


/*
#define x real()
#define y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
*/

//#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
#define NOT(x) (1^x)

const double PI  = acos(-1.0);
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
const int N=100009,M=1000000;

ll ans[100];
 int main()
{
//freopen("travel.in","r",stdin);
//freopen("travel.out","w",stdout);
//__builtin_popcount()
input;

        ll k;
        cin>>k;
        ll m=k%50;
        ll val=50+k/50-1;
        forr(i,1,m)ans[i]=val+50-m+1;
        forr(i,m+1,50)ans[i]=val-m;

        cout<<50<<endl;
        forr(i,1,50)cout<<ans[i]<<" ";



return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e8;
const int MAX_N = 110000;
int memo[MAX_N];
int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}
int main() {
	int N; cin >> N;
	for (int i = 0; i < MAX_N; ++i)memo[i] = -1;
	cout << rec(N) << endl;
	return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;


int main(){
  int a,b;
  cin>>a>>b;
  int d = max(a + a-1,b+b-1);
  d = max(d,a+b);
  cout<<d<<endl;


  return 0;
}

Measured memory_bytes: 256
// finish date: 2018/07/17
#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    N--;
    rep(m, N + 1) {
        if (-m * D + C * (N - m) <= B - A && B - A <= -m * C + D * (N - m)) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  if (N < 600) {
    cout << 8 << endl;
  } else if (N < 800) {
    cout << 7 << endl;
  } else if (N < 1000) {
    cout << 6 << endl;
  } else if (N < 1200) {
    cout << 5 << endl;
  } else if (N < 1400) {
    cout << 4 << endl;
  } else if (N < 1600) {
    cout << 3 << endl;
  } else if (N < 1800) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3588
H,W = gets.split.map &:to_i
C = gets.split.map{ _1.to_i - 1}
D = gets.split.map{ _1.to_i - 1}

S = H.times.map{ gets.chomp.chars }

warp_count = Array.new(H){[10**10]*W}
warp_count[C[0]][C[1]] = 0

query = [C]
move = [[-1,0],[1,0],[0,-1],[0,1]]
warp = 0
loop do
    warp_q = []
    while q = query.shift
        h,w = q
        move.each do |mx,my|
            y = h+my
            x = w+mx
            next if (y<0) ||(H<=y) || (x<0) || (W<=x)
            next if warp_count[y][x] <= warp
            if S[y][x] == "#" then
                warp_q << [h,w]
            else
                query << [y,x]
            end

            warp_count[y][x] = warp
        end
    end

    warp += 1
    warp_q.uniq.each do |h,w|
        (-2..2).each do |my|
            y = h + my
            next if (y<0)||(H<=y)
            (-2..2).each do |mx|
                x = w + mx
                next if (x<0)||(W<=x)
                next if warp_count[y][x] <= warp
                next if S[y][x] == "#"
                warp_count[y][x] = warp
                query << [y,x]
            end
        end
    end

    query.uniq!
    break if query.empty?
end

ans = warp_count[D[0]][D[1]]
p (ans==10**10) ? -1 : ans


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

int main(){
	int N, M, i, j;
	scanf("%d", &N);
	vector<int> a(N + 1);
	for(i = 1; i <= N; i++){
		scanf("%d", &a[i]);
	}
	vector<int> b = a;
	for(i = N, M = 0; i > 0; i--){
		for(j = 2; i * j <= N; j++){
			b[i] ^= b[i * j];
		}
		M += b[i];
	}
	printf("%d\n", M);
	for(i = 1; i <= N; i++){
		if(b[i] == 1){
			printf("%d ", i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;

int main(){
    string s;
    cin>>s;
    int start;
    int n=s.size();
    if(n%2==1)start=n/2;
    else start=(n-2)/2;
    int ans=0;
    while(1){
        bool ok=true;
        rep(i,start){
            if(s[i]!=s[start+i]){
                ok=false;
                break;
            }
        }
        if(ok){
            ans=start*2;
            break;
        }
        start--;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
   	Scanner sc = new Scanner(System.in);

    int Na = sc.nextInt();
    int Nb = sc.nextInt();
    int Nc = sc.nextInt();
    int Nd = sc.nextInt();
    int Ne = sc.nextInt();
    int k = sc.nextInt();
   	if(Ne-Na<=k)System.out.println("Yay!");
    else System.out.println(":(");
 }
}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <stdio.h>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  int n;
  cin >> n;
  vector<vector<int> > vvi(4, vector<int>(13));
  rep(i,n){
    char c;
    int a;
    cin >> c >> a;
    if( c == 'S'){
      vvi[0][a-1] = 1;
    }
    else if( c == 'H'){
      vvi[1][a-1] = 1;      
    }
    else if( c == 'C'){
      vvi[2][a-1] = 1;      
    }
    else if( c == 'D'){
      vvi[3][a-1] = 1;      
    }
  }
  rep(i,4){
    rep(j,13){
      if(i == 0 && vvi[i][j] == 0) cout << 'S' << " " << j+1 << endl;
      if(i == 1 && vvi[i][j] == 0) cout << 'H' << " " << j+1 << endl;
      if(i == 2 && vvi[i][j] == 0) cout << 'C' << " " << j+1 << endl;
      if(i == 3 && vvi[i][j] == 0) cout << 'D' << " " << j+1 << endl;      
    }
  }
}



Measured memory_bytes: 3148
import bisect
import numpy as np

N,K = map(int,input().split())
A = list(map(int,input().split()))

#N,K = 9,9
#A = [-3,-2,-2,-2,0,0,1,2,2]

def simple():
    B = sorted([A[i] * A[j] for i in range(N) for j in range(i+1,N)])
    return B[K-1]

def solve():
    A.sort()

    iplus = bisect.bisect_right(A,0)
    izeros = bisect.bisect_left(A,0)

    pluss = np.array(A[iplus:]).astype(np.int64)
    zeros = A[izeros:iplus]
    minuss = np.array(A[:izeros]).astype(np.int64)

    nplus = len(pluss)
    nzero = len(zeros)
    nminus = len(minuss)

    npminus = nplus * nminus
    npzeros = nzero * (nplus + nminus) + nzero * (nzero-1)//2

    if npminus < K <= npminus + npzeros:
        return 0
    elif K <= npminus:
        mn = A[-1] * A[0] - 1
        mx = 0
        while mx-mn > 1:
            mid = (mn+mx)//2
            xs = -(-mid//minuss)
            cnt = nplus * nminus
            cnt -= np.sum(np.searchsorted(pluss,xs,side="left"))
            if cnt >= K:
                mx = mid
            else:
                mn = mid
        return mx
    else:
        nK = K - npminus - npzeros
        pluss2 = (-minuss)[::-1]
        mn = -1
        mx = max(A[0]**2, A[-1]**2)
        pluss_p2 = pluss**2
        pluss2_p2 = pluss2**2
        while mx-mn > 1:
            mid = (mn+mx)//2
            cnt = 0
            xs = mid//pluss
            cnt += np.sum(np.searchsorted(pluss,xs,side='right'))
            cnt -= np.count_nonzero(pluss_p2 <= mid)
            xs2 = mid//pluss2
            cnt += np.sum(np.searchsorted(pluss2,xs2,side='right'))
            cnt -= np.count_nonzero(pluss2_p2 <= mid)
            cnt = cnt //2
            #print(mn,mid,mx,cnt)
            if nK <= cnt:
                mx = mid
            else:
                mn = mid
        return mx

print(solve())
#for K in range(1,N*(N-1)//2+1):
#    print(solve(),simple())



Measured memory_bytes: 32296
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0256();
	}
	class AOJ0256{
		public AOJ0256() {
			int sum = 0;
			for(int i=0;i<10;i++)sum+=in.nextInt();
			System.out.println(sum);
		}
	}
	
}

Measured memory_bytes: 17188
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};


//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  vector<bool>M(1000010,false);
  map<ll,ll>no;
  rep(i,n)no[a[i]]++;

  ll count=0;
  rep(i,n){
    if(no[a[i]]>=2){
      //continue;
      M[a[i]]=true;
      continue;
    }

    bool ok=true;
    vl vec=divisor(a[i]);
    rep(j,vec.size()){
      
      if(M[vec[j]]){
        ok=false;
        //cout<<a[i]<<" "<<vec[j]<<endl;
        break;
      }
    }
    M[a[i]]=true;
    if(ok)count++;
  }
  
  cout<<count<<endl;
}


Measured memory_bytes: 17452
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL A[101010], B[101010];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &A[i]);
    rep(i, N) scanf("%lld", &B[i]);
    
    // 2. 数列 C[1], ... , C[N] を 構成できるか？
    priority_queue<LL> pq;
    LL diff = 0, ans = 0;
    rep(i, N){
        if(B[i] > A[i]) diff += (B[i] - A[i]), ans++;
        else            pq.push(A[i] - B[i]);
    }
    
    // 3. 数列 C[1], ... , C[N] を 構成できるか？
    while(!pq.empty()){
        LL d = pq.top();
        pq.pop();
        if(diff > 0) diff -= d, ans++;
        if(diff <= 0) break;
    }
    
    // 4. 出力.
    if(diff <= 0) printf("%d\n", ans); 
    else          puts("-1");
    return 0;
    
}

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

#define ll  long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)


int main(){
    ll n,k; 
    cin >> n >> k;
    ll a[n];
    ll dp[n] = {0};
    rep(i,0,n){
        cin >> a[i];
    }
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    rep(i,2,n){
        dp[i] = INT32_MAX;
        rep(j,1,k + 1){
            if(i - j >= 0){
                dp[i] = min(dp[i],dp[i - j] + abs(a[i] - a[i - j]));
            }
            else break;
        }
    }
        cout << dp[n - 1];
}

Measured memory_bytes: 1792
h, w = map(int, input().split())
grid = []
for i in range(h):
    l = list(input())
    grid.append(l)

dp = [[0 for x in range(w)] for y in range(h)]
if grid[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(1, w):
    if grid[0][i] == '.':
        dp[0][i] = dp[0][i-1]
    else:
        if grid[0][i-1] == '.':
            dp[0][i] = dp[0][i-1]+1
        else:
            dp[0][i] = dp[0][i-1]

for i in range(1, h):
    if grid[i][0] == '.':
        dp[i][0] = dp[i-1][0]
    else:
        if grid[i-1][0] == '.':
            dp[i][0] = dp[i-1][0]+1
        else:
            dp[i][0] = dp[i-1][0]

for i in range(1, h):
    for j in range(1, w):
        if grid[i][j] == '.':
            dp[i][j] = min(dp[i-1][j], dp[i][j-1])
        else:
            if grid[i-1][j] == '#' and grid[i][j-1] == '#':
                dp[i][j] = min(dp[i-1][j], dp[i][j-1])
            elif grid[i-1][j] == '#':
                dp[i][j] = dp[i-1][j]
            elif grid[i][j-1] == '#':
                dp[i][j] = dp[i][j-1]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + 1

print(dp[h-1][w-1])




Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

template< typename T >
struct BIT {
  vector<T> data;
  int size;
  BIT(const int n) : data(n+1), size(n) {}
  void add(int a, T val) {
    for (int x=a; x<=size; x+=x&-x) data[x] += val;
  }
  T get(int a) {
    T ret = 0;
    for (int x=a; x>0; x-=x&-x) ret += data[x];
    return ret;
  }
  T query(int l, int r) {
    return get(r) - get(l);
  }
};

template< typename T >
struct ExBIT {
  BIT<T> p, q;
  ExBIT(int n) : p(n), q(n) {}
  void add(int l, int r, T val) {
    p.add(l, -val * l); p.add(r, val * r);
    q.add(l, val); q.add(r, -val);
  }
  T get(int r) {
    return p.get(r) + q.get(r) * r;
  }
};

int main() {
    int n, q; cin >> n >> q;
    BIT<ll> bit(n);
    rep(i, q) {
        int c; cin >> c;
        if (c==0) {
            int a, x; cin >> a >> x;
            bit.add(a, x);
        } else {
            int s, t; cin >> s >> t;
            cout << bit.query(s-1, t) << endl;
        }
    }
}


Measured memory_bytes: 3548
n = int(input())
a = list(map(int, input().split()))
mapa = {}
for i in range(n):
    if a[i] in mapa:
        mapa[a[i]] += 1
    else:
        mapa[a[i]] = 1
count = 0
for i in mapa:
    if i < mapa[i]:
        count += mapa[i] - i
    elif i > mapa[i]:
        count += mapa[i]
print(count)

Measured memory_bytes: 18168
#include <iostream>
#include <bits/stdc++.h>
const int Size = 200005;
long long Arr1[Size], Arr2[Size];
using namespace std;
int main()
{
    long long N,M,K;
    cin >> N >> M >> K;
    vector <long long> cumm1, cumm2;
    cumm1.push_back(0); cumm2.push_back(0);
    for (int i = 1; i <= N; i++){
        cin >> Arr1[i];
        cumm1.push_back(cumm1[i-1] + Arr1[i]);
    }
    for (int i = 1; i <= M; i++){
        cin >> Arr2[i];
        cumm2.push_back(cumm2[i-1] + Arr2[i]);
    }
    long long sum = 0;
    for (long long i = 0; i <= N; i++){
        if (K >= cumm1[i]){
            auto upper = upper_bound(cumm2.begin(), cumm2.end(), (K - cumm1[i]));
            long long idx = (upper - cumm2.begin()) - 1;
            sum = max(sum, idx + i);
        }
    }
    cout << sum ;
}


Measured memory_bytes: 10580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  vector<int> a(2);
  a[0]=-1;
  a[1]=s;
  int an;
  bool loop=true;
  for(int i=2;loop;i++){
    if(a[i-1]%2==0)a.push_back(a[i-1]/2);
    else a.push_back(3*a[i-1]+1);
    for(int j=1;j<i;j++){
      if(a[i]==a[j]){
        loop=false;
        an=i;
        break;
      }
    }
  }
  cout << an << endl;
}

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

using namespace std;

#define re register

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);//x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void print(int x)
{
    if(x<0) 
	x=-x,putchar('-');
    if(x>9) 
	print(x/10);
    putchar(x%10+'0');
}

int n,m,a[110],sum;

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		sum+=a[i];
	}
	m=read();
	while (m--)
	{
		int x,y;
		x=read(),y=read();
		print(sum-a[x]+y);
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
inline void readLong(ll &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
/*================Header Template==============*/
int n,m,k;
int main() {
	readInt(n);
	readInt(m);
	readInt(k);
	bool f=0;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=m;j++) {
//			cout<<i<<" "<<j<<" "<<i*m+j*n-i*j<<endl;
			if(i*m+j*(n-i)-i*j==k) {
				puts("Yes");
				f=1;
				break;
			}
		}
		if(f)
			break;
	}
	if(!f)
		puts("No");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

s = list(str(input()))


for i in range(len(s)):
    if (i+1) % 2 == 1:
        if s[i] not in ["R", "U", "D"]:
            print("No")
            exit()
    elif (i+1) % 2 == 0:
        if s[i] not in ["L", "U", "D"]:
            print("No")
            exit()
print("Yes")


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

int N,a[100010],ind[100010];

inline bool cmp(int x, int y){
    return a[x]<a[y];
}

int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++){
        cin >> a[i];
        ind[i]=i;
    }

    sort(ind+1,ind+N+1,cmp);

    int res=0;
    for (i=1; i<=N; i++)
        if ((i-ind[i])%2!=0) res++;

    cout << res/2 << "\n";
    return 0;
}


Measured memory_bytes: 1024
n,m,k=map(int,input().split())
fact,factinv,mod=[1]*n,[1]*n,998244353
for i in range(2,n):
  fact[i]=fact[i-1]*i%mod
factinv[n-1]=pow(fact[n-1],mod-2,mod)
for i in range(n-2,0,-1):
  factinv[i]=factinv[i+1]*(i+1)%mod
ncr=lambda n,r:fact[n]*factinv[r]%mod*factinv[n-r]%mod
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-i-1,mod)*ncr(n-1,i)%mod
print(ans%mod)


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

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    rep(i,s.size()-1) {
        if (s[i] == s[i+1]) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))

int main() {
    int N;
    double x, result;
    string u;
    double ratio = 380000;

    cin >> N;
    //cout << N << endl;
    for(int i=0; i<N; i++) {
        cin >> x >> u;
        result += (u=="JPY")? x: x * ratio; 
        //cout << x << u << endl;
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
import queue
class gridMan:
  def __init__(s, L):
    s.L = L
    s.H = len(s.L)
    s.W = len(s.L[0])
  def makeWall(s, x = -2):
    w = len(s.L[0]) + 2
    s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
  def dist(s, S): #Sから上下左右に進んで何手かかるかのリスト　および　最大値
    T = [[-1] * s.W for _ in range(s.H)]
    q = queue.Queue()
    q.put([S[0], S[1]])
    T[S[0]][S[1]] = 0
    k = 0
    while not q.empty():
      h, w = q.get()
      k = T[h][w]
      for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        hh = h + i
        ww = w + j
        if s.L[hh + 1][ww + 1] >= 0 and T[hh][ww] == -1:
          q.put([hh, ww])
          T[hh][ww] = k + 1
    return T, k

H, W, K = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]

b = "#"
r = "."

for i in range(H):
  for j in range(W):
    if A[i][j] == b:
      A[i][j] = -1
    elif A[i][j] == r:
      A[i][j] = 0
    else:
      A[i][j] = 0
      S = [i, j]

if S[0] == 0 or S[0] == H - 1:
  print(0)
  exit()
if S[1] == 0 or S[1] == W - 1:
  print(0)
  exit()
g = gridMan(A)
g.makeWall()

L, r = g.dist(S)

ans = 10 ** 10
for i in range(H):
  for j in range(W):
    if 0 <= L[i][j] and L[i][j] <= K:
      t = min(i, j, H - i - 1, W - j - 1)
      if t == 0:
        print(1)
        exit()
      t = (t + K - 1) // K
      ans = min(ans, t)

print(ans + 1)

Measured memory_bytes: 102740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[200005];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	a=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
		if(t[i]==a+1)a++;
	}
	if(a==0)cout<<-1<<endl;
	else cout<<n-a<<endl;
}

Measured memory_bytes: 1024
using System;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    var s = Console.ReadLine();
    var t = Console.ReadLine();
    int i = 0;
    for ( ; i < n; i++) {
      if (s.Substring(i) == t.Substring(0, n - i)) break;
    }
    Console.WriteLine(i + t.Length);
  }
}

Measured memory_bytes: 11092