akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
typedef vector<int> vint;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int L, R;
    cin >> L >> R;
    int mn = INF;
    R = min(R, L + 673);
    for (ll i = L; i < R+1; ++i) {
        for (ll j = i+1; j < R+1; ++j) {
            mn = min(mn, (int)(i*j % 2019));
        }
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N+1][D+1];

        int c = 0;
        int m = 0 ;
        double sqrt = 0;

        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= D; j++){
                X[i][j] = sc.nextInt();
            }
        }

        for(int i = 1; i <= N; i++){
           for(int j = 1; j <= N; j++){
               if(i == j){
                    break;
               }
               for(int k = 1; k <= D; k++){
                    m += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
               }  

                sqrt = Math.sqrt(m);
                if(sqrt == (int)sqrt){
                    c++;
                }
                
                m = 0;
            }
        }


        System.out.println(c);
        
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> vec;

int main()
{
    int N, M;
    cin >> N >> M;
    vec a(N); //各スイッチがどの電球につながっているか
    rep(i, M) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            s--;
            a[s] |= 1<<i; //<<は左シフト
        }
    }
    int p = 0;
    rep(i, M) {
        int x;
        cin >> x;
        p |= x<<i; //全ての電球が点灯するようなスイッチon/offの並び
    }

    int ans = 0;

    for (int s=0; s<(1<<N); s++) {
        int t = 0;
        rep(i, N) {
            if (s>>i & 1) { //i+1ビット目が立ってるか、すなわちスイッチi+1番目がonか
                t ^= a[i]; //^はXOR演算子 tは点灯する電球の並び
            }
        }

        if (t == p) {
            ans++;
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int a, b;
    cin >> a >> b;

    if (a <= 0 and b >= 0) cout << "Zero\n";
    else if ((a > 0 and b > 0) or (min(0, b) - min(0, a)) % 2 != 0) cout << "Positive\n";
    else cout << "Negative\n";
}

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr int MAX = 1e5 + 5, MAXL = 18;

using T = std::tuple<int, int, int>; //to,color,dis

int n;

std::vector<T> g[MAX];
int par[MAXL][MAX];
int dep[MAX];
int ans[MAX];
using S = std::tuple<int, int, int, int>;
std::vector<S> qrs[MAX]; //1:leaforlca 2:Qidx 3:clr 4:y

bool used[MAX];
void dfs1(int x)
{

    used[x] = 1;

    for (auto y : g[x])
    {
        int t;
        std::tie(t, std::ignore, std::ignore) = y;
        if (!used[t])
        {
            par[0][t] = x;
            dep[t] = dep[x] + 1;
            dfs1(t);
        }
    }
}

int getp(int x, int d)
{
    if (d == 0)
        return x;

    int s = 1;

    for (int i = 0; i < MAXL; ++i)
    {
        if (s & d)
            x = par[i][x];
        s *= 2;
    }
    return x;
}

int lca(int u, int v)
{
    if (dep[u] < dep[v])
        std::swap(u, v);

    if (dep[u] > dep[v])
        u = getp(u, dep[u] - dep[v]);

    int lb = -1, ub = n - 1;

    while (ub - lb > 1)
    {
        int mid = (lb + ub) / 2;

        if (getp(u, mid) == getp(v, mid))
            ub = mid;
        else
        {
            lb = mid;
        }
    }
    return getp(u, ub);
}

int cs[MAX], cd[MAX];
int alldis = 0;

void dfs2(int v)
{
    if (used[v])
        return;
    used[v] = 1;
    for (auto s : qrs[v])
    {
        int k, idx, clr, y;
        std::tie(k, idx, clr, y) = s;
        ans[idx] += k * (alldis + y * cs[clr] - cd[clr]);
    }
    for (auto t : g[v])
    {
        int to, clr, dis;
        std::tie(to, clr, dis) = t;
        ++cs[clr];
        cd[clr] += dis;
        alldis += dis;
        dfs2(to);
        --cs[clr];
        cd[clr] -= dis;
        alldis -= dis;
    }
}

int main()
{
    int q;

    std::cin >> n >> q;

    rep(i, n - 1)
    {
        int a, b, c, d;
        std::cin >> a >> b >> c >> d;
        g[a].emplace_back(b, c, d);
        g[b].emplace_back(a, c, d);
    }

    par[0][1] = 1;

    dfs1(1);

    for (int i = 1; i < MAXL; ++i)
    {
        for (int j = 1; j <= n; ++j)
            par[i][j] = par[i - 1][par[i - 1][j]];
    }

    rep(i, q)
    {
        int x, y, u, v;
        std::cin >> x >> y >> u >> v;
        qrs[u].emplace_back(1, i, x, y);
        qrs[v].emplace_back(1, i, x, y);
        qrs[lca(u, v)].emplace_back(-2, i, x, y);
    }

    //std::cerr << "DD" << std::endl;

    std::memset(used, 0, sizeof(used));
    dfs2(1);

    rep(i, q)
            std::cout
        << ans[i] << std::endl;

    std::cerr << "DD" << std::endl;
    /*int a, b;
    while (std::cin >> a >> b)
    {
        std::cerr << lca(a, b) << std::endl;
    }*/
    /*int a, b;
    while (std::cin >> a >> b)
    {
        std::cerr << getp(a, b) << std::endl;
    }*/
    /*for (int i = 1; i <= n; ++i)
        std::cerr << par[0][i] << ' ';
    std::cerr << std::endl;*/

    return 0;
}

Measured memory_bytes: 31040
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin>>str;
  for(int i=0;i<str.size()-1;i++){
    if(str[i]=='S'&&str[i+1]=='T'){
      str.erase(str.begin()+i);
      str.erase(str.begin()+i);
      if(i>0)
	i-=2;
      else
	i--;
    }
    //cout<<str<<endl;
    if(str.size()==0||str.size()==1)
      break;
  }
  cout<<str.size()<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  Int N = s.size();
  Int cnt = 0;
  Int ans = 0;
  for(Int i=0;i<N;i++){
    if(s[i] == 'g' && cnt) cnt--, ans++;
    else if(s[i] == 'p' && cnt) cnt--;
    else if(s[i] == 'g') cnt++;
    else if(s[i] == 'p') cnt++, ans--;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n&&n;) {
		vector<string> v(n);
		vector<char> c;
		rep(i, 0, n) {
			cin >> v[i];
			reverse(all(v[i]));
		}

		bool exist[128];
		memset(exist, 0, sizeof(exist));
		rep(j, 0, 20) {
			rep(i, 0, n) {
				if (v[i].size() <= j)continue;
				if (v[i][j] >= '0'&&v[i][j] <= '9')continue;
				if (exist[v[i][j]])continue;
				exist[v[i][j]] = true;
				c.push_back(v[i][j]);
			}
		}

		int mp[128];
		memset(mp, -1, sizeof(mp));
		rep(i, 0, 10)
			mp[i + '0'] = i;

		bool head[128];
		memset(head, 0, sizeof(head));
		rep(i, 0, n) {
			if (v[i].size() > 1) {
				head[v[i].back()] = true;
			}
		}

		char used[10];
		memset(used, 0, sizeof(used));
		function<int(int, int)> dfs = [&](int idx, int num) {
			int add = 0;
			rep(i, 0, 10) {
				int digit = add;
				add = 0;
				bool flag = false;
				rep(j, 0, n - 1) {
					if (v[j].size() <= i)continue;
					if (mp[v[j][i]] == -1) {
						flag = true;
						break;
					}
					digit += mp[v[j][i]];
				}
				if (flag)
					break;
				add += digit / 10;
				digit %= 10;
				if (v[n - 1].size() > i) {
					if (mp[v[n - 1][i]] == -1)
						break;
					if (digit != mp[v[n - 1][i]])
						return 0;
				}
				else {
					if (digit > 0 || add > 0)
						return 0;
					else
						break;
				}
			}
			if (c.size() > idx + 1) {
				int ret = 0;
				rep(i, 0, 10) {
					if (used[i])continue;
					if (i == 0 && head[c[idx + 1]])continue;
					used[i] = c[idx + 1];
					mp[c[idx + 1]] = i;
					ret += dfs(idx + 1, i);
					mp[c[idx + 1]] = -1;
					used[i] = 0;
				}
				return ret;
			}
			else {
				return 1;
			}
		};
		int ans = 0;
		rep(i, 0, 10) {
			if (used[i])continue;
			if (i == 0 && head[c[0]])continue;
			used[i] = c[0];
			mp[c[0]] = i;
			ans += dfs(0, i);
			mp[c[0]] = -1;
			used[i] = 0;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
const int MAX=100001;
int a[MAX]={},e[MAX]={};
void era(){
   for(int i=4;i<MAX;i+=2)
     e[i]=1;
   for(int i=3;i<MAX;i+=2){
      a[i-1]=a[i-2];
      if(!e[i]){
         a[i]=a[i-1]+(!e[(i+1)/2]); 
         for(int j=i+i;j<MAX;j+=i)
           if(!e[j])
             e[j]=1;
      }else{
         a[i]=a[i-1]; 
      } 
   } 
}
int main(){
int q,l,r;
cin>>q;
era ();
rep(i,q){
  cin>>l>>r;
   cout<<a[r]-a[l-1]<<endl;
}
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a = 1000000007;
		long ans = 1;
		if (Math.abs(n - m) == 1) {
			for (int i = 1; i <= n; i++) {
				ans = ans * i % a;
			}
			for (int i = 1; i <= m; i++) {
				ans = ans * i % a;
			}
			System.out.println(ans);
		} else if (Math.abs(n - m) == 0) {
			for (int i = 1; i <= n; i++) {
				ans = ans * i % a;
			}
			for (int i = 1; i <= m; i++) {
				ans = ans * i % a;
			}
			ans = (ans * 2) % a;
			System.out.println(ans);
		} else {
			System.out.println(0);
		}

	}
}


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

int main() {
	int n,c, mini = 10000000, maxi = -10000000;
	long int sum = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		mini = min(mini, c);
		maxi = max(maxi, c);
		sum += c;
	}
	printf("%d %d %ld\n", mini, maxi, sum);
}


Measured memory_bytes: 3216
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int n, a;
	scanf("%d%d", &n, &a);
	printf("%d\n", n * n - a);
	
	return 0;
}

