akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

bool kaibun(int n){
  vector<int> x;
  bool ans = false;

  while(n>0){
    int tmp = n % 10;
    x.push_back(tmp);
    n /= 10; 
  }
  
  vector<int>::iterator itrA = x.begin();
  vector<int>::iterator itrB = x.end()-1;
  
  for(int i = 0; i < x.size(); ++i){

    if(*itrA == *itrB){
     ans = true; 
    }else{
      ans = false;
      break;
    }
    ++itrA;
    --itrB;
  }
  
  return ans;
}

int main(){
  int A,B;
  cin >> A >> B;
  
  int counter = 0;
  
  for(int i = A; i <= B; i++){
    bool tmp = kaibun(i);
    if(tmp) counter++;
    
  }
  
  cout << counter << endl;

}

Measured memory_bytes: 256
def main():
    N,K = map(int,input().split())
    A = set(map(int,input().split()))
    A = list(A)
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = set(map(lambda x:abs(x-K),A))
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()

    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 81688
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()
	n := len(s)

	// table[i][j] = i文字目より前に文字jが存在するか
	table := make([][]bool, n)
	for i := range table {
		table[i] = make([]bool, 26)
	}
	for i := 0; i < n; i++ {
		if i > 0 {
			for j := 0; j < 26; j++ {
				table[i][j] = table[i-1][j]
			}
		}
		table[i][s[i]-'a'] = true
	}

	ans := []byte(s)
	if len(ans) == 26 {
		// 末尾からみて辞書順最小の次の文字列を決定
		for loop := true; loop && len(ans) > 0; {
			last := len(ans) - 1
			for i := ans[last] - 'a' + 1; i <= 'z'-'a'; i++ {
				if !table[last][i] {
					ans[last] = 'a' + i
					loop = false
					break
				}
			}
			if loop {
				ans = ans[:last]
			}
		}
	} else {
		// 末尾に未出の文字を追加
		for i := 0; ; i++ {
			if !table[n-1][i] {
				ans = append(ans, byte('a'+i))
				break
			}
		}
	}

	if len(ans) > 0 {
		puts(string(ans))
	} else {
		puts(-1)
	}
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

struct edge{
    int from,to;
    string cost;
    edge(){}
    edge(int a,int b,string s) : from(a),to(b),cost(s){}
};


int V,E,s,g;

void solve(){
    vector<edge> es(E);
    vector<edge> rev(E);
    rep(i,E){
        cin>>es[i].from>>es[i].to>>es[i].cost;
        rev[i] = edge(es[i].to,es[i].from,es[i].cost);
    }

    vector<string> d(V,"NO");
    d[g] = "";
    int cnt=0;
    while(true){
        bool update = false;
        for(edge e : rev){
            if(d[e.from] == "NO") continue;
            if(d[e.to] == "NO" || d[e.to] > e.cost + d[e.from]){
                d[e.to] = e.cost + d[e.from];
                update = true;
            }
        }
        if(!update) break;
        if(++cnt==300) break;
    }
    if(d[s].size()>=6*(V-1)){
        cout << "NO" << endl;
        return;
    }
    cout << d[s] << endl;
}

int main(){
    while(true){
        cin >> V >> E >> s >> g;
        //cout << V << " " << E <<" " << s << " " << g << endl;
        if(V==0 && E==0 && s==0 && g==0) break;
        solve();
    }
}

Measured memory_bytes: 3852
Nin = int(input())
a = [input() for i in range(Nin)]

ac  = 0
wa  = 0
tle = 0
re  = 0

for i in range(Nin):
    if a[i] == "AC":
        ac += 1
    elif a[i] == "WA":
        wa += 1
    elif a[i] == "TLE":
        tle += 1
    elif a[i] == "RE":
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)


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

