akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

int main (int argc, char **argv)
{
  int n = 0;
  int *a = NULL;
  int i = 0;
  int rain = 0;

  scanf("%d", &n);
  a = (int *)malloc(n * sizeof(int));

  for(i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
    rain += ((i & 1) ? -a[i] : a[i]);
  }

  printf("%d", rain);

  for(i = 1; i < n; i++)
  {
    rain = (2 * a[i-1]) - rain;
    printf(" %d", rain);
  }

  printf("\n");

  free(a);

  return 0;
}

//
// [Description]
//
// If the amount of mountain is N, the mountain is indexed to 0, 1, ..., N-1.
//
// If mount[i] means that the amount of rain for mountain i,
// these have the following regularity:
//   mount[0]:
//     mount[0]
// 
//   mount[1]:
//     (mount[0] / 2) + (mount[1] / 2) = a[0]
//     -> mount[1] = (2 * a[0]) - mount[0]
// 
//   mount[2]:
//     (mount[1] / 2) + (mount[2] / 2) = a[1]
//     -> mount[2] = (2 * a[1]) - mount[1]
//     -> mount[2] = (2 * a[1]) - ((2 * a[0]) - mount[0])
//     -> mount[2] = (2 * a[1]) - (2 * a[0]) + mount[0]
// 
//   mount[3]:
//     (mount[2] / 2) + (mount[3] / 2) = a[2]
//     -> mount[3] = (2 * a[2]) - mount[2]
//     -> mount[3] = (2 * a[2]) - ((2 * a[1]) - (2 * a[0]) + mount[0])
//     -> mount[3] = (2 * a[2]) - (2 * a[1]) + (2 * a[0]) - mount[0]
//   ...
// 
// So, if i is odd and greater than 0:
//   mount[i] = (2 * a[i-1]) - (2 * a[i-2]) + .... + (2 * a[0]) - mount[0]
// 
// if i is even and greater than 0:
//   mount[i] = (2 * a[i-1]) - (2 * a[i-2]) + .... - (2 * a[0]) + mount[0]
// 
// Since the mountain N equals to mountain 0 and the amount of mountain (= N) is odd,
// the following equation holds:
//   mount[0] = mount[N]
//   ->mount[0] = (2 * a[N-1]) - (2 * a[N-2]) + .... + (2 * a[0]) - mount[0]
//   ->mount[0] = a[N-1] - a[N-2] + ... + a[0]
// 
// Therefore:
//   mount[0] = a[N-1] - a[N-2] + ... + a[0]
//   mount[i + 1] = (2 * a[i]) - mount[i]


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n, a[100000], c[100001] = {0}, cnt = 0;

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i != 0){
			c[i] = abs(a[i]-a[i-1]);
			cnt += abs(a[i]-a[i-1]);
		}
	}
	cnt += abs(a[n-1]);
	cnt += abs(a[0]);
	c[n] = abs(a[n-1]);
	c[0] = abs(a[0]);
	
	for(int i = 0; i < n; i++){
		if(i == 0){
			cout << cnt - c[0] - c[1] + abs(a[1]) << endl;
		}
		else if(i == n-1){
			cout << cnt - c[n] - c[n-1] + abs(a[n-2]) << endl;
		}
		else{
			cout << cnt - c[i] - c[i+1] + abs(a[i-1] - a[i+1]) << endl;
		}
	}
	
	return 0;
}

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

