akhauriyash/Code-Regression huggingface dataset:
// atcoder/abc147/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    const int N = 15 + 1;
    vector<pair<int, int>> g[N];
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      for (int j = 0; j < a; ++j) {
        int x, y;
        cin >> x >> y;
        --x;
        g[i].push_back(make_pair(x, y));
      }
    }

    int mx = 0;
    for (int bit = 0; bit < (1 << n); ++bit) {
      bool f = true;
      for (int i = 0; i < n; ++i) {
        each (j, g[i]) {
          int y = j.second;
          if (bit & (1 << i)) {
            f = f && (bool(bit & (1 << j.first)) == bool(y));
          }
        }
      }
      if (f) {
        setmax(mx, __builtin_popcount(bit));
      }
    }
    cout << mx << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int ans;
int vis[N];
vector<int>v[N];
void dfs(int s){
  vis[s]=1;
  int f =1;
  for(auto i : v[s]){
    if(!vis[i])dfs(i);
  }
  int cur = ar[s];
  for(auto i : v[s]){
    if(cur <= ar[i])f =0;
  }
  if(f){
    // trace(s);
    ans++;
  }
}
signed main(){
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    int n ,m  ;
    cin >> n >> m;
    fn1{
      cin >> ar[i];
    }
    fm{
      int x ,y;
      cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    fn1{
      if(!vis[i])dfs(i);
    }
    cout << ans;
  
  }
  return 0;
}

Measured memory_bytes: 56832
#include <bits/stdc++.h> 
using namespace std;
typedef vector<int> int_vector;
typedef vector< vector<int> > int_matrix;
typedef vector<string> string_vector;
typedef vector< vector<string> > string_matrix;

