akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n, m; cin >> n >> m;
    vll a(m), b(m);
    rep(i, 0, m){
        cin >> a[i] >> b[i];
    }
    vll imos(n+1, 0);
    rep(i, 0, m){
        imos[a[i]]++;
        imos[b[i]]--;
    }
    ll s = 0;
    vll p(n);
    rep(i, 1, n){
        s += imos[i];
        p[i] = s;
    }
    bool v = true;
    rep(i, 1, n){
        if(p[i]%2 == 1){
            v = false;
        }
    }
    if(v){
        prtl("YES");
    }else{
        prtl("NO");
    }
}



Measured memory_bytes: 6432
#include <bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
using namespace std;
typedef long long LL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48); ch=getchar();}
    return x*f;
}
int vis[10005];
int main(){
    int n,ans = 0;
    cin >> n;
    for (int i=1; i<=n; i+=2) {
        int cnt = 0;
        for (int j=1; j<=sqrt(i); j++) {
            if (i % j == 0){
                vis[j] = vis[i/j] = 1;
            }
        }
        for (int j=1; j<=i; j++) {
            if (vis[j] == 1) cnt++;
        }
      //  cout << i << ' ' << cnt  << endl;
        if (cnt == 8) ans++;
        memset(vis, 0, sizeof(vis));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
int main()
{
  int n,k,sum=0;
  scanf("%d %d",&n,&k);
        int arr[n];
        for(int i=0;i<n;i++)
        {
          scanf("%d",&arr[i]);
        }
        std::sort(arr,arr+n);
        for(int i=0;i<k;i++)
        {
          sum+=arr[i];
        }
        printf("%d",sum);
        
  return 0;
}

Measured memory_bytes: 1700
#include<stdio.h>
int main(void)
{
		int i,n,f;
		scanf("%d %d %d",&i,&n,&f);
		if(i==1&&n==0&&f==0){
			printf("Close\n");
			}
		if(i==0&&n==1&&f==0){
			printf("Close\n");
			}
		if(i==1&&n==1&&f==0){
			printf("Open\n");
			}
		if(i==0&&n==0&&f==1){
			printf("Open\n");
			}
		if(i==0&&n==0&&f==0){
			printf("Close\n");
			}
		return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int> a(n * 3);
	for (int i = 0; i < n * 3; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	long long sum = 0;
	for (int i = n; i < n * 3; i += 2) sum += a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1408
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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

n = getN()
nums = getList()
rainbow = 0
colors = [0 for i in range(8)]
for n in nums:
    if n >= 3200:
        rainbow+=1
    else:
        grade = n//400
        if colors[grade] == 0:
            colors[grade] = 1

clnum = sum(colors)
ansmin = max(1, clnum)
ansmax = clnum+rainbow


print(ansmin,ansmax)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define DEBUG(debug_x) cerr <<#debug_x<<": "<<debug_x<<endl;
#define DEBUG2(debug_x, debug_y) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<endl;
#define DEBUG3(debug_x, debug_y, debug_z) cerr <<#debug_x<<":"<<debug_x<<" "<<#debug_y<<":"<<debug_y<<" "<<#debug_z<<":"<<debug_z<<endl;
#define DEBUGVC(debug_x) cerr <<#debug_x<<": "; for(auto a:debug_x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(debug_x) cerr <<#debug_x<<":"<<endl; for(auto a:debug_x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (105)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;
typedef pair<int,int> Pii;
typedef pair<double,double> Pdd;

 
signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    vector<int> c(n,0LL);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(a[i] < a[j]) c[i]++;
        }
    }
    int ans=0;
    vector<int> d(n,0LL);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(a[i]>a[j]) {
                d[j]++;
            }
        }
    }
    DEBUGVC(d);
    //DEBUG(ans);

    for(int i=0; i<n; i++){
        //DEBUG(i);
        //DEBUG(((k-1)*(2*(d[i]+c[i])+(k-2)*c[i]))/2);
        //DEBUG3(i, d[i], d[i]+(k-1)*c[i]);
        int p = d[i]*k; p%=MOD;
        int q = ((k*(k-1)/2)%MOD)*c[i];
        int x = p+q;
        //int x = k*(d[i]*2+(k-1)*c[i])/2;
        //int x = y;
        //DEBUG(x);
        x %= MOD;
        ans += x;
        //DEBUG(ans);
        ans %= MOD;
    }
    cout << ans%MOD << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    int k = -1;
    double minDiff = LLONG_MAX;
    for(int i=0; i<n; ++i){
        int h;
        cin >> h;
        double temp = t - h * 0.006;
        double diff = abs(a - temp);
        if(diff < minDiff){
            minDiff = diff;
            k = i;
        }
    }
    cout << (k + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

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

    cout << x - a - ((x - a) / b) * b << endl;

}

Measured memory_bytes: 256
a,b,c = map(int,input().split())

