akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	string S;
	cin >> S;

	string ans;
	if (S == "Sunny")
		ans = "Cloudy";
	else if (S == "Cloudy")
	{
		ans = "Rainy";
	}
	else
		ans = "Sunny";

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

bool is_square(int n)
{
	int x = (int)sqrt((double)n);
	return x * x == n;
}

bool z_ok(int n, int x, int y)
{
	int b = x + y;
	int c = x * x + y * y + x * y - n;
	int D = b * b - 4 * c;

	if (D < 0) {
		return false;
	}
	if (!is_square(D)) {
		return false;
	}

	int D2 = (int)sqrt((double)D);


	if ((b % 2) != (D2 % 2)) {
		return false;
	}

	int z = -b + D2;

	return z >= 1;
}

int f(int n)
{
	int ans = 0;
	for (int x = 1; x * x <= n; ++x) {
		for (int y = 1; x * x + y * y <= n; ++y) {
			if (z_ok(n, x, y)) {
				++ans;
			}
		}
	}
	return ans;
}

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

	for (int i = 1; i <= N; ++i) {
		cout << f(i) << endl;
	}
}


Measured memory_bytes: 3652
#include <iostream>

int main()
{
	int w, a, b;
	std::cin >> w >> a >> b;

	int ans = 0;
	if( ( a + w ) < b ) {
		ans = b - ( a + w );
	}
	if( ( b + w ) < a ) {
		ans = a - ( b + w );
	}

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



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

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
    int k = X * 4 - Y;
    if (X * 2 <= Y && k >= 0 && k % 2 == 0)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),x(n),y(n);
    for(int i=0;i<n;i++)cin>>a.at(i)>>x.at(i)>>y.at(i);
    int nowa=0,nowx=0,nowy=0;
    bool flag=true;
    for(int i=0;i<n;i++){
        int cost=abs(x.at(i)-nowx)+abs(y.at(i)-nowy);
        if(((a.at(i)-nowa)-cost)<0||((a.at(i)-nowa)-cost)%2!=0)flag=false;
        nowa=a.at(i);
        nowx=x.at(i);
        nowy=y.at(i);
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1408
s = input()

i = 0
j = len(s) - 1
ans = 0
while i != j:
    if abs(i - j) == 1:
        if s[i] == s[j]:
            break
    if s[i] != s[j]:
        if s[i] != "x" and s[j] != "x":
            print(-1)
            exit()
        elif s[i] != "x":
            j -= 1
        else:
            i += 1
        ans += 1
    else:
        i += 1
        j -= 1

print(ans)

Measured memory_bytes: 3316
n,ma,mb=map(int,input().split())
dp=[[[5000]*401for _ in range(401)] for _ in range(n+1)]
dp[0][0][0]=0
maa=mab=0
for i in range(1,n+1):
  a,b,c=map(int,input().split())
  maa+=a
  mab+=b
  for j in range(401):
    for k in range(401):dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-a][k-b]+c)
