akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define MOD 998244353
typedef long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector< pair<int,int> > plus;
    vector< pair<int,int> > minus;
    rep(i,n){
        string t;
        cin>>t;
        int minimum=0, count=0;
        rep(j,t.length()){
            if(t[j]=='(')count++;
            else count--;
            minimum=min(minimum,count);
        }
        if(count>0){
            pair<int,int> ttt;
            ttt.first=minimum;
            ttt.second=count;
            plus.pb(ttt);
        }
        else{
            int minimum=0, count=0;
            for(int j=t.length()-1;j>=0;j--){
                if(t[j]==')')count++;
                else count--;
                minimum=min(minimum,count);
            }
            pair<int,int> ttt;
            ttt.first=minimum;
            ttt.second=count;
            minus.pb(ttt);
        }
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());

    ll countplus=0, countminus=0;
    for(int i=plus.size()-1;i>=0;i--){
        if(countplus<(-plus[i].first)){
            No;
            return 0;
        }
        else{
            countplus+=plus[i].second;
        }
    }
    for(int i=minus.size()-1;i>=0;i--){
        if(countminus<(-minus[i].first)){
            No;
            return 0;
        }
        else{
            countminus+=minus[i].second;
        }
    }
    if(countplus==countminus)Yes;
    else No;
    return 0;
}


Measured memory_bytes: 11276
n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i + 1] = cumsum[i] + A[i]
    cumsum[i + 1] %= mod

ans = 0

for i in range(n - 1):
    ans += A[i] * (cumsum[-1] - cumsum[i + 1])
    ans %= mod
print(ans)


Measured memory_bytes: 93920
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
ans = 0
if n >= m
  puts 0
else
  x.sort!
  d = Array.new(m-1)
  for i in 0..(m-2)
    d[i] = x[i+1] - x[i]
  end
  d.sort!{|a, b| b <=> a}
  for i in (n-1)..(m-2)
    ans += d[i]
  end
  puts ans
end

Measured memory_bytes: 9712
N = int(input())
ls1 = list(map(int, input().split()))

a=0
al1=sum(ls1)
b=al1

for i in range(len(ls1)):
    c1=abs(a-b)
    a=sum(ls1[:i+1])
    b=al1-a
    c2=abs(a-b)
    if c1<c2:
        print(c1)
        break


Measured memory_bytes: 62988
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int[] b = new int[n];
		System.arraycopy(a, 0, b, 0, n);
		Arrays.parallelSort(b);

		if (b[n - 1] == b[n - 2]) {
			for (int i = 0; i < n; i++) {
				System.out.println(b[n - 1]);
			}
		} else {
			for (int i = 0; i < n; i++) {
				if (a[i] == b[n - 1]) {
					System.out.println(b[n - 2]);
				} else {
					System.out.println(b[n - 1]);
				}
			}
		}
	}
}


Measured memory_bytes: 94372
using System;

namespace question3
{
    class Program
    {
        static void Main(string[] args)
        {


            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i]= int.Parse(Console.ReadLine());
            }
            //最大値の模索
            int max1 = -1;
            for (int i = 0; i < n; i++)
            {
                if (max1 < a[i]) max1 = a[i];
            }
            //最大値が被ってないか検索
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                if (max1 == a[i])count++;
            }
            //二番目に大きい値の模索
            int max2 = -1;
            for (int i = 0; i < n; i++)
            {
                if ((max2 < a[i]) && (a[i]<max1)) max2 = a[i];
            }

            //Console.WriteLine("Hello World!");

            for (int i = 0; i < n; i++)
            {
                if (a[i] != max1) Console.WriteLine(max1.ToString());
                else if (count>1) Console.WriteLine(max1.ToString());
                else Console.WriteLine(max2.ToString());
            }


            //Console.ReadLine();

        }
    }
}


Measured memory_bytes: 16972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}


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

