akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
from collections import deque


class Graph:
    def __init__(self, n, adj_matrix):
        self.n = n
        self.adj_matrix = adj_matrix

    def show(self):
        for _ in self.adj_matrix:
            print(*_)

    def dfs(self):
        self.states = [2] * self.n
        self.d = [None] * self.n
        self.f = [None] * self.n
        self.time = 0

        for u in range(self.n):
            if self.states[u] == 2:
                self.dfs_visit(u)

    def dfs_visit(self, u):
        self.states[u] = 1
        self.time += 1
        self.d[u] = self.time

        for v, edge in [(v, edge) for v, edge in enumerate(self.adj_matrix[u])
                        if edge]:
            if self.states[v] == 2:
                self.dfs_visit(v)

        self.states[u] = 0
        self.time += 1
        self.f[u] = self.time

    def show_dfs(self, start=0):
        self.dfs()
        for i, (d, f) in enumerate(zip(self.d, self.f)):
            print(i + 1, d, f)

    def bfs(self, start):
        self.states = [0] * self.n
        self.dists = [float('inf')] * self.n

        queue = deque([start])
        self.dists[start] = 0
        while queue:
            u = queue.popleft()
            edges = self.adj_matrix[u]

            for v, edge in [(v, edge) for v, edge in enumerate(edges) if edge]:
                if self.states[v]:
                    continue

                if self.dists[v] > self.dists[u] + 1:
                    self.dists[v] = self.dists[u] + 1
                queue.append(v)

                self.states[v] = 1

        self.dists = [
            -1 if dist == float('inf') else dist for dist in self.dists
        ]

    def show_bfs(self, start=0):
        self.bfs(start=start)
        for i, dist in enumerate(self.dists):
            print(i + 1, dist)


if __name__ == '__main__':
    n = int(input())
    adj_matrix = [[0] * n for i in range(n)]
    for i in range(n):
        for v in input().split()[2:]:
            adj_matrix[i][int(v) - 1] = 1

    g = Graph(n, adj_matrix)
    g.show_bfs()



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


int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int n;
    cin >> n;
    int *s = new int[n];
    int index = 0;
    while( index < n )
    {
        char c;
        cin >> c;
        char tmp = -1;
        if( c == 'R') tmp = 0;
        if( c == 'G') tmp = 1;
        if( c == 'B') tmp = 2;
        if( tmp >= 0 )
        {
            s[index++] = tmp;
        }
    }

    long long ans = 0;
    for( int i = 1; i < n - 1; i++ )
    {
        int target[2];
        int tmap[3];
        int c = s[i];
        tmap[c] = -1;
        index = 0;
        for( int j = 0; j < 3; j++)
        {
            if( j != c ) target[index++] = j;
        }
        for( index = 0; index < 2; index++)
        {
            tmap[target[index]] = index;
        }

        int l[2];
        int r[2];
        for (int j = 0; j < 2; j++)
        {
            l[j] = 0;
            r[j] = 0;
        }

        int samecount = 0;

        for( int d = 1; i - d >= 0 || i + d < n; d++ )
        {
            int flag = 0;
            if( i - d >= 0 && tmap[s[i-d]] >= 0 ) 
            {
                l[tmap[s[i-d]]]++;
                flag++;
            }
            if( i + d < n && tmap[s[i+d]] >= 0 )
            {
                r[tmap[s[i+d]]]++;
                flag++;
            } 
            if( flag == 2 && s[i-d] != s[i+d]) samecount++;
        }

        ans += l[0] * r[1] + l[1] * r[0] - samecount;
    }
    cout << ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 1000000000
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll ninf = (-1) * (ll)1e16;

struct edge{
	int from, to, cost;
};

int N, M;
vector<edge> G;
ll d[1000];


int main(void){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int a, b, c; cin >> a >> b >> c;
		edge e = {--a, --b, c}; G.push_back(e);
	}

	fill(d, d+N, ninf); d[0] = 0;
	bool updated = true;
	for(int i = 0; i < N-1 and updated; i++){
		updated = false;
		for(auto e: G){
			if(d[e.from] > ninf and d[e.to] < d[e.from] + (ll)e.cost){
				updated = true;
				d[e.to] = d[e.from] + (ll)e.cost;
			}
		}
	}

	ll res = d[N-1];

	// 0->N-1のpathで正の閉路があればinf
	// bool check[1000];
	// fill(check, check+N, false);
	for(int i = 0; i < N-1; i++){
		for(auto e: G){
			if(d[e.from] > ninf and d[e.to] < d[e.from] + (ll)e.cost){
				d[e.to] = d[e.from] + (ll)e.cost;
			}
		}
	}

	if(d[N-1] > res) cout << "inf" << '\n';
	else cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long a[3]={0};
    scanf("%ld%ld%ld", &a[0],&a[1],&a[2]);

    sort(a+0, a+3);

    printf("%ld\n", a[0]+a[1]);


    return 0;
}


