akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
  int n;
  int dx[] = {1,-1,0, 1};
  int dy[] = {0, 1,1,-1};

  int cn=1;
  while(cin >> n, n) {
    int ans[n][n];
    int x=0, y=0;
    int dir=0;

    if (n==1) {
      ans[0][0] = 1;
    } else {
      for(int i=1; ;i++) {
        ans[x][y] = i;
//      cout << x << " " << y << endl;
        x += dx[dir];
        y += dy[dir];
      
        if (x==n-1&&y==n-1) {
          ans[x][y] = i+1;
          break;
        }
        if (dir==0) {
          if (y == 0){
            dir = 1;
          } else {
            dir = 3;
          }
        } else if (dir == 1) {
          if (y==n-1) {
            dir = 0;
          } else if (x==0) {
            dir = 2;
          }
        } else if (dir == 2) {
          if (x==0) {
            dir = 3;
          } else {
            dir = 1;
          }
        } else if (dir == 3) {
          if (x==n-1) {
            dir = 2;
          } else if (y==0) {
            dir = 0;
          }
        }
      }
    }
    printf("Case %d:\n", cn++);
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        printf("%3d",ans[j][i]);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

#define eps 1e-8
#define PI acos(-1.0)

const int M = 110;
using namespace std;
double X,Y;
struct Point
{
    double x,y;
}p[M];
struct Triangle
{
    Point v[3];
};
struct Circle
{
    Point center;
    double r;
};
double pow(double x)
{
    return x*x;
}
double Len(Point a,Point b)
{
    return sqrt(pow(a.x-b.x)+pow(a.y-b.y));
}
double TriangleArea(Triangle a)//求三角形的面积
{
    double px1=a.v[1].x-a.v[0].x;
    double py1=a.v[1].y-a.v[0].y;
    double px2=a.v[2].x-a.v[0].x;
    double py2=a.v[2].y-a.v[0].y;
    return fabs(px1*py2-px2*py1)/2;
}
Circle CircleOfTriangle(Triangle t)//就三角形外接圆
{
    Circle tmp;
    double a=Len(t.v[0],t.v[1]);
    double b=Len(t.v[0],t.v[2]);
    double c=Len(t.v[1],t.v[2]);
    tmp.r=a*b*c/4/TriangleArea(t);
    double a1=t.v[1].x-t.v[0].x;
    double b1=t.v[1].y-t.v[0].y;
    double c1=(a1*a1+b1*b1)/2;
    double a2=t.v[2].x-t.v[0].x;
    double b2=t.v[2].y-t.v[0].y;
    double c2=(a2*a2+b2*b2)/2;
    double d=a1*b2-a2*b1;
    tmp.center.x=t.v[0].x+(c1*b2-c2*b1)/d;
    tmp.center.y=t.v[0].y+(a1*c2-a2*c1)/d;
    return tmp;
}
void Run(int n)
{
    random_shuffle(p+1,p+n+1);//随机排序取点
    int i,j,k;
    Circle tep;
    tep.center=p[1];
    tep.r=0;
    for(i=2;i<=n;i++)
    {
        if(Len(p[i],tep.center)>tep.r+eps)
        {
            tep.center=p[i];
            tep.r=0;
            for(j=1;j<i;j++)
            {
                if(Len(p[j],tep.center)>tep.r+eps)
                {
                    tep.center.x=(p[i].x+p[j].x)/2;
                    tep.center.y=(p[i].y+p[j].y)/2;
                    tep.r=Len(p[i],p[j])/2;
                    for(k=1;k<j;k++)
                    {
                        if(Len(p[k],tep.center)>tep.r+eps)
                        {
                            Triangle t;
                            t.v[0]=p[i];
                            t.v[1]=p[j];
                            t.v[2]=p[k];
                            tep=CircleOfTriangle(t);
                        }
                    }
                }
            }
        }
    }
    printf("%lf\n",tep.r);
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%lf%lf",&p[i].x,&p[i].y);
    Run(n);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static long expo(long base, long exp) {
		long t = 1L;
		while (exp > 0) {
			if (exp % 2 != 0)
				t = (t * base);

			base = (base * base);
			exp /= 2;
		}
		return t;
	}

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);
		long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), k = sc.nextLong();
		long sum = 0;
		
		if(k > a)
			sum += a;
		else
			sum += k;
		
		k -= a;
		k -= b;
		if (k > 0)
			sum -= k;

		pr.println(sum);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 32652
MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def cum_sum(N):
    return N * (N+1) // 2