const char *weekday_str[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
enum WD { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
enum WD zeller(int year, int mon, int day){
    if(year < 1582 || mon < 1 || day < 1) throw;
    if(mon <= 2){ year--; mon += 12; }
    unsigned int h = (year + year/4 - year/100 + year/400 + (13*mon+8)/5 + day) % 7;
    return (WD)h;
}

int main(){
    int m, d;
    while(cin >> m >> d){
        if(m == 0 && d == 0) break;
        WD wd = zeller(2004, m, d);
        cout << weekday_str[wd] << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
n,m,h = map(str,input().split())
ans = []
n = int(n)
m = int(m)
for i in range(m):
  ss = ""
  for j in range(n):
    if i == m//2 and j == n//2:ss += h
    elif (i == 0 or i == m-1) and (j == 0 or j == n-1):ss += "+"
    elif i == 0 or i == m-1:ss += "-"
    elif j == 0 or j == n-1:ss += "|"
    else:ss += "."
  ans.append(ss)

for i in range(m):print("".join(ans[i]))


Measured memory_bytes: 5596
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n, a, b; cin >> n >> a >> b;
    vector<int> C(3);
    rep(i, n){
        int p; cin >> p;
        if(p<=a)C[0]++;
        else if(p<=b)C[1]++;
        else C[2]++;
    }
    cout << *min_element(all(C)) << ln;
}


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

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i=0;i<N;i++) cin >> s.at(i);
  int M;
  cin >> M;
  vector<string> t(M);
  for(int i=0;i<M;i++) cin >> t.at(i);
  
  int max=0, count;
  string NON = "non";
  for(int i=0;i<N;i++){
    count=1;
    if(s[i] == NON) continue;
    if(i!=N-1){
      for(int j=i+1; j<N;j++){
        if(s[i] == s[j]){
          count++;
          s[j] = NON;
        }
      }
    }
    for(int k=0; k<M; k++){
      if(count < 0) break;
      if(s[i]==t[k]) count--;
    }
    if(count>max) max = count;
  }
  
  cout << max << endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,w=0,e=0;
  cin >> a >> b;
  int x = b-a;
  for(int i=0; i<x; i++){
    w += i;
    if(i==x-1){
      i++;
      e = w+i;
      break;
    }
  }
  int ans = e-b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
  string s, double_s, p;
  cin>>s>>p;
  double_s = s + s;
  if(strstr(double_s.c_str(), p.c_str())==NULL) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 3204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0363>
?????????============================================================
????´\??????????????????????????°???????????????????????????????????????????????????
 ??????????????????????????????????????????????????§????????§????¨?????????????????????????????????§?????????
 ??¨?????????????????¢??§????¨???????????????§??????????????????????????????????????????????????§?????????
 ???????????????????¨???¨????????????????????????????????¨????????????????¢?????????????????????????????????????????????????????????????????????????????????§???????????????
 ????????????????????????????????????????????????????????¨?????§????????????????????????????????????????????????????????????
 
 ?????¨?????????????????¨????????????????????§????????????????????§??????????????????????????§??§??????????????????????????\????????????
 ??¨???????????????????????¨??????????????§???????????????????????????????????????????????¨??????
 ?????§??§??????????????????????????????????????±?????????????????°????????????????????????
=================================================================

?§£??¬=============================================================
 dp[i][S] := i-1???????????§????????????i-1?????????????????¶??????S??????????????§?????°
================================================================
*/

ll H,N;
ll dp[10010][1<<4];
bool masu[10010][4];

bool ok(int x,int y,int S){
    if(x < 3 && y < H - 1){
        return !masu[y][x] && !masu[y][x+1] && !masu[y+1][x] && !masu[y+1][x+1] && !((S>>x)&1) && !((S>>(x+1))& 1);
    }else return false;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> N;
    for(int i = 0; i < N;i++){
        ll x,y; cin >> x >> y;
        masu[y][x] = true;
    }
    for(int i = 0; i < H;i++){
        for(int j = 0; j < (1<<4);j++){
            if(ok(0,i,j)){
                if(ok(2,i,j)){
                    dp[i+1][(1<<4)-1] = max(dp[i+1][(1<<4)-1],dp[i][j]+2);
                }
                dp[i+1][(1<<2)-1] = max(dp[i+1][(1<<2)-1],dp[i][j]+1);
            }
            if(ok(1,i,j)){
                dp[i+1][6] = max(dp[i+1][6],dp[i][j]+1);
            }
            if(ok(2,i,j)){
                dp[i+1][12] = max(dp[i+1][12],dp[i][j]+1);
            }
            dp[i+1][0] = max(dp[i+1][0],dp[i][j]);
        }
    }
    ll res = 0;
    for(int i = 0; i < (1<<4);i++){
        res = max(res,dp[H][i]);
    }
    cout << res << endl;
	return 0;
}

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

class SegmentTree {
private:
	std::vector<int64_t> sumContainer_, updateContainer_;
	int tree_width_;

	void lazyEvaluate(const int node_i)
	{
		if (updateContainer_[node_i] == LLONG_MAX) return;
		sumContainer_[node_i] = updateContainer_[node_i];
		if (node_i < tree_width_)
		{
			updateContainer_[2 * node_i] = updateContainer_[node_i] >> 1;
			updateContainer_[2 * node_i + 1] = updateContainer_[node_i] >> 1;
		}
		updateContainer_[node_i] = LLONG_MAX;
	}

	void updateImplement(const int query_l, const int query_r, const int node_l, const int node_r, const int node_i, const int64_t assigned)
	{
		if (query_l <= node_l && node_r <= query_r)
		{
			updateContainer_[node_i] = assigned;
			lazyEvaluate(node_i);
			return;
		}
		lazyEvaluate(node_i);
		if (node_r <= query_l || query_r <= node_l) return;
		const int node_m{(node_l + node_r) >> 1};
		updateImplement(query_l, query_r, node_l, node_m, 2 * node_i, assigned >> 1);
		updateImplement(query_l, query_r, node_m, node_r, 2 * node_i + 1, assigned >> 1);
		sumContainer_[node_i] = sumContainer_[2 * node_i] + sumContainer_[2 * node_i + 1];
	}

	int64_t findImplement(const int query_l, const int query_r, const int node_l, const int node_r, const int node_i)
	{
		if (node_r <= query_l || query_r <= node_l) return 0ll;
		lazyEvaluate(node_i);
		if (query_l <= node_l && node_r <= query_r) return sumContainer_[node_i];
		const int node_m{(node_l + node_r) >> 1};
		return findImplement(query_l, query_r, node_l, node_m, 2 * node_i) + findImplement(query_l, query_r, node_m, node_r, 2 * node_i + 1);
	}
public:
	SegmentTree(const int n)
	{
		int size{1};
		while (size < n) size <<= 1;
		tree_width_ = size;
		sumContainer_.resize(2 * size);
		updateContainer_.resize(2 * size);
	}

	void update(const int left, const int right, int64_t assigned)
	{
		updateImplement(left, right, 0, tree_width_, 1, assigned * tree_width_);
	}

	int64_t find(const int left, const int right)
	{
		return findImplement(left, right, 0, tree_width_, 1);
	}
};

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	SegmentTree st(n);
	for (int q_i{}; q_i < q; q_i++)
	{
		int query, s, t;
		scanf("%d%d%d", &query, &s, &t);
		t++;
		if (query == 0)
		{
			int x;
			scanf("%d", &x);
			st.update(s, t, x);
		}
		else
			printf("%lld\n", st.find(s, t));
	}
	return 0;
}


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

class shop {
public:
	int n, r;
	string S;

	shop(int n = 0, int r = 0, string S = "") :n(n), r(r), S(S){}

	bool operator < (const shop& p) const {
		return S != p.S ? S > p.S : r < p.r;
	}
};

int main(void)
{
	int N, P;
	string S;
	cin >> N;
	shop s;
	priority_queue<shop> v;
	for (int i = 0; i < N; i++)
	{
		cin >> S >> P;
		v.push(shop(i, P, S));
	}

	for (int i = 0; i < N; i++)
	{
		cout << v.top().n + 1 << endl;
		v.pop();
	}

	return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  vector<ll>p(a),q(b),r(c);
  rep(i,0,a)cin>>p[i];
  rep(i,0,b)cin>>q[i];
  rep(i,0,c)cin>>r[i];
  sort(ALLR(p));
  sort(ALLR(q));
  sort(ALLR(r));
  ll sum=0;
  priority_queue<ll,vector<ll>,greater<ll>>que;
  rep(i,0,x)que.push(p[i]),sum+=p[i];
  rep(i,0,y)que.push(q[i]),sum+=q[i];
  res=sum;
  rep(i,0,min(x+y,c)){
    sum-=que.top();
    que.pop();
    sum+=r[i];
    chmax(res,sum);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4852
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    
    h, w = map(int, input().split())
    a = [list(input()) for i in range(h)]
    queue = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                queue.append((i, j))

    visited = [[-1 for i in range(w)] for j in range(h)]
    ans = 0
    nqueue = deque()
    while queue:
        x, y = queue.popleft()
        visited[x][y] = 1
        for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            nx = x + i
            ny = y + j
            if nx >= 0 and ny >= 0 and nx < h and ny < w:
                if visited[nx][ny] == -1 and a[nx][ny] != "#":
                    nqueue.append([nx, ny])
                    visited[nx][ny] = 1
                    a[nx][ny] = "#"
        
        if len(queue) == 0:
            queue = nqueue
            nqueue = deque()
            ans += 1
        
    print(ans-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 142960
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

string h[1002];
vector<int> tmp;

int n;

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

int dfs(int x,int y){
	if( h[y][x] != '*' ) return 0;
	h[y][x] = ' ';
	tmp[y]++;
	for(int i = 0 ; i < 8 ; i++)
		dfs(x+dx[i],y+dy[i]);
}
int main(){
	string t;
	int fst = 0;
	while(cin >> n && n){
		if( fst++ ) cout << "----------" << endl;
		getline(cin,t);
		
		
		int	width = 0;
		for(int i = 1 ; i <= n ; i++) getline(cin,h[i]) , h[i] = " " + h[i] + " " , width = max( width , (int)h[i].size() );
		h[0] = string(width,' ');
		h[n+1] = string(width,' ');
		for(int i = 1 ; i <= n ; i++){
			if( h[i].size() < width ){
				h[i] += string(width - h[i].size(),' ');
			}
		}
		
		map<int,int> www;
		
		for(int i = 1 ; i <= n ; i++){
			for(int j = 0 ; j < width ; j++){
				if( h[i][j] == '*' ){
					tmp = vector<int>(1002,0);
					dfs(j,i);
					sort(tmp.rbegin(),tmp.rend());
					int he = 0;
					int a = tmp[0] , b = tmp[1];
					if( !b ) b = a;
					for(int k = 0 ; k < 1002 ; k++){
						if( tmp[k] ) he++;
					}
					www[(a+b)*he/2]++;
				}
			}
		}
		for( map<int,int>::iterator it = www.begin(); it != www.end() ; it++){
			cout << it->first << " " << it->second << endl;
		}
		
		
	}
	
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

const int Nmax = 1e5 + 5;
int N,S,Max,p;
int a[Nmax][3],dp[Nmax][3];

int main()
{
    scanf("%d",&N);
    for(int i = 1; i <= N; ++i)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        for(int j = 0; j < 3; ++j)
        {
            for(int k = 0; k < 3; ++k)
                if(j != k)
                    dp[i][j] = max(dp[i - 1][k],dp[i][j]);
            dp[i][j] += a[i][j];
        }
    }
    printf("%d",max({dp[N][0],dp[N][1],dp[N][2]}));
    /// cout << dp[N][0] << " " << dp[N][1] << " " << dp[N][2];
    return 0;
}


Measured memory_bytes: 2560
A,B,C = map(int,input().split())
def gcd (x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

if C % gcd(A,B) == 0:
    print("YES")
else:
    print("NO")

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, ans=0, tmp=0;
vector<ll> A;

void mydetect(int num) {
    for(int i=2;i*i<=num;i++) {
        if(num%i==0) break;
        if((i+1)*(i+1)>num) A.push_back(num);
    }
}

void soinsuu() {
    int i=11;

    while(A.size()!=N) {
        mydetect(i);
        i+=5;
    }

    for(int j=0;j<A.size();j++) {
        cout << " " << A[j];
    }
}

signed main(){
    cin >> N;
    //A.push_back(2);
    soinsuu();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[1000];
	ll cnt = 0;
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < N; i++) {
		if (a[i] == a[i + 1]) {			
			++cnt;
		}
		else if (a[i] != a[i + 1]) {
			sum += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	cout << sum << endl;

}








Measured memory_bytes: 256
n = int(input())
words = []
flag = True
for i in range(n):
    words.append(input())
for i in range(1,n):
    if words[i][0] != words[i-1][-1]:
        flag = False
        break
if len(set(words)) != n:
    flag = False
print('Yes' if flag else 'No')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#define ll long long
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
pair<pair<string, int>, int> p[110];//pair型
int length(char* str) {
    int len = strlen(str);
    return len;
}
ll GCD(ll a, ll b)
{

    ll r, tmp;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }


    return b;
}
ll LCM(ll a, ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}
int main()
{
    char S[100010];
    int count = 0;
    cin >> S;
    int len = length(S);
    for (int i = 0; i < len-1; i++) {
        if (S[i] == S[i + 1]) {
            if (S[i] == '0') {
                S[i + 1] = '1';
            }
            else {
                S[i + 1] = '0';
            }
            count++;
        }
    }
    cout << count;
}


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

int main() {
    int n;
    cin >> n;
    double x[n];
    double y[n];
    rep(i, n) cin >> x[i] >> y[i];

    int idx[n];
    rep(i, n) idx[i] = i;

    double ans = 0;
    int cnt = 0;
    do {
        cnt++;
        rep(i, n - 1) {
            int lx = pow(x[idx[i + 1]] - x[idx[i]], 2);
            int ly = pow(y[idx[i + 1]] - y[idx[i]], 2);
            ans += sqrt(lx + ly);
        }
    } while (next_permutation(idx, idx + n));

    printf("%.10f\n", ans / cnt);
    return 0;
}


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

int main(){
  int N,M; cin >> N >> M;
  
  int ab[50][2];
  for(int i=0; i<N; i++){
    cin >> ab[i][0] >> ab[i][1];
  }
  
  int point[50][2];
  for(int i=0; i<N; i++){
    point[i][1]=1000000000;
  }
  
  int c,d;
  for(int i=0; i<M; i++){
    cin >> c >> d;
    for(int j=0; j<N; j++){
      if(abs(ab[j][0]-c)+abs(ab[j][1]-d)<point[j][1]){
        point[j][0]=i;
        point[j][1]=abs(ab[j][0]-c)+abs(ab[j][1]-d);
      }
    }
  }
  
  for(int i=0; i<N; i++){
    cout << point[i][0]+1 << endl;
  }
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int k, n;
  vector<int> a;
  Solver2(LL k, LL n) : k(k), n(n), a(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int ans = INF;
    for (int i = 1; i < n; ++i) {
      ans = min(ans, k - (a[i] - a[i - 1]));
    }
    ans = min(ans, a[n - 1] - a[0]);
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long k, n = 0;
  std::cin >> k >> n;

  Problem::Solver2 sol(k, n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();
        System.out
                .println((x2 - y2 + y1) + " " + (y2 + x2 - x1) + " " + (x2 - y2 + y1 - x2 + x1) + " " + (y1 + x2 - x1));
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++)
            c[i] = i;
        
        for (int i = 0; i < q; i++) {
            int com = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
            if (com == 0) {
                for (int j = 0; j < n; j++) 
                    if (c[j] == c[x] && j != x) c[j] = c[y];
                c[x] = c[y];
            } else {
                System.out.println(c[x] == c[y] ? 1 : 0);
            }
        }
    }
}


Measured memory_bytes: 101468
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
unsigned long long cnt;

void merge(int a[],int left,int mid ,int right){
  int n1=mid-left,n2=right-mid;
  int l[n1+1],r[n2+1];
  for(int i=0;i<n1;i++)
    l[i]=a[left+i];
  for(int i=0;i<n2;i++)
    r[i]=a[mid+i];
  l[n1]=r[n2]=1+pow(10,9);
  int i=0,j=0,k;
  for(k=left;k<right;k++){
    if(l[i]<=r[j]){
      a[k]=l[i];
      i++;

    }
    else{
      a[k]=r[j];
      j++;
      cnt+=right-k-j;

    }
  }
}
void mergesort(int a[],int left,int right){
  int mid;
  if(left+1<right){
    mid = (left +right)/2;
    mergesort(a,left,mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
  }
}

int main(){
  int n,i;
  cin>>n;
  int s[n];
  for(i=0;i<n;i++)
    cin>>s[i];
  mergesort(s,0,n);
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 4644
#include<bits/stdc++.h>
using namespace std;
long long n,h[200000],dp[200000];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
}

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

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


Measured memory_bytes: 3528
def s1(n):
    return n*(n+1)//2
def s2(n):
    return n*(n+1)*(2*n+1)//6
n,k=map(int,input().split())
print(((n+1)*(s1(n+1)-s1(k-1))-(s2(n+1)-s2(k-1))+n-k+2)%(10**9+7))

Measured memory_bytes: 9196
import math

result = []

n = int(input())
def isprime(x):
    if x == 2:
        return True
    if x < 2 or x%2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x%i == 0:
            return False
        i += 2
    return True

for _ in range(n):
    x = int(input())
    if isprime(x):
        result.append(x)
    
print(len(result))


Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
const int INF = 1e9;

class bipartite_matching {
public:
    int n;
    vector<vector<int>> g;
    vector<int> match;

    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for(int v = 0; v < n; ++v){
            if (match[v] < 0) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }

private:
    vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u: g[v]) {
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w))) {
                match[v] = u; match[u] = v;
                return true;
            }
        }
        return false;
    }
};

int N,M,L;
int mat[110][110];
pair<int,int> node[1010];

int main(){
    while(cin >> N >> M >> L && N){
        rep(i,N)rep(j,N) mat[i][j] = (i == j ? 0 : INF);
        rep(i,M){
            int u,v,d;
            cin >> u >> v >> d;
            mat[u][v] = mat[v][u] = d;
        }
        rep(k,N)rep(i,N)rep(j,N) mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j]);
        rep(i,L) cin >> node[i].second >> node[i].first;
        sort(node, node+L);

        bipartite_matching bm(L*2);

        rep(i,L)rep(j,i){
            int dt = node[i].first - node[j].first;
            int dist = mat[node[i].second][node[j].second];
            if(dt >= dist){
                bm.add_edge(j, i+L);
            }
        }

        int f = bm.maximum_matching();
        cout << L-f << endl;
    }
}

