akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static boolean[][] need;

	public static void main(String[] args) {
		while (sc.hasNext()) {
			String line = sc.next() + "X";
			char prev = line.charAt(0);
			int count = 1;
			for (int i = 1; i < line.length(); ++i) {
				if (line.charAt(i) != prev) {
					write(prev - '0', count);
					prev = line.charAt(i);
					count = 1;
				} else {
					++count;
				}
			}
			System.out.println();
		}
	}

	static String[] table = { "", "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ" };

	static void write(int key, int count) {
		if (key == 0) {
			for (int i = 0; i < count - 1; ++i) {
				System.out.print(' ');
			}
		} else {
			--count;
			System.out.print(table[key].charAt(count % table[key].length()));
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
using namespace std;
constexpr int INFi = 1 << 29;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];
  int ans = INFi;
  vector<vector<int>> dp(h + 1, vector<int>(w + 1, INFi));
  dp[0][0] = s[0][0] == '.' ? 0 : 1;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (i + 1 < h && s[i][j] != s[i + 1][j] && s[i + 1][j] == '#')
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      else if (i + 1 < h)
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if (j + 1 < w && s[i][j] != s[i][j + 1] && s[i][j + 1] == '#')
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
      else if (j + 1 < w)
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
    }
  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> A(n,vector<int>(m));
    vector<int> b(m);
    rep(i,n){
        rep(j,m){
            cin >> A.at(i).at(j);
        }
    }
    rep(i,m)cin >> b.at(i);
    vector<int> ans(n,0);
    rep(i,n){
        rep(j,m){
            ans.at(i) += A.at(i).at(j)*b.at(j);
        }
    }
    rep(i,n) cout << ans.at(i) << endl;
}


Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

// グラフ用ヘッダ

typedef double Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
        src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int n,a,b;
int t[8]; // size n
Graph g;
double dp[32][1<<9];

double inf = 1e100;

string solve(){
    priority_queue<tuple<double,int,int>> q;
    rep(i,32)rep(j,1<<9) dp[i][j] = inf;
    dp[a][0] = 0;
    // -d,v,use
    q.emplace(0,a,0);
    while(q.size()){
        dump(q.size());
        double d; int v,use;
        tie(d,v,use) = q.top(); q.pop();
        dump(d,v,use);
        d = -d;
        if(v==b){
            char buf[100];
            sprintf(buf, "%.10lf", d);
            return buf;
        }
        if(dp[v][use] > d) continue;
        for(const Edge& e : g[v]){
            rep(i,n){
                if(use>>i & 1) continue;
                double nd = d+e.weight/t[i];
                int nu = use | (1<<i);
                if(dp[e.dst][nu] > nd){
                    dp[e.dst][nu] = nd;
                    q.emplace(-nd, e.dst, nu);
                }
            }
        }
    }
    return "Impossible";
}

int main(){
    while(cin>>n && n){
        int m,p;
        cin>>m>>p>>a>>b;
        rep(i,n) cin >> t[i];
        g.assign(m+1,{});
        rep(i,p){
            int x,y,z; cin >> x >> y >> z;
            g[x].eb(x,y,z);
            g[y].eb(y,x,z);
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 2852
#include<cstdio>
#include<algorithm>
using namespace std;
int n,dp[2001][2001],a[4000],b[2001],w[2001],cb[2001][2001],cw[2001][2001];
char s[4000][2];

int bitb[2001],bitw[2001];

int sumb(int i){
    int s=0;
    while(i>0){
        s+=bitb[i];
        i -= (i&-i);
    }
    return s;
}

int addb(int i,int x){
    while(i<=n){
        bitb[i]+=x;
        i+=(i&-i);
    }
}

int sumw(int i){
    int s=0;
    while(i>0){
        s+=bitw[i];
        i -= (i&-i);
    }
    return s;
}

int addw(int i,int x){
    while(i<=n){
        bitw[i]+=x;
        i+=(i&-i);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<2*n;i++){
        scanf("%s %d",s[i],&a[i]);
        if(s[i][0]=='B'){
            b[a[i]]=i;
            for(int j=0;j<=n;j++){
                cb[a[i]-1][j]=sumb(n)-sumb(a[i])+sumw(n)-sumw(j);
            }
            addb(a[i],1);
        }
        else{
            w[a[i]]=i;
            for(int j=0;j<=n;j++){
                cw[j][a[i]-1]=sumb(n)-sumb(j)+sumw(n)-sumw(a[i]);
            }
            addw(a[i],1);
        }
    }
    
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]+cb[i-1][0];
        dp[0][i]=dp[0][i-1]+cw[0][i-1];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=min(dp[i-1][j]+cb[i-1][j],dp[i][j-1]+cw[i][j-1]);
        }
    }
    printf("%d\n",dp[n][n]);
}