int get_cij(int i, int j, int n, int nd){
    int cnt=0;
    if(i==j) {
        if (nd==0) return ( (n < i) ? 0 : 1 );
        else cnt++;
    }
    else {
        if (nd==0) return 0;
    }

    int k=0;
    for(k=0; k<nd-1; k++){
        cnt += pow(10, k);
    }

    if (i < n/ (int) pow(10, nd)){
        cnt += pow(10, k);
    }
    else if (i == n/ (int) pow(10, nd)){
        int r = n % (int) pow(10, nd);
        if(j <= (n % 10)){
            cnt += r/10+1;
        }
        else{
            cnt += r/10;
        }
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    int nd = floor(log10(n));
    int cnt=0;
    for(int i=1; i<10; i++){
        for (int j=1; j<10; j++){
            int cij = get_cij(i, j, n, nd); 
            int cji = get_cij(j, i, n, nd);
            cnt+= cij * cji;
        }
    }
    cout << cnt << endl;    
}

Measured memory_bytes: 256
N = input()

def digsum(n):
    total = 0
    while n > 0:
        total += n%10
        n /= 10
        n = int(n)
    return total

if len(N)==1:
    print(N)
    exit()

if N[1:].count('9') == len(N)-1:
    print(digsum(int(N)))
    exit()

ans = int(str(int(N[0])-1) + '9'*(len(N)-1))
print(digsum(ans))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

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


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll H,N,A,sum=0;
    cin >> H >> N;
    rep(i,N){
        cin >> A;
        sum += A;
        if(sum >= H){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 888
from collections import deque

class UnionFind :
    def __init__(self, size) :
        """
        Parameters
        ---
        size : int
            頂点数
        """
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        """
        親のインデックスの取得

        Parameters
        ---
        index : int
            取得する頂点のインデックス

        Returns
        ---
        rootIndex : int
            指定した頂点の根のインデックス
        """
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        """
        木の結合

        Parameters
        ---
        index1 : int
        index2 : int
            結合する頂点のインデックス
        """
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        """
        同じ木に属するかを判定する

        Parameters
        ---
        index1 : int
        index2 : int

        Returns
        ---
        boolean
        """
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        """
        指定した頂点の属する木の大きさを取得する
        """
        return self.size[self.root(index)]

    def getComponent(self) :
        """
        連結成分数を取得する
        """
        return self.component

N, M = map(int, input().split())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
INF = float('inf')

tree = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    tree.union(a, b)

A.sort()
ans = 0
L = (tree.getComponent() - 1) * 2

if L == 0:
    print(0)
    exit()

V = set()
for j, (a, i) in enumerate(A):
    r = tree.root(i)
    if not r in V:
        ans += a
        V.add(r)
        L -= 1
        A[j] = (INF, i)

A.sort()
for a, _ in A[:L]:
    ans += a

if ans == INF:
    print('Impossible')
else:
    print(ans)

Measured memory_bytes: 29476
import sys
import math
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

A, B, C, X, Y = map(int, input().split())

ans = 0
while X > 0 or Y > 0:
    if X > 0 and Y > 0:
        if 2*C <=  A+B:
            X -= 1
            Y -= 1
            ans += 2*C
        else:
            X -= 1
            Y -= 1
            ans += A+B
    elif X > 0:
        if 2*C <= A:
            X -= 1
            ans += 2*C
        else:
            X-= 1
            ans += A
    else:
        if 2*C <= B:
            Y -= 1
            ans += 2*C
        else:
            Y -= 1
            ans += B
print(ans)


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }
 
    int ans = 0;
    auto calc = [&](string s) {
        int buf = 0;
        for (string t: blue) {
            if (t == s) buf++;
        }
        for (string t: red) {
            if (t == s) buf--;
        }
        return buf;
    };
 
    for (string t: blue) {
        ans = max(ans, calc(t));
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
[N, K] = list(map(int,input().split()))
[R, S, P] = list(map(int,input().split()))
T = input()
def calc(s):
    tmp = [0,0,0]
    if s[0] == 'r':
        tmp[2] += 1
    elif s[0] == 's':
        tmp[0] += 1
    else:
        tmp[1] += 1
    old = s[0]
    for i in range(1,len(s)):
        new = s[i]
        if old != new:
            if  new == 'r':
                tmp[2] += 1
            elif new  == 's':
                tmp[0] += 1
            else:
                tmp[1] += 1
        if old == new:
            old = 'a'
        else:
            old = new
    re = R * tmp[0] + S * tmp[1] + P * tmp[2]
    return re
ans = 0
for i in range(K):
    s = ''
    idx = i
    while idx <= N - 1:
        s += T[idx]
        idx += K
    ans += calc(s)
print(ans)

Measured memory_bytes: 3316
def main():
    N,K=map(int,input().split())

    M={}

    mod=pow(10,9)+7
    res=0
    for i in range(K,0,-1):
        syou=K//i
        mc=pow(syou,N,mod)
        if syou>=2:
            for sub_m in range(2,syou+1):
                mc-=M[sub_m*i]
        res+=(i*mc)%mod
        M[i]=mc

    print(res%mod)

if __name__=="__main__":
    main()

Measured memory_bytes: 81112
#include<bits/stdc++.h>
using namespace std;
int test;
int ds[100005];




int find(int pos){
	if(ds[pos]==pos){
		return pos;
	}
	else
	return ds[pos]=find(ds[pos]);
}


void add(int uno,int due){
	
	ds[find(uno)]=ds[find(due)];
	
}

bool diff(int a,int b){
	return find(a)!=find(b);
}



int main(){
int n;
cin>>n;
pair<pair<long long,long long>,int> vx[n],vy[n];

for(int i=0;i<n;i++){
	
cin>>vx[i].first.first>>vx[i].first.second;
vy[i].first.first=vx[i].first.second;
vy[i].first.second=vx[i].first.first;
vy[i].second=vx[i].second=i+1;	
}

sort(vx,vx+n);
sort(vy,vy+n);


vector<pair<long long,pair<int,int> > > edges;
for(int i=0;i<n-1;i++){
	long long cont=min(abs(vx[i+1].first.first-vx[i].first.first),abs(vx[i+1].first.second-vx[i].first.second));
	pair<int,int> cities;
	cities.first=vx[i].second;
	cities.second=vx[i+1].second;
	edges.push_back({cont,cities});
}


for(int i=0;i<n-1;i++){
	long long cont=min(abs(vy[i+1].first.first-vy[i].first.first),abs(vy[i+1].first.second-vy[i].first.second));
	pair<int,int> cities;
	cities.first=vy[i].second;
	cities.second=vy[i+1].second;
	edges.push_back({cont,cities});
}

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

long long ans=0ll;

for(int i=1;i<=n;i++){
	ds[i]=i;
}


for(int i=0;i<edges.size();i++){
	if(diff(edges[i].second.first,edges[i].second.second)){
		add(edges[i].second.first,edges[i].second.second);
		ans+=edges[i].first;
	}
}
cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 10736
// https://atcoder.jp/contests/abc104/tasks/abc104_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define isvisiblechar(c) (0x21 <= (c) && (c) <= 0x7E)
#define cin scanner
#define cout printer
namespace {
class MaiScanner {
  public:
    template <typename T> void input_integer(T &var) {
        var = 0;
        T sign = 1;
        int cc = getchar_unlocked();
        for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
            if (cc == '-')
                sign = -1;
        for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
            var = (var << 3) + (var << 1) + cc - '0';
        var = var * sign;
    }
    inline int c() { return getchar_unlocked(); }
    inline MaiScanner &operator>>(int &var) {
        input_integer<int>(var);
        return *this;
    }
    inline MaiScanner &operator>>(long long &var) {
        input_integer<long long>(var);
        return *this;
    }
    inline MaiScanner &operator>>(string &var) {
        int cc = getchar_unlocked();
        for (; !isvisiblechar(cc); cc = getchar_unlocked())
            ;
        for (; isvisiblechar(cc); cc = getchar_unlocked())
            var.push_back(cc);
        return *this;
    }
    template <typename IT> void in(IT begin, IT end) {
        for (auto it = begin; it != end; ++it)
            *this >> *it;
    }
};
class MaiPrinter {
  public:
    template <typename T> void output_integer(T var) {
        if (var == 0) {
            putchar_unlocked('0');
            return;
        }
        if (var < 0)
            putchar_unlocked('-'), var = -var;
        char stack[32];
        int stack_p = 0;
        while (var)
            stack[stack_p++] = '0' + (var % 10), var /= 10;
        while (stack_p)
            putchar_unlocked(stack[--stack_p]);
    }
    inline MaiPrinter &operator<<(char c) {
        putchar_unlocked(c);
        return *this;
    }
    inline MaiPrinter &operator<<(int var) {
        output_integer<int>(var);
        return *this;
    }
    inline MaiPrinter &operator<<(long long var) {
        output_integer<long long>(var);
        return *this;
    }
    inline MaiPrinter &operator<<(char *str_p) {
        while (*str_p)
            putchar_unlocked(*(str_p++));
        return *this;
    }
    inline MaiPrinter &operator<<(const string &str) {
        const char *p = str.c_str();
        const char *l = p + str.size();
        while (p < l)
            putchar_unlocked(*p++);
        return *this;
    }
    template <typename IT> void join(IT begin, IT end, char sep = ' ') {
        for (bool b = 0; begin != end; ++begin, b = 1)
            b ? *this << sep << *begin : *this << *begin;
    }
};
} // namespace
MaiScanner scanner;
MaiPrinter printer;

int main(void) {
    int n;
    cin >> n;
    if (n < 1200)
        cout << "ABC\n";
    else if (n < 2800)
        cout << "ARC\n";
    else
        cout << "AGC\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <cstdio>
//#include <cstdlib>
//#include <cmath>
//#include <cstring>
//#include <vector>
//#include <set>
//#include <map>
//#include <stack>
//#include <queue>
//#include <string>
//#include <algorithm>
//#include <bitset>
using namespace std;

#define loop(n)          for(int i = 0; i < (n); i++)
#define lp(x, s, e)      for(int x = (s); x < (e); x++)


char X[6][6];


void init() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}




int main()
{
    init();
    int h, w, k ;
    cin >> h >> w >> k;
    loop(h)
        lp(j, 0, w)
    {
        cin >> X[i][j];
    }
    int ans = 0;
    for (int Rmask = 0;Rmask < (1 << h);Rmask++)
    {
        for (int Cmask = 0;Cmask < (1 << w);Cmask++)
        {
            int blacks = 0;
            loop(h)
                lp(j, 0, w)
            {
                if (((Rmask >> i) & 1) == 0 && ((Cmask >> j) & 1) == 0 && X[i][j] == '#')
                blacks++;
            }
            if (blacks == k) ans++;
        }
    }
    cout << ans;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	if (1 <= A && A <= 9 && 1 <= B && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << "-1" << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  string S,CF = "CODEFESTIVAL2016";
  cin >> S;
  int ans = 0;
  FOR(i,0,16)if(S[i] != CF[i])ans++;
  cout << ans << endl;
}


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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    string S;

    cin>>S;

    if(S=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;

    return 0;
}

Measured memory_bytes: 3612
A,B,C = map(int,input().split())
K = int(input())
while K > 0:
  while A>=B and K > 0:
    B *= 2
    K -=1
  while B>=C and K > 0:
    C *= 2
    K -= 1
  if A < B < C:
    break
if B>=C:
  print('No')
else:
  print('Yes')

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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int A = scanner.nextInt();
        String a = "000" + A;
        String b = "ABC" + a.substring(a.length() - 3);
        System.out.println(b);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


Measured memory_bytes: 21588
X = int(input())
x_max=0
if X==1:
    x_max=1
elif X==2:
    x_max=1
i=2
while i**2<=X:
    j=2
    while i**j<=X:
        if x_max<i**j:
            x_max = i**j
        j+=1
    i+=1
print(x_max)

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct Node { int key; struct Node *p, *left, *right; };

Node *T = NULL;

void Preorder(Node *id) {
	if (id == NULL) return;
	cout << " " << id->key;
	Preorder(id->left);
	Preorder(id->right);
}

void Inorder(Node *id) {
	if (id == NULL) return;
	Inorder(id->left);
	cout << " " << id->key;
	Inorder(id->right);
}

void treeInsert(Node *Z) {
	Node *y = NULL;
	Node *x = T;
	while (x != NULL) {
		y = x;
		if (Z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	Z->p = y;
	if (y == NULL)
		T = Z;
	else if (Z->key < y->key)
		y->left = Z;
	else
		y->right = Z;
}

bool treeFind(int key) {
	Node *y = NULL;
	Node *x = T;
	while (x != NULL) {
		y = x;
		if (key == x->key)
			return true;
		else if (key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	Node *node = new Node[n];
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "insert") {
			cin >> node[i].key;
			node[i].left = NULL;
			node[i].right = NULL;
			treeInsert(&node[i]);
		}
		else if (s == "find") {
			int key;
			cin >> key;
			if (treeFind(key))
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else {
			Inorder(T);
			cout << endl;
			Preorder(T);
			cout << endl;
		}
	}
	delete[] node;
	return 0;
}

Measured memory_bytes: 15576
use proconio::{input, fastout};

#[fastout]
fn main() {
  input!{
    n:usize,
    mut a:[usize;n]
  }
  let mut ans : i64 = 0;
  for i in 0..n {
      while a[i] % 2 == 0 {
        a[i] /= 2;
        ans += 1;
      }
  }
  println!("{}",ans);
}


Measured memory_bytes: 2372
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
           
using namespace std;
using namespace __gnu_pbds;
           
//#define int long long
  
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
           
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
           
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
  
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("mincost.in", "r", stdin);
    //freopen("mincost.out", "w", stdout);
    #endif
}

const int mod = 998244353;
const int MAXN = 3030;
int arr[MAXN], dp[MAXN];

signed main() {
    FAST_IO();
    int n, s;
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = MAXN - 1; j >= arr[i]; --j) {
            dp[j] += dp[j - arr[i]];
            if (dp[j] >= mod) {
                dp[j] -= mod;
            }
        }
        dp[arr[i]] += i + 1;
        if (dp[arr[i]] >= mod) {
            dp[arr[i]] -= mod;
        } 
        ans += dp[s];
        if (ans >= mod) {
            ans -= mod;
        }
    }
    cout << ans << '\n';
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    string s;
    cin >> s;
    int n, x = 0;
    cin >> n;
    for (int i = 'a'; i <= 'z'; ++i) {
        set<string> v;
        for (int j = 0; j < s.length(); ++j) {
            if(s[j] == i){
                for (int k = 1; k <= min(static_cast<int>(s.length()-j), n); ++k) {
                    v.emplace(s.substr(j, k));
                }
            }
        }
        for (auto &&a : v) {
            x++;
            if(x == n) {
                cout << a << "\n";
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
/***********************************
*******AUTHOR SHASHI KANT **********         
****GMAIL Shshiksnt140895@gmail.com*
************************************                                  
***********************************/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
/*class graph
{
	map<int,list<int>>adj;
	public :
	       void addedge(int a, int b)
	       {
	           adj[a].push_back(b);
	           adj[b].push_back(a);
	       }

}*/
struct kanp
{
	ll w,v;
};
ll max_val(vector<kanp>ar, ll n, ll sum)
{
	ll  dp[n+1][sum+1];
	for(int i=0; i<=sum; i++)
		dp[1][i] = 0;
	dp[1][ar[1].w] = ar[1].v;
	for(int i=2; i<=n; i++)
	{
		for(int j=0; j<=sum; j++)
		{
			dp[i][j] = dp[i-1][j];
			if(ar[i].w > j)
				continue;
			else
				dp[i][j] = max(dp[i][j], ar[i].v+dp[i-1][j-ar[i].w]);
        }
	}

	return *max_element(dp[n], dp[n]+sum+1);
	   
}
int main(){
     
        ll n, sum;
        cin>>n>>sum;
        vector<kanp>ar(n+1);
        for(int i = 1; i<=n; i++)
        {
        	cin>>ar[i].w;
        	cin>>ar[i].v;
        }
        cout<< max_val(ar, n, sum) << endl;

	return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    P p[m];
    rep(i, m) cin >> p[i].second >> p[i].first;
    sort(p, p+m);

    int ans = 0;
    int pre_b = -1;
    rep(i, m){
        if(p[i].second > pre_b) {
            pre_b = p[i].first-1;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = 1;
		int b = 1;
		while(a != 0) {
			a = sc.nextInt();
			if(a == 0) {
				break;
			}
			System.out.println("Case " + b + ": " + a);
			b++;
		}
	}
}


Measured memory_bytes: 43892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i];
    vector<ll> sum(n), dif(n);
    for(int i = 0; i < n; i++){
        sum[i] = x[i] + y[i];
        dif[i] = x[i] - y[i];
    }
    sort(sum.begin(), sum.end());
    sort(dif.begin(), dif.end());
    ll mx = 0;
    mx = max(mx, sum[n - 1] - sum[0]);
    mx = max(mx, dif[n - 1] - dif[0]);
    cout << mx << "\n";
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;



int main(){
    ll n;
    cin>>n;
    string s="";
    while(n!=0){
        ll k=n%26;
        if(k==0) k=26;
        s+=char(96+k);
        n--;
        n/=26;
    }
    Reverse(s);
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3620
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B

f :: [Int] -> [Int] -> Int
f _ [] = 0
f (x:y:as) (b:bs) = if x <= b then x + (if (max 0 $ y - (b - x)) == 0 then y else b-x) + (f ((max 0 $ y - (b - x)):as) bs)
  else b + (f (y:as) bs)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  bs <- map read.words <$> getLine :: IO [Int]

  print $ f as bs


Measured memory_bytes: 98172
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m,n,a;
	cin>>m>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		m-=a;
	}
	if(m<=0)cout<<"Yes\n";else cout<<"No\n";
}


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int N, L[100000], R[100000], P[100000];

  priority_queue< int64 > Left; // くだり(降順)
  priority_queue< int64, vector< int64 >, greater<> > Right; // のぼり
  int64 rightBase = 0LL, leftBase = 0LL;
  int64 ret = 0LL;

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
    P[i] = R[i] - L[i];
  }
  for(int i = 0; i < N; i++) {
    rightBase += P[i];
    Left.emplace(R[i] - leftBase);
    Right.emplace(R[i] - rightBase);
    while(Left.top() + leftBase > Right.top() + rightBase) {
      int64 l = Left.top() + leftBase, r = Right.top() + rightBase;
      ret += l - r;
      Left.pop(), Right.pop();
      Right.push(l - rightBase), Left.push(r - leftBase);
    }
    leftBase -= P[i];
  }

  cout << ret << endl;
}

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int, int> T;
typedef tuple<int, int, int, int, int> T2;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int w, h; cin>>w>>h;
        if(w == 0) return 0;

        int tx, ty, kx, ky; cin>>tx>>ty>>kx>>ky;

        vector<vector<int>> d(h+2, vector<int>(w+2, 1));
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                cin>>d[i][j];
            }
        }

        map<T, bool> visited;
        visited[T(ty, tx, ky, kx)] = true;

        bool valid = false;
        queue<T2> que;
        que.push(T2(ty, tx, ky, kx, 0));
        while(que.size()){
            int cy1, cx1, cy2, cx2, cnt;
            tie(cy1, cx1, cy2, cx2, cnt) = que.front();
            que.pop();

            if(100 <= cnt) continue;

            if(cy1 == cy2 && cx1 == cx2){
                cout << cnt << endl;
                valid = true;
                break;
            }

            for(int i=0; i<4; i++){
                int ny1 = cy1 + dy[i];
                int nx1 = cx1 + dx[i];
                int ny2 = cy2 - dy[i];
                int nx2 = cx2 - dx[i];

                if(d[ny1][nx1] == 0 && d[ny2][nx2] == 0 && !visited[T(ny1, nx1, ny2, nx2)]){
                    visited[T(ny1, nx1, ny2, nx2)] = true;
                    que.push(T2(ny1, nx1, ny2, nx2, cnt + 1));
                }
                else if(d[ny1][nx1] == 0 && d[ny2][nx2] == 1 && !visited[T(ny1, nx1, cy2, cx2)]){
                    visited[T(ny1, nx1, cy2, cx2)] = true;
                    que.push(T2(ny1, nx1, cy2, cx2, cnt + 1));
                }
                else if(d[ny1][nx1] == 1 && d[ny2][nx2] == 0 && !visited[T(cy1, cx1, ny2, nx2)]){
                    visited[T(cy1, cx1, ny2, nx2)] = true;
                    que.push(T2(cy1, cx1, ny2, nx2, cnt + 1));
                }
            }
        }

        if(!valid){
            cout << "NA" << endl;
        }
    }
}


Measured memory_bytes: 13860
using System;
using System.Collections;
class Program
{
	private static Hashtable sosu;
	static void Main(string[] args)
	{
		sosu = new Hashtable();
		AddSosu(int.Parse(Console.ReadLine()));
		Console.WriteLine(CountSosu());
	}

	static void AddSosu(int num){
		if(num == 1) return;

		int origin = num;
		for(int i=2; i<=origin; i++){
			while(num % i == 0){
				if(sosu[i] == null)
					sosu[i] = 0;
				
				sosu[i] = (int)sosu[i] + 1;

				num /= i;
			}
		}
		AddSosu(origin - 1);
	}
	static UInt64 CountSosu(){
		UInt64 result = 1;
		foreach (int item in sosu.Values){
			result *= (UInt64)(1+item);
			result %= 1000000007;
		}
		return result;
	}
}

Measured memory_bytes: 3032
#!/usr/bin/env python3
import sys
from collections import deque
input = sys.stdin.readline
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)] 
for i in range(n-1):
    a, b = [int(item) - 1 for item in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))