check = set([])

p = a
i = 1
while True:
    tmp = p%b

    if tmp == c:
        print("YES")
        exit()
    
    if tmp in check:
        print("NO")
        exit()
    check.add(tmp)
    i += 1
    p = a*i


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin >> a>>b;
	int t=0,s=0;
	if(b==1) cout <<'0'<<endl;
	else{
		while(t<b){
			if(t==0) t+=a;
			else t+=a-1;
			s++;
		}
		cout <<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define int long long
using namespace std;
const int maxn=10e5+10;
int n,k,w[maxn],v[maxn],f[101][maxn];
main ()
{
    cin>>n>>k;
    fori(i,1,n) cin>>w[i]>>v[i];
    int res=0;
    fori(i,1,n)
    {
        fori(j,1,k)
        {
            f[i][j]=f[i-1][j];
            if (j>= w[i])
            f[i][j] = max(f[i-1][j-w[i]]+v[i],f[i][j]);
            res = max(res,f[i][j]);

        }
    }
    cout<<res;
}


Measured memory_bytes: 291072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> c(n-1);
  vector<ll> s(n-1);
  vector<ll> f(n-1);
  rep(i,n-1){
    cin>>c[i]>>s[i]>>f[i];
  }

  rep(i,n){
    ll ans=0;
    for(int j=i;j<n-1;j++){
      if(ans<=s[j]) ans=s[j];
      else ans=((ans+f[j]-1)/f[j])*f[j];
      ans+=c[j];
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>


int str_length(const char str[]) {

	int len=0;
	int i=0;
	while(str[i]) {
		len++;
		i++;
	}
	
	return(len);
}

int main(void)
{

	char str[10];
	
	scanf("%s",str);
	
	/*for(int i=0; i<str_length(str);i++){
		putchar(str[i]);
	}*/
	
	/*printf("文字数は%dでした。\n", str_length(str));*/
	
	int min=643;
	for(int j=0;j<str_length(str)-2;j++) {
		int temp=(str[j]-'0')*100+(str[j+1]-'0')*10+(str[j+2]-'0');
		if(abs(temp-753)<=min) min=abs(753-temp);
	}
	printf("%d",min);
	return(0);
}


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

int main() {
	int n,k;
	cin >> n >> k;
	int dnum;
	int anum;
	vector<int> HaveTreat(n);
	for(int i = 0; i < k; i++){
		cin >> dnum;
		for(int j = 0; j < dnum; j++){
			cin >> anum;
			HaveTreat[anum-1]++;
		}
	}
	int Trick = 0;
	for(int i = 0; i < n; i++){
		if(HaveTreat[i] == 0){
			Trick++;
		}
	}
	cout << Trick;
}

Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	vector<int64_t> A(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end(), greater<int32_t>());

	int64_t prev = -1, first = -1, second = -1;
	for (int32_t i = 0; i < N; i++) {
		if (A[i] == prev) {
			if (first == -1) {
				first = A[i];
				prev = -1;
				continue;
			} else if (second == -1) {
				second = A[i];
				break;
			}
		}
		prev = A[i];
	}
	int64_t res;
	if (first == -1 || second == -1)
		res = 0;
	else
		res = first * second;

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector <tuple <string, int, int> > res(N);
    rep(i, N) {
        string rbuf;
        int    p;
        cin >> rbuf >> p;
        res.at(i) = make_tuple(rbuf, -p, i);
    }
    sort(res.begin(), res.end());

    rep(i, N) {
        int rnum;
        tie(ignore, ignore, rnum) = res.at(i);
        cout << rnum + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   char bch = b[0];
   int bnum = bch - '0';
   rep(i,bnum-1){
      a += a[0];
   }

   char ach = a[0];
   int anum = ach - '0';
   rep(i,anum-1){
      b += b[0];
   }

   if(a <= b) cout << a << endl;
   else cout << b << endl;

   




   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int K = Integer.parseInt(scanner.next());
	    int N = Integer.parseInt(scanner.next());
	    int A[] = new int[N];
	    
	    for (int i=0; i<N; i++) {
	    	A[i] = Integer.parseInt(scanner.next());
	    }
	    
	    int max = K - (A[N-1] - A[0]);
	    for (int i=0; i<N-1; i++) {
	        if (max < A[i+1] - A[i]) max=A[i+1] - A[i];
	    }
        System.out.print(K-max);
	}

}

Measured memory_bytes: 60104
#include <stdio.h>

int main()
{
   int a,b;
   scanf("%d", &a);
   scanf("%d", &b);
   int total = 0;
   total = a + b;
   
   if(total < 10){
   printf("%d\n",total);
   }else{
   printf("error");
   }
   
   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m;
int ans=0;
struct node
{
    int a,b;
}a[100010];
bool cmp(node a,node b)
{
    return a.a<b.a;
}
priority_queue<int> q;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].a,&a[i].b);
    sort(a+1,a+n+1,cmp);
    int p=1;
    for(int i=m;i>=0;i--)
    {
        while(a[p].a+i<=m&&p<=n) q.push(a[p++].b);
        if(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1660
a=list(input())
b=list(input())
c=list(input())
x='a'

while True:
  if x=='a':
    if len(a)==0:
      print('A')
      exit()
    x=a[0]
    a.remove(x)

  elif x=='b':
    if len(b)==0:
      print('B')
      exit()
    x=b[0]
    b.remove(x)

  elif x=='c':
    if len(c)==0:
      print('C')
      exit()
    x=c[0]
    c.remove(x)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 n,m,k;
    cin >> n >> m>>k;
    i64 time{k},ans{0};

    vector<i64> a(n), b(m);
    for (size_t i=0; i<n; ++i) {
        cin >> a[i];
    }

    for (size_t i=0; i<m; ++i) {
        cin >> b[i];
    }


    i64 tmp_t{0};
    i64 a_max{-1}, b_min{-1};
    for (i64 i=0 ; i<n; ++i) {
        if (tmp_t+a[i] > time) break;
        tmp_t += a[i];
        a_max = i;
        ans = (i+1);
    }
    for (i64 i=0; i<m; ++i) {
        if (tmp_t+b[i] > time) break;
        tmp_t += b[i];
        b_min = i;
        ++ans;
    }

    if (a_max == -1 && b_min == -1) {
        cout << 0 << endl;
        return 0;
    }

    for (i64 i=a_max; i >= 0; --i) {
        if (b_min == b.size()-1) break;
        tmp_t -= a[i];
        --a_max;
        for (size_t j=b_min+1; j<m; ++j) {
            if (tmp_t+b[j] > time) break;
            tmp_t += b[j];
            b_min = j;
        }
        //cout << a_max << " "<< b_min << endl;
        if (a_max == -1 && b_min != -1) ans = max(ans, b_min+1);
        else {
            ans = max(ans, a_max+1 + b_min+1);
        }
    }
    cout << ans << endl;

    return 0;
}


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

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

int nbombs(int H, int W, string S[50], int x, int y) {
int bombcount=0, p, q;
  for(int i=0; i<8; ++i) {
    p = x+dx[i], q = y+dy[i];
    if(p>=0 && p<H && q>=0 && q<W && S[p][q] == '#')
      bombcount++;
  }
  return bombcount;
}

int main(){
  int H, W;
  string S[50];
  
  cin >> H >> W;
  for(int i=0; i<H; ++i) cin >> S[i];

  for(int x=0; x<H; ++x)
    for(int y=0; y<W; ++y)
      if(S[x][y] != '#')
      	S[x].replace(y, 1, to_string(nbombs(H, W, S, x, y)));
  
  for(int i=0; i<H; ++i)
    cout << S[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }

int n, a, b, d;

int x[100001];
int y[100001];

typedef pair<int,int> pp;

map<int, set<pp>> ptsX, ptsY;

map<int, vector<int>> ptX, ptY;

inline int abs(int x){ return x>0?x:-x; }
int dist(int a, int b){ return max(abs(x[a]-x[b]), abs(y[a]-y[b])); }

bool vis[100001];

void dfs(int p);

void lineX(int px, int l, int r){
    auto it = ptsX.find(px);
    if(it == ptsX.end()) return;
    auto& s = it->second;
    while(true){
        auto i2 = s.lower_bound({l, 0});
        if(i2 == s.end()) break;
        if(i2->first > r) break;
        dfs(i2->second);
    }
}

void lineY(int py, int l, int r){
    auto it = ptsY.find(py);
    if(it == ptsY.end()) return;
    auto& s = it->second;
    while(true){
        auto i2 = s.lower_bound({l, 0});
        if(i2 == s.end()) break;
        if(i2->first > r) break;
        dfs(i2->second);
    }
}

int countX(int px, int l, int r){
    auto it = ptX.find(px);
    if(it == ptX.end()) return 0;
    auto& s = it->second;
    return upper_bound(all(s), r) - lower_bound(all(s), l);
}

int countY(int py, int l, int r){
    auto it = ptY.find(py);
    if(it == ptY.end()) return 0;
    auto& s = it->second;
    return upper_bound(all(s), r) - lower_bound(all(s), l);
}

typedef long long ll;
ll ans;

void dfs(int p){
    if(vis[p]) return;
    vis[p]=true;
    ptsX[x[p]].erase({y[p], p});
    ptsY[y[p]].erase({x[p], p});
    lineX(x[p]-d, y[p]-d, y[p]+d);
    lineX(x[p]+d, y[p]-d, y[p]+d);
    lineY(y[p]-d, x[p]-d, x[p]+d);
    lineY(y[p]+d, x[p]-d, x[p]+d);

    ans += countX(x[p]-d, y[p]-d, y[p]+d-1);
    ans += countY(y[p]+d, x[p]-d, x[p]+d-1);
    ans += countX(x[p]+d, y[p]-d+1, y[p]+d);
    ans += countY(y[p]-d, x[p]-d+1, x[p]+d);
}

int main()
{
    read(n, a, b);
    for(int i=1; i<=n; ++i){
        read(x[i], y[i]);
        int A = x[i] + y[i];
        int B = y[i] - x[i];
        x[i]=A; y[i]=B;
        ptsX[x[i]].insert({y[i], i});
        ptsY[y[i]].insert({x[i], i});
        ptX[x[i]].pb(y[i]);
        ptY[y[i]].pb(x[i]);
    }
    for(auto& tmp : ptX) sort(all(tmp.second));
    for(auto& tmp : ptY) sort(all(tmp.second));
    
    d = dist(a, b);
    dfs(a); dfs(b);
    
    printf("%lld\n", ans/2);
    
    return 0;
}


Measured memory_bytes: 54784
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;



int main(){
     LL a,c;
     char b;
     cin>>a>>b>>c;
     if(b=='+')cout<<a+c<<endl;
     else cout<<a-c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
const int P=1e9+7;
int n,cnt[30];char str[N];
int main() {
	scanf("%d%s",&n,str+1);
	for(int i=1; i<=n; i++)
		cnt[str[i]-'a']++;
	long long res=1;
	for(int i=0; i<=25; i++)
		res=(res*(cnt[i]+1))%P;
	printf("%lld\n",(res-1+P)%P);
	return 0;	
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    ll cntmin=0;
    ll sm=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]<=0){
            cntmin++;
            a[i]*=-1;
        }
        sm+=a[i];
    }
    sort(a.begin(),a.end());
    if(cntmin%2==0){
        cout<<sm<<endl;
    }
    else{
        cout<<sm-2*a[0]<<endl;
    }
}





Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N + 1];
		int B[] = new int[N];

		long jizenSum = 0;
		for (int i = 0; i < N + 1; i++) {
			A[i] = sc.nextInt();
			jizenSum += A[i];
		}

		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}

		int tmp = 0;
		for (int i = 0; i < N; i++) {
			tmp = A[i] - B[i];
			if (tmp < 0) {
				if (B[i] - A[i] > A[i + 1]) {
					A[i + 1] = 0;
				} else {
					A[i + 1] = A[i + 1] - (B[i] - A[i]);
				}
				A[i] = 0;
			} else {
				A[i] = tmp;
			}
		}

		long sum = 0;
		for (int i = 0; i < N + 1; i++) {
			sum += A[i];
		}

		System.out.println(jizenSum - sum);
	}
}