def solve2():
    N, M, K = [int(_) for _ in raw_input().split()]
    sumx = 0
    for xi in range(1, N+1):
        sumx = (sumx + cum_sum(N) - (N + 1 - xi) * xi) % MAX
    sumx = (sumx * M * M) // 2 %MAX
    sumy = 0
    for yi in range(1, M+1):
        sumy = (sumy + cum_sum(M) - (M + 1 - yi) * yi) % MAX
    sumy = (sumy * N * N) // 2 %MAX
    ret = (sumx + sumy) * combination(M*N-2, K-2) % MAX
    print ret

if __name__ == '__main__':
    solve2()


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

struct UnionFind {
  vector<int> data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n, m, k; cin >> n >> m >> k;
  vl a(m), b(m), c(k), d(k), ans(n);
  UnionFind uf(n);
  rep(i,m) {
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
    uf.unite(a[i], b[i]);
  }
  rep(i,k) {
    cin >> c[i] >> d[i];
    c[i]--; d[i]--;
  }

  rep(i,n) ans[i] = uf.size(i);
  rep(i,m) {
    if (!uf.same(a[i], b[i])) continue;
    ans[a[i]]--;
    ans[b[i]]--;
  }
  rep(i,k) {
    if (!uf.same(c[i], d[i])) continue;
    ans[c[i]]--;
    ans[d[i]]--;
  }
  rep(i,n) {
    cout << ans[i] - 1 << " \n"[i==n-1];
  }
  return 0;
}


Measured memory_bytes: 5120
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

ll fact[NMAX];
ll inv_fact[NMAX];

void gcd(ll a, ll b, ll &x, ll &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        ll x0,y0,d;
        gcd(b,a%b,x0,y0);
        x = y0;
        y = x0 - (a/b)*y0;
    }
}

ll invers_modular(ll a, ll n)
{
    ll inv,ins;
    gcd(a,n,inv,ins);
 
    if(inv < 0)
    {
        inv = n + inv % n;
    }
    inv%=n;
    return inv;
}


void factorial()
{
    fact[1] = 1;
    for(int i =2; i< NMAX; ++i)
    {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    for(int i = 0; i < NMAX; ++i)
    {
        inv_fact[i] = invers_modular(fact[i], MOD);
    }
}

ll comb(ll n, ll m)
{
	if(n == m)
		return 1;
    if(n < m)
        return 0;
    
    return ((fact[n] * inv_fact[m]) % MOD * inv_fact[n-m]) % MOD; 
    
}

ll calculate(ll n, ll k)
{
	ll res = 1;
	for(int i= 1; i< k; ++i)
	{
		res*=(n-i);
		res = res%MOD;
	}
	return res;
}

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

	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i =0 ; i< n; ++i)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	ll max_sum = 0;
	ll min_sum = 0;
	factorial();
	for(int i =0 ;i < n -k + 1; ++i)
	{
		ll aux = comb(n-i-1,k-1);

		//max_sum += ((v[n-i-1] % MOD) * (aux % MOD)) % MOD;
		ll val = v[i] + MOD; val %= MOD;
		val*= aux; val %= MOD;
		max_sum+= MOD - val; max_sum %=MOD;

		//min_sum += ((v[i] % MOD) * (aux % MOD)) % MOD;
		
	}
	for(int i = k-1; i < n; ++i)
	{
		ll aux = comb(i,k-1);

		ll val = v[i]+MOD; val %= MOD;
		val*= aux; val %= MOD;
		max_sum+= val; max_sum %=MOD;
	}
	cout << max_sum;


    return 0;
}

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

class UnionFind
{
    std::vector<size_t> root;
    const size_t maximum_size;

public:
    UnionFind(const size_t N) : maximum_size(N + 5)
    {
        this->root = std::vector<size_t>(N + 1, this->maximum_size);
    }

    size_t find_root(const size_t A)
    {
        if (this->root[A] >= this->maximum_size)
        {
            return A;
        }
        this->root[A] = this->find_root(this->root[A]);
        return this->root[A];
    }

    size_t size(const size_t A)
    {
        return this->root[this->find_root(A)] - this->maximum_size + 1;
    }

    bool unite(const size_t A, const size_t B)
    {
        size_t rootA = find_root(A);
        size_t rootB = find_root(B);
        if (rootA == rootB)
        {
            return false;
        }

        if (this->size(rootA) < this->size(rootB))
        {
            std::swap(rootA, rootB);
        }

        this->root[rootA] += this->size(rootB);
        this->root[rootB] = rootA;

        return true;
    }

    bool has_same_root(const size_t A, const size_t B)
    {
        return this->find_root(A) == this->find_root(B);
    }
};