int main(){
	// sengen
	int a,b,c,d,e,k;
	// nyuryoku
	cin >> a >> b >> c >> d >> e >> k;
	// keisan
	if(e-a<=k){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void)
{
	double hill[1000], max = 0, min = 1000000000, sum = 0;
	int i = 0;
	
	while (scanf("%lf", &hill[i]) != EOF){
		if (max < hill[i])max = hill[i];
		if (min > hill[i])min = hill[i];
	}
	
	printf("%.1lf\n", max - min);
	
	return (0);
}

Measured memory_bytes: 652
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int board[5][5];
int dp[5][5];
int main(){
	int m;
	cin>>m;
	while(m--){
		for(int i =1;i <=5;i++){
			for(int j =1;j <=5;j++){
				dp[i][j] =0;
			}
		}
		for(int i =1;i <=5;i++){
			int x = 1;
			for(int j =1;j <=5;j++){
				cin>>board[i][j];
				if(board[i][j]==1){
					dp[i][j]=x;
					x++;
				}else{
					dp[i][j]=0;
					x = 1;
				}
				//cout <<board[i][j];
			}
			//cout <<endl;
		}
		/*cout <<endl;
		rep(i, 5){
			rep(j, 5){
				cout <<dp[i][j];
			}
			cout <<endl;
		}*/
		//cout <<endl;
		int ans = 0;
		for(int i =1;i <=5;i++){
			for(int j=1;j <=5;j++){
				if(dp[i][j]==0)continue;
				int tmp =INF;
				for(int k =i;k <=5;k++){
					tmp =min(tmp,dp[k][j]);
					if(tmp==0)break;
					ans =max(ans,(k-i+1)*tmp);
				}
			}
		}
		cout <<ans<<endl;

	}
	return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
a = gets.split(" ").map(&:to_i).sort

b = a[-1]
tmp = b / 2.0

idx = a.bsearch_index{|x| x > tmp}
ans = tmp - a[idx - 1] > a[idx] - tmp ? a[idx] : a[idx - 1]

puts [b, ans].join(" ")


Measured memory_bytes: 10112
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <vector>;
using namespace std;

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

	long long MOD = 1e9 + 7;

	vector<int> vec(n);
	vector<int> sum(n);
	for (int i = 0;i < n;i++) {
		cin >> vec[i];
		if(i==0) sum[0] = vec[0];
		if (i > 0)sum[i] = vec[i] + sum[i - 1];
		sum[i] %= MOD;
	}
	

	long long ans=0;
	for (int i = 0;i < n;i++) {
		long long k = sum[n - 1] - sum[i];
		if (k < 0)k += MOD;
		ans += vec[i] * (k);
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int W, H, N, x, y, a;
  cin >> W >> H >> N;
  int xm = 0, ym = 0, xM = W, yM = H;
  
  for (int i = 0; i < N; i++){
    cin >> x >> y >> a;
    if (a == 2) xM = min(xM, x);
    else if (a == 1) xm = max(xm, x);
    else if (a == 4) yM = min(yM, y);
    else ym = max(ym, y);
  }
  cout << max(yM-ym, 0) * max(xM-xm, 0) << endl;
}

Measured memory_bytes: 256
N=int(input())
"""
R=[]

for i in range(N):
    n=int(input())
    R.append(n)

minv = R[0]
maxv=0
for j in range(1,N-1):
    maxv=max(maxv,R[j]-minv)
    minv=min(minv,R[j])

print(maxv)
"""

R=[int(input()) for i in range(N)]
minv=R[0]
maxv=R[1]-R[0]

for j in range(1,N):
    maxv=max(maxv,R[j]-minv)
    minv=min(minv,R[j])

print(maxv)


Measured memory_bytes: 13600
N = str(input())
N1 = list(set(N))
if len(N1) == 1:
    print("Yes")
elif len(N1) == 2:
    if N.count(N[0]) == 1 or N.count(N[3]) == 1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 38256
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
  
  ll N;
  cin >> N;
  
  string str;
  cin >> str;
  
  ll ans = 1;
  for (ll i=1;i<str.size();i++){
    if (str[i]!=str[i-1]) ans++;
  }
  
  cout << ans;
  
  return 0;
}


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

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

    vector<int> a(w);
    for (int i = 0; i < w; i++) {
        cin >> a[i];
    }

    vector<int> dp1(w, 0), dp2(w, 0);
    for (int i = 0; i < w; i++) {
        if (a[i] == 0) dp1[i] = 1e9;
        else if (i > 0 && a[i] < 0)
            dp1[i] = min(dp1[i - 1] - 1, -a[i]);
        else if (i > 0)
            dp1[i] = dp1[i - 1] - 1;
    }
    for (int i = w - 1; i >= 0; i--) {
        if (a[i] == 0) dp2[i] = 1e9;
        else if (i < w - 1 && a[i] < 0)
            dp2[i] = min(dp2[i + 1] - 1, -a[i]);
        else if (i < w - 1)
            dp2[i] = dp2[i + 1] - 1;
    }

    int ans = 0;
    for (int i = 0; i < w; i++) {
        if (a[i] <= 0) continue;
        ans += max(0, min(a[i], max(dp1[i], dp2[i])));
    }
    cout << ans << endl;
}



Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int INF=1e9+7;
const int maxn=2e5+5;
ll a[100005];
ll gcd(ll t1,ll t2)
{
    return t2==0?t1:gcd(t2,t1%t2);
}
int main()
{
    int n;
    ll x;

    cin>>n;

    for (int q=0;q<n;q++)
    {
        cin>>a[q];
    }
    ll ans=a[0];
    for (int q=1;q<n;q++)
    ans=gcd(ans,a[q]);

    cout<<ans<<endl;


}

Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

void solve(){
    
    int n;

    cin >> n;

    cout << (n + 1) / 2 << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  long double a, b, x;
  cin >> a >> b >> x;
  if (x >= a * a * b / 2) {
    long double alpha = (2 * (a * a * b - x)) / (a * a * a);
    long double ans = atan(alpha) * 180 / M_PI;

    printf("%.10Lf\n", ans);
    return 0;
  } else {
    long double alpha = (a * b * b) / (2 * x);
    long double ans = atan(alpha) * 180 / M_PI;

    printf("%.10Lf\n", ans);
    return 0;
  }
}

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

int main() {
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    sort(a.rbegin(), a.rend());

    int l = p, r = n;
    while (l < r) {
        int mid = l + (r - l) / 2;
        ll total = p * m + (n - mid - 1) * m;
        bool flag = true;
        for (int i = p - 1; i < mid; i++) {
            if (a[mid] + m - a[i] < 0) flag = false;
            total += a[mid] + m - a[i];
        }
        if (total >= m * v && flag) {
            l = mid + 1;
        } else
            r = mid;
    }
    cout << l << endl;
}

