akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int N,L;

int abs(int x) {
	if(x<0)return -x;
	return x;
}

bool cmp(int lhs,int rhs) {
	return abs(lhs)<abs(rhs);
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&L);
	int a[200+5];
	for(int i=1;i<=N;i++)
		a[i]=L+i-1;
	sort(a+1,a+N+1,cmp);
	int sum=0;
	for(int i=2;i<=N;i++)
		sum+=a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MP make_pair
#define endl '\n'
const int mod = 10007;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;

LL num[20];

int main(int argc, char* argv[]) {
    LL n;
    cin >> n;
    if (n & 1)
        cout << 0 << endl;
    else {
        LL ans = n / 10;
        n /= 10;
        LL bse = 1;
        while (bse <= n) {
            bse *= 5;
            ans += n / bse;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
template<class T> int size(T &&x) {
  return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for(auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
struct Nl{~Nl(){cerr << '\n';}};
# define print(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#define int long long


int32_t main(){
    
  fast;
  int n,k; cin >> n >> k;
  int cnt = 0;
  
  for(int i=0;i<n;i++){
    int x; cin >> x;
    if(x>=k) cnt++;
  } 

  cout << cnt;


  return 0;
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll; int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	bool flag = 0;
	REP(i, n){
		int a;
		cin >> a;
		if (a % 2 == 1){
			flag = 1;
			break;
		}
	}

	if (flag) cout << "first" << endl;
	else cout << "second" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define ll long long
int lcm(int x,int y){
	return x/__gcd(x,y)*y;
}
int main(){
	int t,a,ans=1;
	cin>>t;
	while(t--){
		cin>>a;
		ans=lcm(ans,a);
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	bool f;
	for (int i = 0; i < N; i++) {
		f = true;
		for (int a = 0; a < N; a++) {
			for (int b = 0; b < N; b++) {
				if (A[(i + a) % N][b] != A[(i + b) % N][a]) {
					f = false;
				}
			}
		}
		if (f)res += N;
	}
	cout << res << endl;
}

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

int main(void){
  long long L, R;
  cin >> L >> R;
  int min = 2019;
  if((R - L) > 2019) min = 0;
  else{
    for(long long i = L; i <= R - 1; i++){
      for (long long j = i + 1; j <= R; j++){
        if((i * j) % 2019 < min) min = (i * j) % 2019;
      }
    }
  } 
  cout << min;
 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
void solve()
{
	ll k,t;
	rl2(k,t);
	VL arr(t);
	fr(i,0,t)
		rl(arr[i]);
	sort(ALL(arr));
	ll sum=0,ans=0;
	fr(i,0,t)
	{
		if(arr[i]<=k/2)
		{
			sum+=arr[i];
		}
		else
		{
				ll x=arr[i]-(sum+1);
				if(x>0)
					ans+=x;
				sum+=arr[i];
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n, x; cin >> n >> x;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    ll cnt = 0;
    rep(l, n-1) {
        if(a[l] + a[l+1] <= x) continue;
        cnt += a[l] + a[l+1] - x;
        a[l+1] = max<ll>(0, x - a[l]);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 4044
import java.util.*;
 

class Main {
	public static void main (String[] args){
     Scanner scan = new Scanner(System.in);
     
     int N = scan.nextInt();
     int M = scan.nextInt();
     
    
     int k = (int)M/N;
     
     
     int ans=1;
     
     for(int i=k;i>1;i--){
    	 if(M%i==0){
    		 ans=i;
    		 break;
    	 }
     }	 
     System.out.println(ans);
}
}


Measured memory_bytes: 23764
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	exA = A * 2
	S = sum(A)
	D = [sum(A[1::2]), sum(A[2::2])]
	for i in range(2, N):
		D.append(D[-2] - exA[i - 1] + exA[i + N - 2])
	print(" ".join([str(S - 2 * d) for d in D]))

main()


Measured memory_bytes: 28188
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define debug(x) cerr<<#x<<"="<<x<<endl;
#define m(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int maxn=1e6+100;
int n,a[210];

int check(int a[]){
	bool flag=true;
	for(int i=1;i<=n;i++)
		if (a[i]&1)
			flag=false;
	if (flag) return 1;
	return 0;
}

void solve(int a[]){
	for(int i=1;i<=n;i++)
		a[i]/=2;
}

int main(){
	while(cin>>n){
		m(a,0);
		for(int i=1;i<=n;i++) cin>>a[i];
		int cnt=0;
		while(check(a)){
			solve(a);
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

using namespace std;

int n, k;
int dp[610][610];
int f[610];
int ans = 0;
vector<pair<int, int> > line;
bool p[602];

const int MOD = 1e9 + 7;

int add(long long a, long long b){
	return ((a + b) % MOD + MOD) % MOD;
}

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

int main(){
	f[0] = 1;
	f[2] = 1;
	for(int i = 4; i <= 600; i += 2) f[i] = mul(f[i - 2], i - 1);

	scanf("%d%d", &n, &k);

	while(k--){
		int u, v;
		scanf("%d%d", &u, &v);
		if(u > v) swap(u, v);
		line.emplace_back(u, v);
		p[u] = p[v] = true;
	}

	n <<= 1;
	for(int i = 1; i <= n - 1; i++){
		int ins, out; ins = out = 0;
		bool ok = true;

		for(auto k : line){
			int j = i + 1;
			if(i <= k.first && k.first <= j && i <= k.second && k.second <= j) ins++;
			else if ((i <= k.first && k.first <= j) ^ (i <= k.second && k.second <= j)) ok = false;
			else out++;
		}
		if(!ok) continue;
		dp[i][i + 1] = 1, ans = add(ans, f[n - 2 - (out << 1)]);
	}

	for(int len = 2; len <= n - 1; len++){
		for(int i = 1; i <= n - len; i++){
			int j = i + len;

			int ins, out;
			ins = out = 0;

			bool ok = 1;
			for(auto k : line){
				if(i <= k.first && k.first <= j && i <= k.second && k.second <= j) ins++;
				else if ((i <= k.first && k.first <= j) ^ (i <= k.second && k.second <= j)) ok = false;
				else out++;
			}

			if(!ok) continue;

			int tp = 0;

			for(int k = i; k <= j; k++){
				if(p[k]) continue;
				tp++;
			}

			// if(i == 2 && j == 5) cout << tp << endl;

			dp[i][j] = f[tp];

			for(int k = i; k <= i + 1; k++){
				if(!p[k]) tp--;
			}

			// if(i == 2 && j == 5) cout << tp << endl;

			for(int k = i + 1; k < j; k++){
				// if(i == 2 && j == 5) cout << k << " " << dp[i][k] << " " << tp << "XXX\n";
				dp[i][j] = add(dp[i][j], -mul(dp[i][k], f[tp]));
				if(!p[k + 1]) --tp;
			}

			// cout << i << " " << j << " " << dp[i][j] << endl;

			ans = add(ans, mul(dp[i][j], f[n - (len + 1) - (out << 1)]));
		}
	}

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

Measured memory_bytes: 1664
//#include <fstream>

#include <iostream>
#include <algorithm>

using namespace std;

const int NMAX = 100005;
int n, a[NMAX], b[NMAX], c[NMAX];
int dp[4][NMAX];

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> a[i] >> b[i] >> c[i];
	dp[1][1] = a[1];
	dp[2][1] = b[1];
	dp[3][1] = c[1];
	for (int i = 2;i <= n;++i)
	{
		for (int j = 1;j <= 3;++j)
		{
			if (j == 1)
				dp[j][i] = max(dp[2][i - 1], dp[3][i - 1]) + a[i];
			if (j == 2)
				dp[j][i] = max(dp[1][i - 1], dp[3][i - 1]) + b[i];
			if (j == 3)
				dp[j][i] = max(dp[1][i - 1], dp[2][i - 1]) + c[i];
		}
	}
	cout << max(dp[1][n], max(dp[2][n], dp[3][n])) << "\n";
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var halfLen = text.Length / 2;
            var left = text.Substring(0, halfLen);
            var right = new string(text.Reverse().Take(halfLen).ToArray());

            var diff = left.Select((c, i) => left[i] != right[i]).Count(t => t);

            Console.WriteLine(diff);

        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,j,mini,t,x=0;
    int a[100];
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        for(i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(i=0; i<n-1; i++)
        {
            mini=i;
            for(j=i; j<n; j++)
                if(a[j]<a[mini])
                    mini=j;
            if(i!=mini)
            {
                t=a[i];
                a[i]=a[mini];
                a[mini]=t;
                x++;
            }
        }
        printf("%d",a[0]);
        for(i=1; i<n; i++)
            printf(" %d",a[i]);
        printf("\n");
            printf("%d\n",x);
    }
    return 0;
}



Measured memory_bytes: 2036
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import resource
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from copy import deepcopy
sys.setrecursionlimit(1000000)
s, h = resource.getrlimit(resource.RLIMIT_STACK)
# resource.setrlimit(resource.RLIMIT_STACK, (h, h))
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, S):
    def f(s, p):
        if p == 0:
            return s
        elif p < 0:
            return None
        for i in range(M, 0, -1):
            j = p - i
            if j < 0 or j >= len(S):
                continue
            if S[j] == '1':
                continue
            s.append(i)
            v = f(s, j)
            if v:
                return v
            s.pop()
        return None
    
    m = 0
    mm = 0
    for c in S:
        if c == '1':
            mm += 1
            m = max(mm, m)
        else:
            mm = 0
    if m >= M:
        return -1
            
    ans = f([], N)
    if ans:
        return ' '.join(map(str, reversed(ans)))
    return -1
            

        



def main():
    N, M = read_int_n()
    S = read_str()
    print(slv(N, M, S))


if __name__ == '__main__':
    main()


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

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

    int four_divisible = 0;
    int two_divisible = 0;
    for (auto &v : data){
        if (v % 4 == 0){
            four_divisible += 1;
        }else{
            if (v % 2 == 0){
                two_divisible += 1;
            }
        }
    }
    int four_coverage;
    if (two_divisible == 0){
        four_coverage = four_divisible * 2 + 1;
    } else {
        four_coverage = four_divisible * 2;
    }
    
    int two_coverage = two_divisible;
    if (four_coverage + two_coverage >= data.size()){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
a, b = gets.chomp.split.map(&:to_i)

ans = ""
if a == b
  [a, b].min.times do |e|
    ans += a.to_s
  end
else
  [a, b].max.times do |e|
    ans += [a, b].min.to_s
  end
end

puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
	int n,q;
	cin >> n >> q;
	vector<int> s(n),t(n),x(n);
	vector<pair<int, pii> > aa(n);
	for(int i=0; i<n; i++){
		cin >> aa[i].second.first >> aa[i].second.second >> aa[i].first;
	}
	sort(aa.begin(), aa.end());
	for(int i=0; i<n; i++){
		s[i] = aa[i].second.first;
		t[i] = aa[i].second.second;
		x[i] = aa[i].first;
	}
	vector<int> d(q);
	set<int> ds;
	for(int i=0; i<q; i++){
		cin >> d[i];
		ds.insert(d[i]);
	}
	map<int, int> ans;
	for(int i=0; i<n; i++){
		int b=s[i]-x[i];
		int e=t[i]-x[i]-1;
		auto itr = ds.lower_bound(b);
		while(itr!=ds.end() and *itr<=e){
			ans[*itr] = x[i];
			auto curr = itr;
			itr++;
			ds.erase(curr);
		}
	}
	for(int i=0; i<q; i++){
		if(ans.count(d[i]) == 0){
			cout << -1 << endl;
		}else{
			cout << ans[d[i]] << endl;
		}
	}
	return 0;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int x; cin >> x;
    int n = 0;
    while(!(n*(n-1)/2 < x && x <= n*(n+1)/2)) n++;
    cout << n << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf (1LL<<60)
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
int main(){
    int n,m;
    while(cin >> n >> m && n!=0){
        vector<vector<ll> > L(n,vector<ll>(n,inf)),S(n,vector<ll>(n,inf));
        rep(i,n){
            L[i][i] = 0;
            S[i][i] = 0;
        }
        rep(i,m){
            int a,b;
            ll t;
            cin >> a >> b >> t;
            a--;b--;
            char c;
            cin >> c;
            if(c=='L'){
                L[a][b] = min(L[a][b],t);
                L[b][a] = min(L[b][a],t);
            }else{
                S[a][b] = min(S[a][b],t);
                S[b][a] = min(S[b][a],t);
            }
        }
        int rr;
        cin >> rr;
        vector<int> r(rr);
        rep(i,rr){
            cin >> r[i];
            r[i]--;
        }
        rep(k,n){
            rep(i,n){
                rep(j,n){
                    L[i][j] = min(L[i][j],L[i][k]+L[k][j]);
                    S[i][j] = min(S[i][j],S[i][k]+S[k][j]);
                }
            }
        }
        vector<vector<ll> > dp(rr,vector<ll>(n,inf));
        dp[0][r[0]] = 0;
        for(int i=1;i<rr;i++){
            int s = r[i-1];
            int t = r[i];
            rep(j,n){
                rep(k,n){
                    dp[i][k] = min(dp[i][k],dp[i-1][j]+L[s][j]+S[j][k]+L[k][t]);
                    if(j==k){
                        dp[i][k] = min(dp[i][k],dp[i-1][j]+L[s][t]);
                    }
                }
            }
        }
        ll mi = inf;
        rep(i,n){
            mi = min(mi,dp[rr-1][i]);
        }
        cout << mi << endl;
    }
    return 0;
}


Measured memory_bytes: 5156
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,cnt=0,c=1,t=1;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        {
            cnt++;
            i+=3;
        }
        else i++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3624
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll n, m, k;
queue<pll> q;
string s[maxn];
vector<ll> d[maxn];
set<ll> s1[maxn], s2[maxn], d1[maxn], d2[maxn];

void add(ll x, ll y, ll dis){
	dis++;
	if(d[x][y] <= dis) return;
	d[x][y] = dis;
	s1[x].erase(y);
	s2[x].erase(-y);
	d1[y].erase(x);
	d2[y].erase(-x);
	q.push(Mp(x, y));
	return;
}

int main(){
	fast_io;
	
	cin >> n >> m >> k;
	ll x, y, x1, y1, e;
	cin >> x >> y >> x1 >> y1;
	x--, y--, x1--, y1--;
	for(ll i = 0; i < n; i++){
		cin >> s[i];
		d[i].resize(m);
		fill(d[i].begin(), d[i].end(), inf);
		for(ll j = 0; j < m; j++){
			s1[i].insert(j);
			s2[i].insert(-j);
		}
	}
	for(ll j = 0; j < m; j++){
		for(ll i = 0; i < n; i++){
			d1[j].insert(i);
			d2[j].insert(-i);
		}
	}
	add(x, y, -1);
	set<ll>::iterator it;
	while(!q.empty()){
		x = q.front().F;
		y = q.front().S;
		q.pop();
		it = s1[x].lower_bound(y);
		while(it != s1[x].end()){
			e = *it;
			if(e - y > k || s[x][e] == '@') break;
			add(x, e, d[x][y]);
			it = s1[x].lower_bound(e);
		}
		it = s2[x].lower_bound(-y);
		while(it != s2[x].end()){
			e = -*it;
			if(y - e > k || s[x][e] == '@') break;
			add(x, e, d[x][y]);
			it = s2[x].lower_bound(-e);
		}
		it = d1[y].lower_bound(x);
		while(it != d1[y].end()){
			e = *it;
			if(e - x > k || s[e][y] == '@') break;
			add(e, y, d[x][y]);
			it = d1[y].lower_bound(e);
		}
		it = d2[y].lower_bound(-x);
		while(it != d2[y].end()){
			e = -*it;
			if(x - e > k || s[e][y] == '@') break;
			add(e, y, d[x][y]);
			it = d2[y].lower_bound(-e);
		}
	}
	if(d[x1][y1] == inf) d[x1][y1] = -1;
	cout << d[x1][y1];
	
	return 0;
}


Measured memory_bytes: 442364
import java.util.*; 
import java.io.*;

public class Main {	
	static long w[] = new long[1000] , v[] = new long[1000] ;  
	static long dp[][] = new long[105][100007]; 
	public static long fun(int n , int c) {
		if(dp[n][c] != -1) return dp[n][c]; 
		if(n == 0 || c == 0) {
			return 0; 
		}
		else if(w[n-1] > c) return fun(n-1,c); 
		
		else {
			     long temp1 =  fun(n-1 , c); 
			     long temp2 =  v[n-1] +  fun(n-1, (int) (c - w[n-1])); 
			     return dp[n][c] = Math.max(temp1, temp2); 
		     }
	}
	public static void solve(InputReader in) {
		int n = in.readInt(); 
		int W = in.readInt(); 
		for(int i = 0; i<105; i++) {
			for(int j = 0; j<100007; j++) {
				dp[i][j] = -1; 
			}
		}
		for(int i = 0; i<n; i++) {
			w[i] = in.readInt(); 
			v[i] = in.readInt(); 
		}
		System.out.println(fun(n,W));  
	}
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in); 
		int t = 1; 
		while(t-- > 0) {
			solve(in); 
		}
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
     
     public String next() {
		return readString();
	}
    
     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

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

    int n;
    cin>>n;

    int ans=0;

    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        int cnt=0;
        while(a%2==0)
        {
            cnt++;
            a/=2;
        }
        ans+=cnt;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int s[3][20];
int permu[3][6] = { { 0, 0, 1, 1, 2, 2 },
  { 1, 2, 0, 2, 0, 1 },
  { 2, 1, 2, 0, 1, 0 } };

int can[10][12 * 60 * 60];
int sum[10][12 * 60 * 60 + 2];

bool calc(int start, int interval) {
  REP(i, n) {
    if (sum[i][start + interval + 1] - sum[i][start] == 0) { return false; }
  }
  return true;
}

int main() {
  MEMSET(sum, 0);
  while (scanf("%d", &n), n) {
    MEMSET(can, 0);
    set<int> candidate;
    REP(i, n) {
      scanf("%d %d %d", &s[0][i], &s[1][i], &s[2][i]);
      REP(degree, 60) {
        REP(p, 6) {
          int hour = (s[permu[0][p]][i] + degree) % 60;
          int minute = (s[permu[1][p]][i] + degree) % 60;
          int second = (s[permu[2][p]][i] + degree) % 60;
          if (hour % 5 != minute / 12) { continue; }
          hour /= 5;
          int t = hour * 3600 + minute * 60 + second;
          candidate.insert(t);
          can[i][t] = 1;
        }
      }
    }
    REP(i, n) {
      REP(t, 12 * 60 * 60) {
        sum[i][t + 1] = sum[i][t] + can[i][t];
      }
    }
    int s = -1;
    int l = 0;
    int r = 12 * 60 * 60;
    while (l != r) {
      int m = (l + r) / 2;
      FORIT(it, candidate) {
        if (*it + m >= 12 * 60 * 60) {
          break;
        }
        if (calc(*it, m)) {
          s = *it;
          r = m;
          goto next;
        }
      }
      l = m + 1;
next:;
    }
    printf("%02d:%02d:%02d %02d:%02d:%02d\n",
        s / 3600, s / 60 % 60, s % 60,
        (s + l) / 3600, (s + l) / 60 % 60, (s + l) % 60);
  }
}

Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m >> k;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
        if(m<=v[i]){
            ans++;
        }else{
            ans += (m - 1) / v[i];
            ans++;
        }
    }
    cout << ans+k << endl;
}

Measured memory_bytes: 256
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1


        if number == TN:
            e += c
            suuji += number
            numbers.append(e)
    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        a=numbers[-1]
        A = int(a)
        moji = ''
        for b in range(TN):
            B = int(b)
            listSS[A + B] = listT[B]
        for z in listSS:
            moji += z

        answer = moji.replace('?', 'a')
        print(answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<ll,ll>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define iof  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi acos(-1)
const int mxn=1e9+5;
int main()
{
    fast;
    string s;
    cin>>s;
    ll sum=0;
    for(auto i:s)
    {
        sum+=i-'0';
    }
    cout<<(sum%9?"No":"Yes")<<endl;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = (c+b-1)/b;
  int y = (a+d-1)/d;
  if(x <= y) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    string s,t;
    cin >> s;
    cin >> t;
    ll cnt = 0;
    for(ll i=0;i<s.size();i++) {
    	if(s[i] != t[i]) {
    		cnt++;
    	}
    }
    cout << cnt << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 505;
int arr[N];
ll sum = 0;
ll ans = 1;
int n, k;

bool can(ll x) {
    vector<ll> v, acc(n);
    loop(i, n)v.push_back(arr[i] % x);
    sort(ALL(v));
    acc[n - 1] = v[n - 1];
    rloop(i, n - 2)acc[i] = acc[i + 1] + v[i];
    ll sum = 0;
    loop(i, n - 1) {
        sum += v[i];
        if (sum == x * (n - i - 1) - acc[i + 1])return sum <= k;
        if (sum > k)return false;
    }
    return false;
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    loop(i, n)cin >> arr[i], sum += arr[i];

    for (ll i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (can(i))ans = max(ans, i);
            if (sum / i != i && can(sum / i))ans = max(ans, sum / i);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int i,j,n,t;
    cin >> n;
    if(n==1)
    {
        cout << "Hello World"<< endl;
    }
    else if(n==2)
    {
        cin >> i >> j;
        cout << i+j << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[4][4];
int x[4],y[4];
int main(){
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin>>a[i][j];
        }
    }
    for(x[1]=0;x[1]<=100;x[1]++){
        for(x[2]=0;x[2]<=100;x[2]++){
            for(x[3]=0;x[3]<=100;x[3]++){
                y[1]=a[1][1]-x[1];
                y[2]=a[2][2]-x[2];
                y[3]=a[3][3]-x[3];
                int ok=1;
                for(int i=1;i<=3;i++){
                    for(int j=1;j<=3;j++){
                        if(x[i]+y[j]!=a[i][j]){
                            ok=0;
                        }
                    }
                }
                if(ok){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 5010
#define inf 1000000000000000ll
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,A,B;
struct data
{
	int x,y;
	bool operator <(const data&a) const
	{
		return x<a.x||x==a.x&&y<a.y;
	}
}a[N];
ll f[N][N<<1];
signed main()
{
	n=read(),A=read(),B=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=i;
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		ll s=inf;
		for (int j=0;j<=n*2;j++)
		{
			s=min(s,f[i-1][j]);
			if (j&1)
			{
				f[i][j]=s+((j+1>>1)==a[i].y?0:((j+1>>1)<a[i].y?B:A));
			}
			else
			{
				f[i][j]=s+(((j>>1)<a[i].y?B:A));
			}
		}
	}
	ll ans=inf;
	for (int i=0;i<=n*2;i++) ans=min(ans,f[n][i]);
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//考虑看做可以将数放到实数位置 向左a代价 向右b代价 不变0代价 

Measured memory_bytes: 391680
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int A, B, M;
int a[101010], b[101010];
int x[101010], y[101010], c[101010];

void solve() {
    int ans = INF;
    int MINA = INF, MINB = INF;
    FOR(A) {
        chmin(MINA, a[i]);
    }
    FOR(B) {
        chmin(MINB, b[i]);
    }
    ans = MINA + MINB;
    FOR(M) {
        chmin(ans, a[x[i]] + b[y[i]] - c[i]);
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> A >> B >> M;
    FOR(A)
    cin >> a[i];
    FOR(B)
    cin >> b[i];
    FOR(M) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
    }
    solve();
    return 0;
}


Measured memory_bytes: 4224
n , m = map(int,input().split())
kagi = []
for i in range(m):
    a , b = map(int,input().split())
    c = list(map(lambda x:int(x)-1,input().split()))
    k = 0
    for j in c:
        k += 2**j
    kagi.append((a,k))
dp = [[float("inf") for i in range(2**n)] for j in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for j in range(2**n):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j])
        dp[i+1][j | kagi[i][1]] = min(dp[i+1][j | kagi[i][1]],dp[i][j] + kagi[i][0])

if dp[-1][-1] != float("inf"):
    print(dp[-1][-1])
else:
    print(-1)

Measured memory_bytes: 135700
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

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

int a[200010], b[200010], c[200010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    cin >> a[i];
    --a[i];
  }
  int ret = 0;
  REP(x, n) {
    b[a[x]]++;
    if(a[x]+1-b[a[x]] >= 0) {
      if(c[a[x]+1-b[a[x]]] == 0) ret++;
      c[a[x]+1-b[a[x]]]++;
    }
  }
  // cout << "b:"; REP(i, n) cout << b[i] << " "; cout << endl;
  // cout << "c:"; REP(i, n) cout << c[i] << " "; cout << endl;
  // cout << n-ret << endl;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    if(a[x]+1-b[a[x]] >= 0) {
      c[a[x]+1-b[a[x]]]--;
      if(c[a[x]+1-b[a[x]]] == 0) ret--;
    }
    b[a[x]]--;
    a[x] = y;
    b[a[x]]++;
    if(a[x]+1-b[a[x]] >= 0) {
      if(c[a[x]+1-b[a[x]]] == 0) ret++;
      c[a[x]+1-b[a[x]]]++;
    }
    // cout << "b:"; REP(i, n) cout << b[i] << " "; cout << endl;
    // cout << "c:"; REP(i, n) cout << c[i] << " "; cout << endl;
    cout << n-ret << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
import itertools

N, M = map(int, input().split())
KS = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in itertools.product(range(2), repeat=N):
    cnt = [0 for _ in range(M)]  # 各電球のスイッチがオンになっている数
    for c, k in enumerate(KS):  # 電球Kが関係しているスイッチを調べる
        for j in k[1:]:
            j -= 1
            if i[j] == 1:
                cnt[c] += 1

    for m, c in enumerate(cnt):
        if c % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 9148
import math
a, b, C = map(float, input().split())
C = math.radians(C)
c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(C)) ** 0.5
S = (a * b * math.sin(C)) * 0.5
h = b * math.sin(C)
print(S, a + b + c, h, sep = '\n')


Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int m = 26;

int main(){
    ll n,m; cin >> n >> m;
    vpl v(n);
    rep(i,n) cin >> v[i].first >> v[i].second;
    sort(all(v));
    int now = 0;
    multiset<ll> mse;
    ll ans = 0;
    REP(i,1,m+1){
        while(now < n && v[now].first <= i){
            mse.insert(v[now].second);
            now++;
        }
        if(!mse.empty()){
            ans += *mse.rbegin();
            mse.erase(prev(mse.end(),1));
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 9548
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
int main(void){
	int n;
	double x[1000];
	double m,ans;
	for (;;){
		m = 0;
		ans = 0;
		scanf("%d", &n);
		if (n == 0)break;
		f(i, n){
			scanf("%lf", &x[i]);
			m += x[i];
		}
		m = m / n;
		f(i, n){
			ans += (x[i] - m)*(x[i] - m);
		}
		ans = ans / n;
		printf("%f\n", sqrt(ans));
	}
	return 0;
}

Measured memory_bytes: 2676
K,N = map(int,input().split())
A = list(map(int,input().split()))
min_distance = 10000000
distance = 0

for i in range(N):
  if i == 0:
    distance = A[N-1] - A[0]
  elif i == N-1:
    distance = (K-A[i])+A[i-1]
  else:
    distance = (K-A[i+1])+A[i]
  if distance < min_distance:
    min_distance = distance
print(min_distance)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

char s[5005];
int dp[5005][5005];
int main(){
    int n;
    scanf("%d%s", &n, s);
    int m = strlen(s);
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            if(j == 0) dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
            else dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j])%mod;

            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]*2%mod)%mod;
        }
    }
    int ans = dp[n][m];
    for(int i=0;i<m;i++) ans = ans*1ll*((mod+1)/2)%mod;
    printf("%d\n", ans);
}

Measured memory_bytes: 101564
// Date: 2020-03-18

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 400 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL dp[N][N], val[N][N];
int n, m, a[N], b[N];

int main() {
    FIO;
    cin >> n >> m;
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n) cin >> b[i];
    rep(i, 1, n) {
        rep(k, a[i], b[i]) {
            LL cur = 1;
            rep(j, 0, m) {
                val[i][j] += cur;
                val[i][j] %= mod;
                cur = cur * k % mod;
            }
        }
    }
    dp[0][0] = 1;
    rep(i, 1, n) {
        rep(j, 0, m) {
            rep(k, 0, j) {
                dp[i][j] = (dp[i][j] + dp[i-1][k] * val[i][j-k] % mod) % mod;
            }
        }
    }
    cout << dp[n][m];

    return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main(){
  int N,M,i,num=1;
  scanf("%d %d",&N,&M);
  if(N>=1&&N<=100&&M>=1&&M<=N&&M<=5){
    for(i=0;i<M;i++){
      num*=2;
    }
    printf("%d\n",(M*1900+(N-M)*100)*num);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pcase printf("Case %d:\n",ca)
int ca=1;
using namespace std;
int main(){
   int a;
   cin>>a;
   int arr[a];
   for(int i = 0;i<a;i++){
    cin>>arr[i];
   }
   int ma = arr[0];
   ll ans = 0;
   for(int i = 1;i<a;i++){
        ma = max(arr[i],ma);
    if(arr[i]<ma){
        ans+=ma-arr[i];
    }
   }
   cout<<ans<<nl;
   }




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

 
int main(){
  int n,k,r,s,p;
  int64_t score=0;
  string t;
  cin>>n>>k>>s>>p>>r>>t;
  vector<char>vec(n);
  for(int i=0;i<n;i++)vec[i]=t[i];
  for(int i=0;i<n;i++){
    if(vec[i]=='r' &&  !(i>=k && vec[i-k]=='r')){
      score+=r;
    }
   if(vec[i]=='r' &&  (i>=k && vec[i-k]=='r')){
      vec[i]='a';
    }
    if(vec[i]=='s' &&  !(i>=k && vec[i-k]=='s')){
      score+=s;
       
    }
    if(vec[i]=='s' &&  (i>=k && vec[i-k]=='s')){
      vec[i]='a';
    }   
    if(vec[i]=='p' &&  !(i>=k && vec[i-k]=='p')){
      score+=p;
     
    }
     if(vec[i]=='p' &&  (i>=k && vec[i-k]=='p')){
      vec[i]='a';
     
    }
  }
    cout<<score<<endl;
  }
  

Measured memory_bytes: 512