akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	bool can = false;
	cin >>s;
	char last = 0;
	char last2 = 0;
	map<char, int> dis;
	rep(i,s.size()){
		
		if(last==s[i]){
			cout << i << " " << i+1 << endl;
			return 0;
		}
		if(last2==s[i]){
			cout << i - 1 << " " << i+1 << endl;
			return 0;
		}
		last2 = last;
		last=s[i];
	}
	cout<<"-1 -1"<<endl;
}
/*
aaa
1 2
*/

Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
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 INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	deque<int> B(N);
	rep(i,N) cin >> B[i];
	sort(B.begin(),B.end());
	ll ans = 0;
	rep(i,2){
		deque<int> q;
		deque<int> A = B;
		int now;
		if(i == 0){
			q.push_back(A[0]);
			A.pop_front();
			now = 0;
		}
		else{
			q.push_back(A[N-1]);
			A.pop_back();
			now = 1;
		}
		while(!A.empty()){
			int M = A.size();
			if(now == 0){
				q.push_front(A[M-1]);
				if(M >= 2) q.push_back(A[M-2]);
				A.pop_back();
				if(M >= 2) A.pop_back();
			}
			if(now == 1){
				q.push_front(A[0]);
				if(M >= 2) q.push_back(A[1]);
				A.pop_front();
				if(M >= 2) A.pop_front();
			}
			now = 1-now;
		}
		ll nowans = 0;
		rep(i,N-1){
			nowans += abs(q[i]-q[i+1]);
		}
		ans = max(ans,nowans);
	}
	cout << ans << endl;	
}



Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS

#define N (1<<17)
#define MODULO (1000000007)

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <vector>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;

int n;
pair<int, int> pos[N];
int len[N];
priority_queue<long long> PQL, PQR;
long long pbl, pbr;
long long Ans;

int main()
{
	scanf("%d", &n);
	for (int i = 0;i < n;i++)
	{
		scanf("%d%d", &pos[i].first, &pos[i].second);
		len[i] = pos[i].second - pos[i].first;
	}
	for (int i = 0;i < n;i++)
	{
		pbr += len[i];
		PQL.push(pos[i].second - pbl);
		PQR.push(pbr - pos[i].second);
		//__debugbreak();
		while (true)
		{
			long long L = PQL.top() + pbl;
			long long R = -PQR.top() + pbr;
			if (L <= R)
			{
				break;
			}
			Ans += L - R;
			PQL.pop(), PQR.pop();
			PQL.push(R - pbl), PQR.push(pbr - L);
			//__debugbreak();
		}
		pbl -= len[i];
		//__debugbreak();
	}
	printf("%lld\n", Ans);
	//system("pause");
	return 0;
}



Measured memory_bytes: 3316
import sys


if __name__ == "__main__":
    V, E = map(lambda x: int(x), input().split())

    dists = [[sys.maxsize for _ in range(V)] for _ in range(V)]
    for i in range(V):
        dists[i][i] = 0

    for _ in range(E):
        s, t, dist = map(lambda x: int(x), input().split())
        if dist < dists[s][t]:
            dists[s][t] = dist

    for t in range(V):
        for s in range(V):
            if sys.maxsize == dists[s][t]:
                continue
            for goal in range(V):
                if sys.maxsize == dists[t][goal]:
                    continue
                if dists[s][t] + dists[t][goal] < dists[s][goal]:
                    dists[s][goal] = dists[s][t] + dists[t][goal]

    for i in range(V):
        if dists[i][i] < 0:
            print("NEGATIVE CYCLE")
            exit(0)

    for dist in dists:
        print(" ".join([str(elem) if sys.maxsize != elem else "INF" for elem in dist]))



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

string a26(ll n) {
  string res = "";
  while (n) {
    --n;
    res += (char)('a' + (n % 26));
    n /= 26;
  }
  reverse(res.begin(), res.end());
  return res;
}

ll N;
void input() { cin >> N; }
void solve() { cout << a26(N) << endl; }

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

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

int gcd(int u, int v) {
  int r;
  while(v != 0) {
    r = u % v;
    u = v;
    v = r;
  }
  return u;
}

int main() {
  int A, B, K, G;
  cin >> A >> B >> K;
  G = gcd(A, B);
  vector<int> div(G);
  int k = 0;
  for(int i = G; i > 0; i--) {
    if (G % i == 0) {
      div.at(k) = i;
      k++;
    }
  }
  cout << div.at(K - 1) << endl;
}

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

