akhauriyash/Code-Regression huggingface dataset:
n=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
def sub_junretu(num,sub_arr,arr):
    #print("call sub_junretu")
    
    
    
    for i in range(1,num+1):
        if i in sub_arr:
            continue
        tmp=sub_arr.copy()
        #print("sub_arr:",sub_arr)
        #print("tmp:",tmp)
        #print("sub_num:",i)
        tmp.append(i)
        #print("rec")
        sub_junretu(num,tmp,arr)
    #arr.append(sub_arr)
    #print("sub end")
    if len(sub_arr)==num:
        arr.append(sub_arr)
    #return arr
def junretu(num,arr):
    for i in range(1,num+1):
        sub_junretu(num,[i],arr)
    return arr

arr=junretu(n,[])
for num,k in enumerate(arr):
    if P==k:
        p=num
    if Q==k:
        q=num
print(abs(p-q))

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

int top, S[1000];

void init_stack()
{
	top = -1;
}

void push(int v)
{
	S[++top] = v;
}

int pop()
{
	return S[top--];
}

int do_op(int a, int b, char op)
{
	int r = 0;
	
	switch (op) {
	case '+':
		r = a + b;
		break;
	case '-':
		r = a - b;
		break;
	case '*':
		r = a * b;
		break;
	}
	
	return r;
}

int main(int argc, char *argv[]) 
{
	char a[100];
	int op1, op2;

	init_stack();
	while (scanf("%s", a) != EOF) {
		if (isdigit(*a)) {
			push(atoi(a));
		} else {
			op2 = pop();
			op1 = pop();
			push(do_op(op1, op2, *a));
		} 
	}
	
	printf("%d\n", pop());
	
	return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int maxn=a[0];
    int minn=a[0];
    for(int i=0;i<N;i++){
        if(maxn<a[i]){
            maxn=a[i];
        }
        if(minn>a[i]){
            minn=a[i];
        }
    }
    cout<<maxn-minn<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
typedef long long lint;

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            ++cnt;
        }
    }
    if (cnt%2 == 1) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

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