Measured memory_bytes: 47104
def search_neighbor(sea, x, y):
    global dir_x, dir_y
    for i in range(4):
        nx, ny = x + dir_x[i], y + dir_y[i]
        if not 0 <= nx < 12 or not 0 <= ny < 12:
            continue
        if sea[ny][nx]:
            sea[ny][nx] = 0
            search_neighbor(sea, nx, ny)


dir_x = (1, -1, 0, 0)
dir_y = (0, 0, 1, -1)

while True:
    sea = [[int(i) for i in input()] for _ in range(12)]
    count = 0

    for i in range(144):
        x, y = i % 12, i // 12
        if sea[y][x]:
            sea[y][x] = 0
            search_neighbor(sea, x, y)
            count += 1

    print(count)

    try:
        input()
    except:
        break

Measured memory_bytes: 7812
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class ADuplexPrinting {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    int ans;
	    if (N & 1) ans = N / 2 + 1;
	    else ans = N/2;
	    out << ans << '\n';
	}
};


int main() {
	ADuplexPrinting solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a.at(i);
    }

    int counter = 0;
    int nextIndex = 0;
    int currenNumber;
    if(a.at(0)==2){
        cout << 1 << endl;
        return 0;
    }
    for(int i=0; i<N; i++){
        counter++;
        currenNumber = a.at(a.at(nextIndex)-1);
        if(currenNumber == 2){
            counter++;
            cout << counter << endl;
            return 0;
        }
        nextIndex = a.at(nextIndex)-1;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    string s;
    cin >> s;
    REP(i, 3){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

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

int main() {

    int a, b;
    char op;

    for ( ;; ) {

        std::cin >> a >> op >> b;

        switch ( op ) {

        case '+': std::cout << a + b << std::endl; break;
        case '-': std::cout << a - b << std::endl; break;
        case '*': std::cout << a * b << std::endl; break;
        case '/': std::cout << a / b << std::endl; break;
        case '?': goto end;

        }

    }

end:

    return 0;
}



Measured memory_bytes: 3096
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long ans = 0;
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[] x = new long[N];
		long[] y = new long[N];
		long[] z = new long[N];
		for(int i = 0; i < N; i++) {
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
			z[i] = sc.nextLong();
		}
		long[] m = new long[3];
		for(int i = 0; i < 1<<3; i++) {
			long[] total = new long[N];
			long ans1 = 0;
			for(int j = 0; j < 3; j++) {
				if((1 & i >> j) == 1)
					m[j] = -1;
				else
					m[j] = 1;
			}
			for(int j = 0; j < N; j++)
				total[j] = m[0]*x[j]+m[1]*y[j]+m[2]*z[j];
			Arrays.sort(total);
			for(int j = N-1; j > N-M-1; j--)
				ans1 += total[j];
			ans = Math.max(ans, ans1);
		}
		System.out.println(ans);

	}

}

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

int h, w, k, ans[303][303];
int clr = 1;
char s[303][303];

void f(int a, int b, int c, int d)
{
  for(int i = a; i < b; i++)
  {
    bool yoko = false;
    for(int j = c; j < d; j++)
    {
      if(s[i][j] == '#')
      {
        if(yoko)
        {
          f(a, b, c, j);
          c = j;
        }
        else yoko = true;
      }
    }
  }
  
  bool tate = false;
  for(int i = a; i < b; i++)
  {
    for(int j = c; j < d; j++)
    {
      if(s[i][j] == '#')
      {
        if(tate)
        {
          f(a, i, c, d);
          a = i;
        }
        else tate = true;
      }
    }
  }
  
  for(int i = a; i < b; i++)
  {
    for(int j = c; j < d; j++)
    {
      ans[i][j] = clr;
    }
  }
  clr++;
  
  return;
}

