akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
    string s;
    cin >> s;
    bool a = false, b = false, c = false;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'a'){
            a = true;
        }else if(s[i] == 'b'){
            b = true;
        }else if(s[i] == 'c'){
            c = true;
        }
    }
    if(a && b && c){
        cout << "Yes" << endl;

    }else{
        cout << "No" << endl;
    }
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

#define MOD 1000000007

int N;
int a[100000];

long long power(int m){
    long long sum = 1;
    long long s = 2;
    while(m!=0){
        if(m%2==1) sum *= s;
        s *= s;
        m /= 2;
        s %= MOD;
        sum %= MOD;
    }
    return sum;
}

int main(){
    int n;
    cin >> N;
    for(int i=0;i<N;i++) a[i] = 0;
    for(int i=0;i<N;i++){
        cin >> n;
        a[n]++;
    }
    if(N%2==1){
        if(a[0] != 1){
            cout << 0 << endl;
            return 0;
        }
        for(int i=1;i<N;i++){
            if(i%2==1){
                if(a[i] != 0){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(a[i] != 2){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
        cout << power(N/2) << endl;
    }else{
        for(int i=0;i<N;i++){
            if(i%2==1){
                if(a[i] != 2){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(a[i] != 0){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
        cout << power(N/2) << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

// 最大公約数
int gcd(int a, int b){
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main(void){
    int n, x; cin >> n >> x;
    vector<int> A(n);
    REP(i, n) cin >> A[i];
    whole(sort, A);
    int ans = 0; // gcdの引数の片方が0の時、その値はもう一つの引数の値となる
    REP(i, n){
        ans = gcd(ans, abs(A[i] - x));
    }
    cout << ans << endl;
}
/* 今回、初めはA[i - 1] - A[i] で求めようとしていたが、この方法だと
   例えば[1, 3, 6, 8]のセットの時に答えが2となってしまう（本当は 1） */

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

typedef long long ll;
typedef long double ld;


char rev(char x) {
    if(x == 'S') return 'W';
    else return 'S';
}

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

    int N;
    cin >> N;

    string s;
    cin >> s;

    vector<string> a(4);

    a[0] = "SS";
    a[1] = "SW";
    a[2] = "WS";
    a[3] = "WW";

    for(int i = 0; i < 4; i++) {
        for(int j = 1; j < N - 1; j++) {
            if(a[i][j] == 'S') {
                if(s[j] == 'o') {
                    a[i].push_back(a[i][j - 1]);
                } else {
                    a[i].push_back(rev(a[i][j - 1]));
                }
            } else {
                if(s[j] == 'o') {
                    a[i].push_back(rev(a[i][j - 1]));
                } else {
                    a[i].push_back(a[i][j - 1]);
                }
            }
        }

        if(a[i][0] == 'S') {
            if(s[0] == 'o') {
                if(a[i][1] != a[i][N - 1]) continue;
            } else {
                if(a[i][1] == a[i][N - 1]) continue;
            }
        } else {
            if(s[0] == 'o') {
                if(a[i][1] == a[i][N - 1]) continue;
            } else {
                if(a[i][1] != a[i][N - 1]) continue;
            }
        }

        if(a[i][N - 1] == 'S') {
            if(s[N - 1] == 'o') {
                if(a[i][0] != a[i][N - 2]) continue;
            } else {
                if(a[i][0] == a[i][N - 2]) continue;
            }
        } else {
            if(s[N - 1] == 'o') {
                if(a[i][0] == a[i][N - 2]) continue;
            } else {
                if(a[i][0] != a[i][N - 2]) continue;
            }
        }

        cout << a[i] << endl;
        return 0;
    }

    cout << -1 << endl;
}

Measured memory_bytes: 976
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int count = 1;
  if (n == 1) 
  {
    cout << 4 << endl;
  }
  else if (n == 2)
  {
    cout << 4 << endl;
  }
  else
  {
  while (n != 4)
  {
    if (n % 2 == 0)
    {
      n /= 2;
    }
    else
    {
      n = n * 3 + 1;
    }
    ++count;
  }
  cout << count + 3 << endl;
  }
}


Measured memory_bytes: 256
def main(N, K, d, A):
    a = list(set(sum(A, [])))
    print(N - len(a))

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    d = []
    A = []
    for i in range(K):
        d.append(int(input()))
        A.append(list(map(int, input().split())))
    main(N, K, d, A)

Measured memory_bytes: 9392
#include<iostream>
using namespace std;
int main(){
	int n, m, c = 0;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a;
		cin >> a;
		c = c + a;
		}
		
	if(n - c >= 0){
		cout << n - c;
		}
	else{
		cout << "-1";
		}
	}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int n;
  cin >> n;
  
  ll l[n];

  l[0] = 2;
  l[1] = 1;

  rep(i,2,n+1){
    l[i] = l[i-2] + l[i-1];
  }
  
  printf("%lld\n", l[n]);
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int s, count;
    count=0;
    set<int>sets;
    decltype(sets)::iterator it;
    cin >> s; 
    sets.emplace(s);

    for(int i=1; i<=(1000000-1); ++i){
        count++;
        if(s%2==0) {
            it = sets.find(s/2);
            if(it!=sets.end()){
                break;
            }else{
                sets.emplace(s/2);
                s=s/2;
            }
        } else {
            it = sets.find(3*s+1);
            if(it!=sets.end()){
                break;
            }else{
                sets.emplace(3*s+1);
                s=3*s+1;
            }
        } 
    }
        cout << count + 1 << endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n,p;cin>>n>>p;
	string s;cin>>s;
	if(p==2){
		ll ans=0;
		rep(i,s.size()){
			if((s[i]-'0')%2==0)ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}
	if(p==5){
		ll ans=0;
		rep(i,s.size()){
			if(s[i]=='0'||s[i]=='5')ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}
	map<int,int>mp;
	mp[0]=1;
	int d=0;
	int e=1;
	ll ans=0;
	for(int i=s.size()-1;i>=0;i--){
		d+=e*(int)(s[i]-'0');
		e*=10;
		e%=p;
		d%=p;
		ans+=mp[d];
		mp[d]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 110;
const int INF = 1e9;

struct edge {
  int to, cost;
};

int n, m;
vector<edge> graph[MAXN];
int dist[MAXN][MAXN];

void solve() {
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = INF;
      }
    }
  }
  for (int i=0;i<n;i++) {
    for (int j=0;j<graph[i].size();j++) {
      dist[i][graph[i][j].to] = graph[i][j].cost;
    }
  }
  for (int k=0;k<n;k++) {
    for (int i=0;i<n;i++) {
      for (int j=0;j<n;j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int cnt = 0;
  for (int i=0;i<n;i++) {
    for (int j=0;j<graph[i].size();j++) {
      bool shortest = false;
      for (int k=0;k<n;k++) {
        if (dist[k][graph[i][j].to] == dist[k][i] + graph[i][j].cost) {
          shortest = true;
        }
      }
      if (shortest) {
        cnt++;
      }
    }
  }
  cout << m - (cnt / 2) << endl;
}

int main() {
  cin >> n >> m;
  int a, b, c;
  for (int i=0;i<m;i++) {
    cin >> a >> b >> c;
    graph[--a].push_back((edge){--b, c});
    graph[b].push_back((edge){a, c});
  }
  solve();
}


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

using namespace std;

void solve()
{
	string cube[6] = {  "..rr....",
						"..rr....",
						"ggyybbww",
						"ggyybbww",
						"..oo....",
						"..oo...."};
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); ++i)
	{
		if(s[i] == 'U')
		{
			char l1 = cube[2][0], l2 = cube[2][1];
			cube[2].erase(cube[2].begin(), cube[2].begin() + 2);
			cube[2] += l1;
			cube[2] += l2;
			l1 = cube[0][2];
			cube[0][2] = cube[1][2];
			cube[1][2] = cube[1][3];
			cube[1][3] = cube[0][3];
			cube[0][3] = l1;
		}
		else if(s[i] == 'F')
		{
			char l1 = cube[1][2], l2 = cube[1][3];
			cube[1][2] = cube[3][1];
			cube[1][3] = cube[2][1];
			cube[3][1] = cube[4][3];
			cube[2][1] = cube[4][2];
			cube[4][3] = cube[2][4];
			cube[4][2] = cube[3][4];
			cube[2][4] = l1;
			cube[3][4] = l2;
			l1 = cube[2][2];
			cube[2][2] = cube[3][2];
			cube[3][2] = cube[3][3];
			cube[3][3] = cube[2][3];
			cube[2][3] = l1;
		}
		else if(s[i] == 'R')
		{
			char l1 = cube[0][3], l2 = cube[1][3];
			cube[0][3] = cube[2][3];
			cube[1][3] = cube[3][3];
			cube[2][3] = cube[4][3];
			cube[3][3] = cube[5][3];
			cube[4][3] = cube[3][6];
			cube[5][3] = cube[2][6];
			cube[3][6] = l1;
			cube[2][6] = l2;
			l1 = cube[2][4];
			cube[2][4] = cube[3][4];
			cube[3][4] = cube[3][5];
			cube[3][5] = cube[2][5];
			cube[2][5] = l1;
		}
		else if(s[i] == 'D')
		{
			char l1 = cube[3][6], l2 = cube[3][7];
			cube[3].erase(cube[3].begin() + 6, cube[3].begin() + 8);
			string str = "";
			str += l1;
			str += l2;
			str += cube[3];
			cube[3] = str;
			l1 = cube[4][2];
			cube[4][2] = cube[5][2];
			cube[5][2] = cube[5][3];
			cube[5][3] = cube[4][3];
			cube[4][3] = l1;
		}
		else if(s[i] == 'B')
		{
			char l1 = cube[0][2], l2 = cube[0][3];
			cube[0][2] = cube[2][5];
			cube[0][3] = cube[3][5];
			cube[2][5] = cube[5][3];
			cube[3][5] = cube[5][2];
			cube[5][3] = cube[3][0];
			cube[5][2] = cube[2][0];
			cube[2][0] = l2;
			cube[3][0] = l1;
			l1 = cube[2][6];
			cube[2][6] = cube[3][6];
			cube[3][6] = cube[3][7];
			cube[3][7] = cube[2][7];
			cube[2][7] = l1;
		}
		else if(s[i] == 'L')
		{
			char l1 = cube[5][2], l2 = cube[4][2];
			cube[5][2] = cube[3][2];
			cube[4][2] = cube[2][2];
			cube[3][2] = cube[1][2];
			cube[2][2] = cube[0][2];
			cube[1][2] = cube[2][7];
			cube[0][2] = cube[3][7];
			cube[2][7] = l1;
			cube[3][7] = l2;
			l1 = cube[2][0];
			cube[2][0] = cube[3][0];
			cube[3][0] = cube[3][1];
			cube[3][1] = cube[2][1];
			cube[2][1] = l1;
		}
	}
	for(int i = 0; i < 6; ++i)
	{
		cout << cube[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
int main(){
	int W_max,N; int cnt=0;
	while(1){
	cin >> W_max ;
	if(W_max==0) break;
	cin >> N ;
	int weight[1000]={0}; int P[1000]={0}; char ch; int P_max=0;
	int dp[1001][1001]; 
	for(int i=0;i<1001;i++)
		for(int j=0;j<1001;j++) dp[i][j]=-1;//初期化上手くできなかった
	for(int i=0;i<N;i++) cin >> P[i] >> ch >> weight[i] ;
	dp[0][0]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=W_max;j++){
			if(dp[i][j]==-1) continue;
			if(j+weight[i]<=W_max) dp[i+1][j+weight[i]]=max(dp[i+1][j+weight[i]],dp[i][j]+P[i]);
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		};
	};
	int W_min=W_max;
	for(int i=0;i<=W_max;i++) if(dp[N][i]>P_max) P_max=dp[N][i];
	for(int i=0;i<=W_max;i++) if(dp[N][i]==P_max) W_min=min(W_min,i);
	cout << "Case " << ++cnt << ":\n" ;
	cout << P_max << '\n' << W_min << '\n' ;
	};
}

Measured memory_bytes: 5080
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
        int sx,sy,tx,ty;
        cin >> sx >> sy >> tx >> ty;

        int r = tx - sx;
        int u = ty - sy;

        for (int i = 0; i < r; i++) {
                cout << 'R';
        }
        for (int i = 0; i < u; i++) {
                cout << 'U';
        }
        for (int i = 0; i < r; i++) {
                cout << 'L';
        }
        for (int i = 0; i < u; i++) {
                cout << 'D';
        }

        cout << 'D';
        for (int i = 0; i < r + 1; i++) {
                cout << 'R';
        }
        for (int i = 0; i < u + 1; i++) {
                cout << 'U';
        }
        cout << 'L';
        cout << 'U';
        for (int i = 0; i < r + 1; i++) {
                cout << 'L';
        }
        for (int i = 0; i < u + 1; i++) {
                cout << 'D';
        }
        cout << 'R';
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int N;
    cin >> N;

    vector<int> p(N);
    for (int i = 0; i < N; i++)
        cin >> p[i];

    bool ok = false;
    bool flag = true;
    for (int i = 0; i < N - 1; i++) {
        if (p[i] > p[i + 1])
            flag = false;
    }
    if (flag == true)
        ok = true;

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            swap(p[i], p[j]);

            flag = true;
            for (int k = 0; k < N - 1; k++) {
                if (p[k] > p[k + 1])
                    flag = false;
            }
            if (flag == true)
                ok = true;

            swap(p[i], p[j]);
        }
    }


    if (ok == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 384
#include<map>
      #include<iostream>
      #include<deque>
      #include<algorithm>
      #include<string>
      #include<cctype>
      #include<iomanip>
      #include<vector>
      #include<queue>
      #include<tuple>
      #include<stdio.h>
      #include<math.h>
      #include<set>
      
      using namespace std;
      #define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
      #define rep0(i,n) REP(i,0ll,n)
      #define rep1(i,n) REP(i,1ll,n+1)
      
      #define shosu setprecision(10)
      typedef long long ll;
      typedef pair<ll,ll> P;
      typedef pair<P,ll> Q;
      typedef pair<Q,ll> R;
      ll longinf=1ll<<60;
      int inf=1<<29;
      //mleしなければぜんぶllでかく。
      //↑はあんまり気にしなくていい。


      int main(){
            ll q;
            cin>>q;
            ll meda=0;
            ll suma=0;
            ll sumb=0;
            multiset<ll> st1;
            multiset<ll> st2;
            int i=0;
            while(q--){
                  int c;
                  cin>>c;
                  if(c==1){
                        ll a,b;
                        cin>>a>>b;
                        sumb+=b;
                        if(st1.size()==st2.size()+2){
                              if(a>*(++st1.begin())){
                                    suma+=(a-*(++st1.begin()));
                              }
                              else if(a<*(st1.begin())){
                                    suma+=(*(st1.begin())-a);
                              }
                        }
                        else if(st1.size()==st2.size()+1){
                              suma+=abs(a-*(st1.begin()));
                        }
                        if(a>=meda){
                              st1.insert(a);
                              if(st1.size()>st2.size()+2){
                                    st2.insert(*(st1.begin()));
                                    st1.erase(st1.begin());
                              }
                        }
                        else{
                              st2.insert(a);
                              if(st2.size()>=st1.size()){
                                    st1.insert(*(--st2.end()));
                                    st2.erase(--st2.end());
                              }
                        }
                        auto itr=st1.begin();
                        meda=*itr;
                  }
                  else{
                        cout<<meda<<" "<<suma+sumb<<endl;
                  }
            }
      return 0;
      }

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    char a[1000];
    cin>>a[0];
    if(a[0]=='A'){
        cout<<'T'<<endl;
    }else if(a[0]=='C'){
        cout<<'G'<<endl;
    }else if(a[0]=='G'){
        cout<<'C'<<endl;
    }else{
        cout<<'A'<<endl;
    }

}

Measured memory_bytes: 256
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

S = sum(A)
X = [0] * N

X[0] = S - 2 * sum(A[1::2])

for i in range(N - 1):
    X[i + 1] = 2 * A[i] - X[i]

print(*X)


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

signed main(){
  lint A, B; cin >> A >> B;
  lint ans;
  if( A % 2 == 0 && B % 2 == 0 ){
    if( (B - A) % 4 == 0 ) ans = B;
    else ans = (1 ^ B);
  }
  if( A % 2 == 1 && B % 2 == 0 ){
    if( (B - A + 1) % 4 == 0 ) ans = (A ^ 1 ^ B);
    else ans = (A ^ B); 
  }
  if( A % 2 == 0 && B % 2 == 1 ){
    if( (B - A + 1) % 4 == 0 ) ans = 0;
    else ans = 1;
  }
  if( A % 2 == 1 && B % 2 == 1 ){
    if( (B - A) % 4 == 0 ) ans = A;
    else ans = (A ^ 1);
  }
  cout << ans << endl;
}

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

int main() {
  ll n; cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll ans = 0;
  
  ll cnt = 0;
  rep(i, n-1){
    if(v.at(i) >= v.at(i+1))  cnt++;
    else  cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4036
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
set<int> tro,hnk;
set<int>::iterator it;
int main(){
	int N,hog,ba,ta,ha;
	while(1){
		cin>>N;
		if(N==0) break;
		tro.clear();
		hnk.clear();
		for(int i=0;i<N;i++){
			cin>>hog;
			tro.insert(hog);
		}
		for(int i=1;i<=N*2;i++){
			if(tro.find(i)==tro.end()){
				hnk.insert(i);
			}
		}

		ba=ta=ha=0;
		while(1){
			//??????
			if(ba==0){
				it=tro.begin();
				ba=*it;
				tro.erase(*it);
			}
			else{
				it=tro.upper_bound(ba);
				if(it==tro.end()){
					ba=0;
				}
				else{
					ba=*it;
					tro.erase(*it);
				}
			}
			
			if(tro.empty()){
				for(it=hnk.begin();it!=hnk.end();it++){
					ha++;
				}
				break;
			}

			//??±???
			if(ba==0){
				it=hnk.begin();
				ba=*it;
				hnk.erase(*it);
			}
			else{
				it=hnk.upper_bound(ba);
				if(it==hnk.end()){
					ba=0;
				}
				else{
					ba=*it;
					hnk.erase(*it);
				}
			}
			
			if(hnk.empty()){
				for(it=tro.begin();it!=tro.end();it++){
					ta++;
				}
				break;
			}
		}
		cout<<ha<<endl<<ta<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, m, k[20], s[20][20], p[20];
	cin>>n>>m;
	REP(i, m){
		cin>>k[i];
		REP(j, k[i]){
			cin>>s[i][j];
			--s[i][j];
		}
	}
	REP(i, m){
		cin>>p[i];
	}
	int on[20];
	int ans=0;
	REP(i, 1<<n){
		REP(j, n){
			on[j]=0;
		}
		REP(j, n){
			if((i>>j)&1){
				on[j]=1;
			}
		}
		bool ok=true;
		REP(j, m){
			int cnt=0;
			REP(j2, k[j]){
				if(on[s[j][j2]]){
					// DEBUG(j2);
					// DEBUG(cnt);
					++cnt;
				}
			}
			// DEBUG(i);
			// DEBUG(cnt);
			if((cnt&1)!=p[j]){
				ok=false;
				break;
			}
		}
		if(ok){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  int N,pnum,res;
  
  cin >> N;

  pnum = N / 1000;

  if (N % 1000 == 0)
    res = N - pnum * 1000;
  else 
    res = (pnum+1) * 1000 - N;
  
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
    int n, ans = 0;
    cin >> n;
    
    vector<int> x(n);

    rep(i, n) cin >> x[i];
    if (n % 2 != 0) {
        x.emplace_back(0);
        n++;
    }

    int tmp;
    rep(i, n - 1)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (x[i] < x[j])
            {
                tmp = x[i];
                x[i] = x[j];
                x[j] = tmp;
            }

        }
    }
    
    for(int i = 0; i < n; i += 2)
    {
        ans += x[i] - x[i + 1];
    }

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

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC153C
{
    class Program
    {
        static void Main(string[] args)
        {
            var HK = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var H = HK[0];
            var K = HK[1];
            var Hs = Console.ReadLine().Split().Select(x => ulong.Parse(x)).OrderByDescending(x => x).ToArray();
            
            if (K >= Hs.Length)
            {
                Console.WriteLine(0);
                return;
            }

            var ans = 0ul;
            for (var i = K; i < Hs.Length; i++)
                ans += Hs[i];

            Console.WriteLine(ans);
        }
    }
}

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

int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    ll min = (n - 1) * a + b;
    ll max = (n - 1) * b + a;
    if((n == 1 && a != b) || a > b) cout<< 0 <<"\n";
    else cout<< max - min + 1 << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define FOR(i, i0, n) for(int i = (i0); i < (n); i ++)
#define COUT(val) cout << (val) << "\n";
using namespace std;
using ll = long long int;

int main(void){
    int n, wMax, vMax = 0;
    cin >> n >> wMax;
    vector<int> w(n), v(n);
    FOR(i, 0, n){
        cin >> w[i] >> v[i];
        vMax += v[i];
    }

    vector<vector<ll>> dp(n, vector<ll>(vMax+1, wMax+1));
    dp[0][0] = 0, dp[0][v[0]] = w[0];
    
    FOR(i, 1, n){
        FOR(j, 0, vMax+1){
            dp[i][j] = dp[i-1][j];
            if(j >= v[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
        }
    }
    
    int ans = 0;
    FOR(j, 0, vMax+1) if(dp[n-1][j] <= wMax) ans = j;
    COUT(ans);
}

Measured memory_bytes: 79488
S = list(input())
T = []
for i in range(len(S)):
    if i%2 == 0 :
        if S[i] == "L":
            T.append("A")
        
    if i%2 == 1 :
        if S[i] == "R":
            T.append("B")
if "A" in T or "B" in T:
    print("No")
else :
    print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b >= c){
    cout << b+c << endl;
  }else{
    if(c>a+b){
      cout << a+b+b+1 << endl;
    }else{
      cout << a+b+b << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

ll a[110];

int main() {
    int N;
    cin >> N;
    ll ma = 0, mi = LINF;
    rep(i, N) {

        cin >> a[i];
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }
    cout << abs(ma - mi) << endl;
}

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

namelist = []
numlist = []
lenlist = []
for _ in range(n):
    name, num = map(str, input().split())
    if name in namelist:
        numlist[namelist.index(name)] += int(num)
    else:
        namelist.append(name)
        numlist.append(int(num))
        lenlist.append(len(name))

data = []
for name, num, l in zip(namelist, numlist, lenlist):
    data.append([name, num, l])

data = sorted(data, key=lambda x: (x[2], x[0]))

for d in data:
    print(d[0], d[1])



Measured memory_bytes: 5620
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    vector<pair<int,int>> A;
    while(true){
        int x, y;
        cin >> x >> y;
        if(x == 0 and y == 0) break;
        A.emplace_back(min(x, y), max(x, y));
    }
    for(auto p : A){
        cout << p.fi << ' ' << p.se << endl;
    }
}


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

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    ll ans=0;
    rep(i,n-k) ans+=h[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    lint N;
    cin >> N;

    FOR(h, 1, 3501) FOR(n, 1, 3501)
    {
        double w = 1.0 / (4.0 / N - 1.0 / h - 1.0 / n);
        if (w < 3500.5 and w > 0.5 and abs(w - round(w)) < 0.0000001)
        {
            cout << h << " " << n << " " << int(round(w) + 0.1) << endl;
            return 0;
        }
    }
    exit(1);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm> 
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;
}

ll m,n;
ll a[maxn];

ll s;

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	sort(a+1,a+n+1);
	if(a[n-m+1]*4*m>=s)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

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

ll gcd(ll a, ll b)
{
    return a == 0 ? b : gcd(b % a, a);
}

int main()
{
    ll a, b;
    scanf("%lld %lld", &a, &b);

    ll g = gcd(a, b);
    
    int ans = 1;
    for (ll i = 2; i * i <= g; i++) {
        int cnt = 0;
        while (g % i == 0) {
            g /= i;
            cnt++;
        }

        if (cnt > 0)
            ans++;
    }

    if (g > 1)
        ans++;

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

    return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, A, B; cin >> N >> A >> B;
  ll d = B - A;
  

  if (d % 2 == 0) {
    cout << d / 2 << endl;
    return 0;
  }
  ll x = min(A - 1, N - B);
  cout << x + 1 + (d - 1) / 2 << endl;

  return 0;
}



Measured memory_bytes: 3620
n = int(input())
west_east_chars = input()
west_direction_num = [0] * n
east_direction_num = [0] * n

for i in range(1, n):
    if west_east_chars[i-1] == 'W':
        change = 1
    else:
        change = 0
    west_direction_num[i] += west_direction_num[i-1] + change

for i in range(n-2, -1, -1):
    if west_east_chars[i+1] == 'E':
        change = 1
    else:
        change = 0
    east_direction_num[i] += east_direction_num[i+1] + change

ans = 10 ** 10
for a, b in zip(west_direction_num, east_direction_num):
    ans = min(ans, a+b)
print(ans)


Measured memory_bytes: 29088
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n),p(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) cin>>p[i];
  vector<Int> dp(1<<n,0);
  for(Int b=0;b<(1<<n);b++){
    Int t=1;
    for(Int i=0;i<n;i++){
      if((b>>i)&1){
	Int k=a[i]/__gcd(t,a[i]);
	t=(t<=m/k?t*k:m+1);
      }
    }
    dp[b]=m/t;
  }
      
  for(Int i=0;i<n;i++)
    for(Int b=0;b<(1<<n);b++)
      if((b>>i)&1) dp[b]-=dp[b^(1<<i)];
  
  double ans=0;
  for(Int b=0;b<(1<<n);b++){
    double po=1;
    for(Int i=0;i<n;i++)
      if((b>>i)&1) po*=p[i]/100.0;
      else po*=1.0-(p[i]/100.0);
    ans+=po*(m-abs(dp[b]));
  }
  cout<<fixed<<setprecision(12)<<ans<<endl;
  return 0;
}



Measured memory_bytes: 11032
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
#define PI 3.14159265
const int mod=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
bool cmp(int a, int b){
	return a>b;
}
int32_t main(){
	
	FIO();
	
		int n;cin>>n;
		map<string,int> m;
		for(int i=0; i<n; i++){
			string s;cin>>s;
			m[s]++;
		}
		cout<<m.size();

	return 0;
	
		
}


Measured memory_bytes: 19176
#include<bits/stdc++.h>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define inf 10000000000
ll dp[101][100001];
bool vis[101][100001];
ll wajan[101],val[101];
ll n;

ll rec(ll i,ll v)
{
    if(v<=0)
    return 0;
    if(i>n)
    return inf;

   if(vis[i][v])
    return dp[i][v];
    vis[i][v]=1;
    dp[i][v]=rec(i+1,v);
    if(v>=val[i])
    dp[i][v]=MIN(dp[i][v],wajan[i]+rec(i+1,v-val[i]));
   return dp[i][v];
}
int main()
{
    ll w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>wajan[i]>>val[i];
        //minimum weight required to buy items worth value v is denoted by rec(i,v);
       ll i;
       for(i=100000;i>=0;i--)
        if(rec(1,i)<=w)
       {cout<<i;return 0;}

}


Measured memory_bytes: 88960
from _collections import defaultdict
import sys

read = sys.stdin.buffer.read
N = int(input())
A = [int(i) for i in input().split()]
D = defaultdict(int)

for i, a in enumerate(A, 1):
    D[i - a] += 1

ans = 0
for i, a in enumerate(A, 1):
    ans += D[i + a]
print(ans)


Measured memory_bytes: 142272
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int dif = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i+j] != t[j])
                dif++;
        }
        chmin(ans, dif);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y3 - (y2-y1)
print(x3,y3,x4,y4)

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//119
int main() {
	ll N, A, B, C;
	scanf("%lld %lld %lld %lld", &N, &A, &B, &C);

	vector<ll> l(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &l[i]);
	}

	ll result = INF;
	vector<ll> conv(N, 0LL);

	ll num_conv = (ll)pow(4.0, N);
	for (ll iConv = 0; iConv < num_conv - 1; iConv++) {
		vector<ll> len(4, 0); //len[3]�͎g��Ȃ��|
		ll mp = 0;

		for (ll i = 0; i < N; i++) {
			if (conv[i] != 3 && len[conv[i]] > 0) {
				mp += 10;
			}
			len[conv[i]] += l[i];
		}

		if (len[0] == 0 || len[1] == 0 || len[2] == 0) {

		}
		else {
			mp += abs(A - len[0]) + abs(B - len[1]) + abs(C - len[2]);
			result = min(mp, result);
		}

		conv[0]++;
		for (ll i = 0; i < N; i++) {
			if (conv[i] > 3) {
				conv[i + 1]++;
				conv[i] = 0;
			}
		}
	}

	printf("%lld\n", result);

	return 0;
}

//120
/*
int main() {
	static char S[100010];

	scanf("%s", S);

	ll len = strlen(S);

	ll countOne = 0;
	for (ll i = 0; i < len; i++) {
		if (S[i] == '1') {
			countOne++;
		}
	}

	printf("%lld", std::min(countOne, len - countOne) * 2);

	return 0;
}
*/


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

long long cnt;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n)
{
	for (int h = 1; ;) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;

	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i)printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);

	for (int i = 0; i < n; i++) printf("%d\n", A[i]);
	return 0;
}


Measured memory_bytes: 7176
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
const int M=100010;
const int MOD=1000000007;
const long long INF=1000000007;
using ll=long long;

int gcd(int N,int M){
	int tmp;
	if(N<M)return gcd(M,N);
	while(tmp=N%M){
		N=M;
		M=tmp;
	}
	return M;
}
int main(){
	ll n,m;
	string s,t;
	cin>>n>>m;
	cin>>s>>t;
	int x=gcd(n,m);
	ll ans=n*m/x;
	rep(i,0,x)
		if(s[i*n/x]!=t[i*m/x])
		{
			cout<<-1<<endl;
			return 0;
		}
	cout<<ans<<endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    vector<LL> v(N);
    int mi = 0;
    int pl = 0;
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        if(v[i] <= 0) ++mi;
        if(v[i] >= 0) ++pl;
    }

    vector<P> res;
    if(mi == N) {
        for(int i = N - 1; i > 0; --i) {
            res.pb(MP(i, i - 1));
        }
    } else if(pl == N) {
        for(int i = 0; i < N - 1; ++i) {
            res.pb(MP(i, i + 1));
        }
    } else {
        mi = INF;
        pl = 0;
        int mip = 0, mxp = 0;
        for(int i = 0; i < N; ++i) {
            if(mi > v[i]) {
                mi = v[i];
                mip = i;
            }
            if(pl < v[i]) {
                pl = v[i];
                mxp = i;
            }
        }
        if(abs(mi) > abs(pl)) {
            for(int i = 0; i < N; ++i) {
                res.pb(MP(mip, i));
                v[i] += v[mip];
            }
            for(int i = N - 1; i > 0; --i) {
                res.pb(MP(i, i - 1));
            }
        } else {
            for(int i = 0; i < N; ++i) {
                res.pb(MP(mxp, i));
                v[i] += v[mxp];
            }
            for(int i = 0; i < N - 1; ++i) {
                res.pb(MP(i, i + 1));
            }
        }
    }

    cout << res.size() << endl;
    for(P r : res) {
        cout << r.F + 1 << " " << r.S + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))

ans = 0
for j in range(60):
    c0 = 0
    c1 = 0
    for i in range(n):
        if a[i] % 2**(j+1) == 0:
            c0 += 1
        else:
            a[i] -= 2**j
            c1 += 1
    ans += 2 ** j * c0 * c1
    ans %= 10**9 + 7

print(ans)

Measured memory_bytes: 122936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		String ans = "" + s.charAt(0) + (s.length() - 2) + s.charAt(s.length() - 1);
		System.out.println(ans);
		
		sc.close();
	}
}




Measured memory_bytes: 26948
N,K=map(int,input().split())
mod=1000000007
path=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  path[a].append(b)
  path[b].append(a)
#print(path)
  
abc=[False for i in range(N)] #0ならまだ塗ってない

abc[0]=True
cnt=0
ans=K%mod
nx=[]
for i in range(len(path[0])):
  child=path[0][i]
  if abc[child]:
    continue
  ans=ans*(K-1-cnt)
  ans=ans%mod
  cnt=cnt+1
  abc[child]=True
  nx.append(child)
while len(nx)>0:
  a=nx.pop()
  cnt=0
  for i in range(len(path[a])):
    child=path[a][i]
    if abc[child]:
      continue
    ans=ans*(K-2-cnt)
    ans=ans%mod
    cnt=cnt+1
    abc[child]=True
    nx.append(child)
      
print(ans%mod)
      
      
    
    


Measured memory_bytes: 23660
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static int toInt( int hour, int minute ) {
	return hour * 60 + minute;
    }

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int n = stdin.nextInt();
	    final int p = stdin.nextInt();
	    final int q = stdin.nextInt();
	    if ( n == 0 && p == 0 && q == 0 ) {
		break;
	    }
	    final int from = toInt( p / 100, p % 100 );
	    final int to = toInt( q / 100, q % 100 );
	    boolean[][] coms = new boolean[ n ][ to - from ];

	    for ( int i = 0; i < n; i++ ) {
		final int m =  stdin.nextInt();
		for ( int j = 0; j < m; j++ ) {
		    final int mp = stdin.nextInt();
		    final int fm = toInt( mp / 100, mp % 100 );
		    final int mq = stdin.nextInt();
		    final int t = toInt( mq / 100, mq % 100 );
		    
		    Arrays.fill( coms[ i ], fm - from, t - from, true );
		}
	    }
	    //printMap( coms );
	    int count = 0;
	    int maxCount = 0;
	    for ( int i = 0; i < to - from; i++ ){
		boolean flag = false;
		for ( int j = 0; j < n; j++ ){
		    flag |= !coms[ j ][ i ];
		}

		if ( flag ) {
		    count++;
		    maxCount = max( maxCount, count );
		} else {
		    count = 0;
		}
		//System.err.println( count + " " + maxCount );
	    }
	    
	    System.out.println( maxCount );
	}	
    }

    static void printMap( boolean[][] array ) {
	for ( boolean[] ar : array ) {
	    System.err.println( Arrays.toString( ar ) );
	}
    }
}

