akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll l;cin>>l;
  db x=l;
  x/=3;
  cout<<x*x*x<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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


public class Main {
    static ArrayList<Integer>[] graph;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        long r = sc.nextLong(), D = sc.nextLong(), x2 = sc.nextLong();
        for(long i=1;i<=10;i++){
            x2 = r*x2-D;
            System.out.println(x2);
        }
    }
}



Measured memory_bytes: 22868
#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    int x = stoi(a+b);
    for (int i = 1; i <= int(sqrt(float(x))); i++) { 
        if (x / i == i && x % i == 0) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a=0;
			for(int i=0;i*i*i<=n;i++)
				for(int j=0;j<=n;j++)
				{
					int tmp=i*i*i+j*(j+1)*(j+2)/6;
					if(tmp>n)
						break;
					a=Math.max(a, tmp);
				}
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
x_v = list(map(int, input().split(" ")))
y_v = list(map(int, input().split(" ")))

def mincos(x_v, y_v, p):
    wa = 0
    for i in range(n):
        sa = x_v[i] - y_v[i]
        if x_v[i] - y_v[i] < 0:
            sa = y_v[i] - x_v[i]
        wa += sa**p
    return wa**(1/p)
list=[]
print(float(mincos(x_v, y_v, 1)))
print(float(mincos(x_v, y_v, 2)))
print(float(mincos(x_v, y_v, 3)))
for i in range(n):
    sa = x_v[i] - y_v[i]
    if x_v[i] - y_v[i] < 0:
        sa = y_v[i] - x_v[i]
    list.append(sa)
print(max(list))


Measured memory_bytes: 5644
AGCT = 'AGCT'

def chkmax(a, b) a > b ? a : b end

s = gets.strip

count = 0
res = 0 
s.each_char do |c|
  if AGCT.include?(c)
    count += 1
  else
    res = chkmax(res, count)
    count = 0
  end
end
puts chkmax(res, count)


Measured memory_bytes: 1788
from sys import stdout,exit
n = int(input())
print(0)
stdout.flush()
a = input()
if a=="Vacant": exit()
else: l = 0
print(n-1)
stdout.flush()
b = input()
if b=="Vacant": exit()
else: r = n-1
while True:
	m = (l+r)//2
	print(m)
	stdout.flush()
	c = input()
	if c=="Vacant": break
	elif (a!=c)^((m-l)%2): r = m
	else: l,a = m,c
exit()

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int a,b,c,d;
string s;

int main(){
  cin >>s;
  int ans =0;
  for(int i=0;i<4;i++){
    if(s[i] == '-') ans--;
    else ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

 int main(void){
   int a,b;
   scanf("%d",&a); scanf("%d",&b);
   
   if(a==b){
     printf("a == b\n");
 }

   else if(a>b){
     printf("a > b\n");
 }

   else if(a<b){
     printf("a < b\n");
 }

 return 0;
}
  


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int n;
	cin >> n;
	veci w(n);
	ll sum = 0;
	rep(i, n)
	{
		cin >> w[i];
		sum += w[i];
	}
	ll ans = INT_MAX;
	ll left = 0, right = sum;
	for (size_t i = 0; i < n; i++)
	{
		left += w[i];
		right -= w[i];
		ans = min(ans, abs(right - left));
	}
	cout << ans << endl;
	return 0;
}

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

int bubble(vector<pair<int,char> > &a, int n);
void selection(vector<pair<int,char> > &a, int n);

int main(){
    stringstream ss,tt;
    int n;
    cin>>n;
    vector<pair<int,char> > a(n);
    vector<pair<int,char> > b(n);
    rep(i,n){
        cin>>a.at(i).second>>a.at(i).first;
        b=a;

    }
    
    bubble(a,n);
    rep(i,n){
        ss<<a.at(i).second<<a.at(i).first;
        if(i!=n-1){
            ss<<' ';
        }
        else{
            ss<<endl;
        }
    }
    cout<<ss.str();
    cout<<"Stable"<<endl;
    
    selection(b,n);
    rep(i,n){
        tt<<b.at(i).second<<b.at(i).first;
        if(i!=n-1){
            tt<<' ';
        }
        else{
            tt<<endl;
        }
    }
    cout<<tt.str();
    if(ss.str()==tt.str()){
        cout<<"Stable"<<endl;
    }
    else{
        cout<<"Not stable"<<endl;
    }
    return 0;
}

void selection(vector<pair<int,char> > &a,int n){
    for(int i=0;i<n-1;i++){
        int min=i;
        for(int j=i+1;j<n;j++){
            if(a.at(j).first<a.at(min).first){
                min=j;
            }
        }
        if(min!=i){
            swap(a.at(min),a.at(i));
        }
    }
}

int bubble(vector<pair<int,char> > &a,int n){
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i+1;j--){
            if(a.at(j).first<a.at(j-1).first){
                swap(a.at(j),a.at(j-1));
            }
        }
    }
    return 0;
}
 


Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=3e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