Measured memory_bytes: 8088
#include <string>
#include <iostream>
using namespace std;
string s, t; char d[20]; int pos, cnt;
bool calc(int l, int r) {
	if (s[l] == 'T') return true;
	if (s[l] == 'F') return false;
	if (s[l] == '-') return !calc(l + 1, r);
	int depth = 0;
	for (int i = l + 1; i < r - 1; i++) {
		if (s[i] == '(') depth++;
		if (s[i] == ')') depth--;
		if (depth == 0) {
			if (s[i] == '*') return calc(l + 1, i) && calc(i + 1, r - 1);
			if (s[i] == '+') return calc(l + 1, i) || calc(i + 1, r - 1);
			if (s[i] == '-' && s[i + 1] == '>') return !calc(l + 1, i) || calc(i + 2, r - 1);
		}
	}
	return true;
}
bool solve() {
	for (int i = 0; i < (1 << cnt); i++) {
		for (int j = 0; j < cnt; j++) {
			for (int k = 0; k < s.size(); k++) {
				if (d[j] == s[k]) s[k] = (i & (1 << j)) ? 'T' : 'F';
			}
		}
		if (calc(0, pos) != calc(pos + 1, s.size())) return false;
		s = t;
	}
	return true;
}
int main() {
	while (cin >> s, s != "#") {
		cnt = 0; t = s;
		pos = s.find('=');
		for (int j = 0; j < s.size(); j++) {
			if (islower(s[j])) {
				bool found = false;
				for (int k = 0; k < cnt; k++) {
					if (d[k] == s[j]) {
						found = true; break;
					}
				}
				if (!found) d[cnt++] = s[j];
			}
		}
		cout << (solve() ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 3164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.List;
import java.util.stream.Stream;
import java.util.Map;
import java.util.Collection;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.function.Function;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String w = in.next();
            Map<Integer, List<Integer>> map = w.chars().boxed().collect(Collectors.groupingBy(Function.identity()));
            String ret = map.values().stream().filter(l -> l.size() % 2 != 0).count() == 0 ? "Yes" : "No";
            out.println(ret);
        }

    }
}



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

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

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << (B - B / C - B / D + B / (C * D / gcd(C, D))) - ((A - 1) - (A - 1) / C - (A - 1) / D + (A - 1) / (C * D / gcd(C, D))) << endl;
}

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