int main()
{
    size_t N, M;
    cin >> N >> M;

    UnionFind uf(N);
    size_t A, B;
    for (size_t i = 0; i < M; i++)
    {
        cin >> A >> B;
        uf.unite(A, B);
    }

    size_t ans = 0;
    for (size_t i = 1; i <= N; i++)
    {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

const int nmax = 8;
bool graph[nmax][nmax];
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

int dfs(int v,ll N,bool visited[nmax]){
    bool all_visited = true;

    for(int i = 0; i < N; i++)
    {
        if(!visited[i]){
            all_visited = false;
        }
    }

    if(all_visited){
        return  1;
    }
    int ret = 0;
    for(size_t i = 0; i < N; i++)
    {
        if(!graph[v][i]){
            continue;
        }
        if(visited[i]){
            continue;
        }

        visited[i] = true;
        ret += dfs(i,N,visited);
        visited[i] = false;
    }

    return ret;

}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    for (int i = 0; i < M; i++)
    {
        ll a, b;
        cin >> a >> b;
        graph[a - 1][b - 1] = true;
        graph[b - 1][a - 1] = true;
    }
    bool visit[nmax];
    visit[0] = true;
    int ans = dfs(0, N, visit);
    cout << ans << endl;
    return 0;
}


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

#define REP(i, n) for (int i=0;i<(n);i++)
#define FOR(i, a, b) for (int i=(a);i<(b);i++)

using namespace std;

char tmp_s[5001];
string s;
int K;

int main()
{
    scanf("%s", tmp_s);
    s = tmp_s;
    scanf("%d", &K);
    int N = s.size();
    vector<string> S;
    REP(i, N) {
        int j = 0;
        string tmp = "";
        while(j<K && i+j<N) {
            tmp = tmp + s[i+j];
            S.push_back(tmp);
            j++;
        }
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S[K-1] << endl;

    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

template<int MOD>
struct ModInt {
    long long v;
    ModInt(long long _v = 0) {v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) v += MOD;}
    ModInt& operator += (const ModInt &other) {v += other.v; if (v >= MOD) v -= MOD; return *this;}
    ModInt& operator -= (const ModInt &other) {v -= other.v; if (v < 0) v += MOD; return *this;}
    ModInt& operator *= (const ModInt &other) {v = v * other.v % MOD; return *this;}
    ModInt& operator /= (const ModInt &other) {return *this *= inverse(other);}
    bool operator == (const ModInt &other) const {return v == other.v;}
    bool operator != (const ModInt &other) const {return v != other.v;}
    friend ModInt operator + (ModInt a, const ModInt &b) {return a += b;}
    friend ModInt operator - (ModInt a, const ModInt &b) {return a -= b;}
    friend ModInt operator * (ModInt a, const ModInt &b) {return a *= b;}
    friend ModInt operator / (ModInt a, const ModInt &b) {return a /= b;}
    friend ModInt operator - (const ModInt &a) {return 0 - a;}
    friend ModInt power(ModInt a, long long b) {ModInt ret(1); while (b > 0) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
    friend ModInt inverse(ModInt a) {return power(a, MOD - 2);}
    friend ostream& operator << (ostream &os, const ModInt &m) {return os << m.v;}
};
typedef ModInt<998244353> M;

int l[15], r[15];
M dp[200005], tot[15];

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

    int n, k;
    cin >> n >> k;
    for (int i=0; i<k; i++)
        cin >> l[i] >> r[i];

    dp[0] = 1;
    for (int i=1; i<n; i++)
        for (int j=0; j<k; j++) {
            tot[j] += (i >= l[j] ? dp[i-l[j]] : 0) - (i > r[j] ? dp[i-r[j]-1] : 0);
            dp[i] += tot[j];
        }
    cout << dp[n-1] << "\n";

    return 0;
}


Measured memory_bytes: 5192
h, w, K = map(int, input().split())
c_mat = []
for _ in range(h):
    c_mat.append(input())
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        res = 0
        for k in range(h):
            if i >> k & 1:
                continue
            for l in range(w):
                if j >> l & 1:
                    continue
                if c_mat[k][l] == '#':
                    res += 1
        if res == K:
            ans += 1
print(ans)

Measured memory_bytes: 68300
def main():
    N, M = map(int, input().split())
    result = [0] * (M + 1)
    for _ in range(N):
        row = list(map(int, input().split()))
        A = row[1:]
        for num in A:
            result[num] += 1

    print(len(list(filter(lambda x: x == N, result))))


if __name__ == "__main__":
    main()


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

int main()
{
    int n, p, k;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &p, &k);
        if (p % k == 0) printf("%d\n", k);
        else { printf("%d\n", p % k); }
    }
    return 0;
}



Measured memory_bytes: 2736
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=2030;

int n,m;
vector<int> g[N];
vector<pii> path[N],g_lim[N];
int dep[N],fa[N];
int u[N],v[N],w[N];