int main(int argc, const char * argv[]) {
    int a, b, c, x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    
    int cnt = 0;
//    bool f = false;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int sum = i * 500 + j * 100 + k * 50;
                if(sum == x) {
//                    f = true;
                    cnt++;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        vec.at(i) = P(A,i);
    }
    sort(vec.begin(),vec.end());
    int ret = 0;
    for(int i = 0;i < N;i++) {
        if(vec.at(i).second % 2 != i % 2) {
            ret++;
        }
    }
    cout << ret / 2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
 
using namespace std;
 
const int maxn=500005;
typedef long long ll;
 
int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

int n;
ll a[maxn];

ll a1[maxn],a2[maxn];
ll ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]+i<=n) a1[a[i]+i]++;
		if(i-a[i]>=1) a2[i-a[i]]++;
	}	
	for(int i=1;i<=n;i++)
	{
		ans+=a1[i]*a2[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8284
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int DX[4] = {0, 0, +1, -1};
const int DY[4] = {+1, -1, 0, 0};
const int TYPE[4] = {1, 2, 4, 8};
int main() {
    int H, W, K; cin >> H >> W >> K;
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;
    vector<string> C(H); for (auto &c : C) cin >> c;
    vector<vector<int>> done(H, vector<int>(W));
    vector<vector<int>> cost(H, vector<int>(W, 1e9));
    MinHeap<tuple<int, int, int>> Q;
    Q.emplace(0, x1, y1);
    cost[x1][y1] = 0;
    while (!Q.empty()) {
        auto [c, x, y] = Q.top(); Q.pop();
        if (cost[x][y] != c) continue;
        if (x == x2 && y == y2) {
            cout << c << '\n';
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            if ((done[x][y] & TYPE[i]) != 0) continue;
            int nx = x, ny = y, rest = K;
            while (rest) {
                nx += DX[i], ny += DY[i], rest--;
                if (!(0 <= nx && nx < H && 0 <= ny && ny < W)) break;
                if (C[nx][ny] != '.') break;
                if (cost[nx][ny] < c) break;
                if (cost[nx][ny] == c && (done[nx][ny] & TYPE[i]) == 0) {
                    done[nx][ny] |= TYPE[i];
                    rest = K;
                }
                if (cost[nx][ny] > c + 1) {
                    cost[nx][ny] = c + 1;
                    Q.emplace(c + 1, nx, ny);
                }
            }
            done[x][y] |= TYPE[i];
        }
    }
    cout << -1 << '\n';
    return 0;
}

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

#define MOD 1000000007

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (auto& v : a) {
    cin >> v;
  }
  
  vector<long long> sum(n - 1, 0);
  sum[n - 2] = a[n - 1];
  for (int i = n - 3; i >= 0; --i) {
    sum[i] = a[i + 1] + sum[i + 1];
    sum[i] %= MOD;
  }
  
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    ans += a[i] * sum[i];
    ans %= MOD;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6420
n = int(input())

x = list(map(int,input().split()))

ans=0

for i in range(1,n):
	ans^=x[i]
ans2=ans^x[0]
y=[]
y.append(str(ans))
for i in range(1,n):
	t=ans2^x[i]
	y.append(str(t))
print(' '.join(y))


Measured memory_bytes: 35444
package main

import (
	"fmt"
	"io"
	"os"
)

func answer(reader io.Reader, writer io.Writer) {
	var a int
	_, _ = fmt.Fscan(reader, &a)
	n := 180 * (a-2)
	_, _ = fmt.Fprintf(writer, "%d", n)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

#define PI 3.14159265358979

int main(){
	double R;
	cin >> R;
	cout << 2 * R * PI << endl;
}

Measured memory_bytes: 3788
#include<stdio.h>
void swap(int *a,int *b)
{
  int cp;
  cp=*a;*a=*b;*b=cp;
}
int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  swap(&a,&b);
  swap(&a,&c);
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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

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

using ll = long long;

string to_bits(ll x) {
    if (x <= 1) return to_string(x);
    return to_bits(x / 2) + to_string(x % 2);
}

int main() {
    ll N;
    cin >> N;
    string bits = to_bits(N);    // テスト用に

    // cerr << "bit is " << bits << endl;

    const ll MOD = 1e9 + 7;
    static ll dp[70][2][2];
    dp[0][0][0] = 1;

    int n = bits.size();
    rep (i, n) rep (less, 2) rep (carry, 2) {
        if (dp[i][less][carry] == 0) continue;

        rep (x, 2) {
            rep (ncarry, 2) {
                // carryが0かつxorが1かつncarryが0
                if (carry == 1 and x == 1 and ncarry == 0) continue;
                if (carry == 0 and x == 1 and ncarry == 1) continue;

                int b = x ^ ncarry;
                if (!less and b > bits[i] - '0') continue;
                (dp[i + 1][less | (b < bits[i] - '0')][ncarry] += dp[i][less][carry]) %= MOD;
            }
        }
    }

    ll ans = 0;
    rep (less, 2) (ans += dp[n][less][0]) %= MOD;
    cout << ans << endl;

    /*
    cerr << "debug" << endl;
    rep (i, n + 1) rep (less, 2) rep (carry, 2) {
        cerr << "i: " << i << " less: " << less << " carry: " <<
             carry << " => " << dp[i][less][carry] << endl;
    }
    */

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Input
{
    int n;
    int k;
};

static Input read_input()
{
    Input input{};
    cin >> input.n >> input.k;
    return input;
}

static void solve(const Input& input)
{
    int num = 0;
    for (auto i = 0; i < input.n; ++i) {
        int h;
        cin >> h;

        if (h >= input.k) {
            num += 1;
        }
    }

    cout << num << endl;
}

int main(int argc, char** argv)
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    const auto input = read_input();
    solve(input);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  auto nCr_mod2 = [](int n, int r) {
    int ret = 1;
    while (n) {
      ret &= (r & 1) <= (n & 1);
      n >>= 1, r >>= 1;
    }
    return ret;
  };
  int N;
  cin >> N;
  string s;
  cin >> s;
  int a[N - 1];
  for (int i = 0; i < N - 1; i++) a[i] = abs(s[i] - s[i + 1]);
  bool one = false;
  for (int i = 0; i < N - 1; i++) one |= a[i] == 1;
  int ans = 0;
  if (one) {
    for (int i = 0; i < N - 1; i++)
      if (a[i] == 1) ans ^= nCr_mod2(N - 2, i);
  } else {
    for (int i = 0; i < N - 1; i++)
      if (a[i] == 2) ans ^= nCr_mod2(N - 2, i);
    ans *= 2;
  }
  cout << ans << '\n';
  return 0;
}


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

static const int N=100;

int main()
{
    int M[100][100];
    int n,u,k,v;

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

    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j)cout<<" ";
            cout<<M[i][j];
        }
        cout<<endl;
    }
 	return 0;
}




Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef vector<int> vi;

