akhauriyash/Code-Regression huggingface dataset:
current_l = 0
stack_s = []
stack_each_area = []
areas = []
for s in input():
#     print(stack_each_area)
    if(s == '\\'):
        stack_s.append(current_l)
    elif(s == '/'):
        if(len(stack_s)==0):
            continue
        left_edge = stack_s.pop(-1)
        area = current_l - left_edge
        areas.append(area)
        
        merged_area = area
        merged_j = []
        for j in range(len(stack_each_area)):
            if( left_edge < stack_each_area[j][0] and stack_each_area[j][0] < current_l):
                merged_area += stack_each_area[j][1]
                merged_j.append(j)
        for del_j in merged_j[::-1]:
            del stack_each_area[del_j]
        stack_each_area.append((current_l, merged_area))
    current_l += 1
print(sum(areas))
if(len(stack_each_area) != 0):
    print(len(stack_each_area), " ".join([ str(lm[1]) for lm in stack_each_area]))
else:
    print(0)


Measured memory_bytes: 6268
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    string s,t;
    std::cin >> s>>t;
    rep(i,t.size()){
        std::cout << s[i] << t[i];
    }
    if(s.size()>t.size())std::cout << s[s.size()-1] ;
    std::cout  << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b; cin >> a >> b;
	cout << (a*b%2 == 0? "Even" : "Odd") << endl;
}

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

int main() {
    int n, m, a;
    long long ans=0;
    bool flag=false;

    cin >> n;

    for (int i = 0 ; i < n ; ++i) {
        cin >> a;
        
        if (a < 0) {
            a *= -1;
            flag = !flag;
        }

        if (i == 0 || a < m) m = a;
        ans += a;
    }


    if (flag) ans -= m*2;

    cout << ans;

    return 0;
}


Measured memory_bytes: 3540
# aoj 1313
import sys
input = sys.stdin.readline


# the width of the polygon sliced at x
def width(X, Y, x):
    n = len(X)
    lb, ub = float('inf'), -float('inf')
    for i in range(n):
        x1, y1, x2, y2 = X[i], Y[i], X[(i+1) % n], Y[(i+1) % n]
        if (x1-x)*(x2-x) <= 0 and x1 != x2:
            y = y1 + (y2-y1) * (x-x1) / (x2-x1)
            lb = min(lb, y)
            ub = max(ub, y)
    return max(0, ub-lb)


while True:
    m, n = map(int, input().split())
    if m == n == 0:
        break
    X1 = [0] * m
    Y1 = [0] * m
    X2 = [0] * n
    Z2 = [0] * n
    for i in range(m):
        X1[i], Y1[i] = map(int, input().split())
    for i in range(n):
        X2[i], Z2[i] = map(int, input().split())
    min1, max1 = min(X1), max(X1)
    min2, max2 = min(X2), max(X2)
    X = X1 + X2
    X.sort()
    ans = 0
    for i in range(len(X)-1):
        a, b = X[i], X[i+1]
        c = (a+b) / 2
        if min1 <= c <= max1 and min2 <= c <= max2:
            fa = width(X1, Y1, a) * width(X2, Z2, a)
            fb = width(X1, Y1, b) * width(X2, Z2, b)
            fc = width(X1, Y1, c) * width(X2, Z2, c)
            ans += (b-a) / 6 * (fa+4*fc+fb)
    print(ans)