Measured memory_bytes: 1024
import java.util.*;

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

        int n = sc.nextInt();
        while (n-- > 0) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int a = sc.nextInt();

            if (a == 1) {
                for (int i = 1; i <= h; i++) {
                    for (int j = 1; j <= x; j++) {
                        array[j][i] = 1;
                    }
                }
            } else if (a == 2) {
                for (int i = 1; i <= h; i++) {
                    for (int j = x+1; j <= w; j++) {
                        array[j][i] = 1;
                    }
                }
            } else if (a == 3) {
                for (int i = 1; i <= w; i++) {
                    for (int j = 1; j <= y; j++) {
                        array[i][j] = 1;
                    }
                }
            } else {
                for (int i = 1; i <= w; i++) {
                    for (int j = y+1; j <= h; j++) {
                        array[i][j] = 1;
                    }
                }
            }
        }

        int count = 0;
        for (int i = 1; i <= w; i++) {
            for (int j = 1; j <= h; j++) {
                if (array[i][j] == 1) count++;
            }
        }

        System.out.println(h * w - count);
    }
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> a(h + 2, string(w + 2, '#'));
    for (int i = 1; i < h + 1; i++)
    {
        for (int j = 1; j < w + 1; j++)
        {
            char c;
            cin >> c;
            a.at(i).at(j) = c;
        }
    }
    for (auto s : a)
    {
        cout << s << endl;
    }
}

Measured memory_bytes: 256
n = gets.to_i
array = []

n.times.with_index do |i|
  c, p = gets.split(' ')
  array << {order: i, city: c, point: p.to_i }
end

array.sort! do |a,b|
  if a[:city] == b[:city]
    b[:point] <=> a[:point]
  else
    a[:city] <=> b[:city]
  end
end

array.each {|arr| puts arr[:order]+1}


Measured memory_bytes: 1788
#ABC149.C
X = int(input())
def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
  
  # nの平方根まで計算する
    m = int(n**0.5) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True
while True:
    if isPrime(X)==True:
        print(X)
        break
    else:
        X+=1

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    
    Scanner scanner = new Scanner(System.in);
    int S = scanner.nextInt();
    int W = scanner.nextInt();
    
    if(W>=S){
      System.out.println("unsafe");
    }else{
      System.out.println("safe");
    }
    
  }
}


    
  


Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  ll c,l;
  vector<ll> s;
  vector<ll> ord(n+1,-1);
  ll v=0;
  while(ord[v]==-1){
    ord[v]=s.size();
    s.push_back(v);
    v=a.at(v)-1;
  }
  l=ord[v];
  c=s.size()-ord[v];
  if(k<l){
    cout << s.at(k)+1;
  }else{
    k-=l;
    k%=c;
    cout << s.at(l+k)+1;
  }
}

Measured memory_bytes: 8376
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int comp(char k)
{
	if(k == 'J') return 0;
	else if(k == 'O') return 1;
	else return 2;
}

int main()
{
    int m, n, k;
	
	cin >> m >> n >> k;
	
	
	vector<string> field(m);
	vector<vector<vint> > dp(m + 1, vector<vint>(n + 1, vint(3, 0)));
	
	rep(i, m)
		cin >> field[i];
	
	REP(i, 1, m+1) REP(j, 1, n+1) rep(t, 3)
	{
		dp[i][j][t] = dp[i-1][j][t] + dp[i][j-1][t] - dp[i-1][j-1][t] + (comp(field[i-1][j-1]) == t);
	}
	
	while(k--)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		
		rep(i, 3)
		{
			cout << dp[c][d][i] - dp[a-1][d][i] - dp[c][b-1][i] + dp[a-1][b-1][i] << (i == 2 ? "\n" : " ");
		}
	}
}

Measured memory_bytes: 28000
from sys import stdin

input = stdin.readline

N = int(input())

txy = [[int(j) for j in input().split()] for i in range(N)]


def main():
    pt = 0
    px = 0
    py = 0

    flg = False

    for t, x, y in txy:
        d = abs(x - px) + abs(y - py)
        dt = t - pt
        # 到達 あるいは 通過
        if d <= dt:
            # 距離と時間の偶奇が一致しない 戻れない
            if d % 2 != dt % 2:
                break
            else:
                pt = t
                px = x
                py = y
        # 到達しない
        else:
            break
    else:
        # break しなかった 完走
        flg = True

    print("Yes" if flg else "No")
    return


main()


Measured memory_bytes: 21080
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, M;
    cin >> N >> M;

	vector<ll > A(N+1919, 0);
  	for(ll i = 0; i < M; i++){
      	ll a, b; cin >> a >> b;
      	A[a]++;
      	A[b+1]--;
    }
	ll ans = 0;
  	vector<ll > tmp(N+1919, 0);
   	for(ll i = 1; i <= N; i++){
		tmp[i] += tmp[i-1] + A[i];
      	if(tmp[i] == M){
          ans++;
        }
    }
  
  cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cassert>

using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)

void Main()
{
	int K, S;
	cin >> K >> S;

	int64_t count = 0;
	rep(x, K+1)
	{
		rep(y, K+1)
		{
			if (x+y > S) break;
			else if (S-x-y > K) continue;
			++count;
		}
	}

	cout << count << endl;
}

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

	Main();
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

int sz, nr, N, M1, M2, comp[200009], ans[200009], id[200009], frq[200009];
bool ap[200009];
vector < int > v[200009], h[200009];

void df_init (int nod)
{
    id[nod] = nr;
    for (auto it = h[nod].begin (); it != h[nod].end (); it ++)
        if (id[*it] == 0)
            df_init (*it);
}