colors = 0
for i, line in enumerate(edge):
    colors = max(colors, len(line))
    if len(line) == 1:
        start = i
print(colors)

dq = deque()
dq.append((i, -1, -1))

color = [-1] * (n - 1)

while dq:
    v, prev, prev_c = dq.popleft()
    c = 0
    for dest, index in edge[v]:
        if dest == prev:
            continue
        if c == prev_c:
            c += 1
        color[index] = c 
        dq.append((dest, v, c))
        c += 1
for item in color:
    print(item + 1)

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

int n,a,b,c;  
string s,t;

int main() {
  cin >> n;
  rep(i,n+1){
    if(int(i*1.08)==n){
      cout << i << endl; return 0;
    }
  }
  cout << ":(" << endl; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, l, i;
  vector<string> v;

  cin >> n>>l;
  char str[l];

  for (i=0; i < n; i++) {
    cin >> str;
    v.push_back(str);
  }


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

  for (i=0; i<n; i++) {
    cout << v[i];
  }
  cout << endl;
  return 0;
}


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

#define ll long long

int main() {
    int N;
    int z_count = 0;
    int o_count = 0;
    string str;
    cin >> str;
    N = str.size();
    for(int i = 0;i < N;i++) {
        if(str[i] == '0') {
            z_count++;
        }else{
            o_count++;
        }
    }
    printf("%d\n", z_count < o_count ? 2*z_count : 2*o_count);
    return 0;
}

