akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string S;
	cin >> S;

	int n = 0;
	int s = 0;
	int e = 0;
	int w = 0;
	rep(i,S.size()){
		switch(S[i]){
			case 'N':n++;break;
			case 'S':s++;break;
			case 'E':e++;break;
			case 'W':w++;break;
		}
	}

	if(n > 0 && s > 0 && e > 0 && w > 0){
		cout << "Yes" << endl;
		return 0;
	}

	if(n > 0 && s > 0 && e == 0 && w == 0){
		cout << "Yes" << endl;
		return 0;
	}

	if(n == 0 && s == 0 && e > 0 && w > 0){
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;	
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

ll A,B,Q;
ll s[100001];
ll t[100001];
ll x[100000];

int main(){
    cin>>A>>B>>Q;
    repn(i,A) cin>>s[i];
    repn(i,B) cin>>t[i];
    rep(i,Q) cin>>x[i];

    rep(i,Q){
        ll a1=0, a2=A;
        while(a2-a1>1){
            ll c=(a1+a2)/2;
            if(x[i]<s[c]) a2=c;
            else a1=c;
        }
        ll b1=0, b2=B;
        while(b2-b1>1){
            ll c=(b1+b2)/2;
            if(x[i]<t[c]) b2=c;
            else b1=c;
        }

        ll num[4]={a1,a2,b1,b2};
        ll ans=100100100100100;
        rep(j,4) rep(k,2){
            if(j<=1){
                if(num[j]==0 || num[k+2]==0) continue;
                ans=min(ans,abs(x[i]-s[num[j]])+abs(s[num[j]]-t[num[k+2]]));
            }else{
                if(num[j]==0 || num[k]==0) continue;
                ans=min(ans,abs(x[i]-t[num[j]])+abs(t[num[j]]-s[num[k]]));
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
int a,j=1;
int main()
{
	cin>>a;
	while(a>=j)
	j*=2;
	printf("%d\n",j/2);
	
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	h, _ := strconv.Atoi(stringLineScan())
	w, _ := strconv.Atoi(stringLineScan())
	grid := make([]string, h)
	shortest := make([][]int, h)
	b := 0
	for i := 0; i < h; i++ {
		x := make([]int, w)
		s := stringLineScan()
		grid[i] = s
		for j := 0; j < w; j++ {
			x[j] = 1000000000
			if string(grid[i][j]) == "#" {
				b++
			}
		}
		shortest[i] = x
	}
	shortest[0][0] = 1
	shortest = gridsearch(0, 0, h, w, grid, shortest)
	if shortest[h-1][w-1] == 1000000000 {
		fmt.Println(-1)
	} else {
		fmt.Println(h*w - b - shortest[h-1][w-1])
	}
}
func gridsearch(x int, y int, h int, w int, grid []string, shortest [][]int) [][]int {
	c := shortest[x][y] + 1
	if x+1 < h {
		if string(grid[x+1][y]) == "." && shortest[x+1][y] > c {
			shortest[x+1][y] = c
			shortest = gridsearch(x+1, y, h, w, grid, shortest)
		}
	}
	if x-1 >= 0 {
		if string(grid[x-1][y]) == "." && shortest[x-1][y] > c {
			shortest[x-1][y] = c
			shortest = gridsearch(x-1, y, h, w, grid, shortest)
		}
	}
	if y+1 < w {
		if string(grid[x][y+1]) == "." && shortest[x][y+1] > c {
			shortest[x][y+1] = c
			shortest = gridsearch(x, y+1, h, w, grid, shortest)
		}
	}
	if y-1 >= 0 {
		if string(grid[x][y-1]) == "." && shortest[x][y-1] > c {
			shortest[x][y-1] = c
			shortest = gridsearch(x, y-1, h, w, grid, shortest)
		}
	}
	return shortest
}


Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] xs = new int[n][2];
		int[][] ys = new int[n][2];
		for (int i = 0; i < n; i++) {
			xs[i][0] = sc.nextInt();
			xs[i][1] = i;
			ys[i][0] = sc.nextInt();
			ys[i][1] = i;
		}

		Arrays.sort(xs, (a, b) -> Integer.compare(a[0], b[0]));
		Arrays.sort(ys, (a, b) -> Integer.compare(a[0], b[0]));
		PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[0], b[0]));
		for (int i = 0; i < n - 1; i++) {
			pq.offer(new int[]{Math.abs(xs[i][0] - xs[i + 1][0]), xs[i][1], xs[i + 1][1]});
			pq.offer(new int[]{Math.abs(ys[i][0] - ys[i + 1][0]), ys[i][1], ys[i + 1][1]});
		}

		UnionFind uf = new UnionFind(n);

		long answer = 0;
		while (!pq.isEmpty()) {
			int[] d = pq.poll();
			if (uf.connected(d[1], d[2])) continue;
			uf.union(d[1], d[2]);
			answer += d[0];
		}

		System.out.println(answer);
	}

	private static class UnionFind {

		private int[] parent;

		public UnionFind(int n) {
			this.parent = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
			}
		}

		private int root(int v) {
			while (parent[v] != parent[parent[v]]) {
				parent[v] = parent[parent[v]];
			}
			return parent[v];
		}

		public boolean connected(int v, int u) {
			return root(v) == root(u);
		}

		public void union(int v, int u) {
			parent[root(v)] = parent[root(u)];
		}
	}
}