long long A,B,K;

int main(){
    cin>>A>>B>>K;
    if(A>=K){cout<<A-K<<" "<<B<<endl;
    }else if(A+B>=K){cout<<0<<" "<<B-(K-A)<<endl;
    }else {cout<<0<<" "<<0<<endl;}
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

A = []

for i in range(N):
	if i == 0:
		A.append(B[0])
	elif 1 <= i <= N-2:
		A.append(min(B[i],B[i-1]))
	else:
		A.append(B[-1])

print(sum(A))

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> va(n), vb(m);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  for (int i = 0; i < m; ++i) {
    cin >> vb[i];
  }

  vector<ll> csum_a{0}, csum_b;
  partial_sum(va.begin(), va.end(), back_inserter(csum_a));
  partial_sum(vb.begin(), vb.end(), back_inserter(csum_b));

  ll ans = 0;

  // aからi冊読む
  for (int i = 0; i <= va.size(); ++i) {
    ll a_sum = csum_a[i];
    if (a_sum > k) {
      break;
    }

    auto it =
        lower_bound(csum_b.rbegin(), csum_b.rend(), k - a_sum, greater<ll>());
    ans = max(ans, i + m - distance(csum_b.rbegin(), it));
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 11068
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}

int main(){
    ll N;cin>>N;
    vector<ll>A(N);
    ll ans1=0;
    ll cnt1=0;//現在の変化数の和
    ll ans2=0;
    ll cnt2=0;//現在の変化数の和
    rep(i,N){
        cin>>A[i];
    }
    vector<ll>S1(N);
    vector<ll>S2(N);
    S1[0]=A[0];
    S2[0]=A[0];
    rep(i,N-1){
        S1[i+1]=S1[i]+A[i+1];
        S2[i+1]=S2[i]+A[i+1];
    }
    rep(i,N){
        S1[i]+=cnt1;
        if(i%2==0){
            if(S1[i]<=0){
                ans1+=abs(S1[i])+1;
                cnt1+=abs(S1[i])+1;
                S1[i]=1;
            }
        }
        else{
            if(S1[i]>=0){
                ans1+=S1[i]+1;
                cnt1-=S1[i]+1;
                S1[i]=-1;
            }
        }
    }
    rep(i,N){
        S2[i]+=cnt2;
        if(i%2==0){
            if(S2[i]>=0){
                ans2+=S2[i]+1;
                cnt2-=S2[i]+1;
                S2[i]=-1;
            }
        }
        else{
            if(S2[i]<=0){
                ans2+=abs(S2[i])+1;
                cnt2+=abs(S2[i])+1;
                S2[i]=1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
}

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

#define pb push_back
#define mp make_pair

#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)(3e5 + 5);
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e9 + 11);

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a + b == 15)
        cout << "+";
    else if (a * b == 15)
        cout << "*";
    else
        cout << "x";
    return 0;
}


Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);

    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

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

