akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,W; cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];

    vector<ll> dp(n_max, INF);
    dp[0] = 0;
    rep(i,n){
        rrep(j, n_max){
            if(j >= v[i])chmin(dp[j], dp[j - v[i]] + w[i]);
        }
    }

    ll ans = 0;
    rep(i,n_max){
        if(dp[i] <= W)chmax(ans, i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    priority_queue<pair<ll, ll>> prQ;  // (カードの数, カードの枚数)
    rep(i, n) {
        ll a;
        cin >> a;
        prQ.push(make_pair(a, 1));
    }

    rep(i, m) {
        ll b, c;
        cin >> b >> c;
        prQ.push(make_pair(c, b));
    }

    ll ans = 0;
    rep(i, n) {
        auto u = prQ.top();
        prQ.pop();
        ans += u.first;
        u.second--;
        if(u.second > 0) {
            prQ.push(u);
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 6384
int main() {
  int a[101][101] = {0};
  int b[101] = {0};
  int d[101] = {0};
  int i,j,r,c;
  int x;
  int e = 0;

  scanf("%d %d" , &r,&c);

  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      scanf("%d",&x);
      a[j][i] = x;
    }
  }

  for(j=0; j<r; j++){
    for(i=0; i<c; i++) {
      b[i] += a[j][i];
    }
  }

  for(j=0; j<r; j++){
    for(i=0; i<c; i++){
      d[j] += a[j][i];
    }
  }

  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      printf("%d ",a[j][i]);
    }
    printf("%d\n", d[j]);
  }
  for(i =0; i<c; i++) {
    printf("%d " ,b[i]);
    e += b[i];
  }
  printf("%d\n", e);

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >>a;
  int tmp,tmp1,cnt,ans1;
  int ans=0;
  for(int i=1;i<a+1;i++){
    tmp=i;
    cnt=0;
    while(tmp%2==0){
    tmp1=tmp;
    tmp=tmp/2;
    cnt++;
  }
    if(cnt>ans){
      ans=cnt;
      ans1=i;
    }
  }
  if(a==1)
    ans1=1;
  cout<<ans1<<endl;
}


Measured memory_bytes: 256
S=input()

if(S=="SUN"):
    print(7)
elif(S=="MON"):
    print(6)
elif(S=="TUE"):
    print(5)
elif(S=="WED"):
    print(4)
elif(S=="THU"):
    print(3)
elif(S=="FRI"):
    print(2)
