akhauriyash/Code-Regression huggingface dataset:
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

const int MAXN=200000;
set<int> a[MAXN+10];
void solve(long long h, long long w, long long n, vector<long long> X, vector<long long> Y){
	for(int i=0; i<n; ++i) {
		a[Y[i]].insert(X[i]);
	}
	for(int i=1; i<=w; ++i) {
		a[i].insert(h+1);
	}
	int ans=h;
	int cnt=0;
	int x=1,y=1;
	int pl=0;
	int stop=0;
	while(true) {
		++cnt;
		if (pl==0) {
			if (a[y].count(x+1)==0) {
				++x;
				stop=0;
			} else {
				stop++;
				if (stop>=2) {
					ans=min(ans,(cnt+1)/2);
					break;
				}
			}
		} else {
			int p=*a[y].upper_bound(x);
			ans=min(ans,cnt/2+(p-x-1)+((stop==0)?1:0));
			if (y<w && a[y+1].count(x)==0) {
				++y;
				stop=0;
			} else {
				stop++;
				if (stop>=2) {
					ans=min(ans,cnt);
					break;
				}
			}
		}
		pl^=1;
	}
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	freopen("./in_D_2.txt","r",stdin);
#endif
	long long W;
	long long N;
	long long H;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&N);
	vector<long long> Y(N-1+1);
	vector<long long> X(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&X[i]);
		scanf("%lld",&Y[i]);
	}
	solve(H, W, N, X, Y);
	return 0;
}



Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int size = S.size();
  bool flag = true;
  for (int i = 0; i < size; i++) {
  	if ((i + 1) % 2 == 0 && (S[i] == 'L' || S[i] == 'U' || S[i] == 'D')) {
    } else if ((i + 1) % 2 == 1 && (S[i] == 'R' || S[i] == 'U' || S[i] == 'D')) {
    } else {
    	flag = false;
        break;
    }
  }
  if (flag) {
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX =510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2; i<MAX; i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll modpow(ll a, ll n){
  if(n==1) return a%MOD;
  if(n%2==1) return (a*modpow(a,n-1))%MOD;
  else{
    ll t=modpow(a,n/2)%MOD;
    return (t*t)%MOD;
  }
}

ll COM(int n, int k){
  if(n<k)
    return 0;
  if(n<0 || k<0)
    return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//nがとても大きい。
//シンプルに、n=10なら　10C1+10C2+10C3+...+10C10　そこから10Ca,bをひくかんじ
//これって2の何条とかなんじゃなかったっけ
//3C0ってなんだっけ1か、 1+3+3+1=8=2^3
//nのn=1 10 n=2 100 n=10 100...00(10ko)
//nの計算回数を減らさねば
//繰り返し二乗法なるものあり
//nCkはつかわんのね
//nCa modPを求める
//ごちゃごちゃしたのをX/YmodP
//Y^(-1)の求め方はフェルマーのしょうていり
//a^(p-1)=1(modP)
//Y^(P-2)=Y^(-1)
//X*Y^(p-2)(modP)を求めるかんじ。Xはforでまわすかな
int main(){
  COMinit();
  ll n,a,b; cin>>n>>a>>b;
  ll all=modpow(2,n)-1;
  ll aa=a, bb=b;
  for(int i=a-1; i>=2; i--) (aa*=i)%=MOD;
  ll A=modpow(aa,MOD-2);
  for(int i=0; i<a; i++) (A*=(n-i))%=MOD;
  for(int i=b-1; i>=2; i--) (bb*=i)%=MOD;
  ll B=modpow(bb,MOD-2);
  for(int i=0; i<b; i++) (B*=(n-i))%=MOD;
  all-=A;
  if(all<0) all+=MOD;
  all-=B;
  if(all<0) all+=MOD;
  cout<<all<<endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string c[] = {"A", "C", "G", "T"};
  string s[64];
  rep(i, 4) rep(j, 4) rep(k, 4) s[i*16+j*4+k] = c[i]+c[j]+c[k];
  vector<map<string, ll>> dp(n+1);
  set<string> ng3 = {"AGC", "ACG", "GAC"};
  set<string> ng4 = {"AGAC", "AGGC", "AGTC", "AGGC", "ATGC"};
  rep(i, 64) if(!ng3.count(s[i])) dp[3][s[i]] = 1;
  for(int i=4; i<=n; i++) {
    for(auto ele: dp[i-1]) {
      string s = ele.first;
      rep(j, 4) {
        if(ng4.count(s+c[j]) || ng3.count(s.substr(1)+c[j])) continue;
        (dp[i][s.substr(1)+c[j]] += ele.second) %= mod;
      }
    }
  }
  ll ans = 0;
  for(auto ele: dp[n]) (ans += ele.second) %= mod;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4080
from collections import deque

n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

l = [[] for _ in range(n)]
for u, v, w in uvw:
    u, v = u-1, v-1
    l[u].append((v, w))
    l[v].append((u, w))

ans = [0] * n
parents = [-1] * n
q = deque([0])
while q:
    a = q.pop()
    for i, j in l[a]:
        if i == parents[a]:
            continue
        parents[i] = a
        q.append(i)
        ans[i] = ans[a] if j%2 == 0 else (ans[a]+1) % 2
for i in ans:
    print(i)

Measured memory_bytes: 61664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  ll N; cin>>N;
  ll b[2][N/2+1];
  REP(i,N){
    cin >> b[i%2][i/2];
  }
  if(N%2){
    REPR(i,N/2){
      cout << b[0][i] << " ";
    }
    REP(i,N/2){
      cout << b[1][i] << " ";
    }
  }else{
    REPR(i,N/2-1){
      cout << b[1][i] << " ";
    }
    REP(i,N/2){
      cout << b[0][i] << " ";
    }
  }
}

Measured memory_bytes: 3712
#!/usr/bin/php
<?php
$n = trim(fgets(STDIN));
$i = 0;
$a = [];
$max = 1;

for (;;) {
  $s = trim(fgets(STDIN));
  if (isset($a[$s])) {
    $a[$s]++;
    if ($a[$s] > $max) {
      $max = $a[$s];
    }
  } else {
    $a[$s] = 1;
  }

  $i++;
  if ($i == $n) {
    break;
  }
}

$d = [];
foreach ($a as $s => $n) {
  if ($n == $max) {
    $d[] = $s;
  }
}

sort($d);

foreach ($d as $s) {
  echo $s . "\n";
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
 if(a<b&&b<c){
		cout<<a<<" "<<b<<" "<<c<<endl;
}else if(a<c&&c<b) {
	cout<<a<<" "<<c<<" "<<b<<endl;
}else if(b<a&&a<c){
	cout<<b<<" "<<a<<" "<<c<<endl;
}else if(b<c&&c<a){
	cout<<b<<" "<<c<<" "<<a<<endl;
}else if(c<a&&a<b){
	cout<<c<<" "<<a<<" "<<b<<endl;
}else if(c<b&&b<a){
	cout<<c<<" "<<b<<" "<<a<<endl;
}else if(a==b&&b>c){
	cout<<c<<" "<<a<<" "<<b<<endl;
}else if(a==b&&b<c){
	cout<<a<<" "<<b<<" "<<c<<endl;
}else if(b==c&&c>a){
	cout<<a<<" "<<b<<" "<<c<<endl;
}else if(b==c&&c<a){
	cout<<b<<" "<<c<<" "<<a<<endl;
}else if(a==c&&c>b){
	cout<<b<<" "<<a<<" "<<c<<endl;
}else if(a==c&&c,b){
	cout<<a<<" "<<c<<" "<<b<<endl;
}else{
	cout<<a<<" "<<b<<" "<<c<<endl;
}
	return 0;
}

Measured memory_bytes: 1168
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// upper_bound(all(a),k,greater<int>()) gives first no smaller(not greater) than k

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
main()
{
IOS;
int d,t,s;
cin>>d>>t>>s;
if(t*s>=d)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&b==c) printf("No\n");
	else if(a!=b&&b!=c&&a!=c) printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

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

int N,  M; cin >> N >> M;
map<int, set<int>> G;
rep(i, 0, M){
    int a, b; cin >> a >> b;
    G[a].insert(b);
    G[b].insert(a);
}

bool f = false;
for (int n : G[1])
    if (G[N].count(n)) f = true;

if (f) cout << "POSSIBLE\n";
else cout << "IMPOSSIBLE\n";

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



Measured memory_bytes: 37760
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  std::string S, T;
  std::cin >> S >> T;
  T.pop_back();
  std::cout << (S == T ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3560
import math
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
raws = [A, B, C, D, E]
residues = []
for num in raws:
    if num % 10 != 0:
        residues.append(num % 10)
    else:
        residues.append(10)

ans = 0
lastDish = residues.index(min(residues))
for i in range(len(raws)):
    if i != lastDish:
        ans += math.ceil(raws[i] / 10) * 10
    else:
        ans += raws[i]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

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

Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main()
{
long int score = 0;
int N,K,Rock,Scissors,Paper;
cin >> N >> K;
cin >> Rock >> Scissors >> Paper;

string game;
cin >> game;

char table[100010];
int i = 0;
	for(i=0; i<N; i++){
		if(i < K){
			if(game[i] == 'r'){
				score += Paper;
			}else if(game[i] == 's'){
				score += Rock;
			}else if(game[i] == 'p'){
				score += Scissors;
			}
		}else{
			if(game[i] == 'r'){
				if(game[i-K] != 'r'){
					score += Paper;
				}else{
					game[i] = 'a';
				}
			}else if(game[i] == 's'){
				if(game[i-K] != 's'){
					score += Rock;
				}else{
					game[i] = 'a';
				}
			}else if(game[i] == 'p'){
				if(game[i-K] != 'p'){
					score += Scissors;
				}else{
					game[i] = 'a';
				}
			}
		}

	}

cout << score;

}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

const int mod=1000000007;

int pow2[110],inv2[110],f[20],s[1<<15],a[15],dp[1<<15][2];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	pow2[0]=1;for (int i=1;i<=max(n,m);i++) pow2[i]=pow2[i-1]*2%mod;
	inv2[0]=1;for (int i=1;i<=max(n,m);i++) inv2[i]=ll(inv2[i-1])*((mod+1)/2)%mod;
	for (int i=1;i<pow2[n];i++) s[i]=s[i>>1]+(i&1);
	for (int i=0;i<m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		x--;y--;
		f[x]|=pow2[y];
	}
	dp[0][0]=1;
	for (int i=0;i<(1<<n)-1;i++)
	{
		int l=0;
		for (int j=0;j<n;j++)
			if (!(i&(1<<j))) a[l++]=j;
		for (int k=0;k<2;k++)
			if (dp[i][k])
				for (int j=1;j<pow2[l];j++)
				{
					int t=dp[i][k],x=0;bool ok=1;
					for (int p=0;p<l;p++) if (j&pow2[p]) x|=pow2[a[p]];
					for (int p=0;p<l;p++)
						if (j&pow2[p])
							t=ll(t)*inv2[s[f[a[p]]&x]]%mod;
						else
						{
							if (!(f[a[p]]&x)) {ok=0;break;}
							t=ll(t)*(pow2[s[f[a[p]]&x]]-1)%mod*inv2[s[f[a[p]]&x]]%mod;
						}
					if (ok)
					{
						bool tk=k|(l>=2&&a[0]==0&&a[1]==1&&((x&3)==3));
						dp[i|x][tk]=(dp[i|x][tk]+t)%mod;
					}
				}
	}
	printf("%d\n",(ll(mod+1-dp[pow2[n]-1][1])*pow2[m]%mod));
	return 0;
}


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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(int i=0;i<N;i++)	cin >> d.at(i);

	int ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			ans+=d.at(i)*d.at(j);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, label)
  size = queue.size
  index = queue.index{|entry| entry[0] >= label} || size
  return queue[index][1] if index < size && queue[index][0] == label

  return nil if index > 0 && !label.start_with?(queue[index - 1][0])
  queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(label)

  nodes = {}
  queue.insert(index, [label.dup, nodes])
  nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  result = ''
  queue = [['', {start => true}]]
  until queue.empty?
    label, nodes = queue.shift
    result << label
    return result if nodes[goal]
    return nil if result.size > limit

    size = label.size
    queue.each do |key, value|
      key.slice!(0...size)
    end

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = a.times.map{
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  }

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 9676
#include<stdio.h>
main()
{
    int n,tmax,i;
    int c[101],t[101];
    scanf("%d %d",&n,&tmax);
    int min=100;
    c[min]=100000000;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&c[i],&t[i]);
        if(t[i]<=tmax && c[i]<c[min])
        {
            min=i;
        }
    }
    if(min==100)
    {
        printf("TLE");
    }
    else
    {
        printf("%d",c[min]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
void show(MAT<LL> a) {
  int n = a.size();
  REP(i, 0, n) {
    REP(j, 0, n) cerr << a[i][j] << " ";
    cerr << endl;
  }
}

int main() {
  int n;
  cin >> n;
  LL inf = LLONG_MAX / 2;
  MAT<LL> a = MATINIT(LL, n, n, inf);
  REP(i, 0, n) {
    REP(j, 0, n) { cin >> a[i][j]; }
  }
  auto orig = a;
  REP(k, 0, n) {
    REP(i, 0, n) {
      REP(j, 0, n) { a[i][j] = min(a[i][j], a[i][k] + a[k][j]); }
    }
  }
  bool same = 1;
  REP(i, 0, n) {
    REP(j, 0, n) {
      if (a[i][j] != orig[i][j]) {
        same = 0;
        break;
      }
    }
  }
  if (same) {
    //show(a);
    REP(k, 0, n) {
      REP(i, 0, n) {
        REP(j, 0, n) {
          if (i != j && i!=k&&k!=j) {
            if (a[i][j] == a[i][k] + a[k][j]) {
              DUMP(i, j, k);
              //show(a);
              a[i][j] = inf;
            }
          }
        }
      }
    }
    LL sum = 0;
    REP(i, 0, n) {
      REP(j, i, n) { if(a[i][j]<inf)sum += a[i][j]; }
    }
    //show(a);
    cout << sum << endl;

  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sort stable_sort
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for (register int (i)=(1);(i)<=(x);(i)++)
#define rep1(i,x,y) for (register int (i)=(x);(i)<=(y);(i)++)
#define rep2(i,x) for (register int (i)=(x);(i)>=(1);(i)--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
using namespace std;
int n,m,i,j,s=0,t=400001,dis[400005],lk[200005],fa[200005],cnt;
vector<int> ss[200005],adj[200005];
struct edg
{
	int y,z;
}ee[2000005];
vector<int> e[400005];
void add(int x,int y,int z)
{
	cnt++;
	ee[cnt*2-2]=(edg){y,z};
	ee[cnt*2-1]=(edg){x,0};
	e[x].pb(cnt*2-2);e[y].pb(cnt*2-1);
}
bool bfs(int s,int t)
{
	memset(dis,0x3f,sizeof(dis));
	dis[s]=0;queue<int> qx;qx.push(s);
	while(!qx.empty()){
		int x=qx.front();qx.pop();
		foreach(it,e[x])if(ee[*it].z&&dis[ee[*it].y]>dis[x]+1){
			dis[ee[*it].y]=dis[x]+1;
			qx.push(ee[*it].y);
		}
	}
	return dis[t]<dis[t+1];
}
int dfs(int x,int tt,int flw)
{
	if(!flw||x==tt)return flw;
	int ans=0;
	foreach(it,e[x])if(ee[*it].z&&dis[ee[*it].y]==dis[x]+1){
		int t=dfs(ee[*it].y,tt,min(flw,ee[*it].z));
		ans+=t;flw-=t;
		ee[*it].z-=t;ee[(*it)^1].z+=t;
	}
	return ans;
}
int dinic(int s,int t)
{
	int ans=0;
	while(bfs(s,t)){
		ans+=dfs(s,t,0x3f3f3f3f);
	}
	return ans;
}
void dfs2(int x)
{
	foreach(it,adj[x]){
		if(!fa[*it]){
			fa[*it]=x;
			dfs2(*it);
		}
	}
}
int main()
{
	scanf("%d",&n);
	rep(i,n-1){
		int x;
		scanf("%d",&x);
		while(x--){
			int y;
			scanf("%d",&y);
			ss[i].push_back(y);
			if(y!=1){
				add(y,i+n,1);
			}
		}
	}
	rep1(i,2,n) add(s,i,1);
	rep(i,n-1) add(i+n,t,1);
	if(dinic(s,t)!=n-1){
		puts("-1");
		return 0;
	}
	for(i=1;i<cnt*2;i+=2){
		if(2<=ee[i].y&&ee[i].y<=n&&n<ee[i^1].y&&ee[i^1].y<n+n&&ee[i].z){
			lk[ee[i^1].y-n]=ee[i].y;
		}
	}
	rep(i,n-1){
		foreach(it,ss[i])if(*it!=lk[i]){
			adj[*it].pb(lk[i]);
		}
	}
	fa[1]=1;
	dfs2(1);
	rep1(i,2,n)if(!fa[i]){
		puts("-1");
		return 0;
	}
	rep(i,n-1) printf("%d %d\n",lk[i],fa[lk[i]]);
	return 0;
}

Measured memory_bytes: 45892
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int M=1e9+7;
const int MAX=1<<21;
vector<vector<int>> dp(21,vector<int>(MAX));
int n;
int mat[21][21];
int calc(int i,int left){
    if(i==n){
        return 1;
    }
    if(dp[i][left]!=-1){
        return dp[i][left];
    }
    int ans=0;
    for(int j=0;j<n;j++){
        if(mat[i][j]==1){
            int res=1<<j;
            if(left&res){
                ans+=calc(i+1,left^res)%M;  
                ans%=M;
            }
        }
    }
    return dp[i][left]=ans;
}
void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
      	dp[i].assign(MAX,-1);
        for(int j=0;j<n;j++){
            cin>>mat[i][j];
        }
    }
    int sol=calc(0,MAX-1);
    cout<<sol<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 183380
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    ll x=max(a,b);
    ll y=max(c,d);
    
    ll p=min(a,b);
    ll q=min(c,d);
    
    cout<<max(max(x*q,y*p),max(x*y,p*q));
    

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int n;
int x[102],cnt=0;

int main(){
    int n;cin>>n;
    vector<ll> x(n),y(n);
    rep(i,n){cin>>x[i];y[i] = x[i];}
    sort(y.begin(),y.end());
    ll lb,hb;
    lb = y[n/2-1];
    hb = y[n/2];
    rep(i,n){
        if(x[i]<hb)cout<<hb<<endl;
        else cout<<lb<<endl;
    }
return 0;
}

Measured memory_bytes: 5376
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-08-07 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

template<class T> ll upper(T n,T m){return (n+m-1)/m;};
template<class T> ll rounding(T n){return (long double)n+0.5;};

template<class T> bool inG(T x,T n){return 0<=x && 0<n;}
template<class T> bool outG(T x,T n){return x<0 || n<=x;}

inline int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int n,t;
  cin>>n>>t;

  int ans=INF;

  REP(i,n){

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

    if(b <= t) ans=min(ans,a);

  }

  if(ans == INF) cout<<"TLE"<<endl;
  else cout<<ans<<endl;

  return 0;

}


Measured memory_bytes: 256
/*
Author: Arham_doshi
@quote "Code like there's no tommorow!"
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007



using namespace std;

int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}



signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,t,n,k;
    cin>>n;
    k=sqrt(n);
    bool p=false;
    rfo(i,k,2){
        if(n%i==0){
            t=(n/i + i);
            p=true ;
            break;
        }
    }
    
    if(p){
        cout<<t-2;
    }
    else{
        cout<<n-1;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int i = 1;
		Long power = 1L;
		while (i <= c) {
			power = (long) (power * i % (Math.pow(10, 9) + 7));
			// System.out.println(i + "kaime, " + power);
			i++;
		}

		System.out.println(power);
		sc.close();
	}
}

Measured memory_bytes: 23892
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int count = 0;
	static int height;
	static int width;
	static ArrayList<Integer> x = new ArrayList<Integer>();
	static ArrayList<Integer> y = new ArrayList<Integer>();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		height = sc.nextInt();
		width = sc.nextInt();
		int[][] dimensional = new int[height][width];

		for(int i = 0; i < height; i++) {
			for(int j = 0; j < width; j++) {
				dimensional[i][j] = sc.nextInt();
			}
		}
		xyprocess();

		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i < height*width; i++) {
			if((dimensional[x.get(i-1)-1][y.get(i-1)-1]) % 2 != 0) {
				dimensional[x.get(i)-1][y.get(i)-1] +=1;
				count++;
				list.add(i-1);
			}
		}

		System.out.println(count);
		for(int i = 0; i < list.size(); i++) {
			System.out.println(x.get(list.get(i)) + " " + y.get(list.get(i)) + " " + x.get(list.get(i)+1) + " "+ y.get(list.get(i)+1));
		}
	}
	static void xyprocess() {
		boolean flag = true;
		for(int i = 1; i <= height; i++) {
			for(int j = 1; j <= width; j++) {
				x.add(i);
			}
		}
		for(int i = 1; i <= height; i++) {
			if(flag) {
				for(int j = 1; j <= width; j++) {
					y.add(j);
				}
			}else {
				for(int j = width; j >= 1; j--) {
					y.add(j);
				}
			}
			flag = !flag;
		}
	}
}

Measured memory_bytes: 121668
sx, sy, tx, ty = map(int, input().split())

ans = ""

ans += "U" * (ty - sy)
ans += "R" * (tx - sx)
ans += "D" * (ty - sy)
ans += "L" * (tx - sx)
ans += "L"
ans += "U" * (ty - sy + 1)
ans += "R" * (tx - sx + 1)
ans += "D"
ans += "R"
ans += "D" * (ty - sy + 1)
ans += "L" * (tx - sx + 1)
ans += "U"

print(ans)


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

using namespace std;

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

    if ((n[0] == '7') || (n[1] == '7') || (n[2] == '7'))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  int h,w;
  cin >> h >> w;
  REP(i,h){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


void solve()
{
	int l,r,d;
	cin>>l>>r>>d;
	cout<<r/d-(l-1)/d;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct UnionFind{
	vi data;
	UnionFind(int n):data(n,-1){}
	int find(int v){
		return data[v]<0?v:find(data[v]);
	}
	bool unite(int u,int v){
		int ru=find(u),rv=find(v);
		if(ru==rv) return false;
		data[ru]+=data[rv];
		data[rv]=ru;
		return true;
	}
};

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vi ps(n);
		repi(i,1,n) cin>>ps[i],ps[i]--;
		vector<tuple<char,int>> qs;
		rep(i,m){
			char c; cin>>c;
			int v; cin>>v; v--;
			qs.emplace_back(c,v);
		}
		
		vi marked(n);
		marked[0]=1;
		for(auto q:qs)
			if(get<0>(q)=='M')
				marked[get<1>(q)]++;
		
		UnionFind uf(n);
		rep(i,n) if(!marked[i])
			uf.unite(ps[i],i);
		
		ll res=0;
		per(i,m){
			char t; int v; tie(t,v)=qs[i];
			if(t=='M' && --marked[v]==0)
				uf.unite(ps[v],v);
			if(t=='Q')
				res+=uf.find(v)+1;
		}
		cout<<res<<endl;
	}
}

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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   
   string s; cin >> s;
   string ans = "Yes";
   
   for(int i = 0; i < s.size(); i++){
      int idx = i+1;
      if(idx % 2 == 0 && s[i] == 'R'){
         ans = "No";
         break;
      }
      if(idx % 2 != 0 && s[i] == 'L'){
         ans = "No";
         break;
      }
   }
   
   cout << ans;

   return 0;
}


Measured memory_bytes: 256
days = [
       "Thursday",
       "Friday",
       "Saturday",
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday"
       ]

cal = take 366 $ cycle days

endOfTheMonth = [31,29,31,30,31,30,31,31,30,31,30,31]

main = do
    l <- getLine
    if l == "0 0"
      then return ()
      else do
        let [a, b] = map (read :: String -> Int) $ words l
        let s = sum $ take (a - 1) endOfTheMonth
        let s' = s + b - 1
        putStrLn $ cal !! s'
        main

Measured memory_bytes: 4108
#include<bits/stdc++.h>
using namespace std;
long long k,a,b;
int main(){
	cin>>k>>a>>b;
	if(b-a<=2 || k-1<a)cout<<1+k<<endl;
		else cout<<(k-a+1)/2*(b-a)+k-(k-a+1)/2*2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
M = int((N-1)/2)
a = 0
for i in range(M):
    if S[i] == S[M-1-i] and S[i] == S[N - 1 - i]:
        a += 1
    else:
        break

if a == M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

const int N = 21;
vector<string> v(N);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

bool check(int i,int j,int n,int m)
{
  if(i<0 || j<0 || i>=n || j>=m || v[i][j] == '#') return false;
  return true;
}

int bfs(pair<int,int> start,pair<int,int> end,int n,int m)
{
  queue<pair<int,int> > q;
  q.push(start);
  pair<int,int> null = mp(-1,-1);
  q.push(null);
  vector<vector<bool> > vis(21,vector<bool>(21));

  int dist = 0;
  while(!q.empty())
  {
    pair<int,int> u = q.front();
    if(u == end) break;
    q.pop();
    if(u == null)
    {
      if(q.empty()) break;
      dist++;
      q.push(null);
    }

    for(int k=0;k<4;k++)
    {
      int x = u.fi + dx[k];
      int y = u.se + dy[k];

      if(check(x,y,n,m) && !vis[x][y]) 
      {
        q.push(mp(x,y));
        vis[x][y] = true;
      }
    }    
  }

  return dist;
}

int main()
{
  __;
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;i++)
  {
    cin >> v[i];
  }

  int max1 = 0;
  for(int a=0;a<n;a++)
  {
    for(int b=0;b<m;b++)
    {
      for(int c=0;c<n;c++)
      {
        for(int d=0;d<m;d++)
        {
          if(check(a,b,n,m) && check(c,d,n,m) && (mp(a,b) <= mp(c,d))) 
          {
            max1 = max(max1,bfs(mp(a,b),mp(c,d),n,m));
          } 
        }
      }
    }
  }

  cout << max1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector< bool > a(n+1, true);
  for (int i=0; i<m; ++i) {
    int mi;
    cin >> mi;
    a[mi] = false;
  }
  ul mod=1000000007;
  vector< ul > dp(n+1, 0);
  dp[0] = 1;
  for (int i=1; i<=n; ++i) {
    for (int j=1; j<=2; ++j) {
      if (i-j>=0 && a[i-j]) dp[i] += dp[i-j];
    }
    dp[i]%=mod;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int h,w;
    cin>>h>>w;
    char arr[h][w];
    for(ll int i = 0 ; i<h ; i++){
        for(ll int j = 0 ; j<w ; j++){
            cin>>arr[i][j];
        }
    }
    ll int dp[h][w];
    for(ll int i = 0 ; i<h ; i++){
        for(ll int j = 0 ; j<w ; j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for(ll int i = 0 ; i<h ; i++){
        for(ll int j = 0 ; j<w ; j++){
            if(arr[i][j] == '#') continue;
            if(i-1>=0 && arr[i-1][j]!= '#'){
                dp[i][j]+=dp[i-1][j];
                dp[i][j] = dp[i][j]%1000000007;
            }
            if(j-1>=0 && arr[i][j-1]!= '#'){
                dp[i][j]+=dp[i][j-1];
                dp[i][j] = dp[i][j]%1000000007;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 9088
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> graph[n + 1];
    int deg[n + 1] = {}, x[n + 1];
    fill(x, x + n + 1, -1);
    for (int l, r, d; cin >> l >> r >> d; ) {
        graph[l].emplace_back(r, d);
        deg[r]++;
    }
    string result = "Yes";
    stack<int> stack;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 0) {
            stack.emplace(i);
            x[i] = 0;
        }
    }
    while (!stack.empty()) {
        auto top = stack.top();
        stack.pop();
        for (auto& p : graph[top]) {
            if (deg[p.first] > 0) {
                deg[p.first]--;
                if (deg[p.first] == 0) {
                    stack.emplace(p.first);
                }
            }
            if (x[p.first] != -1 && x[p.first] - x[top] != p.second) {
                result = "No";
            } else {
                x[p.first] = x[top] + p.second;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (deg[i] > 0) {
            result = "No";
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
struct edge{int to,cost;};

int d[3602],w,h,dx[]={1,1,1,1,1,2,2,2,3},dy[]={-2,-1,0,1,2,-1,0,1,0};
char m[60][30];
vector<edge> g[3602];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > q;
	fill(d,d+2*h*w+2,INF);
	d[s]=0;
	q.push(P(0,s));
	while(!q.empty()){
		P p=q.top();q.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		rep(i,g[v].size()){
			edge e=g[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	while(cin>>w>>h&&w){
		rep(i,2*h*w+2)g[i].clear();
		rep(i,h)rep(j,w){
			cin>>m[i][j];
			if(m[i][j]=='S'){
				edge e;
				e.to=i*w+j+2;
				e.cost=0;
				g[0].push_back(e);
				e.to+=h*w;
				g[0].push_back(e);
			}
			if(m[i][j]=='T'){
				edge e;
				e.to=1;
				e.cost=0;
				g[i*w+j+2].push_back(e);
				g[h*w+i*w+j+2].push_back(e);
			}
		}
		rep(i,h)rep(j,w){
			rep(k,9){
				int nx=j+dx[k];
				int ny=i+dy[k];
				edge e;
				if(nx>=0&&nx<w&&ny>=0&&ny<h&&m[ny][nx]!='X'){
					e.to=h*w+ny*w+nx+2;
					e.cost=m[ny][nx]-'0';
					if(e.cost>9)e.cost=0;
					g[i*w+j+2].push_back(e);
				}
				nx=j-dx[k];
				if(nx>=0&&nx<w&&ny>=0&&ny<h&&m[ny][nx]!='X'){
					e.to=ny*w+nx+2;
					e.cost=m[ny][nx]-'0';
					if(e.cost>9)e.cost=0;
					g[h*w+i*w+j+2].push_back(e);
				}
			}
		}
		dijkstra(0);
		cout<<(d[1]!=INF?d[1]:-1)<<endl;
	}
}

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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(b==1)
    {
        cout<<0<<'\n';
        return 0;
    }
    int now=1;
    for(int i=1;;i++)
    {
        now--;
        now+=a;
        if(now>=b)
        {
            cout<<i<<"\n";
            return 0;
        }
    }    
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
	int i,n,min,max,num;
	long long int sum=0;
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&num);
		if(i==0){
			min=num;
			max=num;
		}
		sum+=num;
		if(num<min)
			min=num;
		if(num>max)
			max=num;
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include <string.h>
 
int main(){
    char s[3];
    scanf("%s",&s);
    if(strcmp(s,"SUN")==0)
      printf("%d\n",7);
    if(strcmp(s,"MON")==0)
      printf("%d\n",6);
    if(strcmp(s,"TUE")==0)
      printf("%d\n",5);
    if(strcmp(s,"WED")==0)
      printf("%d\n",4);
    if(strcmp(s,"THU")==0)
      printf("%d\n",3);
    if(strcmp(s,"FRI")==0)
      printf("%d\n",2);
    if(strcmp(s,"SAT")==0)
      printf("%d\n",1);
    return 0;
}


Measured memory_bytes: 128
//Hi =)) I'm T.A
#include <bits/stdc++.h>
#define nmax 500005
#define f first
#define s second
#define pb push_back
#define pa pair<int,int>
#define ll long long
#define ld long double
#define reset(a,x) memset(a,x,sizeof(a))
#define task "A"

using namespace std;
const int MOD=1e9+7;

int in[nmax];
ll res(0),f[nmax];;
string s;
vector<int>a[nmax];

void DFS(int u)
{
    for(auto v:a[u])
        if(f[v]<=f[u])
        {
            f[v]=f[u]+1;
            DFS(v);
        }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
 //   freopen(task".inp","r",stdin);
 //   freopen(task".out","w",stdout);
    reset(in,0);
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='<')
        {
            a[i].pb(i+1);
            in[i+1]++;
        }
        else
        {
            a[i+1].pb(i);
            in[i]++;
        }
    }
    for(int i=0;i<=n;i++)
        if(!in[i]) DFS(i);
    for(int i=0;i<=n;i++) res+=1ll*f[i];
    cout<<res;



    return 0;
}


Measured memory_bytes: 49564