int main(){
	int n,k;
	int m=1;

	cin >> n >> k;

	for(int i=0;i<n;i++){
		if(m<k){
			m*=2;
		}else{
			m+=k;
		}
	}
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include<cmath>

using namespace std;

int main()
{
  int a,b,z,x,c,d;
  cin>>a>>b;
  z=a+b;
  x=a-b;
  c=a*b;
  d=max(z,x);
  cout<<max(c,d);
 
  
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 

#define int             long long

 
void anmol()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 
const int N = 1e6 + 5 ;
 int a[N], b[N] , freq[N];

 
   int sum(int n){

    int count =0;
     while(n!=0){
   
     count+=n%10;
     n = n/10;



    }

    return count;

   }



int32_t main(){

  anmol();

  int n;
  cin>>n;

  cout<<n*(n+1+n*n)<<endl;

  


   }




  
 






   

  
  

   
   





  










 
 





  



 
 
    

  
 
 
 
 
 


 

   

 
 



  
  












 
 





  



 
 
    

  































 
 



  
  












 
 





  



 
 
    

  
 
 
 
 
 


 

   

 
 



  
  












 
 





  



 
 
    

  


Measured memory_bytes: 3628
import itertools
from scipy.sparse.csgraph import floyd_warshall

N, M = map(int, input().split())

# Floyd-Warshallでよくやる初期化
dist = []
for i in range(N):
  tmp = []
  for _ in range(N):
    tmp.append(float('inf'))
  dist.append(tmp)
  dist[i][i] = 0  # ここがポイント

# 隣接行列を作る
a = []
b = []
c = []
for _ in range(M):
  x = list(map(int, input().split()))
  a.append(x[0] - 1)
  b.append(x[1] - 1)
  c.append(x[2])
  dist[a[-1]][b[-1]] = x[2]
  dist[b[-1]][a[-1]] = x[2]

# Floyd-Warshall
dist = floyd_warshall(dist)
dist = dist.astype(int).tolist()

# 集計
res = 0
for i in range(M):
  if c[i] > dist[a[i]][b[i]]:
    res += 1
    
print(res)

Measured memory_bytes: 27184
#include<iostream>
#include<string>
using namespace std;
int a,b,c,d,whh[4][2]={0};
char s;
int main(){
	cin>>s;a=s-'0';whh[0][0]=a;whh[0][1]=-a;
	cin>>s;b=s-'0';whh[1][0]=b;whh[1][1]=-b;
	cin>>s;c=s-'0';whh[2][0]=c;whh[2][1]=-c;
	cin>>s;d=s-'0';whh[3][0]=d;whh[3][1]=-d;
	for(int aa=0;aa<=1;aa++)
	for(int bb=0;bb<=1;bb++)
	for(int cc=0;cc<=1;cc++)
	for(int dd=0;dd<=1;dd++){
		if(whh[0][aa]+whh[1][bb]+whh[2][cc]+whh[3][dd]==7){
			cout<<whh[0][aa];
			if(whh[1][bb]>=0)cout<<"+"<<whh[1][bb];else cout<<whh[1][bb];
			if(whh[2][cc]>=0)cout<<"+"<<whh[2][cc];else cout<<whh[2][cc];
			if(whh[3][dd]>=0)cout<<"+"<<whh[3][dd];else cout<<whh[3][dd];
			cout<<"=7"<<endl;return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  
  long long N, M, i;
  cin >> N >> M;
  vector<long long> H(N), Hantei(N, 1), A(M), B(M);
  
  
  for(i = 0; i < N; i++){
    cin >> H.at(i);
  }
  
  for(i = 0; i < M; i++){
    cin >> A.at(i);
    cin >> B.at(i);
  }
  
  
  for(i = 0; i < M; i++){
    
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      
      Hantei.at(B.at(i) - 1) = 0;
    }else if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)){
      
      Hantei.at(A.at(i) - 1) = 0;
    }else{
      
      Hantei.at(B.at(i) - 1) = 0;
      Hantei.at(A.at(i) - 1) = 0;
    }
    
  }
  
  long long goukei = 0;
  for(i = 0; i < N; i++){
    
    goukei += Hantei.at(i);
  }
  
  cout << goukei << endl;
  return 0;
}

Measured memory_bytes: 6428
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = sr()
dp = [0, 1]  # ちょうど払う最小枚数、１円多くはらう最小枚数
for x in N:
    x = int(x)
    prev = dp[:]
    dp[0] = min(prev[0]+x, prev[1]+(10-x))
    dp[1] = min(prev[0]+x+1, prev[1]+(10-x-1))

answer = dp[0]
print(answer)
# 33

Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
long long min1,min2,min3,min4;
int main()
{
	cin >>min1 >>min2 >>min3 >>min4;
	min1=min(min1,min2);
	min3=min(min3,min4);
	cout <<min1+min3;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,k;
  cin>>n>>k;
  int min=10000000,sum=0;
  vector<int> A;
  rep(i,n){
    int a;
    cin>>a;
    if(min>a) min=a;
    sum+=a;
    A.push_back(a);
  }
  
  rep(i,sum){
    int num=sum-i;
    if(sum%num!=0) continue;
    priority_queue<int,vector<int>,less<int>> amari;
    int numsum=0;
    rep(j,n){
      amari.push(A[j]%num);
      numsum+=A[j]%num;
    }
    rep(j,numsum/num) amari.pop();
    int count=0;
    while(!amari.empty()){
      count+=amari.top();
      amari.pop();
    }
    if(count<=k){
      cout<<num<<endl;
      break;
    }
  } 
}

Measured memory_bytes: 256
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});
reader.on("close", function() {
  var value_a: number = Number(lines[0].split(" ")[0]);
  var value_b: number = Number(lines[0].split(" ")[1]);
  var value_x: number = Number(lines[0].split(" ")[2]);
  if (value_a > value_x) {
    console.log("NO");
  } else if (value_b >= value_x - value_a) {
    console.log("YES");
  } else {
    console.log("NO");
  }
});


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  int cost = 0;
  for (i = 0; i < n; i++) {
    int temp = fabs(x[i] - k);
    cost += min(x[i], temp);
  }
  cost *= 2;
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> G(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    sort(c.begin(), c.end(), greater<int>());
    int m = 0;
    queue<int> q;
    q.push(0);
    vector<bool> visited(n, false);
    int cnt = 0;
    vector<int> d(n);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        visited[v] = true;
        m += c[cnt];
        d[v] = c[cnt++];
        for (int to : G[v]) {
            if (visited[to])
                continue;

            q.push(to);
        }
    }

    cout << (m - c[0]) << endl;
    for (int i = 0; i < n; ++i) {
        cout << d[i];
        if (i < n - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int a=0;a<=9;a++)
			for(int b=0;b<=9;b++)
				for(int c=0;c<=9;c++)
					for(int d=0;d<=9;d++)
						if(a+b+c+d==n)
							ans++;
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 2984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011
#define inf 1LL << 60


int n, i;
ll E, T;
ll x[maxN];
ll dp[maxN];

int pp;
deque<int> far, close;

ll cost(ll l, ll r) {
    return dp[l] + (x[r] - x[l]) + max(T, 2 * (x[r] - x[l + 1]));
}

void add(deque<int>& Q, int pos, int refe) {
    while (!Q.empty()) {
        int last = Q.back();
        if (cost(last, refe) < cost(pos, refe)) break;
        Q.pop_back();
    }

    Q.push_back(pos);
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%lld%lld", &n, &E, &T);
    for (i = 1; i <= n; i++) scanf("%lld", &x[i]);

    pp = -1;
    add(close, 0, 1);

    for (i = 1; i <= n; i++) {
        while (pp + 1 < i && T < 2LL * (x[i] - x[pp + 2])) {
            pp++;
            add(far, pp, i);
        }

        while (!close.empty()) {
            if (close.front() > pp) break;
            close.pop_front();
        }

        ll d1 = inf;
        if (!far.empty()) d1 = cost(far.front(), i);

        ll d2 = inf;
        if (!close.empty()) d2 = cost(close.front(), i);

        dp[i] = min(d1, d2);
        add(close, i, i + 1);
    }

    printf("%lld", dp[n] + E - x[n]);


    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
int main()
{
	int n,r;
	cin>>n>>r;
	if(n<10)
		cout<<r+100*(10-n)<<endl;
	else
		cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 200000
int main(){

  int i,j,n;
  int data[N];
  int res,max_i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  max_i=1;
  for(i=2;i<n;i++){
    if(data[max_i]<data[i]){
      max_i=i;
    }
  }
  res=data[1]-data[0];
  for(i=0;i<n-1;i++){
    if(max_i==i){
      max_i++;
      for(j=i+1;j<n;j++){
	if(data[max_i]<data[j]){
	  max_i=j;
	}
      }
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
    else{ 
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
  }
  printf("%d\n",res);
  return 0;
}
  



Measured memory_bytes: 2636
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

struct Edge {
	int a, b, cost;
	bool operator <(const Edge& e)const {
		return cost < e.cost;
	}
};

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> K;
	vector<int>st(N, MOD * 2);
	vector<int>rev(N, MOD * 2);
	vector<Edge>edge;
	for (int i = 0; i < K; i++) {
		Edge e;
		cin >> e.a >> e.b >> e.cost;
		edge.push_back(e);
		st[e.a] = min(st[e.a], e.cost - 2 * e.a + 1);
		if (e.a)rev[e.a - 1] = min(rev[e.a - 1], e.cost + 2 * N - 2 * e.a + 1);
		st[e.b] = min(st[e.b], e.cost - 2 * e.b + 2);
		if (e.b)rev[e.b - 1] = min(rev[e.b - 1], e.cost + 2 * N - 2 * e.b + 2);
	}
	for (int i = 1; i < N; i++)st[i] = min(st[i], st[i - 1]);
	for (int i = N - 2; i >= 0; i--)rev[i] = min(rev[i], rev[i + 1]);
	for (int i = 0; i < N; i++) {
		Edge e;
		e.a = i;
		e.b = (i + 1) % N;
		e.cost = min(rev[i], st[i]) + i * 2;
		edge.push_back(e);
	}
	sort(edge.begin(), edge.end());
	long long int ans = 0;
	UnionFind uf(N);
	for (auto i : edge) {
		if (uf.Check_Same(i.a, i.b))continue;
		ans += i.cost;
		uf.Unite(i.a, i.b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10096
#include<iostream>
#include<vector>
#include<string>
#include<map>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::map<int, int> odd, even;
    int freqOdd = 0, freqEven = 0;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        if(i % 2 == 0){
            even[a[i]]++;
            freqEven = std::max(even[a[i]], freqEven);
        }else{
            odd[a[i]]++;
            freqOdd = std::max(odd[a[i]], freqOdd);
        }
    }

    // 偶数
    std::vector<int> evenVal, oddVal;
    for(auto m : even){
        if(m.second == freqEven){
            evenVal.push_back(m.first);
        }
    }
    // 奇数
    for(auto m : odd){
        if(m.second == freqOdd){
            oddVal.push_back(m.first);
        }
    }

    for(int i = 0; i < evenVal.size(); i++){
        for(int j = 0; j < oddVal.size(); j++){
            if(evenVal[i] != oddVal[j]){
                int evenCost = n / 2 - freqEven;
                int oddCost = n / 2 - freqOdd;
                std::cout << evenCost + oddCost << std::endl;
                return 0;
            }
        }
    }

    // これで終わらない場合 = MAXが同じ数字同士で1種
    // 全部同じ数かどうか
    if(even.size() == 1 && odd.size() == 1){
        std::cout << n / 2 << std::endl;
        return 0;
    }
    // 片方を別種にするしかない
    int nextFreqEven = 0, nextFreqOdd = 0;
    for(auto m : even){
        if(m.second >= nextFreqEven && m.second != freqEven){
            nextFreqEven = m.second;
        }
    }
    for(auto m : odd){
        if(m.second >= nextFreqOdd && m.second != freqOdd){
            nextFreqOdd = m.second;
        }
    }

    // コストの低いほうで計算
    int evenCost, oddCost;
    if(nextFreqEven >= nextFreqOdd){
        evenCost = n / 2 - nextFreqEven;
        oddCost = n / 2 - freqOdd;
    }else{
        evenCost = n / 2 - freqEven;
        oddCost = n / 2 - nextFreqOdd;
    }

    std::cout << evenCost + oddCost << std::endl;

    return 0;
}


Measured memory_bytes: 5888
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> fun [| n; t |] ->
    [ 1 .. n ]
    |> List.map (fun _ -> readIntArray ())
    |> List.filter (fun [| _; time |] -> time <= t)
    |> List.map (fun [| c; _ |] -> c)
    |> List.sort
    |> List.tryHead
    |> fun x ->
        match x with
        | Some x -> x |> string
        | None -> "TLE"
    |> printfn "%s"


Measured memory_bytes: 29900
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <string>

using namespace std;

pair<int, int> firend(int n){
    int a, b;
    a = n%10;
    while(n > 0){
       b = n;
       n /= 10;
    }

    return pair<int, int>(a, b);
}

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    map<pair<int, int>, int> mp;
    for(int i=1; i<=n; i++){
        pair<int, int> p;
        p = firend(i);
        mp[p]++;
    }
    for(int i=1; i<=n; i++){
        pair<int, int> p, q;
        p = firend(i);
        q = pair<int, int>(p.second, p.first);
        ans += (long long)mp[q];
    }

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


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

const int N=1000000;
int lp[N+1],pr[N],a[N+1],k;

void sieve(){
    for(int i=2;i<=N;i++){
        if(lp[i]==0) lp[i]=pr[k++]=i;
        for(int j=0;(j<k && pr[j]<=lp[i]);j++){
            int x=i*pr[j];
            if(x>N) break;
            lp[x]=pr[j];
        }
    }
}

int main()
{
    int n,x,g=-1;
    sieve();
    scanf("%d",&n);
    bool flag=true;
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        g=(g==-1)?x:__gcd(g,x);
        set <int> s;
        while(x>1){
            if(s.find(lp[x])==end(s)){
                a[lp[x]]++;
            }
            if(a[lp[x]]>1) flag=false;
            s.insert(lp[x]);
            x/=lp[x];
        }
    }
    if(flag) puts("pairwise coprime");
    else if(g==1) puts("setwise coprime");
    else puts("not coprime");
    return 0;
}

Measured memory_bytes: 11784
import sys


def calc_inverse_polish_notation_string(s):
    tokens = [token for token in s.split(' ') if token != '']
    stack = []
    for token in tokens:
        if token in ['+', '-', '*', '/']:
            val2 = stack.pop()
            val1 = stack.pop()
            result = eval("%s %s %s" % (val1, token, val2))
            stack.append(result)
        else:
            stack.append(token)

    return stack[0]  # if len(stack) != 1, it should throw an exception


def main():
    for line in sys.stdin.readlines():
        print(calc_inverse_polish_notation_string(line.strip()))

if __name__ == "__main__":
    main()

Measured memory_bytes: 7572
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000, MAX_C = 30;
int N, C;
int s[MAX_N], t[MAX_N], c[MAX_N];
vector<pii> cs[MAX_C+1];
int dp[MAX_N+1];

int main() {
  cin >> N >> C;
  rep(i,N) cin >> s[i] >> t[i] >> c[i];

  rep(i,N) {
    cs[c[i]].push_back(pii(s[i],t[i]));
  }
  rep(i,C+1) {
    sort(all(cs[i]));
  }

  for (int i = 1; i <= C; ++i) {
    for (int j = 0; j < (int)cs[i].size(); ++j) {
      if (j == 0 || cs[i][j-1].sc < cs[i][j].fi) {
        for (int k = cs[i][j].fi; k <= cs[i][j].sc; ++k) ++dp[k];
      } else {
        for (int k = cs[i][j].fi+1; k <= cs[i][j].sc; ++k) ++dp[k];
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= 1e5; ++i) ans = max(ans, dp[i]);

  cout << ans << endl;

  return 0;
}


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


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

  int n,m; cin >> n >> m;
  vector<bool> red(n+1,false);
  vector<int> ball(n+1,1);
  red[1] = true;
  for(int i = 0; i < m; i++){
    int x,y; cin >> x >> y;
    red[y] = red[y] | red[x];
    ball[x]--;
    ball[y]++;
    if(ball[x] == 0) red[x] = false;
  }

  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(red[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	VS s(10);
	while (cin >> s[0]) {
		s[0] += "00000";
		FOR(i, 1, 8) { cin >> s[i]; s[i] += "00000"; }
		s[8] = string(15, '0');
		s[9] = string(15, '0');

		int x = -1, y = -1;
		rep(i, 8)rep(j, 8) {
			if (x == -1 && y == -1 && s[i][j] == '1') { x = j; y = i; break; }
		}

		bool f2 = s[y + 1][x] == '1';
		bool f1 = s[y][x + 1] == '1';
		bool f3 = s[y + 1][x + 1] == '1';

		char ans = '#';
		if (f1 && f2) {//A G
			ans = f3 ? 'A' : 'G';
		}
		else if (f1 && !f2) {//C E
			ans = f3 ? 'E' : 'C';
		}
		else if (!f1 && f2) {//B D F
			if (f3)ans = 'F';
			else ans = s[y + 2][x] == '1' ? 'B' : 'D';
		}
		Cout(ans);
	}
}


Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>

using namespace std;

int a, b, c;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b >> c;
    cout << max(0, c - a + b);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<ll>v;

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int X, Y;
  cin >> X >> Y;
  int a, b;
  //a+b=X 2a+4b=Y 2a+2b=2X 2b=Y-2X
  b = (Y - 2 * X) / 2;
  a = X - b;

  bool r = a + b == X && 2 * a + 4 * b == Y && a>=0 && b>=0;
  cout << (r ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3636
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define ccy cout << "YES\n"
#define ccn cout << "NO\n"
#define cfy cout << "Yes\n"
#define cfn cout << "No\n"
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define vil vector < ll > 
#define vis vector < string > 
#define vip vector < pair < ll, ll > > 
#define pi pair < ll , ll > 
#define pii pair < pair < ll, ll >, ll >
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
ll lets_do_it();
// pi xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
// pi dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
// bool isValid(ll x, ll y, ll row, ll col){
//     return ((x>=0) && (y >=0)  && (x < row) && (y < col));
// }
ll power(ll k, ll num){
	if(num == 0)
		return 1%mod;
	ll value = power(k, num/2);
	value = value%mod;
	value = ((value%mod) * (value%mod))%mod;
	if(num & 1)
		value = (value * (k%mod))%mod;
	value = value%mod;
	return value;
	
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll value = 0;
    value = min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    value -= min(c, k);
    cout << value << endl;

    


    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N,M;
vector<ll> abv[202020];
ll mk[202020];
ll umk[202020], dmk[202020];
ll i, j, k, ans;

ll invp2[202020];
const ll inv2 = (MOD + 1) / 2;

ll dfs(ll a,ll p){
    ll i, j;
    if(a!=1&&abv[a].size()==1){
        return 1;
    }

    ll c = 1, d = N - 1;
    c = c + MOD - invp2[N - 1];
    fornum(i,0,abv[a].size()){
        if(abv[a][i]==p)
            continue;
        ll r = dfs(abv[a][i], a);
        c = (c + MOD - invp2[N - 1 - r] * (1 + MOD - invp2[r]) % MOD) % MOD;
        d -= r;
    }
    c = (c + MOD - invp2[N - 1 - d] * (1 + MOD - invp2[d]) % MOD) % MOD;
    //printf("%lld %lld\n", a, c);
    ans += c * inv2;
    ans %= MOD;
    return N-d;
}


int main(){
    scanf("%lld", &N);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back(b);
        abv[b].push_back(a);
    }
    invp2[0] = 1;
    fornum(i,0,N){
        invp2[i + 1] = invp2[i] * inv2 % MOD;
    }

    dfs(1, -1);
    printf("%lld", ans);

    return 0;
}

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

int main()
{
    int a,b;
    char op;
    while(cin >> a >> op >> b)
    {
        ll sum;
        if(op == '+')
        sum = a + b;
        else
        sum = a - b;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
# import statistics
import heapq


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
n = getInputInt()
data = getSomeInputListInt(n)

data_sorted = sorted(data, key=lambda x:x[1], reverse=True)

lim = sys.maxsize
flg = True

for d in data_sorted:
    if lim > d[1]:
        lim = d[1]
    lim -= d[0]

    if lim<0:
        flg = False
        break

if flg:
    print("Yes")
else:
    print("No")

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

int main(){
    int y,m,d;
    long long a;
    while(cin>>y>>m>>d){
        a=d+100*m+10000*y;
        if(a<18680908)cout<<"pre-meiji"<<endl;
        else if(a>=18680908&&a<=19120729){
            cout<<"meiji "<<y-1867<<' '<<m<<' '<<d<<endl;
        }
        else if(a>=19120730&&a<=19261224){
            cout<<"taisho "<<y-1911<<' '<<m<<' '<<d<<endl;
        }
        else if(a>=19261225&&a<=19890107){
            cout<<"showa "<<y-1925<<' '<<m<<' '<<d<<endl;
        }
        else{
            cout<<"heisei "<<y-1988<<' '<<m<<' '<<d<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1164
public class Main {

	public static void main(String[] args) {
		String num=new java.util.Scanner(System.in).nextLine();
                int number=Integer.parseInt(num);
		int[] masu=new int[3];
		masu[0]=number/100;
		masu[1]=(number-masu[0]*100)/10;
		masu[2]=number-masu[0]*100-masu[1]*10;
		int count=0;
		for(int i:masu) {
			if(i==1) {
				count++;
			}
                }
		System.out.println(count);
	}

}

Measured memory_bytes: 21844
while True:
    n = int(input())
    if n == 0:
        break
    else:
        lst=[0]*10
        for i in range(n):
            lst[int(input())] += 1
        for i in range(10):
            if lst[i] == 0:
                print('-')
            else:
                for j in range(lst[i]):
                    print('*', end='')
                print()


Measured memory_bytes: 7580
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100001
#define M 400001
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
bool gg;
int ans,mark[N];
int n,m,cnt1,cnt2,cnt3,siz;
int cnt,head[N],nxt[M],to[M];
void dfs(int u)
{
	++siz;
	for(int i=head[u],v;i;i=nxt[i])
		if(!mark[v=to[i]])
		{
			mark[v]=-mark[u];
			dfs(v);
		}
		else if(mark[u]!=-mark[v])gg=1;
}
main()
{
	re(n),re(m);
	for(int i=1,u,v;i<=m;++i)
	{
		re(u),re(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	for(int i=1;i<=n;++i)
		if(!mark[i])
		{
			siz=0;
			gg=0;
			mark[i]=1;
			dfs(i);
			if(siz==1)++cnt1;
			else if(gg)++cnt3;
			else ++cnt2;
		}
	ans=cnt1*(2*n-1)-cnt1*(cnt1-1)+cnt3*cnt3+2*cnt2*(cnt2+cnt3);
	printf("%lld\n",ans);
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e5+5;

int32_t main() {
	string s;
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}


Measured memory_bytes: 3596
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			StringTokenizer tokenizer = new StringTokenizer(scanner.nextLine());
			int n = Integer.parseInt(tokenizer.nextToken());
			int s = tokenizer.countTokens();
			int[] num = new int[s];
			for (int i = 0; i < s; i++) {
				num[i] = Integer.parseInt(tokenizer.nextToken());
			}
			Arrays.sort(num);
			Deque<Integer> que = new ArrayDeque<Integer>();
			for (int t : num) {
				que.offer(t);
			}
			Deque<Integer> deque = new ArrayDeque<Integer>();
			boolean flag = true;
			while (!que.isEmpty()) {
				if (flag) {
					deque.offer(que.pop());
					if (!que.isEmpty()) {
						deque.offer(que.pollLast());
					}
					flag = false;
				} else {
					deque.push(que.pollLast());
					if (!que.isEmpty()) {
						deque.push(que.pop());
					}
					flag = true;
				}

			}
			double sum = 0;
			sum += deque.getFirst();
			sum += deque.getLast();
			int a = deque.pop();
			while (!deque.isEmpty()) {
				int b = deque.pop();
				sum += Math.sqrt(a * b) * 2;
				a = b;
			}
			System.out.println(sum <= n ? "OK" : "NA");
		}
	}
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#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++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



struct edge{ll to;};
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G;
  vector<ll> parent;
  vector<ll> depth;
  vector<bool> syugo;
  vector<bool> used;
  int first;
  int last;
  int kazu;

  graph(ll n){
    N = n;
    G.resize(N);
    parent.resize(N);
    depth.resize(N);
    syugo.resize(N);
    used.resize(N);
    kazu=N+1;
    rep(i,N){depth[i] = -1;}
    rep(i,N){syugo[i] = true;}
    rep(i,N){used[i] = false;}
  }
  void add_edge(ll s, ll t){
    G[s].emplace_back((edge){t});
  }
  void reset1(){
    rep(i,N){depth[i] = -1;}
  }
  void reset2(){
    rep(i,N){depth[i] = -1;}
    rep(i,N){syugo[i] = false;}
    kazu=1;
  }

  bool dfs(ll v=0, ll p=-1, ll d=0){
    parent[v] = p;
    used[v]=true;
    depth[v] = d;
    //db(v);
    bool res=false;
    for(auto E : G[v]){ // E つなぐエッジ
      //db(syugo[E.to]);
      if(syugo[E.to] == false) continue;
      if(used[E.to] == true and !(depth[v]==kazu-1 and depth[E.to]==0)) {first=E.to; last=v; res=true; break;}
      if(used[E.to] == false) res= (res or dfs(E.to , v , d+1)); //まだ行ってないなら
      if(res) break;
    }
    used[v]=false;
    return res;
  }
};


void Main(){

  int N,M; cin>>N>>M;

  graph g(N);

  rep(i,M){
    int a,b; cin>>a>>b; --a; --b;
    g.add_edge(a,b);
  }

  bool ok=false;
  rep(i,N){
    if(g.dfs(i)==true){
      ok=true; break;
    }
    g.reset1();
  }

  if(ok==false){
    cout<< -1<<"\n";
    return;
  }

  ok=true;
  while(ok){
    g.reset2();
    for(int now=g.last;now!=g.first;now=g.parent[now]){
      g.syugo[now]=true;
      ++g.kazu;
    }
    g.syugo[g.first]=true;

    if(g.dfs(g.first)==true) continue;
    else break;
  }

  cout<< g.kazu<<"\n";

  rep(i,N){
    if(g.syugo[i]==true){
      cout<< i+1 <<"\n";
    }
  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int n, k;
    std::cin >> n >> k;

    long long sum = 0;
    long long least = 0, most = 0;
    for (int i = 1; i <= k - 1; i++) {
        least += i - 1;
        most += n - (i - 1);
    }
    for (int i = k; i <= n + 1; i++) {
        least += i - 1;
        most += n - (i - 1);
        sum += (most - least + 1) % mod;
        sum %= mod;
    }

    std::cout << sum << std::endl;
}


Measured memory_bytes: 3632
double x[100],y[100],A,h,X,Y,C,S,v,w;i,j,k,s,m,M;main(n){for(;~scanf("%d",&n);n&&printf("%d\n",M+2)){M=-1;for(i=n;i--;)scanf("%lf,%lf",x+i,y+i);for(i=n;i-->0;)for(j=i;j--;)if(v=x[i]-x[j],w=y[i]-y[j],A=hypot(v,w)/2,A<=1)for(S=atan2(w,v),C=cos(S),S=sin(S),h=sqrt(1-A*A);++s%3;h=-h)for(m=0,k=n;k--;M=m>M?m:M)m+=k-i&&k-j&&hypot(x[j]+A*C-h*S-x[k],y[j]+A*S+h*C-y[k])<=1;}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 +7;
const ll MAXN = 1e5 + 5;

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

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

ll a[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,m;
	bool ok=1;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]/=2;
	}
	sort(a+1,a+1+n);
	ll qaq=1;
	for(int i=1;i<=n;i++){
	    qaq=lcm(qaq,a[i]);
	    if(qaq>m) ok=0;
	}
	for(int i=1;i<=n;++i){
        if(qaq/a[i]%2==0){ok=0;break;}
    }
    if(!ok){
    	cout<<0;
    	return 0;
	} 
	ll cnt=0;
	for(int i=1;qaq*i<=m;i+=2){
		cnt++;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 1024
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>

using namespace std;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

static const int dx[4] = { -1,1,0,0 };
static const int dy[4] = { 0,0,-1,1 };
const int INF = 1 << 30;

int h;
int w;

void dfs(int y, int x, int g, vector<string> &b, vector<vector<int>>& vis) {
	vis[y][x] = g;
	for (int dir = 0; dir < 4; ++dir) {
		int ny = y + dy[dir], nx = x + dx[dir];
		if (ny >= 0 && ny < h && nx >= 0 && nx < w) {
			if (b[ny][nx] != '#' && vis[ny][nx] < 0) {
				dfs(ny, nx, g, b, vis);
			}
		}
	}
}

int main(int argc, char* argv[]) {
	int sh, sw, eh, ew, ans = INF;
	cin >> h >> w >> sh >> sw >> eh >> ew;
	--sh, --sw, --eh, --ew;
	vector<string> b(h);
	for (int i = 0; i < h; ++i) {
		cin >> b[i];
	}
	vector<vector<int>> vis(h, vector<int>(w, -1));
	int g = 0;
	for (int r = 0; r < h; ++r) {
		for (int c = 0; c < w; ++c) {
			if (b[r][c] != '#' && vis[r][c] < 0) {
				dfs(r, c, g, b, vis);
				++g;
			}
		}
	}
	vector<set<int>> e(g);
	for (int r = 0; r < h; ++r) {
		for (int c = 0; c < w; ++c) {
			if (b[r][c] != '#') {
				for (int dy = -2; dy <= 2; ++dy) {
					for (int dx = -2; dx <= 2; ++dx) {
						int y = r + dy, x = c + dx;
						if (y >= 0 && y < h && x >= 0 && x < w) {
							if (vis[y][x] >= 0 && vis[r][c] != vis[y][x]) {
								e[vis[r][c]].emplace(vis[y][x]);
								e[vis[y][x]].emplace(vis[r][c]);
							}
						}
					}
				}
			}
		}
	}
	if (vis[sh][sw] == vis[eh][ew]) {
		ans = 0;
	} else {
		vector<int> q;
		vector<int> vg(g);
		q.emplace_back(vis[sh][sw]);
		vg[vis[sh][sw]] = 1;
		for (int tt = 0; !q.empty(); ++tt) {
			vector<int> nq;
			for (int next : q) {
				if (next == vis[eh][ew]) {
					ans = tt;
					break;
				}
				for (int a : e[next]) {
					if (vg[a] == 0) {
						vg[a] = 1;
						nq.emplace_back(a);
					}
				}
			}
			q = nq;
		}
	}
	cout << (ans >= INF ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 33712
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    rep(i, 0, k){
        int d;
        cin >> d;
        rep(j, 0, d){
            int x;
            cin >> x;
            a[x-1] ++;
        }
    }
    int ans = 0;
    rep(i, 0, n){
        if(a[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

struct data {
  int q, a, b;
};

long long q, sum = 0;
vector<data> v;
priority_queue<long long> pqs;
priority_queue<long long, vector<long long>,
               greater<long long>>
    pql;

void solve();

int main() {
  cin >> q;
  v.resize(q);
  for(int i = 0; i < q; ++i) {
    cin >> v[i].q;
    if(v[i].q == 1) cin >> v[i].a >> v[i].b;
  }
  solve();
  return 0;
}

void solve() {
  for(int i = 0; i < q; ++i) {
    if(v[i].q == 1) {
      sum += v[i].b;
      if(pqs.size() != pql.size()) {
        sum -= v[i].a;
        pqs.push(v[i].a);
        sum += pqs.top() * 2;
        pql.push(pqs.top());
        pqs.pop();
      }
      else {
        sum += v[i].a;
        pql.push(v[i].a);
        sum -= pql.top() * 2;
        pqs.push(pql.top());
        pql.pop();
      }
    }
    else
      cout << pqs.top() << " "
           << sum + (pqs.size() != pql.size()) * pqs.top()
           << endl;
  }
}


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

int main()
{
    vector<int> a(5);
    rep(i, 5) cin >> a[i];
    int mx = 0, ans = 0;
    rep(i, 5)
    {
        ans += a[i];
        int x = a[i] % 10;
        if (x == 0)
            continue;
        x = 10 - x;
        ans += x;
        mx = max(mx, x);
    }
    ans -= mx;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624