akhauriyash/Code-Regression huggingface dataset:
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Mod-Int
constexpr int MOD = 1000000007;
struct ModInt {
    ll val;
    ModInt() = default;
    ModInt(ll x) : val(x % MOD + (x < 0 ? MOD : 0)) {}
    ModInt &operator+= (const ModInt &x) {if ((val += x.val) >= MOD) val -= MOD; return *this;}
    ModInt &operator-= (const ModInt &x) {if ((val -= x.val) < 0) val += MOD; return *this;}
    ModInt &operator*= (const ModInt &x) {(val *= x.val) %= MOD; return *this;}
    ModInt operator+ (const ModInt &x) const {return ModInt(*this) += x;}
    ModInt operator- (const ModInt &x) const {return ModInt(*this) -= x;}
    ModInt operator* (const ModInt &x) const {return ModInt(*this) *= x;}
    ModInt pow(ll t) const {
        if (!t) return ModInt(1);
        ModInt m = pow(t / 2);
        m *= m;
        if (t & 1) m *= *this;
        return m;
    }
    ModInt inv() const {return pow(MOD - 2);}
    ModInt &operator/= (const ModInt &x) {return *this *= x.inv();}
    ModInt operator/ (const ModInt &x) const {return ModInt(*this) /= x;}
    friend istream &operator>> (istream &is, ModInt &x) {is >> x.val; return is;}
    friend ostream &operator<< (ostream &os, const ModInt &x) {os << x.val; return os;}
};

// Main
int main() {
    string K;
    int D;
    cin >> K >> D;
    
    vector<vector<vector<ModInt>>> dp(K.size() + 1, vector<vector<ModInt>>(D, vector<ModInt>(2, ModInt(0))));
    dp[0][0][0] = ModInt(1);
    rep(i, K.size()) rep(j, D) rep(s, 2) for (int d = 0; d <= (s ? 9 : K[i] - '0'); ++d) {
        dp[i + 1][(j + d) % D][s || d < K[i] - '0'] += dp[i][j][s];
    }
    
    cout << dp[K.size()][0][0] + dp[K.size()][0][1] - ModInt(1) << "\n";
}


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

int main()
{
    using tsii = tuple<string, int, int>;
    using vtsii = vector<tsii>;
    int N, b;
    string a;
    cin >> N;
    vtsii v;
    rep(i, N)
    {
        cin >> a >> b;
        v.push_back(make_tuple(a, b, i + 1));
        get<1>(v.at(i)) *= -1;
    }
    sort(v.begin(), v.end());

    rep(i, N)
    {
        cout << get<2>(v.at(i)) << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,k;
    cin>>m>>k;
    if(k>=pow(2,m))
        cout<<-1;
    else
    {
        int i;
        if(m==1 && k==1)
            cout<<-1;
        else if(m==0)
            cout<<0<<' '<<0;
        else if(k==0)
            for(i=0;i!=pow(2,m);i++)
                cout<<i<<' '<<i<<' ';
        else
        {
        	cout<<k<<' ';
            for(i=pow(2,m)-1;i>=0;i--)
                if(i!=k)
                    cout<<i<<' ';
            cout<<k<<' ';
            for(i=0;i!=pow(2,m);i++)
                if(i!=k)
                    cout<<i<<' ';
        }
    }
    return 0;
}


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

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  
  for(int i = 0;i <= a;i++){
    for(int j = 0;j <= b;j++){
      for(int k = 0;k <= c;k++){
	int t = i*500 + j*100 + k*50;
	if(t == x){
	  ans++;
	}
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  if(x==w/2 && y==h/2){
    printf("%.12f %d\n",w*h/2,1);
  }
  else{
    printf("%.12f %d\n",w*h/2,0);
  }
}

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

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

//write code hare

	int k;
	cin >> k;

	string s;
	cin >> s;


	if (s.length() <= k) {
		cout << s;
	} else {
		s[k] = '.';
		s[k + 1] = '.';
		s[k + 2] = '.';

		s[k + 3] = '\0';

		for (int i = 0; s[i] != '\0'; i++) {
			cout << s[i];
		}
	}

}

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

int main(){
  string S;
  cin >> S;
  int A=S.at(0)-'0';
  int B=S.at(1)-'0';
  int C=S.at(2)-'0';
  int D=S.at(3)-'0';
  if(A-B-C-D==7){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else if(A-B-C+D==7){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(A-B+C-D==7){
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else if(A-B+C+D==7){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  }
  else if(A+B-C-D==7){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else if(A+B-C+D==7){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(A+B+C-D==7){
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else{
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  }
}
  


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  map<pii,int>mp; ll ans=0;
  for(int i=0; i<n; i++){
    double x; cin >>x;
    ll y=llround(x*1e9); int two=0,five=0;
    while(y%2==0){y/=2; two++;}
    while(y%5==0){y/=5; five++;}
    mp[{two,five}]++;
  }
  for(auto x:mp) for(auto y:mp){
    ll x2=x.first.first,x5=x.first.second;
    ll y2=y.first.first,y5=y.first.second;
    ll xs=x.second,ys=y.second;
    if(x2+y2>=18&&x5+y5>=18){
      if(x<y) ans+=xs*ys;
      else if(x==y) ans+=xs*(xs-1)/2;
    }
  }
  cout <<ans;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3724
#include <cstdio>
#pragma warning(disable : 4996)
int n, m, a, b, c, imos[5009][5009], imos2[5009][5009], imos3[5009][5009];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &a, &b, &c); a--, b--;
		// cover (a, b), (a+1, b),..., (a+c, b)
		imos2[a][b]++;
		imos2[a + c + 1][b]--;
		// cover (a, b+1), (a+1, b+2),..., (a+c, b+c+1)
		imos3[a][b + 1]++;
		imos3[a + c + 1][b + c + 2]--;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			imos2[i + 1][j] += imos2[i][j];
		}
	}
	for (int i = -1; i < n; i++) {
		for (int j = 1; i + j <= n; j++) {
			if (i + j <= 0) continue;
			imos3[i + j][j] += imos3[i + j - 1][j - 1];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			imos[i][j] += imos2[i][j];
			imos[i][j] -= imos3[i][j];
		}
	}
	int ret = 0;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j <= i; j++) {
			sum += imos[i][j];
			if (sum > 0) ret++;
		}
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 265256
import java.util.*;
import java.math.BigDecimal;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double ary[] = new double[n];
    double ans = 0;
    
    for (int i = 0; i < n; i++) { 
      ary[i] = sc.nextDouble(); 
      ans += 1 / ary[i];
    }
    
    ans = 1 / ans;
    
    System.out.println(ans);
  }
}



Measured memory_bytes: 23124
#include<stdio.h>
#define N 1000000
int main(void){
	int i,j,n;
	int R[N];
	int minv;
	int maxv=-1000000000;
	int price;
	scanf("%d",&n);
	
	for(i=0; i<n;i++){
		scanf("%d",&R[i]);
	}
	
	 minv=R[0];
	for(j=1;j<n;j++){
		if(R[j]-minv>maxv){maxv=R[j]-minv;}
		if(R[j]<minv){minv=R[j];}
	}
	price=maxv;
	
	
	printf("%d\n",price);
	
	return 0;
}
	
	


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	int cnt=0,ans=0;
	for(auto&&i:s){
		if(i=='g')++cnt;
		else --cnt;
		if(cnt<0)--ans;
	}
	cout<<ans+cnt/2<<"\n"s;
}


Measured memory_bytes: 3796
from heapq import heappush,heappop
ab=[]
n,m=map(int,input().split())
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort()
k=0
ans=0
hq=[]
cnt=0
for i in range(1,m+1):
	if k>n-1:
		break
	while ab[k][0]<=i:
		heappush(hq,-ab[k][1])
		k+=1
		if k>n-1:
			break
	if len(hq)!=0:
		ans+=heappop(hq)
	cnt+=1
if cnt<m:
	for i in range(m-cnt):
		ans+=heappop(hq)
print(-ans)


Measured memory_bytes: 23876
n=int(input())
h=list(map(int,input().split()))
cost=[0]*n
cost[0]=0
cost[1]=abs(h[0]-h[1])
for i in range(2,n):
    cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]))