Measured memory_bytes: 512
S=input()
import sys

if S[0]!='A':
    print ('WA')
    sys.exit()

count=0
for i in range (len(S[2:len(S)-1])):
    if S[2:len(S)-1][i]=='C':
        count+=1
if count!=1:
    print ('WA')
    sys.exit()
    
count2=0
for j in range (len(S)):
    if S[j].isupper()==True:
        count2+=1
if count2!=2:
    print ('WA')
    sys.exit()

print('AC')

Measured memory_bytes: 3064
#include <cstdio>
  #include <iostream>
  #include <string.h>
  #include <cstring>
  #include <cmath>
  #include <math.h>
  #include <algorithm>
  #include <iomanip>
  #include <map>
  #include <set>
  #include <vector>
  #include <sstream>
  #include <queue>  
  #include <bitset>
#define MAX 100005
#define INF 9999999999999
#define pb push_back
using namespace std;
typedef long long int ll;
 typedef pair<ll,ll> ii;
 typedef vector<ii> vii;
 typedef vector <ll > vi;
 
vector <vii> adj(MAX); 
ll arr[100005];
int main()
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a,b;
cin>>a>>b;
if(a+b<10)
cout<<a+b<<endl;
else
cout<<"error"<<endl;
   return 0;
}  

Measured memory_bytes: 2560
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for x in range(1, N + 1):
    s = str(x)
    l = int(s[0])
    r = int(s[-1])
    d[(l, r)] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)