Measured memory_bytes: 5656
// AOJ 2236 Rabbit Plays Games!
// 2018.2.10 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef struct { int a; int d; } T;
T tbl[40002];
int h[40002], a[40002], d[40002], s[40002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(T *a, T *b) { return ((long long)a->a) * b->d > ((long long)b->a) * a->d; }

int main()
{
	int n, i, j, k, sz;
	long long turn, ans;

	n = in();
	for (i = 0; i <= n; i++) h[i] = in(), a[i] = in(), d[i] = in(), s[i] = in();
	
	sz = 0, ans = turn = 0;
	for (i = 1; i <= n; i++) {
		j = a[0] - d[i];
		k = a[i] - d[0];
		if (k <= 0) continue;
		if (j <= 0) { puts("-1"); return 0; }

		turn += k; if (s[i] > s[0]) ans += k;
		tbl[sz].d = k;
		tbl[sz++].a = (h[i]+j-1)/j;
	}
	qsort(tbl, sz, sizeof(T), cmp);

	for (i = 0; i < sz; i++) {
		ans += turn*tbl[i].a - tbl[i].d;
		if (h[0] <= ans) { puts("-1"); return 0; }
		turn -= tbl[i].d;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main()
{
	int k, n;
	scanf("%d %d", &n, &k);
	int i1;
	for(int i=0; i<n; i++){
		int a;
		scanf("%d", &a);
		if(a==1) i1=i;
	}
	int ans=10000000;
	for(int i=0; i<=n-k; i++){
		if(i>i1 || i+k-1<i1) continue;
		if(ans>(i+k-2)/(k-1)+(n-1-i+k-2)/(k-1)) ans=(i+k-2)/(k-1)+(n-1-i+k-2)/(k-1);
	}
	printf("%d\n", ans);
	return 0;
}

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

#define ll long long
#define INF 99999999
int main()
{
    ll a,b;
    cin >> a >> b;
    ll tmp1,tmp2;
    vector<pair <ll,ll> > c;
    ll f,ff;
    for(ll i = 0;i < a;i++)
    {
        cin >> f >> ff;
        c.push_back(make_pair(f,ff));
    }
    ll ans = 0;
    sort(c.begin(),c.end());
    for(ll i = 0;i < a;i++)
    {
        if(c[i].second < b)
        {
            ans += c[i].first*c[i].second;
            b -= c[i].second;
        }
        else
        {
            ans += c[i].first * b;
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 2420
#include <stdio.h>
//#define scanf scanf_s
typedef long long int lli;

// ITP1_2_D
// 3つの整数a,b,cを読み込み、aからbの中にcの約数がいくつ含まれているかをカウント
int main()
{
	int iInputA, iInputB, iInputC;
	int iCnt;
	int iAns=0;

	scanf("%d %d %d", &iInputA, &iInputB, &iInputC);


	for (iCnt = iInputA; iCnt <= iInputB; iCnt++)
	{
		if (iInputC % iCnt == 0)
		{
			iAns++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

typedef long long LL;

const int N = 100010;

int a[N], n;

int main()
{
    LL sum = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n + 1; i ++)
    {
        scanf("%d", &a[i]);
        sum += abs(a[i] - a[i - 1]);
    }
    
    for(int i = 1; i <= n; i ++)
    {
        LL t = sum;
        if(a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1])
        {
            t -= abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1]);
            t += abs(a[i + 1] - a[i - 1]);
        }
        printf("%lld\n", t);
    }
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n; cin >> n;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  
  vector<int> cost(n);
  rep(i, n) {
    cost[i] = INT_MAX;
  }
  cost[0] = 0;

  for(int i=0; i<n-1; i++) {
    cost[i+1] = min(cost[i+1], cost[i] + abs(h[i+1] - h[i]));
    if (i+2 < n) {
      cost[i+2] = min(cost[i+2], cost[i] + abs(h[i+2] - h[i]));
    }
  }

  cout << cost[n-1] << endl;

}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include <queue>
#include<map>
#include<set>
#include <cstring>
using namespace std;
#define ll long long int


int main()
{
    string s , t ;
    cin>>s>>t ;

    ll n =s.length() , m = t.length() ;
    ll ans = 10001 ;
    for(ll i = 0 ; i <= n - m ; i++ )
    {
        ll cnt = 0 ;
        for(ll j = 0 ; j < m ; j++)
        {
            if(s[i + j] != t[j])
                cnt++ ;
        }

        ans = min(ans , cnt) ;
    }

    cout<<ans ;


}


Measured memory_bytes: 3604
from itertools import permutations

N = int(input())
P = tuple(int(i) for i in input().split())
Q = tuple(int(i) for i in input().split())

perm = list(permutations(range(1, N + 1)))

a = 0
b = 0

for i, p in enumerate(perm) :
  if p == P :
    a = i + 1
  if p == Q :
    b = i + 1
    
print(abs(a - b))

Measured memory_bytes: 46064
#include<cstdio>
#define Mn 100005
int n,m;
int cnt[Mn];
bool red[Mn];
int main() {
	scanf("%d%d", &n, &m);
	int i;
	red[1] = true;
	for (i = 1; i <= n; i++) cnt[i] = 1;
	for (i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (cnt[a] == 0) continue;
		cnt[a]--; cnt[b]++;
		if (red[a]) red[b] = true;
		if (cnt[a] == 0) red[a] = false;
	}
	int ans = 0;
	for (i = 1; i <= n; i++) ans += red[i];
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
 #pragma GCC optimize("unroll-loops")
 #pragma GCC optimize("fast-math")
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

// #define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
unordered_map<int, int>mp;
set<int>st;
void clr() {
    for (auto it : st)
        mp[it] = 0;
    st.clear();
}

bool check(int sz, vector<int>&a) {
    for (int i = 1; i < a.size(); ++i) {
        int c = a[i];
        if (c >= 5e5)
            continue;
        if (a[i - 1] >= a[i]) {
            while (st.size() > 0 && *st.rbegin() > c) {
                    mp[*st.rbegin()] = 0;
                    st.erase(*st.rbegin());
            }
            while (c >= 1 && mp[c] + 1 == sz) {
                mp[c] = 0;
                --c;
            }
            if (c == 0) {
                clr();
                return false;
            }
            mp[c]++;
            st.insert(c);
        } else {
            continue;
        }
    }
    clr();
    return true;
}


signed main() {
    accell();
    int n;
    cin >> n;
    vector<int>a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    bool ok = true;
    for (int i = 0; i + 1 < n; ++i)
        ok &= (a[i] < a[i + 1]);
    if (ok) {
        cout << 1;
        return 0;
    }
    int l = 0;
    int r = n + 1;
    while (r - l > 1) {
        int m = l + r >> 1;
        if (!check(m, a))
            l = m;
        else
            r = m;
    }
    cout << r << endl;
    return 0;
}


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

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

void wt(string x, string y,vector<int>& lis){

  	//cout << x << y << endl;
    int xs = x.size();
    int ys = y.size();
  	
  
    rep(i,-ys,xs){
        int flag = 1;
        rep(j,max(0,i),min( xs , i+ys )){
          	//cout << j << " " << j-i << endl;
            if ((x.at(j) != y.at(j-i)) && (x.at(j)!='?') && (y.at(j-i)!='?')){
                flag = 0;
             
                break;
            } 
        }

        lis.at(i+15000) = flag;
    }

    return;
}

int main(){

    vector<int> ab(30000,1); //0は15000とする
    vector<int> ac(30000,1);
    vector<int> bc(30000,1);

    string a,b,c;
    cin >> a >> b >> c;

    wt(a,b,ab);
    wt(a,c,ac);
    wt(b,c,bc);

    int ans = 100000;
    int as = a.size();
    int bs = b.size();
    int cs = c.size();

    rep(i,-4100,4100){
        rep(j,-4100,4100){
            if ((ab[i+15000] & ac[j+15000]) & bc[j-i+15000]){
                ans = min(ans , max(max(as,bs+i),cs+j) - min(min(0,i),j) );
            }
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}


int main() {
	int N;
	map<int, int>mp;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		mp[a]++;
		mp[a - 1]++; mp[a + 1]++;
	}
	int ans = 0;
	for (auto x : mp) {
		ans = max(ans, x.second);
	}
	cout << ans << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mem(x) memset(x, -1, sizeof(x))
const int MOD = 1e9+7;

template <typename T>
void print(T AA[], int nn){for(int ii=0; ii<nn; ii+=1){cout<<AA[ii]<<" ";}cout<<endl;}
template <typename T> inline void print(T nn){ cout << nn << endl;}
/* ----------------------------------------------------------------------------------- */

const int N = 405;
int A[N], cache[N][N], prefix[N], n;


int fn(int i, int j){
    if(i==j) return 0;
    int &ans = cache[i][j];
    if(ans != -1) return ans;
    ans = 1e15;
    for(int k=i; k<j; k+=1)
        ans = min(ans, fn(i, k)+fn(k+1, j)+prefix[j]-prefix[i-1]);
    return ans;
}


int32_t main(){

    IOS

    mem(cache);
    cin >> n;
    prefix[0] = 0;
    for(int i=1; i<=n; i+=1){
        cin >> A[i];
        prefix[i] = prefix[i-1]+A[i];
    }
    print(fn(1, n));

    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<math.h>
#include<vector>
typedef long long ll;
using namespace std;
bool reseto[110'000];
int main(){
    vector <int> primes;
    for(int i = 2; i < 110'000; i++){
        if(reseto[i]==0){
            primes.push_back(i);
            //cout << i << endl;
            for(int j = i; j < 110'000; j+=i){
                reseto[j] = 1;
            }
        }
    }
    int x;
    cin >> x;
    for(int i = 0; i < primes.size(); i++){
        if(primes[i] >= x){
            cout << primes[i] << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

const int MAXN = 105;
int n;
int x[MAXN];

int calc(int p) {
    int ans = 0;
    fo(i, n) {
        ans += (p-x[i]) * (p-x[i]);
    }
    return ans;
}

void solve() {
    cin >> n;
    sca(x, n);
    int ans = 1e9;
    fo1(i, 100) {
        ans = min(calc(i), ans);
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int d[310][310];
bool d_n[310][310];

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

	ll ans = 0;
	rep(i, n) rep(j, n) cin >> d[i][j];

	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				if (d[i][j] > d[i][k] + d[k][j]) {
					cout << -1 << endl;
					return 0;
				}

				if (d[i][j] == d[i][k] + d[k][j] && d[i][k] > 0 && d[k][j] > 0) {
					d_n[i][j] = true;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {

			if (d_n[i][j] == false) {
				ans += d[i][j];
			}

		}
	}
	cout << ans << endl;
}

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

int main( void )
{
    char c[ 9 ];
    for ( int i = 0; i < 9; i++ )
    {
        cin >> c[ i ];
    }
    cout << c[ 0 ] << c[ 4 ] << c[ 8 ] << endl;
    return 0;
}


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

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

Node root;

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

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->key){
    return u;
  }

  if(k < u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;

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

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent; 
  }

  if(y->parent == NIL){
    root == x;
  }else if(y == y->parent->left){
    y->parent->left = x;
  }else{
    y->parent->right = x;
  }

  if(y != z){
    z->key = y->key; 
  }
}

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

  z->parent = y;

  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

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

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


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

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

  return 0;
}

Measured memory_bytes: 19364
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
 
N,M,k=map(int,input().split())
m=10**9+7
 
g1=[1,1]
g2=[1,1]
inverse=[0,1]
 
for i in range(2,N*M):
  g1.append((g1[-1]*i)%m)
  inverse.append((-inverse[m%i]*(m//i))%m)
  g2.append((g2[-1]*inverse[-1])%m)

c=cmb(N*M-2,k-2,m)
ans=0
for i in range(N):
  ans+=((N-i)*M*M*i*c)%m
  ans%=m
for i in range(M):
  ans+=((M-i)*N*N*i*c)%m
  ans%=m
print(ans%m)

Measured memory_bytes: 26992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int n,k;
vi a;

bool valid(int mx) {
 
	ll cnt=0;
 
	for(int i=0; i<n && cnt<=n+k; ++i) {
		cnt+=ceil(a[i]/double(mx));
	}
 
	return cnt<=n+k;
 
}
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
 
	cin>>n>>k;
	int mx=INT_MIN;
	a.resize(n);
	for(int&q : a) cin>>q, mx=max(mx, q);

	if(k==0) {
		cout<<mx<<"\n";
		return 0;
	}

	int ans=0;
	
	for(int k=mx-1; k>=1; k/=2)
		while(!valid(ans+k))
			ans+=k;
 
	cout<<ans+1<<"\n";
 
	return 0;
}



Measured memory_bytes: 3920
#include <stdio.h>
#include <limits.h>
#define MAX_N 100

int sum(int *data, int start, int end) {
	int i, s = 0;

	for (i = start; i < end; i++) {
		s += data[i];
	}
	return s;
}

int find(int n, int data[MAX_N][MAX_N]) {
	int temp[5100] = {0}, row, index, num_cell, end, i, k, s, maximum;

	maximum = INT_MIN;
	for (row = 0; row < n; row++) {
		index = 0;
		num_cell = 1;

		for (end = n; end >= 0; end--) {
			for (i = 0; i < end; i++) {
				k = index + i;

				s = sum(data[row], i, i+num_cell);
				if (temp[k] < 0) {
					temp[k] = s;
				} else {
					temp[k] += s;
				}
				if (maximum < temp[k]) {
					maximum = temp[k];
				}
			}
			index += end;
			num_cell++;
		}
	}
	return maximum;
}

int main(void) {
	int n, i, j;
	int a[MAX_N][MAX_N] = {{0}};

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	printf("%d\n", find(n, a));
	return 0;
}

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

int main() {
  int A,B,C,X,Y;
  int c_max;
  int money;
  cin >> A >> B >> C >> X >> Y;

  c_max = max(X,Y) * 2;
  
  money = A * X + B * Y;

  for(int i = 0; i <= c_max;i++){
    int a_sheets = X - i / 2;
    int b_sheets = Y - i / 2;
    if(a_sheets < 0 && b_sheets >= 0)a_sheets = 0;
    if(a_sheets >= 0 && b_sheets < 0)b_sheets = 0;
    if(a_sheets < 0 || b_sheets < 0)continue;
    int money_i = A * a_sheets + B * b_sheets + C * i;
    money = min(money,money_i);
  }

  cout << money << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  ll ans=0;

  rep(i,1,n+1)ans+=i*(n+1-i);

  rep(i,0,n-1){
    ll u,v;
    std::cin>>u>>v;
    if(u>v)std::swap(u,v);
    ans-=u*(n+1-v);
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
	int n; cin >> n;
	vector<ll>a(n); for (int i = 0; i < n; i++)cin >> a[i];
	vector<ll>b(n); for (int i = 0; i < n; i++)cin >> b[i];
	ll want = 0; vector<ll>remain; ll give = 0; int minus = 0;
	for (int i = 0; i < n; i++) {
		ll x = a[i] - b[i];
		if (x > 0) { remain.push_back(x); give += x; }
		else if (x < 0) { minus++; want += -x; }
	}
	if (want > give)cout << -1 << endl;
	else
	{
		sort(remain.begin(), remain.end());	reverse(remain.begin(), remain.end());
		int ret = 0;
		for (; want > 0; ret++) { want -= remain[ret]; }
		cout << ret + minus << endl;
	}
	return 0;
}

Measured memory_bytes: 2428
#include<iostream>
#include<deque>
using namespace std;
int N,M,K;
long A[1<<17];
deque<pair<long,int> >P[301];
main()
{
	cin>>N>>M>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<K;i++)P[i].push_back(make_pair(-9e18,0));
	P[K].push_back(make_pair(0,0));
	for(int i=N;i--;)for(int j=1;j<=K;j++)
	{
		while(P[j].front().second-M>i)P[j].pop_front();
		pair<long,int>nxt;
		nxt.first=P[j].front().first+A[i]*j;
		nxt.second=i;
		while(!P[j-1].empty()&&P[j-1].back().first<=nxt.first)P[j-1].pop_back();
		P[j-1].push_back(nxt);
	}
	cout<<P[0][0].first<<endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N, M;
    cin >> N >> M;
    ll ans = (1900*M + 100*(N-M)) * pow(2, M);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3964
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  
  int a[100000]={},i,m;
  a[0] = 100001;
  
  for(i=0; i<n; i++){
    scanf("%d",&m);
    if(a[i]>m) a[i] = m;
    a[i+1] = m;
  }
  
  int sum=0;
  
  for(i=0; i<n; i++){
    sum += a[i];
  }
  
  printf("%d",sum);
  
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int cnt = 0;

    if(s=="RRR") cnt = 3;
    if(s=="SRR") cnt = 2;
    if(s=="RRS") cnt = 2;
    if(s=="RSR") cnt = 1;
    if(s=="SRS") cnt = 1;
    if(s=="SSR") cnt = 1;
    if(s=="RSS") cnt = 1;
    if(s=="SSS") cnt = 0;
    cout << cnt << endl;
    return 0; 
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[3];
int main() {
	ll n,m;
	cin>>n>>m;
	if(n!=1){
		a[n-1]=1;
	}
	else{
		a[n-1]=0;
	}
	ll ch[3];
	for(ll i=0;i<3;i++){
		ch[i]=-1;
	}
	for(ll i=0;i<m;i++){
		ll keta,val;
		cin>>keta>>val;
		keta=n-keta;
		if(ch[keta]!=-1){
			if(ch[keta]!=val){
				cout << -1;
				return 0;
			}
		}
		else{
			ch[keta]=val;
		}
		if(ch[n-1]==0&&n!=1){
			cout << -1;
			return 0;
		}
	}
	for(ll i=0;i<n;i++){
		if(ch[n-1-i]==-1){
			cout << a[n-1-i];
		}
		else{
			cout << ch[n-1-i];
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  private static Scanner sc;

  public static void main(String[] args) {
    sc = new Scanner(System.in);
    new Main().solve();
  }


  private void solve() {
    String S = sc.next();
    String T = sc.next();

    int size = S.length();
    boolean flg = false;
    for (int i = 0; i < size; i++) {
      String tmps = S.substring(0, size - i);
      String tmpt = T.substring(i);
      if (!tmps.equals(tmpt)) {
        continue;
      }

      String tmps2 = S.substring(size - i);
      String tmpt2 = T.substring(0, i);
      if (!tmps2.equals(tmpt2)) {
        continue;
      }
      flg = true;
      break;
    }

    if (flg) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

int main(){
    int h,w;
    int amount=0;
    
    cin >> h >> w;

    string s[h];

    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    for(int i=0;i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] != '#'){
                amount = 0;
                for(int k=i-1; k<=i+1; k++){
                    for(int l=j-1; l<=j+1; l++){
                        if(k >= 0 && l >= 0 && k < h && l < w){
                            if(s[k][l] == '#') amount++;
                        }
                    }
                }
                s[i].replace(j,1,to_string(amount));
            }
        }
    }

    for(int i=0; i<h; i++){
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}

ll f(ll x, ll y, ll z){
    return x*x + y*y + z*z + x*y + y*z + z*x;
}

void solve(long long N){
    vec<ll> s(N+1);
    ll P = sqrt(N)+1;
    FOR(x, P, 1){
        FOR(y, P, 1){
            FOR(z, P, 1){
                ll t = f(x, y, z);
                if(0<t && t<=N){
                    s[t]++;
                }
            }
        }
    }
    FOR(i, N+1, 1){
        cout << s[i] << el;
    }
}



Measured memory_bytes: 3748
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>

using namespace std;
const int INF = 2000000005;
int main()
{
	int n,x,mi=INF;
	cin >> n>>x;
	int d[105] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> d[i];
		mi = min(mi, d[i]);
		x -= d[i];
	}
	cout << n + x / mi << endl;
    return 0;
}


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

int main() {

  string S;
  cin >> S;
  
  int p1 = 0, p2 = 0;
  //最初が0
  for (int i = 0; i < S.size(); i++) {
    if(i%2==0){
      p1 += ((S[i]=='0')? 0 : 1);
    }
    if(i%2==1){
      p1 += ((S[i]=='1')? 0 : 1);
    }
  }

  //最初が1
  for (int i = 0; i < S.size(); i++) {
    if(i%2==0){
      p2 += ((S[i]=='1')? 0 : 1);
    }
    if(i%2==1){
      p2 += ((S[i]=='0')? 0 : 1);
    }
  }
  
  cout << ((p1<p2)?p1:p2) << endl;

  return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var w, a, b int
	fmt.Scan(&w, &a, &b)
	if a+w < b {
		fmt.Print(b - (a + w))
	} else if b+w < a {
		fmt.Print(a - (b + w))
	} else {
		fmt.Print(0)
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>

using namespace std;

typedef long long ll;
#define INF 1000000007

int main(){
    
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int cost = INF;
    for(int x = -100; x <= 100; x++){
        int tmp = 0;
        for(int i = 0; i < n; i++){
            tmp += (a[i] - x) * (a[i] - x);
        }
        cost = min(cost, tmp);
    }

    cout << cost << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
double pi = acos(-1);
int main(){ 
  double r;
  cin >> r;
  printf("%.12f\n", 2.0 * r * pi);
  return 0;
} 

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

int main() {

  int r, g, b, x;
  cin >> r >> g >> b;

  x = r*100 + g*10 + b;
  if(x % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int dataarray[20];
int i,j,answer1,answer2,temp;
for(i=0;i<20;i++){
scanf("%d",&dataarray[i]);
}
for(i=0;i<10;i++){
for(j=i;j<10;j++){
if(dataarray[j]>dataarray[i]){
temp=dataarray[j];
dataarray[j]=dataarray[i];
dataarray[i]=temp;
}
if(dataarray[j+10]>dataarray[i+10]){
temp=dataarray[j+10];
dataarray[j+10]=dataarray[i+10];
dataarray[i+10]=temp;
}
}
}
answer1=dataarray[0]+dataarray[1]+dataarray[2];
answer2=dataarray[10]+dataarray[11]+dataarray[12];
printf("%d %d\n",answer1,answer2);
return 0;
}

Measured memory_bytes: 596
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 六  3/17 20:01:33 2018
 * Ended  Time*  : 六  3/17 20:19:19 2018
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}
int n;

struct Point {
	int x, y;
	bool vis;
}red[205], blue[205];

bool edge[205][205];

bool used[205];
int linker[205];

bool dfs(int u){
	for(int v = 1; v <= n; v++){
		if(edge[u][v] && !used[v]){
			used[v] = true;
			if(linker[v] == -1 || dfs(linker[v])){
				linker[v] = u;
				return true;
			}
		}
	}
	return false;
}




int lungary(){
	int res = 0;
	memset(linker, -1, sizeof(linker));
	for(int i = 1; i <= n; i++){
		memset(used, false, sizeof(used));
		if(dfs(i)) res++;
	}
	return res;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d", &red[i].x, &red[i].y);
	for(int i = 1; i <= n; i++) scanf("%d %d", &blue[i].x, &blue[i].y);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(red[i].x < blue[j].x && red[i].y < blue[j].y) 
				edge[i][j] = true;
		}
	}
	printf("%d\n", lungary());
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  if(n<1000){
    P("ABC");
  }else{
    P("ABD");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX=100;
int main(){
    int h,w;
    cin>>h>>w;
    string s[MAX];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static int[] color;
	static int n;

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		n = in.nextInt();
		int m = in.nextInt();
		color = new int[n];

		List<List<Integer>> g = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			g.add(new ArrayList<Integer>());
		}
		for (int i = 0; i < m; i++) {
			int v1 = in.nextInt();
			int v2 = in.nextInt();

			g.get(v1).add(v2);
			g.get(v2).add(v1);
		}

		assignColor(g);

//		for (int i = 0; i < g.size(); i++) {
//			System.out.println(i + " " + g.get(i));
//		}
		int q = in.nextInt();
		for (int i = 0; i < q; i++) {
			int s = in.nextInt();
			int t = in.nextInt();
			if (color[s] == color[t]) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}
	private static void assignColor(List<List<Integer>> list) {
		Arrays.fill(color, -1);
		int id = 1;
		for (int i = 0; i < n; i++) {
			if (color[i] == -1) {
				dfs(list, i, id++);
			}
		}
	}

	public static void dfs(List<List<Integer>> list, int from, int id) {
		Stack<Integer> stack = new Stack<Integer>();

		stack.push(from);
		color[from] = id;

		while (!stack.isEmpty()) {
			from = stack.peek();
			boolean isConnect = false;
			for (int to : list.get(from)) {
				if (color[to] != -1) {
					continue;
				}
				isConnect = true;
				stack.push(to);
				color[to] = id;
				break;
			}
			if (!isConnect) {
				stack.pop();
			}
		}

	}

}




Measured memory_bytes: 114436
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
int P[1123456];
int cnt[556][556];
bool close[556][556];

int main() {

	cin >> N;
	rep(i, N * N) cin >> P[i];
	rep(i, N * N) --P[i];


	rep(i, N) rep(j, N) {
		cnt[i + 1][j + 1] = min(i, min(j, min(N - i - 1, N - j - 1)));
	}

	ll ans = 0;
	rep(i, N * N) {
		ans += cnt[P[i] % N + 1][P[i] / N + 1];
		close[P[i] % N + 1][P[i] / N + 1] = true;
		queue<pair<pair<int, int>, int>> q;
		const int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 }, dn = 4;
		q.push({ { P[i] % N + 1,P[i] / N + 1 } ,cnt[P[i] % N + 1][P[i] / N + 1] - 1 });
		while (!q.empty()) {
			auto cur = q.front();
			q.pop();
			rep(d, dn) {
				if (close[cur.first.first + dx[d]][cur.first.second + dy[d]] && cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] > cur.second) {
					cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] = cur.second;
					q.push({ { cur.first.first + dx[d],cur.first.second + dy[d] }, cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] });
				}
				else if (cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] > cur.second + 1) {
					cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] = cur.second + 1;
					q.push({ { cur.first.first + dx[d],cur.first.second + dy[d] }, cnt[cur.first.first + dx[d]][cur.first.second + dy[d]] });
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5836
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    cin >> n;
    ll c[n - 1], s[n - 1], f[n - 1];
    rep(i, n - 1) { cin >> c[i] >> s[i] >> f[i]; }

    rep(i, n - 1) {
        ll time = 0;
        repd(j, i, n - 1) {
            ll time_last;
            if (time <= s[j]) {
                time_last = s[j];
            } else {
                ll temp = time - s[j];
                ll num = temp / f[j];
                if (temp % f[j] != 0) {
                    num++;
                }
                time_last = s[j] + f[j] * num;
            }
            time = time_last + c[j];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int num=0;
	int a,b,c,d=0;
	
	scanf("%d",&num);

	a = num / 1000;
	b = (num / 100) - (a * 10);
	c = (num / 10) - (a * 100 + b *10);
	d = num - (a*1000+b*100+c*10);

	if(a==b || b==c || c==d){
		printf("Bad");
	}else{
		printf("Good");
	}


	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define NMAX 10000
#define NPRIME_MAX 1230

int make_prime(int *prime);
int is_prime(int target, int nprime, int *prime);

int main(){
   int i, answer, n, target;
   int nprime, prime[NPRIME_MAX];
   nprime=make_prime(prime);
   scanf("%d",&n);
   for(answer=0,i=0;i<n;i++){
      scanf("%d",&target);
      if(is_prime(target,nprime,prime)==0) ++answer;
   }
   printf("%d\n",answer);
   return 0;
}

int make_prime(int *prime){
   int i, j, flag, nprime;
   for(nprime=0,i=2;i<=10000;i++){
      for(flag=0,j=0;j<nprime;j++){
         if(i%prime[j]==0){
            ++flag;
            break;
         }
      }
      if(flag==0){
         prime[nprime]=i;
         ++nprime;
      }
   }
   return nprime;
}

int is_prime(int target, int nprime, int *prime){
   int j;
   for(j=0;j<nprime;j++){
      if(target==prime[j]) return 0;
      if(target%prime[j]==0) return 1;
   }
   return 0;
}

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

int main(){
 int n,t,x;
 int waru;
 int amari;
 cin >> n>>x>>t;
  
 waru=n/x;
 amari=n%x;
 
 if(amari==0){cout<<t*waru<<endl;}
 else{cout<<t*waru+t<<endl;}
 


}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

double PI = 3.14159265;

int main() {
    double r;
    cin >> r;

    cout << fixed << setprecision(5) << 2.0 * r * PI << endl;
    return 0;
}


Measured memory_bytes: 3760
#include<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    for(int i=-120;i<=120;i++)
    {
        for(int j=-120;j<=120;j++)
        {
            if(i*i*i*i*i-j*j*j*j*j==x)
            {
                printf("%d %d\n",i,j);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 1704
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

int n,k,q,a[200010],st1[21][200010],st2[21][200010],st3[21][200010],st4[21][200010];
int nxt[200010],pre[200010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		int pos=lower_bound(a+1,a+n+1,a[i]+k)-a;
		if(pos>n) pos=-1;
		nxt[i]=pos;
	}
	for(int i=1;i<=n;i++){
		int pos=upper_bound(a+1,a+n+1,a[i]-k)-a-1;
		if(pos<1) pos=-1;
		pre[i]=pos;
	}
	for(int i=1;i<=n;i++){
		st1[0][i]=i;st2[0][i]=i;
		st3[0][i]=i;st4[0][i]=i;
	}
	for(int i=1;i<=20;i++){
		for(int j=1;j<=n;j++){
			if(st1[i-1][j]==-1||nxt[st1[i-1][j]]==-1) st1[i][j]=-1;
			else{
				st1[i][j]=st1[i-1][nxt[st1[i-1][j]]];
				if(st1[i][j]!=-1){
					st3[i][j]=st3[i-1][j]+st3[i-1][nxt[st1[i-1][j]]];
				}
			}
		}
	}
	for(int i=1;i<=20;i++){
		for(int j=1;j<=n;j++){
			if(st2[i-1][j]==-1||pre[st2[i-1][j]]==-1) st2[i][j]=-1;
			else{
				st2[i][j]=st2[i-1][pre[st2[i-1][j]]];
				if(st2[i][j]!=-1){
					st4[i][j]=st4[i-1][j]+st4[i-1][pre[st2[i-1][j]]];
				}
			}
		}
	}
	cin>>q;
	while(q--){
		int l,r;cin>>l>>r;
		int len=0,now=l;
		for(int i=20;i>=0;i--){
			if(now!=-1&&st1[i][now]!=-1&&st1[i][now]<=r){
				now=nxt[st1[i][now]];
				len+=(1<<i);
			}
		}
		int sum1=0,sum2=0;
		now=l;
		for(int i=20;i>=0;i--){
			if(now!=-1&&st1[i][now]!=-1&&st1[i][now]<=r){
				sum1+=st3[i][now];
				now=nxt[st1[i][now]];
			}
		}
		now=r;
		for(int i=20;i>=0;i--){
			if(now!=-1&&st2[i][now]!=-1&&st2[i][now]>=l){
				sum2+=st4[i][now];
				now=pre[st2[i][now]];
			}
		}
		cout<<sum2-sum1+len<<'\n';
	}
	return 0;
}

Measured memory_bytes: 126164
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int deg[N],f[N],n,rt;
void dfs(int u,int fa){
	f[u]=0;R int sz=0,c=0;
	go(u)if(v!=fa){
		dfs(v,u);
		f[u]+=f[v],++sz,c+=(f[v]!=0);
	}
	if(c<sz)f[u]+=sz-1-c;
}
int main(){
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v),++u,++v;
		add(u,v),add(v,u),++deg[u],++deg[v];
	}
	fp(i,1,n)if(deg[i]>2){rt=i;break;}
	if(!rt)return puts("1"),0;
	dfs(rt,0);
	printf("%d\n",f[rt]);
	return 0;
}

Measured memory_bytes: 7296