Measured memory_bytes: 128
N = int(input())
C = input()

R, W = [], []
R_ = []
nR, nW = 0, 0
for c in C:
    if c == 'R':
        nR += 1
    else:
        nW += 1
    R.append(nR)
    W.append(nW)

if nR == 0 or nW == 0:
    print(0)
    exit()

for r in R:
    R_.append(nR - r)

ans = N

for i in range(N):
    r, w, r_ = R[i], W[i], R_[i]
    if r_ > w:
        ans = min(r_, ans)
    else:
        ans = min(w, ans)
print(ans)


Measured memory_bytes: 26820
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;

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

Node *root, *NIL;

Node * find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *x = root;
	Node *y = NIL;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if (y == NIL)
		root = z;
	else {
		if (z->key < y->key)
			y->left = z;
		else
			y->right = z;
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}


int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


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

using namespace std;

int main() {
  string str;
  cin >> str;
  
  size_t half = str.size() / 2;
  size_t hug = 0;
  for (size_t i = 0; i < half; ++i) {
    if (str[i] != str[str.size()-1 -i]) {
      ++hug;
    }
  }
  cout << hug << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s1,s2;
    for (int i=0;i<n;i++) {
        int num_s1=0,num_s2=0;
        cin>>s1;
        for (int j=0;j<s1.size();j++) {
            char c=s1.at(j);
            if (c=='m'||c=='c'||c=='x'||c=='i') {
                if (c=='m') {
                    num_s1+=1000;
                } else if (c=='c') {
                    num_s1+=100;
                } else if (c=='x') {
                    num_s1+=10;
                } else if (c=='i') {
                    num_s1+=1;
                }
            } else {
                int tmp=c-48;
                char next=s1.at(j+1);
                if (next=='m') {
                    num_s1+=tmp*1000;
                } else if (next=='c') {
                    num_s1+=tmp*100;
                } else if (next=='x') {
                    num_s1+=tmp*10;
                } else if (next=='i') {
                    num_s1+=tmp*1;
                }
                j++;
            }
        }
        //cout<<num_s1<<endl;
        cin>>s2;
        for (int k=0;k<s2.size();k++) {
            char c2=s2.at(k);
            if (c2=='m'||c2=='c'||c2=='x'||c2=='i') {
                if (c2=='m') {
                    num_s2+=1000;
                } else if (c2=='c') {
                    num_s2+=100;
                } else if (c2=='x') {
                    num_s2+=10;
                } else if (c2=='i') {
                    num_s2+=1;
                }
            } else {
                int tmp2=c2-48;
                char next2=s2.at(k+1);
                if (next2=='m') {
                    num_s2+=tmp2*1000;
                } else if (next2=='c') {
                    num_s2+=tmp2*100;
                } else if (next2=='x') {
                    num_s2+=tmp2*10;
                } else if (next2=='i') {
                    num_s2+=tmp2*1;
                }
                k++;
            }
        }
        //cout<<num_s2<<endl;
        int sum=num_s1+num_s2;
        if (sum/1000!=0) {
            if (sum/1000!=1) {
                cout<<sum/1000<<"m";
            } else {
                cout<<"m";
            }
        }
        if ( (sum%1000)/100!=0 ) {
            if ( (sum%1000)/100!=1 ) {
                cout<<(sum%1000)/100<<"c";
            } else {
                cout<<"c";
            }
        }
        if ( ((sum%1000)%100)/10!=0 ) {
            if ( ((sum%1000)%100)/10!=1 ) {
                cout<<((sum%1000)%100)/10<<"x";
            } else {
                cout<<"x";
            }
        }
        if ( ((sum%1000)%100)%10!=0 ) {
            if ( ((sum%1000)%100)%10!=1 ) {
                cout<<((sum%1000)%100)%10<<"i";
            } else {
                cout<<"i";
            }
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	if (n % k == 0) cout << 0 << '\n';
	else cout << 1 << '\n';
	
	return 0;
}


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

int main (){
    long long l[300000] = {0};
    long long ans[300000] = {0};
    int n,k;
    int i; 
    long long temp[300000] = {0};
    long long wa = 0;
    long long min = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&l[i]);
        wa += l[i];
        if(i == 0){
            temp[i] = l[i];
        }else{
            temp[i] = temp[i-1] + l[i];
        }
    }
    
    for(i=0;i<n-1;i++){
        ans[i] = 2*temp[i] - wa;
        if(ans[i] < 0){
            ans[i] *= -1;
        }
    }
    min = ans[0];
    for(i=1;i<n-1;i++){
        if(ans[i] < min){
            min = ans[i];
        }
    }
    /*for(i=0;i<n;i++){
        printf("%lld\n",ans[i]);
    }*/
    printf("%lld\n",min);
    
    return 0;
}