Measured memory_bytes: 103252
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    int K;
    cin >> S >> K;
    K--;

    for(int i = 0; i < S.length(); i++) {
        if(S[i] != '1') {
            cout << (int)(S[i] - '0') << endl;
            return 0;
        }
        if(i == K) {
            cout << 1 << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)


int main(){
    ll n;
    ll a=1;
    cin>>n;
    REP(i,n){
        a*=(i+1);
        a%=1000000007ll;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll dp[100005];
int main()
{
   ll n,k;
   cin>>n>>k;
   ll a[n];
   for(int i=0;i<n;i++){
    cin>>a[i];
    dp[i]=1000000000;
   }
   dp[n-1]=0;
   for(int i=n-2;i>=0;i--){
   for(int j=i+1;j<=min(i+k,n-1);j++){
    dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
   }
   }
   cout<<dp[0];
    return 0;
}


Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1000005
int main()
{
    int i,n,a,f,j;
    in(n);
    vi v(n);
    read(v,i,n);
    a=0;
    rep(i,n)
    {
        f=1;
        rep(j,i)
            if(v[j]>v[i])f=0;
        a+=f;
    }
    out(a);
}





Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9 + 7)

typedef struct {
	int *array;
	int last;
	int first;
}queue;

queue *make_queue(int maxN){
	queue *q = (queue *)malloc(sizeof(queue));
	q->array = (int *)malloc(sizeof(int) * maxN);
	q->last = 0;
	q->first = 0;
	return q;
}

int element_num_queue(queue *q){
	return q->first - q->last;
}

void add_data_queue(int val, queue *q){
	q->array[q->first] = val;
	q->first++;
}

int take_data_queue(queue *q){
	if(element_num_queue(q) <= 0){
		printf("no data in the queue\n");
	}
	q->last++;
	return q->array[q->last - 1];
}

void flush_queue(queue *q){
	q->last = 0;
	q->first = 0;
}

int min(int a, int b){
	return a <= b ? a : b;
}

//n:頂点数, s:始点の番号, t:終点の番号, e:(u, v)->f uからvへの容量
int Edmonds_Karp(int N, int s, int t, int **e){
	int v, i, flow_sum = 0;
	int *flow = (int *)malloc(sizeof(int) * N);//各頂点に流せるフロー
	int *p = (int *)malloc(sizeof(int) * N);//増加道の履歴 前の頂点を入れる
	queue *q = make_queue(N * N);

	for(;;){
		//初期化
		for(i = 0; i < N; i++){
			flow[i] = 0;
			p[i] = -1;
		}
		flow[s] = inf;
		p[s] = -2;

		add_data_queue(s, q);
		while(element_num_queue(q) > 0){
			v = take_data_queue(q);
			if(v == t){
				break;
			}
			for(i = 0; i < N; i++){
				if(e[v][i] > 0 && p[i] == -1){
					p[i] = v;
					flow[i] = min(flow[v], e[v][i]);
					add_data_queue(i, q);
				}
			}
		}
		//増加道がなかった場合
		if(flow[t] == 0){
			break;
		}
		//残余ネットワークの構築
		for(v = t; v != s; v = p[v]){
			e[p[v]][v] -= flow[t];
			e[v][p[v]] += flow[t];
		}
		flow_sum += flow[t];
		flush_queue(q);
	}
	return flow_sum;
}

int main(){
	int N, i, j, ans;
	scanf("%d", &N);
	int **E = (int **)malloc(sizeof(int *) * (2 * N + 2));
	for(i = 0; i < 2 * N + 2; i++){
		E[i] = (int *)malloc(sizeof(int) * (2 * N + 2));
		for(j = 0; j < 2 * N + 2; j++){
			E[i][j] = 0;
		}
	}
	for(i = 1; i <= N; i++){
		E[0][i] = 1;
	}
	for(i = N + 1; i <= 2 * N; i++){
		E[i][2 * N + 1] = 1;
	}
	int *a = (int *)malloc(sizeof(int) * N);
	int *b = (int *)malloc(sizeof(int) * N);
	int *c = (int *)malloc(sizeof(int) * N);
	int *d = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d%d", &a[i], &b[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d%d", &c[i], &d[i]);
	}
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			if(a[i] < c[j] && b[i] < d[j]){
				E[1 + i][N + 1 + j] = 1;
			}
		}
	}
