akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{int n,d;
	cin >> n>>d;
	long long int x,y;
	int ans=0;
for(int i=0;i<n;i++){
    cin>>x>>y;
    if((ll)x*x+(ll)y*y<=(ll)d*d){
        ans++;
    }
}
	   cout<<ans;
	return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;
  map<string, int> mp;

  char c;
  rep(i, n) {
    string s; cin >> s;
    mp[s]++;
    if (mp[s] > 1) {
      cout << "No" << endl;
      return 0;
    }
    if (i!=0 && s.at(0) != c) {
      cout << "No" << endl;
      return 0;
    }
    c = s.at(s.size()-1);
  }
  cout << "Yes" << endl;
}


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

typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll result = N - 1;

    ll quotient, remain;
    for (ll i = 2; i * i <= N; i++) {
        quotient = N / i;
       remain = N % i;
        if (remain == 0 && (i + quotient - 2) < result) {
            result = i + quotient - 2;
        }
    }

    if (N == 1) {
        result = N - 2;
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int n,a[100005];
set<int> s;
vector<int> v;
int maxn=1;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n;
  REP(i,n){
    cin>>a[i];
    s.insert(a[i]);
  }
  sort(a,a+n);
  for(int x=0;x<100001;x++){
    int t1=lower_bound(a,a+n,x)-a;
    int t2=upper_bound(a,a+n,x)-a;
    v.push_back(t2-t1);
  }
  for(int i=0;i<(int)v.size();i++){
    if(i+2>=(int)v.size())continue;
    maxn=max(v[i]+v[i+1]+v[i+2],maxn);
  }
  P(maxn);
  return 0;
}


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

const int maxN = 4010;
const int mod = 998244353;
typedef long long ll;

int C[maxN][maxN], pw[maxN];