int main() {
  int N;
  cin >> N;
  int x;
  map<int, int> mp;
  rep(i,N) {
    cin >> x;
    mp[x] = i+1;
  }

  for(auto tmp : mp) {
    // tmp.firstがkeyでtmp.secondがvalue
    cout << tmp.second << " ";
  }
  cout << endl;

  return 0;
}


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

using namespace std;

long long  mod = 1000000007;

long long calc(long long  k,int m){
	if(m==0)return 1;
	if(m==1)return k%mod;
	long long s = calc(k,m/2);
	if(m%2==0){
		return (s*s)%mod;
	}else{
		long long ans;
		ans = (s*s)%mod;
		return (k*ans)%mod;
	}
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	vector<bool> flag(n+1);
	int k;
	for(int i=0;i<n+1;i++){
		cin >> a[i];
		if(flag[a[i]]!=1){
			flag[a[i]] = 1;
		}else{
			k = a[i];
		}
	}
	int x=0;
	int y=0;
	for(int i=0;i<n;i++){
		if(a[i]!=k){
			x+=1;
		}else{
			break;
		}
	}
	for(int i=n;i>=0;i--){
		if(a[i]!=k){
			y+=1;
		}else{
			break;
		}
	}
	vector<long long> p(n+2);
	p[0]=1,p[1]=1;
	vector<long long> inv(n+2);
	for(long long i=2;i<n+2;i++){
		p[i] = (p[i-1]*i)%mod;
	}
	inv[n+1] = calc(p[n+1],mod-2);
	for(long long i=n;i>=0;i--){
		inv[i] = ((i+1)*inv[i+1])%mod;
	}
	for(int k=1;k<=n+1;k++){
		if(k==1){
			cout << n << endl;
			continue;
		}
		long long ans=0;
		long long s;
		s = (p[n+1]*inv[n+1-k])%mod;
		s = (s*inv[k])%mod;
		ans += s;	
		if(x+y>=k-1){
			s = (p[x+y]*inv[x+y-k+1])%mod;
			s = (s*inv[k-1])%mod;
			ans = (ans - s + mod)%mod;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int N;
int M = 0;  //最大数
vector<vector<P>> shougen;  //証言のペア




/*2進数表記のnに含まれる1の個数を返す関数*/
int num1bit(int n){
  int cn = 0;
  for(int i = 0; i < 15; i++){ if(n & (1 << i)) cn++; }
  return cn;
}


/*nの2進数表記でのビット表現 : 条件を満たすか否かを返す関数*/
bool satisfied(int n){
  for(int i = 0; i < 15; i++){
    if(!(n & (1 << i))) continue;  // (i+1)人目が信頼に値しない人である
    else {
      for(int j = 0; j < shougen[i].size(); j++){ //i+1人目の人の証言を全網羅
      P p = shougen[i][j];
      if(p.second == 1){ if(!(n & (1 << (p.first-1)))) return false; }  //p.first番目が信頼できない設定
      else if(p.second == 0){ if(n& (1 << (p.first-1))) return false; } //p.firstが信頼できる設定
      }
    }
  }
  return true;
}
      

/*処理*/
int main(){
  cin >> N;
  shougen.resize(N);

  /*入力*/
  for(int i = 0; i < N; i++){
    int A; cin >> A;
    for(int j = 0; j < A; j++){ int x, y; cin >> x >> y;
      shougen[i].push_back(make_pair(x, y));  // x : 人  y : 真偽
    }
  }

  /*2^N通りを試す 　信頼に値しない人物の証言はどうでもいい*/
  for(int i = 0; i < (1 << N); i++){
    if(satisfied(i)) M = max(M, num1bit(i));
  }

  cout << M << endl;
  return 0;
    
}

Measured memory_bytes: 256
def f(x,y):
  global B
  B[y][x]^=1
  if y>0: B[y-1][x]^=1
  if y<9: B[y+1][x]^=1
  if x>0: B[y][x-1]^=1
  if x<9: B[y][x+1]^=1
  return
R=range(10)
n=input()
for _ in [0]*n:
  A=[map(int,raw_input().split()) for _ in R]
  for p in range(1024):
    B=[A[i][:] for i in R]
    x=[]
    for j in R:
      if j==0: a=map(int,list(format(p,'010b')))
      else: a=B[j-1]
      for i in R:
        if a[i]==1:
          x.append((i,j))
          f(i,j)
    if sum(B[9])==0: break
  for i,j in x: B[j][i]=1
  for e in B: print " ".join(map(str,e))

Measured memory_bytes: 4296
words = []
result = 0
N = int(input())
words.append(input())
for i in range(1, N):
	temp = input()
	if temp in words:
		result +=1
	words.append(temp)
	if words[i][0] != words[i - 1][-1]:
		result +=1
if result == 0:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    if(k==0){
        cout << n*n << endl;
        return 0;
    }
    ll ans=0;
    for(ll i=k+1;i<=n;i++){
        ans+=n/i*(i-k)+max(0LL,n%i-k+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		int nowX = 0;
		int nowY = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i <= Math.max(2 * x, 2 * y); i += 2) {
			int sum = 0;
			nowX = Math.max(0, x - i / 2);
			nowY = Math.max(0, y - i / 2);
			sum = nowX * a + nowY * b + i * c;
			min = Math.min(min, sum);
		}

		System.out.println(min);

		sc.close();
	}
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();
            Array.Sort(n);

            Console.WriteLine(n[0]+n[1]);
            ReadLine();
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
struct sto
{
	int a,b;
	bool operator<(const sto&a)const
	{
		return b<a.b;
	}
}s[100010];
main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&s[i].b,&s[i].a);
	}
	sort(s+1,s+n+1);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i].a<=m)
		{
			m-=s[i].a;
			ans+=s[i].a*s[i].b;
		}
		else
		{
			ans+=m*s[i].b;
			break;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 1792
// Aizu Vol-2 0227: Thanksgiving
// 2017.8.6

#include <stdio.h>

int p[1002];

int main()
{
	int n, m;
	int i, j, k;

	while (1) {
		scanf("%d%d", &n, &m); if (n == 0) break;
		for (i = 0; i < n; i++) scanf("%d", p + i);
		for (i = 0; i < n; i++) {
			k = i;
			for (j = i + 1; j < n; j++) if (p[k] < p[j]) k = j;
			if (k != i) { int t = p[k]; p[k] = p[i], p[i] = t; }
		}
		for (k = j = i = 0; i < n; i++) {
			if (++j == m) j = 0;
			else k += p[i];
		}
		printf("%d\n", k);
	}
	return 0;
}

Measured memory_bytes: 604
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

N, M = map(int, input().split())

ans = 0
i = 1
while i*i <= M:
    if M % i == 0:
        if i >= N:
            ans = max(ans, M // i)
        if M // i >= N:
            ans = max(ans, i)
    i += 1
print(ans)


Measured memory_bytes: 2940
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    long long int K;
    cin>>K;
    long long int A=100;
    int E;

    for(int i=1;A<K;i++){
        long long int B=A*1/100;

        A=A+B;
        E=i;
    }


    cout<<E<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve()
{
    string S; cin >> S;
    LL K; cin >> K;
    for (int i=0; i < S.length() and i < K; i++)
    {
        if (S[i]=='1') continue;
        else {
            cout << S[i] << endl;
            return;
        }
    }
    cout << S[K-1] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
# include <stdio.h>

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

    int ans = 0;
    for (int i = 2; i < n; ++i)
    {
        if ((p[i-2] < p[i-1] && p[i-1] < p[i]) || (p[i-2] > p[i-1] && p[i-1] > p[i])) ans++;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
# import sys
import sys,os,io
# input = sys.stdin.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)

def dfs(start):
  stack = [start]
  while stack:
    v = stack[-1]
    marker = 0
    path_l[v] = 0
    for u in edge[v]:
      if path_l[u]==-1: #子へ降ろす
        marker = 1
        stack.append(u)
      else: #子から吸い上げる
        #吸い上げる際の個々の処理
        path_l[v] = max(path_l[v], path_l[u]+1)
    if marker==0:
      stack.pop()
  return

path_l = [-1]*N
for i in range(N):
  if path_l[i]==-1:
    dfs(i)
ans = max(path_l)
print(ans)


Measured memory_bytes: 89852
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
    int N;
    int cak, don;
    cin >> N;
    bool res=false;
    for(don=0; don<=20; don++){
        for(cak=0; cak<=20; cak++){
            int tot = 4*cak+7*don;
            if(N==tot) res=true;
        }
    }
    if(res==false){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;

int main()
{
    int n;
    long long k;
    cin >> n >> k;
    vector<int> A;
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        A.push_back(num);
    }

    long long counter1 = 0;
    // セットA内の転倒数を計算する
    for (int i = 0; i < A.size(); i++)
    {
        for (int j = i + 1; j < A.size(); j++)
        {
            if (A[i] > A[j])
            {
                counter1++;
                counter1 = counter1 % MOD;
            }
        }
    }

    long long counter2 = 0;
    for (int i = 0; i < A.size(); i++)
    {
        for (int j = 0; j < A.size(); j++)
        {
            if (A[i] > A[j] && i != j)
            {
                counter2++;
                counter2 = counter2 % MOD;
            }
        }
    }
    k = k % MOD;
    long long answer = 0;
    answer = (k * counter1) % MOD + ((counter2 % MOD) * (((k * (k - 1)) / 2) % MOD) % MOD);
    cout << (answer % MOD) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)


using namespace std;

int cnt;

int lcd(int a, int b){
	if (a < b) swap(a, b);
	int c;
	cnt=0;

	while (b != 0){
		c = a%b;
		a = b;
		b = c;
		cnt++;
	}
	return a;
}



int main(){

	int a, b;
	while (cin >> a >> b && a != 0 && b != 0){
		int res = lcd(a,b);
		cout << res << " " << cnt << endl;
	}
}

Measured memory_bytes: 1160
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int di[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dj[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int w, h;
int c[50][50];

int solve(){
    int cnt = 0;
    bool visited[h][w];
    memset(visited, false, sizeof visited);
    queue<pair<int, int> > Q;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(!visited[i][j] && c[i][j] == 1){
                cnt++;
                // bfs
                visited[i][j] = true;
                Q.push(make_pair(i, j));
                while(!Q.empty()){
                    pair<int, int> p = Q.front(); Q.pop();
                    int si = p.first;
                    int sj = p.second;

                    for(int k=0;k<8;k++){
                        int ni = si + di[k];
                        int nj = sj + dj[k];
                        if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                        if(!visited[ni][nj] && c[ni][nj] == 1){
                            visited[ni][nj] = true;
                            Q.push(make_pair(ni, nj));
                        }
                    }
                }
            }
        }
    }
    return cnt;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) cin >> c[i][j];
        }
        int ans = solve();
        cout << ans << endl;
    }
}


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

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

int a[100005];
P A[100005];

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

  sort(a,a+n);

  if(a[n-1] < 0) {
    for(int i = 0; i < n - 1; i++) {
      A[i] = P(a[n-1],a[i]);
      a[n-1] = a[n-1] - a[i];
    }
  }
  else if(a[0] < 0 && a[n-1] >= 0) {
    int i = n - 2;
    int k = 0;
    while(i >= 0 && a[i] >= 0) {
      A[k++] = P(a[0],a[i]);
      a[0] = a[0] - a[i];
      i--;
    }

    for(int j = 0; j <= i; j++) {
      A[k++] = P(a[n-1],a[j]);
      a[n-1] = a[n-1] - a[j];
    }
  }
  else {
    for(int i = 0; i < n - 2; i++) {
      A[i] = P(a[i],a[i+1]);
      a[i+1] = a[i] - a[i+1];
    }
    A[n-2] = P(a[n-1],a[n-2]);
    a[n-1] = a[n-1] - a[n-2];
  }
  cout << a[n-1] << endl;

  for(int i = 0; i < n - 1; i++) {
    cout << A[i].first <<" "<< A[i].second << endl;
  }
}
  
  

  

  



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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] <<endl;

    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
