akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

using namespace std;
string repeat(string s, ll n) {
    string s1 = "";
    for (ll i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  ll n;
  cin>>n;
  vector<string> s(n);
  string g;
  rep(i,0,n) {cin>>g; s[i]=g;}
  vector<pii> v1(n,{0,0});
  vector<ll> op,clos;
  vpii op_clos;
  rep(i,0,n){
    stack<ll> st;
    g=s[i];
    rep(j,0,(ll)g.length()){
      if(st.empty()){
        if(g[j]=='(') st.push(1);
        else st.push(-1);
      }
      else{
        if(g[j]=='('){
          if(st.top()<0) st.push(1);
          else{
            ll x=st.top();
            st.pop();
            st.push(x+1);
          }
        }
        else{
          ll x=st.top();
          x--;
          st.pop();
          if(x!=0) st.push(x);
        }
      }

    }
    ll mn=0,mx=0;
    while(!st.empty()){
      if(st.top()<0) mn=st.top();
      if(st.top()>0) mx=st.top();
      st.pop();
    }
    v1[i]={mn,mx};
    if(mn==0 && mx>0){
      op.push_back(i);
    }
    else if(mx==0 && mn<0){
      clos.pb(i);
    }
    else if(mx>0 && mn<0){
      op_clos.pb({mn,mx});
    }
  }

  ll op1=0,flag=0;
  rep(i,0,(ll)op.size()){
    op1+=v1[op[i]].s;
  }
  auto comp=[](pii &x,pii &y){
    return (x.f+x.s)>(y.f+y.s);
  };
  sort(all(op_clos),comp);
  rep(i,0,(ll)op_clos.size()){
    pii x=op_clos[i];
    if(op1<abs(x.f)) {flag=1; break;}
    else{
      op1+=x.f;
      op1+=x.s;
    }
  }
  // cout<<flag<<endl;
  rep(i,0,(ll)clos.size()){
    pii x=v1[clos[i]];
    if(op1<abs(x.f)){flag=1; break;}
    else op1+=x.f;
  }
  // cout<<op1<<endl;
  if(op1!=0) flag=1;
  if(flag) cout<<"No\n";
  else cout<<"Yes\n";
}
int main(){
    optimizeIO();

    solve();

}


Measured memory_bytes: 58084
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<int> odp;
    for (int i = 0; i < n; ++i)
    {
        int nr = -1;
        vector<int> usu;
        for (int j = 0; j < a.size(); ++j)
        {
            vector<int> t;
            for (int k = 0; k < a.size(); ++k)
                if (k != j)
                    t.push_back(a[k]);
            bool ok = true;
            for (int k = 0; k < t.size(); ++k)
                if (!(t[k] - 1 <= k))
                    ok = false;
            if (ok && a[j] - 1 == j)
            {
                nr = j;
                usu = t;
                break;
            }
        }
        if (nr == -1)
        {
            cout << "-1";
            return 0;
        }
        odp.push_back(a[nr]);
        a = usu;
    }
    for (int i = n - 1; i >= 0; --i)
        cout << odp[i] << endl;
    return 0;
}


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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int n,m;
	cin >> n >> m;
	int list[n+m];
	for(int i = 0;i < n;i++){
		list[i] = 2;
	}
	for(int i = n;i < n+m;i++){
		list[i] = 1;
	}
	int cnt = 0;
	for(int i = 0;i < n+m;i++){
		for(int j = i+1;j < n+m;j++){
			if((list[i] + list[j]) % 2 == 0){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

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

int main() {
	string S;
	cin >> S;
    if(S.at(0) == 'S'){
        cout << "Cloudy" << endl;
    }else if(S.at(0) == 'C'){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int x = scan.nextInt();
		int[] array = new int[m];

		int left = 0;
		int right = 0;
		for (int i = 0; i < m; i++) {
			array[i] = scan.nextInt();
			if(array[i] < x) {
				left++;
			} else {
				right++;
			}
		}
		System.out.println(Math.min(left, right));
	}
}

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

int main() {
	ios :: sync_with_stdio(false);
	int p[31]; iota(p, p + 31, 0);
	int w, n; cin >> w >> n;
	while(n --) {
		int i, j; char c;
		cin >> i >> c >> j;
		swap(p[i], p[j]);
	}
	for(int i = 1; i <= w; i ++)
		cout << p[i] << '\n';
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

int N, A, B;

int main() {
    cin >> N;
    cin >> A;
    int a = N*A;
    cin >> B;
    if(a < B){
        cout << (a);
    } else if (B < a){
        cout << (B); 
    } else {
        cout << (a);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int n;
    cin >> n;

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

    int count = 0;
    bool comp1, comp2; //  < : true,  > : false
    if(p[0] < p[1]) comp1 = true;
    else comp1 = false;

    for (int i = 1; i <= n-2; i++){
        if(p[i] < p[i+1]) comp2 = true;
        else comp2 = false;
        if(comp1 == comp2) count++;
        comp1 = comp2;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int max, dur, min;
	int temp;

	scanf("%d %d %d", &max, &dur, &min);

	if (min > dur){
		temp = min;
		min = dur;
		dur = temp;
	}
	if (min > max){
		temp = min;
		min = max;
		max = temp;
	}

	if (max < dur){
		temp = max;
		max = dur;
		dur = temp;
	}
	if (max < min){
		temp = max;
		max = min;
		min = temp;
	}

	printf("%d %d %d", min, dur, max);

	putchar('\n');

	return 0;

}

Measured memory_bytes: 600
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    string s;
    cin>>s;
    ll n = s.length();
    if(s[n-1]=='s'){
        s += "es";
    }else{
        s += 's';
    }
    out(s);
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ll T;
//    cin>>T;
//    while(T--)
    solve();
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
ll mod=1000000007;

int main() {
    std::ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int ans=0;
    forn(i,n){
        int a;
        cin>>a;
        if(a>=k)ans++;
    }
    cout<<ans;

	return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    ll res = 1e18;
    for (int i = 1; i <= (ll)sqrt(n); i++) {
        if(n%i==0){
            res = min(res,n/i-1+i-1);
        }
    }
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;


struct Problem {
	UL V[3];

	UL Solve2(const vector<UL> &s) {
		vector<array<UL, 3>> dp(s.size() + 1);
		rep(i, 3) dp[0][i] = 0;
		rep(i, s.size()) {
			dp[i + 1][0] = max(dp[i][1], dp[i][2]);
			dp[i + 1][1] = max(dp[i][2], dp[i][0]);
			dp[i + 1][2] = max(dp[i][0], dp[i][1]);
			dp[i + 1][s[i]] += V[s[i]];
		}
		return max(dp[s.size()][0], max(dp[s.size()][1], dp[s.size()][2]));
	}

	void Solve() {
		UL N, K; cin >> N >> K;
		rep(i, 3) cin >> V[i];
		vector<vector<UL>> S(K);
		rep(i, N) {
			char c; cin >> c;
			UL v;
			if (c == 'r') v = 2;
			if (c == 's') v = 0;
			if (c == 'p') v = 1;
			S[i % K].push_back(v);
		}
		UL ans = 0;
		rep(i, K) {
			ans += Solve2(S[i]);
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <string.h>
#include <limits.h>

int sum[5001];

int main(void)
{
  int n, i, j, max;

  while(1){
	/* 配列データの初期化 */
	memset(sum, 0, sizeof(sum));

	/* 入力データの読み込み */
	scanf("%d", &n);
	if(n == 0) break;	/* nが0だったら終了 */
	for(i=1; i<=n; i++){
	  int k;
	  scanf("%d", &k);
	  sum[i] = k + sum[i-1];
	}

	/* 最大値を覚えておく変数の初期化 */
	max = INT_MIN;

	/* 部分列を全探索 */
	for(i=0; i<n; i++){
	  for(j=i+1; j<=n; j++){
		int k = sum[j] - sum[i];
		if(max < k) max = k;
	  }
	}

	/* 答えを表示 */
	printf("%d\n", max);
  }

  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

void solve()
{
	int a,b;
	cin>>a>>b;
	cout << a*b << "\n";	
}

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

Measured memory_bytes: 3616
import re

def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())
def lim(N):
    return [int(input()) for i in range(N)]

A, B = mi()
S = input()

pattern = "[0-9]+"
c = re.compile(pattern)

if c.match(S[:A]) and S[A:A+1] == "-" and c.match(S[A+1:A+1+B]):
    print("Yes")
else:
    print("No")

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

int main(){
  int r, b, g, n, ans = 0;
  cin >> r >> b >> g >> n;
  rep(i, n+1) {
    rep(j, n+1) {
      int gnum = n-((r*i) + (b*j));
      if (gnum % g == 0 && gnum >= 0) {
        ans += 1;
        // cout << i*r << " " << j*b << " " << gnum%g << endl;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int n, c = 0;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p.at(i);
  }
  for (int i = 1; i < n - 1; i++)
  {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]))
    {
      c++;
    }
  }
  cout << c << endl;
}


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

using namespace std;

int main(){

  int n,a,b,c,d;
  int min=10000;
  
  cin>>n;
  cin>>a>>b;
  cin>>c>>d;
  
  for(int i=n;i>0;--i){

	pair<int,int> aa,bb,cc,dd;

	int t_a=a;
	int t_b=b;
	int t_c=c;
	int t_d=d;
	
	aa.second=0;
	bb.second=0;
	cc.second=0;
	dd.second=0;
	
	while(1){
	  if(t_a-i>0){
		aa.second++;
		t_a=t_a-i;
	  }
	  else{
		aa.first=t_a;
		break;
	  }
	}

	while(1){
	  if(t_b-i>0){
		bb.second++;
		t_b=t_b-i;
	  }
	  else{
		bb.first=t_b;
		break;
	  }
	}

	while(1){
	  if(t_c-i>0){
		cc.second++;
		t_c=t_c-i;
	  }
	  else{
		cc.first=t_c;
		break;
	  }
	}

	while(1){
	  if(t_d-i>0){
		dd.second++;
		t_d=t_d-i;
	  }
	  else{
		dd.first=t_d;
		break;
	  }
	}

	if(fabs(aa.first-bb.first)+fabs(aa.second-bb.second)+
	   fabs(cc.first-dd.first)+fabs(cc.second-dd.second) < min)
	  min=fabs(aa.first-bb.first)+fabs(aa.second-bb.second)+
		fabs(cc.first-dd.first)+fabs(cc.second-dd.second);

  }

  cout<<min<<endl;
  
}



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


struct Edge {
	int to, dist, cap;
	Edge(int t, int d, int c) {
		to = t;
		dist = d;
		cap = c;
	}
};

struct State {
	int pos, prev, v;
	double time;
	State(int p, int pr, int v_, double t) {
		pos = p;
		prev = pr;
		v = v_;
		time = t;
	}
	bool operator<(const State& right) const {
		return time > right.time;
	}
};

double min_time[32][32][32];
bool visited[32][32][32];

int main() {
	while(true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) break;

		int start, goal;
		cin >> start >> goal;
		start--;
		goal--;

		vector<vector<Edge>> G(n);
		for (int i = 0; i<m; i++) {
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			x--;
			y--;
			G[x].emplace_back(y, d, c);
			G[y].emplace_back(x, d, c);
		}

		memset(visited, 0, sizeof(visited));
		priority_queue<State> que;
		que.emplace(start, start, 0, 0);
		visited[start][start][0] = true;
		min_time[start][start][0] = 0;

		double ans = -1;
		while (!que.empty()) {
			auto s = que.top();
			que.pop();
			if (min_time[s.pos][s.prev][s.v] < s.time) continue;
			if (s.pos == goal && s.v == 1) {
				ans = s.time;
				break;
			}
			for (int dv = -1; dv <= 1; dv++) {
				int nv = s.v + dv;
				for (auto& e : G[s.pos]) {
					if (e.to == s.prev) continue;
					if (nv < 1 || e.cap < nv) continue;
					double nt = s.time + double(e.dist) / nv;
					if (!visited[e.to][s.pos][nv] || min_time[e.to][s.pos][nv] > nt) {
						visited[e.to][s.pos][nv] = true;
						min_time[e.to][s.pos][nv] = nt;
						que.emplace(e.to, s.pos, nv, nt);
					}
				}
			}
		}

		if (ans < 0) {
			cout << "unreachable" << endl;
		} else {
			printf("%.5f\n", ans);
		}
	}

	return 0;
}



Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct comp{
  bool operator()(const string &s,const string &t){
    return s.size() != t.size() ? s.size() < t.size() : s < t;
  }
};

int main(void){
  int n,a;
  string b;
  map<string,int,comp> d;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b>>a;
    d[b]+=a;
  }
  for(map<string,int,comp>::iterator it=d.begin();it!=d.end();it++){
    cout<<(*it).first<<" "<<(*it).second<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int time = scan.nextInt();
		int planA = scan.nextInt();
		int planB = scan.nextInt();
		if(time * planA >= planB){
			System.out.println(planB);
		}else{
			System.out.println(time * planA);
		}
	}
}

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

int main() {
    
    string s = "";
    int k;

    cin >> k >> s;

    if(s.size() <= k) cout << s;
    else{
    	rep(i, k){
    		cout << s[i];
    	}
    	cout << "...";
    }
    //cout << s.size();
    
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int x, y;
    cin >> y >> x;
    string s, t;
    cin >> s >> t;
    string yes = "YES", no = "NO";
    int L = 1, R = W, U = 1, D = H;
    string str;
    rep(i, N) {
        str += s[i];
        str += t[i];
    }
    repr(i, 2*N-1) {
        if(i&1) {
            if(str[i] == 'L') {
                R++;
            }
            if(str[i] == 'R') {
                L--;
            }
            if(str[i] == 'D') {
                U--;
            }
            if(str[i] == 'U') {
                D++;
            }
        }
        else {
            if(str[i] == 'L') L++;
            if(str[i] == 'R') R--;
            if(str[i] == 'D') D--;
            if(str[i] == 'U') U++;
        }
        // cout << L << " " << R << " " << U << " " << D << endl;
        if(R < L || D < U) break;
        if(L <= 0) L = 1;
        if(R > W) R = W;
        if(U <= 0) U = 1;
        if(D > H) D = H;
    }
    bool f = (L <= x && x <= R) && (U <= y && y <= D);
    cout << (f ? yes : no) << endl;
    return 0;
}

Measured memory_bytes: 1292
import scala.io.StdIn.{readLine,readInt}
import scala.math.pow

object Main {
  def main(args: Array[String]) = {
    val l = readLine() split " " map (_.toDouble)
    val (vx, vy) = (l(2)-l(0), l(3)-l(1))
    val n = readInt()

    for( i <- 1 to n ) {
      val l2 = readLine() split " " map (_.toDouble)
      val (vx2, vy2) = (l2(0)-l(0), l2(1)-l(1))
      val sqr = pow(vx,2) + pow(vy,2)
      val in_p = vx*vx2 + vy*vy2
      val (xt, yt) = ( in_p*vx/sqr + l(0), in_p*vy/sqr + l(1) )

      println(f"$xt%.10f $yt%.10f")
    }
  }
}

Measured memory_bytes: 55824
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;
ll n, ans = 0;
void rec(ll num, bool v3, bool v5, bool v7){
    if(num>n) return;
    else if(v3 && v5 && v7) ans++;
    rec(num * 10 + 3, true, v5, v7);
    rec(num * 10 + 5, v3, true, v7);
    rec(num * 10 + 7, v3, v5, true);
}

int main(){
    cin>>n;
    rec(0, false, false ,false);
    cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535

int a,b,h,m;

int main()
{
    scanf("%d%d%d%d",&a,&b,&h,&m);
    int minuts=h*60+m;
    double hangle=2*PI*minuts/(12*60.0);
    double mangle=2*PI*m/60.0;

    printf("%.15lf\n",sqrt(pow(b-a*cos(hangle-mangle),2)+pow(a*sin(hangle-mangle),2)));
}

Measured memory_bytes: 2476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int sum= 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    
    if( x < K-x ){
      sum += 2*x;
    }
    else{
      sum += 2*(K-x);
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
E = [[0 for i in range(N)] for j in range(N)] #頂点のつながり
for i in range(M):
    a, b = map(int, input().split())
    E[a-1][b-1] = 1
    E[b-1][a-1] = 1

V = [ 0 for i in range(N)] #訪問済みの頂点が1
V[0] = 1 #頂点1は訪問済み

def DPS(now, V):
    res = 0 #全て訪問できた回数
    if 0 not in V:
        return 1
    for i in range(N): 
        if (E[now][i] == 1) and (V[i] == 0): #現在の頂点と隣接してかつ未訪問の頂点
            V[i] = 1
            res = res + DPS(i, V)
            V[i] = 0
    return res

print(DPS(0, V))

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, double> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
pair<vector<T>, vector<int>> dijkstra(const vector<vector<pair<int, T>>>& graph, int n, int s){
    typedef pair<T, int> PP;

    vector<T> d(n+1, INF);
    d[s] = 0;

    vector<int> p(n+1, -1);
    p[s] =  s;

    priority_queue<PP, vector<PP>, greater<PP>> que;
    que.emplace((T)0, s);

    while(!que.empty()){
        T w = que.top().first;
        int to = que.top().second;
        que.pop();

        if(d[to] < w){
            continue;
        }

        rep(i, (int)graph[to].size()){
            int from = graph[to][i].first;
            T nw = w + graph[to][i].second;
            if(nw < d[from]){
                d[from] = nw;
                p[from] = to;
                que.emplace(nw, from);
            }
        }
    }
    return make_pair(d, p);
}

signed main(){
    double xs, ys, xt, yt;
    int n;
    cin >> xs >> ys >> xt >> yt >> n;

    vector<double> x(n), y(n), r(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i];

    vector<vector<P>> edge(n+2, vector<P>());
    double d = max(0.0, sqrt(pow(xs - xt, 2) + pow(ys - yt, 2)));
    edge[0].emplace_back(n+1, d);
    edge[n+1].emplace_back(0, d);

    rep(i, n){
        double ds = max(0.0, sqrt(pow(xs - x[i], 2) + pow(ys - y[i], 2)) - r[i]);
        edge[0].emplace_back(i+1, ds);
        edge[i+1].emplace_back(0, ds);

        double dt = max(0.0, sqrt(pow(xt - x[i], 2) + pow(yt - y[i], 2)) - r[i]);
        edge[n+1].emplace_back(i+1, dt);
        edge[i+1].emplace_back(n+1, dt);

        for(int j = i + 1; j < n; j++){
            double d = max(0.0, sqrt(pow(x[j] - x[i], 2) + pow(y[j] - y[i], 2)) - r[i] - r[j]);
            edge[i+1].emplace_back(j+1, d);
            edge[j+1].emplace_back(i+1, d);
        }
    }

    pair<vector<double>, vector<int>> ans = dijkstra<double>(edge, n+2, 0);
    cout << fixed << setprecision(10) << ans.first[n+1] << endl;

    return 0;
}


Measured memory_bytes: 22640
line = raw_input()
n = int(line)
# 3 5 7 105
# 3 3 3 5 135
# 3 5 11 165
# 3 3 3 7 189
# 3 5 13 195
r = [105, 135, 165, 189, 195]

print len([i for i in r if n >= i])


Measured memory_bytes: 2568
/*
*
*	AUTHOR :- @soham01
*		// "WORK HARD AND NEVER GIVE UP" //
*
*/
#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //find_by_order(), order_of_key()
#define pb push_back
#define mp make_pair 
#define vi vector<long long int >
#define vb vector<bool>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<long long int> >
#define vp vector<pair<long long int , long long int > >
#define seti set<long long int >
#define setc set<char>
#define setd set<double>
#define mod 1000000009
#define endl '\n'
typedef long long int lli;

// ITS MY REQUEST TO PLEASE PLEASE DO LOOK AT THE CONSTRAINS GIVEN CAREFULLY
// DO CHECK FOR CORNER CASES

/*-------LET THE GAME BEGIN-----------*/

void solve()
{
	lli a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout << a<<" "<<b<<" "<<c<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
		solve();
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
#define INF 100000010
using namespace std;
int main(){
	long long n,k,i,j,l,a[N],qdh[N],pos[N],unpos[N],maxs=-INF,mins=INF,tem,tem2;
	cin>>n>>k;
	qdh[0]=0;
	a[0]=0;
	pos[0]=0;
	unpos[0]=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]>0)
		{
			pos[i]=pos[i-1]+a[i];
			unpos[i]=unpos[i-1];
		}
		else
		{
			unpos[i]=unpos[i-1]+a[i];
			pos[i]=pos[i-1];
		}
		qdh[i]=qdh[i-1]+a[i];
	}
	for(i=0;i+k<=n;i++)
	{
		tem=qdh[i+k]-qdh[i];
		tem2=pos[i+k]-pos[i-1];
		maxs=max(maxs,tem+pos[n]-tem2);
		tem2=unpos[i+k]-unpos[i-1];
		mins=min(mins,tem+unpos[n]-tem2);
	}
	cout<<max(maxs,qdh[n]-mins)<<endl;
	return 0;
}

Measured memory_bytes: 3456
N, M, T = map(int, input().split())
a = list(map(int, input().split()))
current = 0
ans = 0
ans += max(a[0] - M, 0)
current = a[0]
for i in range(1, N):
    ans += max(a[i] - a[i - 1] - 2 * M, 0)
    current = a[i]
ans += max(T - a[N - 1] - M, 0)
print(ans)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
ll d,ans=0;
for(int i=0;i<n;++i)
{
    cin>>d;
    while(d>0&&d%2==0)
    {
        ++ans;
        d/=2;
    }
}
cout<<ans;
}

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

using namespace std;

int a[100009];
int b[100009];
int v[100009];

int n;

int main()
{
    cin >> n;

    int i;
    for(i = 1; i <= n; i ++)
        cin >> v[i];

    sort(v + 1, v + n + 1);

    int cr = 1;
    for(i = 1; i <= n; i += 2)
        a[i] = v[cr ++];

    int last = n - (n & 1);
    for(i = last; i >= 1; i -= 2)
        a[i] = v[cr ++];

    swap(a[1], a[n - (n & 1) - 1]);

    long long mx = 0;
    long long sum = 0;
    for(i = 1; i < n; i ++)
        sum += abs(a[i] - a[i + 1]);

    mx = sum;

    cr = n;
    for(i = 1; i <= n; i += 2)
        a[i] = v[cr --];

    last = n - (n & 1);
    for(i = last; i >= 1; i -= 2)
        a[i] = v[cr --];

    swap(a[1], a[n - (n & 1) - 1]);

    sum = 0;
    for(i = 1; i < n; i ++)
        sum += abs(a[i] - a[i + 1]);

    mx = max(mx, sum);


    cout << mx << "\n";

    return 0;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
use std::collections::VecDeque;
#[fastout]
fn main() {
    input! {
        mut s: Chars,
        q: usize,
    }
    let mut ans: VecDeque<char> = VecDeque::new();
    for i in s.iter() {
        ans.push_back(*i);
    }
    let mut t_1 = true;
    for _ in 0..q {
        input! {
            q: usize,
        }
        if q == 1 {
            t_1 = !t_1;
        } else {
            input! {
                f: usize,
                c: char,
            }
            let k: bool;
            if f == 1 {
                k = true;
            } else {
                k = false;
            }
            if t_1 == k {
                ans.push_front(c);
            } else {
                ans.push_back(c);
            }
        }
    }
    if t_1 == true {
        println!("{}", ans.iter().collect::<String>());
    } else {
        println!("{}", ans.iter().rev().collect::<String>());
    }
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

ll n, s;
ll b = LLONG_MAX;

ll f(ll b,ll n){
  if(n<b) return n;
  return f(b,n/b) + (n%b);
}


int main(){
  cin >> n >> s;
  if(s==n){
    cout << n+1 << endl;
    return 0;
  }
  FOR(i,2,sqrt(n)+1){
    if(f(i,n) == s){
      cout << i <<endl;
      return 0;
    }
  }
  ll ans = LLONG_MAX;
  for(ll i = sqrt(n)+1;i>0ll;i--){
    ll b = (n-s)/i + 1;
    ll sum = i + n-i*b;
    if(b<=i || n-i*b <0 || n-i*b>=b) continue;
    if(sum == s){
      cout << b << endl;
      return 0;
    }
  }
  if(ans == LLONG_MAX){
    cout << -1 << endl;
    return 0;
  }
  cout << b<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
bool beauty(int x) {
	string z = to_string(x);
	int len = z.length();
	for (int i = 1; i < len; i++) {
		if (z[i] != z[i - 1] + 1)return false;
	}
	return true;
}
int main() {
	int n; int a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ma = -1;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int t = a[i] * a[j];
			if (beauty(t)) {
				ma = max(ma, t);
			}
		}
	}
	cout << ma << endl;
	return 0;
}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int a,b;
  cin>>a>>b;
  if(a+b==15){cout<<'+'<<endl;}
  else if(a*b==15){cout<<'*'<<endl;}
  else{cout<<'x'<<endl;}
  return 0;  
}

Measured memory_bytes: 3640
D = int(input())
C = list(map(int, input().split()))
s = list()
for i in range(D):
  s1 = list(map(int, input().split()))
  s.append(s1)
t = list()
for i in range(D):
  N = int(input())
  t.append(N-1)
done = [0] * 26

ans = 0
for d in range(1, D+1):
  td = t[d-1]
  done[td] = d
  ans += s[d-1][td]
  for i in range(26):
    ans -= C[i]*(d-done[i])
  print(ans)

Measured memory_bytes: 68476
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, x;
	cin >> n >> x;
	ll ans = n;
	ll y = n-x;
	while(x > 0){
		ll q = y/x;
		ans += q * 2*x;
		y %= x;
		if(y == 0) ans -= x;
		swap(x, y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int m = 1;
        Set<Integer> used = new HashSet<>();
        for (; !used.contains(s); m++) {
            used.add(s);
            if (s % 2 == 0) {
                s /= 2;
            } else {
                s = s * 3 + 1;
            }
        }
        System.out.println(m);
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

int main() {
  int n; cin >> n;
  vector<LL> a(n + 1, 0);
  for (int i = 1; i <= n; i ++) cin >> a[i];

  vector<LL> sum(n + 1, 0);
  vector<LL> ans(n + 1, 0);
  LL num = 0, t;
  for (int i = n; i > 0; i --) {
    if (a[i] == 1) {
      if (sum[i] % 2 == 0) {
        num ++;
        ans[i] = 1;
        t = i;
        for (int j = 1; j * j <= t; j ++) {
          if (t % j == 0) {
            if (j * j == t) sum[j] ++;
            else sum[j] ++, sum[t / j] ++;
          }
        }
      }
    } else {
      if (sum[i] % 2 == 1) {
        num ++;
        ans[i] = 1;
        t = i;
        for (int j = 1; j * j <= t; j ++) {
          if (t % j == 0) {
            if (j * j == t) sum[j] ++;
            else sum[j] ++, sum[t / j] ++;
          }
        }
      }
    }
  }

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

Measured memory_bytes: 6528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const ll max_V=100000,INF=1000000000;

struct edge{ll to,cost;};
typedef pair<ll,ll> P;

ll V;//頂点数
ll E;
vector<edge> G[max_V];
int d[max_V];//頂点sからの最短距離

void dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(ll i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    ll r;
    cin>>V>>E>>r;
    rep(i,E){
        ll s,t,d;
        cin>>s>>t>>d;
        edge e;
        e.cost=d;
        e.to=t;
        G[s].push_back(e);
        
    }
    dijkstra(r);
    for(int i=0;i<V;i++){
        if(d[i]!=INF) cout<<d[i]<<endl;
        else cout<<"INF"<<endl;
    }
}


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

int main(){
	bool usedAlpha[26]={false};
	string s;	cin>>s;

	bool flag=true;
	for(int i=0;i<s.length();i++){
		if(usedAlpha[s[i]-'a']==false)usedAlpha[s[i]-'a']=true;
		else{
			flag=false;
			break;
		}
	}

	flag? cout<<"yes"<<endl : cout<<"no"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
 	while (x->left != NIL) 
 	x = x->left;
  return x;
}

Node treeSearch(Node u, int k){
   /*if(u == NIL || k != u->key){
    return u;
   }
  if(k < u->key){
    return treeSearch(u->left, k);
   }
  else{
    return treeSearch(u->right, k);
   }*/
     if(u==NIL || k==u->key)return u;
  if(k<u->key)return treeSearch(u->left,k);
else return treeSearch(u->right,k);  
  }

Node treeSuccessor(Node x){
	
  Node y;
  if (x->right != NIL) 
  return treeMinimum(x->right);
 
  y = x->parent;
 
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
 
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y  
  if (z->left == NIL || z->right == NIL) y = z;
  else {
  	y = treeSuccessor(z);
 }
 
  if (y->left != NIL) x = y->left;
  else {
  	x = y->right;
 }
  if (x != NIL) x->parent = y->parent;
 
  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
 
  if (y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
    while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if (y == NIL) 	root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if (u != NIL) {
  inorder(u -> left);
  printf(" %d",  u->key);
  inorder(u -> right);
  }
  }
void preorder(Node u){
  if (u != NIL) {
  printf(" %d", u->key);
  preorder(u -> left);
  preorder(u -> right);
  }
  }


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int num; cin >> num;
	rep(i, num)
	{
		int ans = 0;
		int Y = 0, M = 0, D = 0; cin >> Y >> M >> D;
		if (Y % 3 == 0) { ans += 20 - D + (10 - M) * 20; }
		else
		{
			if (M % 2 == 0){ ans += 19 - D + ((10 - M) / 2) * 20 + ((10 - M) /2) * 19; }
			else{ ans += 20 - D + ((9 - M) / 2) * 20 + ((11 - M) / 2) * 19; }
		}
		Y++;
		while (Y != 1000)
		{
			if (Y % 3 == 0) { ans += 200; }
			else { ans += 195; }
			Y += 1;
		}
		printf("%d\n", ans + 1);
	}
	
	

	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//最大公約数をユークリッドの互除法を使って求める
//計算量はlog(max(a,b))
int gcd(int a, int b) {
    if(a==0||b==0) return 0;
    if(a % b == 0)
    return b;
    return gcd(b, a % b);
}



int main() {
    
    int k;
    cin >> k;
    k++;
    int ans = 0;
    rep(i,k) {
        rep(j,k) {
            rep(l,k) {
                ans+=gcd(gcd(i,j),l);
            }
        }
    }

    cout<<ans<<endl;


 return 0;
}


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

int main(){
  string s; cin >> s;
  int t = s.length();
  for(int i=0;i<s.length()-1;i++){
    if(s[i]!=s[i+1])
      t = min(t,max(i+1, (int)s.length()-i-1));
  }
  cout << t << endl;
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define eps 1e-11
#define DEBUG(x) cerr << #x << " = " << x << endl
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

const int MAX = 2e5 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
int main(){

    fastio;
    int n;
    cin >> n;
    vector<int> a(n+5), b(n+5);
    int gap = n+5;
    for(int i=1; i<=n; i++) a[i] = gap * i;
    for(int i=n; i>0; i--) b[i] = gap * (n-i+1);
    
    int inc = 1;
    for(int i=0; i<n; i++){
        int p;
        cin >> p;
        b[p] += inc;
        inc++;
    }

    for(int i=1; i<=n; i++) cout << a[i] << " ";
    cout << "\n";
    for(int i=1; i<=n; i++) cout << b[i] << " ";
    cout << "\n";

    // for(int i=1; i<=n; i++) cout << a[i] + b[i] << " ";
    // cout << "\n";
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0,sum=0,c1=0,c=0,n,p=1,i,j,a,b,q,k,l,m,g[100][100]={0},v[100];
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&a,&b);
		g[a][b]=1;
		g[b][a]=1;
	}
	for(i=0;i<n;i++)
	v[i]=i+1;
	do{
		c=0;
		for(i=1;i<n;i++)
		{
			if(g[v[i]][v[i-1]])
			c++;
		}
		if(c==n-1)
		c1++;
	}while(next_permutation(v+1,v+n));
	printf("%d",c1);
}


Measured memory_bytes: 256
import sys

class WeightedUnionFind:
    def __init__(self, N:int):
        """N: 大きさ
        size: 連結成分の大きさ
        weight: rootからの重み
        """
        self.par = [i for i in range(N)]
        #self.size = [1]*N
        self.rank = [0]*N
        self.weight = [0]*N

    def root(self, x:int)->int:
        """根を求める"""
        if self.par[x] == x: # if root
            return x
        else:
            root_x = self.root(self.par[x]) # 経路圧縮
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = root_x
            return root_x

    def get_weight(self, x: int)->int:
        """x の重みを取得"""
        self.root(x) # 経路圧縮
        return self.weight[x]

    def get_diff(self, x:int, y:int)->int:
        """x と y の差分を取得"""
        if not self.is_same(x, y): return "?" # 判定不可
        return self.get_weight(y) - self.get_weight(x)

    def is_same(self, x:int, y:int)->bool:
        """x と y が同じ集合に属するか否か"""
        return self.root(x)==self.root(y)

    def unite(self, x:int, y:int, w:int)->bool:
        """weight[y] = weight[x]+w となるようにmerge(x が y の親)
        return True if merge 可能"""
        if self.is_same(x, y): return False
        root_x = self.root(x)
        root_y = self.root(y)
        w += (self.weight[x] - self.weight[y])
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y
            self.weight[root_x] = -w
        else:
            self.par[root_y] = root_x
            self.weight[root_y] = w
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1
        return True

    def get_size(self, x:int)->int:
        """xの属するグループのサイズ"""
        return self.size[self.root(x)]

if __name__ == "__main__":
    N,Q = map(int, sys.stdin.readline().split())
    UNITE,DIFF = 0,1
    wuf = WeightedUnionFind(N)
    for _ in range(Q):
        com,*x = map(int, sys.stdin.readline().split())
        if com==UNITE:
            wuf.unite(*x)
        else: # same
            print(wuf.get_diff(*x))



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

N = int(input())
A = sorted(list(map(int, input().split())))

M = 10 ** 6  + 5
dp = [0]*(M)

for a in A:
    index = 1
    if dp[a] != 0:
        dp[a] = 2
        continue
    for i in range(a, M, a):
        dp[i] += 1

ret = 0
for a in A:
    if dp[a] == 1: ret +=1

print(ret)


Measured memory_bytes: 129436
K = int(input())
cnt = 0

for i1 in range(1,K+1):
  for i2 in range(i1+1, K+1):
    if i1%2 != 0 and i2%2 == 0:
      cnt = cnt+1
    elif i1%2 ==0 and i2%2 != 0:
      cnt = cnt+1
      
print(cnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int r,g;
cin >> r >> g;
cout << 2*g-r << endl;
return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	map<char, int> dic;
	dic['I'] = 1;
	dic['V'] = 5;
	dic['X'] = 10;
	dic['L'] = 50;
	dic['C'] = 100;
	dic['D'] = 500;
	dic['M'] = 1000;
	while (true) {
		string S = ""; cin >> S;
		if (S == "") break;
		int N = S.size();
		int ans = 0;
		rep(i,N) {
			if (i != N-1) {
				if (dic[S[i]] < dic[S[i+1]]) ans -= dic[S[i]];
				else ans += dic[S[i]];
			} else ans += dic[S[i]];
		}
		cout << ans << endl;
	}

}



Measured memory_bytes: 3184