Measured memory_bytes: 7372
#include <stdio.h>

int dat[100001] = {};

int main() {
    long n, ans=1;
    int t;

    scanf("%ld", &n);

    for (long i=0; i<n; i++) {
        long a;
        scanf("%ld", &a);
        dat[a]++;
    }

    t = n % 2 + 1;

    if (t == 2 && dat[0] != 1) { //偶数で0がにこあるなら
        puts("0");
        return 0;
    }

    for (long i=t; i<n; i+=2) //偶数、きすうに対応
        if (dat[i] != 2) {
            puts("0");
            return 0;
        }
        
    for (long i=1; i<=n/2; i++)
        ans = (2 * ans) % 1000000007;
    printf("%ld\n", ans);
}

Measured memory_bytes: 512
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  a, b = map(int, input().strip().split())
  if 0 < a < 10 and 0 < b < 10:
    print(a*b)
  else:
    print(-1)

if __name__=='__main__':
  main()



Measured memory_bytes: 2940
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
s = S()
dic = {"A":"a","B":"b","C":"c"}


if s[K-1] == "A":
    ans = s[:K-1] + "a" + s[K:]
if s[K-1] == "B":
    ans = s[:K-1] + "b" + s[K:]
if s[K-1] == "C":
    ans = s[:K-1] + "c" + s[K:]