pn = list(map(lambda x:int(x)-1, input().split()))
ls = [-1] * n
for i in pn:
    ls[pn[i]] = i
par = [i for i in range(n)]
def find(x):
    if par[x] == x:
        return x
    else:
        s = find(par[x])
        par[x] = s
        return s
def unite(x,y):
    s = find(x)
    t = find(y)
    if s>t:
        par[s] = t
    else:
        par[t] = s
for _ in range(m):
    x, y = map(lambda x:int(x)-1, input().split())
    unite(ls[x],ls[y])
ans2 = 0
for i in range(n):
    if find(i)==find(ls[i]):
       ans2+=1
print(ans2)

Measured memory_bytes: 20424
#include <iostream>

using namespace std;

int main(void)
{
	int n;
	int answer;

	while( cin >> n && n != 0 ){
		answer = 0;

		while( n != 1 ){
			if( n % 2 == 0 ) n /= 2;
			else { n *= 3; n++; }
			answer++;
		}
		cout << answer << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int binarySearch(int S[], int T[], long n, int q){
    int counter=0;
    for(int i=0; i<q; i++){
        int left = 0, right = n;
        // Searching algorithm
        while(left < right){
            int mid = (left+right)/2;
            if(T[i] == S[mid]){
                counter++;
                break;
            }
            else if(T[i] > S[mid]) left = mid + 1;
            else right = mid;
        }
    }
    return counter;
}

int main(){
    // Input n
    long n;
    scanf("%ld",&n);
    // Input S
    int S[n];
    for(int i=0; i<n; i++){
        scanf("%d",&S[i]);
    }
    // Inpupt q
    int q;
    scanf("%d",&q);
    // Input T
    int T[q];
    for(int i=0; i<q; i++){
        scanf("%d",&T[i]);
    }
    // Execution
    printf("%d\n",binarySearch(S,T,n,q));
    return 0;    
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int w, a, b;
  cin >> w >> a >> b;

  if (a < (b + w)) {
    if (a + w < b) {
      cout << b - (a + w) << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    if (b + w < a) {
      cout << a - (b + w) << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 892
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
C = [1] * 50
for i in range(50 - 1):
    C[i + 1] = 2 * C[i]

count = [0] * 50

for i in range(N):
    a = A[i]
    j = 0
    while a:
        if a % 2 == 1:
            count[j] += 1
        j += 1
        a //= 2

B = [0] * 60
k = K
j = 0
while k:
    if k % 2 == 1:
        B[j] = 1
    j += 1
    k //= 2

under = [-1] * (j + 1)
just = [0] * (j + 1)
# print (j)

tmp = 0
for i in range(49, j - 1, -1):
    tmp += C[i] * count[i]

for i in range(j - 1, -1, -1):
    tmp1 = count[i] #1の数
    tmp0 = N - tmp1 #0の数
    if B[i] == 0:
        just[i] = just[i + 1] + C[i] * tmp1
        if under[i + 1] >= 0:
            under[i] = under[i + 1] + C[i] * max(tmp1, tmp0)
    else: #B[i] == 1
        just[i] = just[i + 1] + C[i] * tmp0
        if under[i + 1] == -1:
            under[i] = just[i + 1] + C[i] * tmp1
        if under[i + 1] >= 0:
            under[i] = under[i + 1] + C[i] * max(tmp1, tmp0)
            under[i] = max(under[i], just[i + 1] + C[i] * tmp1)


print (max(under[0], just[0]) + tmp)

# print ('count', count)
# print ('B', B)
# print (under)
# print (just)
# print (tmp)

Measured memory_bytes: 14620
s=input()
l=len(s)
n=int(s)
b=[357,375,537,573,753,735]
if l<=3:
    print(sum(1 for j in b if j<=n));exit()
from itertools import product as pr
ans=0
for k in range(3,l+1):
    for i in pr(("7","5","3"),repeat=k):
        if len(set(i))==3:ans+=int(int("".join(i))<=n)
print(ans)

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

typedef long long ll;

using namespace std;

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

    int a = s / 100;
    int b = s % 100;

    if (1 <= a && a <= 12) {
        if (1 <= b && b <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if (1 <= b && b <= 12) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int l,r;
int main()
{
	cin>>l>>r;
	if (l<=0&&0<=r) return puts("Zero"),0;
	if (l>0) return puts("Positive"),0;
	puts((r-l+1)&1?"Negative":"Positive");
	return 0;
}

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

long long ans;
long long a, b;

void in();
void solve();
long long bp(long long);
void out();

int main(){
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	in();
	solve();
	out();
}

void in(){
	cin >> a >> b;
}

void solve(){
	while(a && bp(a) == bp(b)){
		a -= 1ll << bp(a);
		b -= 1ll << bp(b);
	}
	if(b == 0){
		ans = 1;
		return;
	}
	long long pwr = bp(b);
	long long MX = b - (1ll << pwr);
	MX = (1ll << bp(MX) + 1) - 1;
	if(MX >= a)
		ans = (1ll << pwr + 1) - a;
	else
		ans = MX + ((1ll << pwr) - a) * 2 + 1;
}

long long bp(long long x){
	long long ret = -1;
	while(x){
		ret++;
		x >>= 1;
	}
	return ret;
}

void out(){
	cout << ans;
}

Measured memory_bytes: 3652
/*
AizuOnline A0227
Title Thanksgiving
@kankichi573
*/
#include <stdio.h>
int n,m,p[1000];
//

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}


main()
{
        int i,sum;

        while(EOF!=scanf("%d %d",&n,&m) && (m||n))
        {
                for(i=0;i<n;i++)
                        scanf("%d",&p[i]);
        
                qsort(p,n,sizeof(int),compare_int);
                sum=0;
                for(i=0;i<n;i++)
                        if((i % m) != m-1) 
                                sum += p[i];
                printf("%d\n",sum);
        }
        return(0);
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
    VECCIN(head);
    VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
    seco[head]=IN();
    VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair


int main(){
    LCIN(n,k);
    VC2(n,a,b);
    //まずはorが完全にKと同じになるように選ぶ
    //上から見ていって
    //もしそのbitが1ならそこを0にして、それ以外を1にするようなやつをする
    ll ans = 0;
    auto f = [&](ll p){
        //dump(bitset<8>(p));
        ll sum = 0;
        REP(i,n){
            ll t = a[i]|p;
            if(p-t==0)
                sum+=b[i];
        }
        ans=max(ans,sum);
    };
    f(k);
    REPR(i,32){
        if(!(k&1LL<<i))continue;
        ll t = k;
        t&=(~(1LL<<i));
        t|=((1LL<<i)-1);
        f(t);
    }
    COUT(ans);
    

    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);

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

	stack<char> s;
	ll n = x.size();

	rep(i, n) {
		if (s.size() == 0 || x[i] == 'S') s.push(x[i]);
		else if (s.top() == 'S' && x[i] == 'T') s.pop();
		else if (s.top() != 'S' && x[i] == 'T') s.push(x[i]);
	}

	cout << s.size();

	return 0;
}


ll cb(ll a, ll b) {
	ll ans = 1;
	rep(i, b) ans *= (a - i);
	rep(i, b) ans /= (b - i);

	return ans;
}

ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 3800
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

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

const int maxn=101,maxm = 5010, INF = 10010;
int cost[maxn][maxn];
int mincost[maxn];
bool used[maxn];
int n,m,a,b;

int main()
{
    while(cin >> n >> m &&(n&&m))
    {
        memset(cost,INF,sizeof(cost));
        memset(mincost,INF,sizeof(mincost));
        memset(used,false,sizeof(used));
        mincost[0] = 0;

        REP(m)
        {
            cin >> a >> b;
            cin >> cost[a][b];
            cost[b][a] = cost[a][b];
        }

        int ans = 0;
        while(true)
        {
            int minv = INF;
            REP(n)if(!used[i] &&(minv==INF || mincost[i] < mincost[minv])) minv = i;
            if(minv == INF) break;

            used[minv] = true;
            ans += mincost[minv];
            REP(n)mincost[i] = min(mincost[i], cost[minv][i]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 0
N,M = map(int, input().strip().split(' '))
front = set()
rear = set()
for _ in range(M):
  a,b = map(int, input().strip().split(' '))
  if a == 1:
    front.add(b)
  if b == N:
    rear.add(a)

print('POSSIBLE' if len(front&rear) > 0 else 'IMPOSSIBLE')


Measured memory_bytes: 18936
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
#再起のlimitを上げる
import sys
sys.setrecursionlimit(4100000)

x,y = list(map(int,input().split()))

if (x+y) % 3 != 0:
    print(0)
    import sys
    sys.exit()

import math
#組み合わせ kumiawase
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

m = (2 * x - y)//3
n = x - m * 2
if m < 0 or n < 0:
    print(0)
    import sys
    sys.exit()

print(combination(n+m,n))

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

int main(){
  int n,x,array[100000],kyori[100000],ans=0;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>array[i];
    kyori[i]=abs(array[i]-x);//Xからの距離を出す
  }
  for(int i=0;i<n;i++){
    ans=__gcd(ans,kyori[i]);
    //すべての最大公約数を求める(0とnの最大公約数はn,__gcd(a,b)はaとbの最大公約数を求める関数
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  double res = 0;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  res += a[0];
  for(int i = 1;i < n;i++)res += a[i],res /= 2;
  cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 3800
from collections import Counter
import numpy as np

n, m = map(int, input().split())
data = [0] * m

for i in range(m):
    data[i] = list(map(int, input().split()))


data = np.array(data)
ll = data[:, 0]
rr = data[:, 1]

ans = np.min(rr) - max(ll) + 1
ans = max(0, ans)
print(ans)

'''
n, m = map(int, input().split())
tar = [0] * (1 + 10 ** 5)
tar = np.array(tar)

for i in range(m):
    l, r = map(int, input().split())
    tar[l:r + 1] += 1
    #print(tar[:10])

#tar = tar.tolist()
# print(tar[0:5])
count = Counter(tar)
ans = count[m]
print(ans)
#-----------------------------
n, m = map(int, input().split())

ll, rr = map(int, input().split())
for i in range(m - 1):
    l, r = map(int, input().split())

    #lについて
    if (l <= ll):
      pass
    elif (ll < l )

ans = max(ll - rr, 0)
print(ans)

'''


Measured memory_bytes: 37896
import math
a, b = map(int, input().split())
lista = []
listb = []
pa1 = math.ceil(a * 12.5)
pa2 = math.ceil((a+1) * 12.5)
pb1 = int(b * 10)
pb2 = int((b+1) * 10)
for i in range(pa1, pa2) :
    lista.append(i)
for j in range(pb1, pb2) :
    listb.append(j)
aandb = set(lista)&set(listb)
if len(aandb) == 0 :
    print("-1")
else :
    print(min(aandb))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int calc(int nb[256][256], int n, int ret) {
	rep(i,n) {
		rep(j,n) {
			if(ret<nb[i][j]) ret = nb[i][j];		
		}
	}
	return ret;
}

int main() {
	int n;
	string s;
	while(cin >> n, n) {
		int b[256][256] = {};
		int nb[256][256] = {};
		rep(i,n) {
			cin >> s;
			rep(j,n) {
				b[i][j] = s[j]-'0';
			}
		}
		int ret = 0;
		rep(i,n) {
			rep(j,n) {
				if(i==0) {
					nb[i][j] = b[i][j];
					continue;
				}
				nb[i][j] = b[i][j] ? nb[i-1][j]+b[i][j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,n) {
			rep(j,n) {
				if(j==0) {
					nb[i][j] = b[i][j];
					continue;
				}
				nb[i][j] = b[i][j] ? nb[i][j-1]+b[i][j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,2*n) {
			int k = i<n?i:2*n-i;
			rep(j,k) {
				if(j==0) {
					if(i<n) nb[n-i][0] = b[n-i][0];
					else nb[0][i-n] = b[0][i-n];
					continue;
				}
				if(i<n) nb[n-i+j][j] = b[n-i+j][j] ? nb[n-i+j-1][j-1]+b[n-i+j][j] : 0;
				else nb[j][i-n+j] = b[j][i-n+j] ? nb[j-1][i-n+j-1]+b[j][i-n+j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,2*n) {
			int k = i<n?i:2*n-i;
			rep(j,k) {
				if(j==0) {
					if(i<n) nb[n-i][n-1] = b[n-i][n-1];
					else nb[0][2*n-1-i] = b[0][2*n-1-i];
					continue;
				}
				if(i<n) nb[n-i+j][n-1-j] = b[n-i+j][n-1-j] ? nb[n-i+j-1][n-j]+b[n-i+j][n-1-j] : 0;
				else nb[j][2*n-1-i-j] = b[j][2*n-1-i-j] ? nb[j-1][2*n-i-j]+b[j][2*n-1-i-j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1724