else:
    print(1)

    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n][20]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<20;j++){
            if(a[i]%2)b[i][j]++;
            a[i]/=2;
        }
    }
    int x[20]={};
    int r=-1;
    long long ans=0;
    bool over;
    for(int l=0;l<n;l++){
        over=0;
        for(int i=0;i<20;i++)if(x[i]>1)over=1;
        while(r<n && over==0){
            r++;
            for(int i=0;i<20;i++)x[i]+=b[r][i];
            for(int i=0;i<20;i++)if(x[i]>1)over=1;
        }
        ans+=r-l;
        for(int i=0;i<20;i++)x[i]-=b[l][i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16640
n = int(input())
flg = 0
arr = []*n
arr.append(input())
for i in range(n-1):
  tmp = input()
  if arr[-1][-1] != tmp[0]:
    flg = 1
  if tmp in arr:
    flg = 1
  arr.append(tmp)
if flg == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 100005



// Driver code to tes above functions
int32_t main()
{
    
 
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    
    int a, b, x;
    cin >> a >> b >> x;

    double k;

    if(x*2>(a*a*b))
    {
        k = 2*(a*a*b - x);
        k = k/(a*a*a*1.0);
        double ans = atan(k)*180 / (3.141592654);
        cout << setprecision(10) << ans;
    }
    else
    {
        k = 2*x*1.0;
        k = k/(a*b*b*1.0);
        double ans = atan(k)*180 / (3.141592654);
        cout << setprecision(10) << 90 - ans;
    }

    return 0;
    
} 

Measured memory_bytes: 256
S = input()
Q = int(input())
Switch = False
Query = []

import collections
dq = collections.deque(S)

for i in range(Q):
    s = input()
    if s[0] == '1':
        if Switch:
            Switch = False
        else:
            Switch = True
    if s[0] == '2':
        if s[2] == '1' and Switch==False:
            dq.appendleft(s[4])
#             S = s[4]+S
        elif s[2]=='1' and Switch==True:
            dq.append(s[4])
#             S = S+s[4]
        elif s[2] == '2' and Switch==False:
            dq.append(s[4])
#             S = S+s[4]
        else:
#             S = s[4]+S
            dq.appendleft(s[4])

if Switch == False:
    print(''.join(dq))
else:
    print(''.join(dq)[::-1])

Measured memory_bytes: 8564
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_parityll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}
 
#define N 200005
 
ll fact[N];
ll ifact[N];
 
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll ans = fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

int main()
{
   FAST/**/
   
   fact[0] = 1;
   for(ll i=1;i<N;i++)
        fact[i] = fact[i-1]*i, fact[i]%=mod;
   for(ll i=0;i<N;i++)
        ifact[i] = powa(fact[i],mod-2,mod);
   
   ll n,k;
   cin>>n>>k;
   ll ans = 0;
   ll p2 = powa(2,mod-2,mod);
   for(ll i=k;i<=n+1;i++)
   {
       ll last = ((n-i+1+n)*(i))%mod;
       last = (last*p2)%mod;
       //cout<<last<<" ";
       ll fst = (i*(i-1))/2;fst%=mod;
       //cout<<fst<<"\n";
       last = (last-fst+mod+1)%mod;
       //cout<<last<<"\n";
       ans = (ans+last)%mod;
   }
   
   cout<<ans;
   
   return 0;        
}  
   

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i);
        a.at(i)--;
    }

    vector<vector<int>> db(n, vector<int>(64));
    for (int i=0; i<n; ++i) db.at(i).at(0) = a.at(i);
    for (int i=1; i<64; ++i) {
        for (int j=0; j<n; ++j) {
            db.at(j).at(i) = db.at(db.at(j).at(i-1)).at(i-1);
        }
    }

    int cur = 0;
    for (int i=0; i<64; ++i) {
        if (k & (1LL<<i)) {
            cur = db.at(cur).at(i);
        }
    }

    cout << cur + 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 61808
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

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


Measured memory_bytes: 5128
n=int(input())
dp=[10**18]*(n+1)
dp[n]=0
for i in range(5,0,-1):
    for j in range(n,0,-1):
        if j-9**i>=0:
            dp[j-9**i]=min(dp[j-9**i],dp[j]+1)

for i in range(6,-1,-1):
    for j in range(n,0,-1):
        if j-6**i>=0:
            dp[j-6**i]=min(dp[j-6**i],dp[j]+1)
pass
print(dp[0])

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

main()
{
    ll x;
    cin>>x;
    for(ll i=-120;i<=120;i++){
        for(ll j=-120;j<120;j++)
            if(i*i*i*i*i-j*j*j*j*j==x)
        {cout<<i<<" "<<j;return 0;}
    }
    return 0;
}


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