Measured memory_bytes: 64736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 100000000;
const int MAX_N = 10;
int main() {
	int n;
	while (cin >> n,n) {
		int dis[MAX_N + 1][MAX_N + 1];
		int V = 0, s[11] = { 0 };
		for (int i = 0; i < MAX_N + 1; i++) {
			for (int j = 0; j < MAX_N + 1; j++) {
				if (i == j) dis[i][j] = 0;
				else dis[i][j] = INF;
			}
		}
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			dis[a][b] = c;
			dis[b][a] = c;
			V = max(V, max(a, b));
		}
		for (int k = 0; k <= V; k++) {
			for (int i = 0; i <= V; i++) {
				for (int j = 0; j <= V; j++) {
					dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
				}
			}
		}
		int x = INF;
		for (int i = 0; i <=V; i++) {
			int sum = 0;
			for (int j = 0; j <=V; j++) {
				sum += dis[i][j];
			}
			s[i] = sum;
			x = min(x, sum);
		}
		for (int i = 0; i <= V; i++) {
			if (s[i] == x) {
				cout << i << " " << x << endl;
				break;
			}
		}
	}
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,cnt[200010]={};

int main(){
	cin>>n;
	int i,x;
	for(i=1;i<n;++i){
		cin>>x;
		++cnt[x];
	}
	for(i=1;i<=n;++i)
		cout<<cnt[i]<<"\n";
	
	
	return 0;
}

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