char s[maxn];

int main()
{
    int k;
    cin>>k;
    cin>>s;
    int tot=0;
    for(int i=0;i<k;i++)
    {
        if(s[i]=='R') tot++;
    }
    int ans=0;
    for(int i=0;i<tot;i++)
    {
        if(s[i]=='R') ans++;
    }
    printf("%d\n",tot-ans);
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L



int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a[i] = make_pair(x, i+1);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        cout << a[i].second << " ";
    }

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		int S, x;
		Scanner sc = new Scanner(System.in);
		Set<Integer> hash_set = new HashSet<Integer>();

		S = sc.nextInt();
		x = S;

		while(hash_set.contains(x) == false) {
			hash_set.add(x);

			if(x % 2 == 0) {
				x /= 2;
			} else {
				x = 3 * x + 1;
			}
		}

		System.out.println(hash_set.size() + 1);

		sc.close();
	}

}

Measured memory_bytes: 23764
import math
import numpy as np
N = int(input())
a = np.array([int(input()) for _ in range(N)])
s = np.sum(a)
m = 998244353
dp1 = np.zeros((N+1, s+1), dtype=np.int64)
dp1[0, 0] = 1
dp2 = np.zeros((N+1, s//2+1), dtype=np.int64)
dp2[0, 0] = 1
for i, ai in enumerate(a):
    dp1[i+1, :]   += dp1[i, :] * 2 % m
    dp1[i+1, ai:] += dp1[i, :-ai]
    dp2[i+1, :]   += dp2[i, :] % m
    dp2[i+1, ai:] += dp2[i, :-ai]
subset1 = np.sum(dp1[N, math.ceil(s/2):])
subset2 = 0 if s % 2 == 1 else dp2[N, s//2]
print((3 ** N - 3 * subset1 + 3 * subset2) % m)

Measured memory_bytes: 329412
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
S = list(input())

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(1, N):
    for j in range(i+1, N+1):
        if S[i-1]==S[j-1]:
            dp[i][j] = min(dp[i-1][j-1]+1, j-i)
            ans = max(ans, dp[i][j])

print(ans)

Measured memory_bytes: 270364
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

K = gets_i
S = gets_s

if S.size <= K
  puts S
else
  puts S[0,K] + "..."
end

Measured memory_bytes: 14576
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
using namespace std;
typedef long long ll;

int main(){
  int A, B, C;  cin >> A >> B >> C;
  if(A==B and B==C){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=1e5+4;

vector<int> v[N],tv;

int visit[N];

void dfs(int node)
{
    visit[node]=1;
    
    for(int it:v[node])
    if(!visit[it])
    dfs(it);
    
    tv.pb(node);
}

int main()                  
{
    int n,m;
    
    scn(n);  scn(m);
    
    while(m--)
    {
        int a,b;
        
        scn(a); scn(b);
        
        v[a].pb(b);
    }
    
    rep(i,1,n+1)
    if(!visit[i])
    dfs(i);
    
    int ans=0;
    
    int dis[n+1]={0};
    
    reverse(tv.begin(),tv.end());
    
    for(int node:tv)
    {
        //cout<<node<<" ";
        
        for(int it:v[node])
        dis[it]=max(dis[it],dis[node]+1);
        
        ans=max(ans,dis[node]);
    }
    
    pri(ans);
    
} 

Measured memory_bytes: 8828
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
#define sllit set<long long int>::iterator
#define pll pair<long long int,long long int>
#define vpll vector<pair<long long int,long long int> >
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli ndigit(lli n){lli count=0;if(n==0)	return 1;while(n){count++;n/=10;}return count;}

/******************************START********************************/
int main()
{
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,t,d,n,m,sum=0,ans=0,temp;
    lli arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr,arr+3);
    a=arr[0];b=arr[1];c=arr[2];
    if(a==b && a==c)	cout << "No" << endl;
    else if(a==b && b!=c)	cout << "Yes" << endl;
    else if(a!=b && b==c)	cout << "Yes" << endl;
    else	cout << "No" << endl;
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char ss[100010];
int len;

char mir(int x){
	if(ss[x]=='b') return 'd';
	if(ss[x]=='d') return 'b';
	if(ss[x]=='p') return 'q';
	if(ss[x]=='q') return 'p';
} 

int main(){
	cin>>ss; len=strlen(ss);
	for(int i=0;i<len;i++)
		if(mir(len-i-1)!=ss[i]){
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    cout << N-K+1 << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N,A,B;
	cin>>N>>A>>B;
	N%=12;
	auto f = [&](int now){
		if(now%2==0){
			A = A - B;
		}else{
			B = A + B;
		}
	};
	REP(i,N)f(i);
	OUT(A,B);
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    string s1,s2,s3;
    cin >> s1 >> s2>> s3;
    cout << s1.at(0) << s2.at(1) << s3.at(2) << endl;

}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        a: usize,
        mut b: usize,
        mut c: usize,
        k: usize,
    }
    for _ in 0..k {
        if a >= b {
            b *= 2;
        } else {
            c *= 2;
        }
    }
    let ans = if a < b && b < c { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	int S[2000], T[2000];
	rep(i, N) cin >> S[i];
	rep(i, M) cin >> T[i];

	ll mod = 1e9 + 7;
	ll dp[2001];
	ll dp2[2001] = {};

	rep(i, M + 1) dp[i] = 1;
	rep1(i, N) {
		rep1(j, M) {
			if (S[i - 1] == T[j - 1]) {
				dp2[j] = dp[j];
				dp[j] = dp[j - 1] + dp[j];
			}
			else {
				dp[j] = dp[j - 1] + dp2[j];
			}
		}
		rep1(j, M) {
			dp[j] %= mod;
			dp2[j] %= mod;
		}
	}
	co(dp[M] % mod);

	Would you please return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

struct RMQ {
  static const int MAX_N = 1 << 17;
  int n, dat[2 * MAX_N - 1];
  RMQ(int n_) { init(n_); }

  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    REP(i, 2 * n - 1) dat[i] = INT_MAX;
  }

  void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while (0 < k) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b)
      return dat[k];
    else {
      int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }

  int query(int a, int b) { return query(a, b, 0, 0, n); }
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ rmq(n);
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com)
      cout << rmq.query(x, y + 1) << endl;  // 注意
    else
      rmq.update(x, y);
  }
  return 0;
}


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

int main(){
    int h;
    while(cin >> h, h){
        int d[11][6] = {0};
        for(int i = 0; i < h; i++){
            for(int j = 0; j < 5; j++){
                cin >> d[i][j];
            }
        }
        int score = 0;
        bool f = true;
        while(f){
            f = false;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < 5; j++){
                    if(d[i][j] <= 0) continue;
                    int now = d[i][j];
                    int count = 1;
                    for(int k = j + 1; k < 5; k++){
                        if(d[i][k] == now) count++;
                        else break;
                    }
                    if(count >= 3){
                        f = true;
                        score += now * count;
                        for(int k = j; k < j + count; k++) d[i][k] = -1;
                        break;
                    }
                }
            }
            for(int i = 0; i < 5; i++){
                for(int j = h - 1; j > 0; j--){
                    if(d[j][i] != -1) continue;
                    for(int k = j - 1; k >= 0; k--){
                        if(d[k][i] > 0){
                            swap(d[j][i], d[k][i]);
                            break;
                        }
                    }
                }
            }
        }
        cout << score << endl;
    }
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "YES" : "NO");}
//----------------------------------------------------------------