ans=5000
for i in range(1,min(maa//ma,mab//mb)+1):
  if dp[n][ma*i][mb*i]!=5000:ans=min(ans,dp[n][ma*i][mb*i])
print(-1if ans==5000else ans)

Measured memory_bytes: 98140
const input = require("fs").readFileSync("/dev/stdin", "utf8")
let cin = input.split(/ |\n/), cid = 0
const next = () => cin[cid++]
const nexts = (n) => cin.slice(cid, cid+=n).map(i=>parseInt(i))

const [A, B, H, M] = nexts(4)

const long = M * 6.0
const short = (H + M / 60) * 30.0
let angle = Math.abs(long - short)

// console.log(long, short, angle)

// console.log(long, short, angle)
const result = Math.sqrt(A**2 + B**2 - 2 * A * B * Math.cos(angle * (Math.PI / 180)))
console.log(result)


Measured memory_bytes: 29820
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int d,c;cin>>d>>c;
    cout<<d*c<<endl;
}


Measured memory_bytes: 3072
import numpy as np

H,W = map(int,input().split())
matrix = np.zeros((H,W))

h,w = map(int,input().split())

for i in range(h):
  matrix[i,:] = 1
for i in range(w):
  matrix[:,i] = 1

print(int(H*W - np.sum(np.sum(matrix))))

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

using namespace std;

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n + 1);
  REP(i, n - 1) cin >> a[i + 1];
  a[0] = a[1];
  a[n] = a[n - 1];
  int r = 0;
  REP(i, n){
    r += min(a[i], a[i + 1]);
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>
#include<unordered_map>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
const int N = 1e6 + 5;
const int M = 1e6 + 5;
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    if(n == 1) return puts("No"),0;
    int l = s.size();
    if(l & 1) return puts("No"),0;
    l = l/2;
    string s1 = s.substr(0,l);
    string s2 = s.substr(l,l);
    if(s1 == s2) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 256
n = int(input())
G = []
for i in range(n):
    T = [0]*n
    G.append(T)
for i in range(n):
    L = list(map(int,input().split()))
    for j in range(2,len(L)):
        G[i][L[j]-1] += 1
time = 1
D = [-1]*n
F = [-1]*n
def dfs(src):
    global time
    D[src] = time
    time += 1
    for dst in range(n):
        if G[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time
    time += 1
for root in range(n):
    if D[root] == -1:
        dfs(root)
for i in range(n):
    print(i+1,D[i],F[i])


Measured memory_bytes: 5780
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

}

Measured memory_bytes: 3608
#include <stdio.h>


int main(){
  int len, i, flag, temp, cnt = 0;
  int A[100];

  scanf("%d", &len);

  for(i = 0; i < len; i++){
    scanf("%d", &A[i]);
  }


  flag = 1;

  while(flag){
    flag = 0;

    for(i = len - 1; i > 0; i--){
      if(A[i] < A[i-1]){
	temp = A[i];
	A[i] = A[i-1];
	A[i-1] = temp;
	cnt++;
	flag = 1;
      }
    }
  }

  for(i = 0; i < len - 1; i++){
    printf("%d ", A[i]);
  }

  printf("%d\n%d\n", A[len - 1], cnt);


  return 0;
}



Measured memory_bytes: 2040
#coding: utf-8
import numpy as np

n, m, c = map(int, raw_input().split())

b = np.array(map(int, raw_input().split()))

counter = 0
for i in range(n):
    a = np.array(map(int, raw_input().split()))
    if(sum(a*b)+c > 0): counter += 1

print(counter)


Measured memory_bytes: 10536
#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'

const int N = 1e6;

using namespace std;

main()
{
    fast;
    ll n,p,i;
    cin>>n>>p;
    map<ll,int> factorization;
    ll k=p;
    for (i=2;i<=sqrt(p);i++)
    {
        while (k%i==0)
        {
            factorization[i]++;
            k/=i;
        }
    }
    if (k!=1)
        factorization[k]++;
    ll ans=1;
    for (auto e: factorization)
    {
        if (e.ss>=n)
        {
            ll cnt=e.ss/n;
            ans*=(ll)(pow(e.ff,cnt));
        }
    }
    cout<<ans<<endl;
}

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

int main() 
{
	ll a,b,c,d,w=1,t=0;
	cin>>a>>b>>c>>d;
	while(1)
	{
		if(t%2==0)
		{
			c=c-b;
			if(c<=0)
				break;
		}
		else
		{
			a=a-d;
			if(a<=0)
				break;
		}
		t++;
	}
	if(t%2==0)
	cout<<"Yes"<<"\n";
	else
	cout<<"No"<<"\n";
	return 0;
}


Measured memory_bytes: 3628
n = int(input())
ans = [0] * (pow(10, 4) + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            c = (x + y + z) ** 2 - x * y - y * z - z * x
            if c <= 10000:
                ans[c] += 1
for i in range(1, n + 1):
    print(ans[i])

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll h,w; cin >> h >> w;
    ll odd = (w+1)/2;
    ll even = w/2;
    ll ans = 0;
    if(h%2==0){
        ans = (odd+even)*(h/2);        
    }else{
        ans = odd*((h+1)/2)+even*(h/2);
    }
    if(h==1 || w==1) ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::{BufRead, Write, stdin, stdout};
use std::collections::BTreeSet;

fn generate<M: FnMut(&mut Vec<u16>)>(n: usize, a: &mut Vec<u16>, cb: &mut M) {
    if n == 1 {
        cb(a);
    } else {
        for i in 0..n - 1 {
            generate(n - 1, a, cb);

            if n % 2 == 0 {
                a.swap(i, n - 1);
            } else {
                a.swap(0, n - 1);
            }
        }
        generate(n - 1, a, cb);
    }
}

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let n: u16 = split.next().unwrap().parse().unwrap();
    let m: u16 = split.next().unwrap().parse().unwrap();
    let ab: BTreeSet<(u16, u16)> = (0..m)
        .map(|_| {
            let mut s = String::new();
            input.read_line(&mut s).unwrap();
            let mut split = s.split_whitespace();
            let a: u16 = split.next().unwrap().parse().unwrap();
            let b: u16 = split.next().unwrap().parse().unwrap();
            (a - 1, b - 1)
        })
        .collect();
    let mut count = 0u16;
    let mut perm: Vec<u16> = (0..n).collect();
    generate(perm.len(),
             &mut perm,
             &mut |perm| if perm[0] == 0 &&
                            perm.windows(2)
                 .map(|arr| ab.contains(&(arr[0], arr[1])) || ab.contains(&(arr[1], arr[0])))
                 .all(|x| x) {
                 count += 1;
             });
    writeln!(output, "{}", count).unwrap();
}

fn main() {
    let stdin = stdin();
    solve(stdin.lock(), stdout());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("3 3
1 2
1 3
2 3\n",
             "2\n");
    }
    #[test]
    fn case2() {
        test("7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7\n",
             "1\n");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  V a(n), b(n);
  cin >> a >> b;

  priority_queue<P> pq;
  rep(i, n) if (a[i] < b[i]) pq.emplace(b[i], i);
  ll ans = 0;

  while (!pq.empty()) {
    auto [y, j] = pq.top(); pq.pop();
    int i = (j - 1 + n) % n;
    int k = (j + 1) % n;
    int &x = b[i];
    int &z = b[k];
    int mx = max(x, z);

    int m = (y-mx)/(x+z) + 1;
    chmin(m, (y-a[j])/(x+z));

    if (y == mx || m <= 0) {
      cout << -1 << '\n';
      return 0;
    }

    ans += m;
    b[j] -= (x+z)*m;
    if (a[j] < b[j]) pq.emplace(b[j], j);
  }

  bool ok = true;
  rep(i, n) if (a[i] != b[i]) ok = false;
  cout << (ok ? ans : -1) << '\n';
  return 0;
}


Measured memory_bytes: 6888
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long int> A(N), B(N);
    for(int n=0; n<N; n++) {
        cin >> A[n] >> B[n];
    }
    long long int cnt=0;
    for(int n=N-1; n>=0; n--) {
        cnt += (B[n]-(A[n]+cnt)%B[n])%B[n];
    }
    
    cout << cnt << endl;


    return 0;
    
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000010
using namespace std;
int num[N],fa[N];
int find(int x){return x==fa[x]?fa[x]:fa[x]=find(fa[x]);}
int nxt[N<<1],to[N<<1],head[N],cnt;
void add(int u,int v)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
int ton[N],tot;
void dfs(int u,int d)
{
	num[u]=d;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v==fa[u]) continue;
		fa[v]=u;
		dfs(v,-d);
		num[u]+=num[v];
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int ru=1,rv=1;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		int hx=find(u),hy=find(v);
		if(hx==hy)  ru=u,rv=v;
		else fa[fa[u]]=fa[v],add(u,v),add(v,u);
	}
	fa[ru]=0;
	if(m==n-1)
	{
		dfs(1,1);
		int ans=0;
		if(num[1]){puts("-1");return 0;}
		for(register int i=1;i<=n;i++) ans+=abs(num[i]);
		printf("%d\n",ans);
		return 0;
	}
	dfs(ru,1);
	int u=rv;
	while(u) ton[++tot]=num[u],u=fa[u];
	if(tot&1)
	{
		int ans=0;
		if(num[ru]&1){puts("-1");return 0;}
		for(int u=rv;u;u=fa[u])
		num[u]-=num[ru]>>1;
		for(int i=1;i<=n;i++) ans+=abs(num[i]);
		printf("%d\n",ans);
		return 0;
	}
	if(num[ru]){puts("-1");return 0;}
	sort(ton+1,ton+tot+1);
	for(register int u=rv;u;u=fa[u]) num[u]-=ton[tot>>1];
	int ans=0;
	for(register int i=1;i<=n;i++)
	ans+=abs(num[i]);
	printf("%d",ans);
	return 0;
}

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