int main(){
    int a,b;
    cin >>a>>b;
    int ma=max(a,b);
    int mi=min(a,b);
    for(int i=0;i<ma;i++){
        cout << mi;
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define SQUARES_SIZE 4
int main(void)
{
    char str[SQUARES_SIZE];
    int  count;
  
    fgets(str, sizeof(str), stdin);

    for (int i = 0; i < SQUARES_SIZE; i++)
    {
        if(*(str + i) == '1')
          count++;
    }    
    printf("%d", count);
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      //500円玉の枚数
      int a = sc.nextInt();
      //100円だまの枚数
      int b = sc.nextInt();
      //50円玉の枚数
      int c = sc.nextInt();
      //合計金額
      int x = sc.nextInt();
      //カウンター
      int counter = 0;
      for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
          for(int k = 0; k <= c ;k++){
            int total = 500 * i + 100 * j + 50 * k;
            if(total == x){
            	counter++;
            }
          }
        }
      }
      System.out.print(counter);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

#define MOD 1000000007

char s[10005];int n,d;
int dp[10005][105][2];

int f(int k, int t, int e){
	int& r=dp[k][t][e];
	if(r>=0)return r;
	if(k==n)return r=t==0;
	r=0;
	fore(i,0,10){
		if(e&&i>s[k])break;
		r+=f(k+1,(t+i)%d,e&&i==s[k]);
		if(r>=MOD)r-=MOD;
	}
	return r;
}

int main(){
	scanf("%s%d",s,&d);n=strlen(s);
	fore(i,0,n)s[i]-='0';
	mset(dp,-1);
	printf("%d\n",(f(0,0,1)+MOD-1)%MOD);
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const int MOD = 1000000007;
// const ll INF = 1LL << 60;

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;}

int main()
{
    int N,T;
    cin >> N >> T;
    int t[N];
    ll time = 0;
    for(int i = 0; i < N; i++) cin >> t[i];
    for(int i = 1; i < N; i++)
    {
        if(t[i] - t[i - 1] < T) time += t[i] - t[i - 1];
        else time += T;
    }
    cout << time + T << endl;
} 

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int maxN=55555;
int n;
bool p[60000];

void init()
{
    for (int i=2; i<=maxN; ++i)
        if (p[i]==0)
            for (int j=2; i*j<=maxN; ++j)
                p[i*j]=1;
}


int main()
{
    cin>>n;
    init();
    for (int i=2; i<=maxN; ++i)
        if (p[i]==0 && (i%5==1))
        {
            cout<<i<<' ';
            n--;
            if (n==0) break;
        }
    return 0;
}


Measured memory_bytes: 256
#include <complex>
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
typedef complex<double> xy_t;
double size(xy_t a, xy_t b, xy_t c);

/*
int main(){
  xy_t P(-2, 1), Q;
  cout << P << endl;
  cout << P.real() << endl;
  cout << P.imag() << endl;
  Q = P + xy_t(5, -2);
  //Q *= xy_t(cos(a). sin(a));
  cout << abs(P) << endl;
  cout << norm(P) << endl;
}
*/

xy_t P[110];
int main(){
  int N=0;
  double x,y;
  while (~scanf("%lf,%lf", &x, &y)){
    P[N++] = xy_t(x,y);
  }
  double sum = 0.0;
  for (int i=0; i+2<N; ++i){
    xy_t a=P[0], b=P[(i+1)%N], c=P[(i+2)%N];
    sum += size(a, b, c);
  }
  printf("%.6f\n", sum);
}

double size(xy_t a, xy_t b, xy_t c){
  double l1,l2,l3;
  l1 = abs(a-b);
  l2 = abs(b-c);
  l3 = abs(c-a);
  double z = (l1+l2+l3)/2;
  double s = sqrt(z*(z-l1)*(z-l2)*(z-l3));
  return s;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;
	int ans=n;
	n=n-(n/k)*k;
	ans=min(ans,n);
	n=(abs(n-k));
	ans=min(n,ans);
	cout<<ans;
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

Measured memory_bytes: 256
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int x,n,i;
    cin >> x >> n;
    vector<int>a(n);
    for(i = 0;i < n;++i)
        cin >> a[i];
    sort(all(a));
    int minn = INT_MAX;
    i = 1;
    if(!binary_search(all(a),x))
        {
            cout << x;// - i;
            return 0;
        }
    while(1)
    {
        if(!binary_search(all(a),x - i))
        {
            
            cout << x - i;
            return 0;
        }
      if(!binary_search(all(a),x + i))
        {
            cout << x + i;
            return 0;
        }
        ++i;
    }
    
//     for(i = 0;i < n;++i)
//      {
//          int diff = abs(x - a[i]);
//          minn = min(minn,diff);
//      }
     
//     for(i = 0;i <= minn;++i)
//     {
        
//     }
//   // cout << "hcbs";
//     cout << x + minn + 1;
   
}



Measured memory_bytes: 3660
import qualified Data.IntMap as M

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  getLine
  as <- readInts
  putStrLn $ unwords $ map show $ solve as

solve :: [Int] -> [Int]
solve as = go M.empty $ zip [1..] as
  where
    go mp []           = M.elems mp
    go mp ((i, a):ias) = go (M.insert a i mp) ias

Measured memory_bytes: 39676
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    // Initialize variables and read input.
    int N, M;
    cin >> N >> M;
    VEC(int) switches(M, 0);
    VEC(int) P(M);

    FOR(i, 0, M) {
        int k, t;
        cin >> k;
        FOR(j, 0, k) {
            cin >> t;
            switches[i] |= 1 << (t - 1);
        }
    }
    READVEC(P);

    // Compute.
    VEC(int) bitcount(1 << 10);
    FOR(i, 1, 1 << 10)
        bitcount[i] = bitcount[i / 2] + i % 2;

    int ret = 0;
    FOR(i, 0, 1 << N) {
        int on = 0;
        FOR(j, 0, M)
            if (bitcount[i & switches[j]] % 2 == P[j])
                on++;
        if (on == M)
            ret++;
    }

    // Display output.
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
#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()
{
  string s; cin >> s;
  int n = s.size();
  bool first_win = false;
  if (n % 2 == 0) { first_win = (s[0] == s[n - 1]); }
  else { first_win = (s[0] != s[n - 1]); }

  printf("%s\n", first_win ? "First" : "Second");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
struct edge{
  int to,weight;
};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VV<edge> tree(n);
  REP(i,n-1){
    int u,v,w;
    cin >> u >> v >> w;
    u--,v--;
    tree[u].push_back({v,w});
    tree[v].push_back({u,w});
  }
  queue<pii> q;
  q.push({0,0});
  vb used(n,false);
  vb ans(n);
  while(!q.empty()){
    auto p = q.front();
    q.pop();
    if(used[p.fi]) continue;
    used[p.fi] = true;
    ans[p.fi] = p.se%2;
    REP(i,tree[p.fi].size()){
      if(!used[tree[p.fi][i].to]) q.push({tree[p.fi][i].to,p.se+tree[p.fi][i].weight});
    }
  }
  for(auto i:ans) cout << i << endl;
}


Measured memory_bytes: 6528
#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<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}


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;//n乗を効率的に求める
    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;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int k;
    cin >> k;
   string a;
  cin >> a;
    int s=a.size();
    combination c(k+s);
    mint ans=1;
    mint res=0;
    mint ji=1;
    rep(i,k) ans*=25;
    //cout << ans.x << endl;
    rep(i,k+1) {
        res+=ans*c(k+s-i-1,s-1)*ji;
        ji*=26;
        ans/=25;
        //cout << res.x << endl;
    }
    cout << res.x << endl;
    


    return 0;
}


