akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n, a, b;
  cin >> n >> a >> b;
  vector<long long> v(n);
  for(int i = 0; i < n ; i++) cin >> v[i];

  long long ok = 1e9, ng = 0;
  while(abs(ok - ng) > 1){
    long long mid = floor((ok+ng)/2);
    long long cnt = 0;
    for(int i = 0; i < n ; i++){
      long long t = v[i] - mid * b;
      if(t > 0) cnt += (t+a-b-1)/(a-b);
    }
    if(cnt <= mid) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1024
a, b = map(int, input().split())
l = [i for i in range(1, 1000)]
L = []
for i in range(999):
    L.append(sum(l[:i+1]))


for i in range(998):
    if (L[i] - a) == (L[i+1] - b):
        print(L[i]- a)

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

int main() {
  int n;
  cin >> n;
  vector<long long> x45, y45;
  for ( int i = 0; i < n; i++ ) {
    long long x, y;
    cin >> x >> y;
    x45.push_back(x+y);
    y45.push_back(x-y);
  }
  
  sort(x45.begin(), x45.end());
  sort(y45.begin(), y45.end());
  
  cout << max(x45[n-1]-x45[0], y45[n-1]-y45[0]) << endl;
  return 0;
}


Measured memory_bytes: 6636
import collections

N = int(input())
a = list(map(int, input().split()))
a_s = collections.Counter(a) 
A = a_s.most_common()
count = 0

for i in range(len(A)):
    if int(A[i][1]) >= int(A[i][0]):
        count += int(A[i][1]) - int(A[i][0])
    else:
        count += int(A[i][1])

print(count)

Measured memory_bytes: 21232
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

ll fact(int n) {
	ll ans = 1;
	for (int i = 2; i <= n; i++) {
		ans *= i;
	}
	return ans;
}

int main() {
	string s;
	cin >> s;
	vector<int> freq(256, 0);
	for(int i = 0; i < s.size(); i++) {
		freq[s[i]]++;
	}
	bool hasOdd = false;
	int num = 0;
	for(int i = 'a'; i <= 'z'; i++) {
		if(freq[i] % 2 == 1) {
			if (hasOdd) {
				cout << 0 << endl;
				return 0;
			}
			hasOdd = true;
			freq[i]--;
		}
		num += freq[i] / 2;
	}
//	cout << num<<endl;
	ll ans = fact(num);
	for(int i = 'a'; i <= 'z'; i++) {
		if (freq[i] > 1) {
//			cout << "freq" << i << ":" << freq[i]<<","<<ans<<endl;
			ans /= fact(freq[i] / 2);
		}
	}
	cout << ans << endl;
	
	
}

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

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

  int n; cin >> n;
  vector<int> v(n, 0);
  for (int i = 0; i < n-1; i++)
  {
    int m; cin >> m;
    v.at(m-1)++;
  }
  for (int i = 0; i < v.size(); i++)
  {
    cout << v.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

int main(void)
{
  char s[200020];
  char t[200020];
  int i,ans = 0;
  scanf("%s",s);
  scanf("%s",t);
  for(i=0; s[i] != '\0'; i++)
  {
    if(s[i] != t[i]) ans++;
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b;
  c = a * b;
  if (c % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (ll i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

ll H,W,n;
set<pl> board;
set<pl> setik[10];

ll check(ll x, ll y){
    // cout << "Checking first time "<< x << " " <<y <<"\n" ;
    ll ans = 0;
    if(x+2 >= H || y+2 >= W || x < 0 || y < 0)
        return -1;
    rp(i,3) rp(j,3){
        // dump(x+i);
        // dump(y+j);
        // dump(ans);
        if(board.find(mp(x+i,y+j)) != board.end()){
            ans++;
        }
    }
    return ans;
}

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

    cin >> H >> W >> n;
    ll a[n],b[n];
    rp(i,n) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        board.insert(mp(a[i],b[i]));
    }
    ll x[3] = {0ll,1ll,2ll};
    rp(i,n) {
        rp(j,3) rp(z,3){
            ll bN = check(a[i]-x[j],b[i]-x[z]);
            if(bN != -1 && bN != 0)
                setik[bN].insert(mp(a[i]-x[j],b[i]-x[z]));
        }
    }
    ll tSum = 0;
    rep(i,1,10){
        tSum += setik[i].size();
    }
    cout << (W-2)*(H-2) - tSum << "\n";
    rep(i,1,10){
        cout << setik[i].size()<<"\n";
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 64384
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

input = gets
index = input.to_i - 1

p nums[index]

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

int main(){
    int n; cin>>n;
    int m = n;
    int s = 0;
    while(n!=0){
        s += n%10;
        n /= 10;
    }
    if(m%s==0) cout << "Yes" <<endl;
    else cout << "No" << endl;
}


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

int main() {
  for(int N; cin >> N, N; ) {
    int ans = 0;
    for(int i = 0; 4*(i*i) <= N; ++i) {
      for(int j = i; (i*i) + 3*(j*j) <= N; ++j) {
        for(int k = j; (i*i) + (j*j) + 2*(k*k) <= N; ++k) {
          int l = N - i*i - j*j - k*k;
          if(floor(sqrt(l)) == ceil(sqrt(l))) ++ans;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std; 
 
typedef long long ll;
 
int main()  {  
    int n = 0;
    ll ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 and i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3220
package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()

	line := s.Text()
	fields := strings.Fields(line)
	x, _ := strconv.Atoi(fields[1])

	s.Scan()
	line = s.Text()
	fields = strings.Fields(line)

	var childs []int
	for _, f := range fields {
		i, _ := strconv.Atoi(f)
		childs = append(childs, i)
	}
	sort.Ints(childs)

	max := len(childs) - 1
	remain := x
	given := 0
	for i, child := range childs {
		if i == max {
			if remain == child {
				given++
			}
			break
		}
		remain = remain - child
		if remain >= 0 {
			given++
		}
		if remain <= 0 {
			break
		}
	}
	fmt.Println(given)
}


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

using namespace std;

int main(){
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    int cnt[100000];
    int cnt_ = 0;
    cnt[0] = 0;
    for(int i = 1; i < S.size(); i++){
        if(S[i] == 'C' && S[i-1] == 'A') cnt_++;
        cnt[i] = cnt_;
    }
    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        cout << cnt[r-1] - cnt[l-1] << endl;
    }
}

Measured memory_bytes: 1408
n = int(input())
h = list(map(int, input().split())) 

ans = 0

for i in range(max(h)):
    if h[0] == 0:
        zeroFlag = True
        for j in range(0, n):
            if h[j] == 0:
                zeroFlag = True
            if h[j] != 0 and zeroFlag == True:
                ans += 1
                zeroFlag = False
            if h[j] > 0:
                h[j] -= 1
    else:
        numFlag = True
        for j in range(0, n):
            if h[j] == 0:
                numFlag = True
            if h[j] != 0 and numFlag == True:
                ans += 1
                numFlag = False
            if h[j] > 0:
                h[j] -= 1

print(ans)

Measured memory_bytes: 9084
n, s0, s1, g0, g1 = gets.split.map(&:to_i)
s = gets.chomp

s[s1-1] = 'f'
#s[g1-1] = 'g'
#p [s[s0,g0-s0],s[s1,g1-s1]]
if s[s0,g0-s0].index("##") || s[s1,g1-s1].index("##")
  
  puts "No"
  exit
end

f = s[s1-2, g1-s1+3]
#p f#
if g0 > g1 && !( f.index("...") || f.index(".f.") || f.index("f..")  )
  puts "No"
  exit
end

puts "Yes"



Measured memory_bytes: 2556
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)3e5 + 777;
ll a[MAXN], pref[MAXN], suff[MAXN];
int n;

void solve() {
	cin >> n;
	n *= 3;

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

	multiset<ll> setik;
	for(int i = 1; i <= n; ++i) {
		pref[i] = pref[i - 1];
		pref[i] += a[i - 1];
		setik.insert(a[i - 1]);

		if(len(setik) > n / 3) {
			auto iter = setik.begin();
			pref[i] -= *iter;
			setik.erase(iter);
		}

		DBG(pref[i]);
	}

	setik.clear();
	for(int i = 1; i <= n; ++i) {
		suff[i] = suff[i - 1];
		suff[i] -= a[n - i];
		setik.insert(-a[n - i]);

		if(len(setik) > n / 3) {
			auto iter = setik.begin();
			suff[i] -= *iter;
			setik.erase(iter);
		}

		DBG(suff[i]);
	}

	ll answ = -LL_INF;

	for(int i = n / 3; i <= 2 * (n / 3); ++i) {
		answ = max(answ, pref[i] + suff[n - i]);
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const ll INF = ll(1e14);
ll a, b, n;

ll f(ll x) {
  ll res = (a * x / b) - a * (x / b);
  return res;
}

int main() {
  // a * x が bを超えない最大のx
  cin >> a >> b >> n;
  ll maxv = n + 1;
  ll l = -1, r = maxv;
  while (l + 1 < r) {
    ll x = (l + r) / 2;
    // cout << x << endl;

    if(x >=  b) r = x;
    else l = x; 
  }
  ll ans = f(l);
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
    char b;
    scanf("%c",&b);
    if (b == 'A'){
        printf("T");
        
    }
    else if(b == 'T'){
        printf("A");
    }
    else if(b == 'G'){
        printf("C");
    }
    else{
        printf("G");
    }
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#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++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll n,k;
vector<ll> vec(100000);

ll merge(ll st,ll en){

  if(en - st == 1){
    return 0;
  }
  ll mid = (st + en) / 2;
  ll t1 = merge(st,mid);
  ll t2 = merge(mid,en);
  ll piv = st;
  ll sum = 0;
  ull len1 = mid- st;
  ull len2 = en - mid;
  vector<ll> vec1(len1),vec2(len2);
  rep(i,len1){
    vec1[i] = vec[i+st];
  }
  rep(i,len2){
    vec2[i] = vec[i+mid];
  }
  ll x = 0;
  ll y = 0;

  while(x != len1 && y != len2){
    if(vec1[x] < vec2[y]){
      vec[piv] = vec1[x];
      x++;
    }else{
      vec[piv] = vec2[y];
      sum += len1  - x;
      y++;
    }
    piv++;
  }
  while(x != len1){
    vec[piv] = vec1[x];
    x++;
    piv++;
  }
  while(y != len2){
    vec[piv] = vec2[y];
    sum += len1 - x;
    y++;
    piv++;
  }
//  rep(i,n){
//    cout << vec[i] << " ";
//  }
//  cout << endl;

  return t1 + t2 + sum;
}

int main(){
  cin >> n;
  vec.resize(n);
  rep(i,n){
    cin >> vec[i];
  }
  cout << merge(0,n) << endl;
}


Measured memory_bytes: 5828
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int x, y;
    cin >> x >> y;

    auto passed = 0;
    for (auto kame = 0; kame <= x; ++kame) {
        auto legs = kame * 4 + (x - kame) * 2;
        if (legs == y) {
            ++passed;
        }
    }

    cout << (passed ? "Yes" : "No") << endl;
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false); 
            cin.tie(NULL);
    // cout<<"bie"<<endl;
    LL N;
    cin>>N;
    if(N>=400 and N<=599)
    cout<<8;
    if(N>=600 and N<=799)
    cout<<7;
    if(N>=800 and N<=999)
    cout<<6;
    if(N>=1000 and N<=1199)
    cout<<5;
    if(N>=1200 and N<=1399)
    cout<<4;
    if(N>=1400 and N<=1599)
    cout<<3;
    if(N>=1600 and N<=1799)
    cout<<2; 
    if(N>=1800 and N<=1999)
    cout<<1;
}



Measured memory_bytes: 3648
#include<stdio.h>

int main(){
		int n,a,b,i,j;
		long long v[50];
		scanf("%d%d%d",&n,&a,&b);
		for(i=0;i<n;i++)scanf("%lld",&v[i]);
		for(i=0;i<n;i++){
				for(j=0;j<n;j++){
						if(v[i]>v[j]){
								long long tmp=v[i];
								v[i]=v[j];
								v[j]=tmp;
						}
				}
		}
		long long ans=0;
		for(i=0;i<a;i++)ans+=v[i];
		long long ai=v[a-1];
		int num=0,anum=0,bnum=0;
		for(i=0;i<n;i++){
				if(ai==v[i]&&i<a)anum++;
				if(ai==v[i]&&i<b)bnum++;
				if(ai==v[i])num++;
		}
		long long ncm[101][101]={0};
		long long anss=0;
		ncm[0][0]=1;
		for(i=1;i<101;i++){
				for(j=0;j<101;j++){
						if(j==0)ncm[i][j]=1;
						else ncm[i][j]=ncm[i-1][j]+ncm[i-1][j-1];
				}
		}
		if(v[0]==ai){
				for(i=anum;i<=bnum;i++)anss+=ncm[num][i];
		}else anss=ncm[num][anum];
		if(ans%a==0)printf("%lld\n%lld\n",ans/a,anss);
		else printf("%.9f\n%lld\n",ans/(float)a,anss);
		return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;
typedef long long ll;

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

template <typename T> void read(T &x) {
  x = 0;
  char c = getchar();
  T sig = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      sig = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  x *= sig;
}

ll dp[3005][3005][4];

class Solution {
public:
  void solve() {
    int R, C, K;
    read(R), read(C), read(K);
    vector<vector<int>> a(R + 1, vector<int>(C + 1));
    memset(dp, 0, sizeof(0));
    for (int i = 0; i < K; ++i) {
      int r, c, v;
      read(r), read(c), read(v);
      a[r][c] = v;
    }
    for (int i = 1; i <= R; ++i)
      for (int j = 1; j <= C; ++j) {
        for (int k = 0; k <= 3; ++k)
          dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
        for (int k = 0; k <= 3; ++k)
          dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
        if (a[i][j])
          for (int k = 3; k > 0; --k)
            dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + a[i][j]);
      }
    ll ans = 0;
    for (int i = 0; i <= 3; ++i)
      ans = max(ans, dp[R][C][i]);
    printf("%lld", ans);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution solution = Solution();
  solution.solve();
}

Measured memory_bytes: 320392
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>


using namespace std;



int main(){
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    
    string cand[4] = {"maerd", "remaerd", "esare", "resare"};
    
    string temp;
    int flag = 0;
    string ans;
    
    for(int i = 0; i < S.size(); ++i){
        temp.push_back(S[i]);
//        cout << temp << " ";
        for(int j = 0; j < 4; ++j){
            if(temp == cand[j]){
                flag = 1;
                temp = "";
                break;
            } else {
            }
        }
//        if(flag == 0){
//            ans = "NO";
//            break;
//        } else {
//            flag = 0;
//        }
        
        if(i == S.size() - 1){
            if(temp == ""){
                ans = "YES";
                break;
            } else {
                ans = "NO";
                break;
            }
            
        }
    }
    
    
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define M_PI 3.14159265358979
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


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

	if (S[S.size() - 1] == 's') {
		S.append("es");
	}
	else {
		S.append("s");
	}

	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3596
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        String s = nln();
        int c = 0;
        for(int i = 0; i < 3; i++){
            if(s.charAt(i) == 'A')
                c++;
        }
        if(c == 3 || c == 0)
            pn("No");
        else
            pn("Yes");
    }
   
    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        //t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }
 
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////
 
    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}


Measured memory_bytes: 21076
calc_list = list()

while True:
    calc = {}
    base = input("")
    term = base.split(' ')
    a = int(term[0])
    op = term[1]
    b = int(term[2])
    if(op == '?'):
        break
    calc = {'a':a, 'op':op, 'b':b}
    calc_list.append(calc)

for ca in calc_list:
    if(ca['op'] == '+'):
        print("{}".format(ca['a'] + ca['b']))
    elif(ca['op'] == '-'):
        print("{}".format(ca['a'] - ca['b']))
    elif(ca['op'] == '*'):
        print("{}".format(ca['a'] * ca['b']))
    elif(ca['op'] == '/'):
        print("{}".format(ca['a'] // ca['b']))



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

int main()
{
  int a[] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};

  int x, y;
  cin >> x >> y;

  if(a[x] == a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cerr<<v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    string S, T;
    cin >> S >> T;
    S += T.back();

    cout << (S==T ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define RREP(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define ALL(vector) vector.begin(), vector.end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    ll ans = 0;
    REP(n,N+1){
        if(n==0) continue;
        ll end = N / n;
        ans += n * end * (end + 1) / 2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define MAX 100000
typedef struct{
  char name[10];
  int time;
} process;

void enqueue(process);
process dequeue(void);

process q[MAX];
int head,tail;


int main(){
  int i,j,t,ct=0;
  process p[MAX],r;
  scanf("%d%d",&i,&t);
  for(j=0;j<i;j++){
    scanf("%s%d",p[j].name,&p[j].time);
    enqueue(p[j]);
  }
  while(head!=tail){
    r=dequeue();
    if(r.time>t){
      r.time -=t;
      enqueue(r);
      ct+=t;
    }
    else if(r.time<=t){
      ct+=r.time;
      printf("%s %d\n",r.name,ct);
    }
}
return 0;
}

void enqueue(process x){
  q[tail]=x;
  tail=(tail+1)%MAX;
}

process dequeue(void){
  process x;
  x=q[head];
  head=(head+1)%MAX;

  return x;
}



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


int main() {
    double A , B , H , M;
    cin >> A >> B >> H >> M;
    double rad = 0;

    double ans;

    double min = H * 60 + M;

    double pi = 3.14159265358979;

    double l = 6 * min;
    double s =0.5 * min;

    double x;

    for(int i=0 ; i<50;i++){
        if(l>=360) l-= 360;
        else break;
    }

    if(l>=s){
        rad = l-s;
    }
    else{
        rad = s-l;
    }

    if(rad > 180){
        rad = 360 - rad;
    }

    x = rad / 180 * pi;

    ans = sqrt(A*A + B*B -2*A*B*cos(x));

    cout << fixed << setprecision(12);

    cout << ans << endl;

}

Measured memory_bytes: 4144
#include <stdio.h>
#include <stdlib.h>
 
int binsearch(int S[], int n, int key)
{
    int left = 0;
    int right = n;
    int mid;
     
    while (left <= right) {
        mid = (left + right)/2;
        if (S[mid] == key) 
            return 1;
        else if (S[mid] < key)
            left = mid + 1;
        else
            right = mid - 1;
    }
    return 0;
}
 
int main()
{
    int n, q;
    int *S, T;
    int i, j = 0;
    int *A;
     
    scanf("%d", &n);
    S = (int*)malloc(sizeof(int) * n);
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
     
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &T);
        if (binsearch(S, n, T)) {
            j++;
        }
    }
     
    printf("%d\n", j);
     
    return 0;
}

Measured memory_bytes: 992
#include<bits/stdc++.h>
#define endl  "\n"
#define ll long long
#define PI acos(-1.0)
#define test cout<<"\n****\n"
#define precise fixed(cout);cout<<setprecision(12)
#define fast  ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using  namespace  std;


int main(){

    string str;
    cin>>str;

    if(str[2]==str[3] && str[4]==str[5]){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<pair<int,int>>A(N);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[i]={a,i};
  }
  sort(A.rbegin(),A.rend());
  vector<vector<long>>dp(2020,vector<long>(2020,-(1L<<60)));
  dp.at(0).at(0)=0;
  for(int i=0;i<N;i++){// i:詰める個数-1
    long k=A[i].first;// 活発度
    long r=A[i].second;// 移動前の位置
    for(int x=0;x<=i;x++){// x:確定している左に詰める個数、かつ左に移動後の位置
      long y=i-x;// y:確定している右に詰める個数
      long z=N-1-y;// z:右に移動後の位置
      dp[x+1][y]=max(dp[x+1][y],dp[x][y]+abs(r-x)*k);
      dp[x][y+1]=max(dp[x][y+1],dp[x][y]+abs(r-z)*k);
      // cout<<"(x,y)="<<"("<<x<<","<<y<<")"<<endl;
      // cout<<"dp[x][y]:"<<dp[x][y]<<endl;
      // cout<<"dp[x+1][y]:"<<dp[x+1][y]<<endl;
      // cout<<"dp[x][y+1]:"<<dp[x][y+1]<<endl;
    }
  }
  long ans=-(1L<<60);
  for(int i=0;i<=N;i++)ans=max(ans,dp[i][N-i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 35212
#include <stdio.h>
#include <algorithm>
#define R register
#define MN 2005
int n,m,ans=1;int st[MN][MN],stk[MN],tp;char s[MN];
bool b[MN][MN],a[MN][MN];
int main(){
	scanf("%d%d",&n,&m);
	for (R int i=1; i<=n; ++i){
		scanf("%s",s+1);
		for (R int j=1; j<=m; ++j)
			a[i][j]=s[j]=='.';
	}ans=std::max(n,m);
	for (R int i=1; i<n; ++i)
		for (R int j=1; j<m; ++j)
			if (1^a[i][j]^a[i][j+1]^a[i+1][j]^a[i+1][j+1])
				b[i][j]=1;
	for (R int i=1; i<n; ++i)
		for (R int j=1; j<m; ++j)
			st[i][j]=b[i][j]?st[i-1][j]+1:0;
	for (R int i=1; i<n; ++i){
		tp=0;for (R int j=1; j<=m; ++j){
			while(tp&&st[i][stk[tp]]>=st[i][j]){
				ans=std::max(ans,(j-stk[tp-1])*(st[i][stk[tp]]+1));
				--tp;
			}stk[++tp]=j;
		}
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 23680
#include <cstdio>

int main(){
	int n, ac, bc;
	while(scanf("%d", &n), n != 0){
		ac = bc = 0;
		for(int i = 0;i < n;i++){
		int a, b;
		scanf("%d%d", &a, &b);
			if(a > b)ac += a + b;
			else if(a == b)ac += a, bc += b;
			else bc += a + b;
		}
		printf("%d %d\n", ac, bc);
	}
	return 0;
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


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

        string s;
        cin>>s;
        s[0] = s[0] + 1;
        cout<<s[0]<<"\n";
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define MOD 1e9+7
#define fastio ios_base::sync_with_stdio(0),cin.tie(0)
#define debug(x) cout << x << endl

int main(){
	int a,b;
	cin >> a >> b;
	int ans=0;
	ans=a;
	if (b<a){
		ans--;
	}
	cout << ans << endl;
	return 0;
}

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

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

int main(){
  int n,k;
  cin >> n >> k;
  if(n<k)cout << "1" << endl;
  else if(n%k != 0)cout << "1" << endl;
  else cout << "0" << endl;
}


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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
    if ( l >= r ) return;
     int root = pre[pos++];
    
     int m = distance(in.begin(), 
     find(in.begin(), 
     in.end(),
     root));
    
    
     
     rec(l, m);
     rec(m + 1, r);
     post.push_back(root);
}

void s() {
     pos = 0;
     rec(0, pre.size());
    
     for ( int i = 0; i < n; i++ ) {
        if ( i ) cout << " ";
         cout << post[i];
         }
    
     cout << endl;
}



int main(){
    int k; 
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> k;
        pre.push_back(k);
    }
    
    for ( int i = 0; i < n; i++ ) {
        cin >> k;
        in.push_back(k);
}
    
    s();
    return 0;
}




Measured memory_bytes: 3128
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;

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

  int a[N];
  double b[N];
  for (i = 0; i < N; i++){
    cin >> a[i];
  }

  double ans = 0;
  for (i = 0; i < N; i++){
    ans += (1.0 / a[i]);
  }

  ans = 1.0 / ans;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <map>

using namespace std;
// typedef unsigned long long ull;

int main(int argc, char const *argv[]) {
    map<char, string> S;
    cin >> S['a'] >> S['b'] >> S['c'];

    char turn = 'a';
    while (true) {
        if (S[turn].length() == 0) {
            break;
        }
        char next_turn = S[turn][0];
        S[turn] = S[turn].substr(1);
        turn = next_turn;
    }
    std::cout << (char)(turn - 32) << std::endl;

    return 0;
}


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


signed main() {
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  
  vector<bool> kaburi(N, true);
  for( int i = K; i < N; i++ ){
    if( T.at(i) == T.at(i-K) && kaburi.at(i-K) == true ){
      kaburi.at(i) = false;
    }
  }
  
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( kaburi.at(i) == true ){
      if( T.at(i) == 'r' ) ans += P;
      else if( T.at(i) == 's' ) ans += R;
      else if( T.at(i) == 'p' ) ans += S;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

// const long long MOD = 998244353;
unsigned long long MOD = 998244353;

// long long modpow(long long a, long long n, long long mod) {
//     long long res = 1;
//     while (n > 0) {
//         if (n & 1) res = (res%mod) * (a % mod);
//         a = (a%mod) * (a%mod) % mod;
//         n >>= 1;
//     }
//     return res;
// }

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

void solve(long long N, std::vector<long long> D){
    // SORT(D);
    vector<unsigned long long> v(N+10,0);
    ll maxnum=0;
    for (ll i = 0; i < N; i++) {
        v[D[i]]++;
        maxnum = max(maxnum,D[i]);
    }
    // vout(v);
    unsigned long long ret = 1;
    for (ll i = 0; i < maxnum; i++) {
        // ret *= pow(v[i],v[i+1]);
        // ret = (ret * modpow(v[i],v[i+1],MOD))%MOD;
        ret = (( ret%MOD ) * ( mod_pow(v[i],v[i+1],MOD)%MOD ))%MOD;
        ret %= MOD;
        // debg(ret);
    }
    if(D[0]!=0 || v[0]!=1){
        cout << 0 << "\n";
    }else{
        cout << ret%MOD << "\n";
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 1792
#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;
    vector<int> x(N), y(N), order;
    int cnt = 0;
    rep(i,N) cin >> x.at(i) >> y.at(i);
    rep(i,N) order.push_back(i);
    long double sum = 0;
    do {
        rep(j,N-1) {
            long double diffx = x.at(order.at(j+1)) - x.at(order.at(j));
            long double diffy = y.at(order.at(j+1)) - y.at(order.at(j));
            sum += sqrt(diffx*diffx + diffy*diffy);
        }
        ++cnt;
    } while (next_permutation(order.begin(), order.end()));
    sum /= cnt;
    cout << fixed << setprecision(8) << sum << endl;
}



Measured memory_bytes: 3844
#include <iostream>

int main()
{
	int A = 0, B = 0, ans = 0;

	std::cin >> A >> B;

	if (A >= 13){
		ans = B;
	}
	else if (A >= 6){
		ans = B / 2;
	}
	else{
		ans = 0;
	}

	std::cout << ans << std::endl;

	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    if(n==3||n==5||n==7){
        cout << "YES"<< "\n";
    }else cout << "NO" <<"\n";

    return 0;
}

Measured memory_bytes: 256
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys,heapq,math
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    n,k=mdata()
    l=[0]*n
    for i in range(k):
        d=int(data())
        s=mdata()
        for j in s:
            l[j-1]+=1
    cnt=0
    for i in l:
        if i==0:
            cnt+=1
    print(cnt)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int H, W, N; scanf("%d %d %d", &H, &W, &N);
  int a, b;
  map<pair<int, int>, int> S;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &a, &b);
    for (int dr = -2; dr <= 0; ++dr) {
      for (int dc = -2; dc <= 0; ++dc) {
        int nr = a + dr, nc = b + dc;
        if (1 <= nr and nr + 2 <= H and 1 <= nc and nc + 2 <= W) {
          ++S[{ nr, nc }];
        }
      }
    }
  }
  vector<ll> ans(10, 0);
  ans[0] = 1LL * (H - 2) * (W - 2);
  for (pair<pair<int, int>, int> p : S) {
    ++ans[p.second];
    --ans[0];
  }
  for (int i = 0; i < 10; ++i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 56448
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
int main(){
  ll j,i,n,a;
  vector<ll> b(65,0),c(65,0);
  const ll mod=1000000007;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a;
    for(j=0;j<=61;j++){
      ll v=pow(2,j);
      if(v&a){
        b[j]++;
      }
      else{
        c[j]++;
      }
    }
  }
  ll ans=0;
  for(i=0;i<=62;i++){
    ll v=pow(2,i);
    v=v%mod;
    b[i]=b[i]%mod,c[i]=c[i]%mod;
    ans+=v%mod*b[i]%mod*c[i]%mod;
  }
  ans=ans%mod;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 4128
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int[] n = new int[2];
			@SuppressWarnings("unchecked")
			MultiSet<Integer>[] set = new MultiSet[2];
			for(int i=0; i<2; i++){
				n[i] = in.nextInt();
				set[i] = new MultiSet<Integer>();
			}
			if(n[0] == 0 && n[1] == 0) break;
			for(int i=0; i<2; i++){
				int[] w = new int[n[i]];
				for(int j=0; j<n[i]; j++){
					w[j] = in.nextInt();
				}
				for(int j=0; j<n[i]; j++){
					int sum = 0;
					for(int k=j; k<n[i]; k++){
						sum += w[k];
						set[i].add(sum);
					}
				}
			}
			long res = 0;
			for(int i: set[0].set.keySet()){
				if(set[1].set.containsKey(i)){
					res += set[0].get(i)*set[1].get(i);
				}
			}
			System.out.println(res);
		}
	}
}

class MultiSet<T>{
	HashMap<T, Integer> set;
	public MultiSet(){
		set = new HashMap<T, Integer>();
	}
	
	public void add(T val){
		if(set.containsKey(val)){
			set.put(val, set.get(val)+1);
		}else{
			set.put(val, 1);
		}
	}
	
	public int get(T val){
		if(set.containsKey(val)) return set.get(val);
		return 0;
	}
}

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

int main() {
  string s; cin >> s;
  
  int a = 0;
  while(s.at(a) != 'A') a++;
  int z = s.size() - 1;
  while(s.at(z) != 'Z') z--;
  cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
using namespace std;
const int MAX=100002;
int main(){
	IOS;
	long long n,a,b,sum=0;
	cin>>n>>a>>b;
	if(a!=b)
	{
		long long ma=max(a,b);
		long long mi=min(a,b);
		if((ma-mi)%2==0)
		{
			sum=(ma-mi)/2;
		}else
		{
			if(n-mi>=ma-1)//左走 
			{
				sum=mi-1+(ma-mi)/2;
				if((ma-mi)%2!=0)
				sum++;
			}else
			{
				sum=n-ma+(ma-mi)/2;
				if((ma-mi)%2!=0)
				sum++;
			}	
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    int cnt = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) {
                    continue;
                }
                if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) {
                    ++cnt;
                }
            }
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3580
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(max(A+B,A-B,A*B));

    }
    private static int max(int a,int b,int c){
        if(a>=b&&a>=c){
            return a;
        }else if(b>=c){
            return b;
        }else return c;
    }
}



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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n' //toggle off for interactive problems
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 2e3+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int s;
int dp[N];
// dp[i]: number of way to change i $ 
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> s;
	dp[0] = 1;
	for(int i=3; i<=s; i++) {
		for(int j=3; j<=i; j++){
			dp[i] += dp[i-j];
			dp[i] %= MOD;
		}
	}
	int ans = dp[s];
	cout << ans << endl;
	
	return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = L_INF;

    for (ll d = 0; d <= 300000; d++) {
        ll t = A * max(X - d / 2, 0LL) + B * max(Y - d / 2, 0LL) + C * d;
        ans = min(ans, t);
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
while True:
    h, w = map(int, raw_input().split())

    if h == 0 and w == 0:
        break
    
    hcnt = 1
    for i in range(0, h):
        wid = ""
        if hcnt == 1 or hcnt == h:
            for j in range(0, w):
                wid += "#"
            print wid
        else:
            wid += "#"
            for j in range(1, w-1):
                wid += "."
            wid += "#"
            print wid
        hcnt += 1
    print ""

Measured memory_bytes: 4212
#include <iostream>
#include <string>
#include <vector>
#include <map>

std::map<std::vector<int>, int> cache;

int query(const std::vector<int>& q) {
  if (cache.count(q)) return cache[q];
  std::cout << "?";
  for (size_t i = 0; i < q.size(); ++i) {
    if (q[i]) std::cout << " " << i + 1;
  }
  std::cout << std::endl;
  std::string res;
  std::cin >> res;
  return cache[q] = (res[0] == 'R');
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> q(n * 2);
  std::string s(n * 2, '?');
  for (int i = 0; i < n; ++i) q[i] = 1;
  auto first = query(q);
  int left = 1, right = n;
  while (left < right) {
    int mid = (left + right - 1) >> 1;
    q.assign(n * 2, 0);
    for (int i = 0; i < n; ++i) q[mid + i] = 1;
    auto res = query(q);
    if (res == first) left = mid + 1;
    else right = mid;
  }
  q.assign(n * 2, 0);
  for (int i = 0; i < n; ++i) q[left + i] = 1;
  int l = left - 1, r = l + n, last = first ^ 1;
  s[l] = "BR"[first];
  s[r] = "BR"[first ^ 1];
  for (int i = 0; i < n * 2; ++i) {
    if (i >= l && i <= r) continue;
    q[r] = 0; q[i] = 1;
    auto now = query(q);
    if (now == last) s[i] = s[r];
    else s[i] = 'B' + 'R' - s[r];
    q[r] = 1; q[i] = 0;
  }
  last ^= 1;
  for (int i = 0; i < n * 2; ++i) q[i] ^= 1;
  for (int i = l + 1; i < r; ++i) {
    q[i] = 1; q[l] = 0;
    auto now = query(q);
    if (now == last) s[i] = s[l];
    else s[i] = 'B' + 'R' - s[l];
    q[i] = 0; q[l] = 1;
  }
  std::cout << "! " << s << std::endl;
  return 0;
}


Measured memory_bytes: 852