Measured memory_bytes: 7424
A = []
for _ in range(3):
    a = [int(a) for a in input().split()]
    A.append(a)
N = int(input())
for _ in range(N):
    num = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==num:
                A[i][j] = -1

# Rows
for row in range(3):
    bingo_row = True
    for col in range(3):
        if A[row][col]!=-1:
            bingo_row = False
    if bingo_row:
        print('Yes')
        exit()
    
# Columns
for col in range(3):
    bingo_col = True
    for row in range(3):
        if A[row][col]!=-1:
            bingo_col = False
    if bingo_col:
        print('Yes')
        exit()

# Naname
bingo_naname = True
for i in range(3):
    col, row = i, i
    if A[row][col] != -1:
        bingo_naname = False
if bingo_naname:
    print('Yes')
    exit()
bingo_naname = True
for i in range(3):
    col, row = 2-i, i
    if A[row][col] != -1:
        bingo_naname = False
if bingo_naname:
    print('Yes')
    exit()

print('No')


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

int main() {
  string S;
  cin >> S;
  int N = 0;
  for (int i = 0; i < S.size(); i++) N += (S.at(i) - '0');
  if (N % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template<typename T>
std::vector<int> topological_sort(const Graph<T> &graph) {
    Graph<T> g = graph;
    int n = g.size();
    std::vector<int> res;
    std::queue<int> que;
    std::vector<std::set<int>> in(n);
    for(int i=0;i<n;++i) {
        for(int j=0;j<(int)(g[i].size());++j) {
            in[g[i][j].to].insert(i);
        }
    }
    for(int i=0;i<n;++i) {
        if((int)(in[i].size()) == 0) que.push(i);
    }
    while(!que.empty()) {
        int now = que.front(); que.pop();
        res.push_back(now);
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            if((int)(in[next].size()) == 1) {
                que.push(next);
            }
            in[next].erase(now);
        }
        g[now].clear();
    }
    for(int i=0;i<n;++i) {
        if((int)(g[i].size()) > 0) {
            res.resize(1, -1);
            break;
        }
    }
    return res;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vvi a(n, vi(n-1));
  for(int i=0;i<n;++i) {
    for(int j=0;j<n-1;++j) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  Graph<int> g(n*n);
  map<int, bool> used;
  for(int i=0;i<n;++i) {
    for(int j=0;j<n-2;++j) {
      int u = a[i][j], v = a[i][j+1];
      if(i < u) u = n * i + u;
      else u = n * u + i;
      if(i < v) v = n * i + v;
      else v = n * v + i;
      used[u] = true;
      used[v] = true;
      g[u].push_back(Edge<int>(u, v, 1));
    }
  }
  vector<int> d = topological_sort(g);
  if((int)(d.size()) != n*n) {
    cout << -1 << endl;
    return 0;
  }
  if(d[0] == -1) {
    cout << -1 << endl;
    return 0;
  }
  int match = 0, ma = 0;
  vector<int> dist(n*n, 0);
  for(int i=0;i<n*n;++i) {
    if(!used[d[i]]) continue;
    used[d[i]] = false;
    int now = d[i];
    for(int j=0;j<(int)(g[now].size());++j) {
      int next = g[now][j].to;
      dist[next] = max(dist[next], dist[now] + 1);
      ma = max(ma, dist[next]);
    }
  }
  for(auto &e: used) {
    if(e.second) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ma + 1 << endl;
}


Measured memory_bytes: 207472
#include<bits/stdc++.h>
using namespace std;
int main() {
    int h,w;
    cin >>h>>w;
    char a[h][w];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		cin >> a[i][j];
		}
	}
	for(int i=0;i<w+2;i++){
		cout<<"#";
	}
	cout<<endl;
	 for(int i=0;i<h;i++){
	 	cout<<"#";
    	for(int j=0;j<w;j++){
    		cout<< a[i][j];
		}
		cout<<"#"<<endl;
	}
	for(int i=0;i<w+2;i++){
		cout<<"#";
	}
	return 0;
}

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

using namespace std;

int main() {
	string s;
	int year = 0;
	int month = 0;
	int day = 0;
	cin >> s;
	year = (s[3] - '0') + (s[2] - '0') * 10 + (s[1] - '0') * 100 + (s[0] - '0') * 1000;
	month = (s[6] - '0') + (s[5] - '0') * 10;
	day = (s[9] - '0') + (s[8] - '0') * 10;
	if (year >= 2019){
		if (year > 2019) cout << "TBD";
		else 
		if (month >= 4){
			if (month > 4)
				cout << "TBD";
			else if (month == 4){
				if (day <= 30)
					cout << "Heisei";
				else
					cout  << "TBD";
			}
		} else{
			if (day < 30)
				cout << "Heisei";
			else
				cout << "TBD";
		}
	}else
		cout << "Heisei"; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n, p, maxp, max, d1, d2;
	while( cin >> n && n ){
		max = -1;
		for ( int i = 0; i < n; i++ ){
			cin >> p >> d1 >> d2;
			if ( max < d1 + d2 ){
				maxp = p;
				max = d1 + d2;
			}
		}
		cout << maxp << " " << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
s = input()
p = input()
Flag = False
for i in range(len(s)):
    if len(s)<len(p):
        print("No")
        break
    for j in range(len(p)):
        if i+j>=len(s):
            if s[i+j-len(s)] != p[j]:break
        elif s[i+j] != p[j]:break
        if j == len(p)-1:
            print("Yes")
            Flag = True
            break
    if Flag:break
    if i == len(s)-1:print("No")


Measured memory_bytes: 5560
s = input()
n = len(s)
ans = 1
l = ''
k = s[0]
for i in range(1,n):
    
    
    if l + s[i] != k :
        k =  l + s[i] 
        l =''
        ans += 1
    else:
        l += s[i]
print(ans)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000009
#define pb push_back
#define endl '\n'
#define tez_chal ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e9+7;
int solve()
{
 
  ll n,W;cin>>n>>W;
  vector<ll>weight(n),value(n);
  //for(ll i:range(n)) cin>>weight[i]>>value[i];
  for(ll i=0;i<n;i++) cin>>weight[i]>>value[i];

  ll sum_values=0;
  
  for(auto v:value) sum_values+=v;

  vector<ll>dp(sum_values+1,INF);
  
 
  dp[0]=0;

  for(ll item=0;item<n;item++){

  	// left to right (if an item can be used multiple times)
  	// right to left (if an item can only be used single time) 
  	// reason is i'm just using a single array to represent the previous work + i'm updating the 
  	// same array for the current item... to avoid use of the already computed answer for teh
  	// current item , we should proceed right to left.
	  for(ll i=sum_values;i>=0;i--){
	  	   if(i-value[item]>=0){
	  	   	dp[i]=min(dp[i],dp[i-value[item]] + weight[item]);
	  	   }
	  }

  }
  ll ans=0;
  
  for(ll i=0;i<=sum_values;i++){
  	if(dp[i]<=W) ans=max(i,ans);
  }
  
   cout<<ans<<endl;


return 0;
}


 








int main()
{  
    tez_chal;     ll t=1;  //cin>>t;
    
    while(t--) solve();

    // ll testcase=1;
    // while(t--){
    // 	cout<<"Case #"<<testcase++<<": ";
    // 	solve();
    // }

    return 0;
}




Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    string S;
    cin >>S;
    int n = S.size();
    vi SS(n);
    rep(i,n) SS[i] = S[n-1-i]-'0';
    vi mod19(n);
    int p10 =1;
    mod19[0] = SS[0];
    rep2(i,1,n){
        p10 = (p10*10)%2019;
        mod19[i] = (mod19[i-1] + p10*SS[i])  % 2019;
    }
    vi count(2019,0);
    count[0] = 1;
    rep(i,n){
        count[mod19[i]]++;
    }
    ll ans=0;
    rep(i,2019){
        ans += count[i]*(count[i]-1)/2;
    }
    cout <<ans<<endl;
}


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

typedef long long ll;

ll N, K;
ll x[100000];

int main(){
    scanf("%lld%lld", &N, &K);
    ll sum = 0;
    ll minl = 1e9;
    for(long i=0; i<N; i++){
        scanf("%lld", &x[i]);
    }
    for(long i=K-1; i<N; i++){
        sum = abs(x[i] - x[i-K+1]);
        minl = min(minl, min(sum+abs(x[i]), sum+abs(x[i-K+1])));
    }
    printf("%lld", minl);
}



Measured memory_bytes: 1024
x1,y1,x2,y2=map(int,input().split())
xdis=x2-x1
ydis=y2-y1
x3=x2-ydis
y3=y2+xdis
x4=x1-ydis
y4=y1+xdis
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(void)
{
    unsigned char s[200001];
    long long int a,b = 0,i;
    scanf("%s",s);
    a = strlen(s);
    
    for(i = 0 ; i < a ; i++)
    {
        if(s[i] == '1')
        {
            b += 1;
        }
        if(s[i] == '2')
        {
            b += 2;
        }
        if(s[i] == '3')
        {
            b += 3;
        }
        if(s[i] == '5')
        {
            b += 5;
        }
        if(s[i] == '6')
        {
            b += 6;
        }
        if(s[i] == '7')
        {
            b += 7;
        }
        if(s[i] == '8')
        {
            b += 8;
        }
        if(s[i] == '9')
        {
            b += 9;
        }
        if(s[i] == '0')
        {
            b += 0;
        }
        if(s[i] == '4')
        {
            b += 4;
        }
    }
    b = b % 9;
    if(b == 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 1816
n, m = map(int, input().split())
dp = [-1] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    dp[aa] = 0
    a.append(aa)
mod = 10 ** 9 + 7

dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == 0:
        continue
    else:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



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

	ll a,b;
	string s;
	cin >>a >>b;
	ll z=a*b;
	cout << (z%2==1? "Odd":"Even") <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

struct Edge {
    ll to, id;
    Edge(ll to, ll id):to(to),id(id) {}
};

vector<vector<Edge>> G;
vl ans;
 
void dfs(ll v, ll p = -1, ll c = 0) {
    // 行きの処理はこのへんに書く
    ll num = 1;
    for(Edge e : G[v]) {
        if(e.to == p) {
            continue;
        }
        if(num == c) {
            num++;
        }
        ans[e.id] = num;
        num++;
        dfs(e.to, v, ans[e.id]);
        // 帰りの処理はこのへんに書く
    }
}
 
int main() {
    ll n;
    cin >> n;    
 
    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    
    ll K = 0;
    rep(v, n) {
        chmax(K, (ll)G[v].size());
    }
    out(K);
    
    const ll root = 0;
    ans.resize(n-1);
    dfs(root);
    
    rep(id, n-1) {
        out(ans[id]);
    }
    
    re0;
}

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

ll mod = 1e9 + 7;

int power(int x, unsigned int y, int p)  
{  
    int res = 1;   
  
    x = x % p; 
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

int main(){
	string s;
	cin >> s;
	unordered_map <int, int> counts;
	ll curr = 0, res = 0;
	for(int i = s.size() - 1; i >= 0; --i){
		curr += power(10, s.size() - i - 1, 2019) * (s[i] - '0');
		curr %= 2019;
		counts[curr]++;
	}
	for(auto &i : counts){
		if(i.first == 0)
			res += i.second;
		res += (i.second * (i.second - 1)) / 2;
	}
	cout << res << endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1')
            res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
  S = input()
  while len(S)>=5:
    if len(S)>=7 and S[-7:]=="dreamer":
      S = S[:-7]
      continue
    
    elif len(S)>=6 and S[-6:]=="eraser":
      S = S[:-6]
      continue
    elif S[-5:]=="dream" or S[-5:]=="erase":
      S = S[:-5]
      continue
    else:
      break
  if len(S)==0:
    print('YES')
  else:
    print('NO')
    
main()


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

int n, k, score;

int main() {
  cin >> n >> k;
  vector<int> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  for (int i = k; i < n; i++) {
    if (a[i] > a[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 4052
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<long int> A(N);
    for (int i=0;i<N;i++) cin>>A[i];
    long long ans=0;
    sort(A.begin(),A.end());   
    ans=A[N-1];
    int j=N-2;
    for (int i=0;i<N-2;i++){
        ans+=A[N-2-i/2];
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;


int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef long long ll;
int len,fin;
char x[100020];
int main(){
    scanf(" %s",x);
    len=strlen(x);
    for(fin=1;fin<=len;fin++){
        int l=len-fin,r=fin-1;
        if(l>r) continue;
        if(x[len/2]!=x[l]||x[len/2]!=x[r]) break;
    }
    printf("%d\n",fin-1);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n,a[200010];
    cin>>n;
    for(int i=0;i<n;i++){
	cin>>a[i];
	a[i]*=-1;
	a[i]+=1e9;
    }
    vector<ll> v;
    v.push_back(0);
    for(int i=0;i<n;i++){
	auto it=upper_bound(v.begin(),v.end(),a[i]);
	if(it==v.end())v.push_back(a[i]);
	else v[it-v.begin()]=a[i];
    }
    cout<<v.size()-1<<endl;
}




Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
const ll mod =   1e9+7;

int main()
{  fast
string s;
cin>>s;
int n=s.size();
if(s[n-1]=='s'){
	string ss=s+"es";
	cout<<ss;
}
else
cout<<s+'s';
}

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

int main () {
  int N;
  cin >> N;
  int a, b;
  a = N / 10;
  b = N % 10;
  if (a == 9 || b == 9) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),
  fast;
	
	string str;
	cin>>str;
	ll q;
	cin>>q;
	deque<char> dq;
	ll cnt=0;
	for(ll i=0;i<str.length();i++)dq.push_back(str[i]);
	while(q--){
		ll p ; 
		cin>>p;
		if(p==1){
			cnt++;
		}
		else {
			ll s;
			cin>>s;
			char ch ;cin>>ch ;
			if(s==1){
				if(~cnt&1)
				dq.push_front(ch);
				else{
					dq.push_back(ch);
				}
			}
			else {
				if(cnt&1)
				dq.push_front(ch);
				else{
					dq.push_back(ch);
				}
			}
		}
	}
	if(cnt&1)reverse(dq.begin(),dq.end());
	// cout<<dq.size()<<endl;
	for(auto x: dq)cout<<x;

	return 0;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;

	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	int ans=0;
	for(int i=0;i<v.size();i++)
	 if(v[i]>m[v[i]]) ans+=m[v[i]];
	else if(v[i]<m[v[i]]) ans+=m[v[i]]-v[i];
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 5112
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=1000000007;

void solve(){

	string s;
	cin>>s;
	ll max=0;

	ll r=0;
	ll sum=0;
	for(ll left=0;left<s.size();left++){
		r=left;
		while(r<s.size() && (s[r]=='A' || s[r]=='G' || s[r]=='C' || s[r]=='T')){
			r++;
			sum++;
		}
		if(sum>max){
			max=sum;
		}
		sum=0;
	}

	cout<<max<<endl;

	
}


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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    ll N, K;
    cin >> N >> K;
    if (2 * K - N - 1 > 0) {
        write(-1);
        return 0;
    }

    vector<ll> a, b, c;
    int M = 2 * K - 1;
    a.push_back(K + (M - 1) / 2);
    b.push_back(K + 2 * M - 1);
    c.push_back(K + 3 * M - 1);
    rep(i, (M - 1) / 2) {
        a.push_back(K + (M - 1) / 2 + (i + 1));
        b.push_back(K + 2 * M - 1 - 2 * (i + 1));
        c.push_back(K + 3 * M - 1 - (i + 1));
    }
    rep(i, (M - 1) / 2) {
        a.push_back(K + (M - 1) / 2 - (i + 1));
        b.push_back(K + M + 2 * i + 1);
        c.push_back(K + 2 * M + i);
    }
    for (ll& x : a) x += N - M;
    for (ll& x : b) x += (N - M) * 2;
    for (ll& x : c) x += (N - M) * 3;
    rep(i, N - M) {
        a.push_back(K + i);
        b.push_back(K + N + i);
        c.push_back(K + 2 * N + i);
    }

    rep(i, N) cout << a[i] << ' ' << b[i] << ' ' << c[i] << endl;
}

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

int main()
{
    int rot;
    string str;
    cin >> rot >> str;

    for (char ptr : str)
    {
        char ch = (ptr - 'A' + rot) % 26 + 'A';
        cout << ch;
    }
    cout << endl;
}



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){if(a < b) a = b;}

ll fz(int n, ll k, const VL& a){
	VL jun;
	rep(i, n) rep(j, i) jun.push_back(a[i]*a[j]);
	sort(all(jun));
	return jun[k-1];
	
}

ll f0(int n, ll k, const VL& a){
	auto f=[&](ll m){
		ll rt =0;
		rep(i , n){
			if(a[i] == 0){
				if(m>=0) rt += n;
			}else if (a[i] < 0) {
				ll  mn = (m / a[i]) - 10;
				while (mn * a[i] > m) mn++;
				int  ps = lower_bound(all(a), mn) - a.begin();
				rt += n - ps;
			}else{
				ll  mx = (m / a[i]) + 10;
				while (mx * a[i] > m) mx--;
				int ps = upper_bound(all(a), mx) - a.begin();
				rt += ps;
			}
			if(a[i]*a[i]<=m) rt--;
		}
		return rt / 2;
	};
	
	const ll INF =  (ll)(1e18) + 111;
	ll l=-INF , r=INF, smz=0;
		while(r - l >1){
		ll md = (r + l) / 2;
		smz = f(md);
		( smz >=k ? r: l) = md; 
		//dbg(md, smz, "w");
	}
	//cout << r <<"\n";
	return r;
}

ll f1(int n, ll k, const VL& a){

	auto f=[&](ll m){
		ll rt =0;
		rep(i , n){
			if (a[i] < 0) {
				int ps = partition_point(all(a), [&](auto p){
					return p * a[i] > m;})  - a.begin();
				rt += n - ps;
			}else{
				int ps = partition_point(all(a), [&](auto p){
					return p * a[i] <= m; })  - a.begin();
				rt += ps;
			}
			if(a[i]*a[i]<=m) rt--;
		}
		return rt / 2;
	};
	
	const ll INF =  (ll)(1e18) + 111;
	ll l=-INF , r=INF, smz=0;
		while(r - l >1){
		ll md = (r + l) / 2;
		smz = f(md);
		( smz >=k ? r: l) = md; 
		//dbg(md, smz, "w");
	}

	return r;
}

void rndtest(int tz){
	mt19937 mt((unsigned)time(nullptr)) ;
	
	rep(g, tz){
		int n = int(mt()%5000) + 3;
		ll k = ll(mt()%((ll)n*(n-1)/2))+ 1;
		VL a(n);
		//rep(i, n) cin >>a[i];
		rep(i, n) a[i] = (ll)(mt()%100) - 50;
		sort(all(a));
		ll z0 = f0(n, k ,a),  z1= f1(n, k ,a), zz=0;
		if(z0 != z1){
			dbg("hazre ", n, k);
			for(auto x :a) cerr<<x<<" "; cerr<<"\n";
			dbg("f0 f1 fz", z0, z1, zz);
		}
	}

}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >>n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(all(a));
	
	cout << f1(n, k, a) <<"\n";
	
	//rndtest(200);
	

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=int(input().split()[0]);a=set(input())\n"
"while a&set(str(n)):n+=1\n"
"print(n)\n"
"\"";
  system(s);
  return 0;
}            

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

using namespace std;
using ll = long long;

struct st
{
    int ind;
    int flag;
    char m;
};



int main()
{
    string s;
    int q; cin >> s >> q;
    vector<int> sum(q); //i個目の後にある反転クエリの数
    vector<st> query;

    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        if(t == 1)sum[i]++;

        else{
            int g;
            char moji;
            cin >> g >> moji;
            query.push_back({i,g,moji});
        }
    }

    for(int i = q - 1; i >= 1; i--)sum[i - 1] = sum[i] + sum[i - 1];

    string mae, usiro;
    for(auto i : query)
    {
        if(i.flag == 1 && sum[i.ind] % 2 == 0){
            mae.push_back(i.m);
        }else if(i.flag == 2 && sum[i.ind] %2 == 1){
            mae.push_back(i.m);
        }else{
            usiro.push_back(i.m);
        }
    }
    reverse(mae.begin(), mae.end());
    if(sum[0] & 1)reverse(s.begin(), s.end());
    mae = mae + s;
    mae = mae +usiro;
    cout << mae << endl;
}

Measured memory_bytes: 5812
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int vis[66][66];
int ans[66];
char s[66];
int n;
int _min(int x,int y){
        if(x < y) return x;
        else return y;
}
int main(){
        while(scanf("%d",&n) != EOF){

                for(int i = 0;i < n;++i){
                        scanf("%s",s);
                        for(int j = 0;s[j];++j){
                                vis[i][ s[j] - 'a' ] ++;
                        }
                }
                for(int i = 0;i < 26;++i) ans[i] = 999;
                for(int i = 0;i < 26;++i){
                        for(int j = 0;j < n;++j){
                                ans[i] = _min(ans[i],vis[j][i]);
                        }
                }
                for(int i = 0;i < 26;++i){
                        while(ans[i]--){
                                printf("%c",i+'a');
                        }
                }
                printf("\n");
        }
        return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  double n;
  while(cin>>n){
    if(n==0) return 0;
  
    vector<double> A(n,0);
    rep(i,n) cin>>A[i];
  
    double e=accumulate(ALL(A),0)/n;
    double s=0;
    rep(i,n) s+=(A[i]-e)*(A[i]-e);
    cout<<fixed<<setprecision(10)<<sqrt(s/n)<<endl;
  }
  
  return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9 + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin >> n;
  i64 a;
  vector<i64> cum(n + 1);
  reps(i, 1, n) {
    cin >> a;
    cum[i] = cum[i-1] + a;
  }

  map<i64, i64> cnt;
  reps(i, 0, n) {
    ++cnt[cum[i]];
  }

  map<i64, bool> exist;
  i64 ans = 0;
  reps(i, 0, n) {
    if (exist[cum[i]]) continue;
    exist[cum[i]] = true;
    ans += (((cnt[cum[i]] - 1) * cnt[cum[i]]) / 2);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n){cin>>a[i];}
    vector<ll> cumsum(n+1,0);
    rep(i,n){
        cumsum[i+1] = cumsum[i]+a[i];
    }
    vector<ll> lst;
    rep(i,n){
        repr(j,i,n){
            lst.push_back(cumsum[j+1]-cumsum[i]);
        }
    }
    ll nn = lst.size();
    vector<ll> count(45,0);
    ll now = 44;
    multiset<ll> st; 
    rep(i,nn){
        st.insert(lst[i]);
    }
    ll res = 0;
    while(now>=0){
        ll cnt=0;
        for(auto x:st){
            if(x&(1LL<<now)){
                cnt++;
            }
        }
        if(cnt>=k){
            res += 1LL<<now;
            auto it = st.begin();
            while(it != st.end()){
                if((*it&(1LL<<now))==0){
                    it = st.erase(it);
                }else{
                    it++;
                }
            }
        }
        now--;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 27628
s=list(input())
t=list(input())

if not "?" in s:
    if ("".join(t) in "".join(s)):
        print("".join(s))
    else:
        print("UNRESTORABLE")
    exit()

ans=[]
switch=1
p=len(s)-len(t)
for i in range(p+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!="?":
            switch=0
    if switch==1:
        c_s=s[:]
        for j in range(len(t)):
            c_s[j+i]=t[j]
        for j in range(len(c_s)):
            if c_s[j]=="?":
                c_s[j]="a"
        ans.append("".join(c_s))
    switch=1

if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Measured memory_bytes: 63424
import math
N,K= map(int, input().split())
a=[0]*(K+1)
co=0
mod=(10**9+7)
for i in range(K,0,-1):

    b=K//i
    t=2*i
    m=0
    while t<=K:
        m=m+a[t]
        t+=i
    c=pow(b,N,mod)
    a[i]=c-m
    co+=(a[i]*i)%mod


print(co%mod)


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

int main() {
  vector<string> days = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
  cin >> s;
  
  for (int i = 0; i < days.size(); ++i) {
    if (days[i] == s) {
      cout << 7 - i << endl;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using std::sort;
using std::lower_bound;

const int MAXN=2005;
int n;
int L[MAXN];

inline int solve(){
	sort(L+1,L+n+1);
	int ret=0;
	for(int i=1;i+1<n;++i){
		for(int j=i+1;j<n;++j){
			int k=lower_bound(L+j+1,L+n+1,L[i]+L[j])-L-1;
			ret+=k-j;
		}
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&L[i]);
	printf("%d",solve());
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long X = in.nextLong();
		int sum = 0;
		int index = 0;
		while (sum < X) {
			index++;
			sum += index;
		}
		System.out.println(index);
		in.close();
	}
}

Measured memory_bytes: 23764
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int a[5];
    scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
    int m = 20;
    rep(i, 5) {
        if (a[i] % 10 != 0 && m > a[i] % 10) {
            m = a[i] % 10;
        }
    }
    if (m == 20) {
        printf("%d", a[0] + a[1] + a[2] + a[3] + a[4]);
        printf("\n");
        return 0;
    }
    int ret = 0;
    rep(i, 5) {
        if (a[i] % 10 == 0) {
            ret += a[i];
        } else {
            ret += ((a[i] / 10) + 1) * 10;
        }
    }
    ret -= (10 - m);

    printf("%d", ret);

    /* --------------------------------- */
    printf("\n");
    return 0;
}

Measured memory_bytes: 256