print(cost[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

struct S {
    LL t,d;
};

void solve() {
    int n,k;
    cin >> n >> k;
    vector<S> s(n);
    REP(i,0,n) cin >> s[i].t >> s[i].d;
    LL sum = 0;
    unordered_map<int, int> m;
    sort(all(s), [](auto &l, auto &r) {return l.d > r.d;});
    REP(i,0,k) {
        sum += s[i].d;
        m[s[i].t]++;
    }
    LL ans = sum + 1LL * m.size() * m.size();
    int index = k - 1;
    REP(i,k,n) {
        if (index < 0) break;
        while (index >= 0 && m[s[index].t] == 1) {
            --index;
        }
        if (index < 0) break;
        if (m.count(s[i].t) > 0) continue;
        sum += s[i].d - s[index].d;
        m[s[i].t]++;
        m[s[index].t]--;
        LL tmp = sum + 1LL * m.size() * m.size();
        ans = max(ans, tmp);
        --index;
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

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

typedef long long int LLI;

LLI N;
LLI ans;
string S;
char buf[414514];
int R[414514];
map<char, LLI> dic; 

int main() {
  scanf("%s", buf);
  N = strlen(buf);
  for (int i=0; i<N; i++) {
    S += buf[i];
    dic[buf[i]]++;
    if (i < N-1) S += '*';
  }

  int i = 0, j = 0;
  while (i < S.size()) {
    while (i-j >= 0 && i+j < S.size() && S[i-j] == S[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while (i-k >= 0 && i+k < S.size() && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
    i += k; j -= k;
  }

  ans = N*(N-1)/2+1;
  /*for (int i=0; i<S.size(); i++) {
    if (i%2 == R[i]%2) R[i]--;
    printf("%d: %d\n", i, R[i]);
    ans -= R[i]/2;
  }*/

  for (char c='a'; c<='z'; c++) {
    ans -= dic[c]*(dic[c]-1)/2;
  }
  //if (ans == 0) ans = 1;
  printf("%lld\n", ans);
}


Measured memory_bytes: 2564
from math import log2, ceil


class SegmentTree:
    def __init__(self, n):
        tn = 2 ** ceil(log2(n))
        self.a = [2 ** 31 - 1] * (tn * 2)

    def find(self, c, l, r, i):
        if self.a[c] != -1:
            return self.a[c]
        mid = (l + r) // 2
        if i <= mid:
            return self.find(c * 2, l, mid, i)
        else:
            return self.find(c * 2 + 1, mid + 1, r, i)

    def update(self, c, l, r, s, t, x):
        if l == s and r == t:
            self.a[c] = x
            return
        cv = self.a[c]
        if cv != -1:
            self.a[c * 2] = self.a[c * 2 + 1] = cv
            self.a[c] = -1
        mid = (l + r) // 2
        if t <= mid:
            self.update(c * 2, l, mid, s, t, x)
        elif s > mid:
            self.update(c * 2 + 1, mid + 1, r, s, t, x)
        else:
            self.update(c * 2, l, mid, s, mid, x)
            self.update(c * 2 + 1, mid + 1, r, mid + 1, t, x)


n, q = map(int, input().split())
st = SegmentTree(n)
for _ in range(q):
    query = input().split()
    if query[0] == '0':
        s, t, x = map(int, query[1:])
        st.update(1, 0, n - 1, s, t, x)
    else:
        print(st.find(1, 0, n - 1, int(query[1])))

Measured memory_bytes: 11020
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
ll a[100010];
int c[100010];
int b[100010];
int d[100010];
ll ans[100010];
int main()
{
#ifdef DEBUG
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
#endif
    int n;
    scanf("%d",&n);
    int i;
    ll sum=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        a[i]-=sum;
        sum+=a[i];
        c[i]=i;
    }
    int m;
    ll k;
    scanf("%d%lld",&m,&k);
    int x;
    for(i=1;i<=m;i++)
    {
        scanf("%d",&x);
        swap(c[x],c[x+1]);
    }
    for(i=1;i<=n;i++)
        if(!b[i])
        {
            int cnt=0;
            int j;
            for(j=i;!b[j];j=c[j])
            {
                b[j]=1;
                d[++cnt]=j;
            }
            for(j=1;j<=cnt;j++)
                ans[d[j]]=a[d[(j+k-1)%cnt+1]];
        }
    for(i=1;i<=n;i++)
    {
        ans[i]+=ans[i-1];
        printf("%lld.0\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 4096
# 写経
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a > 0 else 0)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b > 0 else 0)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c > 0 else 0)
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> point(n, k);
    vector<int> correct(n, 0);
    int person;
    REP(i,q){
        cin>>person;
        correct[person-1]++;
    }
    REP(i,n){
        if(point[i]+correct[i]-q<=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        };
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const int N=2e5+20;
//题意:N个数,操作:每次把某个数减去A,其余的数减去B.问让n个数<=0的最少操作次数
//n<=1e5,a[i],A,B<=1e9 每次取最大数减去A,其余的数减去B,直接模拟TLE
//因为ans有明显的单调性,关键如何判定 
//若k轮能扫完 等价于最多用k次A.
//A*x+(k-x)*B>=a[i],每个a[i]用k最小次数为 :(a[i]-B*k)/(A-B) 
ll n,a[N],A,B,s;
bool check(ll k)
{
//	if(k*A+(n-1)*B<s)
//		return false;
	ll cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=B*k)
			continue;
		ll num=(a[i]-B*k)/(A-B); 
		if((a[i]-B*k)%(A-B))
			num++;
		
		cnt+=num;
	}
	return cnt<=k;
}
int main()
{
	while(cin>>n>>A>>B)
	{
		s=0;
		for(int i=1;i<=n;i++)
			scanf("%I64d",&a[i]),s+=a[i];
		ll l=1,r=1e9,ans;
		while(l<=r)
		{
			ll mid=(l+r)>>1;
			if(check(mid))
			{
				ans=mid;
				r=mid-1;
			}	
			else
				l=mid+1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
  int a,b;
  char op;
  do
  {
  scanf("%d %c %d",&a,&op,&b);
  if(op=='+')
    printf("%d\n",a+b);
  else if(op=='-')
    printf("%d\n",a-b);
  else if(op=='*')
    printf("%d\n",a*b);
  else if(op=='/')
    printf("%d\n",a/b);

  }while(op!='?');
}

Measured memory_bytes: 1808
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

#ifndef CODE_
#include "f:/kyopro/code.c"
#define CODE_
#endif

i32 const prime_judge(i64 const n){
    if(n==1LL) return 0;
    i64 r=0LL;
    while(r*r<=n) ++r;
    --r;
    for(i64 i=2LL;i<=r;++i){
        if(n%i==0LL) return 0;
    }
    return 1;
}

i64 const prime_sieve(i32 **const a,i64 const n){
    (*a)=(i32 *)calloc(n,sizeof(i32));
    i64 r=0LL,cnt=0LL;
    while(r*r<=n) ++r;
    --r;
    (*a)[0LL]=1;
    for(i64 i=2LL;i<=r;++i){
        if((*a)[i-1LL]) continue;
        for(i64 j=i*i-1LL;j<n;j+=i) (*a)[j]=1;
    }
    for(i64 i=0LL;i<n;++i){
        if((*a)[i]) (*a)[i]=0;
        else{
            (*a)[i]=1;
            ++cnt;
        }
    }
    return cnt;
}

i64 const prime_factorize(i64 **const a,i64 **const b,i64 const n){
    if(n==1LL){
        (*a)=(i64 *)calloc(1LL,sizeof(i64));
        (*b)=(i64 *)calloc(1LL,sizeof(i64));
        (*a)[0LL]=1LL;
        (*b)[0LL]=0LL;
        return 0LL;
    }
    i64 m=n/2LL;
    i32 *d;
    prime_sieve(&d,m);
    i64 w=n;
    i64 cnt=0LL;
    i64 *x=(i64 *)calloc(m,sizeof(i64));
    for(i64 i=2LL;i<=m;++i){
        if(!d[i-1LL]) continue;
        i32 flag=1;
        while(w%i==0LL){
            w/=i;
            ++x[i-1LL];
            if(flag){
                ++cnt;
                flag=0;
            }
        }
    }
    free(d);
    if(cnt==0LL){
        free(x);
        (*a)=(i64 *)calloc(1LL,sizeof(i64));
        (*b)=(i64 *)calloc(1LL,sizeof(i64));
        (*a)[0LL]=n;
        (*b)[0LL]=1LL;
        return 1LL;
    }
    (*a)=(i64 *)calloc(cnt,sizeof(i64));
    (*b)=(i64 *)calloc(cnt,sizeof(i64));
    i64 p=0LL;
    for(i64 i=0LL;i<m;++i){
        if(x[i]==0LL) continue;
        (*a)[p]=i+1LL;
        (*b)[p]=x[i];
        ++p;
    }
    free(x);
    return cnt;
}

void prime_table(i64 **const a,i64 const n){
    (*a)=(i64 *)calloc(n,sizeof(i64));
    if(n==1LL){
        (*a)[0LL]=2LL;
        return;
    }
    if(n==2LL){
        (*a)[1LL]=3LL;
        return;
    }
    if(n==3LL){
        (*a)[2LL]=5LL;
        return;
    }
    i64 cnt=3LL;
    i64 x=7LL;
    i64 p=0LL;
    while(1){
        if(prime_judge(x)){
            (*a)[cnt++]=x;
            if(cnt==n) return;
        }
        if(p==3LL){
            x+=4LL;
            p=0LL;
        }
        else{
            x+=2LL;
            ++p;
        }
    }
    return;
}

i32 main(void){
    i64 n;
    i32 *d;
    prime_sieve(&d,1299709LL);
    while(scanf("%lli",&n)){
        if(n==0LL) return 0;
        if(d[n-1LL]){
            printf("0\n");
            continue;
        }
        i64 p=n-1LL,q=n-1LL;
        while(!d[++p]);
        while(!d[--q]);
        printf("%lli\n",p-q);
    }
    return 0;
}



Measured memory_bytes: 6936
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    vector<int> a(10);
    rep(i, 10)
    {
        cin >> a[i];
    }
    SORT(a);
    for (int i = 9; i > 6; i--)
    {
        cout << a[i] << endl;
    }
    return 0;
}



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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


int main(){
    int d;
    cin>>d;
    if(d>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}



Measured memory_bytes: 3628
import copy
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
#check
#何行目かを決める
for i in range(n + 1 - m):
    #何文字目かを決める
    for j in range(n + 1 - m):
        k = 0
        while 1:
            if a[i + k][j:j+m] != b[k]:
                break
            else:
                if k == m - 1:
                    print("Yes")
                    exit()
                k += 1
print("No")

Measured memory_bytes: 3700
#include <stdio.h>
int main(void){
    int n,m,x,i,broken[100010]={0},dp[100010]={0};
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&x);
        broken[x]=1;
    }
    dp[n]=1;
    dp[n+1]=0;
    for(i=n-1;i>=0;i--){
        if(broken[i]==1) continue;
        dp[i] = (dp[i+1]+dp[i+2])%1000000007;
    }
    printf("%d",dp[0]);
}

Measured memory_bytes: 2512
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n,q,a,b,c;
	scanf("%d",&n);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	for(scanf("%d",&q);q--;){
		scanf("%d%d%d",&a,&b,&c);
		for(int k=0;k<b-a;k++)swap(v[a+k],v[c+k]);
	}
	for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i]);
}



Measured memory_bytes: 2772
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<iomanip>

using namespace std;



typedef struct __city{
  int P;
  int Y;
  int junban;
  int num;

  bool operator<( const __city& right ) const {
      return P == right.P ? Y< right.Y : P < right.P;
  }
}city;

int cmp( const void *p, const void *q ) {
    return ((city*)p)->junban - ((city*)q)->junban;
}

bool asc( const city& left, const city& right ) {
    return left.junban < right.junban;
}

int main(){
  int N,M;
  cin>>N>>M;
  vector<city> c(M);

  for (int i=0;i<M;i++){
    cin>>c.at(i).P>>c.at(i).Y;
    c.at(i).junban=i;
  }
  sort(c.begin(),c.end());

  int prePre=c.at(0).P,preNum=0;
  for (int i=0;i<M;i++){
      if (c.at(i).P!=prePre){
        prePre=c.at(i).P;
        c.at(i).num=1;
        preNum=1;
      }
      else {
        c.at(i).num=(++preNum);
      }
    }

  sort(c.begin(),c.end(),asc);

  for (city x:c){
    cout<<setfill('0') <<setw(6)<<right<<x.P;
    cout<<setfill('0') <<setw(6)<<right<<x.num<<endl;
  }
  return 0;
}


Measured memory_bytes: 3072
fun main(args: Array<String>) {
    var S = readInputLine().reversed()
    
    val regex = Regex("""^(maerd|remaerd|esare|resare)+$""")
    
    if (regex.matches(S)) {
        println("YES")
    } else {
        println("NO")
    } 
}

fun readInputLine(): String {
    return readLine()!!
}



Measured memory_bytes: 45932
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);

int V, E;
vector<vector<int>> dist;
vector<vector<int>> dp;

int rec(int bit, int v)
{
  // 計算済みのとき
  if (~dp.at(bit).at(v))
  {
    return dp.at(bit).at(v);
  }
  // 初期条件
  if (bit == 0)
  {
    if (v == 0)
    {
      return dp.at(bit).at(v) = 0;
    }
    else
    {
      return dp.at(bit).at(v) = INF;
    }
  }
  // 再帰ステップ
  int res = INF;
  // 最短経路における、ひとつ前の頂点がu
  for (int u = 0; u < V; u++)
  {
    if (!(bit & (1 << u)))
    {
      continue;
    }
    if (dist.at(u).at(v) == INF)
    {
      continue;
    }
    int prev_bit = bit & ~(1 << u);
    res = min(res, rec(prev_bit, u) + dist.at(u).at(v));
  }
  return dp.at(bit).at(v) = res;
}

int main()
{
  cin >> V >> E;
  dist.resize(V, vector<int>(V, INF));
  for (int i = 0; i < E; i++)
  {
    int s, t, d;
    cin >> s >> t >> d;
    dist.at(s).at(t) = d;
  }
  dp.resize((1 << V), vector<int>(V, -1));
  int res = rec((1 << V) - 1, 0);
  if (res == INF)
  {
    res = -1;
  }
  cout << res << endl;
}


Measured memory_bytes: 6248
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define MOD 1000000007
#define OO 0x3f3f3f3f
#define NIL -1
using namespace std;
typedef long long ll;
typedef long double ld;

int n;

vector <pair <int, int>> arr;

int main() {
    Data_Nerd

	scanf("%d", &n);

    arr.resize(n);

    for(int i = 0; i < n; ++i)
    	scanf("%d%d", &arr[i].second, &arr[i].first);

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

    ll time = 0;

    for(int i = 0; i < n; ++i) {
    	time += arr[i].second;

    	if(time > arr[i].first)
    		return puts("No"), 0;
    }

    puts("Yes");

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    n=n%10;
    if (n==2||n==4||n==5||n==7||n==9)
    cout<<"hon"<<endl;
    if (n==0||n==1||n==6||n==8)
    cout<<"pon"<<endl;
    if (n==3)
    cout<<"bon"<<endl;
    return 0;
}



Measured memory_bytes: 3616
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
LL check(LL l1, LL r1, LL l2, LL r2)
{
	LL ret = max(l1 * r2, l2 * r1);
	if (min(r2, r1) <= max(l1, l2))
		return ret;
	if (l1 > l2) swap(l1, l2), swap(r1, r2);
	LL mid1 = min((l1 + r2) / 2, r1);
	LL mid2 = r2 - (mid1 - l1);
	return max(ret, mid1 * mid2);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int ncase;
	cin >> ncase;
	while (ncase--)
	{
		LL a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		LL l = 1, r = INF * 2;
		LL ans = 0;
		while (l <= r)
		{
			LL mid = (l + r) / 2;
			vector<pair<LL, LL>> vp1, vp2;
			if (mid >= a)
			{
				if (a > 1) vp1.emplace_back(1LL, a - 1);
				vp1.emplace_back(a + 1, mid + 1);
			}
			else
			{
				vp1.emplace_back(1LL, mid);
			}
			if (mid >= b)
			{
				vp2.emplace_back(b + 1, mid + 1);
				if (b > 1) vp2.emplace_back(1LL, b - 1);
			}
			else
			{
				vp2.emplace_back(1LL, mid);
			}
			LL maxv = 0;
			while (!vp1.empty() && !vp2.empty())
			{
				auto& p1 = vp1.back();
				auto& p2 = vp2.back();
				if (p1.first > p1.second)
				{
					vp1.pop_back();
					continue;
				}
				if (p2.first > p2.second)
				{
					vp2.pop_back();
					continue;
				}
				LL o = min(p1.second - p1.first, p2.second - p2.first);
				maxv = max(check(p1.second - o, p1.second, p2.first, p2.first + o), maxv);
				p1.second -= o + 1;
				p2.first += o + 1;
			}
			if (maxv >= a * b) r = mid - 1;
			else ans = mid, l = mid + 1;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define min(x,y) (x)>(y)?(y):(x)
#define LEN  100005

typedef struct pp {
	char name[15];
	int t;
}p;

p Q[LEN];
int head, tail;

void enqueue(p pa)
{
	if (head != (tail + 1) % LEN)
	{
		Q[tail++] = pa;
		tail = tail % LEN;
	}
}
p dequeue()
{
	p pa;
		pa = Q[head];
		head = (head + 1) % LEN;
		return pa;
}

int main()
{
	int n, q;
	int time=0,mint;
	p  pb;
	scanf("%d %d",&n,&q);
	for (int i = 1; i <= n; i++)
	{
		scanf("%s%d",Q[i].name,&Q[i].t);
	}
	head = 1;
	tail = n + 1;

	while (head != tail)
	{
		pb = dequeue();
		mint = min(pb.t,q);
		time += mint;
		pb.t -= mint;
		if (pb.t > 0) {
			enqueue(pb);
		}
		else
		{
			printf("%s %d\n", pb.name, time);
		}
	}
	return 0;
}


Measured memory_bytes: 4540
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    V<int> okasi(n, 0);
    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int a; cin >> a;
            okasi[a - 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (okasi[i] == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
//Factors of an num
/*
vector<ll> fact(ll n){
	vector<ll>v;
	for(int i=1;i*i<=n;i++){
		if(n%i ==0){
			v.push_back(i);
		
		if(i!=n/i)
			v.push_back(n/i);
	    }
	}

	return v;
}
*/


/*
Seive Of Eratos..
int N=1e5;
vector<bool> isprime(N+1,true);
void pri(int n){
	for(int i=2;i*i<=n;i++){
		if(isprime[i]){
			for(int j=i*i;j<=n;j+=i){
				isprime[j]=false;
			}
		}
	}
	return;
}
*/

/*
//Prime Factors
vector<bool> isprime(1e6+1,true);
 vector<int> primes;
 void sieve()
 {

    ll  i,j;
    isprime[0] = false;
    isprime[1] = false;

    for(i=2; i<=1e6 ;i++)
  {

    if(isprime[i])
    {

      primes.push_back(i);

      for(j=i*i; j<=1e6; j+=i)
      {
        isprime[j]=false;
      }

    }

  }
}

vector<int> primefactors(int  N)

 {

    vector<int> factors;
    ll pf_idx = 0, pf=primes[pf_idx];

    while(pf*pf<=N)
    {
        while(N % pf == 0)
        {
            N/=pf;
            factors.push_back(pf);
        }
        pf = primes[++pf_idx];
    }
    
    if(N != 1) factors.push_back(N);
    return factors;
}
 */   

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin.tie(NULL);
   ll a,b,c,d;	
   cin>>a>>b>>c>>d;
   ll ans=INT_MIN;
   ll a1=max(a*c,b*d);
   ll b1=max(a*d,b*c);
   ans=max(a1,b1);
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << c[i][j];
    }
    cout <<endl;
    for(int j=0;j<w;j++){
      cout << c[i][j];
    }
    cout <<endl;
  }
}


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

using namespace std;

class dice 
{
private:
	int num[7];
public:
	dice(int array[]);
	void turnE();
	void turnN();
	void turnS();
	void turnW();
	void command(string com);
	void displayTop();
	int findRight(int top, int front);
};

dice::dice(int array[])
{
	int i;
	for (i = 0; i < 6; i++)
		num[i + 1] = array[i];
}

void dice::command(string com)
{
	int len = com.length();
	int i;
	char ch;
	for (i = 0; i < len; i++)
	{
		ch = com.at(i);
		if (ch == 'E')
		{
			turnE();
			continue;
		}
		if (ch == 'N')
		{
			turnN();
			continue;
		}
		if (ch == 'W')
		{
			turnW();
			continue;
		}
		if (ch == 'S')
		{
			turnS();
			continue;
		}
	}
}

void dice::turnE()
{
	int temp;
	temp = num[6];
	num[6] = num[3];
	num[3] = num[1];
	num[1] = num[4];
	num[4] = temp;
}

void dice::turnN()
{
	int temp;
	temp = num[6];
	num[6] = num[5];
	num[5] = num[1];
	num[1] = num[2];
	num[2] = temp;
}

void dice::turnS()
{
	int temp;
	temp = num[6];
	num[6] = num[2];
	num[2] = num[1];
	num[1] = num[5];
	num[5] = temp;
}

void dice::turnW()
{
	int temp;
	temp = num[6];
	num[6] = num[4];
	num[4] = num[1];
	num[1] = num[3];
	num[3] = temp;
}

void dice::displayTop()
{
	cout << num[1] << endl;
}

int dice::findRight(int top, int front)
{
	int i;
	// find_front
	for (i = 1; i < 7 && num[i] != front; i++);
	if (i == 1)
		turnS();
	else if (i == 3)
	{
		turnW();
		turnS();
	}
	else if (i == 4)
	{
		turnE();
		turnS();
	}
	else if (i == 5)
	{
		turnS();
		turnS();
	}
	else if (i == 6)
	{
		turnN();
	}
	// now let the front to front

	for (i = 1; i < 7 && num[i] != top; i++);
	if (i == 4)
	{
		turnE();
	}
	else if (i == 6)
	{
		turnE();
		turnE();
	}
	else if (i == 3)
	{
		turnW();
	}

	return num[3];
}

int main(void)
{
	int array[6];
	int i;
	for (i = 0; i < 6; i++)
		cin >> array[i];
	dice dic(array);

	int q, top, front;
	cin >> q;
	for (i = 0; i < q; i++)
	{
		cin >> top >> front;
		cout << dic.findRight(top, front) << endl;
	}
	return 0;
}


Measured memory_bytes: 3044
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	
	int a, b ,c;
	cin >> a >> b >> c;
	if (a == b + c || b == a + c || c == a + b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}

	
}



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

int main(){
    int N;
    cin >> N;
    int A[110];
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    int num[110]={0};
    for (int i=0; i<N; i++){
        num[A[i]]++;
    }
    int count=0;
    for (int i=1; i<=100; i++){
        if (num[i]){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define ufor(i,l,r) for (int i=l;i<=r;i++)
#define MAXN 1000500
long long a[MAXN],b[MAXN],c[MAXN];
int X,Y,A,B,C;
long long ans=0;

bool cmp(int x,int y)
{
	return x>y;
}

void init()
{
	scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
	ufor (i,1,A) scanf("%lld",&a[i]);sort(a+1,a+1+A,cmp); a[A+1]=0;
	ufor (i,1,B) scanf("%lld",&b[i]);sort(b+1,b+1+B,cmp); b[B+1]=0;
	ufor (i,1,C) scanf("%lld",&c[i]);sort(c+1,c+1+C,cmp); c[C+1]=0;
	//ufor (i,1,A) suma[i]=suma[i-1]+a[i];
	//ufor (i,1,B) sumb[i]=sumb[i-1]+b[i];
	//ufor (i,1,C) sumc[i]=sumc[i-1]+c[i];
	ans=0;
	ufor (i,1,X) ans+=a[i];
	ufor (i,1,Y) ans+=b[i]; 
}
int main()
{
	init();
	//ans=suma[X]+sumb[Y];
	int p=X,q=Y;
	ufor (i,1,X+Y)
	{
		if (p==0 || q==0)
		{
			if (q>0 && c[i]>b[q]) 
				ans+=c[i]-b[q--]; else
			if (p>0 && c[i]>a[p]) 
				ans+=c[i]-a[p--];
			continue;
		} 
		if (a[p]>=b[q] && c[i]>b[q])
			ans+=c[i]-b[q--]; else
		if (a[p]<b[q] && c[i]>a[p])
			ans+=c[i]-a[p--]; else
		break;
	}

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


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

int N;
int W,H;
double X1[222],Y1[222],X2[222],Y2[222];
int sx1[222],sy1[222];
int sx2[222],sy2[222];
bool F[555][555];
double dx[555],dy[555];

const double eps = 1e-10;

int search( const vector<double>& ps, double x ){
  for( int i=0;i<ps.size();i++ )
     if( abs( ps[i] - x ) < eps ) return i;    
  assert(false);
  return -1;
}

int zip( double *Z1, double *Z2, int *z1, int *z2, double *d ){
  vector<double> ps;
  for(int i=0;i<N;i++){
    ps.push_back( Z1[i] );
    ps.push_back( Z2[i] );
  }
  sort( ps.begin(), ps.end() );
  ps.erase( unique( ps.begin(), ps.end() ), ps.end() );
  int w = ps.size();
  for(int i=0;i<N;i++){
    z1[i] = search( ps, Z1[i] );
    z2[i] = search( ps, Z2[i] );
  }
  for(int i=0;i<w;i++){
    d[i] = ps[i];
  }
  return w;
}

int main(){
  int ttt=0;
  while( ~scanf("%d",&N) && N ){
    memset( F,0,sizeof( F ) );
    for(int i=0;i<N;i++){
      double x,y,r; scanf("%lf%lf%lf",&x,&y,&r);
      X1[i] = x - r;
      X2[i] = x + r;
      Y1[i] = y - r;
      Y2[i] = y + r;
    }
    W = zip( X1, X2, sx1, sx2, dx );
    H = zip( Y1, Y2, sy1, sy2, dy );
    for(int i=0;i<N;i++){
      //cout << sx1[i] << " - " <<sx2[i] << endl;
      //cout << sy1[i] << " - " <<sy2[i] << endl;
      for(int x=sx1[i];x<sx2[i];x++){
        for(int y=sy1[i];y<sy2[i];y++){
          F[x][y] = true;
        }
      }
    }
    double res = 0.0;
    for(int x=0;x<W;x++){
      for(int y=0;y<H;y++){
        if( F[x][y] ) {
          //cout << dx[x+1]-dx[x] << " * " << dy[y+1]-dy[y] << endl;
          res += ( dx[x+1]-dx[x] ) * ( dy[y+1]-dy[y] );      

        }
      }
    }
    printf("%d %.2lf\n",++ttt,res);
  }
}

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

bool isInt(double a){
    if((int)a==a){
        return true;
    }else{
        return false;
    }
}

int main(){
    int N,D;
    cin>>N>>D;
    vector<vector<int>>X(N,vector<int>(D));
    double kyori=0;
    int count=0;
    rep(i,N){
        rep(j,D){
            cin>>X[i][j];
        }
    }

    rep(i,N){
        rep(j,N){
            if(i<=j) continue;
            rep(k,D){
                kyori+=pow(X[i][k]-X[j][k],2);
            }
            if(isInt(sqrt(kyori))){
                count++;
            }
        kyori=0;
        }
    }

    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read(){
	int c=0,nx,sign=1;
	do{
		nx=getchar()-'0';
		if(nx=='-'-'0')
			sign=-1;
	}while(nx<0 or nx>9);
	while(nx>=0 and nx<=9){
		c=c*10+nx;
		nx=getchar()-'0';
	}
	return sign*c;
}
const int N=200;
int a[N],len,cnt[N];
char s[2][30]={"Possible","Impossible"};
int main(){
	int n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		len=max(len,a[i]);
		++cnt[a[i]];
	}
	if(len%2==0){
		if(cnt[len>>1]!=1){
			puts(s[1]);
			return 0;
		}
	}else if(cnt[(len+1)>>1]!=2){
		puts(s[1]);
		return 0;
	}
	for(int i=len;i>len/2;i--)
		if(cnt[i]<2){
			puts(s[1]);
			return 0;
		}
	for(int i=1;i<len>>1;i++)
		if(cnt[i]){
			puts(s[1]);
			return 0;
		}
	puts(s[0]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
    int n; cin >> n;
    vector <int> L(n);
    for(int i=0;i<n;i++) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int l=j,r=n; int mid;
            while(l+1<r){
                mid = (l+r)/2;
                if(L[i]+L[j]>L[mid]&&L[mid]+L[j]>L[i]&&L[i]+L[mid]>L[j]){
                    l = mid;
                }else{
                    r = mid;
                }
            }
            ans += (l-j);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;
  string b = "zyxwvutsrqponmlkjihgfedcba";
  set<char> st;
  for (char c = 'a'; c <= 'z'; c++) {
    st.insert(c);
  }

  for (int i = 0; i < s.size(); i++) {
    st.erase(s[i]);
  }

  if (st.size() > 0) {
    cout << s + *st.begin() << ln;
  } else if (s == b) {
    cout << -1 << ln;
  } else {
    string t = s;
    next_permutation(all(t));
    for (int i = 0; i < t.size(); i++) {
      cout << t[i];
      if (t[i] != s[i]) {
        cout << ln;
        break;
      }
    }
  }

  return 0;
}

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

ll c[10][10];

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++){
		int la = i % 10, fi = 0;
		int k = i;
		while(k){
			if(k / 10 == 0) fi = k;
			k /= 10;
		}
		c[fi][la]++;
	}
	ll ans = 0;
	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= 9; j++){
			ans += c[i][j] * c[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int N, H[250];
	cin >> N;

	for (int i = 0; i < N; i++) cin >> H[i];
	int k = 0;
	while (k < N) {
		cout << "node " << k + 1 << ": key = " << H[k] << ", ";
		int l = (k + 1) / 2 - 1;
		if (k != 0)
			cout << "parent key = " << H[l] << ", ";
		l = (k + 1) * 2 - 1;
		if (l < N)
			cout << "left key = " << H[l] << ", ";
		l = (k + 1) * 2;
		if (l < N)
			cout << "right key = " << H[l] << ", ";
		cout << "\n";
		k++;
	}
	return 0;
}

Measured memory_bytes: 2988
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>
#include <string.h>


using namespace std;

int A[404][404];
int dx[] = {1, -1, 0 ,0};
int dy[] = {0 ,0, 1, -1};
long d;
long p;

void dfs (int x, int y, int c){
	if(c == 1){
		d++;
	} else {
		p++;
	}
	A[x][y] = 0;
	for(int i = 0;i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(A[nx][ny] == -c) dfs(nx, ny, -c);
	}
}

int main(){

	int H, W;
	cin >> H >>  W;

	int x=0, y=0;

	for(int i = 0; i < 404; i++)
		for(int j = 0 ; j < 404; j++)
			A[i][j]=0;

	for(int i = 1; i<=H; i++){
		string S;
		cin >> S;
		for(int j = 1;j<=W;j++){
			if(S[j-1] == '#'){
				A[i][j] = 1;
				x++;
			} else {
				A[i][j] = -1;
				y++;
			}
		}
	}

	long long sum = 0;
	for(int i = 1; i<=H; i++){
		for(int j = 1;j <=W;j++){
			if(A[i][j] != 1) continue;
			d=0; p=0;
			dfs(i, j, 1);
			sum += d * p;
		}
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define pll pair<ll,ll>
#define pii pair<int32_t,int32_t>
#define loop(i,n) for(int64_t i=0; i<n; i++)
#define loop1(i,a,b) for(int64_t i=a; i<=b; i++)
#define rloop(i,n) for(int64_t i=n-1; i>=0; i--) 
#define rloop1(i,a,b) for(int64_t i=a; i>=b; i--) 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define print(val) cout << #val << ": " << val << "\n";
#define print_c(a) cout<<#a<<": ";for(auto it=begin(a);it!=end(a);it++)cout<<*it<<" ";cout<<"\n";
#define fill(c,v) fill(begin(c),end(c),v);
template <typename T> T flip(T val) {reverse(begin(val),end(val)); return val;}

int main() {
  fast_io
  ll t=1; 
  int h,w,k;
  cin >> h >> w >> k;

  char matrics[h][w];
  for(int i=0; i<h; i++) {
    string temp; cin >> temp;
    for(int j=0; j<w; j++) {
      matrics[i][j] = temp[j];
    }
  }

  vector<vector<bool> > comb1;
  vector<vector<bool> > comb2;
  ll total_size1 = pow(2,h);
  ll total_size2 = pow(2,w);

  for(ll counter = 0; counter < total_size1; counter++) { 
    vector<bool> vec(h);
    for(ll j = 0; j < h; j++) { 
      if(counter & (1 << j)) 
        vec[j] = 1;
      else vec[j] = 0;
    } 
    comb1.push_back(vec);
  }

  for(ll counter = 0; counter < total_size2; counter++) { 
    vector<bool> vec(w);
    for(ll j = 0; j < w; j++) { 
      if(counter & (1 << j)) 
        vec[j] = 1;
      else vec[j] = 0;
    } 
    comb2.push_back(vec);
  } 

  ll b_count;
  ll ans=0;

  for(auto & hor : comb1) {
    for(auto & ver : comb2) {
      b_count=0;
      for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
          if(matrics[i][j]=='#' and hor[i]==0 and ver[j]==0) {
            b_count++;
          }
        }
      }
      if(b_count == k) ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    string s,t;cin>>s>>t;
    string ans="";
    rep(i,0,n-1){
        ans=ans+s[i]+t[i];
    }
    cout<<ans<<endl;
    
    
    return 0;
}




Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int i,j,a[9],b[9];
    string name[9];
    for(i=0;i<9;i++){
        cin>>name[i]>>a[i]>>b[i];
        cout<<name[i]<<" "<<a[i]+b[i]<<" "<<a[i]*200+b[i]*300<<endl;
    }
    return 0;
}

Measured memory_bytes: 3048
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<map>
#define INF 0xFFFFFF
#define ull unsigned long long
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define endl "\n"
#define M(a,b)  (a+b)/2
#define L(x) 2*x
#define R(x) 2*x+1
using namespace std;
typedef pair<int,ll> ii;
typedef pair<int,ii> iii;
int Move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
/*
    nothing at all
*/
int scr(string s){
    int score=INF;
    for(int i=0;i<s.size()-1;i++){
        score=min(score,abs(s[i]-s[i+1]));
    }
    //cout<<s<<" "<<score<<endl;
    return score;
}
int main(){
    int n;
    cin>>n;
    int arr[2*n+10];
    for(int i=0;i<2*n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+(2*n));
    int rzlt=0;
    for(int i=0;i<n;i++){rzlt+=arr[2*i];}
    cout<<rzlt;
    return 0;
}


Measured memory_bytes: 3160