/*	for(i = 0; i < 2 * N + 2; i++){
		for(j = 0; j < 2 * N + 2; j++){
			printf("E[%d][%d] = %d\n", i, j, E[i][j]);
		}
	}
*/	ans = Edmonds_Karp(2 * N + 2, 0, 2 * N + 1, E);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e15+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=40000;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
ll dp[22][(1<<21)+2];
ll a[22][22],n;
ll solve(ll id,ll mask)
{
	if(id==n&&mask==(1<<n)-1)
		return 1;
	if(id==n)
		return 0;
	if(dp[id][mask]!=-1)
		return dp[id][mask];
ll ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[id][i]==1&&(mask&(1<<i))==0)
		{
			ans=(ans+solve(id+1,mask|1<<i))%mod;
		}
	}
  dp[id][mask]=ans;

	return ans;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	ll i,j;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			cin>>a[i][j];
	}
	cout<<solve(0,0);
	//cout<<l;
}

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

int main(){
  int n, a, b;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  for(int i = 0; i < n; i++){
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;
  for(int i = 0; i < n; i++){
    if(x == s[i])
      a = i;
  }
  b = 0;
  for(int i = a + 1; i < n; i++)
    b += t[i];
  cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
int main() {
	unsigned long long a, b, x;
	cin >> a >> b >> x;
	if (a == 0) {
		cout << b / x+1 << endl;
		return 0;
	}
	cout << (b / x+1) - ((a - 1) / x+1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    for(int i=1;i<n-1;i++)
    {
        if(a[i]<a[i-1] && a[i]>a[i+1])
        {
            ans++;
        }
        else if(a[i]>a[i-1] && a[i]<a[i+1])
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int maxi = 1e6+10;
vector<int> v[maxi];
int n;
ll a[maxi];

void dfs(int i, int pre) {
	a[i] += a[pre];

	for(auto j: v[i]) {
		if(j!=pre) dfs(j, i);
	}
}

int main(){
	int q;
	cin >> n >> q;
	for(int i = 0; i < n-1; i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	while(q--) {
		int x, y;
		cin >> x >> y;
		x--;
		a[x]+=y;
	}

	dfs(0, -1);

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

}

Measured memory_bytes: 44672
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N; 
	long long pow10[1000010] = {}; 
	long long pow9[1000010] = {}; 
	long long pow8[1000010] = {}; 
	long long mod = 1000000007; 
	pow10[0] = 1; pow9[0] = 1; pow8[0] = 1; 
	for(int i = 1; i < 1000005; i++){
		pow10[i] = pow10[i-1] * 10 % mod; 
		pow9[i] = pow9[i-1] * 9 % mod; 
		pow8[i] = pow8[i-1] * 8 % mod; 
	}
	cout << (mod * 2 + pow10[N] - pow9[N] * 2 + pow8[N]) % mod << "\n"; 
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    ll K;
    cin >> S;
    cin >> K;

    ll N;
    N = S.length();
    map<string, ll>  M;

    for(ll d=0; d<=4; d++){
        for(ll i=0; i+d<N; i++){
            string temp = "";
            for(ll j=i; j<=i+d; j++){
                temp += S[j];
            }
            if(!M.count(temp)){
                M[temp] = 1;
            }
        }
    }

    vector<string> ans;

    for(auto iter=M.begin(); iter!=M.end(); iter++){
        // cout << iter->first << " " << iter->second << endl;
        ans.push_back(iter->first);
    }
    sort(ans.begin(), ans.end());

    cout << ans[K-1] << endl;
    return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
        int[]ans = new int[10001];
        for(int x = 1;x < 100;x++){
            for(int y = 1;y< 100;y++){
                for(int z = 1;z < 100;z++){
                    int next = x*x + y*y + z*z + x*y + y*z + z*x;
                    //map.put(next,map.getOrDefault(next,0) + 1);
                    if(next <= 10000)
                    ans[next] = ans[next] + 1;
                }
            }
        }
        for(int i = 1;i <= n;i++){
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 38920
import sys

sys.setrecursionlimit(100005)
MOD = 1000000007


def dfs(v, a):
    w, b = 1, 1
    for u in links[v]:
        if u == a:
            continue
        cw, cb = dfs(u, v)
        w *= cw + cb
        b *= cw
        w %= MOD
        b %= MOD
    return w, b


n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    links[x].add(y)
    links[y].add(x)

print(sum(dfs(0, None)) % MOD)


Measured memory_bytes: 112452
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
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;
}

int main() {
	int n;
	cin >> n;
	ll ans = 1LL;
	for (int i = 0; i < n; i++) {
		ll t;
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=3005,mod=998244353;
ll n,s,a[N],dp[N][N];
ll func(ll idx,ll sum){
    if(sum==0)return n-idx+2;
    if(sum<0 || idx>n)return 0;
    if(dp[idx][sum]!=-1)return dp[idx][sum];
    ll &ans = dp[idx][sum];
    ans = func(idx+1,sum) + func(idx+1,sum-a[idx]);
    ans%=mod;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n>>s;
    for(ll i=1;i<=n;i++)cin>>a[i];
    ll ans=0;for(ll i=1;i<=n;i++)ans+=func(i,s),ans%=mod;
    cout<<ans;
}


Measured memory_bytes: 70912
A, B, C = map(int, raw_input().split())

S = set()
S.add(tuple(sorted([A,B,C])))

cnt = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    a = B/2 + C/2
    b = C/2 + A/2
    c = A/2 + B/2
    A, B, C = a, b, c
    cnt += 1
    if tuple(sorted([A, B, C])) in S:
        print -1
        exit()
print cnt


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int k,s; cin >> k >> s;
  int ans = 0;
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      int z = s - (i+j);
      if(0 <= z && z <= k) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N, T;
  int t[210000];
  int res=0;
  cin >> N >> T;

  rep(i,N) cin >> t[i];

  FOR(i,1,N-1){
    res += min(T, t[i]-t[i-1]);
  }
  res += T;

  cout << res << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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;}
using Int = long long;
const char newl = '\n';

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

  Int n,k;
  cin>>n>>k;

  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  auto calc=[&](Int x)->Int{
    Int res=0;
    for(Int a:as){
      if(a<=x) continue;
      res+=(a-x+x-1)/x;
    }
    return res;
  };

  Int l=0,r=1e18;
  // calc(l) >  k
  // calc(r) <= k
  while(l+1<r){
    Int m=(l+r)>>1;
    if(calc(m)<=k) r=m;
    else l=m;
  }
  cout<<r<<newl;
  return 0;
}


Measured memory_bytes: 4756
n = int(input())
h = list(map(int,input().split()))
ans = 0
for i in range(n):
  ok = True
  for j in range(i):
    if h[j]<=h[i]:
      continue
    else:
      ok = False
      break
  if(ok):
    ans+=1
print(ans)
  

Measured memory_bytes: 9020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ppp{
	string s;
	int p,pos;
}a[105];
bool cmp(ppp x,ppp y){
	if(x.s==y.s) return x.p>y.p;
	return x.s<y.s;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].s>>a[i].p;
		a[i].pos=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		cout<<a[i].pos<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 4000000000000000000
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

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

  return 0;
}


Measured memory_bytes: 256
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
 
void solve()
{
  int n,k;
  cin >> n >> k;
  int a[n+1];
  fp(i,1,n)
    cin >> a[i];
  int cst[n+1];
  fill(cst,cst+n+1,mod);
  cst[1]=0;
  cst[2]=cst[1]+abs(a[2]-a[1]);
  fp(i,3,n)
  {
     for(int j=i-1;j>=(max(1ll,i-k));j--)
        cst[i]=min(cst[j]+abs(a[j]-a[i]),cst[i]);
  }
  cout << cst[n] << '\n';
  return ;
}

signed main()
{
   FAST;
	int T=1;
	// cin >> T;
	while(T--)
	{
		solve();
	}
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

struct edge {int to, cost;};

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

// 全点対間最短経路
int V, E; cin >> V >> E;
VVI d(V, VI(V, INF));
rep(i, 0, V) d[i][i] = 0;
rep(i, 0, E){
    int64_t s, t, c; cin >> s >> t >> c;
    d[s][t] = c;
}

rep(k, 0, V) rep(i, 0, V) 
    if (d[i][k] < INF) 
        rep(j, 0, V)
            if (d[k][j] < INF)  
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

rep(i, 0, V) if (d[i][i] < 0) {
    cout << "NEGATIVE CYCLE\n";
    return 0;
}

rep(i, 0, V) {
    rep(j, 0, V) {
        if (d[i][j] == INF) cout << "INF";
        else cout << d[i][j];
        if (j < V-1) cout << ' ';
    }
    cout << "\n";
}

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり




Measured memory_bytes: 3304
# -*- coding: utf-8 -*-

h,w = map(int,input().split())
s = [0] * (h+2)
s[0] = [0] * (w+2)
for i in range(1,h+1):
    s[i] = [0] + list(input()) + [0]
s[h+1] = [0] * (w+2)

for i in range(1,w+1):
    for j in range(1,h+1):
        bomb = 0
        if s[j][i-1] == "#":
            bomb += 1
        if s[j+1][i-1] == "#":
            bomb += 1
        if s[j-1][i-1] == "#":
            bomb += 1
        if s[j][i] == "#":
            bomb += 1
        if s[j+1][i] == "#":
            bomb += 1
        if s[j-1][i] == "#":
            bomb += 1
        if s[j][i+1] == "#":
            bomb += 1
        if s[j+1][i+1] == "#":
            bomb += 1
        if s[j-1][i+1] == "#":
            bomb += 1
        if s[j][i] == "#":
            bomb = "#"
        s[j][i] = bomb

del s[0]
del s[-1]

for i in range(h):
    s[i] =  s[i][1:-1]
    s[i] = map(str,s[i])
    s[i] = "".join(s[i])
    print(s[i])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int H, W, h, w;
int** table;

int get(int i, int j) {
	if (i < 0 || i >= H || j < 0 || j >= W) {
		return 0;
	}
	return table[i][j];
}

int main() {
	cin >> H >> W >> h >> w;

	if (H % h == 0 && W % w == 0) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;

	table = new int* [H];
	for (int i = 0; i < H; i++) {
		table[i] = new int[W];
		for (int j = 0; j < W; j++) {
			table[i][j] = 0;
		}
	}

	for (int i = h - 1; i < H; i++) {
		for (int j = w - 1; j < W; j++) {
			table[i][j] = get(i - h, j) + get(i, j - w) - get(i - h, j - w) - 1;
		}
	}

	int c = 1 - table[H - 1][W - 1];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			table[i][j] = c;
		}
	}

	for (int i = h - 1; i < H; i++) {
		for (int j = w - 1; j < W; j++) {
			table[i][j] = get(i - h, j) + get(i, j - w) - get(i - h, j - w) - 1;
		}
	}

	for (int i = H - 1; i > 0; i--) {
		for (int j = 0; j < W; j++) {
			table[i][j] -= table[i - 1][j];
		}
	}
	for (int j = W - 1; j > 0; j--) {
		for (int i = 0; i < H; i++) {
			table[i][j] -= table[i][j - 1];
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << table[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2816
n=int(input())
arr=list(map(int,input().split()))
dummy=len(arr)
ans=0
if dummy>2:
    for i in range(dummy-2):
        for j in range(i+1,dummy-1):
            for k in range(j+1,dummy):
                if arr[i]!=arr[j] and arr[j]!=arr[k] and arr[k]!=arr[i]:
                    if arr[i]<arr[j]+arr[k] and arr[j]<arr[k]+arr[i] and arr[k]<arr[j]+arr[i]:
                        ans+=1
    print(ans)
else:
    print(0)

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

int main() {
	int n;
  	cin >> n;
  	for(int i = 0; i <= 100; ++i) {
      for(int j = 0; j <= 100; ++j) {
		if(i * 4 + j * 7 == n) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  char S[200001],T[200001];long long a=0;
  if(!scanf("%s %s",S,T))return 0;
  for(long long i=0;i<(long long)strlen(S);i++){if(S[i]!=T[i])a++;}
  return printf("%lld\n",a),0;
}

Measured memory_bytes: 2096
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


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

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

	int largesteven = 0;

	int counter = 0;
	for(int i = 0; i < n; i++){
		if(a[i] % 2 != 0)continue;
		while(a[i] % 2 == 0 && a[i] > 0){
			a[i] /= 2;
			counter++;
		}
	}

	cout << counter << endl;



}



Measured memory_bytes: 256
n, q = map(int, input().split())
s = input().rstrip()
psums = [0]
for i, ch in enumerate(s):
    psums.append(psums[-1])
    if ch == 'C' and i - 1 >= 0 and s[i - 1] == 'A':
        psums[-1] += 1

def sumRange(left, right):
    res = psums[right + 1] - psums[left]
    if s[left] == 'C' and left - 1 >= 0 and s[left - 1] == 'A':
        res -=1
    return res

ret = []
for _ in range(q):
    left, right = map(lambda x: int(x) - 1, input().split())
    ret.append(sumRange(left, right))
print('\n'.join(map(str, ret)))

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

int main(){
    int n, build, floor, room, person;
    int rooms[4][3][10];
    cin >> n;
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                rooms[i][j][k] =0;
            }
        }
    }
    for(int i=0;i<n;i++){
        cin >>build >>floor >>room >>person;
        rooms[build-1][floor-1][room-1] += person;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout << " ";
                cout << rooms[i][j][k];
            }
            cout << endl;
        }
        if(i!=3){
            cout << "####################" << endl;
        }
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int n,s,ans,a[200005],dp[200005];
int main(){
cin>>n>>s;
for(int k=1;k<=n;k++){
   cin>>a[k];
}
dp[1]=0;
dp[2]=abs(a[2]-a[1]);
for(int k=3;k<=n;k++){
        dp[k]=INT_MAX;
for(int i=1;i<=s;i++){
        if(k-i==0)
        break;
   int t=abs(a[k-i]-a[k])+dp[k-i];
dp[k]=min(dp[k],t);
}

}
cout<<dp[n];
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所----------------------------------------------------
intl n,m;
intl a,b,c,d;
string s,t;

void input_var(){
    cin >> n;
}
//-------------------------------------------------------------------------------


signed main(){
    cout << fixed << setprecision(10);
    input_var();
    string s = "";
    while(n != 0){
        s += (char)('a' + ((n - 1) % 26));
        n = (n - 1) / 26;
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3624
import bisect

def sub():
    N, Q = [int(e) for e in input().split(" ")]
    cc = [c for c in input()]
    qs = [input() for _ in range(Q)]
    qs = [[int(e) for e in q.split(" ")] for q in qs]
    
    buf_left = []
    buf_right = []
    for i in range(N-1):
        if cc[i] == "A" and cc[i+1] == "C":
            buf_left.append(i+1)
            buf_right.append(i+2)
    # print(buf_left)
    for left, right in qs:
        index_left = bisect.bisect_left(buf_left, left)
        index_right = bisect.bisect_right(buf_right, right)
        # print(index_left, index_right)
        print(index_right-index_left)

sub()


Measured memory_bytes: 29088
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
s = A1[0] + sum(A2)
ts = s
for i in range(1, N):
    ts += A1[i] - A2[i - 1]
    s = max(ts, s)
print(s)


Measured memory_bytes: 3060
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    read = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    read = raw_input
readint = lambda: int(rr())
readlist = lambda: map(int, read().split())

####
def solve((X, N), A):
    Aset = set(A)
    ans = 1234
    for p in range(102):
        if p not in Aset:
            d = abs(p - X)
            if d < ans:
                ans = d
                ansi = p
    return ansi

print solve(readlist(), readlist())


Measured memory_bytes: 64264
/*
dp[i] = min cost to reach (n-1) from i.
*/

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n;
	vector<int> h, dp;
	cin>>n;
	h.assign(n, 0);
	dp.assign(n+2, 0);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	dp[n-1] = 0;
	dp[n-2] = abs(h[n-2]-h[n-1]);
	for(int i=n-3;i>=0;i--){
		dp[i] = min(dp[i+1]+abs(h[i]-h[i+1]), dp[i+2]+abs(h[i]-h[i+2]));
		//cout<<dp[i]<<"\n";
	}
	cout<<dp[0]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int i[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  scanf("%d",&n);
  printf("%d",i[n-1]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    string n;
    cin >> n;
    for(int i = 0;i < n.length();i++){
        if(n[i] == '1'){
            n[i] = '9';
        }else{
            n[i] = '1';
        }
    }
    cout << n << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
long long ans=1e18, n, m;
int main() {
	cin >> n >> m;
	for(long long i=1;i<n;i++){
		ans=min(ans,max(abs(i*m-m/2*(n-i)),max(((m+1)/2-m/2)*(n-i),abs(i*m-(m+1)/2*(n-i)))));
		ans=min(ans,max(abs(i*m-m*(n-i)/2),max(((n-i+1)/2-(n-i)/2)*(m),abs(i*m-(n-i+1)/2*m))));
	}
	for(long long i=1;i<m;i++){
		ans=min(ans,max(abs(i*n-n/2*(m-i)),max(((n+1)/2-n/2)*(m-i),abs(i*n-(n+1)/2*(m-i)))));
		ans=min(ans,max(abs(i*n-n*(m-i)/2),max(((m-i+1)/2-(m-i)/2)*(m),abs(i*n-(m-i+1)/2*n))));
	}
	cout << ans;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
inline int in() { int x; cin >> x; return x; }

void solve() {
  int n = in();
  int go[10][10] = {};
  int ans = 0;
  FOR (i,1,n+1) {
    string s = to_string(i);
    go[s[0]-'0'][s.back()-'0']++;
  }

  FOR (i,1,10)
    FOR (j,1,10)
      ans += go[i][j] * go[j][i];

  cout << ans << endl;
}

#undef int
int main() {
	solve();
}

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

int main()
{
	int n, a, b, d;
	scanf("%d %d %d", &n, &a, &b);
	d = a - b - 1;
	if((d % 2) == 0)
		printf("Borys\n");
	else
		printf("Alice\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
 #define watch(x) cout<<(#x)<<" is " <<x<<"\n"

#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9 + 7;
const ll MAX = 3e3+7;
const ll inf = 1e18+1;
ll a[MAX],b[MAX],dp[MAX][4];
int main(){
 fastio;
 ll n,t;
 cin>>n>>t;

 f(i,0,n){
    cin>>a[i]>>b[i];
 }

 f(i,0,n){
    af(j,t,0){
        if(t>a[i]+j){
        dp[j+a[i]][0] = max(dp[j+a[i]][0],dp[j][0] + b[i]);
        dp[j+a[i]][1] = max(dp[j+a[i]][1],dp[j][1] + b[i]);
        }
        dp[j][1] = max(dp[j][1],dp[j][0]+b[i]);
    }
 }
 cout<<dp[t-1][1]<<"\n";
 return 0; 
}

Measured memory_bytes: 3756
#include<iostream>
#include<iomanip>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;

int main(){
	double L,a,b,c;
	double s;
	cin>>L;
	a=L/3;
	b=(L-a)/2;
	c=L-a-b;
	s=a*b*c;
	cout<<fixed<<setprecision(8)<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a;
	while(scanf("%d",&a)!=EOF)
	{
		long long max=-2147483647,sum=0;
		for(int i=0;i<a;i++)
		{
			int b;
			scanf("%d",&b);
			sum+=b;
			if(b>max) max=b;
		}
		if(max>=sum-max) printf("No");
		else            printf("Yes");
		printf("\n");
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int a;
  string s;
  cin >> a >> s;

  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}



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

int main() {
  int n;
  cin >> n;
  r(a,1){
    if(n==1)cout<<"a"<<endl;
    else r(b,2){
      if(n==2)cout<<"a"<<char('a'+b)<<endl;
      else r(c,max(a,b)+2){
        if(n==3)cout<<"a"<<char('a'+b)<<char('a'+c)<<endl;
        else r(d,max(a,max(b,c))+2){
         if(n==4) cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<endl;
          else r(e,max(a,max(b,max(c,d)))+2){
            if(n==5) cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<endl;
            else r(f,max(a,max(b,max(c,max(d,e))))+2){
              if(n==6) cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<char('a'+f)<<endl;
              else r(g,max(a,max(b,max(c,max(d,max(e,f)))))+2){
                if(n==7) cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<char('a'+f)<<char('a'+g)<<endl;
                else r(h,max(a,max(b,max(c,max(d,max(e,max(f,g))))))+2){
                  if(n==8)cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<char('a'+f)<<char('a'+g)<<char('a'+h)<<endl;
                  else r(i,max(a,max(b,max(c,max(d,max(e,max(f,max(g,h)))))))+2){
                    if(n==9)cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<char('a'+f)<<char('a'+g)<<char('a'+h)<<char('a'+i)<<endl;
                    else r(j,max(a,max(b,max(c,max(d,max(e,max(f,max(g,max(h,i))))))))+2){
                      if(n==10)cout<<"a"<<char('a'+b)<<char('a'+c)<<char('a'+d)<<char('a'+e)<<char('a'+f)<<char('a'+g)<<char('a'+h)<<char('a'+i)<<char('a'+j)<<endl;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<queue>
#include<map>

using namespace std;



int main(){
    string s;
    cin >> s;

    cout << s[0] << s[1] << s[2] << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 10
#define INF 1e9
typedef vector<int> Vec;
 
int N, res;
map<Vec,int> dist[2];
Vec v[2];
 
void bfs(int p){
    int t = !p;
    Vec next;
    queue<Vec> que; 
 
    dist[p][v[p]] = 0;
    que.push(v[p]);
 
    while(!que.empty()){
	Vec s = que.front(); que.pop();
 
	if(s == v[t]){
	    res = dist[p][s];
	    break;
	}
 
	if(dist[p][s] >= (N-1)/2){
	    break;
	}
 
	for(int i = 0 ; i < N-1 ; i++){
	    for(int j = i + 1 ; j < N ; j++){
		next = s;
		reverse(next.begin()+i, next.begin()+j+1);
 
		if(!dist[p].count(next)){
		    dist[p][next] = dist[p][s] + 1;
		    que.push(next);
		} 
	    }
	}
    }
}
 
int main(){
    cin >> N;
    v[0].resize(N);
    for(int i = 0 ; i < N ; i++){
	cin >> v[0][i];
	v[1].push_back(i+1);
    }
 
    res = 9;
    bfs(0); bfs(1);
    map<Vec,int>::iterator it, val;
   
    for(it = dist[0].begin() ; it != dist[0].end() ; ++it){
	val = dist[1].find(it->first);
	if(val != dist[1].end()){
	    res = min(res, it->second+val->second);
	}    
    }
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 83052
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = [[0]*3 for i in range(M)]
for i in range (M):
    d[i][0],d[i][1],d[i][2] = map(int,input().split())

now_min = min(a)+min(b)
mim = 10**9
for i in range(M):
    if a[d[i][0]-1] + b[d[i][1]-1] - d[i][2] <= mim:
        mim = a[d[i][0]-1] + b[d[i][1]-1] - d[i][2]

print(min(now_min,mim))

Measured memory_bytes: 78188
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 100;
LL n, k;
LL a[maxn], c[maxn*4];
map<LL, int> M;
vector<LL> V;
void Modify(int x, int s){
    for(; x <= n; x += x&(-x)) c[x] += s;
}
LL Query(int y){
    if(y <= 0) return 0;
    LL ans = 0;
    for(int x = y; x; x -= x&(-x)) ans += c[x];
    return ans;
}

int main()
{
    int x;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &x), a[i] = x;
    LL sum = 0;
    for(int i = 1; i <= n; i++) {
        sum += a[i];
        sum -= k;
        V.push_back(sum);
    }
    sort(V.begin(), V.end());
    for(int i = 0; i < V.size(); i++) M[V[i]] = i+1;
    sum = 0;
    LL ans = 0;
    for(int i = 1; i <= n; i++){
        sum += a[i];
        sum -= k;
        ans += Query(M[sum]);
        if(sum >= 0) ans++;
        Modify(M[sum], 1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 17392
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 5e3 + 10;
ll dp[MAX_N][MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    string in;
    int k;
    cin >> n >> in;
    dp[0][0] = 1;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j <= n; j ++) {
            if(dp[i][j] == 0) {continue;}
            //cout << i << " " << j << " " << dp[i][j] << endl;
            dp[i + 1][j + 1] += 2 * dp[i][j];
            fix(dp[i + 1][j + 1]);
            if(j != 0) {
                dp[i + 1][j - 1] += dp[i][j];
                fix(dp[i + 1][j - 1]);
            } else {
                dp[i + 1][j] += dp[i][j];
                fix(dp[i + 1][j]);
            }
        }
    }
    for(int i = 0; i < in.size(); i ++) {
        dp[n][in.size()] *= (mod + 1ll) / 2ll;
        fix(dp[n][in.size()]);
    }
    cout << dp[n][in.size()] << endl;
    return 0;
}



Measured memory_bytes: 194176
def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
print(anagram(N,S))

Measured memory_bytes: 19504
#!/usr/bin/env python3

import sys
input=sys.stdin.readline


LEN=2*10**5+10

moves=[0]*LEN
for i in range(1,LEN):
  tmp=i
  cnt=0
  while tmp!=0:
    popcount=0
    for j in range(20):
      if tmp&(1<<j):
        popcount+=1
    tmp%=popcount
    cnt+=1
  moves[i]=cnt

n=int(input())
x=input()
k=x.count('1')
if k==0:
    for i in range(n):
        print(1)
elif k==1:
    pos=x.index('1')
    for i in range(n):
        if i==pos:
            print(0)
        else:
            if pos==n-1:
                print(2)
            else:
                if i==n-1:
                    print(2)
                else:
                    print(1)
else:
    sum1=0
    sum2=0
    tmp1=1
    tmp2=1
    for i in range(n-1,-1,-1):
        if x[i]=='1':
            sum1+=tmp1
            sum1%=k+1
            sum2+=tmp2
            sum2%=k-1
        tmp1*=2
        tmp1%=k+1
        tmp2*=2
        tmp2%=k-1
    for i in range(n):
        if x[i]=='0':
            tmp=sum1+pow(2,n-i-1,k+1)
            tmp%=k+1
            print(moves[tmp]+1)
        else:
            tmp=sum2-pow(2,n-i-1,k-1)
            tmp%=k-1
            print(moves[tmp]+1)


Measured memory_bytes: 11104