akhauriyash/Code-Regression huggingface dataset:
def main():
    N, M = map(int, input().split())

    d = [-1] * (N + 1)
    for _ in range(M):
        s, c = map(int, input().split())
        if ~d[s] and d[s] != c:
            print(-1)
            return
        d[s] = c

    if N > 1 and d[1] == 0:
        print(-1)
        return

    if ~d[1]:
        ans = d[1]
    elif N == 1:
        ans = 0
    else:
        ans = 1

    for i in range(2, N + 1):
        ans *= 10
        if ~d[i]:
            ans += d[i]

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair<ll,int>
const int N=100;

struct Edge{
  int to,nxt,val;
}edge[3000000];
int head[N*N],tot;
void add(int u,int v,int w){
  edge[++tot]={v,head[u],w};
  head[u]=tot;
}

char s[N][25];
int l[N][25],r[N][25],c[N],id=0;
int len[N],n,st,ed;

bool check(int i,int l,int r){
  while(l<r){
    if(s[i][l]!=s[i][r])return 0;
    l++,r--;
  }
  return 1;
}

ll dis[N*N],inf=1e18;
void dijkstra(){
  for(int i=0;i<N*N;i++)dis[i]=inf;
  priority_queue<pli,vector<pli>,greater<pli>>pq;
  pq.push({0,st}),dis[st]=0;
  while(!pq.empty()){
    pli fir=pq.top();pq.pop();
    int u=fir.second;
    if(fir.first>dis[u])continue;
    for(register int i=head[u];i;i=edge[i].nxt){
      int v=edge[i].to;
      if(dis[v]>dis[u]+edge[i].val){
        dis[v]=dis[u]+edge[i].val;
        pq.push({dis[v],v});
      }
    }
  }
}
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%s%d",s[i]+1,&c[i]);
    len[i]=strlen(s[i]+1);
    for(int j=1;j<=len[i];j++)
      l[i][j]=++id,r[i][j]=++id;
  }
  st=++id,ed=++id;
  for(int i=1;i<=n;i++){
    add(st,l[i][1],c[i]);
    for(int j=1;j<=len[i];j++){
      if(check(i,j,len[i]))add(l[i][j],ed,0);
      for(int k=1;k<=n;k++){
        if(len[k]<len[i]-j+1){
          bool flag=1;
          int a=j,b=len[k];
          for(;b>=1;a++,b--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            } 
          if(flag)add(l[i][j],l[i][a],c[k]);
        }else{
          bool flag=1;
          int a=j,b=len[k];
          for(;a<=len[i];a++,b--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag){
            if(check(k,1,b))add(l[i][j],ed,c[k]);
            else add(l[i][j],r[k][b],c[k]);
          }
        }
      }
    }
  }
  for(int i=1;i<=n;i++){
    add(st,r[i][len[i]],c[i]);
    for(int j=1;j<=len[i];j++){
      if(check(i,1,j))add(r[i][j],ed,0);
      for(int k=1;k<=n;k++){
        if(len[k]<j){
          bool flag=1;
          int a=j,b=1;
          for(;b<=len[k];b++,a--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag)add(r[i][j],r[i][a],c[k]);
        }else{
          bool flag=1;
          int a=j,b=1;
          for(;a>=1;a--,b++)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag){
            if(check(k,b,len[k]))add(r[i][j],ed,c[k]);
            else add(r[i][j],l[k][b],c[k]);
          }
        }
      }
    }
  }
  dijkstra();
  if(dis[ed]>=inf)puts("-1");
  else printf("%lld\n",dis[ed]);
  return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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(){
  string s;
  cin >> s;
  ll k;
  cin >> k;

  vector<string> t;
  for(ll i = 1; i <= k; i++){
    for(ll j = 0; j < s.size()-i+1; j++){
      string b = s.substr(j, i);
      t.pb(b);
    }
  }
  sort(all(t));
  t.erase(unique(all(t)), t.end());
  cout << t[k-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
a,b,k=map(int,input().split())
l=[]
if k>(b-a)+1:
  k=(b-a)+1
for i in range(a,a+k):
  l.append(i)
for i in range(b-k+1,b+1):
  l.append(i)
ll=sorted(list(set(l)))
for i in ll:
  print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;



int32_t main() {
	int m, k;
	cin >> m >> k;
	if (k >= (1 << m)) {
		cout << -1 << endl;
		return 0;
	}
	if (m == 1) {
		if (k == 1) {
			cout << -1 << endl;
			return 0;
		}
		else {
			cout << "0 0 1 1" << endl;
			return 0;
		}
	}
	
	int n = (1<<m);
	
	vector<int> ans;
	for(int i = 0; i < n; i++)
		if(i != k)
			ans.pb(i);
	ans.pb(k);
	
	for(int i = n-1; i >= 0; i--)
		if(i != k)
			ans.pb(i);
			
	ans.pb(k);

	for(auto i : ans) cout << i << " ";
	cout << endl;
}


Measured memory_bytes: 4080
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  long long n;cin>>n;
  long long a[5];
  long long ans=0;
  long long i;
  for(i=0;i<5;i++){
    cin>>a[i];
  }
  sort(a,a+5);
  ans=n/a[0];
  if(n%a[0]!=0) ans++;
  ans+=4;

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
    if(x >= r && y >= r && y+r <= h && x+r <= w){
	   cout << "Yes" << "\n";
    }
    else {
       cout << "No" << "\n";
    }
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        String ans = "";

        if (n.charAt(0) == '1') {
            ans += "9";
        } else {
            ans += "1";
        }

        if (n.charAt(1) == '1') {
            ans += "9";
        } else {
            ans += "1";
        }

        if (n.charAt(2) == '1') {
            ans += "9";
        } else {
            ans += "1";
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
//char a[10001];
int main()
{
	int l,r,ans=0,count;
	//freopen("1.txt","r",stdin);
	cin>>count;
	//	count=i;
		while(count!=0)
		{
			if(count%10==9)ans++;
			count/=10;
		}
		//cout<<a[i]<<" "<<n<<endl;
	
	if(ans!=0)
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const int MAX_V=1e5+3;

struct edge{int to;LL cost;};
typedef pair<LL,int> P;//firstは最短距離,secondは頂点番号

int V;
vector<edge> G[MAX_V];
LL d[MAX_V];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    
    while(!que.empty()){
        P p=que.top();que.pop();//仮の最短距離が短い順に取り出す
        int v=p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));//仮の最短距離と頂点の組を更新が行われる度に追加していく
            }
        }
    }
}