void dfs (int nod)
{
    ap[nod] = 1, comp[++sz] = nod, frq[id[nod]] ++;
    for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
        if (ap[*it] == 0)
            dfs (*it);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d", &N, &M1, &M2);
while (M1 --)
{
    int x, y;
    scanf ("%d %d", &x, &y), v[x].push_back (y), v[y].push_back (x);
}
while (M2 --)
{
    int x, y;
    scanf ("%d %d", &x, &y), h[x].push_back (y), h[y].push_back (x);
}
for (int i=1; i<=N; i++)
    if (id[i] == 0) nr ++, df_init (i);
for (int i=1; i<=N; i++)
    if (ap[i] == 0)
    {
        dfs (i);
        for (int j=1; j<=sz; j++)
            ans[comp[j]] = frq[id[comp[j]]];
        while (sz) frq[id[comp[sz --]]] --;
    }
for (int i=1; i<=N; i++)
    printf ("%d ", ans[i]);
printf ("\n");
return 0;
}


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

int main()
{
    int N;
    int d[110];
    int i,count=0;
    cin >> N;
    for(i=0;i<N;++i){
        cin >> d[i];
        }
    
    sort(d,d+N);
    for(i=0;i<N;i++){
        if(d[i] !=d[i-1]){
            count +=1;
        }
    }
    cout << count << endl;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};


int main(){
    int n, m; cin >> n >> m;
    vector<pair<int, int>> lis(n, {1, 0});
    lis[0] = {1, 1};
    REP(i, 0, m){
        int x, y; cin >> x >> y;
        x--; y--;
        if(lis[x].second == 1){
            if(lis[x].first == 1){
                lis[x] = {0, 0};
                lis[y] = {lis[y].first+1, 1};
            }else{
                lis[x].first--;
                lis[y] = {lis[y].first+1, 1};
            }
        }else{
            lis[x].first--;
            lis[y].first++;
        }
    }
    ll ans = 0;
    REP(i, 0, n){
        if(lis[i].second == 1){
            ans++;
        }
    }
    cout << ans << endl;
}  

Measured memory_bytes: 1024
i = list(map(int, input().split()))

if i[0] == 5 and i[1] == 5 and i[2] == 7:
    print('YES')
elif i[0] == 5 and i[1] == 7 and i[2] == 5:
    print('YES')
elif i[0] == 7 and i[1] == 5 and i[2] == 5:
    print('YES')
else: print('NO')



Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int num = parseInt(sc.nextLine());
      int[] number = new int[num];
      String[] tmp = sc.nextLine().split(" ");
      int count = 0;

      for (int i = 0; i < num; i++) {
        number[i] = parseInt(tmp[i]);
      }
      for (int i = 0; i < num; i++) {
        int temp = 0;
        for (int j = i + 1; j < number.length; j++) {
          if (number[j] <= number[i]) {
            temp++;
            i++;
          } else {
            break;
          }
        }
        count = temp > count ? temp : count;
      }
      System.out.println(count);
      sc.close();
      }

      public static int parseInt(String num) {
        return Integer.parseInt(num);
      }
}