int main(){
    ll n,W,ans=0,w0;
    cin >> n >> W;
    vector<ll> v[4];
    for(int i = 0;i < n;i ++){
        ll x,y;
        cin >> x >> y;
        if(!i) v[0].push_back(y),w0=x;
        else{
            v[x-w0].push_back(y);
        }
        
    }
    for(int i = 0;i < 4;i ++){
        sort(v[i].begin(),v[i].end());
    }
    vector<ll> s[4];
    for(int i = 0;i < 4;i ++){
        s[i].push_back(0);
        for (int j = v[i].size()-1;j >= 0;j --){
            s[i].push_back(s[i].back()+v[i][j]);
        }
    }
    for(int i0 = 0;i0 <= v[0].size();i0 ++){
        for(int i1 = 0;i1 <= v[1].size();i1 ++){
            for(int i2 = 0;i2 <= v[2].size();i2 ++){
                for(int i3 = 0;i3 <= v[3].size();i3 ++){
                     ll sumv = s[0][i0]+s[1][i1]+s[2][i2]+s[3][i3];
                     ll sumw = i0*w0+i1*(w0+1)+i2*(w0+2)+i3*(w0+3);
                     if(sumw<=W) ans = max(ans,sumv);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
char ans[1010][1010];
void fil(int mx, int my, int a, int b)
{
	for (int i = 0; i < mx; i += 2)
	{
		for (int j = 0; j < my; j += 2)
		{
			if (a > 0)
			{
				if (a >= 2)ans[i][j] = '<', ans[i][j + 1] = '>', ans[i + 1][j] = '<', ans[i + 1][j + 1] = '>';
				else ans[i][j] = '<', ans[i][j + 1] = '>';
				a = max(0, a - 2);
			}
			else
			{
				if (b >= 2)ans[i][j] = '^', ans[i][j + 1] = '^', ans[i + 1][j] = 'v', ans[i + 1][j + 1] = 'v';
				else if (b >= 1)ans[i][j] = '^', ans[i + 1][j] = 'v';
				b = max(0, b - 2);
			}
		}
	}
}
int main()
{
	int mx, my, a, b;
	scanf("%d%d%d%d", &mx, &my, &a, &b);
	for (int i = 0; i < mx; i++)for (int j = 0; j < my; j++)ans[i][j] = '.';
	bool f = true;
	if (mx % 2 == 0 && my % 2 == 0)
	{
		if ((a + b) * 2 > mx*my || ((a + b) * 2 == mx*my&&a % 2 == 1))f = false;
		else fil(mx, my, a, b);
	}
	else if (mx % 2 == 0 && my % 2 == 1)
	{
		if ((a + b) * 2 > mx*my || ((a + b) * 2 == mx*my&&a % 2 == 1) || a * 2 > (my - 1)*mx)f = false;
		else
		{
			for (int i = 0; i < min(mx / 2, b); i++)ans[i * 2][my - 1] = '^', ans[i * 2 + 1][my - 1] = 'v';
			fil(mx, my - 1, a, max(0, b - mx / 2));
		}
	}
	else if (mx % 2 == 1 && my % 2 == 0)
	{
		if ((a + b) * 2 > mx*my || ((a + b) * 2 == mx*my&&b % 2 == 1) || b * 2 > (mx - 1)*my)f = false;
		else
		{
			for (int i = 0; i < min(my / 2, a); i++)ans[mx - 1][i * 2] = '<', ans[mx - 1][i * 2 + 1] = '>';
			fil(mx - 1, my, max(0, a - my / 2), b);
		}
	}
	else
	{
		if ((a + b) * 2>mx*my || a * 2 > (my - 1)*mx || b * 2 > (mx - 1)*my)f = false;
		else
		{
			if ((a + b) * 2 <= mx*my - 3 || my / 2 % 2 == a % 2)
			{
				for (int i = 0; i < min(mx / 2, b); i++)ans[i * 2][my - 1] = '^', ans[i * 2 + 1][my - 1] = 'v';
				for (int i = 0; i < min(my / 2, a); i++)ans[mx - 1][i * 2] = '<', ans[mx - 1][i * 2 + 1] = '>';
				fil(mx - 1, my - 1, max(0, a - my / 2), max(0, b - mx / 2));
			}
			else
			{
				for (int i = 0; i < min(mx / 2 - 1, b); i++)ans[i * 2][my - 1] = '^', ans[i * 2 + 1][my - 1] = 'v';
				for (int i = 0; i < min(my / 2 - 1, a); i++)ans[mx - 1][i * 2] = '<', ans[mx - 1][i * 2 + 1] = '>';
				a = max(0, a - my / 2 + 1), b = max(0, b - mx / 2 + 1);
				if (a > 0)ans[mx - 3][my - 3] = '<', ans[mx - 3][my - 2] = '>', a--;
				if (a > 0)ans[mx - 1][my - 2] = '<', ans[mx - 1][my - 1] = '>', a--;
				if (b > 0)ans[mx - 3][my - 1] = '^', ans[mx - 2][my - 1] = 'v', b--;
				if (b > 0)ans[mx - 2][my - 3] = '^', ans[mx - 1][my - 3] = 'v', b--;
				fil(mx - 1, my - 1, a, b);
			}
		}
	}
	if (!f)printf("NO\n");
	else
	{
		printf("YES\n");
		for (int i = 0; i < mx; i++)
		{
			for (int j = 0; j < my; j++)printf("%c", ans[i][j]);
			printf("\n");
		}
	}
}

Measured memory_bytes: 2176
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int main(){
    fastio
    int n ; 
    cin >> n ; 
    int cur = 1 ;
    int ans = 0 ; 
    for(int i = 0; i < n; i++){
        int x ;
        cin >> x ; 
        if ( x == cur ) {
            cur++ ; 
            ans++ ; 
        }
    }
    if ( ans == 0 ) cout << -1 << endl;
    else cout << n - ans << endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000
#define ulinf 10000000000000000000ull
#define MOD 1000000007
#define lson(v) ((v)<<1)
#define rson(v) (((v)<<1)^1)
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[100005],dep[100005],fa[100005],res=0;
vector < pii > adj[100005];
int dfs(int ver){
	int xb,ret=0;
	for(xb=0;xb<adj[ver].size();++xb){
		adj[ver][xb].first=dfs(adj[ver][xb].second);
	}
	sort(adj[ver].begin(),adj[ver].end());
	for(xb=adj[ver].size()-1;xb>=0;--xb){
		ret=MAX(ret,(int)adj[ver].size()-xb+adj[ver][xb].first);
	}
	return ret;
}
int main(){
    // inputing start
    int xb,x2;
	scanf("%d",&n);
	for(xb=1;xb<n;++xb){
		scanf("%d",a+xb);
		adj[--a[xb]].push_back(make_pair(0,xb));
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
	printf("%d\n",dfs(0));
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

int abc[128];
int main() {
    string S;
    cin >> S;
    set<char> lset;
    for(int i; i< S.size();++i){
        lset.insert(S[i]);
        abc[S[i]- 'A'] ++;
    }

    if( lset.size() == 2){
        for(int i;i<26;++i){
            if(abc[i] != 0 && abc[i] != 2){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    };
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll X;
    cin >> X;
    int a;
    for(int i = X;;i++){
        a = i;
        for(int l = 2;l*l<=i;l++){
            if(a%l == 0)a/=l;
        }
        if(a == i)break;
    }
    cout << a << "\n";
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());

        // 主処理
        while (!isPrime(x)) {
            x += x % 2 == 0 ? 1 : 2;
        }

        long result = x;

        // 出力
        System.out.println(result);
        sc.close();
    }

    public static boolean isPrime(long num) {
        if (num == 2) {
            return true;
        } else if (num < 2 || num % 2 == 0) {
            return false;
        }
        double sqrtNum = Math.sqrt(num);
        for (long i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr double PI = 3.1415926535;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    H = H*60 + M;
    double theta1 = H / 720 * 2 * PI;
    double theta2 = M / 60 * 2 * PI;
    double x1 = A*sin(theta1);
    double y1 = A*cos(theta1);
    double x2 = B*sin(theta2);
    double y2 = B*cos(theta2);
    double dist = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    cout << setprecision(10) << sqrt(dist) << endl;
}

Measured memory_bytes: 4116
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
// const ll MOD = 1e9 + 7 ;
const ll MOD = 998244353 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int fast(int a, int b){
    if ( b == 0 ) return 1; 
    if ( b == 1 ) return a ;
    int y = fast(a, b / 2) % MOD ;
    int ans = 1; 
    if ( b & 1 ) ans = a ;
    int result = y * y ; 
    result %= MOD ;
    result *= ans ;
    return result % MOD ;
}
int inverse(int x){
    return fast(x, MOD - 2) ;
}
signed main(){
    fastio
    int n , m , k ;
    cin >> n >> m >> k ; 
    vector<int> fact(n + 1) ;
    fact[0] = fact[1] = 1 ;
    for(int i = 2; i < n + 1; i++){
        fact[i] = i * fact[i - 1] ;
        fact[i] %= MOD ;
    }
    auto C = [&](int A, int B){
        int ans = fact[A] * inverse(fact[B])  ;
        ans %= MOD ;
        ans *= inverse(fact[A - B]) ;
        ans %= MOD ;
        return ans ;
    };
    int ans = 0 ;
    for(int i = 0; i < k + 1; i++){
        int t = m * C(n - 1, i) ;
        t %= MOD ;
        t *= fast(m - 1, n - 1 - i) ; 
        t %= MOD ;
        ans += t ;
        ans %= MOD;
    }
    cout << ans << endl ; 
    return 0; 
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    if (a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        String s = sc.next();
        switch (s) {
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");
                break;
        }
    }
}



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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) { cin >> S.at(i); }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
}


Measured memory_bytes: 9604
N, W = list(map(int,raw_input().split()))
dp = [0 for i in range(W+1)]
for i in range(N):
  wi, vi = list(map(int,raw_input().split()))
  for w in range(W-wi, -1, -1):
    dp[w+wi] = max(dp[w+wi],dp[w]+vi)
print(max(dp))

Measured memory_bytes: 33132
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];

    ll sum[200200];
    sum[0] = 0;
    for(ll i = 1; i <= 200010; i++){
        sum[i] += sum[i - 1] + i;
    }

    ld kitai[200200];
    for(int i = 0; i < n; i++){
        kitai[i] = (ld)sum[p[i]] / (ld)p[i];
    }

    ld kitaisum[200200];
    kitaisum[0] = 0;
    for(int i = 1; i <= n; i++){
        kitaisum[i] = kitaisum[i - 1] + kitai[i - 1];
    }

    int l = 0; 
    int r = k;

    ld ans = kitaisum[k] - kitaisum[0];
    while(r <= n){
        r++;
        l++;
        ans = max(ans, kitaisum[r] - kitaisum[l]);
        if(r == n + 1){
            break;
        }

    }

    cout << fixed << setprecision(15) << ans << endl;

}

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

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef map<string, int> maps;
typedef map<int, int> mapi;

#define db double
#define add push_back
#define rem pop_back
#define mod 1000000007
#define all(a) a.begin(), a.end()
#define sz(a) int((a).size())
#define BS(i, j, k) binary_search(i, j, k)
#define prec(n) fixed<<setprecision(n)

void input(int *a, int size)  { for(int i = 0; i < size; ++i) cin >> a[i]; }
void output(int *a, int size) { for(int i = 0; i < size; ++i) cout << a[i] << " "; cout<<endl; }

#define repi(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define rep(i, a, b)  for(int i = a; i <  b; i++)
#define repn(i, a, b) for(int i = a; i <= b; i++)
#define repv(i, b, a) for(int i = b - 1; i >= a; i--)
#define _1 first
#define _2 second

const double EPS = 1e-9;
const double PI = acos(-1.);
const int MOD = 1e9 + 7;
const int MAXN = 320001;
int INF = __INT64_MAX__;
int MAX = -1e9;
int MIN = 1e9;
string YN[] = {"NO", "YES"};

bool isPrime(int n)
{
          if (n <= 1)  return false;
          if (n <= 3)  return true;

          if (n%2 == 0 || n%3 == 0) return false;

          for (int i=5; i*i<=n; i=i+6)
                    if (n%i == 0 || n%(i+2) == 0)
                              return false;
          return true;
}
int n, m, pref1[MAXN], pref2[MAXN], cnt;
string s;
void solution()
{
		cin >> n >> s;
		if(s[0] == 'E')
			pref1[0] = 1;
		if(s[0] == 'W')
			pref2[0] = 1;
		for(int i = 1; i < n; i++){
			pref1[i] = pref1[i - 1] + (s[i] == 'E');
			pref2[i] = pref2[i - 1] + (s[i] == 'W');
		}
		for(int i = 0; i < n; i++){
			if(s[i] == 'E'){
				cnt = pref2[i] + pref1[n - 1] - pref1[i];
				MIN = min(MIN, cnt);
			}
			if(s[i] == 'W'){
				cnt = pref2[i] - 1 + pref1[n - 1] - pref1[i];
				MIN = min(MIN, cnt);
			}
			//cout << MIN << endl;
		}
		cout << MIN;
}
__INT16_C() main()
{
          ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
          int t = 1;
          //cin >> t;
          while(t--) solution();
}


Measured memory_bytes: 3092
N, K = map(int, input().split())
*a, = map(int, input().split())
MOD = 10**9+7

dp = [[0]*(K+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 1

sums = [0]*(K+2)
for i in range(1, N+1):
    sums[0] = 0
    for j in range(1, K+2):
        sums[j] = (dp[i-1][j-1]+sums[j-1]) % MOD

    for j in range(1, K+1):
        sj = max([0, j-a[i-1]])
        dp[i][j] = (sums[j+1]-sums[sj]+MOD) % MOD

print(dp[N][K])


Measured memory_bytes: 119404
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

    if(n<=999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = 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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  ll W,H,x,y;
  cin>>W>>H>>x>>y;
  cout<<fixed<<setprecision(10)<<(double)W*H/2;
  if(W%2==0 && H%2==0){
    if(W/2==x&&H/2==y){
      cout<<' '<<1<<endl;
    }else{
      cout<<' ' << 0<<endl;
    }
  }else{
    cout<<' ' << 0<<endl;
  }
}

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

#pragma GCC optimization ("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

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-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set



int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	int x; cin >> x; cout << (x ? 0 : 1) << endl;
}
/**

*/

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    string s;
    cin>>s;
    int l=s.size();
    if(s[l-1]!='s') s+='s';
    else s+="es";
    cout<<s<<endl;

}

Measured memory_bytes: 3656
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++)
			a[i] = scanner.nextInt();
		int minStamina = (1 << 30);
		for(int p = 1, stamina ; p <= 100 ; p++)
		{
			stamina = 0;
			for(int i = 0 ; i < n ; i++)
				stamina += (a[i] - p) * (a[i] - p);
			minStamina = Math.min(minStamina, stamina);
		}
		System.out.println(minStamina);
		scanner.close();
	}
}

Measured memory_bytes: 21844
#include"bits/stdc++.h"
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define D(i,j,n) for(register int i=j;i>=n;i--)
#define ll long long
#define N 140000
#define lc ch[x][0]
#define rc ch[x][1]
using namespace std;
void in(int&a);void in(ll&a);
int n,w[N],ch[N][2],fff;
ll l=0,r=1ll<<33,m;vector<ll>p[N];
void up(int x){
	ll l=m-w[lc]-w[rc],q=1ll<<33;
	if(p[lc].empty()||p[rc].empty())return;
	int n=p[lc].size(),m=p[rc].size(),a=0,b=0,c=0,d=0;
//	if(fff==1){printf("%d\n",x);F(i,0,n-1)printf("%lld ",p[lc][i]+w[lc]);puts("");F(i,0,m-1)printf("%lld ",p[rc][i]+w[rc]);puts("");}
	ll xa,ya,xb,yb;
	while(a<n||b<m){
		while(a<n&&c<m&&p[lc][a]+p[rc][m-1-c]>l)c++;
//	if(fff==1)printf("%d %d %d %d %d %d\n",n,m,a,b,c,d);
		while(a<n-1&&c<m&&p[lc][a+1]+p[rc][m-1-c]<=l)a++;
//	if(a<n&&c<m&&fff==1)printf("%lld %lld\n",p[lc][a],p[rc][m-1-c]);
//	if(a<n-1&&c<m&&fff==1)printf("%lld %lld\n",p[lc][a+1],p[rc][m-1-c]);
		while(b<m&&d<n&&p[rc][b]+p[lc][n-1-d]>l)d++;
		while(b<m-1&&d<n&&p[rc][b+1]+p[lc][n-1-d]<=l)b++;
//	if(b<m&&d<n&&fff==1)printf("%lld %lld\n",p[rc][b],p[lc][n-1-d]);
//	if(fff==1)printf("%d %d %d %d %d %d\n",n,m,a,b,c,d);
		if(c>=m&&d>=n)return;
		xa=xb=ya=yb=1ll<<33;
		if(a<n&&c<m)xa=p[rc][c]+w[rc],ya=p[lc][n-1-a]+w[lc];
		if(b<m&&d<n)xb=p[lc][d]+w[lc],yb=p[rc][m-1-b]+w[rc];
//	if(fff==1)printf("%lld %lld %lld %lld\n",xa,xb,ya,yb);
		if(xa<xb||(xa==xb&&ya<yb)){
			if(ya<q)p[x].push_back(xa),q=ya;
			a++;c++;
		}
		else{
			if(yb<q)p[x].push_back(xb),q=yb;
			b++;d++;
		}
	}
}
void dfs(int x){
	if(!lc){return;}
	p[x].clear();
	dfs(lc);if(p[lc].empty())return;
	dfs(rc);up(x);
//	if(fff==1){printf("%d %d\n",x,p[x].size());if(!p[x].empty())F(i,0,p[x].size()-1)printf("%d ",p[x][i]);puts("\n");}
}
bool check(){
//fff=m==224;
//fff=(m<=20);if(fff==1)printf("\n%d\n",m);
dfs(1);return !p[1].empty();}
int main()
{
	in(n);int fa;
	F(i,2,n){
		in(fa);in(w[i]);
		ch[fa][!!ch[fa][0]]=i;
	}
//	F(x,1,n)printf("%d %d %d %d\n",x,w[x],lc,rc);
	F(x,1,n)if(!lc)p[x].push_back(0);
	while(l<=r){
		m=l+r>>1;
		if(check())r=m-1;
		else l=m+1;
	}
	printf("%lld\n",l);
//	int ans=w[2]+w[5]+w[3]+w[6];for(int j=9;j<=n;j+=4)ans=max(ans,w[j]+w[j-4]+w[j-5]);for(int j=10;j<=n;j+=4)ans=max(ans,w[j]+w[j-4]+w[j-3]);printf("%d\n",ans);
	return 0;
}
void in(ll&a){register char c;register bool y=false;c=getchar();a=0;
while(c<'0'||c>'9'){if(c=='-'){c=getchar();y=true;break;}c=getchar();}
while(c>='0'&&c<='9'){a=(a<<3)+(a<<1)+c-'0';c=0;c=getchar();}if(y)a=-a;}
void in(int&a){register char c;register bool y=false;c=getchar();a=0;
while(c<'0'||c>'9'){if(c=='-'){c=getchar();y=true;break;}c=getchar();}
while(c>='0'&&c<='9'){a=(a<<3)+(a<<1)+c-'0';c=0;c=getchar();}if(y)a=-a;}


Measured memory_bytes: 18556
n = int(input())
p_list = list(map(int, input().split()))
m = 0

for i in range(0, n - 2):
    if (p_list[i] > p_list[i + 1] and p_list[i + 1] > p_list[i + 2]) or (p_list[i] < p_list[i + 1] and p_list[i + 1] < p_list[i + 2]):
        m += 1

print(m)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
#define umap unordered_map
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;
#define oorret true //std::out_of_rangeが返された時
#define oor(x) [&](){try{x;} catch(const std::out_of_range& oor){return oorret;} return x;}()
double pi = 3.141592653589793238;
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up
int D;
void calculate(vector<int> c, vector<vector<int>> s, int contest,int day, vector<int> &t, ll &score){
    ll p=0;
    int a[26];
    rep(i, 26){
        a[i]=0;
    }
    rep(i, D){
        rep(j, 26){
            p-=c[j]*(i+1-a[j]);
        }
        if(i!=day){
            p+=s[i].at(t[i])+c[t[i]]*(i+1-a[t[i]]);
            a[t[i]]=i+1;
        }else{
            p+=s[day].at(contest)+c[contest]*(day+1-a[contest]);
            a[contest]=i+1;
        }
        
    }
    if(score<p){
        score=p;
        t[day]=contest;
    }
}

int main(){
cin>>D;
vector<int> c(26);
rep(i, 26){
    cin>>c[i];
}
vector<vector<int>> s(D);
int r;
rep(i, D){
    rep(j, 26){
        cin>>r;
        s[i].push_back(r);
    }
}
int M[26];
rep(i, 26){
    M[i]=0;
}
vector<vector<int>> m(D);
rep(i, D){
    rep(j, 26){
        m[i].push_back(0);
    }
}
vector<int> a(26);

rep(i, 26){
    a[i]=0;
}
rep(i, D){
}
vector<int> t(D);
ll score=0;
rep(i, D){
    rep(j, 26){
        M[j]=0;
    }
    rep(j, 26){
        score-=c[j]*(i+1-a[j]);
        rep(k, j+1){
            if(s[i].at(j)+c[j]*(i+1-a[j])>M[k]){
                rep(l, j-k){
                    M[j-l]=M[j-l-1];
                    m[i].at(j-l)=m[i].at(j-l-1);
                }
                M[k]=s[i].at(j)+c[j]*(i+1-a[j]);
                m[i].at(k)=j;
                break;
            }
        }
    }
    score+=M[0];
    a[m[i].at(0)]=i+1;
    t[i]=m[i].at(0);
}
rep(j, 20){
    rep(i, j+2){
        rep(k, D){
            calculate(c, s, m[k].at(i),k, t, score);
        }
    }
}
rep(i, D){
    cout<<t[i]+1<<endl;
}
}


Measured memory_bytes: 3792
import math
cos=math.cos
sin=math.sin

def solve(x):
    p=math.pi
    z=x/360*p*2
    
    X,Y=0,0
    for i in range(10**5):
        X+=cos(z*i)
        Y+=sin(z*i)
        if X**2+Y**2<10**-6:
            #print(x,i+1,x*(i+1))
            return i+1
            break

x=int(input())
print(solve(x))


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int n;
    cin>>n;
    //bool like[n][n];
    int a[n+1];
    rep2(i,n){
        cin>>a[i];
    }
    int ans=0;
    rep2(i,n){
        if(a[a[i]]==i && i<a[i])ans++;
    }
    cout<<ans<<endl;




    return 0;

}
/*


*/


Measured memory_bytes: 640
n = int(input())
if n == 1:
    print(1)
    exit()

l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append([x, y])

res = 10 ** 100
for i in range(n):
    for j in range(i + 1, n):
        sa = []
        invalid = False
        for p,q in zip(l[i], l[j]):
            sa.append(p - q)

        cnt = 0
        flag = [False] * n
        for p in range(n):
            if not flag[p]:
                cnt += 1
            flag[p] = True
            nxt = [l[p][0] + sa[0], l[p][1] + sa[1]]
            for q in range(n):
                if l[q] == nxt:
                    if flag[q]:
                        cnt -= 1
                    else:
                        flag[q] = True
        
        # cnt = 0
        # flag = [False] * n
        # for p in range(n):
        #     if flag[p]:
        #         continue
        #     cnt += 1
        #     flag[p] = True
        #     for q in range(p + 1, n):
        #         if flag[q]:
        #             continue
        #         sb = []
        #         for a,b in zip(l[p], l[q]):
        #             sb.append(a - b)
                
        #         if sa[0] == 0:
        #             if sb[0] == 0 and sb[1] % sa[1] == 0:
        #                 flag[q] = True
        #         elif sa[1] == 0:
        #             if sb[1] == 0 and sb[0] % sa[0] == 0:
        #                 flag[q] = True
        #         else:
        #             if sb[0] % sa[0] == 0 and sb[1] % sa[1] == 0:
        #                 if sb[0] // sa[0] == sb[1] // sa[1]:
        #                     flag[q] = True
        res = min(res, cnt)
print(res)

Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * A - Strings
 * 英小文字のみからなる 2 つの文字列 S, T が与えられます。
 * これらの文字列を T, S の順に空白を空けずに連結し、できる文字列を出力してください。
 */
public class Main {

    public static void main( String[] args ) {

        // 入力値
        Scanner sc = new Scanner( System.in );
        String s = sc.next();   // 文字列S
        String t = sc.next();   // 文字列T

        System.out.println( t.concat( s ) );

        sc.close();
    }
}

Measured memory_bytes: 35504
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
const double PI = 3.14159265359;

int main()
{
    LLONG N, M, K; cin >> N >> M >> K;
    vector<LLONG> as(N), bs(M);
    for (int i = 0; i < N; ++i) cin >> as[i];
    for (int i = 0; i < M; ++i) cin >> bs[i];
    vector<LLONG> aSum(N + 1), bSum(M + 1);
    LLONG sum = 0;
    aSum[0] = bSum[0] = 0;
    for (int i = 0; i < N; ++i)
    {
        sum += as[i]; aSum[i + 1] = sum;
    }
    sum = 0;
    for (int i = 0; i < M; ++i)
    {
        sum += bs[i]; bSum[i + 1] = sum;
    }
    LLONG ans = 0;
    for (LLONG aNum = 0; aNum <= N; ++aNum)
    {
        if (aSum[aNum] > K) break;
        LLONG bNum = distance(bSum.begin(),
            upper_bound(bSum.begin(), bSum.end(), K - aSum[aNum])) - 1;
        ans = max(ans, aNum + bNum);
    }
    cout << ans << endl;
}


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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		 // 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({ a, ex });
	}

	// 最後に残った数について
	if (N != 1) res.push_back({ N, 1 });
	return res;
}