void init(){
	int i, j;
	C[0][0] = 1;
	for(i = 1; i < maxN; ++i){
		C[i][0] = C[i][i] = 1;
		for(j = 1; j < i; ++j){
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}
	for(i = 1, pw[0] = 1; i < maxN; ++i)
		pw[i] = (pw[i - 1] << 1) % mod;
}

inline int Cbar(int n, int k){
	if(k < 0){
		return 0;
	}
	return C[n + k - 1][k];
}

int main (){
	int k, n, i, j, cnt;
	scanf("%d%d", &k, &n);
	init();
	for(i = 2; i <= 2 * k; ++i){
		ll ans = 0;
		for(j = 1, cnt = 0; j <= k; ++j)
			if(0 < (i - j) && (i - j) <= k) ++cnt;
		if(cnt & 1){
			cnt /= 2;
			for(j = 0; j <= cnt; ++j){
				ll t = (C[cnt][j] * 1ll * Cbar(k - 1 - j - (cnt - j) * 2, n - j)) % mod;
				t = (t * pw[j]) % mod;
				ans = (ans + t) % mod;
			}
			for(j = 0; j <= cnt; ++j){
				ll t = (C[cnt][j] * 1ll * Cbar(k - 1 - j - (cnt - j) * 2, n - 1 - j)) % mod;
				t = (t * pw[j]) % mod;
				ans = (ans + t) % mod;
			}
		}
		else{
			cnt /= 2;
			for(j = 0; j <= cnt; ++j){
				ll t = (C[cnt][j] * 1ll * Cbar(k - j - (cnt - j) * 2, n - j)) % mod;
				t = (t * pw[j]) % mod;
				ans = (ans + t) % mod;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 49204
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

c1 = Counter(D)
c2 = Counter(T)

for k, v in c2.items():
    if v <= c1[k]:
        continue
    else:
        print("NO")
        break
else:
    print("YES")


Measured memory_bytes: 57048
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void read(i64 &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
int n,k;char c;i64 v0,v1,v2;
int main(){
	read(n);read(v0);v1=v2=-1e18;
	rep(i,1,n-1){
		scanf(" %c",&c);read(k);
	//	putchar(c);
		if(c=='-')k=-k;
		i64 val0=v0+k,val1=v1-k,val2=v2+k;
		v0=max(val0,max(val2,val1));
		if(c=='+')v1=max(val1,val2),v2=val2;
		else v1=max(val0,max(val1,val2)),v2=max(val1,val2);
	}cout<<v0<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
range = xrange
input = raw_input

n = int(input())
A = [int(x) for x in input().split()]

money = 1000
for i in range(n - 1):
    if A[i] < A[i + 1]:
        money += (money//A[i]) * (A[i + 1] - A[i])
print money


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

int main(){
  int n,c,k;
  cin>>n>>c>>k;
  vector<int> t;
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    t.push_back(m);
  }
  sort(t.begin(),t.end());
  int cnt=0;
  for(int i=0;i<n;){
    int m=t[i++];
    for(int j=0;j<c-1&&i<n;i++,j++)
      if(m+k<t[i]) break;
    cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 892
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if ((a < b) && (b < c)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 26232
import itertools
P, Q, R = (int(i) for i in input().split())

d = {"AB": P, "BC": Q, "AC":R, "BA": P, "CB":Q, "CA":R}
min = P+Q+R
roots = itertools.permutations("ABC", 3)

for r in roots:
    sumtime = 0
    sumtime+= d[r[0]+r[1]]
    sumtime += d[r[1]+r[2]]
    if sumtime < min:
        min = sumtime

print(min)


Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin >> s >> t;
    rep(i,s.size()-1){
        FOR(j,i+1,s.size()){
            if(s[i]>s[j]){
                swap(s[i],s[j]);
            }
        }
    }
    rep(i,t.size()-1){
        FOR(j,i+1,t.size()){
            if(t[i]<t[j]){
                swap(t[i],t[j]);
            }
        }
    }
    if(s<t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323



void solve()
{
       ll n;
       cin>>n;
       ll h[n];
       rep(i,0,n) cin>>h[i];
       ll ans=1, f=1;
       rep(i,1,n)
       {      f=1;
              rep(j,0,i)
              {
                     if(h[i]<h[j]) f=0;
              }
              if(f==1) ans++;
       }
       cout<<ans;
}


int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	while(true){
		int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0;i < h; ++i){
			for(int j = 0;j < w; ++j){
				if((i+j)%2 == 0){
					cout << '#';
				} else {
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

const int NMAX = 500 + 5;
int mat[NMAX][NMAX];

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    if (H % h == 0 && W % w == 0) {
        cout << "No\n";
        return 0;
    }

    mat[0][0] = 1000000000 - 1;
    mat[h - 1][w - 1] = -1000000000;
    for (int i = 0; i < H; ++ i)
        for (int j = 0; j < W; ++ j)
            mat[i][j] = mat[i % h][j % w];


    cout << "Yes\n";
    for (int i = 0; i < H; ++ i)
        for (int j = 0; j < W; ++ j)
            cout << mat[i][j] << " \n"[j + 1 == W];
    return 0;
}


Measured memory_bytes: 3968
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in graph[0]:
    if n-1 in graph[i]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 38320
import sys

N,M = map(int, input().split())

strNs = []
strMs = []

for n in range(N):
	strNs.append(input())
	
for m in range(M):
	strMs.append(input())
	
def check_rest(start_row, start_col):
	for j in range(1,M):
		if strNs[start_row+j][start_col:start_col+M] != strMs[j]:
			return False
	else:
		return True
		

for i in range(N-M+1):
	tmp = strNs[i].find(strMs[0])
	while tmp >= 0:
		if check_rest(i, tmp):
			print("Yes")
			sys.exit()
		elif tmp + M > N:
			break
		else:
			tmp = strNs[i].find(strMs[0],tmp+1)
			
print("No")

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9+7;

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

int main() {
  int n;
  scanf("%d", &n);
  vector<T> blocks;
  for (int i = 0; i < n; i++) {
    int w, s, v;
    scanf("%d %d %d", &w, &s, &v);
    blocks.emplace_back(s, w, v);
  }

  sort(blocks.begin(), blocks.end(), [](T& t1, T& t2) {return get<0>(t1) + get<1>(t1) < get<0>(t2) + get<1>(t2);});

  const int MAXS = 2e4+10;
  vector<vector<ll>> dp(n, vector<ll>(MAXS, 0));
  for (int s = get<1>(blocks[0]); s < MAXS; s++) {
    dp[0][s] = get<2>(blocks[0]);
  }
  for (int i = 1; i < n; i++) {
    auto& block = blocks[i];
    int slimit = get<0>(block);
    int w = get<1>(block), v = get<2>(block);
    for (int s = 0; s < w; s++) {
      dp[i][s] = dp[i-1][s];
    }
    for (int s = w; s < MAXS; s++) {
      dp[i][s] = max(dp[i-1][s], v + dp[i-1][min(s - w, slimit)]);
    }
  }
  
  printf("%lld\n", dp[n-1][MAXS - 1]);
}


Measured memory_bytes: 160512
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> ps(n);

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

    int cnt = 0;
    for(int i = 1; i < n - 1; i++) {
        if (
            (ps[i-1] < ps[i] && ps[i] < ps[i+1])
            || (ps[i-1] > ps[i] && ps[i] > ps[i+1])
        ) cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;

LL gcd(LL m, LL n)
{
  LL temp;
  if (m < n) {temp = n; n = m; m = temp;}
  while (m % n != 0)
    {
      temp = n;
      n = m % n;
      m = temp;
    }
  return n;
}

int main() {
  LL A, B, C, D;
  cin >> A >> B >> C >> D;
  
  LL bc_count  = B / C;
  LL bd_count  = B / D;
  LL bcd_count = B / (C+D);
  LL lcm = C * D / gcd(C,D);
  LL b_count = LL(B / C) + LL(B / D) - LL(B / lcm);
  LL a_count = LL((A-1) / C) + LL((A-1) / D) - LL((A-1) / lcm);
  LL num = b_count - a_count;
  LL answer = B - A + 1 - num;
  
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <cstddef>
#include <cinttypes>

#include <type_traits>
#include <limits>
#include <vector>
#include <algorithm>

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<std::vector<std::pair<unsigned, size_t>>> B(N+1);
  std::vector<unsigned> Y(M);
  std::vector<size_t> P(M);
  for (size_t i=0; i<M; ++i) {
    scanf("%zu %u", &P[i], &Y[i]);
    B[P[i]].emplace_back(Y[i], i);
  }

  for (size_t j=1; j<=N; ++j)
    std::sort(B[j].begin(), B[j].end());

  std::vector<std::pair<unsigned, size_t>> res(M);
  for (size_t j=1; j<=N; ++j)
    for (size_t k=0; k<B[j].size(); ++k)
      res[B[j][k].second] = {j, k+1};

  for (size_t i=0; i<M; ++i)
    printf("%06u%06zu\n", res[i].first, res[i].second);
}


Measured memory_bytes: 9728
#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<int> A(N);
	int res = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	res = sum;
	int t = 0;
	for (int i = 0; i < N; i++) {
		t += A[i];
		res = min(res, abs(sum - t - t));
	}
	cout << res << endl;
}

Measured memory_bytes: 256
Tmp = []
Tmp = input().rstrip().split(' ')
 
sA = (Tmp[0])
sB = (Tmp[1])
 
if sA == 'H' and sB == 'H':
  print('H')
elif sA == 'H' and sB == 'D':
  print('D')
elif sA == 'D' and sB == 'D':
  print('H')
elif sA == 'D' and sB == 'H':
  print('D')

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321987654321
#define PI 3.14159265358979323846264
#define MOD 20091101
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

int n, cnt[100];
int main() {
	scanf("%d", &n);
	int K = 0;
	fup(i, 0, n - 1, 1)
	{
		int x;
		scanf("%d", &x);
		cnt[x]++;
		K = max(K, x);
	}
	if (K & 1)
	{
		fup(i, K / 2 + 1, K, 1)
		{
			cnt[i] -= 2;
			if (cnt[i] < 0)
			{
				puts("Impossible");
				return 0;
			}
		}
		fup(i,1,K/2+1,1)
			if(cnt[i])
			{
				puts("Impossible");
				return 0;
			}
	}
	else
	{
		cnt[K / 2]++;
		fup(i, K / 2, K, 1)
		{
			cnt[i] -= 2;
			if (cnt[i] < 0)
			{
				puts("Impossible");
				return 0;
			}
		}
		fup(i, 1, K / 2, 1)
			if (cnt[i])
			{
				puts("Impossible");
				return 0;
			}
	}
	puts("Possible");
}

Measured memory_bytes: 384
class Graph(): #non-directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]-1].append(e[1]-1)
            self.graph[e[1]-1].append(e[0]-1)
            self.deg[e[0]-1] += 1
            self.deg[e[1]-1] += 1

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
H = list(map(int, input().split()))

E = [tuple(map(int, input().split())) for _ in range(M)]

G = Graph(N, E)

res = 0

for node in range(N):
    flag = True
    for adj in G.graph[node]:
        if H[adj] >= H[node]:
            flag = False
            break
    res += flag

print(res)

Measured memory_bytes: 43688
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String[] array = reader.readLine().split(" ");
            int H = Integer.parseInt(array[0]);
            int W = Integer.parseInt(array[1]);
            int A = Integer.parseInt(array[2]);
            int B = Integer.parseInt(array[3]);

            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < B; i++) {
                for (int j = 0; j < A; j++) {
                    ans.append("0");
                }
                for (int j = A; j < W; j++) {
                    ans.append("1");
                }
                ans.append("\n");
            }
            for (int i = B; i < H; i++) {
                for (int j = 0; j < A; j++) {
                    ans.append("1");
                }
                for (int j = A; j < W; j++) {
                    ans.append("0");
                }
                ans.append("\n");
            }

            System.out.print(ans.toString());
        }
    }

}


Measured memory_bytes: 30240
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
using namespace std;
ll num[100005];
int main () {
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%lld", &a);
	for (i = 1; i <= a; i++) scanf("%lld", &num[i]);
	stable_sort(num + 1, num + a + 1);
	for (i = 2; i <= a; i++) {
		if (num[i] == abs(num[i - 1])) num[i] = -num[i];
	}
	b = a;
	for (i = 1, j = a; i <= a; i++) {
		if (num[i] > 0) continue;
		while (j >= 1 && num[j] > 0) j--;
		b -= 2;
		if (j == 0) break;
		num[i] = -num[i]; num[j] = -num[j];
	}
	printf("%lld\n", b);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int  M = N;
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (M % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
stdin=sys.stdin

ns=lambda:stdin.readline().rstrip()
ni=lambda:int(stdin.readline().rstrip())
nm=lambda:map(int,srdin.readline().split())
nl=lambda:list(map(int,stdin.radline().split()))
a=int(input())
s=input()
print(s if 3200<=a else 'red')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    vector<int> vc( 3 );
    for( auto &x : vc )
    {
        cin >> x;
    }
    REP( i, 3 )
    {
        if( count( ALL( vc ), vc[ i ] ) == 1 )
        {
            cout << vc[ i ] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,a[5]={0};
string s[100000],b[5]={"AC","WA","TLE","RE"};
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>s[i];
		rep(j,4) if(s[i]==b[j]) a[j]++;
	}
	rep(i,4) cout<<b[i]<<" x "<<a[i]<<endl;
	return 0;}

Measured memory_bytes: 6752
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
 
def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0
 
    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]
 
 
print(frog(n, k, h))

Measured memory_bytes: 56416
/////////////////////////////////////////////template 1
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

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

    return 0;
}

Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

C = [list(map(int, input().split())) for _ in range(3)]

for i in range(3):
    for j in range(3):
        lu = C[i][j]
        for ii in range(3):
            if i == ii:
                continue
            for jj in range(3):
                if j == jj:
                    continue
                rd = C[ii][jj]
                ld = C[ii][j]
                ru = C[i][jj]

                if lu + rd != ld + ru:
                    print('No')
                    exit()
print('Yes')


Measured memory_bytes: 65536
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll n, x, ans = 0, t;
	cin >> n >> x;
	vector<int> a(n);
	for(auto &i : a) cin >> i;
	for(int i = 0; i < n; i++) {
		if(a[i] > x) ans += a[i]-x, a[i] = x;
		if(i && a[i]+a[i-1] > x) ans += a[i]+a[i-1]-x, a[i] = x - a[i-1];
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, w;
  cin >> n >> w;
  vector<pair<ll, ll>> nw(n);
  // F:weight, S:value
  rep(i, n) cin >> nw[i].F >> nw[i].S;
  vector<vector<ll>> dp(n, vector<ll>(w + 1, 0));
  rep(i, n) {
    if (i >= 1) rep(j, w + 1) {
        dp[i][j] = dp[i - 1][j];
      }
    for (ll j = nw[i].F; j <= w; j++) {
      chmax(dp[i][j - nw[i].F], dp[i][j] + nw[i].S);
    }
  }
  cout << MAX(dp[n - 1]) << endl;
  ret;
}


Measured memory_bytes: 82328
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int sum = 700;
  string S;
  cin >> S;

  if(S[0]=='o') sum+=100;
  if(S[1]=='o') sum+=100;
  if(S[2]=='o') sum+=100;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

A, B, C, K = In.ints()

res = 0

res += min(K, A)

K-=A

if K>0:
    K-=B

    if K>0:
        res -= min(K, C)

Out.int(res)
 
######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 68104
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
struct edge{
  int from,to,cost,used;
  edge(){}
  edge(int from,int to,int cost):from(from),to(to),cost(cost){used=0;}
  bool operator<(const edge& e) const{
    return cost<e.cost;
  }
};
int kruskal(int N,vector<edge> &edges){
  int res=0;
  sort(edges.begin(),edges.end());
  UnionFind uf(N+1);
  for(int i=0;i<(int)edges.size();i++){
    edge& e=edges[i];
    if(!uf.same(e.from,e.to)){
      res+=e.cost;
      e.used=1;
      uf.unite(e.from,e.to);
    }
  }
  return res;
}
vector<int> G[555];
int C[555][555];
int INF=1LL<<55LL;
int num,ans;
int V,E;
unordered_set<int> dfs(int v,int p){
  //cout<<v<<" "<<p<<endl;
  unordered_set<int> res;
  res.insert(v);
  for(int u:G[v]){
    if(u==p) continue;
    int tmp=C[v][u];
    unordered_set<int> chd=dfs(u,v);
    int alt=INF;
    for(int i=0;i<V;i++){
      for(int j=i+1;j<V;j++){
	if(i==u&&j==v) continue;
	if(i==v&&j==u) continue;
	if(chd.count(i)^chd.count(j)) alt=min(alt,C[i][j]);
      }
    }
    //cout<<alt<<" "<<tmp<<endl;
    if(alt>tmp){
      num++;
      ans+=tmp;
    }
    for(int i:chd) res.insert(i);
  }
  return res;
}
signed main(){
  cin>>V>>E;
  vector<edge> edges(E);
  for(int i=0;i<E;i++){
    cin>>edges[i].from>>edges[i].to>>edges[i].cost;
    edges[i].from--;
    edges[i].to--;
  }
  kruskal(V,edges);
  for(int i=0;i<555;i++)
    for(int j=0;j<555;j++)
      C[i][j]=INF;
  for(int i=0;i<E;i++){
    //cout<<i<<" "<<edges[i].used<<endl;
    if(edges[i].used){
      G[edges[i].from].push_back(edges[i].to);
      G[edges[i].to].push_back(edges[i].from);
    }
    C[edges[i].from][edges[i].to]=edges[i].cost;
    C[edges[i].to][edges[i].from]=edges[i].cost;
  }
  num=ans=0;
  dfs(0,-1);
  cout<<num<<" "<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6764
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long  int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const lli MOD = 998244353;
const lli MAX = 2100000;

lli fac[MAX], finv[MAX], inv[MAX];

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
lli COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lli add(lli a, lli b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}
lli mul(lli a, lli b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}
lli fastPow(lli base, lli p) {
	lli ret = 1;
	while (p) {
		if (p & 1) ret = mul(ret, base);
		base = mul(base, base);
		p >>= 1;
	}
	return ret;
}
void solve() {
	lli n, m, k;
	cin >> n >> m >> k;
	lli ret = 0;
	for (lli i = 0; i <= k; i++) {
		lli temp = COM(n - 1, i) % MOD;
		temp = mul(temp, m);
		temp = mul(temp, fastPow(m - 1, n - i - 1));
		ret = add(ret, temp);
	}
	cout << ret << endl;
}
int main()
{
	COMinit();
	zanj0();
	solve();
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

int main() {
  int N;
  cin >> N;
  vector<PII> input;
  for (int i = 0; i < N; i++) {
    LL a, b;
    cin >> a >> b;
    input.push_back(PII(b, a));
  }
  sort(input.begin(), input.end());
  LL sum = 0;
  bool ok = true;
  for (int i = 0; i < N; i++) {
    auto val = input[i];
    sum += val.second;
    if (val.first < sum) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int run();
int main() {
// #ifdef home
//     freopen("i", "r", stdin);
//     freopen("d", "w", stderr);
// #endif
//     cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}


int run() {
    int n,h,w;
    cin>>n>>h>>w;
    int ans=(n-h+1)*(n-w+1);
    if(ans<0)
        cout<<"0";
    else cout<<ans;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,iti,ni,goukei,max=0,b,bangou=0,i;
	//printf("??£????????°?????\?????????\n");
	scanf("%d",&n);
	while(n!=0)
	{
		for(i=0;i<=n-1;i++)
		{
			//printf("??£????????????\n");
			//printf("1???????????????????????¢\n");
			//printf("2???????????????????????¢\n");
			scanf("%d %d %d",&b,&ni,&iti);
			goukei=iti+ni;
			
			if(max<goukei)
			{
				max=goukei;
				 bangou=b;
			}
		}
	
	
		printf("%d %d\n",bangou,max);
		scanf("%d",&n);
		max=0;
		bangou=0;
	}
	return 0;
	
	
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int dp[5000];
int powm(int a, int b, int m) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1ll;
    }
    return res;
}
int fact[200005];

int calc(int dx, int dy, int mod) {
	return fact[dx + dy] * powm(fact[dx] * fact[dy] % mod, mod - 2, mod) % mod;
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int m; cin >> m;
	int nu; cin >> nu;
	fact[0] = 1;
	int mod = 1e9 + 7;
	for (int i = 1; i < 200005; ++i) fact[i] = (fact[i - 1] * i) % mod;
	std::vector<pair<int, int> > c(nu);
	for (int i = 0; i < nu; ++i) { cin >> c[i].fi >> c[i].se; c[i].fi--; c[i].se--; } 
	c.pb(n - 1, m - 1);
	sort(c.begin(), c.end());
	for (int i = 0; i < nu + 1; ++i) {
		dp[i] = calc(c[i].fi, c[i].se, mod);
		for (int j = i - 1; j >= 0; --j)
			if (c[j].fi <= c[i].fi && c[j].se <= c[i].se) {
				int sij = calc(c[i].fi - c[j].fi, c[i].se - c[j].se, mod);
				dp[i] = dp[i] - sij * dp[j] % mod;
				if (dp[i] < 0) dp[i] += mod; 
			}
	}
	cout << dp[nu];
}

Measured memory_bytes: 2048
import bisect

def d162(n , sli):

    ans = 0
    Rli = []
    Gli = []
    Bli = []

    for i in range(n):
        if sli[i] == "R":
            Rli.append(i)
        elif sli[i] == "G":
            Gli.append(i)
        else:
            Bli.append(i)

    Rcount = len(Rli)
    Gcount = len(Gli)
    Bcount = len(Bli)
    Rli.sort()
    Gli.sort()
    Bli.sort()

    for i in range(n - 3):
        for w in range(i + 1 , n):
            if sli[i] != sli[w]:
                k = "RGB".replace(sli[i] , "").replace(sli[w] , "")
                if k == "R":
                    ans += Rcount - bisect.bisect_right(Rli , w)
                elif k == "G":
                    ans += Gcount - bisect.bisect_right(Gli , w)
                else:
                    ans += Bcount - bisect.bisect_right(Bli , w)
                if w + w - i < n and sli[w + (w - i)] == k:
                    ans -= 1

    return ans

def main():
    n = int(input())
    sli = list(str(input()))
    print(d162(n , sli))
if __name__ == '__main__':
    main()

Measured memory_bytes: 74936
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //Search for all i
    for (int i = 0; i < N; i++)
    {
        //Update the values of A[i+1] ... A[N]
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int x,n; cin>>x>>n;
    vector<int> p;
    rep(i,n){
        int v; cin>>v;
        p.push_back(v);
    }
    int ans;
    rep(i,100){
        bool judge=false;
        int pla=x+i;
        int mai=x-i;
        rep(j,n){
            if(p[j]==mai){
                judge=true;
                break;
            }
        }
        if(!judge) {
            ans=mai;
            break;
        }
        judge=false;
        rep(j,n){
            if(p[j]==pla){
                judge=true;
                break;
            }
        }
        if(!judge) {
            ans=pla;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cmath>
#define int long long
signed main(){
  const double PI= 3.1415926535897932384626433832795029L ;
double a,b,x,temp,ans;
std::cin>>a>>b>>x;
temp=x/a/a;
if(a*a*b==x){
  ans=0.0;
}
else if(a*a*b/2.0L<=x){
  ans=std::atan(((b-temp)*2.0L)/a);
  ans=ans/PI*180.0L;
}else{
  ans=std::atan2(b,x/a/b*2.0L);
  ans=ans/PI*180.0L;
}
printf("%.16f", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

llint dp[1000][5] = {};

int main(void){

  std::string N;
  llint K;
  std::cin >> N >> K;

  dp[0][0] = 1;
  dp[1][0] = 1;
  dp[1][1] = 9;
  for(int keta=2; keta<200; keta++){
    for(int k=0; k<4; k++){
      dp[keta][k] += dp[keta-1][k];
      dp[keta][k+1] += dp[keta-1][k]*9;
    }
  }

  
  std::vector<std::pair<int, int> > data;  
  
  llint result = 0;
  while(N.size() != 0){
    llint i_ketame = N[0]-'0';
    if(i_ketame == 0){
      N = N.substr(1);
      continue;
    }
    
    for(llint j=0; j<i_ketame; j++){
      data.push_back(std::make_pair(N.size()-1, j==0?K:K-1));
    }
    N = N.substr(1);
    K--;
    if(K<0) break;
  }
  if(K==0) result++;
  for(const auto& elem: data){
    if(elem.second<0) continue;
    //std::cout << elem.first << " " << elem.second << std::endl;
    //std::cout << dp[elem.first][elem.second] << std::endl;;
    result += dp[elem.first][elem.second];
  }
  std::cout << result << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
def f(x):
    if len(x) == n:
        p.append(x)
    else:
        for i in S:
            f(x+[i])

n , a , b , c = map(int,input().split())
take = [int(input()) for i in range(n)]
S = [0,1,2,3]
p = []
f([])
ans = 10**9
for i in range(len(p)):
    sai = [0,0,0]
    cou = 0
    for j in range(n):
        if p[i][j] != 3:
            if sai[p[i][j]] == 0:
                cou -= 10
            sai[p[i][j]] += take[j]
            cou += 10
    sai.sort()
    if sai[0] == 0:
        continue
    cou += abs(sai[0]-c)+abs(sai[1]-b)+abs(sai[2]-a)
    ans = min(ans,cou)
    
print(ans)

Measured memory_bytes: 12916
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    ll pre[n]={0},suf[n]={0};
    for (i=1;i<n;i++)
    {
        pre[i]=__gcd(pre[i-1],a[i-1]);
        suf[n-i-1]=__gcd(suf[n-i],a[n-i]);
    }
    ll ans=0;
    for (i=0;i<n;i++)
        ans=max(ans,__gcd(pre[i],suf[i]));
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(void)
{
    int d;

    scanf("%d",&d);
         if (d==22) printf("Christmas Eve Eve Eve\n");
    else if (d==23) printf("Christmas Eve Eve\n");
    else if (d==24) printf("Christmas Eve\n");
    else if (d==25) printf("Christmas\n");
    return 0;
}


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

char map[21][21];
int tx[4] = {-1,0,1,0};
int ty[4] = {0,1,0,-1};
int w,h,c;

int search(int y,int x){
  int i,nx,ny;
  c++;
  for(i=0;i<4;i++){
    nx=x+tx[i];
    ny=y+ty[i];
    if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]!='#'){
      map[ny][nx]='#';
      search(ny,nx);
    }
  }
  
  return c;
  
}

int main(){

  int i,j,nx,ny;
  int a;

  while(1){
    c=0;
    cin>>w>>h;
  
    if(w==0&&h==0){
      break;
    }	    
 
    
    for(i=0; i<h ; i++){
      for(j=0; j<w ; j++){
	cin>>map[i][j];
	if(map[i][j]=='@'){
	  nx = j;
	  ny = i;
	}
      } 
    }
    
    map[ny][nx]='#';
    a=search(ny,nx);
    cout<<c<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll pow_mod(ll n, ll p, ll mod) {
    if (p == 0) {
        return 1;
    } else if (p % 2 == 1) {
        return pow_mod(n, p - 1, mod) * n % mod;
    } else {
        ll s = pow_mod(n, p / 2, mod);
        return s * s % mod;
    }
}
vector<ll> list_mod_inverse(ll n, ll m) {
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i)
        inv[i] = inv[m % i] * (m - m / i) % m;
    return inv;
}
ll nck(ll n, ll k, ll m) {
    if (n - k < k) k = n - k;
    auto inv = list_mod_inverse(k + 1, m);
    ll ret = 1;
    REP1(i, k) {
        ret *= ((n - i + 1) * inv[i]) % m;
        ret %= m;
    }
    return ret;
}

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll p = (nck(n, a, MOD) + nck(n, b, MOD)) % MOD;
    ll x = (pow_mod(2, n, MOD) + MOD - 1) % MOD;
    ll ans = (x - p + MOD) % MOD;
    cout << ans << endl;
}


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

vector< vector<ll > > multmat(vector< vector<ll> > a, vector< vector< ll > > b, ll n){
	ll mod = 1e9 + 7;
	vector< vector< ll > > temp(n, vector< ll > (n, 0));
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)
			for(int k = 0 ; k < n ; k++){
				temp[i][k] += a[i][j] * b[j][k];
				temp[i][k] %= mod;
			}
	return temp;
}

int main(){
	ll n, k;
	cin >> n >> k;
	vector< vector< ll > > edges(n, vector< ll > (n, 0));
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)
			cin >> edges[i][j];
	// vector< vector< ll > > can(n, vector< ll > (n));
	// can = edges;
	vector< vector< ll > > paths(n, vector< ll > (n, 0));
	for(int i = 0 ; i < n ; i++)
		paths[i][i] = 1;
	while( k ){
		if( k % 2 )
			paths = multmat(paths, edges, n);
		k /= 2;
		edges = multmat(edges, edges, n);
	}
	ll ans = 0, mod = 1e9 + 7;
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)
			ans = (ans + paths[i][j]) % mod;
	cout << ans << endl;
	return(0);
}

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

#define ll long long

using namespace std;

int a[100010],b[100010],c[100010];

int main()
{
    int n;
    ll k;
    cin >> n >> k;

    for(int i=0;i<n;i++)
        cin >> a[i];

    /*b[0] = 0;

    for(int i=1;i<n;i++)
    {
        if(a[i] < a[b[i-1]])
            b[i] = i;
        else
            b[i] = b[i-1];
    }*/

    c[n-1] = n-1;

    for(int i=n-2;i>=0;i--)
    {
        if(a[i] > a[c[i+1]])
            c[i] = i;
        else
            c[i] = c[i+1];
    }

    /*for(int i=0;i<n;i++)
        cout << a[b[i]] << " ";
    cout << endl;

    for(int i=0;i<n;i++)
        cout << a[c[i]] << " ";
    cout << endl;*/

    ll ans = 0;
    int c1 = 0;
    //pair <int,int> p;

    for(int i=0;i<n-1;i++)
    {
        ll temp = a[c[i+1]] - a[i];

        if(ans < temp)
        {
            ans = temp;
            c1 = 1;
        }
        else if(ans == temp)
            c1++;
    }

    cout << c1 << endl;
}

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

int top, s[1000];

void push(int x)
{
	s[++top] = x;
}


int pop()
{
	top--;
	return s[top+1];
}


int main(void)
{
	int a, b;
	top = 0;
	char s[1000];
	
	while(scanf("%s", s) != EOF){
		if(s[0] == '+')
		{
			a = pop();
			b = pop();
			push(a+b);
		}
		else if(s[0] == '-')
		{
			b = pop();
			a = pop();
			push(a-b);
		}
		else if(s[0] == '*')
		{
			a = pop();
			b = pop();
			push(a*b);
		}
		else
		{
			push(atoi(s));
		}
	}
	
	printf("%d\n", pop());
	
	return 0;
}



Measured memory_bytes: 2092
//
// Copyright 2020 TuringEdu. All Rights Reserved.
//
// FileName: C.cc
// Author: Beiyu Li <sysulby@gmail.com>
// Date: 2020-06-16
//
#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;

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

using LL = long long;
using Pii = pair<int, int>;
template <typename T>
using Heap = __gnu_pbds::priority_queue<T, greater<T>,
      __gnu_pbds::pairing_heap_tag>;
template <typename T>
using BST = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>,
      __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 100000 + 5;

int n;
int a[maxn];
int vec[maxn], sz;
int s[maxn], t[maxn];

LL merge_sort(int l, int r) {
  if (l == r) return 0;
  int mid = (l + r) / 2;
  LL ret = merge_sort(l, mid) + merge_sort(mid + 1, r);
  int i = l, j = mid + 1, p = l;
  while (i <= mid || j <= r) {
    if (j > r || (i <= mid && s[i] <= s[j])) t[p++] = s[i++];
    else t[p++] = s[j++], ret += mid - i + 1;
  }
  For(i,l,r) s[i] = t[i];
  return ret;
}

bool check(int x) {
  s[0] = 0;
  For(i,1,n) s[i] = s[i-1] + (a[i] < x? -1: 1);
  return merge_sort(0, n) * 2 <= (LL)n * (n + 1) / 2;
}

int main() {
  scanf("%d", &n);
  For(i,1,n) {
    scanf("%d", &a[i]);
    vec[sz++] = a[i];
  }
  sort(vec, vec + sz);
  sz = unique(vec, vec + sz) - vec;
  int l = 0, r = sz - 1;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (check(vec[mid])) l = mid;
    else r = mid - 1;
  }
  printf("%d\n", vec[l]);

  return 0;
}

Measured memory_bytes: 1792