int main()
{
  cin >> h >> w >> k;
  rep(i,h)rep(j,w) cin >> s[i][j];
  
  f(0, h, 0, w);
  
  rep(i,h)
  {
    rep(j,w) cout << ans[i][j] << ((j+1 == w)? "\n" : " ");
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
 
int main(void) {
  unsigned long long int N, A, B, amari, Ans;
  scanf("%llu %llu %llu", &N, &A, &B); 
  amari = N % (A + B);
  if(amari>A) {
    Ans = A + (N - amari) / (A + B) *A;
  }
  else {
    Ans = amari + (N - amari) / (A + B) * A;
  }
  printf("%llu", Ans);
  return 0;
}


Measured memory_bytes: 128
#c
h, w, k=map(int, input().split())
s = [input() for i in range(h)]

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
ans = 0
count = 0
for i in range(h):
    count += s[i].count("#")

for i in range(2 ** (h+w)):
    bag = []
    for j in range(h+w):  # このループが一番のポイント
        if ((i >> j) & 1): 
            bag.append(j)
    d_count = []
    for p in bag:
        
        if p < h:#行
            for r in range(w):
                if s[p][r] == "#":
                    d_count.append([p,r])
        else:#列
            for c in range(h):
                if s[c][p-h] == "#":
                    d_count.append([c,p-h])
    if count - len(get_unique_list(d_count)) == k:
        ans += 1
print(ans)
        

Measured memory_bytes: 9236
s=input()
if s[1:2]=="R":
  if s[0:1]=="R"and s[2:3]=="R":
    print(3)
  elif s[0:1]=="S"and s[2:3]=="S":
    print(1)
  else:
    print(2)
elif "R" in s:
  print(1)
else:
  print(0)


Measured memory_bytes: 8972
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    a--;  b--;  c--;  d--;
    
    if (c < d) {
        for (int i = b; i < d; i++) {
            if (char(s[i]) == '#' && char(s[i + 1]) == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = a; i < c; i++) {
            if (char(s[i]) == '#' && char(s[i + 1]) == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else {
        int pass = false;
        for (int i = b - 1; i < d; i++) {
            string test;
            for (int j = i; j < i + 3; j++) test += s[j];
            //cout << test << endl;
            if (test == "...") {
                pass = true;
            }
        }
        //cout << pass<<endl;
        for (int i = a; i < c; i++) {
            if (char(s[i]) == '#' && char(s[i + 1]) == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        if (pass) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
int main() {
    char s[10001];
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    
    int len = strlen(s);
    int a = (int)'A';
    int z = (int)'Z';
    for(int i = 0; i < len; i++) {
        int c = (int)s[i] - a;
        printf("%c", (char)((c + n) % (z - a + 1) + a));
    }
}

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

int main() {
	int n, cnt = 0;
	cin>>n;
	char ch;
	for(int i = 0; i<n; i++){
		char s;
		cin>>s;
		if(s != ch)
		ch = s, cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		int n = Integer.parseInt(input);
		int x = 0;

		if (n >= 3 && n <= 10000) {
			for (int i = 1; i <= n; i++) {
				if (i % 3 == 0) {
					System.out.print(" " + i);
				} else {
					x = i;

					while ((x >= 10) && ((x % 10) != 3)) { // 3を含む値をチェックして、あれば出力するプログラム
						x /= 10;
					}

					if (x % 10 == 3) {
						System.out.print(" " + i);
					}
				}

			}

		}
		System.out.println();
	}
}



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

#define  prec(n)        fixed<<setprecision(n)
#define  optimize       ios::sync_with_stdio(0); cin.tie(0);
#define  PI             acos(-1.0)
#define  RESET(a, b)    memset(a, b, sizeof(a))
#define  pb             push_back
#define  pii            pair<int,int>
#define  pll            pair<ll,ll>
#define  vv             vector<int>
#define  ff             first
#define  ss             second
#define  sz(v)          v.size()
#define  all(v)         v.begin(),v.end()

int const MOD=(int) 1e9+7;
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return m-(abs(a)%m); else if(a<m) return a; else return (a%m); }
const int N = 200007;
const int MAX=1000005;

int main()
{
    optimize
    int n; cin>>n;
    if(n==1) cout<<0<<endl;
    else cout<<1<<endl;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        if(b==1)
            cout<<"Bob";
        else cout<<"Alice";
    }
    if(b>a)
    {
        if(a==1)
            cout<<"Alice";
        else cout<<"Bob";
    }
    if(a==b) cout<<"Draw";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int length=0,i=0,sum=0;
            String ring1="";
            boolean first=true;
            
            while ((line = br.readLine()) != null) {
	            if(first){
	            	ring1=line;
	            	length=Integer.parseInt(br.readLine());
	            	first=false;
	            	i=0;
	            }else{
	            	String toring=line+line;
	            	i++;
	            	for(int k=0;k<toring.length()-ring1.length();k++){
	            		if(ring1.equals(toring.substring(k, k+ring1.length()))){
	            			sum++;
	            			break;
	            		}
	            	}
	            	if(i==length){
	            		System.out.println(sum);
	            		break;
	            	}
	            }
            }
        }
    }


}

Measured memory_bytes: 24252
#include <stdio.h>

int main() {
    int x, y;
    while (scanf("%d%d", &x, &y) == 2 && (x || y)) {
        if (x > y) {
            printf("%d %d\n", y, x);
        } else {
            printf("%d %d\n", x, y);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	int n, m, c, a, num = 0, ans = 0;
	cin >> n >> m >> c;
	vector<int>b(m);
	for (int i = 0;i < m;i++)cin >> b[i];
	for (int i = 0;i < n;i++) {
		num = 0;
		for (int i = 0;i < m;i++) {
			cin >> a;
			num += a * b[i];
		}
		if (num+c>0)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long LL;

int main() {
	LL A, B, C, D;
	cin >> A >> B >> C >> D;
	LL x1 = B / C - A / C + (A % C == 0);
	LL x2 = B / D - A / D + (A % D == 0);
	LL E = C * D / __gcd(C, D);
	LL x3 = B / E - A / E + (A % E == 0);
	LL tot = x1 + x2 - x3;
	printf("%lld\n", B - A + 1 - tot);
}

Measured memory_bytes: 256
// finish date: 2018/08/19
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


bool ex(int n) {
    int cnt =0;
    FOR(i, 1, n + 1) if (n % i == 0) cnt++;
    if(cnt==8) return true;
    else return false;

}

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

    int cnt = 0;
    for (int i = 1; i <= N; i += 2) {
        if (ex(i)) cnt++;
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000007

void func()
{
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n+1],b[m+1];a[0]=0;b[0]=0;
    loop(i,1,n+1){
        cin>>a[i];
    }
    loop(i,1,m+1){
        cin>>b[i];
        b[i]=b[i]+b[i-1];
    }
    ll sum=0,ans=0;
    loop(i,0,n+1){
        sum=sum+a[i];
        if(sum<=k){
            auto x=lower_bound(b,b+m+1,(k-sum))-b;
            if(b[x]==(k-sum)&&x<=m){
                ans=max(ans,i+x);
                //cout<<x<<" "<<ans<<"\n";
            }
            else if(b[x]!=(k-sum)&&x<=m){
                ans=max(ans,i+x-1);
                //cout<<x<<" "<<ans<<" "<<i<<"\n"; 
            }
        }
    }
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 6732
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

struct Node{
	int key;
	Node *l;
	Node *r;
	Node *p;
};
Node *nil = new Node{INT_MAX};

vector<int> pre, in;
void preorder(Node *node){
	pre.push_back(node->key);
	if(node->l != nil) preorder(node->l);
	if(node->r != nil) preorder(node->r);
}

void inorder(Node *node){
	if(node->l != nil) inorder(node->l);
	in.push_back(node->key);
	if(node->r != nil) inorder(node->r);
}

void print(vector<int> v){
	r(i, s(v))
		cout << ' ' << v[i];
	cout << endl;
}

void printPreorder(Node *node){
	pre.clear();
	preorder(node);
	print(pre);
}

void printInorder(Node *node){
	in.clear();
	inorder(node);
	print(in);
}

void insert(Node *T, int key){
	Node *z = new Node{key, nil, nil, nil};
	if(T->key == INT_MAX){
		*T = *z;
		return;
	}
	Node *x = T;
	Node *y = x->p;
	while(x != nil){
		y = x;
		x = (key < x->key) ? x->l : x->r;
	}
	z->p = y;
	if(key < y->key){
		y->l = z;
	}else{
		y->r = z;
	}
}

Node* find(Node *node, int key){
	if(node == nil) return nil;
	int cmp = node->key;
	if(key == cmp) return node;

	return find( (key<cmp) ? node->l : node->r , key);
}

bool contains(Node *node, int key){
	return find(node, key) != nil;
}

Node* successor(Node *z){
	Node *succ = z->r;
	while(succ->l != nil){
		succ = succ->l;
	}
	return succ;
}

void remove(Node *z){
	bool isl = z->p->l == z;
	if(z->l == nil){
		if(z->r == nil){
			if(isl){
				z->p->l = nil;
			}else{
				z->p->r = nil;
			}

		}else{
			z->r->p = z->p;
			if(isl){
				z->p->l = z->r;
			}else{
				z->p->r = z->r;
			}
		}

	}else{
		if(z->r == nil){
			z->l->p = z->p;
			if(isl){
				z->p->l = z->l;
			}else{
				z->p->r = z->l;
			}

		}else{
			Node *succ = successor(z);
			isl = succ->p->l == succ;
			if(isl){
				succ->p->l = succ->r;
			}else{
				succ->p->r = succ->r;
			}
			z->key = succ->key;
		}
	}
}

void remove(Node *node, int key){
	Node *z = find(node, key);
	if(z != nil)
		remove(z);
}

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

	Node *root = new Node{INT_MAX};
	string cmd;
	int arg;
	r(i, m){
		cin >> cmd;
		switch(cmd[0]){
		case 'i':
			cin >> arg;
			insert(root, arg);
			break;
		case 'f':
			cin >> arg;
			cout << (contains(root, arg) ? "yes" : "no") << endl;
			break;
		case 'd':
			cin >> arg;
			remove(root, arg);
			break;
		default:
			printInorder(root);
			printPreorder(root);
		}
	}

	return 0;
}



Measured memory_bytes: 26872
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,t,a[1000010];
char s[1000010];
int C(int x,int y){
	if (y>x) return 0;
	if (y==0) return 1;
	if (x%2==0 && y%2==1) return 0;
	return C(x>>1,y>>1);
}
int main(){
	cin>>n;
	scanf("%s",s+1);
	FOR(i,1,n-1) a[i]=abs(s[i]-s[i+1]);
	--n;
	if (n==1){cout<<a[1]<<endl; return 0;}
	FOR(i,0,n-1) if (C(n-1,i)) t+=a[i+1];
	if (t%2==1){puts("1");return 0;}
	FOR(i,1,n) if (a[i]==1){puts("0");return 0;}
	t/=2;
	if (t%2==0) puts("0"); else puts("2");
	return 0;
}

Measured memory_bytes: 5120
n = int(input())
vert = [[0,0]+list(map(int,range(1,n+1)))]
parents = [0]
now = 0
time = 0
for i in range(n):
    ukv = list(map(int,input().split()))
    vert.append([0,0]+ukv[2:])
while(parents):
    for i in range(2,len(vert[now])):
        if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
    else:
        if now != 0:
            time += 1
        vert[now][1] = time
        now = parents.pop()
for i in range(1,n+1):
    print(i,*vert[i][0:2])


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  int n;cin >> n;
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  rep(i,n) {
    string s;cin >> s;
    if(s == "AC") a++;
    if(s == "WA") b++;
    if(s == "TLE") c++;
    if(s == "RE") d++;
  }
  cout << "AC" << " " << "x" << " " << a << endl;
  cout << "WA" << " " << "x" << " " << b << endl;
  cout << "TLE" << " " << "x" << " " << c << endl;
  cout << "RE" << " " << "x" << " " << d << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix

struct UnionFind {
    vector<int> parent;
    int size;
    UnionFind(int n) :parent(n, -1), size(n) {}
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y)return false;
        if (sizeOf(x) < sizeOf(y))swap(x, y);
        parent[x] += parent[y]; parent[y] = x; size--;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
    int sizeOf(int x) { return -parent[root(x)]; }
};

signed main()
{
    int2(n, k);
    Int(l);
    UnionFind road(n), line(n);
    rep(i, k) {
        int2(a, b);
        road.unite(a-1, b-1);
    }
    rep(i, l) {
        int2(a, b);
        line.unite(a-1, b-1);
    }
    map< i_i, int > funami;
    rep(i, n) {
        funami[i_i(road.root(i), line.root(i))]++;
    }

    rep(i, n) {
        std::cout << funami[i_i(road.root(i), line.root(i))] << " ";
    }
    cout << endl;

    return 0;
}




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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;  cin >> s;
    int a, b, c, d;
    a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';

    if (a + b + c + d == 7) {
      cout << a << "+" << b << "+" << c << "+" << d << "=7";
    } else if (a + b + c - d == 7) {
      cout << a << "+" << b << "+" << c << "-" << d << "=7";
    } else if (a + b - c + d == 7) {
      cout << a << "+" << b << "-" << c << "+" << d << "=7";
    } else if (a - b + c + d == 7) {
      cout << a << "-" << b << "+" << c << "+" << d << "=7";
    } else if (a + b - c - d == 7) {
      cout << a << "+" << b << "-" << c << "-" << d << "=7";
    } else if (a - b - c + d == 7) {
      cout << a << "-" << b << "-" << c << "+" << d << "=7";
    } else if (a - b + c - d == 7) {
      cout << a << "-" << b << "+" << c << "-" << d << "=7";
    } else {
      cout << a << "-" << b << "-" << c << "-" << d << "=7";
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtTest.ABC_105
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var array = new int[n];
            var sums = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(input[i]);
                if (i == 0)
                {
                    sums[i] = array[i] % m;
                }
                else
                {
                    sums[i] = (sums[i - 1] + array[i])%m;
                }
            }

            var marginDict = new Dictionary<int, int>();
            marginDict.Add(0, 1);
            long cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (marginDict.ContainsKey(sums[i]))
                {
                    cnt += marginDict[sums[i]];
                    marginDict[sums[i]]++;
                }
                else
                {
                    marginDict.Add(sums[i], 1);
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 20064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    ll a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    ll x,y;
    if(n%2==1)
    {
        x=a[(n-1)/2];
        y=b[(n-1)/2];
    }
    else
    {
        x=a[(n-2)/2]+a[(n)/2];
        y=b[(n-2)/2]+b[n/2];
    }
    cout<<y-x+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 6748
lst = [int(input()) for i in range(5)]

lst = sorted(lst, key =lambda x: 10 if x%10==0 else x%10, reverse = 1)
ans = 0
for l in lst[:4]:
    if l%10 == 0:
        ans += l
    else:
        ans += l//10*10 + 10
ans += lst[4]
print(ans)

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

int main(){
    int n;
    cin >> n;
    
    int a[5][4][11]={0};
    int b,f,r,v;
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        a[b][f][r]+=v;
    }
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                cout<<" "<<a[i][j][k];
            }
            cout<<endl;
        }
        if(i!=4)cout<<"####################"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}
#define int long long
inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,m;
bool gi;
int he,to;
int num[100005];
int col[100005],vis[100005];
int h[100005],t[200005],ne[200005],e;
void add(int x,int y){
   t[++e]=y;
   ne[e]=h[x];
   h[x]=e;
}
void dfs1(int x,int ff){
    vis[x]=1; 
	for(int i=h[x];i;i=ne[i]){
	    int v=t[i]; 
		if(v!=ff){
            if(vis[v]){
                he=x;to=v;
                if(col[he]==col[to])gi=1;
            }
            else{
                col[v]=col[x]^1;
                dfs1(v,x);
            }
        }
	 }
}
int num2[100005];
int sum;
long long ans;
void dfs2(int x,int ff){
    for(int i=h[x];i;i=ne[i]){
		int v=t[i];
	    if(v!=ff&&!(x==he&&t[i]==to||x==to&&t[i]==he)){
		    dfs2(v,x);
			num2[x]+=num2[v];
			num[x]+=num[v];
		}
	}
}
int stk[100005],top;
signed main () {
#ifndef ONLINE_JUDGE
//file("agc004f");
#endif
    n=read();
	m=read();
	F(i,1,m){
	   int x=read(),y=read();
	   add(x,y);
	   add(y,x);
	}
	col[1]=1;
	dfs1(1,0);
	F(i,1,n){
		if(col[i])num[i]=1;
		else num[i]=-1;
	}
	F(i,1,n)sum+=num[i];
	if(m==n-1){
	  if(sum){
		  puts("-1");
		  return 0;
	  }
	}
	else{
	   if(gi){
	     if(sum%2==1){
			 puts("-1");
		 return 0;
		 }
		 num[he]-=(sum/2);
		 num[to]-=(sum/2);
		 ans+=1ll*abs(sum/2);
	   }
	   else{
	      if(sum){
		     puts("-1");
			 return 0;
		  }
		  num2[he]=1;
		  num2[to]=-1;
	   }
	}
	dfs2(1,0);
	F(i,1,n){
		if(!num2[i])ans+=1ll*abs(num[i]);
	    else{
		  if(num2[i])num[i]=-num[i];
			stk[++top]=num[i];
		}
	}
	stk[++top]=0;
	sort(stk+1,stk+top+1);
	int X=stk[(top+1)/2];
	F(i,1,top)ans+=1ll*abs(stk[i]-X);
	printf("%lld\n",ans);
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  bool sim = false;
  if(s.at(2) == s.at(3)){
    if(s.at(4) == s.at(5)){
      cout << "Yes" << endl;
      sim = true;
    }
  }
  
  if(!sim) cout << "No" << endl;
  
    
}

Measured memory_bytes: 3608
#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++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    int k;
    cin >> k >> s;
    if(s.size()<=k) cout<< s<< endl;
    else{
        cout<<s.substr(0,k)<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#define DMAX 10
int main(void)
{
  int i, j, d, g, p[DMAX], c[DMAX], mpnum = 0;
  scanf("%d %d", &d, &g);
  for (i = 0; i < d; i++) {
    scanf("%d %d", &p[i], &c[i]);
    mpnum += p[i];
  }
  for (i = 0; i < 1 << d; i++) {
    int ans = 0, pnum = 0, mres = -1;
    for (j = 0; j < d; j++) {
      if ((i >> j) & 1) {
        ans += (j + 1) * 100 * p[j] + c[j];
        pnum += p[j];
      } else mres = j;
    }
    if (ans < g) {
      int rnum = (g - ans - 1) / (100 * (mres + 1))+ 1;
      if (rnum >= p[mres]) continue;
      pnum += rnum;
    }
    if (pnum < mpnum) mpnum = pnum;
  }
  printf("%d\n", mpnum);
}

Measured memory_bytes: 128
n = int(input())
a = []
for _ in range(2):
    a.append(
        list(map(int, input().split()))
    )
"""
n = 5
a = [
    [3, 2, 2, 4, 1],
    [1, 2, 2, 2, 1]
    ]
"""
tmp = [0] * n
for i in range(n):
    tmp[i] = sum(a[0][:i+1]) + sum(a[1][i:])
print(max(tmp))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, w, weight[110], value[110];
ll dp[110][100100];

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

    for(int i = 0; i < n; i++){
        for(int sum_w = 0; sum_w <= w; sum_w++){

            if(sum_w - weight[i] >= 0) {
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);

        }
    }

    cout << dp[n][w] << endl;
}

Measured memory_bytes: 79360
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
  if d.get(i):d[i]+=1
  else:d[i]=1
ans=0
for i in d:
  ans+=d[i]*(d[i]-1)//2
for i in a:
  print(ans-(d[i]-1))

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

int main() {
  string S;
  bool ok = true;

  cin >> S;

  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0 && S[i] == 'L') {
      ok = false;
    }
    if (i % 2 != 0 && S[i] == 'R' ) {
      ok = false;
    }
  }

  cout << (ok?"Yes":"No");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int64_t i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

static const int64_t kRem = 1000000007;

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

	int64_t counts[60] = {0};

	int n; cin >> n;
	FOR_LT(i, 0, n) {
		int64_t a; cin >> a;
		FOR_LT(j, 0, 60) {
			if (a & (1LL << j)) counts[j]++;
		}
	}

	int64_t ans = 0;
	FOR_LT(i, 0, 60) {
		int64_t c = counts[i] * (n - counts[i]);
		c %= kRem;
		int64_t v = (1LL << i);
		v %= kRem;
		int64_t ca = c * v;
		ca %= kRem;
		ans += ca;
		ans %= kRem;
	}
	cout << ans << endl;

	return 0;
}

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

class node{
public:
  int v;
  node *p, *l, *r;
};

node *nil;

void pr(node *c){
  if(c == nil) return;
  cout << " " << c->v;
  pr(c->l);
  pr(c->r);
  return;
}
void in(node *c){
  if(c == nil) return;
  in(c->l);
  cout << " " << c->v;
  in(c->r);
  return;
}
void po(node *c){
  if(c == nil) return;
  po(c->l);
  po(c->r);
  cout << " " << c->v;
  return;
}

void solve(){
  int m; cin >> m;
  vector<string> s(m);
  vector<int> a(m);
  for(int i = 0; i < m; i++){
    cin >> s[i];
    if(s[i] != "print"){
      cin >> a[i];
    }
  }

  node *root = nil;
  for(int i = 0; i < m; i++){
    if(s[i] == "insert"){
      int x = a[i];
      if(root == nil){
        node *y = new node;
        root = y;
        root->v = x;
        root->p = nil;
        root->l = nil;
        root->r = nil;
        continue;
      }
      bool left;
      node *c = root;
      node *p = nil;
      while(c != nil){
        p = c;
        if(x < c->v){
          left = true;
          c = c->l;
        }
        else{
          left = false;
          c = c->r;
        }
      }
      node *y = new node;
      y->p = p;
      if(left == true) p->l = y;
      else p->r = y;
      y->l = nil;
      y->r = nil;
      y->v = x;
    }
    else if(s[i] == "find"){
      int x = a[i];
      node *c = root;
      while(c != nil){
        if(x == c->v) break;
        else if(x < c->v) c = c->l;
        else c = c->r;
      }
      if(c != nil) cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else{
      in(root);
      cout << endl;
      pr(root);
      cout << endl;
    }
  }
}

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



Measured memory_bytes: 50888
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
       N:usize,
       UV:[(Usize1,Usize1);N-1]
    }
    // 各長さごとに各頂点の含まれる回数は...。
    // 長さNなら1回*N頂点、長さN-1なら2(N-1)...(N-1)*2, N*1
    let mut ans = 0;
    for i in 1..=N {
        ans += i * (N + 1 - i);
    }
    // 辺の含まれる回数は…？
    // 例えば　u,vなら、0,1,...u × v,v+1...N-1 なので、(u+1)*(N-v)
    for &(u, v) in UV.iter() {
        ans -= if u < v {
            (u + 1) * (N - v)
        } else {
            (v + 1) * (N - u)
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 7640
using System;
class main
{
    static void Main(string[] args)
    {
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            double x1, y1, x2, y2, x3, y3, px, py, abc, abp, pbc, apc;
            string[] a = s.Split(' ');
            x1 = double.Parse(a[0]);
            y1 = double.Parse(a[1]);
            x2 = double.Parse(a[2]);
            y2 = double.Parse(a[3]);
            x3 = double.Parse(a[4]);
            y3 = double.Parse(a[5]);
            px = double.Parse(a[6]);
            py = double.Parse(a[7]);
            abc = Math.Abs(((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))) * 0.5);
            abp = Math.Abs(((x1 * (y2 - py)) + (x2 * (py - y1)) + (px * (y1 - y2))) * 0.5);
            pbc = Math.Abs(((px * (y2 - y3)) + (x2 * (y3 - py)) + (x3 * (py - y2))) * 0.5);
            apc = Math.Abs(((x1 * (py - y3)) + (px * (y3 - y1)) + (x3 * (y1 - py))) * 0.5);
            if ((abp + pbc + apc) - abc < 0.001)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 5752
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    cout << ((n >= 195) ? 5 : (n >= 189) ? 4 : (n >= 165) ? 3 : (n >= 135) ? 2 : (n >= 105) ? 1 : 0) << "\n";
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

int main() {
  ll N;
  cin >> N;
  vi A(N);
  vvi x(N), y(N);

  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    for (ll j = 0; j < A[i]; j++) {
      ll a, b;
      cin >> a >> b;
      a -= 1;
      x[i].push_back(a);
      y[i].push_back(b);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < (1 << N); i++) {
    vi v;
    ll k = i;
    ll cnt = 0;
    for (ll j = 0; j < N; j++) {
      if (k % 2) cnt++;
      if (k % 2) v.push_back(1);
      else v.push_back(0);
      k /= 2;
    }
    bool ok = true;
    for (ll j = 0; j < N; j++) {
      if (v[j] == 0) continue;
      for (ll k = 0; k < A[j]; k++) {
        if (y[j][k] == 1 && v[x[j][k]] == 0) ok = false;
        if (y[j][k] == 0 && v[x[j][k]] == 1) ok = false;
      }
    }
    if (ok) ans = max(ans, cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[1000];
long long k;
int main() {
    scanf("%s",s);
    scanf("%lld",&k);
    bool as=true;
    long long n=strlen(s);
    for(int i=1;i<n;i++) {
        if(s[i]!=s[i-1]) {
            as=false;
            break;
        }
    }
    if(as) {
        printf("%lld",n*k/2);
        return 0;
    }
    bool fst=true;
    long long m=1;
    bool eq=s[n-1]==s[0];
    long long ans=0;
    for(int i=1;i<n;i++) {
        if(s[i]!=s[i-1]) {
            if(!eq || !fst) {
                ans+=k*(m/2);
            }
            else {
                ans+=(m/2);
            }
            fst=false;
            m=1;
        }
        else m++;
    }
    if(!eq) {
        ans+=k*(m/2);
    }
    else {
        ans+=(m/2);
    }
    if(eq) {
        m=0;
        for(int i=0;i<n && s[i]==s[0];i++) m++;
        for(int i=n-1;i>=0 && s[i]==s[0];i--) m++;
        ans+=(k-1)*(m/2);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256