int main() {	

	ll a; cin >> a;

	vector<pair<long long, long long>> a_prime;  // a^x ならば { a, x }
	a_prime = prime_factorize(a);
	ll ans = 0;
	for (ll i = 0; i < a_prime.size(); i++) {
		ll tmpSum = 1;
		ll tmp = 1;
		while (true) {
			if (tmpSum <= a_prime[i].second) {
				ans++;
				tmp++;
				tmpSum += tmp;
			}
			else {
				break;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A = int(input())
    B = int(input())
    if A > B:
        print('GREATER')
    elif A < B:
        print('LESS')
    else:
        print('EQUAL')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define _ <<" "<<
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
const int N = 1e5 + 10;

int main()
{
    Fast_IO();

    int n , m ;
    cin >> n >> m ;
    vector<vi> vec(N) ;
    multiset<int>ms ; 
    for ( int i = 0 ; i < n ; ++ i )
    {
    int  a , b ;
    cin >> a >> b ;

        vec[a].pb(b);
    }
    int res = 0 ;
    for ( int day = m - 1 ; day >= 0 ; --day )
    {
        for (int x : vec[m - day ])
        ms.insert(x); 
        if (!ms.empty()){
        	res += *prev(ms.end());
            ms.erase(prev(ms.end()));

        	
        }
        
    }
    cout << res ;
    return 0 ;
}










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


int main() {

    int n, d;
    cin>>n;
    d=2*n;

    int a[d], count=0;

    for(int i=0; i<d; i++) cin>>a[i];


    sort(a, a+d);

    for(int i=0; i<d; i+=2){
        count+=a[i];
    }

    cout<<count<<endl;

}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
}

Measured memory_bytes: 384
from collections import deque

INF = 10**6
n, m = map(int, input().split())
path = {i: [] for i in range(1, n+1)}
for i in range(m):
    a, b = map(int, input().split())
    path[a].append(b)
    path[b].append(a)

dist = [INF for i in range(n+1)]
dist[1] = 0
ans = [0 for i in range(n+1)]
que = deque([1])

while len(que) > 0:
    p = que.popleft()
    for r in path[p]:
        if dist[r] == INF:
            dist[r] = dist[p] + 1
            ans[r] = p
            que.append(r)

print('Yes')
for a in ans[2:]:
    print(a)

Measured memory_bytes: 103612
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

const int MAX_N = 202020;
vector<int>e[MAX_N + 5],er[MAX_N + 5];
int fin[MAX_N + 5],li[MAX_N + 5],state[MAX_N + 5];
int cnt = 0;
void dfs1(int now) {
	state[now] = 1;
	fore(x, e[now]) {
		if (state[x] == 0) {
			cnt++;
			dfs1(x);
		}
	}
	cnt++;
	fin[now] = cnt;
}
void dfs2(int now,int num) {
	state[now] = 1;
	li[now] = num;
	fore(x, er[now]) {
		if (state[x] == 0)dfs2(x,num);
	}
}
void scc(int N){
	//各頂点について終了時間を計算
	for (int i = 0; i < N; i++) {
		if (state[i] == 0)dfs1(i);
	}
	//逆辺を計算
	for (int i = 0; i < N; i++) {
		fore(x, e[i])er[x].pb(i);
	}

	for (int i = 0; i < N; i++)state[i] = 0;

	//終了時間の降順でdfsをしていく
	vector<pair<int, int>>finli;
	for (int i = 0; i < N; i++) {
		finli.pb({fin[i],i});
	}
	sort(all(finli));
	reverse(all(finli));
	int num = 0;
	for (int i = 0; i < N; i++) {
		int v = finli[i].second;
		if (state[v] == 0) {
			dfs2(v, num);
			num++;
		}
	}
}

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

	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		int s, t;
		cin >> s >> t;
		e[s].pb(t);
	}
	scc(V);

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int u, v;
		cin >> u >> v;
		puts((li[u] == li[v]));
	}

	return 0;
}