#define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1

// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())

// debug
#define check(x) std::cout << #x << " = " << x << '\n'

// print
#define cout(x) std::cout << x << '\n'

// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

int SumOfDigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

void PrintMap(std::map<int, int>& m) {
  for (auto iter: m) {
    std::cout << iter.first << " => " << iter.second << "\n";
  }
}

int Digits(int x) {
  int d = 0;
  while (x > 0) {
    x /= 10;
    d++;
  }
  return d;
}

void solve();

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

void solve() {
  int n, c, k;
  std::cin >> n >> c >> k;
  VI t(n);
  REP(i, n) { std::cin >> t.at(i); }
  ASORT(t);
  // REP(i, n) { cout(t.at(i)); }
    
  int b = 1;
  int p = 0;
  int tn, tf;
  REP(i, n-1) {
    tn = t.at(i+1);
    
    if (p == 0) {
      tf = t.at(i);
      p++;
    }

    if (p == c || tn > tf + k) {
      p = 0;
      b++;
    } else {
      p++;
    }
    // check(tn); check(tf); check(p); check(b); std::cout << '\n';
  }
  cout(b);
}

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

using namespace std;

int main(){
    unsigned long long H,now=3;
    cin >> H;
    if(H==1){
        cout << 1 << endl;
    }
    for(unsigned long long i=2;i<=H;i*=2){
        if(i<=H && H<i*2){
            cout << now << endl;
            break;
        }else{
            now = now*2 + 1;
        }
    }
}

