akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var ABC = ReadSplitInt();
            var fiveCount = ABC.Count(x => x == 5);
            var sevenCount = ABC.Count(x => x == 7);
            YESOrNO(fiveCount == 2 && sevenCount == 1);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 13268
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
vector<string> len[N];
int nx[N][26], fin[N];
int cnt = 1, vis[N][26];

void ins(const string& s) {
  int cur = 1;
  trav(x, s) {
    if (!nx[cur][x-'a'])
      nx[cur][x-'a'] = ++cnt;
    cur = nx[cur][x-'a'];
  }
  fin[cur] = 1;
}

int dfs(int cur, int c, const string& s) {
  if (c >= sz(s)) return 0;
  int ret = 0;
  for (int j = 0; j < 26; j++) {
    // if (s == "xyxcba") {
    //   cerr << c << " " << j << " " << nx[cur][j] << " " << vis[sz(s)-1-c][j] << endl;
    // }
    if (nx[cur][j] && vis[sz(s)-1-c][j])
      ret += fin[nx[cur][j]];
  }
  if (nx[cur][s[c]-'a'])
    ret += dfs(nx[cur][s[c]-'a'], c+1, s);
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    len[sz(s)].push_back(s);
  }
  ll ans = 0;
  for (int i = 1; i <= 1000 * 1000; i++) if (sz(len[i])) {
    trav(x, len[i]) {
      for (int j = 0; j < sz(x); j++)
        for (int k = 0; k < 26; k++)
          vis[j][k] = 0;
      for (int j = 0; j < sz(x); j++) {
        if (j) for (int k = 0; k < 26; k++)
          vis[j][k] = vis[j-1][k];
        vis[j][x[j]-'a'] = 1;
      }
      // query
      reverse(all(x));
      ans += dfs(1, 0, x);
      // cout << x << " " << ans << endl;
    }
    trav(x, len[i]) {
      ins(x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 227052
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

ll powmod(ll x, ll n, ll m = MOD) {
    ll ans = 1;
    while(n) {
        if(n & 1) {
            ans = ans * x % m;
        }
        x = x * x % m;
        n >>= 1;
    }
    return ans;
}
inline ll invmod(ll x, ll m = MOD) {
    return powmod(x, m - 2);
}

const int N = 11111;
int a[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    map<int, int> pff;
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
        int x = a[i];
        map<int, int> pf;
        for(int d = 2; d * d <= x; d++) {
            while(x % d == 0) {
                pf[d]++;
                x /= d;
            }
        }
        if(x > 1) {
            pf[x]++;
        }
        rall(p, pf) {
            int cur = pff[p.fi];
            pff[p.fi] = max(cur, p.se);
        }
    }
    int mult = 1;
    rall(p, pff) {
        rep(i, 1, p.se) {
            mult = mult * p.fi % MOD;
        }
    }
    int ans = 0;
    rep(i, 1, n) {
        ans = ans + mult * invmod(a[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N,ans;
  ans =0;
  cin>>N;
  vector<int> a(N),b(N),c(N-1);
  for(int i=0;i<N;i++){
    cin>>a[i];
    a[i]--;
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  for(int i=0;i<N-1;i++){
    cin>>c[i];
  }
  for(int i=0;i<N-1;i++){
    ans+=b[a[i]];
    if(a[i+1]==a[i]+1){
      ans+=c[a[i]];
    }
  }
  ans+=b[a[N-1]];
  cout<<ans<<endl;
  return 0;
}

  


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll a;
	ll b1, b2;
	scanf("%lld %lld.%lld", &a, &b1, &b2);
	ll b=b1*100+b2;
	cout<<(a*b/100ll)<<endl;
    return 0;
}


Measured memory_bytes: 3692
w, h, n = map(int, input().split())
z = [input().split() for i in range(n)]
w = list(range(w+1))
h = list(range(h+1))
for i in range(n):
    if z[i][2] == '1':
        w = [j for j in w if j >= int(z[i][0])]
    elif z[i][2] == '2':
        w = [j for j in w if j <= int(z[i][0])]
    elif z[i][2] == '3':
        h = [j for j in h if j >= int(z[i][1])]
    elif z[i][2] == '4':
        h = [j for j in h if j <= int(z[i][1])]
if w == [] or h == []:
    print(0)
else:
    dh = max(h)-min(h)
    dw = max(w)-min(w)
    print(dh * dw)

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

int main(){
	string jud; cin >> jud;
	int n; cin >> n;
	vector<string> t(n);
	rep(i,n){
		cin >> t[i];
		t[i] += t[i];
	}

	ll ans = 0;
	rep(i,n){
		rep(j,10){
			string jud2 = t[i].substr(j,jud.size());

			if(jud == jud2){
				ans++;
				break;
			}

		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 3172
'use strict';
var NS = {};
function addProps(ns) {
    var isBrowser = function() {
        return typeof window !== 'undefined';
    }
    ns.isBrowser = isBrowser;
    
    var isNodejs = function() {
        return ! isBrowser();
    }
    ns.isNodejs = isNodejs;
    
    if (isBrowser()) {
        var getHtmlEncoded = function(string0) {
            return String(string0)
                    .replace(/&/g, '&amp;')
                    .replace(/"/g, '&quot;')
                    .replace(/'/g, '&#39;')
                    .replace(/</g, '&lt;')
                    .replace(/>/g, '&gt;');
        }
        ns.getHtmlEncoded = getHtmlEncoded;
        
        var outputCode = function() {
            document.getElementById('code').innerHTML = '<pre><code>' + getHtmlEncoded(addProps) + '</code></pre>';
        }
        ns.outputCode = outputCode;
    }
    
    var getInput = function() {
        var inputLines = [];
        if (isBrowser()) {
            var html = document.getElementById('input').innerHTML;
            inputLines = html.split('<br>');
        }
        if (isNodejs()) {
            inputLines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
        }
        return inputLines;
    }
    
    var doOutput = function(outputLines) {
        if (isBrowser()) {
            document.getElementById('output').innerHTML = outputLines.map(getHtmlEncoded).join('<br>\n');
        }
        if (isNodejs()) {
            for (var i = 0; i < outputLines.length; i++) {
                console.log(outputLines[i]);
            }
        }
    }
    ns.doOutput = doOutput;
    
    var getNthPower = function(r, n) {
        var power = 1;
        for (var i = 0; i < n; i++) {
            power *= r;
        }
        return power;
    }
    
    var main = function() {
        var inputLines = getInput();
        var n = Number(inputLines[0]);
        var n1 = getNthPower(n, 3);
        doOutput([n1]);
    }
    ns.main = main;
}
addProps(NS);
if (NS.isBrowser()) {
    window.onload = function() {
        NS.outputCode();
    }
}
NS.main();

Measured memory_bytes: 7644
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

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

	int i, n, cnt1 = 0, cnt2 = 0, tmp;

	cin >> n;
	vector<int> vc, vc2, vc3, vc4;

	for (i = 1; i <= n; i++)
	{
		vc.push_back(i);
		vc2.push_back(i);
	}

	for (i = 0; i < n; i++)
	{
		cin >> tmp;

		vc3.push_back(tmp);
	}

	for (i = 0; i < n; i++)
	{
		cin >> tmp;

		vc4.push_back(tmp);
	}

	do
	{
		for (i = 0; i < n; i++)
		{
			if (vc[i] != vc3[i])
				break;
		}

		if (i != n)
			cnt1++;
		else
			break;
	} while (next_permutation(vc.begin(), vc.end()));

	do
	{
		for (i = 0; i < n; i++)
		{
			if (vc2[i] != vc4[i])
				break;
		}

		if (i != n)
			cnt2++;
		else
			break;
	} while (next_permutation(vc2.begin(), vc2.end()));
	
	cout << abs(cnt1 - cnt2) << '\n';

	return 0;
}

Measured memory_bytes: 256
//
// 二部グラフ判定 (by DFS)
//
// cf.
//   深さ優先探索 (DFS) による各種グラフ探索特集 (執筆予定)
//
//
// verified:
//   ARC 099 E - Independence
//     https://beta.atcoder.jp/contests/arc099/tasks/arc099_c
//


/*
    二部グラフかどうかを判定する
    また、各連結成分ごとに、(左ノード数, 右ノード数) を求める
 */


#include <iostream>
#include <vector>
using namespace std;


// nums[i] := i 番目の連結成分の {左ノード数, 右ノード数}, 「dir = 1: 左、-1: 右」
using pint = pair<int,int>;
using Graph = vector<vector<int> >;

bool dfs(const Graph &G, int v, int vdir, pint &num, vector<int> &dir) {
    bool res = true;
    dir[v] = vdir;
    if (vdir == 1) ++num.first;
    else if (vdir == -1) ++num.second;
    for (auto nv : G[v]) {
        if (dir[nv] == 0) {
            if (!dfs(G, nv, -vdir, num, dir)) res = false;
        }
        else if (dir[nv] != -vdir) res = false;
    }
    return res;
}

bool isbipartite(const Graph &G, vector<pint> &nums) {
    bool res = true;
    int N = (int)G.size();
    vector<int> dir(N, 0);
    for (int v = 0; v < N; ++v) {
        if (dir[v] != 0) continue;
        pint num = {0, 0};
        if (!dfs(G, v, 1, num, dir)) res = false;
        nums.push_back(num);
    }
    return res;
}


int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int> > isexistedge(N, vector<int>(N, 1));
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b; --a, --b;
        isexistedge[a][b] = isexistedge[b][a] = 0;
    }
    Graph G(N);
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j)
        if (isexistedge[i][j] && i != j)
            G[i].push_back(j);
    
    // 二部グラフの構成
    vector<pint> nums;
    if (!isbipartite(G, nums)) {
        cout << -1 << endl;
        return 0;
    }
    
    // ナップサック DP
    vector<int> dp(N+10, 0);
    dp[0] = 1;
    for (int i = 0; i < (int)nums.size(); ++i) {
        for (int j = N; j >= 0; --j) {
            if (!dp[j]) continue;
            dp[j] = 0;
            dp[j + nums[i].first] = 1;
            dp[j + nums[i].second] = 1;
        }
    }
    
    long long a = -1;
    long long mindif = N;
    for (int i = 0; i <= N; ++i) {
        if (!dp[i]) continue;
        if (mindif > abs(i - N/2)) mindif = abs(i - N/2), a = i;
    }
    long long b = N-a;
    cout << a*(a-1)/2 + b*(b-1)/2 << endl;
}

Measured memory_bytes: 5120
package main

import "fmt"

func main() {
	// Code for A - Red or Not
	var a int
	var s string
	fmt.Scanf("%d", &a)
	fmt.Scanf("%s", &s)

	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}


Measured memory_bytes: 1832
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dp[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dp[n][n] = 1;}
	else if (r == 0) {return dp[n][0] = 1;}
	else if (r == 1) {return dp[n][1]=n;}
	else {dp[n][r]=dp[n - 1][r - 1] % 1000000007 + dp[n - 1][r] % 1000000007;
	return dp[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
int main() {
	int a[3][3];
	int c[3][3];
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> a[i][j];
			c[i][j] = 0;
		}
	}
	int N;
	cin >> N;
	int b[12];
	for (int i = 0;i < N;i++) {
		cin >> b[i];
	}
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < N;k++) {
				if (b[k] == a[i][j]) {
					c[i][j] = 1;break;
				}
			}
		}
	}
	int t = 1;
	for (int i = 0;i < 3;i++) {
		if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1) {
			cout << "Yes" << endl;t = 0;break;
		}
		else if (c[0][i] == 1 && c[1][i] == 1 && c[2][i] == 1) {
			cout << "Yes" << endl;t = 0;break;
		}
	}
		if (t == 1 && c[0][0] == 1 && c[1][1] == 1 && c[2][2] == 1) {
			cout << "Yes" << endl;t = 0;
		}else if (t == 1 && c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1) {
			cout << "Yes" << endl;t = 0;
		}
		if (t == 1) {
			cout << "No" << endl;
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

lli maxPoints(int n, tuple<lli, lli, lli> *a) {
	lli dp[n][3];
	dp[0][0] = get<0>(a[0]);
	dp[0][1] = get<1>(a[0]);
	dp[0][2] = get<2>(a[0]);
	Fo(i, 1, n) {
		dp[i][0] = get<0>(a[i])+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = get<1>(a[i])+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = get<2>(a[i])+max(dp[i-1][0], dp[i-1][1]);
	}
	return max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	tuple<lli, lli, lli> a[n];
	fo(i, n) {
		lli a1, a2, a3;
		cin >> a1 >> a2 >> a3;
		a[i] = mt(a1, a2, a3);
	}

	lli ans = maxPoints(n, a);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void) {
	int x, xx,a;
	scanf("%d", &x);
	scanf("%d", &xx);
	if (x > xx) {
		a = x - xx;
	}
	else if (x < xx) {
		a = xx - x;
	}
	else {
		a = x - xx;
	}
	printf("%d\n", a);
	return 0;
}


Measured memory_bytes: 2752
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String c1 = scan.next();
        String c2 = scan.next();
        String c3 = scan.next();
        System.out.println("" + c1.charAt(0) + c2.charAt(1) + c3.charAt(2));
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sc(x) scanf(" %c",&x)
#define sll(x) scanf("%I64d",&x)
#define f(i,n,k) for(int i=k;i<n;i++)
#define pi(x) printf("%d ",x);
#define pll(x) printf("%I64d ",x);
int main()
{
    ll x;
    cin>>x;
    ll k,t,t1;
    k=floor(x/500);
    k*=1000;
    t=x%500;
    t1=floor(t/5);
    t1*=5;
    cout<<k+t1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
using namespace std;
using ii = pair<long, long>;

struct P {
    int x, y;
};

int r, c, n;

long encode(P p) {
    int h = max(r, c);
    if (p.x == 0) {
        return 1 + p.y;
    } else if (p.y == c) {
        return 1 + h + p.x;
    } else if (p.x == r) {
        return 1 + 3 * h - p.y;
    } else {
        return 1 + 4 * h - p.x;
    }
}

int main() {
    cin >> r >> c >> n;
    vector<ii> border;
    auto onBorder = [](int a, int b) {
        return (a == 0 || a == r) || (b == 0 || b == c);
    };
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (onBorder(x1, y1) && onBorder(x2, y2)) {
            long e1 = encode({x1, y1}), e2 = encode({x2, y2});
            border.push_back(ii(min(e1, e2), -min(e1, e2)));
            border.push_back(ii(max(e1, e2), min(e1, e2)));
        }
    }
    if (border.empty()) {
        cout << "YES" << endl;
        return 0;
    }
    sort(border.begin(), border.end());
    
    stack<long> st;
    for (ii p: border) {
        if (p.second < 0) {
            st.push(p.second);
        } else {
            assert(!st.empty());
            long t = st.top();
            st.pop();
            if (p.second + t) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 6384
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	a := ""
	for _, c := range s {
		if c == 'B' {
			if r := len(a) - 1; r >= 0 {
				a = a[:r]
			}
		} else {
			a = a + string(c)
		}
	}
	fmt.Println(a)
}


Measured memory_bytes: 512
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int, input().split())
a = [None]*n
b = [None]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())

l = k.bit_length()
def sub(k):
    ans = 0
    for num,val in zip(a,b):
        if (k|num) == k:
            ans += val
    return ans
ans = sub(k)
for i in range(l):
    # i桁が1のとき、そこを0にしてそれ以降を1にする
    if k>>i&1:
        kk = ((k>>i)-1)*(1<<i) + (1<<i) - 1
        val = sub(kk)
        ans = max(ans, val)

print(ans)

Measured memory_bytes: 78808
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;
typedef pair<Point, double> Circle;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

int intersection(Circle c1, Circle c2){
    double dist = abs(c1.first - c2.first);
    if(c1.second + c2.second < dist) return 4;
    if(equals(c1.second + c2.second, dist)) return 3;
    if(abs(c1.second - c2.second) < dist && dist < c1.second + c2.second) return 2;
    if(equals(abs(c1.second - c2.second), dist)) return 1;
    else return 0;
}

int main(){
    double c1x, c1y, c1r; cin>>c1x>>c1y>>c1r;
    double c2x, c2y, c2r; cin>>c2x>>c2y>>c2r;
    Circle c1 = {Point(c1x, c1y), c1r};
    Circle c2 = {Point(c2x, c2y), c2r};

    cout << intersection(c1, c2) << endl;
}


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

int main()
{
    string s;
    cin >> s;
    int len = 0;
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
        {
            len++;
            ans = max(ans, len);
        }
        else
        {
            len = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
lst = list(input().upper())
max_count = 0
if "R" in lst:
    slicedList = lst[lst.index("R")+1:]
    
    counter = 0
    for i in lst:
        if i == "R":
            counter += 1
            if counter > max_count:
                max_count = counter
        else:
            counter = 0
                
print(max_count)     

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

using namespace std;

#define ff first
#define ss second
#define mp make_pair

long long vet[100];

vector < pair<int, int> > v;

int main () {

        int n;
        scanf("%d", &n);

        int m;
        int rem = -1;

        for (int i = 0; i < n; i++) {
                scanf("%lld", &vet[i]);

                if (i) {
                        while (vet[i - 1] > vet[i]) {
                                if (vet[i - 1] > 0 && vet[i] >= 0) {
                                        vet[i] += vet[i - 1];
                                        m++;
                                        v.push_back(mp(i, i + 1));
                                } else if (vet[i - 1] > 0) {
                                        if (abs(vet[i- 1]) > abs(vet[i])) {
                                                vet[i] += vet[i - 1];
                                                m++;
                                                v.push_back(mp(i, i + 1));
                                        } else {
                                                rem = i;
                                                break;
                                        }
                                } else {
                                        rem = i;
                                        break;
                                }
                        }
                }
        }

        if (rem != -1) {
                for (int i = rem; i >= 1; i--) {
                        while (vet[i -1] > vet[i]) {
                                m++;
                                vet[i - 1] += vet[i];
                                v.push_back(mp(i + 1, i));
                        }
                }
        }

        printf("%d\n", m);

        for (int i = 0; i < m; i++) {
                printf("%d %d\n", v[i].ff, v[i].ss);
        }

        return 0;

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

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

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

using namespace std;

class BGuidebook {
public:
    int N;
    vector<tuple<string, int, int>> r;

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        REP(i, N) {
            string s; int x;
            in >> s >> x;
            r.emplace_back(s, -x, i+1);
        }
        sort(ALL(r));
        REP(i, N) {
            OUT(get<2>(r[i]));
        }
    }
};


int main() {
    BGuidebook solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private final static Main main = new Main();

    public static void main(String[] args) {
        main.contest();
    }

    private void contest() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() * 2;
        int[] list = new int[n];
        for (int i=0; i<n; ++i) {
            list[i] = sc.nextInt();
        }
        Arrays.sort(list);
        int sum = 0;
        for(int i=0; i<n; i+=2) {
            sum += list[i];
        }
        System.out.println(sum);
    }
}


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

int main(){
    int A, B, C, X, i, j, k;
    int ans = 0;

    cin >> A >> B >> C >> X;
    
    for (i=0; i<A+1; i++){
        for(j=0; j<B+1; j++){
            for(k=0; k<C+1; k++){
            if (X == 500*i + 100*j + 50*k)
                ans++;
            }
        }
    }
    
    cout << ans << '\n';

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();

        long sum = 0;
        if (a < k) {
            sum = a;
            if (a+b < k) {
                sum -= k-(a+b);
            }
        } else {
            sum = k;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27084
N = list(map(int,input()))
K = int(input())

def f(n,k):
  if len(n) == 1:
    if k == 1:
      return n[0]
    else:
      return 0
  else:
    r = n[-1]
    m = n[:-1]
    m2 = m.copy()
    m2[-1] = m2[-1] - 1
    for i in range(len(m)):
      if m2[-i] < 0:
        m2[-i] += 10
        m2[-i-1] = m2[-i-1] - 1
    if k == 1:
      m = n[:-1]
      return f(m,1) + 9
    else:
      return f(m,k) + f(m,k-1) * r + f(m2,k-1) * (9-r)
    
print(f(N,K))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 2005;

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

LL sumh_l[SIZE][SIZE];
LL sumh_r[SIZE][SIZE];
LL sumw_u[SIZE][SIZE];
LL sumw_d[SIZE][SIZE];
int grid[SIZE][SIZE];

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

    int h, w;
    cin >> h >> w;
    for( int i = 0; i < h; ++i ) {
        for( int j = 0; j < w; ++j ) {
            char c;
            cin >> c;
            if( c != '#' ) {
                grid[i][j] = 1;

            }
        }
    }

    for( int i = 0; i < h; ++i ) {
        for( int l = 0, r = w - 1; l < w; ++l, --r ) {
            if( !grid[i][l] ) sumh_l[i][l] = 0;
            else if( l != 0 ) sumh_l[i][l] = sumh_l[i][l - 1] + 1;
            else sumh_l[i][l] = 1;
            if( !grid[i][r] ) sumh_r[i][r] = 0;
            else if( r != w - 1 ) sumh_r[i][r] = sumh_r[i][r + 1] + 1;
            else sumh_r[i][r] = 1;

        }
    }

    for( int i = 0; i < w; ++i ) {
        for( int u = 0, d = h - 1; u < h; ++u, --d ) {
            if( !grid[u][i] ) sumw_u[u][i] = 0;
            else if( u != 0 ) sumw_u[u][i] = sumw_u[u - 1][i] + 1;
            else sumw_u[u][i] = 1;
            if( !grid[d][i] ) sumw_d[d][i] = 0;
            else if( d != h - 1 ) sumw_d[d][i] = sumw_d[d + 1][i] + 1;
            else sumw_d[d][i] = 1;

        }
    }

    LL res = 0;
    for( int i = 0; i < h; ++i ) {
        for( int j = 0; j < w; ++j ) {
            if( grid[i][j] ) {
                res = max( res, 
                        sumh_l[i][j] + sumh_r[i][j] + sumw_u[i][j] + sumw_d[i][j] - 3 );

            }
        }
    }
    cout << res << endl;


    return 0;
}



Measured memory_bytes: 141568
def kipp(i,f):
    if i == 3:
        if eval(f) == 7:
            print(f+"=7")
            exit()
    else:
        kipp(i+1,f+"+"+s[i+1])
        kipp(i+1,f+"-"+s[i+1])

s = input()
kipp(0,s[0])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 112000000012345678LL
#define MOD 1000000007

vector<pair<long,long>> dijkstra(const vector<vector<pair<int,long>>> &vec, int from){
  using P = pair<long,int>;
  vector<pair<long,long>> d(vec.size(), {INF, 0});
  priority_queue<P, vector<P>, greater<P>> pq;
  d[from] = {0, 1};
  pq.push(mp(0,from));
  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int v = p.second;
    long dd = p.first;
    if(d[v].first < dd) continue;
    for(auto to : vec[v]){
      long nd = dd + to.second;
      int ni = to.first;
      if(d[ni].fi > nd){
        d[ni] = {nd, d[v].second};
        pq.push({nd, ni});
      } else if(d[ni].fi == nd){
        d[ni].second += d[v].second;
        d[ni].second %= MOD;
      }
    }
  }
  return d;
}

int main(){
  int n,m;
  cin>>n>>m;
  int s,t;
  cin>>s>>t;
  s--;t--;
  vector<vector<pair<int,long>>> g(n);
  vector<int> x(m),y(m),z(m);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g[a].pb({b,c});
    g[b].pb({a,c});
    x[i] = a;
    y[i] = b;
    z[i] = c;
  }

  auto ds = dijkstra(g, s);
  auto dt = dijkstra(g, t);

  long ans = (ds[t].se * dt[s].se) %MOD;
  assert(ds[t] == dt[s]);

  vector<bool> good(n, false);
  rep(i,n){
    if(ds[i].fi + dt[i].fi == ds[t].fi){
      good[i] = true;
      if(ds[i].fi == dt[i].fi){
        long tmp = (ds[i].se * dt[i].se) %MOD;
        ans -= (tmp * tmp) %MOD;
        ans = (ans + MOD) %MOD;
      }
    }
  }

  rep(i,m) if(good[x[i]] && good[y[i]]){
    int u = x[i], v = y[i];
    if( max(min(ds[u].fi, ds[v].fi), min(dt[u].fi, dt[v].fi)) >= min(max(ds[u].fi, ds[v].fi), max(dt[u].fi, dt[v].fi)) ) continue;
    if(min(ds[u].fi, dt[u].fi) + min(ds[v].fi, dt[v].fi) + z[i] != ds[t].fi) continue;
    long tmp;
    if (ds[u].fi < ds[v].fi){
      // s - u - v - t
      tmp = (ds[u].se * dt[v].se) %MOD;
    } else {
      // s - v - u - t
      tmp =  (ds[v].se * dt[u].se) %MOD;
    }
    ans -= (tmp * tmp) %MOD;
    ans = (ans + MOD) %MOD;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    ll a,b;
    ll v,w;
    cin>>a>>v>>b>>w;

    ll t;
    cin>>t;

    ll d=abs(a-b);
    ll c=(v-w)*t;
    if(d<=c)cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 3636
n = int(input())
nums = list(map(int,input().split()))

s1 = (sum(nums) - nums[0]) % (10**9 + 7)
sums = [s1]
for i in range(1,n):
  s = sums[i-1] - nums[i]
  s %= 10**9 + 7
  sums.append(s)

ans = 0
for i in range(n):
  temp = nums[i] * sums[i] % (10**9 + 7)
  ans += temp

print(ans%(10**9+7))

Measured memory_bytes: 31404
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
L = LIR(m)
for i in range(m):
    L[i] = [i, str(L[i][0]).zfill(6), L[i][1]]


L.sort(key=lambda x:x[1:])
cnt = 1
L[0][2] = str(1).zfill(6)
for i in range(1, m):
    if L[i][1] != L[i-1][1]:
        cnt = 1
    else:
        cnt += 1
    L[i][2] = str(cnt).zfill(6)



L.sort(key=lambda x:x[0])
for i in L:
    print(i[1] + i[2])

Measured memory_bytes: 104924
#include<bits/stdc++.h>
#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;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    sort(v.rbegin(),v.rend());
    ll sum = v[0];
    int cnt = 1;
    int id = 1;
    for(int i = 2; i < n; i++){
        if(cnt%3 == 0){
            id++;
            cnt = 1;
        }
        sum += v[id];
        cnt++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4852
def main():
    X = input()
    delcnt = 0
    delans = 0
    for i in range(len(X)):
        if X[i]=='S':
            delcnt += 1
        if X[i]=='T' and delcnt>0:
            delans +=2
            delcnt -=1
    print(len(X)-delans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3500
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if(a + b >= c) System.out.println("Yes");
        else System.out.println("No");

        scan.close();
    
    }

}

Measured memory_bytes: 21844
/*
Author : N_o_o_B
Created : April 22 2020 22:47:05 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    string s,t;
    cin >> s >> t;
    int n = sz(s);
    s += s;
    bool ok = 0;
    fori(i,n){
        ok |= (s.substr(i,n)==t);
    }
    cout << (ok ? "Yes":"No") << endl;


    time_taken();
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ans = [-1]*(n-1)
g = Array.new(n+1){[]}
(n-1).times do |i|
  a,b = gets.split.map(&:to_i)
  g[a] << [b,i]
  g[b] << [a,i]
end

color = 1
g.each do |a|
  color = [a.length, color].max
end

visited = [false]*(n+1)
visited[1] = true
que = [1]
while !que.empty?
  v = que.shift
  m = g[v].length*2
  used = [false]*(m+1)
  g[v].each do |u,i|
    if ans[i] != -1
      used[ans[i]] = true if ans[i] <= m
    else
      que << u if !visited[u]
      visited[u] = true
    end
  end
  #p [v, used]
  c = 1
  while !g[v].empty?
    t = g[v].shift
    next if ans[t[1]] != -1
    c += 1 while used[c]
    ans[t[1]] = c
    used[c] = true
    #p [v, t, c]
  end
end
p color
puts ans.join("\n")

Measured memory_bytes: 31996
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef vector<vector<int>> Graph;

const int INF = 1e9;
const long long LINF = 1e18;

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

    Graph G(N, vector<int>());

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    for (size_t i = 0; i < G[0].size(); i++) {
        int x = G[0][i];
        for (size_t j = 0; j < G[x].size(); j++) {
            if (G[x][j] == N - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
        
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 12016
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1e18;

ll dp[101][4][4][4];

bool ng(int a, int b, int c){
    return (a==1 && b==2 && c==3);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    dp[0][0][0][0] = 1;
    for(int i = 0; i < N; i++){
        for(int a = 0; a < 4; a++){
            for(int b = 0; b < 4; b++){
                for(int c = 0; c < 4; c++){
                    for(int d = 0; d < 4; d++){
                        if(ng(b,c,d)||ng(c,b,d)||ng(b,d,c)) continue;
                        if(ng(a,c,d)||ng(a,b,d)) continue;
                        dp[i+1][b][c][d] += dp[i][a][b][c];
                        dp[i+1][b][c][d] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int a = 0; a < 4; a++){
        for(int b = 0; b < 4; b++){
            for(int c = 0; c < 4; c++){
                ans += dp[N][c][b][a];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll dp[25][1<<22];

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n;cin>>n;
  VV<int> v(n,V<int>(n));

  rep(i,0,n)rep(j,0,n){
      cin>>v[i][j];
  }

  dp[0][0]=1;
  rep(i,0,n){
      rep(j,0,(1<<n)){
         if(__builtin_popcount(j)!=i)continue;
         
         rep(k,0,21){
             if((j&(1<<k))==0 && v[i][k]){
                 (dp[i+1][j+(1<<k)]+=dp[i][j])%=mod;
             }
         }
      }
  }
  cout<<dp[n][(1<<n) -1]<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 323840
def get
  gets.chomp.split(" ").map(&:to_i)
end

n,m = get
input = m.times.map{get.sort}

task = Hash.new 0

input.each do |t|
  task[t] += 1
end

node = Hash.new 0

task = task.select{|k,v| v.odd?}
task.each do |k,v|
  node[k[0]] += 1
  node[k[1]] += 1
end

puts node.all?{|k,v| v.even?} ? :YES : :NO

Measured memory_bytes: 28156