int main(){
    int N,Q,K;
    cin>>N;V=N;
    REP(i,N-1){
        int a,b;
        LL c;
        cin>>a>>b>>c;a--;b--;
        G[a].PB(edge{b,c});
        G[b].PB(edge{a,c});
    }
    cin>>Q>>K;
    K--;
    dijkstra(K);
    REP(i,Q){
        int x,y;
        cin>>x>>y;x--;y--;
        cout<<d[x]+d[y]<<endl;
    }
    return 0;
}


Measured memory_bytes: 11120
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<ll> a(N);
  REP(i,N) cin >> a[i];

  REP(j,Q) {
    ll x; cin >> x;
    ll res = 0;
    int right = 0;
    ll sum = 0;
    REP(left,N) {
      while ( right < N && sum + a[right] <= x ) {
        sum += a[right];
        ++right;
      }
      res += right - left;
      if (right == left) ++right;
      else sum -= a[left];
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  REP(i, n) cin >> h[i];
  ll l = 0, r = 1e9;
  while(r-l>1){
    ll c = (l+r)/2;
    ll j = 0;
    REP(i, n){
      ll hp = h[i]-b*c;
      if(hp <= 0) continue;
      j += (hp+a-b-1)/(a-b);
    }
    if(j > c) l = c;
    else r = c;
  }
  cout << r << endl;
  return 0;
}

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

int main()
{
	string s,ans;
	int K;
	cin >> s>>K;
	vector<int> res(s.size(), 0);
	for (int i = 0; i < s.size(); ++i){
		res[i] = ('z' - s[i] + 1) % 26;
		if (K >= res[i]){
			K-= res[i];
			ans += 'a';
		}
		else{
			ans += s[i];
		}
	}
	if (K){
		ans[ans.size() - 1] += (K%26);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
    
	string S;
	cin>>S;
	
	set<char> s;
	for(int i=0;i<S.size();i++){
		s.insert(S[i]);
	}
	
	long long K;
	cin>>K;
	
	long long ans = 0;
	
	if(s.size()!=1){
		long long C = 0;
		for(int i=S.size()-1;i>=0;i--){
			if(S[i]==S[0]){
				C++;
				S.erase(S.begin()+i);
			}
			else{
				break;
			}
		}
		long long D = 0;
		while(true){
			if(S[0]!=S[1])break;
			D++;
			S.erase(S.begin()+1);
		}
		S.erase(S.begin());
		D++;
		
		for(int i=1;i<S.size();i++){
			if(S[i]==S[i-1]){
				ans++;
				S[i]='(';
			}
		}
		
		
		ans *= K;
		ans += C/2;
		ans += D/2;
		ans += ((C+D)/2)*(K-1);
		
		
	}
	else{
		ans = (K*S.size())/2;
	}
	
	cout<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
*a, = map(int, input().split())
b = [0]*(n//2) + a[n//2:]
for i in reversed(range(n//2)):
    b[i] = sum(b[(i+1)*(j+1)-1] for j in range(n//(i+1)))%2 ^ a[i]
print(sum(b))
print(*[i+1 for i in range(n) if b[i]==1])


Measured memory_bytes: 17852
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = L[:]
for i in range(N-1):
  D[i+1] += D[i]
cnt = 0
for i in range(N):
  if D[i] <= X:
    cnt += 1
  else:
    break

print(cnt+1)

Measured memory_bytes: 3060
n=int(input())
k=[]
for i in range(n):
    k.append(list(map(int,input().split())))
dp=[[0,0,0],k[0]]+[[0,0,0] for i in range(n-1)]
for i in range(2,n+1):
    dp[i]=[max(dp[i-1][1:])+k[i-1][0],max(dp[i-1][0],dp[i-1][2])+k[i-1][1],max(dp[i-1][:2])+k[i-1][2]]
print(max(dp[n]))

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 7 && b == 5 && c == 5) {
        cout << "YES";
    }
    else if (a == 5 && b == 7 && c == 5) {
        cout << "YES";
    }
    else if (a == 5 && b == 5 && c == 7) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
}


Measured memory_bytes: 3544
N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
#A.insert(0, 0)
ans = -1
push = 0

for i in range(N+1):

    if A[push] == 1:
        ans = i+1
        break
        
    else:
        push = A[push]
      
print(ans)


Measured memory_bytes: 13028
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a = inm()
x = inl()
d = [[[0]*(50*n+1) for i in range(n+1)] for j in range(n+1)]
d[0][0][0] = 1
for i in range(n):
    for j in range(n+1):
        for k in range(50*n+1):
            if d[i][j][k]>0:
                d[i+1][j][k] += d[i][j][k]
                if j<n:
                    d[i+1][j+1][k+x[i]] += d[i][j][k]
sm = 0
for j in range(1,n+1):
    sm += d[n][j][j*a]
print(sm)


Measured memory_bytes: 91740
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;

ll gcd(ll a, ll b) {
	ll temp;
	while (a % b != 0)
	{
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

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

	int h, w;
	cin >> h >> w;
	vvi a(h, vi(w, 0));
	vs ans;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	vvb f(h, vb(w, true));

	rep(i, h) {
		rep(j, w - 1) {
			if (a[i][j] % 2 != 0) {
				a[i][j]--;
				a[i][j + 1]++;
				string s = "";
				s += to_string(i+1) + ' ';
				s += to_string(j + 1) + ' ';
				s += to_string(i + 1) + ' ';
				s += to_string(j + 1 + 1);
				ans.push_back(s);
			}
		}
	}

	rep(i, h - 1) {
		if (a[i][w - 1] % 2 != 0) {
			a[i][w - 1]--;
			a[i + 1][w - 1]++;
			string s = "";
			s += to_string(i + 1) + ' ';
			s += to_string(w - 1 + 1) + ' ';
			s += to_string(i + 1 + 1) + ' ';
			s += to_string(w - 1 + 1);
			ans.push_back(s);
		}
	}

	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}

	return 0;
}



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

vector<int> graph[200010];
vector<int> ans;

void dfs(int v, int p=-1) {
    for(int u: graph[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, Q; cin >> N >> Q;
    int a, b;
    for(int i = 0; i < N-1; i++) {
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ans.resize(N);
    int q, x;
    for(int i = 0; i < Q; i++) {
        cin >> q >> x; q--;
        ans[q] += x;
    }
    dfs(0);
    for(int i = 0; i < N; i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 23552
import Control.Monad
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as V

main = do
  [_,q] <- map read.words<$>getLine
  s <- getLine
  lrs <- replicateM q $ map read.words<$>getLine
  mapM_ print $ solve s lrs

solve :: String -> [[Int]] -> [Int]
solve s = go
  where
  go [] = []
  go ([l,r]:lrs) = memo!r - memo!l : go lrs
  memo = V.fromList $ go 0 s
    where
    go n [] = [n]
    go n ('A':'C':s) = n:n:go (n+1) s
    go n (c:s) = n:go n s

Measured memory_bytes: 81660
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
string s;
long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int ans;
int main(){
	cin>>s;
	for(int i=0;i<sz(s)/2;i++){
		if(s[i]!=s[sz(s)-1-i])
		ans++;
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
import sys

def main():

	n = int(input())
	d = list(map(int, input().split()))
	S = 0
	for i in range(0, n):
		for j in range(i+1, n):
			S = S + d[i]*d[j]
			
	print(S)


if __name__ == "__main__":
	main()

Measured memory_bytes: 2940
N,M = map(int,input().split())
ks = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

ans = 0
for bit in range(1<<N):
    count = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            for a in range(M):
                if i+1 in ks[a][1:]:
                    count[a] +=1
    a = 0
    for i in range(M):
        if count[i] % 2 == p[i]:
            a += 1
            if a == M:
                ans += 1

print(ans)


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

int main(){

    while(1){
        int n; cin >> n;
        if(!n) break;
        double pw; cin >> pw;
        vector<double> vw(n);
        vector<double> pf(n);
        vector<double> vf(n);
        vector<double> th(n);
        for(int i = 0; i < n; i++){
            cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
        }

        double ans;
        double l = 0.0, r = 1000.0;

        for(int i = 0; i < 100; i++){

            double p1 = (r + 2*l) / 3;
            double p2 = (2*r + l) / 3;

            //cout << l << " " << r << " " << p1 << " " << p2 << endl;            

            double cost1 = (double)(p1 * pw);
            double cost2 = (double)(p2 * pw);
            
            for(int i = 0; i < n; i++){
                double F1 = (double)((th[i] - p1 * vw[i]) / vf[i]);
                double F2 = (double)((th[i] - p2 * vw[i]) / vf[i]);
                F1 = max(F1, 0.0);
                F2 = max(F2, 0.0);
                
                
                cost1 += (double)(F1 * pf[i]);
                cost2 += (double)(F2 * pf[i]);                                                
            }


            if(cost1 < cost2) r = p2;
            else l = p1;

            ans = cost1;
        }

        printf("%.4f\n", ans);
    }

    return 0;
}


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

int main() {
  ll N, K; cin>>N>>K;
  vector<double> win(N+1);
  double sum=0;
  for(ll i=1; i<=N; i++){
    ll X=i;
    ll count=0;
    while(X<K){
      count++;
      X*=2;
    }
    // cout<<count<<endl;
    win[i]=(pow(0.5, count))/N;
    sum+=win[i];
  } //i
  cout<<fixed<<setprecision(12)<<sum<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

ll dp[(1 << 16)];
ll score[(1 << 16)];

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

    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < (1 << n); ++i){
        // Least Significant Bit
        int LSB = i & -i;
        int subset = i ^ LSB;
        score[i] = score[subset];
        int LSB_digit = -1;
        for(int d = 0; d < n; ++d){
            if(LSB & (1 << d)){
                LSB_digit = d;
                break;
            }
        }
        if(LSB_digit == -1)  continue;
        for(int d = 0; d < n; ++d){
            if(subset & (1 << d)){
                score[i] = score[i] + a[d][LSB_digit];
            }
        }
    }

    for(int i = 0; i < (1 << n); ++i){
        int tmp = i;
        while(tmp){
            chmax(dp[i], score[tmp] + dp[i ^ tmp]);
            tmp = (tmp - 1) & i;
        }
    }

    cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1280
N = gets.to_i

require 'prime'

ans = 0
1.upto(N) do |n|
  next if n.even?
  divisors_count = n.prime_division.inject(1) { |sum, d| sum * (d[1] + 1) }
  ans += 1 if divisors_count == 8
end

puts ans


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


using namespace std;
using ll =long long;
using db = double;
//nCm 
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nCmここまで

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	cout <<setprecision(10);
	double n ;
	int  k; 	
	cin >> n >> k; 	
	vector<double> a(n);
	rep(i,n) cin >>a[i];
	
	double M = 0 ;
	double index = 0 ;
	//どこからk個が一番良いかを見る。
	double now = 0 ;
	rep(i,k){
		now  += a[i] ;
	}
	chmax(M,now);
	For(i,1,n-k+1){
		now -= a[i-1] ;
		now += a[i+k-1] ;
		if(chmax(M,now)) index = i ;
		chmax(M,now);
	}
	double ans = 0 ;
	rep(i,k){
		
		ans += ((db)(a[index] * (a[index] + 1)) / 2.) /(db)a[index]  ;
		index ++ ;
	}
	//k回計算
	cout <<ans << endl;
}


Measured memory_bytes: 1792
using System;
class _0047
{
    public static void Main()
    {
        string str;
        string[] data;
        bool[] cup = new bool[3];
        bool tmp;
        cup[0] = true;
        for (int i = 1; i < cup.Length; i++) cup[i] = false;
        while ((str = Console.ReadLine()) != null)
        {
            data = str.Split(',');
            tmp = cup[data[0][0] - 'A'];
            cup[data[0][0] - 'A'] = cup[data[1][0] - 'A'];
            cup[data[1][0] - 'A'] = tmp;
        }
        for (int i = 0; i < cup.Length; i++) if (cup[i]) Console.WriteLine((char)(i + 'A'));
    }
}

Measured memory_bytes: 5256
// AOJ 2874 Pigeonhole principle
// 2018.3.29 bal4u

#include <stdio.h>
#include <stdlib.h>

int a[1002];

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int N, N1, i, j;

	scanf("%d", &N), N1 = N-1;
	for (i = 0; i < N; i++) scanf("%d", a+i);
	qsort(a, N, sizeof(int), cmp);
	for (i = 0; i < N; i++) for (j = N-1; i < j; j--) {
		if ((a[i]-a[j]) % N1 == 0) goto done;
	}
done: printf("%d %d\n", a[i], a[j]);
	return 0;
}



Measured memory_bytes: 2104
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		String S = nextString();

		for(int i=0;i<S.length();i++){
			if(S.length()-S.replaceAll(String.valueOf(S.charAt(i)), "").length() !=1){
				System.out.println("no");
				return ;
			}
		}
		System.out.println("yes");
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main(){
    int N, M, X;
    cin >> N >> M >> X;

    int cost1 = 0;
    int cost2 = 0;

    for(int i=0;i<M;i++){
        int temp;
        cin >> temp;

        if(temp < X){
            cost1++;
        }
        else if(temp > X){
            cost2++;
        }
    }

    cout << min(cost1, cost2) << endl;
    return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m; cin >> n >> m;
	vector<int>c(m+1); rep(i, 1, m+1)cin >> c[i];
	vector<vector<int> >v(m+1, vector<int>(n + 1));
	sort(c.begin(), c.end());
	rep(i, 0, m + 1)v[i][0] = 0;
	rep(i, 0, n + 1)v[0][i] = INF;

	rep(i, 1, m+1) {
		rep(j, 1, n + 1) {
			if (j - c[i] < 0)v[i][j] = v[i-1][j];
			else v[i][j] = min(v[i-1][j], v[i][j - c[i]]+1);
		}
	}

	cout << v[m][n] << endl;
	return 0;
}

Measured memory_bytes: 7096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll=long long;
int main(){
  double a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans_t, ans_a;
  ans_t= (double)a/(double)d + 0.999999;
  ans_a= (double)c/(double)b + 0.999999;
  //cout << ans_t << ans_a << endl;
  if(ans_t >= ans_a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<long long int> v1(N),v2(N),v3(N),v4(N),v5(N),v6(N),v7(N),v8(N);
  for(int i=0;i<N;i++){
    long long int a,b,c;
    cin>>a>>b>>c;
    v1.at(i)=(a+b+c);
    v2.at(i)=(a+b-c);
    v3.at(i)=(a-b+c);
    v4.at(i)=(a-b-c);
    v5.at(i)=(-a+b+c);
    v6.at(i)=(-a+b-c);
    v7.at(i)=(-a-b+c);
    v8.at(i)=(-a-b-c);
  }
  
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  sort(v3.begin(),v3.end());
  sort(v4.begin(),v4.end());
  sort(v5.begin(),v5.end());
  sort(v6.begin(),v6.end());
  sort(v7.begin(),v7.end());
  sort(v8.begin(),v8.end());
  
  long long int t=0;
  long long int ans=0;
  for(int i=1;i<M+1;i++){
    t += v1.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v2.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v3.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v4.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v5.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v6.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v7.at(N-i);
  }
  ans = max(ans,t);
  t=0;
  for(int i=1;i<M+1;i++){
    t += v8.at(N-i);
  }
  ans = max(ans,t);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin>>s;
  for(int i=0;i<4;i++){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=4;i<12;i++){
    cout<<s[i];
  }
  cout<<endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;
class P
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        var m = a.Select((V, I) => new { V, I }).ToDictionary(x => x.V, x => x.I);

        Array.Sort(a);
        Console.WriteLine(a.Where((x, i) => i % 2 != m[x] % 2).Count() / 2);
    }
}


Measured memory_bytes: 22876
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector< int > a(N), b(N);

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

    int ans = 0;
    for (int i = 0; i < 29; i++) {
        vector< int > a_mod(N), b_mod(N);
        for (int j = 0; j < N; j++) {
            a_mod[j] = a[j] % (1 << (i + 1));
            b_mod[j] = b[j] % (1 << (i + 1));
        }

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

        int cnt = 0;
        for (int j = 0; j < N; j++) {
            int add = 0;
            if ((1 << i) - a_mod[j] >= 0) {
                add += lower_bound(b_mod.begin(), b_mod.end(),
                                   (1 << (i + 1)) - a_mod[j]) -
                       lower_bound(b_mod.begin(), b_mod.end(),
                                   (1 << i) - a_mod[j]);
            } else {
                add += lower_bound(b_mod.begin(), b_mod.end(),
                                   (1 << (i + 1)) - a_mod[j]) -
                       b_mod.begin();
                add += b_mod.end() -
                       lower_bound(b_mod.begin(), b_mod.end(),
                                   (1 << (i + 1)) + (1 << i) - a_mod[j]);
            }
            cnt += add;
        }

        if (cnt & 1) {
            ans += (1 << i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3432
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
ll dp[1000002];
int main(){
  string a;cin>>a;
  ll ans=0;
  rep(i,a.size()){
    ans+=a[i]-'0';
    ans%=9;
  }
  if(ans==0)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3744
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
        int sum = 0;
        int temp = 0;
        int cnt = 1;
        for (int i = 0; i < n; i++) {
			temp = sc.nextInt();
            sum += temp;
            if (sum > x){
            	break;
            }
            cnt += 1;
        }
		
		System.out.println(cnt);
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 10;
const int LOG = 61;
int par[LOG][N];

int main(){
  fastIO;
  int n;
  ll k;
  cin >> n >> k;
  for(int i = 1; i <= n; i ++ )
    cin >> par[0][i];
  for(int i = 1; i < LOG; i ++ ){
    for(int j = 1; j <= n; j ++ )
      par[i][j]=par[i-1][par[i-1][j]];
  }
  int r = 1;
  for(int i = 0 ; i < LOG; i ++ ){
    if((k & (1ll << i)))
      r = par[i][r];
  }
  cout << r << "\n";
  return 0;
}

Measured memory_bytes: 51320
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll H;
	scan(H);
	ll cnt=1;
	ll ans=0;
	while(H){
		H/=2;
		ans+=cnt;
		cnt*=2;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    ll H, W; cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        ll ans = (H*W+1) / 2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;


/**
 * Lesson4A　半径 r の円の面積と円周の長さを求めるプログラム
 * @author 前島佑介
 * @version 2014/12/1
 */
class Main {

	// プログラムのエントリポイント
	public static void main(String[] args) {

		//入力値
		double dbNum = 0;

		//面積
		double dbArea = 0.0;

		//円周
		double dbCircumference = 0.0;

		try{
			//キーボードからの入力準備
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			//キーボードからの入力をString型で受け取る
			String strLine = br.readLine();

			//入力値
			dbNum = Double.parseDouble(strLine);

			//面積は半径ｘ半径ｘPI
			dbArea = dbNum * dbNum * Math.PI;

			//円周は２ｘ半径ｘPI
			dbCircumference = 2.0 * dbNum * Math.PI;

			 //小数5桁まで
		    DecimalFormat insdf = new DecimalFormat("0.000000");

			//結果を出力 小数5桁まで表示
			System.out.println(insdf.format(dbArea) +  " " + insdf.format(dbCircumference));

			//例外処理
			}catch(IOException e) {

				//例外時の出力
				System.out.println(e);

			}catch(NumberFormatException e) {

				//数値以外の入力値で出力
				System.out.println("数値で入力して下さい");
			}
	}
}

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

int main() {
  int K, S;
  cin >> K >> S;
  ll cnt = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      if (S < x + y) {
        break;
      } else {
        int rem = S - x - y;
        if (rem <= K) {
          ++cnt;
        }
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c;
    
    if(a>b)
    {
        d=b;
        b=a;
        a=d;
    }
    if(b>c)
    {
        d=c;
        c=b;
        b=d;
    }
    if(a>b)
    {
        d=b;
        b=a;
        a=d;
    }
    cout << a << " " << b << " " << c << endl;
    
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,a,mod=1e9+7,pow2=1,ans = 0,num_of_pair; cin >> N;
  vector<ll> v(60);
  for (ll i = 0; i < N; ++i) {
    cin >> a;
    for (ll j = 0; j < 60; ++j) {
      v[j] += a>>j&1;
    }
  }
  for (ll i = 0; i < 60; ++i) {
    num_of_pair = v[i]*(N-v[i])%mod;
    ans = (ans + num_of_pair * pow2)%mod;
    pow2 = 2*pow2%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque


def matrix(n):
    for _ in range(n):
        adj = list(map(int, input().split()))
        i = adj[0]
        v = adj[2:]
        for j in v:
            mat[i - 1][j - 1] = 1


def bfs(v):
    d[v] = 1
    dist[v] = 0
    dq.append(v)
    while dq:
        v = dq.popleft()
        for n, i in enumerate(mat[v]):
            if i == 1 and not d[n]:
                d[n] = 1
                dist[n] = dist[v] + 1
                dq.append(n)

n = int(input())
mat = [[0] * n for _ in range(n)]
d, dist = [0] * n, [-1] * n
dq = deque()
matrix(n)
bfs(0)
for i, v in enumerate(dist):
    print(i + 1, v)

Measured memory_bytes: 8068
#include <algorithm>
#include <exception>
#include <ios>
#include <sstream>
#include <cctype>
#include <streambuf>
#include <string>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <cwchar>
#include <cwctype>
using namespace std;

int main(){
    int a,b,c,d,s=0;
    cin>>a>>b>>c>>d;
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++){
            for (int k=0;k<=c;k++){
                if (500*i+100*j+50*k==d){
                    s++;
                }
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]

count=0
success=True
while(success==True):
    for i in range(N):
        if A[i]%2==1:
            success=False
            break
        else:
            A[i]=int(A[i]/2)
    if success==False:
        break
    count+=1
print(count)


Measured memory_bytes: 3060
n, m, x = list(map(int, input().split()))
z = [list(map(int, input().split())) for _ in range(n)]
nux = 10**13
for i in range(2**n):
    alu = [-x]*m
    buy = []
    for j in range(n):
        if (i >> j) & 1:
            buy.append(j)
    num = 0
    if i == 30:
        s = 1
    for k in buy:
        num += z[k][0]
        for ss in range(m):
            alu[ss] += z[k][ss+1]
    if len([i for i in alu if i < 0]) == 0:
        nux = min(num, nux)
if nux == 10**13:
    print(-1)
else:
    print(nux)


Measured memory_bytes: 9232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    int n = Integer.parseInt(r.readLine());

    sl = r.readLine().split(" ");

    int a[] = new int[200006];

    StringBuilder sb = new StringBuilder();

    boolean f = false;

    int i = 0;

    for(i = n - 1; i >= 0; i -= 2)
    {
      sb.append(sl[i]);
      sb.append(" ");
    }

    if(i == -1)
    {
      i = 0;
    }
    else
    {
      i = 1;
    }

    for(; i < n; i += 2)
    {
      sb.append(sl[i]);
      sb.append(" ");
    }

    System.out.println(sb);

  }

}

Measured memory_bytes: 77784
def insertionSort(A, n, g):
	global cnt

	for i in range(g, n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j + g] = A[j]
			j = j - g
			cnt = cnt + 1
		A[j + g] = v

def shellSort(A, n):
	global m
	global G

	h = 1
	while (True):
		if h > n:
			break
		G.append(h)
		h = 3 * h + 1

	m = len(G)
	G.reverse()

	for i in range(m):
		insertionSort(A, n, G[i])

if __name__ == '__main__':
	N = int(input())
	R = [int(input()) for i in range(N)]

	cnt = 0
	G = []
	m = 0

	shellSort(R, N)

	print(m)
	print(" ".join(map(str, G)))
	print(cnt)
	for i in range(N):
		print(R[i])

Measured memory_bytes: 47492
#include<stdio.h>

int main()
{
    int A=0, B=0;
    
    scanf("%d", &A);
    scanf("%d", &B);

    if(A+B >= 10)
    {
        printf("error\n");
    }
    else
    {
        printf("%d\n", A+B);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#define int                  long long int
#define ff                   first
#define ss                   second
#define pb                   push_back
#define mp                   make_pair
#define pii                  pair<int,int>
#define vi                   vector<int>
#define mi                   map<int,int>
#define pqb                  priority_queue<int>
#define pqs                  priority_queue<int,vi,greater<int>>
#define setbits(x)           __builtin_popcountll(x)
#define zrobits(x)           __builtin_ctzll(x)
#define mod                  1000000007
#define inf                  1e18
#define precise(x,y)         fixed<<setprecision(y)<<x
#define w(x)                 int x;cin>>x;while(x--)
#define endl                 "\n"
#define no_of_digit(n)       floor(log10(n))+1
#define copyarr(a,b,n)       copy_n(a,n,b)
mt19937                      rng(chrono::steady_clock::now().time_since_epoch().count());

//*******************to check if all number in array are positive*******************
//all_of(arr,arr+n,[](int x){return x>0;})?cout<<"positive":cout<<"some negative";


//*******************to check if any element in array is negative*******************
//any_of(arr,arr+n,[](int x){return x<0;})?cout<<"Any negative":cout<<"All positive";


int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //*****************Enter the code here*******************//
    int l=INT_MIN,r=INT_MAX;
    int n,m;
    cin>>n>>m;
    while(m--)
    {
    	int a,b;
    	cin>>a>>b;
    	l=max(l,a);
    	r=min(r,b);
    }
    cout<<max(0,r-l+1)<<endl;
    return 0;
}


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

int main() {

    int N, X;
    cin >> N >> X;

    int sum = 0;
    int count = 1;
    vector<int> data(N);
    for (int i = 0; i < N;i++) {
        cin >> data.at(i);
    }
    for (int i = 0; i < N;i++) {
        sum = sum + data.at(i);
        if (X >= sum ) {
            count = count + 1;
        }
        else {
            break;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

    static int n;
    static int m;
    static int ans;
    static int[] rate;
    static int var;
    static int ansmin;
    static int ansmax;
    static int[] w;
    static int[] ww;
    static boolean[] visit;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        ansmin = 0;
        ansmax = 0;
        rate = new int[9];
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if (tmp >= 3200) {
                tmp = 3200;
            }
            rate[tmp/400]++;
        }
        for (int i = 0; i < 7; i++) {
            if (rate[i] != 0) {
                ansmin++;
                ansmax++;
            }
        }
        if (rate[7] == 0) {
            if (rate[8] != 0) {
                ansmin++;
                ansmax+=rate[8];
            }
        }else{
            ansmin++;
            ansmax++;
            if (rate[8] != 0) {
                ansmax+=(rate[8]);
            }
        }

        System.out.println(ansmin + " " + ansmax);

        sc.close();
    }

    public static void dfs(int placenow) {
        // if went all -> success! 
        // if not went all -> fail...
        
        /*
         dfs
         Go All Place that there is way to and not having been yet. 

         if island 1 is start point, dfs(1);
         if there is way to island 2 and island 3,
         - island 2 changes non-visited -> visited, and dfs(2).
         - island 3 changes non-visited -> visited, and dfs(3).
         

        */

        visit[placenow] = true;
        boolean success = true;
        for (int i = 0; i < n; i++) {
            if (visit[i] == false) { // not go all place
                success = false;
                break;
            }
        }
        if (success) {
            ans++;
            visit[placenow] = false;
            return;
        }

        for (int i = 0; i < m; i++) {
            if (w[i] == placenow && visit[ww[i]] == false ) {
                dfs(ww[i]);
            }else if(ww[i] == placenow && visit[w[i]] == false){
                dfs(w[i]);
            }else{
                continue;
            }
        }
        visit[placenow] = false;
        return;
    }

}



Measured memory_bytes: 21588