int main(void) {
  ll n, k;
  cin >> n >> k;

  vector<pair<ll, ll>> v;
  rep(i,n){
    ll a, b;
    cin >> a >> b;
    v.pb(mp(a, b));
  }

  sortall(v);

  rep(i, v.size()){
    if(k>v[i].second) k-=v[i].second;
    else {prt(v[i].first); return 0;}
  }
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;  
#define REP(i,n) for(int i=0;i<(n);i++)  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl  
#define DIV 1000000007

int main(){
	ll input; cin >> input;
	ll ans = 0;
	ans = 2*(input / 11);
	if(input % 11 > 6)
		ans += 2;
	else if(input % 11)
		ans += 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = [s for s in map(int, input().split())]
num = 0
for i in range(n):
    x = a_list[i] / 2
    y = (i + 1) / 2
    if x != int(x) and y != int(y):
        num += 1
print(num)


Measured memory_bytes: 9168
# coding: utf-8
# Your code here!


    
def coll(n):    
    k=0
    while n>1:
        if n%2:
            n=n*3+1
            k+=1
        while n%2==0:
            n=n//2
            k+=1
    return k
    
while True:
    n=int(input())
    if n==0:
        break
    print(coll(n))


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

#define ll long long
#define mx 100005
int ar[mx];
char ch[mx];
int n,m;
void solve()
{
     ll val;
     scanf("%lld",&val);
     set<ll>s;
     for(ll i=1;i*i<=val-1;i++)
     {
         if((val-1)%i==0)
         {
             if(i!=1)s.insert(i);
             if((val-1)/i!=1)s.insert((val-1)/i);
         }
     }
     for(ll i=2;i*i<=val;i++)
     {
         ll tem=val;
         while(tem%i==0)
         {
            tem/=i;
            if((tem-1)%i==0)
            {
                s.insert(i);
                break;
            }
         }
     }
     printf("%d\n",s.size()+1);
}
int main()
{
    int t=1;
    while(t--)solve();
    return 0;
}


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

const ll MAX_N = 110;
const ll INF = 1e18;

int main(){
    ll N, W;
    cin >> N >> W;
    vector<P> things(N);
    rep(i, 0, N)cin >> things[i].first >> things[i].second;
    ll w1 = things[0].first;
    rep(i, 0, N) things[i].first -= w1;

    ll dp[MAX_N][3 * 110]; // dp[i][j] := i個の品物を買ったときの、重さw1*i+jの時の価値の最大値

    rep(i, 0, N + 1) rep(j, 0, 330) dp[i][j] = -INF;
    dp[0][0] = 0;
    ll ans = 0;

    rep(i, 0, N){
        rrep(k, 1, N + 1){
            rep(j, 0, 305){
                dp[k][j + things[i].first] = max(dp[k][j + things[i].first], dp[k-1][j] + things[i].second);
                //if(k * w1 + j + things[i].first <= W) ans = max(ans, dp[k][j + things[i].first]);
            }
        }
    }
    rep(i, 1, N + 1){
        rep(j, 0, N * 3 + 1) if(w1 * i + j <= W) ans = max(ans, dp[i][j]);
        /* rep(j, 0, N * 3  + 1){
            cout << dp[i][j] << " ";
        }
        cout << endl; */
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> diff;
    ll a_sum = 0;
    ll b_sum = 0;
    bool judge = 1;
    rep(i, N) { cin >> A[i]; }

    rep(i, N) { cin >> B[i]; }

    rep(i, N) {
        a_sum += A[i];
        b_sum += B[i];
        if (A[i] < B[i])
            judge = 0;
        if (A[i] >= B[i])
            diff.push_back(A[i] - B[i]);
    }

    if (judge) {
        cout << 0 << endl;
        return 0;
    }
    ll diff_sum = a_sum - b_sum;
    if (a_sum - b_sum < 0) {
        cout << -1 << endl;
        return 0;
    }
    ll res = 0;
    sort(diff.begin(), diff.end());
    rep(i, diff.size()) {
        if (diff_sum - diff[i] >= 0)
            diff_sum -= diff[i], res++;
    }

    res = N - res;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2936
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
 
public class Main{
 
    Scanner sc=new Scanner(System.in);;
 
    int INF=1<<28;
    double EPS=1e-9;
 
    int[][] a;
    int w, h;
    boolean[][] visited;
 
    void run(){
        for(;;){
            h=sc.nextInt();
            w=sc.nextInt();
            if((h|w)==0){
                break;
            }
            a=new int[h][w];
            visited=new boolean[h][w];
            for(int j=0; j<h; j++){
                String s=sc.next();
                for(int i=0; i<w; i++){
                    switch(s.charAt(i)){
                    case '@':
                        a[j][i]=0;
                        break;
                    case '#':
                        a[j][i]=1;
                        break;
                    case '*':
                        a[j][i]=2;
                        break;
                    }
                }
            }
            solve();
        }
    }
 
    void solve(){
        int ans=0;
        for(int j=0; j<h; j++){
            for(int i=0; i<w; i++){
                if(!visited[j][i]){
                    ans++;
                    bfs(i, j);
                }
            }
        }
        println(ans+"");
    }
 
    void bfs(int x, int y){
        LinkedList<P> que=new LinkedList<P>();
        que.offer(new P(x, y));
        visited[y][x]=true;
        int[] dx={0, 0, -1, 1};
        int[] dy={-1, 1, 0, 0};
        for(; !que.isEmpty();){
            P p=que.poll();
            for(int i=0; i<4; i++){
                P q=new P(p.x+dx[i], p.y+dy[i]);
                if(q.x>=0&&q.x<w&&q.y>=0&&q.y<h&&!visited[q.y][q.x]
                        &&a[p.y][p.x]==a[q.y][q.x]){
                    que.offer(q);
                    visited[q.y][q.x]=true;
                }
            }
        }
    }
 
    class P{
        int x, y;
 
        P(int x, int y){
            this.x=x;
            this.y=y;
        }
    }
 
    void debug(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
 
    void print(String s){
        System.out.print(s);
    }
 
    void println(String s){
        System.out.println(s);
    }
 
    public static void main(String[] args){
        new Main().run();
    }
}


Measured memory_bytes: 32608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author Y
 */
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int a;
        int c = 0;
        
        for(int i=0 ; i<N; i++){
            a = Integer.parseInt(br.readLine());
            
            if(a%2==0){
                if(a==2) c++;
            }else if(a%3==0){
                if(a==3) c++;
            }else if(a%7==0){
                if(a==7) c++;
            }else{
                for(int j = 2;j<=Math.sqrt(a);j++){
                    if(a%j == 0) break; 
                    if(j == Math.floor(Math.sqrt(a))) c++;
                }
            }  
        }
        System.out.println(c);
        
        
        
    }
}

Measured memory_bytes: 27676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b,c,d;
  cin >> n;
  a=n/1000;
  b=(n/100)%10;
  c=(n/10)%10;
  d=n%10;
  if((a==b && b==c)||(b==c && c==d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,m,ans,ask;
ll a[2000086];
ll xorsum[2000086],sum[2000086],r;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
}
   for(int i=1;i<=n;i++){
   	 if(i==1){xorsum[i]=a[i],sum[i]=a[i];}
   	 xorsum[i]=xorsum[i-1]^a[i];
   	 sum[i]=sum[i-1]+a[i];
   }
   r=1;
  // for(int i=1;i<=n;i++)
  // cout<<xorsum[i]<<" "<<sum[i]<<endl;
   for(int l=1;l<=n;l++){
   	 while(((xorsum[r]^xorsum[l-1])==(sum[r]-sum[l-1]))&&r<=n){
   	  r++;
   }
     r--;
   	 //printf("%d %d\n",l,r);
   	 ans+=(r-l+1);
   	 r++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 10112
using System;
using System.Text;

class Program
{
    public void Proc()
    {
        int itemCount = int.Parse(Console.ReadLine());
        int[] items = new int[itemCount];
        for (int i = 0; i < itemCount;i++)
        {
            items[i] = int.Parse(Console.ReadLine());
        }

        // ??????????????????
        int min = int.MaxValue;
        int max = int.MinValue;

        for(int i=0; i<items.Length; i++)
        {
            max = Math.Max(max, items[i] - min);
            min = Math.Min(min, items[i]);
        }
        Console.WriteLine(max);
    }


    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 10796
n = (int(x) for x in input().split())
a_list = list(map(int, input().split()))

even_list = []

i = 0

# 1. 偶数かどうか判定する
while i < len(a_list) : 
 div_a = a_list[i] % 2
 if div_a == 0 : 
  even_list.append(a_list[i])
 i = i + 1

# 2. 3または5で割れるか
j = 0
all_num = True

while j < len(even_list) :
 
 div_even = even_list[j] % 3 
 if div_even != 0 :
     div_even = even_list[j] % 5
     if div_even != 0 :
        all_num = False
        break

 j = j + 1

if all_num == True : 
 print('APPROVED')
else:
 print('DENIED')

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int i, j, k, n, q, S[100000], T[100000];
  k = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &S[i]);

  scanf("%d", &q);
  for(i = 0; i < q; i++) scanf("%d", &T[i]);

  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(T[i] == S[j]){
	k++;
	break;
      }
    }
  }

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

  return 0;
}

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

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

using namespace std;

signed main()
{
    int N;
    cin >> N;
    rep(i, 50000)
    {
        if (int(i * 1.08) == N)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

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


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> l(m);
    vector<int> r(m);
    for(int i=0;i<m;i++){
        cin>>l.at(i)>>r.at(i);
    }
    int lm=0,rm=n;
    for(int i=0;i<m;i++){
        lm=max(l.at(i),lm);
        rm=min(r.at(i),rm);
    }
    
    
    int a;
    a=lm;
    int b;
    b=rm;
    if(b-a+1<1){
        cout<<0<<endl;
    }
    else{
    cout<<b-a+1<<endl;
    }
}

Measured memory_bytes: 1024
INF = float('inf')
ans,d,g = 0,[],[]
n,m = map(int,input().split())
for i in range(n):
	d.append([])
	for j in range(n):
		d[i].append(0 if i == j else INF)

for i in range(m):
	a,b,c = map(int,input().split())
	a -= 1
	b -= 1
	g.append([a,b,c])
	d[a][b],d[b][a] = c,c

for k in range(n):
	for i in range(n):
		for j in range(n):
			d[i][j] = min(d[i][j],d[i][k]+d[k][j])

for e in g:
	if d[e[0]][e[1]] != e[2]:
		ans += 1

print(ans)


Measured memory_bytes: 3444
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	char input[200001];
	string s, t;
	int sol = 0;

	scanf("%s", input);
	s = input;
	scanf("%s", input);
	t = input;

	const int n = s.size();

	for (int i = 0; i < n; i++)
	{
		if (s[i] != t[i])
		{
			sol++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 3532
g=->k{k.times.map{gets.split.map &:to_i}};N,C=g[1][0];D=g[C];M=g[N];T=3.times.map{[0]*C};N.times{|y|N.times{|x|T[(y+x)%3][M[y][x]-1]+=1}};p [*0...C].permutation(3).map{|e|r=0;3.times{|i|C.times{|c|r+=T[i][c]*D[c][e[i]]}};r}.min

Measured memory_bytes: 6652
#include <iostream>

using namespace std;
using ll = long long;

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

  while(n) {
    if (n%10 == 7) {
      cout << "Yes" << endl;
      return 0;
    }
    n /= 10;
  }
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3596
def main():
    N,M = map(int,input().split())
    H = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(M)]
    ans = [0 for i in range(N)]
 
    for data in AB:
        if H[data[0]-1] <= H[data[1]-1]:
            ans[data[0]-1] = 1
        if H[data[0]-1] >= H[data[1]-1]:
            ans[data[1]-1] = 1
 
    print(ans.count(0))
 
 
if __name__ == "__main__":
    main()

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, k, a[10];
set< string > num_set;

void calc(vector< int >& vec) {
	do {
		stringstream ss;
		for_(i,0,k) ss << vec[i];
		num_set.insert(ss.str());
	} while (next_permutation(vec.begin(), vec.end()));
}

void dfs(int i, vector< int >& vec, int K) {
	if (i == n) {
		if (K == 0) calc(vec);
		return;
	}
	
	dfs(i + 1, vec, K);
	
	vec.push_back(a[i]);
	dfs(i + 1, vec, K - 1);
	vec.pop_back();
}

int main() {
	while (cin >> n >> k, n) {
		for_(i,0,n) cin >> a[i];
	
		sort(a, a + n);
		
		vector< int > vec;
		
		num_set.clear();
		dfs(0, vec, k);
		cout << num_set.size() << endl;
	}
}

Measured memory_bytes: 1492
#include <iostream>
#include <map>
#include <vector>
#include <utility>
using namespace std;

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

    vector<vector<int> > s(M);
    for(int i=0; i<M; ++i) { 
        int k; cin>> k;
        for(int j=0; j<k; ++j){
            int a; cin >> a; --a;
            s[i].push_back(a);
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; ++i) cin >> p[i];

    long long res = 0;
    for(int bit=0; bit<(1<<N); ++bit) {
        bool ok = true;
        for(int i=0; i<M; ++i) {
            int con = 0;
            for (auto v : s[i]){
                if(bit & (1<<v)) ++con;
            }
            if(con%2 != p[i]) ok = false;
        }
        if(ok) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define LL long long

const int MOD = 1000000007;
int n, a[100005];
int vis[100005];
LL fac[100005], inv[100005], facinv[100005];

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

LL C(LL n, LL m)
{
    if(n < 0 || m < 0 || m > n) return 0;
    return fac[n] * facinv[m] % MOD * facinv[n-m] % MOD;
}

int main()
{
    while(~scanf("%d", &n))
    {
        init();
        int l, r;
        memset(vis, 0, sizeof(vis));
        for(int i = 1; i <= n + 1; ++i)
        {
            scanf("%d", &a[i]);
            if(vis[a[i]] > 0)
            {
                r = i;
                l = vis[a[i]];
            }
            vis[a[i]] = i;
        }
        l--;
        r = n + 1 - r;
        for(int i = 1; i <= n; ++i)
        {
            if(i == 1)
            {
                printf("%d\n", n);
                continue;
            }
            LL a = C(n + 1, i);
            LL b = C(l + r, i - 1);
            a -= b;
            if(a < 0) a += MOD;
            printf("%lld\n",a);
        }
        printf("1\n");
    }
}


Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#define DCSB {printf("-1");exit(0);}
using namespace std;
vector<int>G[100010];
struct edge{
    int v,next;
}a[500001];
int n,m,u,v,ans=0,els,huanu,huanv,tot=0,q[500001],head[500001],fa[500001],dep[500001],f[500001];
void add(int u,int v){
    a[++tot].v=v;
    a[tot].next=head[u];
    head[u]=tot;
}
void dfs(int u,int ff,int dpt){
    dep[u]=dpt;
    fa[u]=ff;
    f[u]=(dpt%2)?1:-1;
    for(int i=0;i<(int)G[u].size();i++){
        int v=G[u][i];
        if(v!=ff){
            if(dep[v]){
                huanu=u;
                huanv=v;
                continue;
            }
            dfs(v,u,dpt+1);
            f[u]+=f[v];
        }
    }
}
void gao_tree(){
    if(f[1]!=0)DCSB
    for(int i=1;i<=n;i++)ans+=abs(f[i]);
    printf("%d",ans);
}
void gao_jihuan(){
    if(f[1]%2!=0)DCSB
    els=-f[1]/2;
    ans=abs(els);
    for(;huanu;huanu=fa[huanu])f[huanu]+=els;
    for(;huanv;huanv=fa[huanv])f[huanv]+=els;
    for(int i=1;i<=n;i++)ans+=abs(f[i]);
    printf("%d",ans);
}
void gao_ouhuan(){
    int top,mid;
    top=0;
    if(f[1])DCSB
    for(;huanv!=huanu;huanv=fa[huanv]){
        q[++top]=f[huanv];
        dep[huanv]=0;
    }
    sort(q+1,q+top+1);
    mid=q[(top+1)/2];
    ans=abs(mid);
    for(int i=1;i<=n;i++)if(dep[i])ans+=abs(f[i]);
    for(int i=1;i<=top;i++)ans+=abs(q[i]-mid);
    printf("%d",ans);
}
int main(){
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,0,1);
    if(m==n-1)gao_tree();
    else if((dep[huanv]-dep[huanu])%2==0)gao_jihuan();
    else gao_ouhuan();
    return 0;
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    string x;
    cin >> x;
    int res = 0;
    ff(j,0,2){
        if(x[j] == 'R')res = 1;
    }
    ff(j,0,1){
        if(x[j] == x[j + 1] && x[j + 1] == 'R')res = 2;
    }
    if(x[0] == x[1] && x[1] == x[2] && x[2] == 'R')res = 3;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;

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

	cin>>n>>d;
	if(n%(d*2+1) == 0){
		cout<<n/(d*2+1);
	}
	else{
		cout<<n/(d*2+1)+1;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	int a,b ,c, d;
	cin >> a >>b  >>c >> d;
	int i = 0;
	while(a != 0 && c != 0){
		if(i % 2 == 0){
			// 高橋君の攻撃
			c -= b;
		} else {
			a -= d;
		}
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		if( a <= 0){
			cout << "No" << endl;
			return 0;
		}
		i ++;
	}
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, K, Q, T;

ll gcd(ll a, ll b) {
	if (b == 0ll) return a;
	return gcd(b, a%b);
}

int main()
{
	int i, j;
	ll x, M;
	scanf("%d%lld", &N, &M);
	set<ll> st;
	scanf("%lld", &x);
	int cnt2 = 0;
	while (x % 2 == 0) {
		x /= 2;
		++cnt2;
	}
	st.insert(x);
	for(i = 2; i<= N; ++i){
		scanf("%lld", &x);
		if (st.count(x) == 0) {
			int k = 0;
			while (x % 2 == 0) {
				x /= 2;
				++k;
			}
			st.insert(x);
			if (k != cnt2) {
				printf("0");
				return 0;
			}
		}
	}
	ll lcm = 1ll;
	for (auto &e : st) {
		ll a = lcm;
		ll b = e;
		if (a < b) swap(a, b);
		ll g = gcd(a, b);
		lcm *= e / g;
		if (lcm > M) {
			printf("0");
			return 0;
		}
	}
	ll num = 1ll;
	--cnt2;
	while (cnt2) {
		num <<= 1;
		--cnt2;
	}
	ll ans = ((M / lcm) /num + 1ll) / 2ll;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4992
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum[] = new int[3];
		int nums[] = new int[3];
		for (int i = 0; i < n; i++) {
			nums[0] = sc.nextInt();
			nums[1] = sc.nextInt();
			nums[2] = sc.nextInt();
			if( i == 0) {
				sum[0] = nums[0];
				sum[1] = nums[1];
				sum[2] = nums[2];
			}
			else {
				int[] newSum = new int[3];
				for(int j = 0; j < 3; j++) {
					for(int t = 0; t < 3; t++) {
						if(j != t)
							newSum[j] = Math.max(newSum[j], nums[j]+sum[t]);
					}
				}
				sum = new int[3];
				sum = newSum.clone();
				newSum = new int[3];
			}
		}
		System.out.println(Math.max(sum[0], Math.max(sum[1], sum[2])));
	}
}


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

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

  string s;
  cin >> s;
  vector<string> t = {"dream", "dreamer", "erase", "eraser"};
  int l = s.size();
  while (!s.empty()) {
    bool flag = false;
    for (string &x : t) {
      if (s.size() < x.size()) continue;
      if (s.substr(s.size()-x.size(), x.size()) == x) {
        s.erase(s.size()-x.size(), x.size());
        flag = true;
      }
    }
    if (!flag) {
      cout << "NO" << '\n';
      return 0;
    }
  }
  cout << "YES" << '\n';
  return 0;
}

Measured memory_bytes: 512