void dfs(int u,int p){
    dep[u]=dep[p]+1,fa[u]=p;
    for(int v:g[u])if(v!=p)dfs(v,u);
}
int lca(int x,int y){
    while(x!=y){
        if(dep[x]<dep[y])swap(x,y);
        x=fa[x];
    }
    return x;
}
int pass[N][N],ans;
int choose[N][2];//这个点选择的两条链
void solve(int u,int p){
    choose[u][0]=choose[u][1]=-1;
    FOR(i,1,m)pass[u][i]=-1;
    for(int v:g[u])if(v!=p){
        solve(v,u);
        FOR(i,1,m)if(pass[v][i]!=-1)pass[u][i]=pass[v][i];
    }
    for(pii p:path[u])pass[u][p.fi]=p.se;//继承的同时，ban掉一些以u为lca的边
    int cnt=0;//有多少边经过u的父边
    FOR(i,1,m)cnt+=pass[u][i]!=-1;
    if(cnt<2){
        ans+=cnt;
    }else {
        ans+=2;
        for(int v:g[u])if(v!=p){
            //printf("\033[33m%d,%d\033[0m\n",choose[v][0],choose[v][1]);
            if(choose[v][0]!=-1&&choose[v][1]!=-1&&pass[u][choose[v][0]]!=-1&&pass[u][choose[v][1]]!=-1){//两个都继承上来
                choose[u][0]=choose[v][0];
                choose[u][1]=choose[v][1];//直接采用儿子的限制
                return;
            }
        }
        int x=-1,y=-1;
        FOR(i,1,m)if(pass[u][i]!=-1)x==-1?x=i:y=i;
        choose[u][0]=x,choose[u][1]=y;
        //printf("solve(%d,%d)\n",u,p);
        //FOR(i,1,m)printf("%d%c",pass[u][i]," \n"[i==m]);
        //printf("x=%d,y=%d\n",x,y);
        g_lim[x].pb({y,pass[u][x]^pass[u][y]^1});
        g_lim[y].pb({x,pass[u][x]^pass[u][y]^1});
        //printf("add_lim(%d,%d,%d)\n",x,y,pass[u][x]^pass[u][y]^1);
    }
}
int rv[N],vis[N];
void dfs2(int u,int col){
    if(vis[u])return;
    rv[u]=col;
    vis[u]=1;
    for(pii p:g_lim[u])dfs2(p.fi,p.se^col);
}
int main(){
    scanf("%d%d",&n,&m);
    FOR(i,1,n-1){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a].pb(b),g[b].pb(a);
    }
    dfs(1,0);
    FOR(i,1,m){
        scanf("%d %d",&u[i],&v[i]);
        w[i]=lca(u[i],v[i]);
        if(u[i]!=w[i])path[u[i]].pb({i,0});//0:从u出发的边
        if(v[i]!=w[i])path[v[i]].pb({i,1});//1:到达u的边
        path[w[i]].pb({i,-1});//经过u的边
    }
    solve(1,0);
    FOR(i,1,m)if(!vis[i])dfs2(i,0);
    printf("%d\n",ans);
    FOR(i,1,m){
        if(rv[i])printf("%d %d\n",v[i],u[i]);
        else printf("%d %d\n",u[i],v[i]);
    }
    return 0;
}


Measured memory_bytes: 16512
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
using namespace std;

void solve() {
	int X, A;
	cin >> X >> A;
	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;
	return;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
// 最初の文字の固まりを整数値と想定して読み込む
while (true) {
int H = sc.nextInt();
int W = sc.nextInt();
if (H == 0 && W == 0) {
break;
}
    for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
            System.out.print("#");
            }
            System.out.print("\n");
            }
    System.out.println();
        }
}
}



Measured memory_bytes: 38116
#insertion
n=int(input())
s=input()
count=1
Llist=[]
Rlist=[]
s=s+"X"
for i  in range(n):
    if s[i]==s[i+1]:
        count+=1
    else:
        if s[i]=="(":
            Llist.append(count)
        else:
            Rlist.append(count)
        count=1
#LのがRよりもつよい
if s[0]==")":
    Llist.insert(0,0)
if s[-2]=="(":
    Rlist.append(0)

Lsum=0
Rsum=0
for i in range(len(Llist)):
    Lsum+=Llist[i]
    Rsum+=Rlist[i]
    if Lsum>=Rsum:
        pass
    elif Lsum<Rsum:
        Llist[0]+=(Rsum-Lsum)
        Lsum+=(Rsum-Lsum)
if Lsum!=Rsum:
    Rlist[-1]+=(Lsum-Rsum)
anstr=""
for i in range(len(Llist)):
    a,b=Llist[i],Rlist[i]
    anstr+="("*a
    anstr+=")"*b
print(anstr)    

Measured memory_bytes: 3064
#ABC158C
import sys
a, b = map(int, sys.stdin.readline().split())
#print(a,b)

for num in range(0, 1001):
    A = int(num*0.08)
    B = int(num*0.1)
    #print(A, B, num)
    if a==A and b ==B:
        print(num)
        break