Measured memory_bytes: 3316
import sys
N = int(input())
mod = 10**9 + 7
if N == 1:
  print(0)
  sys.exit()
if N >= 2:
  ans0 = [0]*(N+1)
  ans  = [0]*(N+1)
  ansp = [0]*(N+1)
  ans0[1] = 1
  ansp[1] = 8
  ans[1] = 0
  for i in range(N - 1):
    j = i + 1
    ans[j+1] = (2*ans0[j] + 10*ans[j])%mod
    ans0[j+1] = (9*ans0[j] + ansp[j])%mod
    ansp[j+1] = (ansp[j]*8)%mod
  print(ans[N]%mod)  

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

	int main(){
      string S,T;
      cin >> S;
      while (S!=""){
        S.pop_back();
        S.pop_back();
        T=S;
        T.erase(T.begin(),T.begin()+T.size()/2);
        if (S==T+T){
          cout << S.size() << endl;
          return 0;
        }
      }
    }


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll dp[110][10]{};

int main(int argc, char **argv)
{
	ll H, W, K; cin >> H >> W >> K;

	**dp = 1;

	REP(h, H)REP(w, W)
	{
		REP(bits, (1ll<<(W-1)))
		{
			bool ok{true};
			REP(ww, W-2)
			{
				if ((bits & (1ll<<ww)) && (bits & (1ll<<(ww+1))))
					ok = false;
			}
			if (!ok) continue;

			if (w >= 1 && (bits & (1ll<<(w-1))))
				(dp[h+1][w-1] += dp[h][w]) %= MOD;
			else if (w <= W-2 && (bits & (1ll<<w)))
				(dp[h+1][w+1] += dp[h][w]) %= MOD;
			else
				(dp[h+1][w] += dp[h][w]) %= MOD;
		}
	}

	std::cout << dp[H][K-1] << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

string s, t;
ll dp[3005][3005];

void solve() {
    cin >> a >> b >> c >> d;
    dp[a][b] = 1ll;
    for(ll i=a;i<=c;i++){
        for(ll j=b;j<=d;j++){
            if (i == a && j == b) continue;
            // 真ん中を塗る場合
            dp[i][j] += dp[i][j-1] + dp[i-1][j];
            dp[i][j] %= mod;

            // 真ん中を塗らない場合
            dp[i][j] += dp[i][j-1] * (i - 1) % mod;
            dp[i][j] %= mod;

            dp[i][j] += dp[i-1][j] * (j - 1) % mod;
            dp[i][j] %= mod;

            ll tmp = ((dp[i-1][j-1] * (i - 1)) % mod) * (j - 1) % mod;
            tmp = mod - tmp;

            dp[i][j] += tmp;
            dp[i][j] %= mod;
        }
    }
    ll ans = dp[c][d];
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 73892
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

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

	bool broken = false;
	
	int n; cin >> n;
	int time = 0, px = 0, py = 0;
	while(n--) {
		int t, x, y; cin >> t >> x >> y;
		int needed = abs(x - px) + abs(y - py);
		broken |= (needed > (t - time) || ((needed % 2) != ((t + time) % 2)));
		time = t, px = x, py = y;
	}
	cout << (broken? "No": "Yes") << endl;
}


Measured memory_bytes: 384
def modelAnswer(N:int,A:list) -> None:
   total = 0
   for j in range(N-1):
      total += abs(A[j] - A[j+1])
   total += abs(A[0]) + abs(A[N-1])
   for i in range(N):
      p = 0 if(i == 0) else A[i-1]
      n = 0 if(i == N - 1) else A[i + 1]
      print(total + abs(p - n) - (abs(p - A[i])+ abs(A[i] - n)))
def main():
   N = int(input())
   A = list(map(int,input().split()))
   modelAnswer(N,A[:])
if __name__ == '__main__':
   main()

Measured memory_bytes: 14048
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main() {
	long long N;
	cin >> N;
	vector<vector<long long>> A(N, vector<long long>(3));

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A.at(i).at(j);
		}
	}

	vector<vector<long long>> dp(110000, vector<long long>(3));

	for (int i = 0; i < 3; i++) {
		dp.at(0).at(i) = A.at(0).at(i);
	}

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j == k) continue;
				dp.at(i).at(k) = max(dp.at(i).at(k), dp.at(i - 1).at(j) + A.at(i).at(k));
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 3; i++) {
		ans = max(ans, dp.at(N - 1).at(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 14880
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]

for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)

stack = []
stack.append([0, set()])
ans = 0
while stack:
  v, visited = stack.pop()
  visited.add(v)
  if len(visited) == N:
    ans += 1
    continue
  for child in G[v]:
    if child in visited:
      continue
    visited_c = visited.copy()
    stack.append([child, visited_c])
  
print(ans)

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

int main()
{
    int n,temp;
	cin >> n;
	int* a = new int[n];
	vector<int> v; 
	for(int i = 0;i < n;i++)
		cin >> a[i];
	v.push_back(a[0]);
	if(n % 2 == 1)
	{
	    for(int i = 1;i < n;i = i + 2)  
	    {
	    v.insert(v.begin(),a[i + 1]);
	    v.insert(v.end(),a[i]);
	    }
	}
	if(n % 2 == 0)
	{
		for(int i = 1;i < n - 1;i = i + 2)  
	    {
	    v.insert(v.begin(),a[i + 1]);
	    v.insert(v.end(),a[i]);
	    }
	    v.insert(v.end(),a[n - 1]);
	    for(int x = 0,y = n-1;x < y;x++,y--)
	    {
	    	temp = v[x];
	    	v[x] = v[y];
	    	v[y] = temp;
	    }
	}
	for(int i = 0;i < n;i++)
	cout << v[i] << " ";
	delete []a;
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
LL n;
LL bit[MAXN];

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}


void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)