Measured memory_bytes: 35564
import itertools
N = int(input())
nm = []
for i in range(N):
    S = input()
    nm.append(S[0])
tm = [nm.count(i) for i in str('MARCH')]
f = [(n == 0) for n in tm]
ans = 0
for i,j,k in itertools.combinations(range(5), 3):
    ans += tm[i]*tm[j]*tm[k] 
print(ans)


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

bool f(int x) { return x%2==1; }

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  for (int i=1; i<=3; i++) {
    if (f(a*b*i)) out("Yes");
  }
  out("No");

  return 0;
}


Measured memory_bytes: 256
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int INF = 1e9 + 90;

int bfs(vector<string> &ara, int r, int c,pii start)
{

  queue<pii> Q;
  Q.push(start);
  vector<vector<int>> dist(r, vector<int>(c , -1));
  dist[start.first][start.second] = 0;
  while (!Q.empty())
  {
    pii now = Q.front();
    Q.pop();
    int curr = dist[now.first][now.second];
    int x = now.first, y = now.second;
    // left
    if (x > 0 && ara[x-1][y] != '#' && dist[x-1][y] == -1){
      pii nw = {x - 1, y};
      Q.push(nw);
      dist[x - 1][y] = curr + 1;
    }
    // up
    if (y > 0 && ara[x][y-1] != '#' && dist[x][y-1] == -1)
    {
      pii nw = {x, y-1};
      Q.push(nw);
      dist[x][y-1] = curr + 1;
    }
    // right
    if (x + 1 < r && ara[x + 1][y] != '#' && dist[x + 1][y] == -1)
    {
      pii nw = {x + 1, y};
      Q.push(nw);
      dist[x + 1][y] = curr + 1;
    }
    // down

    if (y + 1 < c && ara[x][y+1] != '#' && dist[x][y+1] == -1)
    {
      pii nw = {x, y+1};
      Q.push(nw);
      dist[x][y+1] = curr + 1;
    }
  }
  int mx = 0;
  for (int i = 0; i < r ; i++){
    for (int j = 0; j < c ; j++){
      mx = max(mx, dist[i][j]);
    }
  }
  return mx;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int r, c;
  cin >> r >> c;
  vector<string> ara(r);
  for(auto &x : ara)
    cin >> x;
  int mx = 0;
  for (int i = 0; i < r; i++){
    for (int j = 0; j < c; j++){
      if(ara[i][j] == '#')
        continue;
      pii x = {i, j};
      mx = max(mx, bfs(ara, r, c,x));
    }
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    string s;
    cin>>s;
    bool a=false,b=false,c=false,d=false;
    for(int i=0;i<s.length();i++){
        if(s[i]=='N') a=true;
        else if(s[i]=='S') b=true;
        else if(s[i]=='E') c=true;
        else d=true;
    }
    if(a==b && c==d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtC154
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            long N = long.Parse(NK[0]);
            long K = long.Parse(NK[1]);

            long[] p = new long[N];
            string[] pstr = Console.ReadLine().Split(' ');
            long[] Ruisekiwa = new long[N];
            for (long i = 0; i < N; i++)
            {
                p[i] = long.Parse(pstr[i]);
                if(i > 0)Ruisekiwa[i] = Ruisekiwa[i - 1] + p[i];
                else if(i==0) Ruisekiwa[i] = p[i];
            }

            double max = Ruisekiwa[K-1];
            for(long i = 0; i < N-K; i++)
            {
                max = Math.Max(max, Ruisekiwa[i + K] - Ruisekiwa[i]);
            }
            //for (long i = 0; i < N; i++) Console.WriteLine($"i{i}  ExpValue{ExpValue[i]} ");
            double ans = max / 2 + (0.5) * K;
            Console.WriteLine($"{ans:F12}");
        }
    }
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int N , K;
  cin >> N >> K;
  if((N+1)/2 < K){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, k;
    cin >> n >> k;
    if (k % 2 == 1) {
        ll x = n/k;
        cout << x*x*x << endl;
    } else {
        ll x = n/k;
        ll y = (n + k/2) / k;
        cout << x*x*x + y*y*y << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
s = input()

# r_num = [0 for i in range(n)]
# g_num = [0 for i in range(n)]
# b_num = [0 for i in range(n)]

nums = [[0 for i in range(n)] for j in range(3)]

ans = 0

befs = [0 for i in range(3)]
for i in range(n):
    if s[i] == "R":
        befs[0] += 1
    elif s[i] == "G":
        befs[1] += 1
    else:
        befs[2] += 1
    for j in range(3):
        nums[j][i] = befs[j]

vac = [[-1,2,1],
       [2,-1,0],
       [1,0,-1]]
tr = {"R":0,"G":1,"B":2}

for i in range(n):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            continue
        else:
            v1 = tr[s[i]]
            v2 = tr[s[j]]
            nex = vac[v1][v2]
            # print(nex)
            tp = nums[nex][-1]-nums[nex][j+1]
            if tr[s[j+1]] == nex:
                tp += 1
            if j+j-i <= n-1 and tr[s[j+j-i]] == nex:
                tp -= 1
            ans += tp

print(ans)


Measured memory_bytes: 69048
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
   ll n,d,i;
   cin>>n>>d;
   ll x[n],y[n];
   rep(i,n)
   cin>>x[i]>>y[i];
   ll count=0;
   rep(i,n)
   {
     if(x[i]*x[i]+y[i]*y[i]<=d*d)
        count++;
   }
   cout<<count<<endl;


    return 0;
}

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

int main()
{
  int n;
  int kazu=0,sum=0;
  int max,min;

  while(1)
    {
      cin >> n;

      if(n == 0)break;

      sum = 0;

      for(int i = 0;i < n;i++)
	{
	  cin >> kazu;
	  sum += kazu;

	  if(i == 0)
	    {
	      max = kazu;
	      min = kazu;
	    }

	  if(max < kazu) max = kazu;

	  if(kazu < min) min = kazu;
	}
      sum = sum - max - min;

      cout << sum/(n-2) << endl;
    }
}



Measured memory_bytes: 3080
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

struct UnionFind {
  vector<int> uni;
  explicit UnionFind(int n): uni(n+5, -1) {};
  int root(int x) { return (uni[x] < 0) ? x : uni[x] = root(uni[x]); }
  int size(int x) { return -uni[root(x)]; }
  i64 unite(int x, int y) {
    const i64 p = size(x),  q = size(y);
    x = root(x); y = root(y);
    if (x == y) return 0;
    uni[x] += uni[y];
    uni[y] = x;
    return p*q;
  }
};

int N, M;
list<pii> edges;

signed main()
{
  iostreamBooster();

  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int a, b; cin >> a >> b; --a, --b;
    edges.emplace_front(a, b);
  }

  i64 ans = (i64)N * (N-1) / 2;
  UnionFind uf(N);
  list<i64> buf;

  for (const auto &e : edges) {
    buf.emplace_front(ans);
    ans -= uf.unite(e.first, e.second);
  }

  for (const auto &e : buf) cout << e << '\n';

  return 0;
}



Measured memory_bytes: 7936
# coding: utf-8
# Your code here!
k, s = map(int, input().rstrip().split())
result = 0
for x in range(k+1):
    if 2*k >= s - x:
        for y in range(k+1):
            if s - x - y >= 0 and s - x - y <= k:
                result += 1

print(result)

Measured memory_bytes: 41068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a[100010];
int main() {
    cin >> n >> m;
    ll lcm = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] /= 2;
        ll gcd = __gcd(a[i], lcm);
        lcm *= a[i] / gcd;
    }
    bool f = 1;
    for (int i = 0; i < n; i++) {
        if (lcm / a[i] % 2 == 0) {
            f = 0;
            break;
        }
    }
    if (!f) {
        cout << 0 << endl;
        return 0;
    }
    ll k = m / lcm;
    cout << (k + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 1024
extern crate core;

use std::fmt;
use std::i32::{MAX};
use std::cmp::{Ordering, min, max };
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::{Display, Formatter, Error};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_lines{
    ($count: expr; $delimiter: expr; $ty: ty) => {{
        let line_count = $count;
        let mut vec: Vec<Vec<$ty>> = Vec::with_capacity(line_count);
        for _ in 0 .. line_count {
            vec.push(read_line!($delimiter; $ty));
        }
        vec
    }};
    ($count: expr; $ty: ty) => {{
        let line_count = $count;
        let mut vec: Vec<$ty> = Vec::with_capacity(line_count);
        for _ in 0 .. line_count {
            vec.push(read_value!());
        }
        vec
    }}
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn main() {
    let mut count = vec![vec![0; 1 << 15]; 4];
    for n in 1 .. 1 << 8 {
        if n * n >= 1 << 15 {break;}
        count[0][n * n] = 1;
        for c in 0 .. 3 {
            for i in 0 .. (1 << 15) - n * n {
                count[c + 1][i + n * n] += count[c][i];
            }
        }
    }
    loop {
        let_all!(n: usize); if n == 0{break;}
        let mut result = 0;
        for i in 0 .. 4 {
            result += count[i][n];
        }
        println!("{}", result);
    }
}



Measured memory_bytes: 5040
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

int main () {
	stack<int> s;
	int n;
	while(cin >> n){
		if(n == 0){
			cout << s.top() << endl;
			s.pop();
		}else{
			s.push(n);
		}
	}
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
typedef long long ll;
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e5+10;
int a[maxn],idx[maxn],idx_cnt,sum[maxn],ans=0;
int Begin[maxn],Next[maxn*30],to[maxn*30],e,vis[maxn];
inline void add_edge(int x,int y){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
}
void dfs(int x){
	int tot=0;
	vis[x]=1;
	for(int i=Begin[x];i;i=Next[i]) if(!vis[to[i]]){
		dfs(to[i]);
		tot+=sum[to[i]];
	}
	chkmin(tot,sum[x]);
	sum[x]-=tot,ans+=tot;

}
int main(){
	int n=read();
	REP(i,1,n){
		a[i]=read();
		idx[++idx_cnt]=a[i];
	}
	sort(idx+1,idx+idx_cnt+1);
	idx_cnt=unique(idx+1,idx+idx_cnt+1)-idx-1;
	REP(i,1,n) sum[lower_bound(idx+1,idx+idx_cnt+1,a[i])-idx]++;
	REP(i,1,idx_cnt) REP(j,0,30) if(i<=(1<<j)){
		int u=(1<<j)-idx[i];
		u=lower_bound(idx+1,idx+idx_cnt+1,u)-idx;
		if(idx[u]==(1<<j)-idx[i]) add_edge(i,u);
	}
	REP(i,1,idx_cnt) if(!vis[i]) dfs(i);
	REP(x,1,idx_cnt) REP(i,0,30) if(idx[x]==(1<<i)) ans+=sum[x]/2,sum[x]%=2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9600
<?php
fscanf(STDIN,"%d %d",$N,$K);
$V = fgets(STDIN);
$arrayV = explode(" ",$V);
$max = 0;
$minusCounterL = 0;
$minusCounterR = 0;
$arrayL = array();
$arrayR = array();

//必ず1つは取り出すのでKが1の時は最大値が0より小さい可能性があるため別処理
if($K === 1){
  echo max($arrayV[0],$arrayV[$N-1]);
}else{
  //左から取り出す数、回数制限･配列の要素数を超えない
  for($i=0; $i<=$K && $i<=$N; $i++){
    if($i !== 0){
      $arrayL[] = $arrayV[$i-1];
      if($arrayV[$i-1] < 0){
        $minusCounterL++;
      }
      //最大を求めるので取り出すのが0以下で止まることはない
      if($arrayV[$i-1] <= 0){
        continue;
      }
    }
    $arrayR = array();
    $minusCounterR = 0;
    //右から取り出す数、合計が回数制限･配列の要素数を超えない
    for($j=0; $j<=$K-$i && $j<=$N-$i; $j++){
      if($j !== 0){
        $arrayR[] = $arrayV[$N-$j];
        if($arrayV[$N-$j] < 0){
          $minusCounterR++;
        }
        //最大を求めるので取り出すのが0以下で止まることはない
        if($arrayV[$N-$j] <= 0){
          continue;
        }
      }
      $arrayResult = array_merge($arrayL,$arrayR);
      //削除する数･合計が回数制限を越えない、左右取出数より少ない、負数の数を超えず削除
      for($m=1; $m<=$K-$i-$j && $m<$i+$j && $m<=$minusCounterL+$minusCounterR; $m++){
        $mins = array_keys($arrayResult, min($arrayResult));
        unset($arrayResult[$mins[0]]);
      }
      //最大値更新
      $value = array_sum($arrayResult);
      if($value > $max){
        $max = $value;
      }
    }
  }
  echo $max;
}


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M;
    vector<ll> vec(4);
    REP(i, 3) {
        cin >> N >> M;
        N--; M--;
        vec[N]++; vec[M]++;
    }
    ll one = 0;
    ll two = 0;
    REP(i, 4) {
        if (vec[i] == 1) one++;
        else if (vec[i] == 2) two++;
    }
    if (one == 2 && two == 2) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

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




int main() {
	
	ll N, K;
	cin >> N >> K;

	ll A[MAX];
	repn(i, N) cin >> A[i];

	ll B[MAX];

	B[0] = 0;

	repn(i, N) {
		B[i] = (B[i - 1] + A[i] - 1) % K;
	}

	map<ll,ll> cnt;

	ll ans = 0;

	rep(i, N+1) {

		if (i >= K) { cnt[B[i - K]]--; }
		ans += cnt[B[i]];
		cnt[B[i]]++;
		
	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 19968
#include<stdio.h>
#define MAX 100000

int partition(int, int);
int A[MAX];

int main(){
  int n,i,r,k;

  scanf("%d",&n);

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

  k = partition(0,n-1);

  for(i = 0 ; i < n ; i++){
    if(i > 0) printf(" ");
    if(i == k) printf("[");
    printf("%d",A[i]);
    if(i == k) printf("]");
  }
  printf("\n");

  return 0;
}


int partition(int p, int r){
  int x,y,i,j;
  x = A[r];
  i = p - 1;
  for(j = p ; j < r ; j++){
    if(A[j] <= x){
      i++;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }
   y = A[i+1];
   A[i+1] = A[r];
   A[r] = y;

  return i+1;
}



Measured memory_bytes: 2124
from collections import defaultdict

H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]

d1 = defaultdict(int)
d2 = defaultdict(int)

b = defaultdict(int)

for h, w in hw:
    d1[h] += 1
    d2[w] += 1
    b[(h, w)] = 1

m1 = max(d1.values())
m2 = max(d2.values())

e1 = [k for k in d1.keys() if d1[k] == m1]
e2 = [k for k in d2.keys() if d2[k] == m2]

flag = True

for x in e1:
    for y in e2:
        if b[(x, y)] == 1:
            pass
        else:
            flag = False
            break
    if not flag:
        break

if flag:
    print(m1+m2-1)
else:
    print(m1+m2)

Measured memory_bytes: 118316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void printV(std::vector<int> const &input){for (int i = 0; i < input.size(); i++)std::cout << input.at(i) << ' ';}

signed main(void){
    int R;
    cin >> R;
    long double temp=2*R*M_PI;
    cout.precision(32);
    cout << temp << endl;
    return 0;
}

Measured memory_bytes: 3788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var plan = new List<int[]>();
            plan.Add(new int[] { 0, 0, 0 });
            var ans = "No";

            for(int i = 0; i < n; i++)
            {
                var txy = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var dt = txy[0]-plan[i][0];
                var dx = Math.Abs(plan[i][1] - txy[1]);
                var dy = Math.Abs(plan[i][2] - txy[2]);
                if (dt < dx + dy)
                {
                    Console.WriteLine("No");
                    return;
                }
                else
                {
                    if ((dt - dx - dy) % 2 == 1)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }

                plan.Add(txy);
            }

            Console.WriteLine("Yes");

            


            
        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 23484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  ll mod = pow(10,9) + 7;
  ll n,k;
  cin >> n >> k;
  ll res = 0;
  for(int i = k;i <= n + 1;i++){
    res += (n - (i - 1)) * i + 1;
    res %= mod;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3636