else:
    print(-1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define LL long int
 
void solve(){
    int n;
    cin >> n;
 
    vector<string> s(n);
 
    for(int i = 0; i < n; ++i) cin >> s[i];
 
    sort(s.begin(),s.end());
 
    vector<string> ans;
    int l = 0;
    int r = l;
 
    int count = 0;
    int max = -1;
 
    while(r < n && l < n){
        if(s[l] == s[r]){
            count++;
            r++;
        }else{
            if(count == max){
                ans.push_back(s[l]);
            }
            if(count > max){
                max = count;
                ans.clear();
                ans.push_back(s[l]);
            }
            l = r;
            count = 0;
        }
    }
 
    if(count == max){
                ans.push_back(s[l]);
    }
    if(count > max){
        max = count;
        ans.clear();
        ans.push_back(s[l]);
    }

    for(int i = 0; i < ans.size(); ++i){
        cout << ans[i] << endl;
    }
 
    return ;
}
 
int main(){
    solve();
 
    return 0;
}

Measured memory_bytes: 15988
in_data=input()

in_list=[]

in_list=in_data.split(" ")

in_list[0]=int(in_list[0])
in_list[1]=int(in_list[1])
in_list[2]=int(in_list[2])


if in_list[0]<in_list[1] and in_list[1]<in_list[2] :
    print("Yes")

else:
    print("No")






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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N;
    cin >> N;

    string pre;
    cin >> pre;

    unordered_set<string> words;
    words.emplace(pre);

    string ans = "Yes";
    rep(i, N - 1) {
        string now;
        cin >> now;

        if(not((pre.back() == now.front()) and (words.count(now) == 0))) {
            ans = "No";
        }
        words.emplace(now);
        pre = now;
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>

using namespace std;

int ans[10005];
int res[105][105];

int main(){
    int h,w;
    scanf("%d %d",&h,&w);
    int n;
    scanf("%d",&n);
    for (int i = 1;i <= n;i++){
        scanf("%d",&ans[i]);
    }
    int k = 1;
    int l = 0;
    for (int i = 0;i < w;i++){
        if (l == 0){
            for (int j = 0;j < h;j++){
                if (ans[k]!=0){
                    res[j][i] = k;
                    ans[k]--;
                }
                else{
                    k++;
                    res[j][i] = k;
                    ans[k]--;
                }
            }
            l = 1;
        }
        else{
            for (int j = h-1;j >=0;j--){
                if (ans[k]!=0){
                    res[j][i] = k;
                    ans[k]--;
                }
                else{
                    k++;
                    res[j][i] = k;
                    ans[k]--;
                }
            }
            l = 0;
        }
    }
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            printf("%d%c",res[i][j],j == w-1?'\n':' ');
        }
    }
    return 0;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int h,w;
char s[1000][1000];
bool c[1000][1000];

signed main(){
  cin>>h>>w;
  rep(i,h){
    cin>>s[i];
  }
  int ans=0;

  rep(i,h){
    rep(j,w){
      if(s[i][j]=='.'){
        queue<P> q;
        q.push(P(i,j));
        int a=0,b=0;
        while(!q.empty()){
          P p = q.front();
          q.pop();
          int x=p.S,y=p.F;
          if(c[y][x]) continue;
          if(s[y][x]=='.') a++;
          else b++;
          c[y][x]=true;
          rep(k,4){
            int ax=x+vx[k];
            int ay=y+vy[k];
            if(!(0<=ax&&ax<w&&0<=ay&&ay<h)) continue;
            if(s[y][x]=='.'&&s[ay][ax]=='#')
              q.push(P(ay,ax));
            if(s[y][x]=='#'&&s[ay][ax]=='.')
              q.push(P(ay,ax));
          }
        }
        ans+=a*b;
      }
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1024
s = input().strip()

if s[0] != 'A':
    print('WA')
else:
    i = 0
    j = 0
    for k in range(2, len(s) - 1):
        if s[k] == 'C':
            i += 1
        if s[k].islower():
            j += 1
    if s[-1].islower() and s[1].islower():
        j += 2
    if i == 1 and j == len(s) - 2:
        print('AC')
    else:
        print('WA')


 

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

int P[8];
int Q[8];
bool Used[8] = {false};

int factorial(int n) {
  if (n <= 1) return 1;
  else return n*factorial(n-1);
}

int KthSmallest(int n) {
  int j = 0;
  for (int i = 0; i < n; i++){
  	if (!Used[i]) j++;
  }
  return j;
}

int main (void) {
  int N; 
  cin >> N;
  int a = 1, b = 1;
  
  for (int i = 0; i < N; i++){
    cin >> P[i];
    int k = KthSmallest(P[i]);
    Used[P[i]-1] = true;
    a += (k-1) * factorial(N-i-1);
  }
  for (int i = 0; i < N; i++) Used[i] = false;
  for (int i = 0; i < N; i++){
    cin >> Q[i];
    int k = KthSmallest(Q[i]);
    Used[Q[i]-1] = true;
    //cout << k-1 << "," << factorial(N-i-1) << endl;
    
    b += (k-1) * factorial(N-i-1);
  }
  //cout << a << " " << b << endl;
  cout << abs(a-b) << endl;
  
  return 0;
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc065
// status: [review][study]
// tag: [最小全域木][minimum_spanning_tree]

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

#define SUBMIT
//#define DEBUG

struct node {
    int x, y, id;
};

struct edge {
    int u, v, d;

    bool operator<(const edge& other) const { return d < other.d; }
};

node a[200010];
edge g[300010];
int n, m, fa[200010];

int cmpx(const node& lhs, const node& rhs) { return lhs.x < rhs.x; }
int cmpy(const node& lhs, const node& rhs) { return lhs.y < rhs.y; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(6
8 3
4 9
12 19
18 1
13 5
7 6
)");
#endif
    stream >> n;
    for (int i = 1; i <= n; ++i) {
        fa[i] = i;
        stream >> a[i].x >> a[i].y;
        a[i].id = i;
    }

    sort(a + 1, a + n + 1, cmpx);
    for (int i = 1; i < n; ++i) g[++m] = edge {a[i].id, a[i + 1].id, a[i + 1].x - a[i].x};
    sort(a + 1, a + n + 1, cmpy);
    for (int i = 1; i < n; ++i) g[++m] = edge {a[i].id, a[i + 1].id, a[i + 1].y - a[i].y};

    int ans = 0;
    sort(g + 1, g + m + 1);
    for (int i = 1; i <= m; ++i) {
        if (find(g[i].u) != find(g[i].v))
        {
            ans += g[i].d;
            fa[fa[g[i].u]] = fa[g[i].v];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	unordered_set<string> S;
	string word;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {	
		cin >> word;
		if (word == "insert"){
			cin >> word;
			S.insert(word);
		}
		else if (word == "find"){
			cin >> word;
			cout << ((S.count(word) > 0) ? "yes" : "no") << endl;
		}
	}
}

Measured memory_bytes: 30568
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int root(vector<int>& g, int i){
    if(g[i]==i) return i;
    int new_i=root(g, g[i]);
    g[i]=new_i;
    return new_i;
}

void unite(vector<int>& g, int i, int j){
    int new_i=root(g, g[i]);
    int new_j=root(g, g[j]);
    g[new_i]=new_j;
}

int main(){
    int n, k, l; cin >> n >> k >> l;
    vector<int> g_pq(n), g_rs(n);
    for(int i=0; i<n; ++i){
        g_pq[i]=g_rs[i]=i;
    }
    for(int i=0; i<k; ++i){
        int p, q; cin >> p >> q;
        --p; --q;
        unite(g_pq, p, q);
    }
    for(int i=0; i<l; ++i){
        int r, s; cin >> r >> s;
        --r; --s;
        unite(g_rs, r, s);
    }

    vector<unordered_set<int>> gs;
    unordered_map<int, int> root_to_graph;
    for(int i=0; i<n; ++i){
        int i_root=root(g_pq, i);
        if(root_to_graph.find(i_root)==root_to_graph.end()){
            int g=gs.size();
            gs.push_back(unordered_set<int>());
            root_to_graph[i_root]=g;
        }
        gs[root_to_graph[i_root]].insert(i);
    }

    vector<int> ans(n);
    for(auto& g : gs){
        unordered_map<int, int> i_to_g;
        unordered_map<int, int> g_to_n;
        for(auto i : g){
            int g=root(g_rs, i);
            i_to_g[i]=g;
            ++g_to_n[g];
        }
        for(auto& p : i_to_g){
            ans[p.first]=g_to_n[p.second];
        }
    }
    bool first=true;
    for(int i=0; i<n; ++i){
        if(first) first=false;
        else cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 33736
import math
import collections
import itertools
import heapq
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    sA = sorted(A)
    sC = sorted(C)

    res = 0
    for b in B:
        a = bisect.bisect_left(sA, b)
        c = N - bisect.bisect_right(sC, b)
        res += a*c

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 124208
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll h,n;
  cin >> h >> n;
  ll sum=0;
  rep(i,n) {
    ll x;
    R x;
    sum+=x;
  }
  if(h<=sum) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

//MODULAR ARITHMATIC
const int mmod = 1000000000 + 7;

lld add(lld a, lld b, lld m = mmod) {
	return (a % m + b % m) % m;
}

lld sub(lld a, lld b, lld m = mmod) {
	return (a % m - b % m + m) % m;
}

lld mul(lld a, lld b, lld m = mmod) {
	return ((a % m) * (b % m) % m);
}

lld pwr(lld a, lld b, lld m = mmod) {
	a %= m;
	lld r = 1;
	while (b) {
		if (b & 1) r = r * a % m;
		b >>= 1;
		a = a * a % m;
	}
	return r;
}

lld inv(lld a, lld m = mmod) {
	return pwr(a, m - 2, m);
}

//FACTORIAL MOD mmod
#define SIZE 1000000
lld fact[SIZE + 1];
void factorial() {
	fact[0] = 1;
	for (lld i = 1; i <= SIZE; i++) {
		fact[i] = (fact[i - 1] % mmod * (i % mmod)) % mmod;
	}
}

//NCR MOD mmod
lld nCr(lld n, lld r) {
	return (((fact[n] * inv(fact[r])) % mmod) * (inv(fact[n - r]))) % mmod;
}

lld dp[2001][2001];

lld solve(lld n, lld l) {
	if (n < 0 || n == 1 || n == 2 || l < 0) return 0;
	if ((l == 0 && n != 0) || (n == 0 && l != 0)) return dp[n][l] = 0;
	if (n == 0 && l == 0) {
		return dp[n][l] = 1;
	}
	lld c = 0;
	if (dp[n][l] != -1) return dp[n][l];
	for (lld i = 3; i <= n; i++) {
		c += solve(n - i, l - 1);
		c %= MOD;
	}
	return dp[n][l] = c;

}

int main() {
	fast;
	cin.tie(0);

	factorial();

	lld n;
	cin >> n;
	lld x = 0;
	for (lld k = 2; k <= n; k++) {
		x = add(x, mul(pwr(8, n - k), mul(nCr(n, k), sub(pwr(2, k), 2))));
	}

	cout << x << endl;
}








Measured memory_bytes: 11404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int a[85][85], b[85][85];
bool dp[85][85][15000];

int main(){
    int h,w; cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> b[i][j];
        }
    }

    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    rep(i, h){
        rep(j, w){
            rep(k, 15000){
                if(dp[i][j][k]){
                    if(i < h -1){
                        dp[i+1][j][k + abs(a[i+1][j] - b[i+1][j])] = true;
                        dp[i+1][j][abs(k - abs(a[i+1][j] - b[i+1][j]))] = true;
                    }    
                    if(j < w-1){
                        dp[i][j+1][k + abs(a[i][j+1] - b[i][j+1])] = true;
                        dp[i][j+1][abs(k - abs(a[i][j+1] - b[i][j+1]))] = true;
                    }
                }
            }
        }
    }
    
    rep(k,15000){
        if(dp[h-1][w-1][k]){
            cout << k << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 99456
#if !defined(ONLINE_JUDGE)
    #include "prettyprint.hpp" 
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 1729
    #define cer(x) 13
#endif
const bool testcase=0;
typedef long long int ll;
#define INF LONG_MAX
#define MINF LONG_MIN 
#define MAXR 111111
const ll mod1 = 1000000007;
const ll mod2 = 998244353;



//loop 
#define loop(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define loope(i,L,R) for (int i = L; i <= R; i++)
#define rloop(i,L,R) for (int i = L; i > R; i--)
#define rloope(i,L,R) for (int i = L; i >= R; i--)
#define nl cout<<'\n'



//misc
#define sz(x) ((int)((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL) 
#define checkbit(n,b) ( (n >> b) & 1)
#define test int _T_=1;if(testcase){cin>>_T_;}while(_T_--)



//vector
#define lastEle(vec) vec[vec.size()-1]
#define all(ve) ve.begin(),ve.end()
#define rall(x) x.rbegin(),x.rend()
#define fi first
#define se second



template<typename T>inline T mmod(T a,T b,T mod){return ((a%mod)*(b%mod))%mod;}
template<typename T>inline T smod(T a,T b,T mod){return ((a%mod)+(b%mod))%mod;}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.fi>>a.se;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

ll lcm(ll a,ll b){return (max(a,b)/__gcd(a,b))*min(a,b);} 

// MAIN
void solve();
int main(){
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
    fast;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    test {
        solve();
    }
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cerr << "\nElapsed Time: " << elapsed_time << "ms\n";
    return 0;
}


// SOLVE 

void solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	ll mn;
	if(x >= 0) {
		mn = min(x/d,k);
		k -= mn;
		x = x - (mn*d);
		x = x - (d*(k%2!=0));
	}else{
		mn = min(abs(x)/d,k);
		k -= mn;
		x = x + (mn*d);
		x = x + (d*(k%2!=0));		
	}
	cout << abs(x) << '\n';
}



Measured memory_bytes: 3648
n, tl = [int(x) for x in input().split()]

temp_list = []
for _ in range(n):
    c, t = [int(x) for x in input().split()]
    if t <= tl:
        temp_list.append(c)
temp_list.sort()
if len(temp_list) == 0:
    ans = "TLE"
else:
    ans = temp_list[0]
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,int> p;
int main(){
    int n,ans=0;
    cin>>n;
    int num=1;
    for(int i=1;i<=n;i++){
        if(i%10==0) continue;
        if(i>num*10) num*=10;
        int x=i%10;
        int y=i/num;
        p[{x,y}]++;
    }
    for(auto t:p){
        int x=t.first.first,y=t.first.second;
        ans+=t.second*p[{y,x}];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
vs = list(map(int, input().split()))

eq_lis = []
odd_lis = []
for i in range(n):
    if i %2 ==0:
        eq_lis.append(vs[i])
    else:
        odd_lis.append(vs[i])
        
a = Counter(eq_lis)
b = Counter(odd_lis)
a_val = list(a.values())
b_val = list(b.values())
a_max = max(a_val)
b_max = max(b_val)

a_sorted = sorted(a.items(), key= lambda x:x[1])
b_sorted = sorted(b.items(), key= lambda x:x[1])

if a_sorted[-1][0] == b_sorted[-1][0]:
    if len(a_sorted) == 1 and len(b_sorted) == 1:
        print(n-a_max)
    elif len(a_sorted)==1 and len(b_sorted) >1:
        print(n-a_max-b_sorted[-2][1])
    elif len(a_sorted)>1 and len(b_sorted) ==1:
        print(n-b_max-a_sorted[-2][1])
    else:
        if b_sorted[-2][1] >= a_sorted[-2][1]:
            print(n-a_max-b_sorted[-2][1])
        else:
            print(n-b_max-a_sorted[-2][1])    
else:
    print(n-a_max-b_max)

Measured memory_bytes: 28232
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
    } else {
        // D = I - 100*(10-N)
        cout << r + 100*(10-n) << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;
ll n,k;
vector<ll>vec;
vector<ll>::iterator it;
int main(){
	scanf("%lld%lld",&n,&k);
	if((k+k+n+n-1)*(n+n)/2>(k+n+n+k+n+n+n-1)*n/2)return printf("-1"),0;
	int up=(n+1)>>1;
	for(register int i=0;i<up;i++)printf("%lld %lld %lld\n",k+i,k+n+n-up+i,k+n+n+(i<<1));
	for(register int i=up;i<n;i++)printf("%lld %lld %lld\n",k+i,k+n+i-up,k+n+n+((i-up)<<1)+1);
	return 0;
}

Measured memory_bytes: 2304
def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


if __name__ == '__main__':
    main()


Measured memory_bytes: 126208
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
ll c[10][10];
void wf(int n){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(c[i][k]==INF)continue;
            for(int j=0;j<n;j++){
                if(c[k][j]==INF)continue;
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
}
int main(void){
    int h,w;
    cin>>h>>w;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>c[i][j];
        }
    }
    int a[201][201];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    wf(10);
    ll sum=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]!=1&&a[i][j]!=-1){
                sum+=c[a[i][j]][1];
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int L[100];

    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    int cnt = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(L[i] != L[j]){
                for(int k=j+1;k<N;k++){
                    if(L[i] != L[k] && L[j] != L[k]){
                        if(L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]){
                            cnt++;
                        }
                    }
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3512
a, b,c = map(int,input().split())
if(a==5 and b==7 and c==5):
    print("YES")
elif(a==5 and b==5 and c==7):
    print("YES")
elif(a==7 and b==5 and c==5):
    print("YES")
else:
    print("NO")
   
   
        



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

int main(){
    long long n, check, count = 0 , ans=0 ,a5=10;
    cin >> n;
    if(n%2!=0){
        cout << 0 << endl;
        return 0; 
    }
    while(n/a5!=0){
        ans+= n/a5;
        a5 *=5;
    }
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim A As Integer = NextInt()
        Dim B As Integer = NextInt()
        Dim K As Integer = NextInt()

        For i As Integer = 0 To K - 1
            If A + i <= B Then WriteLine(A + i)
        Next

        For j As Integer = K - 1 To 0 Step -1
            If A + K - 1 < B - j Then WriteLine(B - j)
        Next
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
N, A, B = list(map(int, input().split()))
S = input()

total, kaigai = 0, 0

for i in range(N):
    if S[i] == 'c':
        print('No')

    elif S[i] == 'b':
        if total < A+B and kaigai < B:
            print('Yes')
            total += 1
            kaigai += 1
        else:
            print('No')

    elif S[i] == 'a':
        if total < A+B:
            print('Yes')
            total += 1
        else:
            print('No')


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string s;

    cin >> n >> s;

    REP(i, s.size())
    {
        s[i] = (char)('A' + (s[i] - 'A' + n) % 26);
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256