Measured memory_bytes: 13812
def dist(a,b,c,d,n):
    L=3**n
    area1=(a//L)*3+b//L
    if area1==2:
        b=3*L-b-1
        d=3*L-d-1
    if area1==3:
        a,b=b,a
        c,d=d,c
    if area1==5:
        a,b=3*L-b-1,a
        c,d=3*L-d-1,c
    if area1 in [6,7]:
        a=L*3-a-1
        c=L*3-c-1
    if area1==8:
        a,b=L*3-a-1,L*3-b-1
        c,d=L*3-c-1,L*3-d-1

    area1=(a//L)*3+b//L
    area2=(c//L)*3+d//L

    if area1>8 or area2>8:
        a=0
        while True:
            a+=1
    if n==0:
        if area1==1 and area2==7: return 4
        else: return abs(a-c)+abs(b-d)

    if area1>area2:
        a,b,c,d=c,d,a,b
        area1,area2=area2,area1
    
    if area1==area2:
        return dist(a%L,b%L,c%L,d%L,n-1)

    elif area1==0:
        if area2 in [5,7,8]:
            return abs(a-c)+abs(b-d)
        elif area2 in [3,6]:
            return dist(b,a,d,c,n)

        elif area2 in [1,2]:
            L=3**(n-1)
            a12=(a//L)*3+b//L
            a22=(c//L)*3+(d-3*area2*L)//L
            if a//L!=c//L:
                return abs(a-c)+abs(b-d)
            elif a//L==0:
                p=(d//L)-(b//L)
                if p==1: return dist(a,b-2*L,c,d-2*L,n-1)
                else: return dist(a,b%L,c,d%L+2*L,n-1) +(p-2)*L
            elif a//L==1:
                if area2==1 and a12==5 and a22==3: return dist(a-L,b-2*L,c-L,d-2*L,n)
                else: return min(a+c-2*(L-1),4*L-a-c)+abs(b-d)
            elif a//L==2: return dist(a-2*L,b,c-2*L,d,n)

        else: return 0

    elif area1==1:
        if area2 in [3,5,6,8]:
            return abs(a-c)+abs(b-d)
        elif area2==2:
            return dist(a,b-L,c,d-L,n)
        elif area2==7:
            return min(b+d-2*(L-1),(4*L)-b-d)+abs(a-c)
        else: return 0



for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    print(dist(a-1,b-1,c-1,d-1,29))

Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;

const int MAX_N = 100000;
char C[MAX_N];
int size;


struct S {
  int step;
  char l, r;
  bool canStep() {
    if(l == r) return false;
    if(l == 'D' && r == 'L' ||
       l == 'R' && r == 'D' ||
       l == 'U' && r == 'L' ||
       l == 'R' && r == 'U' ||
       l == 'R' && r == 'L') return false;
    return true;
  }
};

bool solve() {
  S s;
  s.step = 1;
  queue<S> que;
  s.l = C[0]; s.r = 0;
  que.push(s);
  s.l = 0; s.r = C[0];
  que.push(s);

  while(!que.empty()) {
    s = que.front(); que.pop();
    if(s.step == size) return true;
    bool isL;
    if(s.l == 0) isL = true;
    else isL = false;

    if(isL) s.l = C[s.step];
    else s.r = C[s.step];

    ++s.step;
    if(s.canStep()) {
      if(isL) s.r = 0;
      else s.l = 0;
      que.push(s);
    }
  }
  return false;
}

int main() {
  int T;
  char c;
  cin >> T;
  scanf("%c", &c);
  while(T--) {
    size = 0;
    while(scanf("%c", &c) && c != '\n') {
      C[size++] = c;
    }
    if(solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn gcd(x: i64, y: i64) -> i64 {
    let mut x = x;
    let mut y = y;
    while y != 0 {
        let t = y;
        y = x % y;
        x = t;
    }
    x
}

fn main() {
    input!(a: i64, b: i64);
    let g = gcd(a, b);
    println!("{}", a * b / g);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF=INT_MAX;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){
	int N,W;
	cin>>N>>W;
	vector<int>w,v;
	vector<vector<int> >dp;
	dp.assign(N+2,vector<int>(W+2,0));
	v.PB(0);w.PB(0);
	REP(i,N){
		int vt,wt;
		cin>>vt>>wt;
		v.PB(vt);w.PB(wt);
	}
	int res=0;
	FOR(i,1,N+1){
		REP(wt,W+1){
			if(wt>=w[i]){
				if(v[i]+dp[i-1][wt-w[i]]>dp[i-1][wt]){
					dp[i][wt]=v[i]+dp[i-1][wt-w[i]];
				}else{
					dp[i][wt]=dp[i-1][wt];
				}
			}else{
				dp[i][wt]=dp[i-1][wt];
			}
		}
	}

	cout<<dp[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 5228
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a= new int[n];
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        int count=0;
        for(int i=0;i<n;i++){
            if(a[i]!=i+1)
                count++;
        }
        if(count<=2)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 23764
"""
何回も再帰するときはlimitを増やす
dfs
"""
import sys
sys.setrecursionlimit(200000)

n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]


tree = [[] for _ in range(n)]
for a,b in l:
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

bit = [0 for _ in range(n)]
def dfs(v):
    bit[v] = 1
    for j in tree[v]:
        if bit[j]==0:
            dfs(j)

ans = 0
for i in range(m):
    a,b = l[i]
    a -= 1
    b -= 1
    tree[a].remove(b)
    tree[b].remove(a)
    bit = [0 for _ in range(n)]
    dfs(a)
    if bit.count(1) !=n:
        ans += 1

    tree[a].append(b)
    tree[b].append(a)
print(ans)



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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i<N; i++)cin >> A.at(i);
  
  int64_t kane =1000;
  int64_t kabu =0;
  
  for(int i=0; i<N-1; i++){
    if(A.at(i)>A.at(i+1)){
      kane += kabu * A.at(i);
      kabu =0;
    }
    if(A.at(i)<A.at(i+1)){
      kabu += kane/A.at(i);
      kane %= A.at(i);
    }
    
  }
  
  kane += kabu*A.at(N-1);
  
  cout << kane << endl;
    
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>=13)
		printf("%d",b);
	else if(a<=5)
		printf("0");
	else
		printf("%d",b/2);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a, b, c, d, x, start, end;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  start = (a < c ? c : a);
  end = (b < d ? b : d);
  x = end - start;
  x = (x > 0 ? x : 0);

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

  return 0;
}


Measured memory_bytes: 128