Measured memory_bytes: 19520
'use strict'

function main(input) {
  input = input.split('\n');
  const NK = input[0].split(' ').map(n => Number(n));
  const countBucket = [...Array(NK[0]+1)].fill(0);
  const A = input[1].split(' ').map(n => Number(n)).forEach(n => countBucket[n] += 1);

  console.log(countBucket.sort((a, b) => b - a).slice(NK[1]).reduce((a, b) => a + b));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 37760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

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

		String[] tmpArray = br.readLine().split(" ");

		long input[] = new long[n];

		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
		}

		Arrays.sort(input);

//		boolean result = true;

		//パターン1　全て0
		if(input[n - 1] == 0){
			System.out.println("Yes");
			return;
		}

		//ここから先はnが3の倍数である必要がある
		if(n % 3 == 0){
			//パターン2　あるxが1/3、他が0
			if(input[0] == 0 && input[n/3 - 1] == 0 && input[n/3] == input[n - 1]){
				System.out.println("Yes");
				return;
			}

			//パターン3　x^y^z=0となるx,y,zが均等枚数
			if(input[0] == input[n/3 - 1] && input[n/3] == input[2*n/3 - 1] && input[2*n/3] ==input[n - 1]
					&& (input[0]^input[n/3]^input[2*n/3]) == 0){
				System.out.println("Yes");
				return;
			}
		}