void up(LL x, LL v){
	while(x<=(n)){
		bit[x]+=v;
		x+=x&-x;
	}
}

LL qu(LL x){
	LL su = 0;
	while(x>0){
		su+=bit[x];
		x-=x&-x;
	}
	return su;
}

LL k;
int main(){
  fio();
  cin>>n>>k;
  vector<LL> a(n+1);
  for1(i,n) {
  	cin>>a[i];
  	LL l = max(1LL, i - a[i]);
  	LL r = min(n, i+a[i])+1;
  	up(r,-1);
  	up(l,+1);
  }
  k = min(100LL, k);

  vector<LL> an(n+1);
  while(k){
  	 //cout<<"yes"<<endl;
	  for1(i,n) an[i] = qu(i);
	  //debug(an);
	  memset(bit, 0 ,sizeof bit);
	  for1(i,n){
	  	LL l = max(1LL, i - an[i]);
	  	LL r = min(n, i+an[i])+1;
	  	up(r,-1);
	  	up(l,+1);
	  }
	  k--;
	}
  for1(i,n) cout<<an[i]<<" ";
  cout<<endl;
  return 0;
}

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

import math

def factoring(n):
    num = 0
    for i in range(1, n + 1):
        if n % i == 0:
            num += 1
    return num


N = int(input())
ans = 0
for i in range(1, N + 1, 2):
    if int(factoring(i)) == 8:
        ans += 1 

print(ans)


Measured memory_bytes: 2940