Measured memory_bytes: 49208
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(n+1,0) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		if(a>n) ans++ ;
		else cnt.at(a)++ ;
	}
	for(int i=1;i<=n;i++){
		if(cnt.at(i)<i) ans += cnt.at(i) ;
		else ans += cnt.at(i)-i ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    while(true) {
        int n, k;
        cin >> n >> k;
        if(!n && !k) break;

        int sum = 0;
        int ans = 0;
        queue<int> q;
        for(int i = 0; i < n; ++i) {
            int num;
            scanf("%d", &num);

            sum += num;
            if(i == k-1) ans = sum;
            if(i >= k) {
                sum -= q.front();
                q.pop();
                ans = max(ans, sum);
            }
            q.push(num);
        }

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

Measured memory_bytes: 0
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int x,y;
  cin>>x>>y;
  if(y%2==0&y/2-x>=0&2*x-y/2>=0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  ll ans = 0;
  rep(i, n-1){
    int x = (i+1) / 2;
    ans += a[x];
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4028
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		vvi in(n,vi(2));
		rep(i,2)rep(j,n)cin>>in[j][i];
		vvi h(n,vi(2));
		int x=0,y=0;
		int out=0,ans=inf;
		while(1){
			if(x!=n-1)while(in[x][y]==1&&in[x+1][y]==1){
				x++;
				if(x==n-1)break;
			}
			while(in[x][y]==2)x--;
			if(x==n-1)break;
			if(h[x][y]==1)break;
			h[x][y]=true;
			out++;
			y^=1;
			x=min(x+2,n-1);
		}
		if(x==n-1)ans=out;
		h=vvi(n,vi(2));
		x=0;y=1;
		out=0;
		while(1){
			if(x!=n-1)while(in[x][y]==1&&in[x+1][y]==1){
				x++;
				if(x==n-1)break;
			}
			while(in[x][y]==2)x--;
			if(x==n-1)break;
			if(h[x][y]==1)break;
			h[x][y]=true;
			out++;
			y^=1;
			x=min(x+2,n-1);
		}
		if(x==n-1)cout<<min(ans,out)<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1232
from collections import Counter

N=int(input())
list1=list(map(int,input().split()))

dic1=Counter(list1)

def choose2(n):
    return n*(n-1)/2

sum=0
for key in dic1:
    sum+=choose2(dic1[key])

for i in list1:
    print(int(sum-dic1[i]+1))

Measured memory_bytes: 34116
#include<stdio.h>
#include<string.h>

int main(void)
{
  int i, n, m, pn[100000]={}, ans[100000]={}, pi;
  int seikai=0, pena=0;
  char input[3];
  scanf("%d%d", &n, &m);
  for(i = 0; i < m; i++){
    scanf("%d%s", &pi, input);
    if(strcmp(input, "AC") == 0){
      if(ans[pi-1] == 0){
        seikai++;
        pena += pn[pi-1];
        ans[pi-1] = 1;
      }
    }else{
      pn[pi-1]++;
    }
  }
  printf("%d %d\n", seikai, pena);
  
  return 0;
}

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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int MAXN = 2E5 + 100, INF = 1E17 + 5;
int val[MAXN], t[4*MAXN], lazy[4*MAXN];

void push(int v) {
	t[2*v + 1] += lazy[v];
	lazy[2*v + 1] += lazy[v];
	t[2*v + 2] += lazy[v];
	lazy[2*v + 2] += lazy[v];
	lazy[v] = 0;
}

void build_tree(int v, int l, int r) {
	if(r < l)
		return;
	if(l == r) {
		t[v] = val[l];
		return;
	}
	int mid = (l + r)/2;
	build_tree(2*v + 1, l, mid);
	build_tree(2*v + 2, mid + 1, r);
	t[v] = max(t[2*v + 1], t[2*v + 2]);
}

void update(int v, int l, int r, int tl, int tr, int val) {
	if(tr < tl)
		return;
	if(tr == r && tl == l) {
		lazy[v] += val;
		t[v] += val;
		return;
	}
	push(v);
	int mid = (l + r)/2;
	update(2*v + 1, l, mid, tl, min(tr, mid), val);
	update(2*v + 2, mid + 1, r, max(tl, mid + 1), tr, val);
	t[v] = max(t[2*v + 2], t[2*v + 1]);
}

int query(int v, int l, int r, int tl, int tr) {
	if(tr < tl)
		return -INF;
	if(tl == l && tr == r)
		return t[v];
	push(v);
	int mid = (l + r)/2;
	return max(query(2*v + 1, l, mid, tl, min(mid, tr)), 
			query(2*v + 2, mid + 1, r, max(tl, mid + 1), tr));
}

int32_t main() {
	int n, m;
	cin >> n >> m;
	vi l(m), r(m), a(m);
	vi v(m);
	vvi ends(n + 1), begins(n + 1);
	iota(all(v), 0);
	build_tree(0, 0, n);
	for(int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> a[i];
		ends[r[i]].pb(i);
		begins[l[i]].pb(i);
	}
	vi dp(n + 1, -INF);
	dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int pos : begins[i]) {
			update(0, 0, n, 0, l[pos] - 1, a[pos]);
		}
		dp[i] = query(0, 0, n, 0, i - 1);
		update(0, 0, n, i, i, dp[i]);
		for(int pos : ends[i])
			update(0, 0, n, 0, l[pos] - 1, -a[pos]);
	}
	int res = 0;
	for(int i = 0; i <= n; i++)
		res = max(res, dp[i]);
	cout << res << '\n';
}


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

int makeStrExceptQuo( string s, string a[100], string b[100] )
{
    int index = 0, index2 = 0, cnt = 0;
    bool sw = 0;
    for( int i = 0; i < s.size(); i++ )
    {
        if( sw == 0 && s[i] != '"' )
            b[index2] += s[i];
        else if( sw == 0 && s[i] == '"' )
        {
            sw = 1;
            index2++;
            cnt++;
        }
        else if( sw == 1 && s[i] == '"' )
        {
            sw = 0;
            index++;
            cnt++;
        }
        else
            a[index] += s[i];
    }
    return cnt;
}

int main()
{
    int cnt1, cnt2;
    string s, t, a[100], b[100], c[100], d[100];

    while( cin >> s )
    {
        if( s == "." )
            break;
        cin >> t;

        for( int i = 0; i < 100; i++ )
        {
            a[i] = "";
            b[i] = "";
            c[i] = "";
            d[i] = "";
        }

        cnt1 = makeStrExceptQuo( s, a, b );
        cnt2 = makeStrExceptQuo( t, c, d );

        bool judge = 1;
        if( cnt1 != cnt2 )
            judge = 0;

        int cnt = 0;
        for( int i = 0; i < 100; i++ )
        {
            if( b[i] != d[i] )
            {
                judge = 0;
                break;
            }
            if( a[i] != c[i] )
                cnt++;
        }

        if( judge && cnt == 0 )
            cout << "IDENTICAL" << endl;
        else if( judge && cnt == 1 )
            cout << "CLOSE" << endl;
        else
            cout << "DIFFERENT" << endl;

    }

    return 0;
}


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

int main()
{
  std::string s, t;
  std::cin >> s >> t;
  for (int i = 0; i < s.size(); ++i)
  {
    if (s == t)
    {
      puts("Yes");
      return 0;
    }
    s = s.back() + s.substr(0, s.size() - 1);
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	char s[200007];
	cin >> s;
	int64_t ans = 0;
	int c = 0;
	for(int i = 0;i < strlen(s);i++)
	{
		while(s[i] == 'A')
		{
            c++;
            i++;
		}
        if(s[i] == 'B' && s[i+1] == 'C')
        {
            ans += c;
            i++;
        }
        else
            c = 0;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define MAX 1000000

typedef struct {
  char name[10];
  int time;
  int flag;
}Pro;

void enqueue(Pro);
  
int n,head,tail;
Pro queue[MAX];

int main(){
  int i,q,record,total;
  Pro v;
  
  scanf("%d %d",&n,&q);
  if(n < 1 || 1000000 < n)exit(0);
  if(q < 1 || 1000 < q)exit(0);

  head = 1;
  tail = head;
  total = 0;

  for(i = 1; i <= n; i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
    queue[i].flag = 0;
    if(queue[i].time < 1 || 50000 < queue[i].time)exit(0);
    total += queue[i].time;
    if(total < 1 || 1000000 < total)exit(0);
  }
  tail += n ;
  
  record = 0;
  
  while(1){
    
    if(queue[head].time - q <= 0){
      record += queue[head].time;
      printf("%s %d\n",queue[head].name,record);
      head = (head + 1)%MAX;
    }
    else if(queue[head].time - q > 0){
      record += q;
      queue[head].time = queue[head].time - q;
      v = queue[head];
      head = (head + 1)%MAX;
      enqueue(v);
    }
    if(head == tail)break;
  }
  
  return 0;
}

void enqueue(Pro v){
  
  queue[tail] = v;
  tail = (tail + 1)%MAX;
  
}




Measured memory_bytes: 5428
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

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


int main()
{
	while (1){
		int t_cardnum,h_cardnum;
		int t_card[100] = { 0 }, h_card[100] = {0};
		int t_sum = 0, h_sum = 0;
		scanf("%d %d",&t_cardnum,&h_cardnum);

		if (t_cardnum == 0 && h_cardnum == 0){
			break;
		}

		int i, j;
		for (i = 0; i < t_cardnum; i++){
			scanf("%d", &t_card[i]);
			t_sum += t_card[i];
		}
		for (i = 0; i < h_cardnum; i++){
			scanf("%d", &h_card[i]);
			h_sum += h_card[i];
		}

		if ((t_sum + h_sum) % 2 == 1){
			printf("%d\n",-1);
			continue;
		}

		int diff;
		diff = t_sum - h_sum;

		int point,sum=1000,t_num,h_num;
		for (i = 0; i < t_cardnum; i++){
			for (j = 0; j < h_cardnum; j++){
				point = t_card[i] - h_card[j];
				if (point == (diff / 2)){
					if (sum>t_card[i] + h_card[j]){
						t_num = i;
						h_num = j;
						sum = t_card[i] + h_card[j];
					}
				}
			}
		}

		if (sum == 1000){
			printf("%d\n",-1);
		}
		else{
			printf("%d %d\n", t_card[t_num], h_card[h_num]);
		}
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;

bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second < right.second;
}
using namespace std;
lli n, m, p;



int main() {
	string s;
	lli a, b;
	cin >> a >> b;
	
	cout << ((a+b>a-b && a+b>a*b) ? a+b :((a-b>a*b)? a-b:a*b));
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int n;
bool f=true;

signed main() {
    cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        if (a%2 == 0 && (a%3 != 0 && a%5 != 0)) f = false;
    }
    if (f) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n, s=0, d;
  scanf("%d", &n);
  d = n;
  while( d > 0){
    s += d % 10;
    d /= 10;
  }
  if( n % s ){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}
    

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

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

    int n = s.size(), mxLen = 0;

    for( int i = 0; i < n; i++ ){
        for( int j = i; j < n; j++ ){
            if( s[ j ] == 'A' or s[ j ] == 'G' or s[ j ] == 'C' or s[ j ] == 'T' ){
                mxLen = max( mxLen, j - i + 1 );
            }
            else{
                i = j;
                break;
            }
        }
    }
    cout << mxLen << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  
  map<int, int> cnt;
  for (int x : A) {
    if (cnt.count(x)) {
      cnt.at(x)++;
    } 
    else {
      cnt[x] = 1;
    }
  }
  
  bool ans = true;
  
  if(n%2 == 0){
    for (auto x : cnt) {
      if(x.first == 0){
        ans = false;
      }
      else if(x.second != 2){
        ans = false;
      }
    }
  }
  
  if(n%2 != 0){
    for (auto x : cnt) {
      if(x.first == 0){
        if(x.second != 1){   
          ans = false;
        }
      }
      else if(x.second != 2){
        ans = false;
      }
    }
  }

  if(ans){
    int64_t s = 1;
    
    for (int i = 0; i < n/2; i++) {
      s *= 2;
      s %= 1000000007;
    }

    
    cout << s << endl;
  }
  else{
    cout << 0 << endl;
  }
  

}
             
 


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

using namespace std;

typedef long long ll;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int hx[][6] = {{0, 0, 1, -1, -1, -1}, {1, 1, 1, -1, 0, 0}};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int INF = 1 << 29;

inline int in(){int x;scanf("%d",&x);return x;}

int W, H;
int gx, gy;
struct Board {
  int grid[32][32];
  int cx, cy;
  Board(){}
  void load(){
    for (int y = 0; y < H; y++){
      for (int x = 0; x < W; x++){
        grid[y][x] = in();
        if (grid[y][x] == 2) cx = x, cy = y;
        if (grid[y][x] == 3) gx = x, gy = y;
      }
    }
  }
  bool in_bounds(int x, int y){ return 0 <= x && x < W && 0 <= y && y < H; }
  bool movable(int d){
    int nx = cx + dx[d], ny = cy + dy[d];
    return in_bounds(nx, ny) && grid[ny][nx] != 1;
  }
  bool move(int d){
    while (movable(d)){
      if (is_end()) break;
      grid[cy][cx] = 0;
      cx += dx[d];
      cy += dy[d];
    }
    if (is_end()) return true;
    grid[cy][cx] = 2;
    int nx = cx + dx[d], ny = cy + dy[d];
    if (!in_bounds(nx, ny)) return false;
    grid[ny][nx] = 0;
    return true;
  }
  bool is_end(){ return cx == gx && cy == gy; }
  void dump(){
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        printf("%c", "_#*G"[grid[i][j]]);
      }
      puts("");
    }
  }
};

int ans;
void dfs(Board b, int turn=0){
  if (b.is_end()){
    ans = min(ans, turn);
    return;
  }
  if (turn >= 10) return;
  for (int d = 0; d < 4; d++){
    if (!b.movable(d)) continue;
    Board nb = b;
    if (!nb.move(d)) continue;
    dfs(nb, turn + 1);
  }
}

int main()
{
  while (W = in(), H = in()){
    Board b;
    b.load();
    ans = INF;
    dfs(b);
    if (ans == INF) puts("-1");
    else printf("%d\n", ans);
  }

  return 0;
}

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

using namespace std;

#define pt pair<int, int>
#define x first
#define y second
#define what_is(x) cerr << #x << " is " << x << endl;
#define endl '\n'
#define int long long
#define ld long double
random_device rd;
mt19937 rnd(rd());
const int inf = __LONG_LONG_MAX__;

const int N = 3e5 + 5, mod = 1e9 + 7;

int a[N][2][61];

int bp(int a, int k)
{
	if (k == 0) return 1;
	if (k % 2) return (bp(a, k - 1) * a) % mod;
	int temp = bp(a, k / 2) % mod;
	return (temp * temp) % mod;
}

signed main()
{
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; ++i)
		cin >> vec[i];
	for (int i = n - 1; i > 0; --i)
	{
		int x = vec[i], bit = 0;
		while (x)
		{
			++a[i][x % 2][bit];
			++bit;
			x /= 2;
		}

		while (bit < 60)
		{
			++a[i][0][bit];
			++bit;
		}

		for (int j = 0; j < 60; ++j)
		{
			a[i - 1][0][j] = a[i][0][j];
			a[i - 1][1][j] = a[i][1][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		vector<int> bits(60);
		int x = vec[i], bit = 0;
		while (x)
		{
			bits[bit] = x % 2;
			++bit;
			x /= 2;
		}

		for (int j = 0; j < 60; ++j)
		{
			int temp = a[i + 1][(bits[j] + 1) % 2][j] % mod;
			int pw = bp(2, j) % mod;
			ans += (pw * temp) % mod;
			ans %= mod;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 288512
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,a,b,h[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);read(a);read(b);
	a-=b;
	for(int i=1;i<=n;i++)
		read(h[i]);
	int l=1,r=inf;
	while(l<r){
		int mid=l+r>>1;ll t=0;
		for(int i=1;i<=n;i++)
			t+=max(0ll,((ll)h[i]-(ll)mid*b+a-1)/a);
		if(t<=mid) r=mid; else l=mid+1;
	}
	printf("%d\n",r);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}




Measured memory_bytes: 640
import numpy as np
n = int(input())
flag = 0

for i in range(n):
    a,b,c = [int(z) for z in input().split()]
    p = np.abs(b)+np.abs(c)
    if a < p or (a-p)%2 != 0:
        flag = 1
    
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14432
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    final String s = sc.next();
    final String t = sc.next();
    int count = 0;
    for (int i = 0; i < s.length(); ++i) {
      if (s.charAt(i) != t.charAt(i))
        ++count;
    }
  	System.out.println(count);
  }
}

Measured memory_bytes: 41040
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

const int maxN = 185;
char res[maxN*(maxN+1)/2][maxN*(maxN+1)/2];

char solve(const vector<string>& A, int sx, int ex, int sy, int ey){
    int x = sx * (2 * maxN - sx + 1) / 2 + ex - sx;
    int y = sy * (2 * maxN - sy + 1) / 2 + ey - sy;
    if(res[x][y] != -1) return res[x][y];
    if(sx == ex && sy == ey) return res[x][y] = 0;
    char r = 100;
    int L = sx, R = ex + 1;
    while(R-L > 1){
        int mid = (L+R)/2;
        auto c1 = solve(A, sx, mid-1, sy, ey);
        auto c2 = solve(A, mid, ex, sy, ey);
        if(c1 == 0 && c2 == 0 && A[sx][sy] == A[mid][sy]){
            r = 0;
        } else {
            r = min<char>(r, max(c1, c2) + 1);
        }
        if(c1 == c2) break;
        if(c1 > c2) R = mid;
        else L = mid;
    }
    L = sy, R = ey + 1;
    while(R-L > 1){
        int mid = (L+R)/2;
        auto c1 = solve(A, sx, ex, sy, mid-1);
        auto c2 = solve(A, sx, ex, mid, ey);
        if(c1 == 0 && c2 == 0 && A[sx][mid-1] == A[sx][mid]){
            r = 0;
        } else {
            r = min<char>(r, max(c1, c2) + 1);
        }
        if(c1 == c2) break;
        if(c1 > c2) R = mid;
        else L = mid;
    }
    return res[x][y] = r;
}

int main(){
    int H, W; cin >> H >> W;
    vector<string> A(H);
    for(auto& a : A) cin >> a;
    memset(res, -1, sizeof(res));
    cout << (int)solve(A, 0, H-1, 0, W-1) << endl;
}

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

int main() {
    int N;
    cin >> N;
    string ans = ((N == 0) ? "0" : "");
    long long a = 1;
    while (N != 0) {
        long long b = a * -2;
        long long div = abs(b);
        if (abs(N % div) == abs(a)) {
            ans += "1";
            N -= a;
        } else {
            ans += "0";
        }
        a = b;
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter


def f(N):
    d = []
    i = 2
    while N > 1:
        if N % i == 0:
            d.append(i)
            N //= i
        else:
            i += 1
    return d

def solve(N):
    c = Counter()
    for k in range(2, N + 1):
        c.update(f(k))
    ans = 1
    P = 10 ** 9 + 7
    for count in c.values():
        ans *= (count + 1)
        ans %= P
    return ans


if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  deque<int> ans;

  for (int i=0; i<n; i++) {
    int a; cin>>a;
    if (i%2 != n%2) ans.push_front(a);
    else ans.push_back(a);
  }

  while (!ans.empty()) {
    cout << ans.front();
    ans.pop_front();
    cout << (ans.empty()? '\n' : ' ');
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pa;

#define fst first
#define snd second
#define pb push_back

const int maxn=1000005,maxm=306;
const double pi=acos(-1.0);
const ll mod=1000000007;
const double eps=1e-8;


int n;
ll a[maxn];
ll tt=1;
double pp=0;

int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
    {
        scanf("%lld",a+i);
        if(a[i]==0) tt=0;
    }
    if(tt>0)
    {
        for(i=0;i<n;i++)
        {
            pp+=log10(a[i]);
            if(pp>=18+eps) break;
        }
        if(i>=n)
        {
            for(j=0;j<n;j++) tt*=a[j];
            if(tt>1000000000000000000LL) tt=-1;
        }
        else tt=-1;
    }
    printf("%lld\n",tt);
    return 0;
}


Measured memory_bytes: 4920
#include<bits/stdc++.h>
#define mod 1e9+7
typedef long long ll;

int main()
{
	int n,m,sum=0;
	std::cin>>n>>m;
	while(m--)
	{
		int z;
		std::cin>>z;
		sum+=z;
	}
	if(sum<=n)
	    std::cout<<n-sum;
    else
    	std::cout<<"-1";
}

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

int main() {
    ll S; cin >> S;
    ll k = ceil(sqrt(S));
    ll t = k * k - S;
    cout << "0 0 " << k << ' ' << t << ' ' << 1 << ' ' << k << endl;
}



Measured memory_bytes: 256
fn main () {
    fn input () -> (isize, isize, isize) {
        let mut ab = String::new();
        std::io::stdin().read_line(&mut ab).unwrap();
        let ab: Vec<_> = ab.trim().split_whitespace().flat_map(str::parse).collect();
        (ab[0], ab[1], ab[2])
    }
    fn get_height (coord: &(isize, isize, isize), cx: isize, cy: isize) -> isize {
        // h = |xi - cx| + |yi - cy| + z
        let &(x, y, z) = coord;
        let x = if x - cx >= 0 { x - cx } else { cx - x };
        let y = if y - cy >= 0 { y - cy } else { cy - y };
        x + y + z
    }
    fn chk (coord: &(isize, isize, isize), cx: isize, cy: isize, h: isize) -> bool {
        // z == max(hi - |xi - cx| - |yi - cy|, 0)
        let &(x, y, z) = coord;
        let x = if x - cx >= 0 { x - cx } else { cx - x };
        let y = if y - cy >= 0 { y - cy } else { cy - y };
        let h = h - x - y;
        if h >= 0 { h == z } else { 0 == z }
    }

    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();
    let coordinates: Vec<_> = (0..n).map(|_|input()).collect();
    for cx in 0..101 {
        for cy in 0..101 {
            for i in 0..n {
                let mut correct = true;
                if coordinates[i].2 == 0 {
                    continue;
                }
                let level = get_height(&coordinates[i], cx, cy);
                for i in 0..n {
                    if !chk(&coordinates[i], cx, cy, level) {
                        correct = false;
                        break;
                    }
                }
                if correct {
                    println!("{} {} {}", cx, cy, level);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 4352
from collections import Counter
n = int(input())
s = []
c_count = [[0] * n for _ in range(26)]
for i in range(n):
    count = Counter(input().rstrip())
    for key in count.keys():
        c_count[ord(key)-97][i] = count[key]

for i, item in enumerate(c_count):
    print(chr(i + 97) * min(item), end="")
print("")

Measured memory_bytes: 3316