Measured memory_bytes: 256
using System;

class ABC_165_C
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        string[] input2 = Console.ReadLine().Split(' ');
        int[] H = new int[N];
        int[] ans = new int[N];
        for (int i = 0; i < N; i++)
        {
            H[i] = int.Parse(input2[i]);
            ans[i] = 1;
        }

        for (int i = 0; i < M; i++)
        {
            string[] input3 = Console.ReadLine().Split(' ');
            int a = int.Parse(input3[0]);
            int b = int.Parse(input3[1]);

            if (H[a - 1] >= H[b - 1]) ans[b - 1] = 0;
            if (H[b - 1] >= H[a - 1]) ans[a - 1] = 0;
        }

        int count = 0;
        for (int i = 0; i < ans.Length; i++)
        {
            if (ans[i] == 1) count++;
        }

        Console.WriteLine(count);
    }
}

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

int gcd(int a, int b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
int main() {
  int a, b;
  cin >> a >> b;
  cout << (a+1) + (b+1) - (gcd(a,b)+1) << endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n,q;
    cin >> n >> q;
    vector<ll> s(n),t(n),x(n);
    using P = pair<ll, pair<ll,ll>>;
    vector<P> vp(n);
    rep(i,n){
        ll s_, t_, x_;
        cin >> s_ >> t_ >> x_;
        vp[i] = {x_, {s_, t_}};        
    }
    sort(all(vp));
    rep(i,n){
        s[i] = vp[i].second.first;
        t[i] = vp[i].second.second;
        x[i] = vp[i].first;
    }
    vector<ll> d(q);
    map<ll, int> mp;
    rep(i,q) {
        cin >> d[i];
        mp[-d[i]] = i;
    }

    vector<ll> res(q, -1);
    rep(i,n){
        auto itr = mp.upper_bound(x[i]-t[i]);
        vector<ll> kills;
        while (itr != mp.end()) {
            if (x[i]-s[i] < itr->first) break;

            kills.push_back(itr->first);
            res[itr->second] = x[i];
            ++itr;
        }
        for(ll kill : kills){
            mp.erase(kill);
        }
    }
    rep(i,q){
        cout << res[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 27408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b,x;cin>>a>>b>>x;
  ll adiv=(a-a%x)/x,bdiv=(b-b%x)/x;
  ll ans=bdiv-adiv;if(a%x==0) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n,i;
  cin>>n;
  double a[n];
  for(i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n-1;i++)
  {
    a[i]=(a[i]+a[i+1])/2.0;
    a[i+1]=a[i];
  }
  cout<<a[n-1];
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

struct UnionFind{
    vl p;
    vl rank;
    vl cnt;

    UnionFind(ll n){
        rank.resize(n,0);
        p.resize(n,0);
        cnt.resize(n,0);
        rep(i,n){
            p[i] = i;
            rank[i] = 0;
            cnt[i] = 1;
        }
    }

    ll find(ll x){
        if(x != p[x]) p[x] = find(p[x]);
        return p[x];
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] > rank[y]){
            p[y] = x;
            cnt[x] += cnt[y];
        }else{
            p[x] = y;
            cnt[y] += cnt[x];
            if(rank[x] == rank[y]) rank[y]++;
        }
    }

    ll size(ll x){
        return cnt[find(x)];
    }
};

int main(){
    ll n; cin >> n;
    vpl a(n),b(n);
    rep(i,n){
        cin >> a[i].first;
        a[i].second = i;
    }
    rep(i,n){
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(all(a)); sort(all(b));
    bool flag = false;
    rep(i,n){
        if(a[i].first>b[i].first){
            puts("No");
            return 0;
        }
        if(i<n-1 && a[i+1].first <= b[i].first) flag = true;
        a[i].first = i;
        b[i].first = i;
    }
    rep(i,n){
        swap(a[i].first,a[i].second);
        swap(b[i].first, b[i].second);
    }
    sort(all(a)); sort(all(b));
    UnionFind uf(n);
    rep(i,n){
        uf.unite(a[i].second, b[i].second);
    }
    if(flag){
        puts("Yes");
        return 0;
    }
    rep(i,n){
        if(uf.size(i)==n){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


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


int main(){
  ll n; cin >> n; ll sum = 0;
  
  for(ll i=1; i <= n; i++){
    if(((i % 3) != 0)&&((i % 5) != 0)) sum += i;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

void minmax( int a, int l, int& largest, int& smallest ) {
    int base = 1;
    int x[6] = {};
    for(int i=1; i<l; i++) base *= 10;
    rep(dl, l) {
        x[dl] = (a / base) % 10;
        base /= 10;
    }
    sort( x, x+l );
    largest = smallest = 0;
    rep(i, l) {
        largest *= 10;
        smallest *= 10;
        largest += x[l-1-i];
        smallest += x[i];
    }
}

int main(){
    int a, l;
    while( cin >> a >> l, a||l ) {
        bool found = false;
        int cnt = 0;
        vector<int> hist;
        hist.push_back(a);
        while(!found) {
            cnt++;
            int large, small;
            minmax( a, l, large, small );
            int i=0;
            for(; i<hist.size(); i++) {
                if( hist[i] == large-small ) {
                    found = true;
                    break;
                }
            }
            if( !found ) {
                hist.push_back( large-small );
                a = large - small;
            } else {
                cout << i << ' ' << large-small << ' ' << cnt-i << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1220
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [x, a, b] = input[0].split(' ').map(x => parseInt(x))

  if (Math.abs(x - a) < Math.abs(x - b)) {
    console.log('A')
  } else {
    console.log('B')
  }
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29596
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n,k,i,j,a[200010];
  cin >> n >>k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  if(k>1000){
    for(i=0;i<n;i++){
      if(i==0){
        printf("%lld",n);
        continue;
      }
      printf(" %lld",n);
    }
    printf("\n");
    return 0;
  }
  for(i=0;i<k;i++){
   vector<ll> s(200010,0);
    for(j=0;j<n;j++){
      if(j-a[j]<0){
        s[0]++;
      }
      else{
        s[j-a[j]]++;
      }
      if(j+a[j]>n){
        s[n]--;
      }
      else{
        s[j+a[j]+1]--;
      }
    }
    for(j=0;j<n;j++){
      s[j+1]+=s[j];
    }
    for(j=0;j<n;j++){
      a[j]=s[j];
    }
  }
  for(i=0;i<n;i++){
    if(i==0){
      printf("%lld",a[i]);
      continue;
    }
    printf(" %lld",a[i]);
  }
  printf("\n");
}

Measured memory_bytes: 6884
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m,counter=0,ans=0;
    bool ok;
    cin>>n>>m;
    vector<int> sw[m];
    vector<int> p(m,0);
    vector<int> onf(n);
    rep(i,m){
        int k;
        cin>>k;
        rep(j,k){
            int s;
            cin>>s;
            sw[i].push_back(s);
        }
    }
    rep(i,m) cin>>p[i];
    rep(i,1<<n){
        rep(j,n) onf[j]=0;
        rep(j,n){
            if(i>>j&1) onf[j]=1;
        }
        ok=true;
        rep(j,m){
            counter=0;
            for(auto v: sw[j]){
                if(onf[v-1]==1) counter++;
            }
            if(counter%2!=p[j]) ok=false;
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  char s[3]={};
  int i,k;
  scanf("%s",s);
  if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
    k=3;}
  else if(s[0]=='R'&&s[1]=='R'&&s[2]=='S'){
    k=2;}
  else if(s[0]=='S'&&s[1]=='R'&&s[2]=='R'){
    k=2;}
  else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S'){
    k=0;}
  else{
    k=1;}
  printf("%d",k);
  return 0;
}

Measured memory_bytes: 1728
K,*as=$<.read.split.map(&:to_i)

min = 2
max = 2
(K-1).downto(0) do |i|
  min = ((min-1)/as[i]+1)*as[i]
  max = max/as[i]*as[i] + as[i] - 1
  if max < min
    puts -1
    exit 0
  end
end

puts [min,max].join(' ')

Measured memory_bytes: 9340
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		int S = stdIn.nextInt();
		int W = stdIn.nextInt();
		if(S <= W) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35856
N = int(input())

li = ["AC","WA", "TLE" , "RE"]
ans = [0 for _ in range(4)]

for i in range(N):
    S = input()
    for j in range(4):
        if li[j]==S:
            ans[j] += 1

for i in range(4):
    print("{} x {}".format(li[i], ans[i]))



Measured memory_bytes: 74224
/*      Author : Kaustubh Gangwar
        Institute : IIITA        */
#include <bits/stdc++.h>
using namespace std;
#define modo 1000000007
#define F first
#define S second 
#define pb push_back
#define gcd __gcd
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x).begin(),(x).end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define CODING ios_base::sync_with_stdio(false); 
#define SAMRAT cin.tie(0),cout.tie(0);
#define mii map<int,int>
#define nl '\n'
typedef long long  ll;
typedef pair<int,int> pii;
 
ll bpow(ll a, ll b) {
    a=a; ll ans = 1;
    while(b){
        if (b & 1)
        ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}

int32_t main()
{ 
   CODING SAMRAT
   int test=1;
   //cin>>test;
   while(test--)
   {
       string s; cin>>s;
       
       int ans=0;
       f(i,0,3)
       {   
           if(s[i]=='R')
           {   int cnt=1;
               f(j,i+1,3)
               {
                   if(s[j]!='R')
                   {
                       i=j-1;
                       break;
                   }
                   else
                   cnt++;
                   
                   if(j==2)
                   break;
               }
               
           ans=max(ans,cnt);
           }
       }
        cout<<ans<<nl;
    
    
   }

return 0;
}

Measured memory_bytes: 3648
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn list_all_paths(remained_towns: &Vec<usize>,
                  traced_towns: &Vec<usize>) -> Vec<Vec<usize>>{

    if remained_towns.len() == 0{
        return vec![traced_towns.clone()];
    }

    let mut ans: Vec<Vec<usize>> = vec![];
    for i in 0..remained_towns.len(){
        let mut traced_towns = traced_towns.clone();
        let mut remained_towns = remained_towns.clone();
        traced_towns.push(remained_towns[i]);
        remained_towns.remove(i);
        let mut list = list_all_paths(&remained_towns, &traced_towns);
        ans.append(&mut list);
    }

    return ans;
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, m, r) = (line[0], line[1], line[2]);
    let rs: Vec<usize> = read_as_vec::<usize>().into_iter().map(|x| x-1).collect::<Vec<usize>>();
    let dummy = std::u64::MAX;
    let mut matrix = vec![vec![dummy;n];n];

    for i in 0..n{
        matrix[i][i] = 0;
    }
    for _ in 0..m{
        let line = read_as_vec::<usize>();
        let (a, b, c) = (line[0]-1, line[1]-1, line[2]);
        matrix[a][b] = c as u64;
        matrix[b][a] = c as u64;
    }


    for i in 0..n{
        for j in 0..n{
            for k in 0..n{
                if matrix[j][i] == dummy || matrix[i][k] == dummy{
                    continue;
                }
                matrix[j][k] = cmp::min(matrix[j][k], matrix[j][i]+matrix[i][k]);
            }
        }
    }

    let mut r_matrix = vec![vec![0;r];r];

    for i in 0..r{
        for j in i..r{
            r_matrix[i][j] = matrix[rs[i]][rs[j]];
            r_matrix[j][i] = matrix[rs[i]][rs[j]];
        }
    }
    //println!("{:?}", matrix);
    //println!("{:?}", r_matrix);
    let matrix = r_matrix;
    let towns: Vec<usize> = (0..r).collect::<Vec<usize>>();
    let all_paths = list_all_paths(&towns, &vec![]);
    //println!("{:?}", all_paths);

    let mut ans = dummy;
    for route in all_paths{
        let mut cost = 0;
        for i in 1..route.len(){
            cost += matrix[route[i]][route[i-1]];
        }
        ans = cmp::min(cost, ans);
    }

    println!("{}", ans);
}


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

using namespace std;

using LL = long long;
using II = pair<int, int>;

const int MAX_N = 100005;

#define int long long

int N;
LL A[MAX_N];

bool check1(LL mid)
{
  for(int i = 0; i < N; i++) {
    mid = mid / A[i] * A[i];
  }
  return mid >= 2;
}

bool check2(LL mid)
{
  for(int i = 0; i < N; i++) {
    mid = mid / A[i] * A[i];
  }
  return mid <= 2;
}

signed main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  if(A[N-1] != 2) {
    cout << -1 << endl;
    return 0;
  }

  LL l = 0, r = 114514191981036436;
  while(r-l>1) {
    LL mid = (l+r)/2;
    if(check1(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  LL minAns = r;

  l = 0; r = 114514191981036436;
  while(r-l>1) {
    LL mid = (l+r)/2;
    if(check2(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  LL maxAns = l;

  if(minAns > maxAns) {
    cout << -1 << endl;
    return 0;
  } else {
    cout << minAns << " " << maxAns << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct UnionFind {
    int N;
    vector<int> parents;

    UnionFind(int _N) : N(_N){
        parents.assign(N,-1);
    }

    int find(int x) { //xの親を返す
        if (parents[x] < 0) return x;
        return parents[x] = find(parents[x]);
    }
    
    void unite(int x, int y) {  //xとyの含むグループを併合
        int px = find(x);
        int py = find(y);
        if (parents[px] > parents[py]) swap(px,py); 
        if (px != py) {
            parents[px] += parents[py];
            parents[py] = px;
        }     
    }

    bool same(int x, int y) { //x,yが同じグループにいるか判定
        return find(x) == find(y);
    }

    int size(int x) { //xと同じグループのメンバーの個数
        return -parents[find(x)];
    }
    
    vector<int> root() {//ufの根を列挙
        vector<int> res;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) res.push_back(i);
        }
        return res;
    }

    int group_count() { //ufのグループの数を数える
        int cnt = 0;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) cnt ++;
        }
        return cnt;
    }
};

int main() {
    int N,K,L; cin >> N >> K >> L;
    UnionFind uf0(N),uf1(N);
    rep(i,K) {
        int p,q; cin >> p >> q;
        --p; --q;
        uf0.unite(p,q);
    }
    rep(i,L) {
        int p,q; cin >> p >> q;
        --p; --q;
        uf1.unite(p,q);
    }
    vector<P> group(N);
    map<P,int> groupnum;
    rep(i,N) {
        int p = uf0.find(i);
        int q = uf1.find(i);
        group[i] = make_pair(p,q);
        groupnum[make_pair(p,q)] ++;
    }
    rep(i,N) cout << groupnum[group[i]] << ' ';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 17680
#include<stdio.h>
int main(){
	int n,m,j,b,ai,l;
	unsigned long long int  a[101][101], gh[101][101],ans[101][101];
	
	scanf("%d %d %d",&n,&m,&l);
	for(j=0;j<101;j++){
		for(b=0;b<101;b++){
			ans[j][b]=0;
			a[j][b]=0;
			gh[j][b]=0;
		}
	}
	for(j=0;j<n;j++){
		for(b=0;b<m;b++){
			scanf("%d",&a[j][b]);
		}
	}
	for(j=0;j<m;j++){
		for(b=0;b<l;b++){
			scanf("%d",&gh[j][b]);
		}
	}
	for(j=0;j<n;j++){
		for(b=0;b<l;b++){
			for(ai=0;ai<m;ai++){
				ans[j][b]+=a[j][ai]*gh[ai][b];
			}
		}
	}
		for(j=0;j<n;j++){
			for(b=0;b<l;b++){
				if(b==0){printf("%llu",ans[j][b]);
				}
				else{
					printf(" %llu",ans[j][b]);
				}
			}printf("\n");
		}
		scanf("%d",&n);
	return 0;
}


Measured memory_bytes: 2092
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CHalfAndHalf solver = new CHalfAndHalf();
        solver.solve(1, in, out);
        out.close();
    }

    static class CHalfAndHalf {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextInt();
            long b = in.nextInt();
            long c = in.nextInt();
            long x = in.nextInt();
            long y = in.nextInt();
            long min = Long.MAX_VALUE;
            for (int i = 0; i <= Math.max(x, y); i++) {
                min = Math.min(min, a * Math.max(0, x - i) + b * Math.max(0, y - i) + c * 2 * i);
            }
            out.println(min);

        }

    }
}



Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[100010], ans = 0, ta = 1;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int num[100010] = { 0 };
	for (int i = 0; i < n; i++) {
		if ((n % 2 == 1 && a[i] % 2 == 1) || (n % 2 == 0 && a[i] % 2 == 0)) {
			cout << 0 << endl;
			return 0;
		}
		else {
			num[a[i]]++;
		}
	}
	if (n % 2 == 1) {
		if (num[0] != 1) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 2; i < n; i += 2) {
			if (num[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	else {
		for (int i = 1; i < n; i += 2) {
			if (num[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	for (int i = 0; i < n / 2; i++) {
		ta *= 2;
		ta %= 1000000007;
	}
	cout << ta << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define N 100
#define white 0
#define gray 1
#define black 2

void dfs_visit(int);
void dfs();

int n,M[N][N];
int color[N],d[N],f[N],tt;

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}
void dfs_visit(int u){
  int v;
  color[u]=gray;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==white){
      dfs_visit(v);
    }
  }
  color[u]=black;
  f[u]=++tt;
}
void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=white;
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==white)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    string ans = "AC";

    if (s[0] != 'A') ans = "WA";

    int c_count = 0;
    for (int i = 1; i < s.size(); ++i) {
        if (isupper(s[i])) {
            if (i == 1 || i == s.size() - 1 || s[i] != 'C') {
                ans = "WA";
            }
            c_count++;
        }
    }
    if (c_count != 1) ans = "WA";
    cout << ans;
    return 0;
}


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

using namespace std;

#define MAX_VTX 256

int parent[MAX_VTX];
int rank[MAX_VTX];

void init(int num){	
	for(int i=0; i<num; ++i){
		parent[i] = i;
		rank[i]=0;
	}
}

int find(int x){
	if(parent[x]==x)
		return x;
	else
		return parent[x]=find(parent[x]);
}

void unite(int x, int y){

	x=find(x);
	y=find(y);

	if(x==y)
		return;
	
	if(rank[x]<rank[y]){
		parent[x]=y;
	}
	else{
		parent[y]=x;
		
		if(rank[x]==rank[y])
			rank[x]++;
	}
}

bool same(int x, int y){
	return find(x)==find(y);
}

int n, k, m, r;
bool vis[64]={0};

int main(){
	
	cin>>n;
	cin>>k;
	
	init(n+1);
	
	for(int i=0; i<k; ++i){
	
		int m;
		cin>>m;
		
		int d=-1;
		
		for(int j=0; j<m; ++j){
			
			int a;
			cin>>a;
			
			if(d<0)
				d=a;
				
			unite(d, a);
		}
	}
	
	int res=0;
	
	cin>>r;
	
	for(int i=0; i<r; ++i){
		
		int p, q;
		cin>>p>>q;
		
		if(same(p, q)){
			
			if(!vis[p]){
				vis[p]=true;
				res++;
			}
			if(!vis[q]){
				vis[q]=true;
				res++;
			}
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    if(A[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    reverse(ALL(A));
    ll ans = 1ll;
    REP(i, N) {
        if(log10(double(ans)) + log10(double(A[i])) > 18) {
            cout << -1 << endl;
            return 0;
        }
        ans = ans * A[i];
        if(ans - 1000000000000000000 > 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
//ABC86A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a%2 == 1 && b%2 == 1){
		cout << "Odd" << endl;
	}else{
		cout << "Even" << endl;
	}
	return 0;
}

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

using namespace std;

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

    string s;
    cin >> s;
    s += '$';
    int curLen = 0, ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == 'R')
            curLen++;
        else
            ans = max(ans, curLen), curLen = 0;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int n, m, Q, D[101000], head, tail;
vector<int>E[101000];
int v[101000][12], Col[101000];
struct point{
    int a, d, c;
}w[101000];
int QQ[1010000][2];
void Ins(int a, int d, int c){
    if(v[a][d])return;
    v[a][d] = 1;
    if(!Col[a])Col[a] = c;
    tail++;
    QQ[tail][0]=a,QQ[tail][1]=d;
}
int main(){
    int i,a,b;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        E[a].push_back(b);
        E[b].push_back(a);
    }
    scanf("%d",&Q);
    for(i=0;i<Q;i++){
        scanf("%d%d%d",&w[i].a,&w[i].d,&w[i].c);
    }
    for(i=Q-1;i>=0;i--){
        head = tail = 0;
        Ins(w[i].a,w[i].d,w[i].c);
        while(head < tail){
            head++;
            int x = QQ[head][0], d = QQ[head][1];
            if(!d)continue;
            for(int j=0;j<E[x].size();j++){
                Ins(E[x][j],d-1,w[i].c);
            }
        }
    }
    for(i=1;i<=n;i++)printf("%d ",Col[i]);
}

Measured memory_bytes: 18680
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

# inputa = [int(n) for n in inputa]
# inputa.sort()

# inputa = list(inputa[0])

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

cnt = 0
for i in range(1, a+1):
    if len(str(i)) % 2 == 1:
       cnt += 1

print(cnt)



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

typedef long long ll;
typedef pair<int,int> P;

vector<int>x(200),y(200);

#define MAX 114514

int main(){
        int N;
        while(cin>>N&&N){
                int width,height;
                for(int i=1;i<N;i++){
                        int n,d; cin>>n>>d;
                        x[i]=x[n];
                        y[i]=y[n];
                        switch(d){
                                case 0:x[i]--;break;
                                case 1:y[i]--;break;
                                case 2:x[i]++;break;
                                case 3:y[i]++;break;
                        }
                }
                int xmin=MAX;
                int xmax=-MAX;
                int ymin=MAX;
                int ymax=-MAX;
                for(int i=0;i<N;i++){
                        xmin=min(xmin,x[i]);
                        xmax=max(xmax,x[i]);
                        ymin=min(ymin,y[i]);
                        ymax=max(ymax,y[i]);
                }
                width=xmax-xmin+1;
                height=ymax-ymin+1;
                cout<<width<<" "<<height<<endl;
        }
        return 0;
}



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

using namespace std;

int ansn(int n){
    if(n == 1) return 1;
    return n * ansn(n - 1);
}

int main(void){
    int n, m;
    cin >> n >> m;
    int ans = 0;
    ans += (n * (n-1) / 2) + (m * (m-1) / 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N=1e5;


signed main(){
    int N,M;cin>>N>>M;
    vector<int>Graph[3*N];
    REP(i,M){
        int a,b;cin>>a>>b;a--;b--;
        Graph[3*a].pb(3*b+1);
        Graph[3*a+1].pb(3*b+2);
        Graph[3*a+2].pb(3*b);
    }
  	vector<int>depth(3*N,INF);
    int S,T;cin>>S>>T;S--;T--;
    queue<int>q;
    q.push(3*S);
  	depth[3*S]=0;
    while(q.size()){
        int now=q.front();q.pop();
        for(auto v:Graph[now]){
            if(depth[v]!=INF)continue;
            depth[v]=depth[now]+1;
            q.push(v);
        }
    }
    cout<<(depth[3*T]==INF?-1:depth[3*T]/3)<<endl;
}

Measured memory_bytes: 18944
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <numeric>
using namespace std;


//Peaks
//*
int main() {

	int n, m,a,b,cnt=0;
	vector<pair<int,bool>> tower;
	pair<int, bool> input;
	input.second = true;
	cin >> n >> m;
	for (int i = 0; i < n;i++) {
		cin >> input.first;
		tower.push_back(input);
	}
	for (int i = 0; i < m;i++) {
		cin >> a >> b;
		if (tower[a-1].first< tower[b - 1].first) {
			tower[a - 1].second = false;
		}
		else if (tower[a - 1].first > tower[b - 1].first) {
			tower[b - 1].second = false;
		}
		else {
			tower[a - 1].second = false;
			tower[b - 1].second = false;
		}
	}
	for (int i = 0; i < tower.size(); i++) {
		if (tower[i].second==true) {
			cnt++;
		}
	}
	cout << cnt;

	return 0;
}
//*/


Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
set<int> dp[200][200];	//closed
string s;
void num(int &x){
	int ret=0,y=x;
	while(isdigit(s[y])){
		ret*=10;
		ret+=s[y]-'0';
		y++;
	}
	dp[x][y-1].insert(ret);
	x=y;
}
int main(){
	while(true){
		cin>>s;
		if(s[0]=='#') break;
		int N=s.size();
		rep(i,N) rep(j,N) dp[i][j].clear();
		for(int x=0;x<N;x++){
			if(isdigit(s[x])) num(x);
		}
		rep(d,N) rep(x,N-d){
			int y=x+d;
			if(s[x]=='('&&s[y]==')'&&!dp[x+1][y-1].empty()){
				dp[x][y]=dp[x+1][y-1];
				continue;
			}
			for(int m=x+1;m<=y-1;m++){
				if(s[m]=='+'){
					for(int a:dp[x][m-1]) for(int b:dp[m+1][y]) dp[x][y].insert(a+b);
				}
				if(s[m]=='-'){
					for(int a:dp[x][m-1]) for(int b:dp[m+1][y]) dp[x][y].insert(a-b);
				}
				if(s[m]=='*'){
					for(int a:dp[x][m-1]) for(int b:dp[m+1][y]) dp[x][y].insert(a*b);
				}
				if(s[m]=='/'){
					for(int a:dp[x][m-1]) for(int b:dp[m+1][y]) if(b!=0) dp[x][y].insert(a/b);
				}
			}
		}
		cout<<dp[0][s.size()-1].size()<<endl;
	}
}

Measured memory_bytes: 3148