int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> a(50),b(50);
  for (int i = 0; i < M; i++)
  {
    cin >> a.at(i) >> b.at(i);
  }

  vector<int> num(50);
  for (int i = 0; i < N; i++)
  {
    num.at(i) = 0;
  }

  for (int i = 0; i < M; i++)
  {
    num.at(a.at(i) - 1)++;
    num.at(b.at(i) - 1)++;
  }

  for (int i = 0; i < N; i++)
  {
    cout << num.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
string s;
int main()
{
	cin >> s;
	for(int i = 0 ; i < 4; i++){
		if(s[i] == '+'){
			s[i] = +1;
		}else {
			s[i] = -1;
		}
	}
	cout << s[0] + s [1] + s[2] + s[3] + s[4];
    return 0;
}


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

int calc(int v){
    if(dp[v]){return dp[v];}
    for(int to:g[v]){
        dp[v]=max(dp[v],calc(to)+1);
    }
    return dp[v];
}

int main(){
    int N,M,i,x,y,ans=0;
    scanf("%d%d",&N,&M);
    g.resize(N);
    dp.resize(N);
    
    for(i=0;i<M;i++){
        scanf("%d%d",&x,&y);
        x--;y--;
        g[y].push_back(x);
    }
    
    for(i=0;i<N;i++){
        ans=max(ans,calc(i));
    }
    printf("%d\n",ans);
    return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  bool judge = true;
  string s;cin>>s;
  vector<ll>hash(26);
  for(i=0;i<4;i++){
    hash[s[i]-'A']++;
  }
  for(i=0;i<26;i++){
    if(hash[i]!=0&&hash[i]!=2)judge=false;
  }
  ans1(judge);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
//#define debug

int main() {
  int N, M, i, hs, he, ws, we, temp;
  while (scanf("%d%d", &N, &M), (N != 0) || (M != 0) ) {
    int h[1501] = {0}, w[1501] = {0}, squares = 0;
    unsigned short hight[1500001] = {0}, width[1500001] = {0};
    for (i = 0; i < N; i++) scanf("%d", &h[i]);
    for (i = 0; i < M; i++) scanf("%d", &w[i]);
    for (hs = 0; hs < N; hs++) {
      for (he = hs, temp = 0; he < N; he++) {
	temp += h[he];
	hight[temp]++;
      }
    }
    for (ws = 0; ws < M; ws++) {
      for (we = ws, temp = 0; we < M; we++) {
#ifdef debug
	printf("%d\n", temp);
#endif
	temp += w[we];
	width[temp]++;
      }
    }
    for (i = 1; i < 1500001; i++) {
      squares += hight[i] * width[i];
    }
#ifdef debug
    for (i = 0; i < 21; i++)
      printf("hight[%d]:%d\n", i, hight[i]);
    for (i = 0; i < 21; i++)
      printf("width[%d]:%d\n", i, width[i]);
#endif
printf("%d\n", squares);
    }
  return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, 1, n+1) cin >> a[i];
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, 1, n+1){
        ans += mp[i-a[i]];
        mp[i+a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27344
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll k[101010];
ll b[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
string s[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
ll sr,sc;
int main() {
   cin>>N>>K;
   rep(i,0,N){
       cin>>v[i];
   }
   rep(i,0,K+1){
       rep(j,0,K+1-i){
           vector<ll> num;
           ll right = min(i,N);
           rep(k,0,min(i,N)){
               num.push_back(v[k]);
           }
           urep(k,N-1,max(right+1,N-j)){
               num.push_back(v[k]);
           }
           sort(num.begin(),num.end());
           ll num1=0;
           rep(k,0,min(K-i-j,(ll)num.size())){
               num[k]=max((ll)0,num[k]);
           }
           rep(k,0,num.size()){
               num1+=num[k];
           }
           ans=max(num1,ans);
       }
   }
   cout<<ans<<endl;
	return 0;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];


    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int union_tree[2000];
int union_find(int now) {
	if (union_tree[now] == now) return now;
	return union_tree[now] = union_find(union_tree[now]);
}
int union_merge(int a, int b) {
	a = union_find(a);
	b = union_find(b);
	if (a == b) return 0;
	union_tree[a] = b;
	return 1;
}

void solve(){
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return;
		vector<tuple<int, int, int>> inputs;
		REP(i, m) {
			int a, b, c;
			cin >> a >> b >> c;
			inputs.push_back(make_tuple(c, a, b));
		}
		sort(ALL(inputs));
		int target = n / 2;
		REP(i, n) {
			union_tree[i+1] = i + 1;
		}
		REP(i, inputs.size()) {
			target -= union_merge(get<1>(inputs[i]), get<2>(inputs[i]));
			if (target <= 0) {
				cout << get<0>(inputs[i]) << endl;
				break;
			}
		}
	}
}

#undef int
int main() {
	init();

	solve();
}


Measured memory_bytes: 3452
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(1, n):
    if a[i] == a[i - 1] + 1:
        ans += c[a[i - 1] - 1]
print(ans)


Measured memory_bytes: 38256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			Long n;
			Long result;
			Long r;
			int index;
			int index0;
			Long a;
			Long a0;
			result=0L;
			a0=0L;
			index0=0;
			
			n=sc.nextLong();
			
			Map <Integer,Integer> map= new HashMap<Integer,Integer> ();
			for(index=0;index<5;index++) {
				a = sc.nextLong();
				if(index==0) {
					a0=a;
					index0=0;
					}
				else if(a<a0) {
					a0=a;
					index0=index;
					}
				}
			sc.close();
			
			// 
			r = n%a0;
			result = (n-r) / a0;
			if(n<=a0) {
				result=(long)5;
			}
			else if(r>0) {
				result=result+5;
			}
			else {
				result=result+4;
			}
			
			// 出力
			System.out.println(result);
	}
}

Measured memory_bytes: 23764
import sys
n=int(input())
A =list(map(int,input().split()))
mi = 0
for i in range(n):
    if mi < A[i]:
        mi = A[i]-1
    elif mi == A[i]:
        mi = A[i]
    elif A[i]-mi < 0 :
        print('No')
        sys.exit()
print('Yes')




Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define res register int
#define ll long long
using namespace  std;
int a,b;
int len;
bool flag=false;
bool neg,pos;
int main()
{
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0)
	flag=true;
	if(a<0&&b<0)
	{
		len=(b-a+1);
		if(len%2==0)
		pos=true;
		else neg=true;
	}
	if(a>0&&b>0)
	pos=true;
	if(flag==true)
	{
		printf("Zero");
		return 0;
	}
	if(pos==true)
	{
		printf("Positive");
		return 0;
	}
	if(neg==true)
	{
		printf("Negative");
		return 0;
	}
}


Measured memory_bytes: 256
import numpy as np
import sys

input = sys.stdin.readline

N,A,B = map(int,input().split())

S = input()

nai = 0
gai = 0


goukaku = 0
for i in range(len(S)):
    if S[i] == 'a':
        nai+=1
        if goukaku < A+B:
            goukaku+=1
            print("Yes")
        else:
            print("No")

    elif S[i] == 'b':
        gai+=1
        if goukaku < A+B and gai <= B:
            goukaku+=1
            print("Yes")
        else:
            print("No")

    elif S[i] == 'c':
        print("No")

Measured memory_bytes: 13336
#include <iostream>

int main() {
    int R;
    std::cin >> R;

    if (R < 1200) {
        std::cout << "ABC" << std::endl;
    } else if (R < 2800) {
        std::cout << "ARC" << std::endl;
    } else {
        std::cout << "AGC" << std::endl;
    }
}


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


int main()
{
  string s1,s2,s;
  cin >> s1 >> s2;
  s = s1 + s2;
  auto num = atoi(s.c_str());
  bool flag = false;
  for(int i = 0;i < num ;i++){
    if(i*i > num) break;
    if(i*i == num){
      flag = true;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
  
}


Measured memory_bytes: 256
// Author            -  Ranadev Varma
// Codeforces Handle -  Ranadev_CaptainR
// Codechef Handle   -  ranadev
 
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("O2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("unroll-loops")
 
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <iterator>
#include <iomanip>
#include <set>

using namespace std ;

#define MOD 1000000007LL
#define LOD 1000000006
#define pi 3.14159

#define lol1 ios::sync_with_stdio(false)
#define lol2 cin.tie(NULL);cout.tie(NULL)

#define FOR(i,a,b)  for(int i = a ; i < b ; i++)
#define RFOR(i,a,b) for(int i = a ; i > b ; i--)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    lol1;
    lol2;
    int n;
    cin >> n;
    FOR(i,0,108)
    {
        FOR(j,0,108)
        {
            if(4*i + 7*j == n)
            {
                cout << "Yes" << "\n";
                return 0;
            }
        }
    }
    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int Dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int Dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s, ss;
	cin >> s;
	ss = s;
	int ans = 0, n = s.size(), ans1 = 0;
	for(int i = 1; i < n; i++){
		if(s[i] == s[i - 1]){
			if(s[i - 1] == '0'){
				s[i] = '1';
			}else{
				s[i] = '0';
			}
			ans++;
		}
	}
	s = ss;
	for(int i = n - 2; i >= 0; i--){
		if(s[i] == s[i + 1]){
			if(s[i + 1] == '0'){
				s[i] = '1';
			}else{
				s[i] = '0';
			}
			ans1++;
		}
	}
	cout << min(ans, ans1);
}

Measured memory_bytes: 512
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>>c(h, vector<char>(w));
	rep(i, 0, h)rep(j, 0, w)cin >> c[i][j];

	int ans = 0;
	rep(i, 0, 1 << h) {
		rep(j, 0, 1 << w) {
			vector<bool>hline(h, 1);
			vector<bool>wline(w, 1);
			int x, y;
			x = i; y = j;
			rep(ni, 1, h + 1) {
				if (x % (1 << ni))hline[ni - 1] = false;
				x = x - x % (1 << ni);
			}
			rep(nj, 1, w + 1) {
				if (y % (1<< nj))wline[nj - 1] = false;
				y = y - y % (1 << nj);
			}
			int nans = 0;
			rep(ni, 0, h){
				rep(nj, 0, w) {
					if (hline[ni] && wline[nj])
						if (c[ni][nj] == '#')
							nans++;
				}
			}
			if (nans == k)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int s, g;
	s = max(a, c);
	g = min(b, d);

	cout << max(0, g - s) << endl;

	return 0;
}

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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int a,b,c,cnt=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++){
		if(i%c==0)cnt++;
	}
	cout<<cnt;
}


Measured memory_bytes: 3580
def f(n):
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    return cnt


def main():
    N = int(input())
    a = list(map(int, input().split(' ')))
    exp_2 = list(map(f, a))
    print(sum(exp_2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    /*char ch;
    cin >> ch;
    if(ch>='A'&&ch<='Z')
        cout << 'A' << endl;
    else
        cout << 'a' << endl;
    int a[10000];
    int n,k;
    cin >> n>> k;
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout << ans << endl;*/
    ll c;
    cin >> c;
    vector<ll>v;

            while(c>0)
            {
                if(c%26==0)
                v.push_back(26);
                else
                v.push_back(c%26);
                //cout << c << endl;
                if(c%26==0)
                    c= c/26-1;
                else
                    c= c/26;

            }

            for(ll i=v.size()-1;i>=0;i--)
            {
                //cout << v[i] << endl;
                printf("%c",v[i]+96);
            }

}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int passed = 0;
	int overseas = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'a') {
			if(passed < a + b) {
				cout << "Yes\n";
				passed += 1;
			}
			else {
				cout << "No\n";
			}
		}
		else if(s[i] == 'b') {
			overseas += 1;
			if(passed < a + b) {
				if(overseas <= b) {
					passed += 1;
					cout << "Yes\n";
				}
				else {
					cout << "No\n";
				}
			}
			else {
				cout << "No\n";
			}
		}
		else if(s[i] == 'c') {
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll res=LLONG_MIN;
    res = max(res,b*c);
    res  = max(res,b*d);
    res = max(a*c,res);
    res  = max(a*d,res);
    cout<<res;
}


Measured memory_bytes: 3652
#include <stdio.h>
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a < b)) {
		if (b < c)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 580
a,b,c,x=int(input()),int(input()),int(input()),int(input())

k=0
for i in range(min([x//500+1,a+1])):
    for j in range(min([(x-500*i)//100+1,b+1])):
        if 500*i+100*j+50*c>=x:
            k+=1

print(k)


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

int main() {
	int n;
	scanf("%d", &n);
	for (int i = n; i >= 1; i --) {
		if (i == 1) {
			printf("%d\n", i);
			return 0;
		}
		for (int j = 2; j * j <= i; j ++) {
			int k = i;
			if (k % j == 0) {
				while (k % j == 0) {
					k /= j;
				}
				if (k == 1) {
					printf("%d\n", i);
					return 0;
				}
			}
		}
	}
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[n-1] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    string N;
    cin >> N;
    for(int i = 0; i < 8; i++) {
        string ans;
        ans += N.at(0);
        int sum = N.at(0) - '0';
        for(int j = 0; j < 3; j++) {
            //cout << (i >> (j + 1)) << endl;
            if(i >> j & 1) {
                sum += N.at(j + 1) - '0';
                ans += '+';
                ans += N.at(j + 1);
            } else {
                sum -= N.at(j + 1) - '0';
                ans += '-';
                ans += N.at(j + 1);
            }
        }
        //˜cout << sum << endl;
        if(sum == 7) {
            cout << ans << "=7" << endl;
            break;
        }

    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int h,a;
cin>>h>>a;
int cnt=0;
while(h>0){
    h-=a;
    cnt++;
}
cout<<cnt<<endl;
//system("pause");
return 0;
}

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

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i,n) for(int i = 0; i<n; ++i)
#define ff(i,n) for(int i = 1; i<n; ++i)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;

const int M = 5 * 1e5 + 100;
const int N = 5 * 1e3 + 100;

pair<pii,int> a[M];
int board[N][N];
int n,k;

int work()
{
    int now = 0;
    int high = 0;
    int ans = 0;
    for(int i=1; i<=n; ++i) for(int j=1; j<=i; ++j)
    {
        while(now < k && a[now].st.st == i && a[now].st.nd == j) { high = max(high ,a[now].nd + 1); now++; }
        //cout << i space j space high << endl;
        board[i - high + 1][j] += 1;
        board[i + 1][j] += -1;
        high = max(high-1,0);
    }
    //cout << 1 << endl;
    for(int i=1; i<=n; ++i) for(int j=1; j<=i; ++j)
    {
        board[i][j] += board[i-1][j];
    }
    for(int i=1; i<=n; ++i) for(int j=1; j<=i; ++j) if(board[i][j]) ans++;
    //for(int i=1; i<=n; ++i) { for(int j=1; j<=i; ++j) cout << board[i][j] << " "; cout << endl; }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    fo(i,k) { cin >> a[i].st.st >> a[i].st.nd >> a[i].nd; a[i].st.st += a[i].nd; }
    //for(int i=0; i<k; ++i) cout << a[i].st.st space a[i].st.nd space a[i].nd << endl;
    //cout << 1 << endl;
    sort(a,a+k);
    cout << work() << endl;
}

Measured memory_bytes: 107052
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define REP(i, n) FOR(i, 0, n - 1)

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

	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int &hi : h)
		cin >> hi;

	vector<int> dp(n, int(1e9));
	dp[0] = 0;
	FOR(i, 1, n - 1) {
		for(int j = i - 1; j >= max(0, i - k); --j)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	cout << dp.back() << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S; cin >> S;
  if (stoi(S.substr(0,2)) <= 12 && stoi(S.substr(0,2)) > 0) {
    if (stoi(S.substr(2,2)) <= 12 && stoi(S.substr(2,2)) > 0)
      cout << "AMBIGUOUS" << endl;
    else
      cout << "MMYY" << endl;
  } else {
    if (stoi(S.substr(2,2)) <= 12 && stoi(S.substr(2,2)) > 0)
      cout << "YYMM" << endl;
    else
      cout << "NA" << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  int n;
  while (n = in()){
    string cipher = instr();
    vector<duo> vd;
    for (int i = 0; i < n; i++){
      int a, b;
      a = in() - 1;
      b = in() - 1;
      vd.push_back(duo(a, b));
    }
    revs(vd);

    for (int i = 0; i < n; i++){
      int a, b;
      a = vd[i].first;
      b = vd[i].second;
      int d = abs(a - b);
      swap(cipher[a], cipher[b]);
      cipher[a] = (cipher[a] - 'a' + d) % 26 + 'a';
      cipher[b] = (cipher[b] - 'a' + d) % 26 + 'a';
    }
    puts(cipher.c_str());
  }
  return (0);
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
// const ll INF = 1LL << 30;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

int main() {
    ll n; cin >> n;
    Vl a(n);
    set<ll> now;
    map<ll, ll> cnt;
    rep(i, 0, n){
        cin >> a[i];
        now.insert(a[i]);
        cnt[a[i]]++;
    }
    ll q; cin >> q;

    ll ans = 0;
    for(auto it : now){
            ans += cnt[it]*it;
    }

    Vl rec;

    rep(i, 0, q){
        ll b, c; cin >> b >> c;
        ans += (c-b)*cnt[b]; 

        if(cnt[c] != 0) cnt[c] += cnt[b];
        else cnt[c] = cnt[b];
        cnt[b] = 0;
        
        rec.push_back(ans);
    }   

    rep(i, 0, sz(rec)) co(rec[i]);

    return 0;
}


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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;

int main() {

    int ans = 0;
    int A,B,C,X; cin>>A>>B>>C>>X;
    rep(i,A+1){
        rep(j,B+1){
            rep(k,C+1){
                if(500*i+100*j+50*k == X){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

int main(){
  int n,k;
  string s;
  cin>> n >> k >> s;
  
  char start=s.at(0);
  for (int i=1; i<n; i++){
    if (start!=s.at(i)){
      for (int j=i; j<n; j++){
        if (start!=s.at(j)){
          s.at(j)=start;
        }
        else{
          i=j;
          break;
        }
      }
      k--;
      if (k==0) break;
    }
  }
  
  int ans=0;
  for (int i=1; i<n; i++){
    if (s.at(i-1)==s.at(i)) ans++;
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll a[99];
int main(){
	rep(i,0,3){
		ll n;
		scanf("%lld",&n);
		a[n]++;
	}
	puts(a[5]==2&&a[7]==1?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
vector<int> v[MAXN];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int any=0;
	for(int i=1;i<=n;i++)
	{
		int l,r;
		cin>>l>>r;
		if(l+1>r-1)
		{
			any++;
		}
		else
		{
			v[l+1].pb(r-1);
		}
	}
	multiset<int> s_right;
	int how_many_right_want[m+1];
	memset(how_many_right_want,0,sizeof(how_many_right_want));
	int empty_left=0,empty_right=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			s_right.insert(v[i][j]);
		}
		int k=v[i].size();
		if(empty_left>=k)
		{
			empty_left-=k;
		}
		else
		{
			int req=k-empty_left;
			while(req--)
			{
				int x=(*s_right.begin());
				how_many_right_want[x]++;
				s_right.erase(s_right.begin());
			}
			empty_left=0;
		}
		empty_left++;
	}
	int p=empty_left;
	int ans=0;
	for(int i=m;i>=1;i--)
	{
		int k=how_many_right_want[i];
		if(empty_right>=k)
		{
			empty_right-=k;
		}
		else
		{
			ans=ans+(k-empty_right);
			empty_right=0;
		}
		if(i>m-empty_left)
		{
			empty_right++;
		}
	}
	if(any>empty_right)
	{
		ans=ans+(any-empty_right);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

signed main() {
    int n;
    cin >> n;
    double ans;
    if(n%2==0) ans=0.5;
    else ans=(double)(n+1)/2/n;
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 256