print(ans)

Measured memory_bytes: 21896
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;

int main(){
    ll n,m,r; cin>>n>>m>>r;
    vector<ll> v(r);
    REP(i,r)cin>>v[i], v[i]--;
    vector<vector<ll>> g(n,vector<ll> (n, 1e15));
    REP(i,n)g[i][i]=0;
    REP(i,m){
        ll a,b,c; cin>>a>>b>>c;
        a--; b--;
        g[a][b]=c;
        g[b][a]=c;
    }
    REP(k,n)REP(i,n)REP(j,n){
        g[i][j]=min(g[i][j], g[i][k]+g[k][j]);
    }
    ll ans=1e18;
    sort(ALL(v));
    do {
        ll preans=0;
        FOR(i,1,r){
            preans+=g[v[i-1]][v[i]];
        }
        ans=min(preans, ans);
    }while(next_permutation(ALL(v)));
    cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 200005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define fi first
#define se second

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
  ll mid;
  while(abs(ok - ng) > 1LL) {
    mid =  (ok + ng) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      ok = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      ng = mid;
    }
  }
  return ok;
}

ll NUM_TEST_CASE = 1;

ll N,M,K,A[NMAX] = {},B,C,D,E;
unordered_map<ll, ll>mp;

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm
  mp[0] = 1;
  ll sum = 0;
  for (int i = 0; i < N; ++i)
  {
    sum += A[i];
    ans += mp[sum]++;
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
void init(){
  // initialize for each test case
  // Fill(dp, -1);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // cin >> NUM_TEST_CASE;

  for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
  {
    init();

    cin >> N;
    for (int i = 0; i < N; ++i)
     {
       scanf("%lld", &A[i]);
     }
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();
  }

  return 0;
}

Measured memory_bytes: 10056
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
s = [LIST()[1:] for _ in range(M)]
p = LIST()

ans = 0
for x in product([0, 1], repeat=N):
    for i in range(M):
    	cnt = 0
    	for n in s[i]:
    		if x[n-1] == 1:
    			cnt += 1
    	if cnt%2 != p[i]:
    		break
    else:
    	ans += 1
print(ans)


Measured memory_bytes: 5812
#include<bits/stdc++.h>
 using namespace std;
 int main(){
  int n;
  cin>>n;
int arr[100];
int max=0;
for(int i=0;i<n;i++){
  cin>>arr[i];
  if(abs(arr[i])>abs(arr[max]))  //find the maximum element in the array
    max=i;        //update the maximum elemnt in the array
}
///why we finding the maximum element in the array means 
// if the sequence has positive numbers means adding big number to every element makes increasing sequence
// or negative means we add min number to the elements to make it increasing sequence.

// so add the element present in the max element position
cout<<2*n-1<<"\n"; //we only performing 2n operations

for(int i=0;i<n;i++){
  arr[i]+=arr[max];
  cout<<max+1<<" "<<i+1<<"\n";  //it means printing max positon and element position we are adding
}
//so now our array is updated.
//..lets find our maximum element is +ve or -ve
if(arr[max]>=0){
  for(int i=1;i<n;i++){
    arr[i]+=arr[i-1];
    cout<<i<<" "<<i+1<<"\n";
  }
}
else{
  for(int i=n-2;i>=0;i--){
    arr[i]+=arr[i+1];
    cout<<i+2<<" "<<i+1<<"\n";
  }

}
  return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <map>

using namespace std;
using lli = long long int;
using ll = long long;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include <utility>      // std::swap
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;


    ll W,H,N,M;
    ll sum;
    ll ans=0;
    ll sm,lr;
    ll A;
    deque<ll> s;
    bool f=false;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    A=N%2;
    REP(i,N){
        int a;
        cin>>a;
        if(i%2==A){
            s.push_back(a);
        }else{
            s.push_front(a);
        }
    }
    REP(i,N){
        cout<<s[i];
        if(i!=N-1)cout<<" ";
    }
    //cout<<ans;
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <string>
using namespace std;
string minus2(int K){
    if (K==1){
        return "1";
    }
    else if (K==0){
        return "0";
    }
    string S="";
    if (K % 2 != 0){
        S="1";
        K--;
    }
    else{
        S="0";
    }
    K /= -2;
    cerr << K << endl;
    return minus2(K)+S;
}
int main(void){
    int N;
    cin >> N;
    cout << minus2(N) << endl;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    let mut num_of_divs = vec![1; n + 1];
    num_of_divs[0] = 0;
    for i in 2..=n {
        if num_of_divs[i] != 1 {
            continue;
        }
        for j in (i..=n).step_by(i) {
            let mut x = j;
            let mut cnt = 1;
            while x % i == 0 {
                x /= i;
                cnt += 1;
            }
            num_of_divs[j] *= cnt;
        }
    }

    let ret: usize = num_of_divs.iter().enumerate().map(|(i, v)| i * v).sum();
    println!("{}", ret);
}


Measured memory_bytes: 80156