//

		System.out.println("No");
	}

}


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

ll inf=1ll<<60,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	if (n%10==9||(int)n/10==9){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    int sim = 0;
    for(int i=0; i<n; i++)
    {
        int k = i;
        int cur = 0;
        for(int j=0; j<n && k<n; j++, k++)
        {
            if(t[j] == s[k])
            {
                cur ++;
            }
        }
        sim = max(sim, cur);
    }
    cout << 2*n - sim << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(){
  int N, A[200010], ans = 1;
  int num[200010] = { 0 };
  long long K, i;
  scanf("%ld %lld", &N, &K);
  for (i = 0; i < N; i++) scanf("%ld", A + i);
  for (i = 0; i < K; i++) {
    if (num[ans - 1] == 0) {
      num[ans - 1] = i;
    }
    else {
      K = (K - num[ans - 1]) % (i - num[ans - 1]) + num[ans - 1];
      break;
    }
    ans = A[ans - 1];
  }
  ans = 1;
  for (i = 0; i < K; i++) {
    ans = A[ans - 1];
  }
  printf("%ld", ans);
  return 0;
}


Measured memory_bytes: 3296
#include<iostream>
#include<vector>
#include<utility>
#include<math.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vp;

#define pb push_back
#define mod 1000000007
#define inf 999999999
#define rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = a; i < (n); i++)
#define out(n) cout << n << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  a[0] = toupper(a[0]);
  b[0] = toupper(b[0]);
  c[0] = toupper(c[0]);

  cout << a[0] << b[0] << c[0] << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>

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

int main()
{
	int n;
	scanf("%d,",&n);
	printf("%d\n",(n-2)*180);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int n ,j=1 ,c=0 ;
    cin >> n ;
    int a[n];
    for(int i=0 ; i<n ;i++){
        cin>> a[i] ;
        if(a[i]%2!=0 && j%2!=0)
            c=c+1 ;
        j=j+1 ;

    }
    cout<< c << endl ;
    return 0;
}


Measured memory_bytes: 3604