Measured memory_bytes: 256
///There is No God Besides Allah, Hazrat Muhammad (SAW) is the Messenger of Allah

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

#define _FIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define TC(t) while(t--){slove();}

#define all(v) (v).begin(),(v).end()
#define rall(v) reverse(all(v))
#define S(v) sort(all(v))
#define SP(v,s,e) sort(v.begin()+s,v.begin()+e)
#define Rs(v) sort(rall(v))
#define f(s,e) for(int i=s;i<e;i++)
#define rf(e,s) for(int i=e;i>=s;i--)
#define fi(it,v) for(auto it=v.begin();it!=v.end();++it)
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),v.end())
#define mi(v) *min_element(all(v))
#define ma(v) *max_element(all(v))
#define fup(v,n) fill(all(v),n)
#define point(x)  fixed<<setprecision(x)
#define endl "\n"

#define pb push_back
#define ff first
#define se second

const double pi = acos(-1.0);
const int mod=1000000007;///1e9+7
const int maxn = 2000010;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef set<ll> St;
typedef multiset<ll> MSt;
typedef map<ll,ll> M;
typedef map<string,ll> MS;
typedef map<char,char> MC;

ll b_exp(ll a,ll n)
{
    ll ans = 1;
    while(n>0)
    {
        if(n&1)
            ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

void slove()
{
    int n,m;
    cin>>n>>m;
    ll a[n];
    ll sum = 0;
    f(0,m)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
        cout<<-1<<endl;
    else
    {
        cout<<n-sum<<endl;
    }

}


int main()
{
   // _FIO;
//   int t;
//   cin>>t;
//   TC(t);


slove();

}

///ALHAMDULILLAH

///Source_C0de-Fahim Shahriar


Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int main(){
    int N;
    int ans=0;
    string S;
    cin >> N >> S;
    for (int i = 2;i < N;i++){
        if(S[i-2] == 'A' && S[i-1] == 'B' && S[i] == 'C')ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int w,h,ct;
	string s;
	while(cin>>w>>h){
		if(w==0&&h==0) break;
		int a[w+2][h+2];
		for(int i=0;i<h+2;i++){
			for(int j=0;j<w+2;j++){
				a[j][i]=0;
			}
		}
		int num=1;
		for(int i=1;i<h+1;i++){
			cin>>s;
			for(int j=1;j<w+1;j++){
				if(s[j-1]=='.'){
					a[j][i]=1;
				}
				else if(s[j-1]=='#'){
					a[j][i]=0;
				}
				else if(s[j-1]=='@'){
					a[j][i]=2;
				}
			}
		}
		do{
			ct=0;
			for(int i=1;i<h+1;i++){
				for(int j=1;j<w+1;j++){
					if(a[j][i]==2&&a[j-1][i]==1){
						a[j-1][i]=2;
						ct++;
						num++;
					}
					else if(a[j][i]==2&&a[j+1][i]==1){
						a[j+1][i]=2;
						ct++;
						num++;
					}
					else if(a[j][i]==2&&a[j][i-1]==1){
						a[j][i-1]=2;
						ct++;
						num++;
					}
					else if(a[j][i]==2&&a[j][i+1]==1){
						a[j][i+1]=2;
						ct++;
						num++;
					}
				}
			}
		} while(ct>0);
		cout<<num<<endl;
	}
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>

using namespace std;

int main()
{
    int x1=0;
    int x2=0;
    int y1=0;
    int y2=0;
    cin>>x1;
    cin>>y1;
    cin>>x2;
    cin>>y2;
    int delx = (x2-x1);
    int dely = (y2-y1);
    int x3 = x2-dely;
    int y3 = y2+delx;
    int x4 = x1-dely;
    int y4 = y1+delx;
    cout<<x3 << " ";
    cout<<y3 << " ";
    cout<<x4 << " ";
    cout<<y4;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return tuple(map(int, input().split()))


def main():
    N = int(input())
    A = inpl()
    cumA = [0] * (N + 1)
    for i, a in enumerate(A):
        cumA[i + 1] = cumA[i] + a
    dp = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    for L in range(1, N):
        for i in range(N - L):
            dp[i][i + L] = cumA[i + L + 1] - cumA[i] + min(dp[i][i + k] + dp[i + k + 1][i + L] for k in range(L))
        # print(dp)
    print(dp[0][N - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 47324
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  int pre, now, ans=0;
  cin >> now;
  pre=now;
  ans=now;
  rep(i, n-1){
    cin >> now;
    ans+=min(pre, now);
    pre=now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct
{
    char e;
    int y;
} year;

year ytoj(int y)
{
}

int main(void)
{
    int e, y;
    int ans;

    scanf("%d %d", &e, &y);
    switch (e){
    case 0:
        if (y < 1912){
            putchar('M');
            ans = y - 1868 + 1;
        }
        else if (y < 1926){
            putchar('T');
            ans = y - 1912 + 1;
        }
        else if (y < 1989){
            putchar('S');
            ans = y - 1926 + 1;
        }
        else {
            putchar('H');
            ans = y - 1989 + 1;
        }
        break;
    case 1:
        ans = y + 1868 - 1;
        break;
    case 2:
        ans = y + 1912 - 1;
        break;
    case 3:
        ans = y + 1926 - 1;
        break;
    case 4:
        ans = y + 1989 - 1;
        break;
    }
    printf("%d\n", ans);

    return 0;
}

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


int main() {
    int N;
    cin >> N;
    ll ans = 0;
    rep(i,N) if ((i+1) % 3 != 0 && (i+1) % 5 != 0) ans += (ll)i + 1;
    cout << ans << endl;
}


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

int main() {
  int z;
  
  while(cin >> z && z) {
    int mx = 0;
    for(int x=1; x*x*x<=z*z*z; x++) {
      int y = pow(z*z*z-x*x*x, 1.0/3);
      if(y > 0) mx = max(mx, x*x*x+y*y*y);
    }
    cout << z*z*z-mx << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1220
d = 10 ** 9 + 7
n = int(input())
lista = [int(x) for x in input().split()]
for k in lista:
    k %= d

totalJ = sum(lista)

total = 0
for i in range(n-1):
    totalJ -= lista[i]
    total += totalJ * lista[i]
total %= d
print(total)



Measured memory_bytes: 31440
def is_prime(x):
    if x==2:
        return 1
    elif x&1==0:
        return 0
    elif pow(2,x-1,x)==1:
        return 1
    else:
        return 0
N = int(input())
c=0
for i in range(N):
    n=int(input())
    c+=is_prime(n)
print(c)

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

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

	if (a == 'H' && b == 'H' || a=='D' && b=='D') {
		cout << 'H' << endl;
	}
	else {
		cout << 'D' << endl;
	}
	return 0;
}

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

int mp[4][102];
int n;

int dfs(int y, int x, int c){
  if ( y > 2 || x > n ){
    return -1;
  }
  c += mp[y][x];
  if ( y == 2 && x == n ) {
    return c;
  }

  return max(dfs(y+1,x,c),dfs(y,x+1,c));
}
main()
{
  memset(mp,0,sizeof(mp));
  
  cin >> n;
  for ( int i = 1; i <= 2; i++ ) {
    for ( int j = 1; j <= n; j++ ) {
      cin >> mp[i][j];
    }
  }

  cout << dfs(1,1,0) << endl;

  return (0);
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100

int main(){

    int a;
    int spls_a;
    int ary_a[MAX];
    int cnt_a = 0;
    int max_a;

    int b;
    int spls_b;
    int ary_b[MAX];
    int cnt_b = 0;
    int max_b;

    int i;
    int j;

    int k;
    int ary_k[MAX];
    int cnt_k = 1;

    scanf("%d %d %d", &a, &b, &k);

    for(i=1 ; i<=MAX ; i++){

        spls_a = a%i;
        spls_b = b%i;

        if(spls_a==0){
            ary_a[cnt_a] = i;
            cnt_a++;
        }
        if(spls_b==0){
            ary_b[cnt_b] = i;
            cnt_b++;
        }
    }

    max_a = cnt_a;
    max_b = cnt_b;

    for(i=0 ; i<max_a ; i++){
        for(j=0 ; j<max_b ; j++){
            if(ary_a[i]==ary_b[j]){
                ary_k[cnt_k] = ary_a[i];
                cnt_k++;
            }
        }
    }

    printf("%d", ary_k[cnt_k-k]);

}

Measured memory_bytes: 128
/*
 * 2つの整数a,bを読み込み、a,bの大小関係を出力するプログラム
 *
 * Input
 * a b
 *
 * Constraints
 * -1000<=a,b<=1000
 */

#include <stdio.h>

int main()
{
	int a,b;
	scanf("%d %d", &a, &b);

	if (a > b)
		printf("a > b\n");
	else if(a < b)
		printf("a < b\n");
	else 
		printf("a == b\n");

	return 0;
}


Measured memory_bytes: 2036
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(-100>x |y>100){
    printf("error\n");
  }
  if(W<=0 | H&&r>100){
    printf("error\n");
  }
   if(x-r<0 | x+r>W){
    printf("No\n");
  }else if(y-r<0 | y+r>H){
    printf("No\n");
   }
   else if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
     printf("Yes\n");
   }
 
  return 0;
}

 
 

Measured memory_bytes: 584
n,m,c = gets.chomp.split(' ').map(&:to_i)
b = gets.chomp.split(' ').map(&:to_i)
ans = 0

n.times do |i|
  sum = 0
  j = 0
  as = gets.chomp.split(' ').map(&:to_i)
  as.each do |a|
    sum+=a*b[j]
    j+=1
  end
  ans += 1 if sum+c > 0
end
puts ans

Measured memory_bytes: 14312
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N;
    cin >> N;
    string ans[] = {"pon", "pon", "hon", "bon", "hon",
                    "hon", "pon", "hon", "pon", "hon"};
    cout << ans[N % 10] << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vi adj[150001];
vector<ld> dpadj[150001];
ld dp[150001];
vector<ld> dp2adj[150001];
ld dp2[150001];

void dfs1(int u, int p)
{
	ld ans = 0;
	ll child = 0;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		dfs1(v,u);
		child++;
		ans+=dp[v];
	}
	if(child==0) 
	{
		dp[u]=0;
		return ;
	}
	ans/=ld(child);
	ans+=1;
	dp[u] = ans;
}

void dfs2(int u, int p)
{
	ld ans = 0;
	ll child = 0;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		dfs2(v,u);
		child++;
		ans+=dp[v];
	}
	if(child==0) 
	{
		return ;
	}
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		if(child==1)
		{
			dpadj[u][i] = 0;
			continue;
		}
		dpadj[u][i] = 1 + (ld(1)/ld(child-1))*(ans-dp[v]);
	}
}

void dfs3(int u, int idx, int p)
{
	ll child=0;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		child++;
	}
	if(p==-1)
	{
		dp2[u] = dp[u];
	}
	else
	{
		dp2[u] = (ld(child)/ld(child+1))*dp[u] + (ld(1)/ld(child+1))*(dp2adj[p][idx]+1);
	}
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		if(p==-1)
		{
			dp2adj[u][i] = dpadj[u][i];
		}
		else
		{
			dp2adj[u][i] = ld(child-1)/ld(child)*dpadj[u][i] + ld(1)/ld(child)*(dp2adj[p][idx]+1);
		}
	}
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(v==p) continue;
		dfs3(v,i,u);
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int u, v; cin>>u>>v;
		u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	for(int i = 0; i < n; i++)
	{
		dpadj[i].resize(int(adj[i].size()));
		dp2adj[i].resize(int(adj[i].size()));
	}
	dfs1(0,-1);
	dfs2(0,-1);
	dfs3(0,0,-1);
	for(int i = 0; i < n; i++)
	{
		cout<<fixed<<setprecision(10)<<dp2[i]<<'\n';
	}
}


Measured memory_bytes: 44416
#include <stdio.h>

int main(void) {
	int a, b, c, n, x, sum;
	
	while(1){
		scanf("%d %d", &n, &x);
		
		sum=0;
		
		if(n==0 && x==0)
		break;
		
		for(a=1;a<=n-2;a++){
			for(b=a+1;b<=n-1;b++){
				for(c=b+1;c<=n;c++){
					if(a+b+c==x)
					sum+=1;
				}
			}
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 600
n,m,x,y=map(int,input().split())
xs=input().split()
ys=input().split()
xs=[int(i) for i in xs]
ys=[int(i) for i in ys]

xs.sort()
ys.sort()
flag=0
if xs[-1]<y:
  z=xs[-1]+1
  if z==x or z==y:
    pass
  elif ys[0]>=z:
      print('No War')
      flag=1
if flag==0:
  print('War')

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

int min2(int a,int b){
    if(a < b) return a;
    else return b;}

int main(int argc, char const *argv[]) {
  int N, K, S;
  cin >> N >> K >> S;
  if (S < 1e+9){
    for(int i = 0; i < K; i++){
      cout << S << " ";
    }
    for(int i = 0; i < N - K; i++){
      cout << S + 1 << " ";
    }
  }
  else {
    for(int i = 0; i < K; i++){
      cout << S << " ";
    }
    for(int i = 0; i < N - K; i++){
      cout << 1 << " ";
    }
  }
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題166

            string[] line = Console.ReadLine().Split(' ');
            int N = int.Parse(line[0]);
            int K = int.Parse(line[1]);

            List<int> sunuke = new List<int>();

            for (int i = 0; i < K; i++)
            {
                int d = int.Parse(Console.ReadLine());

                string[] lines = Console.ReadLine().Split(' ');

                for (int j = 0; j < d; j++)
                {
                    int num = sunuke.IndexOf(int.Parse(lines[j]));

                    //Console.WriteLine(num);


                    if (num < 0)
                    {
                        sunuke.Add(int.Parse(lines[j]));
                    }

                }
            }

            //foreach (int a in sunuke)
            //{
            //    Console.WriteLine(a);
            //}

            //Console.WriteLine(sunuke.Count);


            Console.WriteLine(N - sunuke.Count);



            //for (int i = 0; i < K; i++)
            //{
            //    int d = int.Parse(Console.ReadLine());


            //}




        }


    }
}


Measured memory_bytes: 28064
#include <stdio.h>

int main(void)
{
    char base;
    base = getchar();
    if (base == 'A')
    {
        puts("T");
    }
    else if (base == 'T')
    {
        puts("A");
    }
    else if (base == 'C')
    {
        puts("G");
    }
    else if (base == 'G')
    {
        puts("C");
    }

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    bool f = true;
    int cnt = 0;
    while (f) {
        for (int i = 0; i < n; ++i) {
            if (a[i] % 2) {
                f = false;
                break;
            } else {
                a[i] /= 2;
            }
        }
        if (f) ++cnt;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def examA():
    N = I()
    A = LI()
    ans = 0
    for i in range(N-1):
        if A[i+1]==A[i]:
            A[i+1] = 101
            ans +=1
    print(ans)
    return

def examB():
    T = I()
    ans = ["Yes"]*T
    for i in range(T):
        A, B, C, D = LI()
        if A<B:
            ans[i] = "No"
            continue
        if D<B:
            ans[i] = "No"
            continue
        if C>=B:
            continue


    return

def examC():
    N = I()
    S = SI()
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    loop = 2**N
    for i in range(loop):
        curR = ""; curB = ""
        curR2 = ""; curB2 = ""
        for j in range(N):
            if i&(1<<j)==(1<<j):
                curR +=S[j]
                curR2 +=S[j+N]
            else:
                curB +=S[j]
                curB2 +=S[j+N]
        d1[(curR,curB)] +=1
        d2[(curR2,curB2)] +=1
    ans = 0
    for key,i in d1.items():
        cur = i*d2[(key[1][::-1],key[0][::-1])]
        ans +=cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 187452
#include <stdio.h>

int main(){
	
	int n, flag = 1;
	scanf("%d", &n);
	
	char s[n + 1];
	scanf("%s", &s);
	
	
	if(n % 2 ==1){
		printf("No\n");
	}
	else if(n % 2 == 0){
		for(int i = 0; i < n / 2; i++){
			if(s[i] != s[i + n / 2]){
				flag = 0;
			}
		}
	
	if(flag){
		printf("Yes\n");
	}
	
	else{
		printf("No\n");
	}
		
	}
	
	return 0;
	
}

Measured memory_bytes: 1616
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: i64 = sc.read();
    let b: i64 = sc.read();
    let x = (a + b) / 2;
    if (a - x).abs() == (b - x).abs() {
        println!("{}", x);
    } else {
        println!("IMPOSSIBLE");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	fsum := 0
	for i := 1; i <= n; i++ {
		if (i%3 == 0) || (i%5 == 0) {
		} else {
			fsum += i
		}
	}

	fmt.Println(fsum)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n;
    cin >> n;
    unordered_map<string, bool> map;
    string word;
    cin >> word;
    map[word] = true;
    string last_word = word;
    bool flag = true;
    for (int i = 0; i < n-1; i++){
        cin >> word;
        if (word[0] != last_word[last_word.size()-1] || map[word]){
            flag = false;
        }
        else map[word] = true;
        last_word = word;
    }
    if (flag) cout << "Yes\n";
    else cout << "No\n";
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define ins insert
#define si size()
#define E exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
#pragma GCC optimize(2)
using namespace std;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;}void put1(){ puts("Yes") ;}void put2(){ puts("No") ;}
void debug(){printf("T   A   T\n");}void put3(){ puts("-1"); }ll qpf(ll a, ll b, ll p)
{ll ret = 0;while(b){if(b & 1) ret = (ret + a) % p;a = (a + a) % p;b >>= 1;}
return ret % p ;}ll qp(ll a, ll n, ll p){ll ret = 1;while(n){if(n & 1) ret = qpf(ret, a, p);
a = qpf(a, a, p);n >>= 1;}return ret % p ;}//��=acos(L/2R);
//void say(){ cout<<"I CAN AC"<<endl;}

const int manx=1e6+5;
const double eps =1e-8;


int main()
{
    string s; cin>>s;
    ll a=0,b=0;
    for(int i=0;i<s.si;i++){
        if(s[i]=='A') a++;
        else b++;
    }
    if(a&&b) put1();
    else put2();
    return 0;
}



Measured memory_bytes: 256