akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int N,M;    //点と橋の数
int a[50]={0}, b[50]={0};   //入力保存用
int graph[50][50]={{0}};  //橋の繋がり
int visited[50];

void dfs(int v){    //
    visited[v]=1;   //到着
    int v2; //次の点
    for(v2=0;v2<N;v2++){
        if(visited[v2]){ //到着済についてはもう見ない
            continue;
        }
        if(graph[v][v2]==0){ //端があったら深さ増やす
            continue;
        }
        dfs(v2);
    }
}

int main()
{
    int ans=0;

    scanf("%d %d", &N,&M);

    int i,j;
    for(i=0;i<M;i++){
        scanf("%d %d", &a[i], &b[i]);
        a[i]--; //橋の番号と配列の要素あわせ
        b[i]--;
        graph[a[i]][b[i]]=1;
        graph[b[i]][a[i]]=1;
    }

    for(i=0;i<M;i++){
        graph[a[i]][b[i]]=0;
        graph[b[i]][a[i]]=0;

        for(j=0;j<N;j++){
            visited[j]=0;
        }

        dfs(0);

        for(j=0;j<N;j++){
            if(visited[j]==0){
                ans++;
                break;
            }
        }

        graph[a[i]][b[i]]=1;
        graph[b[i]][a[i]]=1;
    }

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

    return 0;
}


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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 610;

int n, col[2][maxn][maxn], d[2], SQRT[maxn * maxn];
vector<pair<int, int> > all[2][2];

void dfs(int i, int j, int c, int col[maxn][maxn], int d) {
	if(i < 0 || j < 0 || i >= n || j >= n || col[i][j]) {
		return;
	}
	col[i][j] = c;
	c = -c;
	for (int x = 0; x * x <= d; ++x) {
		int y = SQRT[d - x * x];
		if(x * x + y * y == d) {
			dfs(i + x, j + y, c, col, d);
			dfs(i - x, j + y, c, col, d);
			dfs(i + x, j - y, c, col, d);
			dfs(i - x, j - y, c, col, d);
		}
	}
	return;
}

void work(int col[maxn][maxn], int d) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if(!col[i][j]) {
				dfs(i, j, 1, col, d);
			}
		}
	}
}

int main() {
	scanf("%d%d%d", &n, d, d + 1);
	for (int i = 0; i < maxn; ++i) {
		SQRT[i * i] = i;
	}
	n <<= 1;
	work(col[0], d[0]);
	work(col[1], d[1]);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			all[col[0][i][j] > 0][col[1][i][j] > 0].push_back(make_pair(i, j));
		}
	}
	n >>= 1;
	n *= n;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			if(all[i][j].size() >= n) {
				for (int k = 0; k < n; ++k) {
					printf("%d %d\n", all[i][j][k].first, all[i][j][k].second);
				}
				return 0;
			}
		}
	}
}


Measured memory_bytes: 36312
#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;
typedef unsigned int uint;
using namespace std;

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);

  int ans=0;
  ans+=abs(a[2]-a[1]);
  ans+=abs(a[1]-a[0]);

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n;
    cin >> n;
    vector<int> vec(n);
    els(vec) {
        cin >> el;
    }
    sort(vec.begin(), vec.end());
    double res = 0, div = 1;
    for (int i = n - 1; i > 0; --i) {
        div *= 2;
        res += vec[i] / div;
    }
    res += vec[0] / div;
    printf("%.10lf", res);
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}


Measured memory_bytes: 256
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

ll dp[30010][5];

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(10, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 10; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'0'] = i;
    }
    return res;
}

void solve()
{
    IN(n);
    string s;cin >> s;
    auto next = calcNext(s);

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            if (next[i][j] >= n) continue;
            dp[next[i][j] + 1][1] += dp[i][0];
            dp[next[i][j] + 1][2] += dp[i][1];
            dp[next[i][j] + 1][3] += dp[i][2];
        }
    }

    // 集計
    long long res = 0;
    for (int i = 0; i <= n; ++i) res += dp[i][3];

    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    string s1,s2,s3;
    cin>>s1>>s2;
    for(int i=0;i<s2.length()-1;i++){
        string s;
        s=s2[i];
        s3+=s;
    }
    if(s3==s1)cout<<"Yes\n";
    else cout<<"No\n";
}



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

using namespace std;
typedef long long ll;
const ll MOD = 998244353, MAX = 1000010;
int n, k;
ll fac[1000100], fnv[1000100];

ll comb(ll n, ll r) {
    if (r<0||r>n) return 0;
    return fac[n]*fnv[r]%MOD*fnv[n-r]%MOD;
}

ll f(ll a, ll b) {
    if (a<b) return 0;
    if (b==n) return comb(2*a-1,a)-comb(2*a-1,b-2);
    if (0<b) return comb(2*a+n-b,a)-comb(2*a+n-b,b-1);
    return comb(k,a);
}

int main() {
    int i, m;

    scanf("%d%d",&n,&k);
    fac[0] = fnv[0] = fac[1] = fnv[1] = 1;
    for (i=2;i<=MAX;i++) fnv[i]=(fac[i]=MOD-MOD/i*fac[MOD%i]%MOD)*fnv[i-1]%MOD;
    for (i=2;i<=MAX;i++) fac[i]=fac[i-1]*i%MOD;
    ll ans = 0;
    for (m=k;m>=0;m-=2) ans += f((k-m)/2,n-m);
    printf("%lld\n",(ans%MOD+MOD)%MOD);

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define change_read() freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin)
#define change_write() freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout)
#define creat_read() freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout)
using namespace std;
const int maxm = 3e5+10;
long long num[maxm];
long long sum[maxm];
long long les[maxm];
long long bet[maxm];
priority_queue<long long>que2;
priority_queue<long long,vector<long long>,greater<long long> >que1;
int main() {
//    change_read();
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long len,x;
    while(cin>>x) {
        while(!que1.empty()) que1.pop();
        while(!que2.empty()) que2.pop();
        len = x*3;
        for(int i = 1; i<=len; i++) {
            cin>>num[i];
            sum[i] = sum[i-1]+num[i];
            if(i<=x)
                que1.push(num[i]);
            else if(i>(x<<1))
                que2.push(num[i]);
        }
        bet[x] = sum[x];
        for(int i = 1; i<=x; i++) {
            que1.push(num[i+x]);
            bet[i+x] = bet[i+x-1]+num[i+x]-que1.top();
            que1.pop();
        }
        les[x<<1] = sum[len]-sum[x<<1];
        for(int i = 1; i<=x; i++) {
            que2.push(num[len-x-i+1]);
            les[len-x-i] = les[len-x-i+1]-que2.top()+num[len-x-i+1];
            que2.pop();
        }
        long long ans = -1e18;
        for(int i = x; i<=(x<<1); i++) {
            ans = max(ans,bet[i]-les[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

//3 1 4 1 5 9
//3 4 7 7 9 14
//2 2 5 6 14 9







Measured memory_bytes: 10100
#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }





using ll = long long;
using ull = unsigned long long;


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;


void exec() 
{
	int n;
	read(n);

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

	ll ans = 0;

	for (int i = 1; i < n; ++i) {
		if (arr[i - 1] > arr[i]) {
			ans += (arr[i - 1] - arr[i]);
			arr[i] = arr[i - 1];
		}
	}

	print(ans);
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

    return 0;
}

Measured memory_bytes: 3988
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }

// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
string S;
int A[200001];
int B[200001];
int C[200001];

LL BB[100001];
LL BSUM[100001];
LL CC[100001];
int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> A[i];
	}
	REP(i, 0, N) {
		cin >> B[i];
	}
	REP(i, 0, N) {
		cin >> C[i];
	}
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	REP(i, 0, N) {
		BB[i] = lower_bound(A, A + N, B[i]) - A;
	}
	partial_sum(BB, BB + N, BSUM + 1);
	REP(i, 0, N) {
		CC[i] = BSUM[lower_bound(B, B + N, C[i]) - B];
	}
	cout << accumulate(CC, CC + N, (LL)0) << endl;
	return 0;
}


Measured memory_bytes: 4608
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()
a = l()


if n % 2 == 0:
    po = [a[i] for i in range(n)]
    
    for i in range(n-3,-1,-1):
        po[i] += po[i+2]

    ans = sum(a[0::2])
    ans = max(ans,sum(a[1::2]))
    co = 0
    for i in range(0,n,2):
        if i+1 <= n-1:
            ans = max(ans,co+po[i+1])
        else:
            ans = max(ans,co)
        co += a[i]

    print(ans)

else:
    po = [a[i] for i in range(n)]
    mi = [-Max for i in range(n)]
    
    for i in range(n-3,-1,-1):
        po[i] += po[i+2]

    ans = sum(a[1::2])
    ans = max(ans,sum(a[0::2]) - a[-1])
    #print(ans)
    l1 = [-Max for i in range(n)]
    for i in range(n):
        if i != n-1:
            l1[i] = po[i+1]

    """
    co = 0
    for i in range(0,n,2):
        if i != n-1:
            l1[i] = co + po[i+1]
        else:
            l1[i] = co
        co += a[i]
    co = 0
    for i in range(1,n,2):
        if i != n-1:
            l1[i] = co + po[i+1]
        else:
            l1[i] = co
        co += a[i]
    """

    for i in range(n-1,-1,-1):
        if i == n-1:
            continue
        elif i == n-2:
            mi[i] = l1[i]
        else:
            mi[i] = max(mi[i+2]+a[i],l1[i])


    l1 = mi


    """
    for i in range(n-1,-1,-1):
        if i <= n-3:
            mi[i] = min(mi[i+2],a[i])
        else:
            mi[i] = a[i]
    print(mi)
    """
    
    l2 = [-Max for i in range(n)]
    
    for i in range(n-1,-1,-1):
        l2[i] = po[i]
        
    #print(l1)
    #print(l2)
    co = 0

    for i in range(0,n,2):
        if i + 2 <= n-1:
            #print(ans,co+l1[i+1],co+l2[i+2])
            ans = max(ans,co+l1[i+1],co+l2[i+2])
        elif i+1 <= n-1:
            ans = max(ans,co+l1[i+1])
        else:
            ans = max(ans,co)
        
        co += a[i]
    co = 0
    #print(ans)
    for i in range(1,n,2):
        #print(ans,co+l1[i+1])
        ans = max(ans,co+po[i+1])
        #ans = max(ans,co+l1[i+1])
        co += a[i]
    #print("po:"+str(mi[1]))
    print(ans)









Measured memory_bytes: 118216
def examA():
    S = SI()
    if "W" in S and not "E" in S:
        print("No")
    elif "E" in S and not "W" in S:
        print("No")
    elif "N" in S and not "S" in S:
        print("No")
    elif "S" in S and not "N" in S:
        print("No")
    else:
        print("Yes")
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    S = [I()for _ in range(N)]

    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(ll i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod=1e9+7;
ll ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,k;
	cin >> n >> k;
	rep(i,k,n+2){
		ans=(ans+((((n-i+1)+n)*i)/2-((0+i-1)*i)/2+1+mod)%mod)%mod;
	//	cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3660
#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)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
   lint N, K;
   cin >> N >> K;
   vector<lint> A(N);
   REP(i, N) cin >> A[i];
   sort(A.begin(), A.end());
   vector<lint> frac(N+1);
   frac[0] = 1;
   FOR(i, 1, N+1) {
       frac[i] = frac[i-1] * i % MOD;
   }
    lint ans = 0;
    REP(i, N) {
        if(i < K - 1) continue;
        ans = (ans + A[i] * frac[i] % MOD * power(frac[K-1], MOD-2, MOD) % MOD * power(frac[i-K+1], MOD-2, MOD) % MOD + MOD) % MOD;
    }
    REP(i, N) {
        if(N-1-i < K-1) continue;
        ans = (ans -A[i] * frac[N-1-i] % MOD * power(frac[K-1], MOD-2, MOD) % MOD * power(frac[N-1-i-K+1], MOD-2, MOD) % MOD + MOD) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n=int(input())
absa=[]


for i in range(n):
    c=[]
    c=[int(j) for j in input().split()]
    absa.append([c[0],c[1],c[1]+c[0]])


from operator import itemgetter
absa.sort(key=itemgetter(2))

t=0
k=0
for i in range(n):
    if i%2==0:
        t+=absa[-1][0]
        del absa[-1]
    else:
        k+=absa[-1][1]
        del absa[-1]
    
    

print(t-k)







Measured memory_bytes: 24560
# coding: utf-8
while 1:
    h=int(input())
    if h==0:
        break
    field=[]
    for i in range(h):
        field.insert(0,list(map(int,input().split())))
        field[0]+=[0]
    ans=0
    f=True
    while f:
        f=False
        for i in range(h):
            now=-1
            count=0
            for j in range(6):
                if now!=field[i][j] and count>=3:
                    for k in range(count):
                        field[i][j-1-k]=0
                    ans+=now*count
                    count=0
                    f=True if now!=0 else f
                elif now!=field[i][j]:
                    count=0
                now=field[i][j]
                count+=1
        for i in range(h-1):
            for j in range(5):
                if field[i][j]==0:
                    for k in range(i+1,h):
                        if field[k][j]!=0:
                            field[i][j],field[k][j]=field[k][j],field[i][j]
                            break
    print(ans)


Measured memory_bytes: 5624
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let v: Vec<(char, i32, usize)> = (0..n)
        .map(|i| {
            let s: String = read();
            let mut it = s.chars();
            let c = it.next().unwrap();
            let k: i32 = (it.next().unwrap() as i32) - 48;
            (c, k, i)
        })
        .collect();

    let mut bubble_sorted = v.clone();
    let mut bubble_flag: bool = true;
    while bubble_flag {
        bubble_flag = false;
        for index in (1..n).rev() {
            if bubble_sorted[index].1 < bubble_sorted[index - 1].1 {
                bubble_flag = true;
                bubble_sorted.swap(index, index - 1);
            }
        }
    }

    for (index, card) in bubble_sorted.iter().enumerate() {
        if index != n - 1 {
            print!("{}{} ", card.0, card.1);
        } else {
            println!("{}{}", card.0, card.1);
        }
    }

    let mut is_bubble_sorted_stable = true;
    for index_i in 0..n {
        for index_j in (index_i + 1)..n {
            if bubble_sorted[index_i].1 == bubble_sorted[index_j].1
                && bubble_sorted[index_i].2 > bubble_sorted[index_j].2
            {
                is_bubble_sorted_stable = false;
            }
        }
    }

    if is_bubble_sorted_stable {
        println!("Stable");
    } else {
        println!("Not stable");
    }

    let mut select_sorted = v.clone();
    for index in 0..n {
        let mut min_j = index;
        for j in index..n {
            if select_sorted[j].1 < select_sorted[min_j].1 {
                min_j = j
            }
        }
        if index != min_j {
            select_sorted.swap(index, min_j);
        }
    }

    for (index, card) in select_sorted.iter().enumerate() {
        if index != n - 1 {
            print!("{}{} ", card.0, card.1);
        } else {
            println!("{}{}", card.0, card.1);
        }
    }

    let mut is_select_sorted_stable = true;
    for index_i in 0..n {
        for index_j in (index_i + 1)..n {
            if select_sorted[index_i].1 == select_sorted[index_j].1
                && select_sorted[index_i].2 > select_sorted[index_j].2
            {
                is_select_sorted_stable = false;
            }
        }
    }

    if is_select_sorted_stable {
        println!("Stable");
    } else {
        println!("Not stable");
    }
}



Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;


int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  vector<pair<ll,ll>> vec_sorted(n);
  rep(i,n){
    cin >> vec[i];
    vec_sorted[i] = make_pair(vec[i],i);
  }
  sort(all(vec_sorted),greater<pair<ll,ll>>());

  vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
  rep(i,n){
    //cout << vec_sorted[i].first << endl;
    rep(j,i+1){
      chmax(dp[j][i-j+1],dp[j][i-j] + abs(vec_sorted[i].second - (n-1-(i-j))) * vec_sorted[i].first);
      chmax(dp[j+1][i-j],dp[j][i-j] + abs(vec_sorted[i].second - j) * vec_sorted[i].first);
    }
  }
  ll ans = 0;
//  rep(i,n+1){
//    rep(j,n+1){
//      cout << dp[i][j] << " ";
//    }
//    cout << endl;
//  }

  rep(i,n+1){
    chmax(ans,dp[i][n-i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34676
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(i%c==0)d++;
    }
    cout<<d<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
#define INF 1000000

int min(int a,int b){
  if (a>b)
    return b;
  else
    return a;
}

int main(){
  int n,m,i,j,a,b,time,cost,k,p,q,r;
  while (1){
    scanf("%d %d",&n,&m);
    if (n==0 && m==0) return 0;
    int C[m][m],T[m][m];
    for (i=0;i<m;i++)
      for (j=0;j<m;j++){
        if (i!=j){
            C[i][j]=INF;
            T[i][j]=INF;
          }else{
            C[i][j]=0;
            T[i][j]=0;
        }
      }
    for (i=0;i<n;i++){
      scanf("%d %d %d %d",&a,&b,&cost,&time);
      C[a-1][b-1]=cost;
      C[b-1][a-1]=cost;
      T[a-1][b-1]=time;
      T[b-1][a-1]=time;
    }
    for (k=0;k<m;k++)
      for (i=0;i<m;i++)
        for (j=0;j<m;j++){
          C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
          T[i][j]=min(T[i][j],T[i][k]+T[k][j]);
        }
    scanf("%d",&k);
    for (i=0;i<k;i++){
      scanf("%d %d %d",&p,&q,&r);
      if (r==0)
        printf("%d\n",C[p-1][q-1]);
      else
        printf("%d\n",T[p-1][q-1]);
    }
  }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S, T;
	cin >> S >> T;
	int ans = T.size();
	for (int i = 0; i < S.size() - T.size() + 1; i++) {
		int cnt = 0;
		for (int j = 0; j < T.size(); j++) {
			if (S[i + j] != T[j]) {
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3600
use std::io;


fn main() {
    let (n, x) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    println!("{}", recur(n, x));

}

fn recur(n: usize, x: usize) -> usize {
    if n == 0 {
        if x == 0 { return 0; }
        else { return 1; }
    }

    let mut h = 1;
    let mut l = 1;
    for _ in 0..n {
        h = h * 2 + 3;
        l = l * 2 + 1;
    }
    l = (l - 1) / 2;

    if x == 1 { 0 }
    else if x <= h / 2 {
        recur(n - 1, x - 1)
    } else if x == h / 2 + 1 {
        recur(n - 1, x - 1) + 1
    } else {
        recur(n - 1, x - h / 2 - 1) + l + 1
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
use std::collections::{VecDeque, HashSet, HashMap};
use std::cmp::max;

fn read_line() -> String {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf);
  buf
}

pub fn main() {
  fn read_hwm() -> (i32, i32, i32) {
    let a:Vec<i32> = read_line().split_whitespace().map(|e| e.parse().unwrap()).collect();
    (a[0], a[1], a[2])
  }

  fn read_hw() -> (i32, i32) {
    let a:Vec<i32> = read_line().split_whitespace().map(|e| e.parse().unwrap()).collect();
    (a[0], a[1])
  }

  let (_, _, m) = read_hwm();
  let mut h_map = HashMap::new();
  let mut h_max: i32 = 0;
  let mut w_map = HashMap::new();
  let mut w_max: i32 = 0;
  let mut set = HashSet::<(i32, i32)>::new();

  for _ in 0..m {
    let hw = read_hw();
    *h_map.entry(hw.0).or_insert(0) += 1;
    *w_map.entry(hw.1).or_insert(0) += 1;
    h_max = max(h_max, *h_map.get(&hw.0).unwrap());
    w_max = max(w_max, *w_map.get(&hw.1).unwrap());
    set.insert(hw);
  }

  let h_vec:Vec<i32> = h_map.into_iter().filter(|a| (*a).1.eq(&h_max)).map(|a|a.0).collect();
  let w_vec:Vec<i32> = w_map.into_iter().filter(|a| (*a).1.eq(&w_max)).map(|a|a.0).collect();


  let h_len = (&h_vec).len();
  let w_len = (&w_vec).len();
  let tyouhuku = {
    let mut find = false;
    for i in 0..h_len as usize {
      for j in 0..w_len as usize {
        if !set.contains(&((&h_vec)[i], (&w_vec)[j])) {
          find = true;
          break;
        }
      }
      if find {break;}
    }
    !find
  };
  println!("{}", if tyouhuku {h_max+w_max-1} else {h_max+w_max})
}


Measured memory_bytes: 18348
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <functional>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

int t[8][3] = {
	{1,2,3},
	{4,5,6},
	{7,8,9},
	{1,4,7},
	{2,5,8},
	{3,6,9},
	{1,5,9},
	{3,5,7}
};

char solve(char *c){
	for (int i = 0; i < 8; i++){
		if(c[t[i][0]-1] == c[t[i][1]-1] && c[t[i][1]-1] == c[t[i][2]-1]){
			if(c[t[i][0]-1] == 's') continue;
			return c[t[i][0]-1];
		}
	}
	return 'd';
}

int main(){
	char c[10];
	while(~scanf("%s",c)){
		printf("%c\n",solve(c));
	}
	return 0;
}

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }

int main(void) {
	string A, B, C;
	cin >> A >> B >> C;
	if (A.back() == B.front() && B.back() == C.front()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
X = int(input())
def countWays(costList, aim):
    an = [1] + [0]*(10**5+105)
    for i in range(aim):
        for j in costList:
           an[i+j] = max(an[i+j],an[i])
    return an[aim]

print(countWays([100,101,102,103,104,105],X))

Measured memory_bytes: 4596
<?php

fscanf(STDIN,"%d %d %d",$a,$b,$x);
$a_mod_x = $a % $x;
$left = $a;
if($a_mod_x != 0)
{
	$left = $a - $a_mod_x + $x;
}
$right = $b - $b % $x;

$ans = ($right - $left) / $x + 1;

echo $ans, "\n";


Measured memory_bytes: 4604
def min_ind_except_for_fixed(seq, fixed):
  m = float('inf')
  ind = -1
  for i in range(len(seq)):
    if not fixed[i] and seq[i] < m:
      ind = i
      m = seq[i]
  return ind


def dijkstra_mat(adj_matrix, start, goal):
  V = len(adj_matrix)
  assert V == 10
  cost = [float('inf')] * V    # cost[i] = (minimum cost from node_start to node_i)
  cost[start] = 0
  fixed = [False] * V
  for _ in range(V):
    u = min_ind_except_for_fixed(cost, fixed)
    fixed[u] = True
    for j in range(V):
      cost[j] = min(cost[j], cost[u] + adj_matrix[u][j])
  return cost[goal]



h, w = map(int, input().split())
adj_matrix_weight = [list(map(int, input().split())) for _ in range(10)]

min_cost_change_to_1 = [dijkstra_mat(adj_matrix_weight, start=i, goal=1) for i in range(10)]
# print(min_cost_change_to_1)

total_min_cost = 0
for _ in range(h):
  line = list(map(int, input().split()))
  for num in line:
    if num != -1:
        total_min_cost += min_cost_change_to_1[num]

print(total_min_cost)


Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        char[] cs = s.toCharArray();

        String ans = "";
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] == 'B') {
                if (ans.length() != 0) {
                    ans = ans.substring(0, ans.length() - 1);
                }
            } else {
                ans += cs[i];
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;

    if (A > B) {
        cout << 0 << endl;
    }
    else {
        if (N == 1 && A != B) {
            cout << 0 << endl;
        }
        else {
            cout << (A + B * (N - 1)) - (A * (N - 1) + B) + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
def main():
    k = int(input())
    hp = [i for i in range(k+4)]
    r, w = 1, 10
    while w <= k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1

    print(hp[k])

main()


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

long long gcd(long long a,long long b){
  if (a%b==0 )return b;
  else return gcd(b,a%b);
}
long long dp[100010];
int main() {
  int n; cin>>n;
  vector<int>vec(n);
  int ave=0;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    vec[i]=a;
    ave+=a;
  }
  ave/=n;
  
  int sum1=0;
  int sum2=0;
  for(int i=0;i<n;i++){
    sum1+=pow(abs(vec[i]-ave),2);
  }
  for(int i=0;i<n;i++){
    sum2+=pow(abs(vec[i]-(ave+1)),2);
  }
  cout<<min(sum1,sum2)<<endl;
}

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

using namespace std;

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

    int N = S.size();

    // 長さ2の部分文字列のチェック
    for (int i = 0; i < N - 1; ++i) {
        if (S[i] == S[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }

    // 長さ3の部分文字列のチェック
    for (int i = 0; i < N - 2; ++i) {
        if (S[i] == S[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int flag = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] != i+1) {
            if (p[p[i]-1] != i+1) {
                flag = 1;
                break;
            } else {
                cnt++;
            }
        }
    }

    if (flag || cnt >= 3) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

vector <pair<int, int> > v;

int main() {
	int n;
	scanf("%d", &n);
	int sum = n+1 - n%2;
	for (int i=1 ; i<=n ; i++) {
		for (int j=i+1 ; j<=n ; j++) {
			if (i+j != sum) v.pb(mp(i, j));
		}
	}
	printf("%d\n", v.size());
	for (int i=0 ; i<v.size() ; i++) {
		printf("%d %d\n", v[i].x, v[i].y);
	}
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;

int main(){
	int N; cin >> N;
	vector<int> b(2*N,0);
	int g = 0, z = 0, c = 0;
	repp(i,0,N){
		int A,B; cin >> A >> B;
		if(A == -1 && B == -1){
			g += 2;
			++c;
		} else if(A == -1){
			b[B-1] = 1;
			++g;
			++z;
		} else if(B == -1){
			b[A-1] = 1;
			++g;
			++z;
		} else {
			b[A-1] = b[B-1] = 2;
		}
	}
	vector<vector<LL>> dp(N+1,vector<LL>(N+1,0));
	dp[c][0] = 1;
	repp(i,0,2*N){
		if(b[i] == 2) continue;
		vector<vector<LL>> nx(N+1,vector<LL>(N+1,0));
		repp(j,0,N+1) repp(k,0,N+1){
			int r = 2*j+k+z-g;
			if(r < 0) continue;
			if(b[i] == 1){
				if(r > 0) (nx[j][k] += dp[j][k]*r) %= mod;
				if(k < N) (nx[j][k+1] += dp[j][k]) %= mod;
			} else {
				if(j > 0 && k < N) (nx[j-1][k+1] += dp[j][k]*j) %= mod;
				if(k > 0) (nx[j][k-1] += dp[j][k]) %= mod;
				(nx[j][k] += dp[j][k]) %= mod;
			}
		}
		swap(dp,nx);
		if(b[i] == 0) --g;
		if(b[i] == 1) --z;
	}
	cout << dp[0][0] << endl;
	return 0;
}
/*
j : (-1,-1)
k : (*,-1) (外からのみ追加可能)
r : (*,-1) を要求
z : (*,-1) の残り
g : -1 の残り個数

2j+k+z=g+s
*/


Measured memory_bytes: 1740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168&lang=ja

int main() {

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

    ll dp[n+5]; REP(i, n+5) dp[i] = 0;
    dp[0] = 1;
    REP(i, n+1) {
      dp[i+1] += dp[i];
      dp[i+2] += dp[i];
      dp[i+3] += dp[i];
    }

    cout << (dp[n]+(3650-1))/3650 << "\n";
  }

  return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
    int N; cin >> N;
    bool res = false;
    for (int i = 0; i*4 <= N; ++i) {
        for (int j = 0; j*7 <= N; ++j) res |= i*4 + j*7 == N;
    }
    if (res) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#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())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

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

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}
template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}
void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int f(int r, int d, int xi) {
  return r * xi - d;
}

int main() {
  int r, d, x;
  cin >> r >> d >> x;

  int xi = x;
  for (int i = 1; i <= 10 ; ++i) {
    xi = f(r, d, xi);
    p(xi);
  }
}

Measured memory_bytes: 256
loop {
    x = gets.split(' ')
    x[0] = x[0].to_i
    x[1] = x[1].to_i
    if (x[0] == 0 && x[1] == 0)
        break
    end
    if (x[0] > x[1])
        x[0], x[1] = x[1], x[0]
    end
    puts("#{x[0]} #{x[1]}")
}



Measured memory_bytes: 6836
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=222222;
int col[maxn],fir[maxn],to[maxn],nxt[maxn],D[maxn],tot;
bool vis[maxn];
queue<int> Q;
void add_edge(int x,int y,int z)
{
	nxt[++tot]=fir[x];
	to[fir[x]=tot]=y;
	D[tot]=z;
}
void bfs(int x)
{
	Q.push(x);vis[x]=true;
	col[x]=0;
	while(!Q.empty())
	{
		int q=Q.front();Q.pop();
		for(int i=fir[q],v=to[i];i;i=nxt[i],v=to[i])if(!vis[v]) col[v]=col[q]^D[i],vis[v]=true,Q.push(v);
	}
}
int main()
{
	int N;scanf("%d",&N);
	for(int i=1;i<N;++i)
	{
		int a,b,c;scanf("%d%d%d",&a,&b,&c);
		c=(c&1);
		add_edge(a,b,c);
		add_edge(b,a,c);
	}
	bfs(1);
	for(int i=1;i<=N;++i) printf("%d\n",col[i]);
	return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String moji = sc.nextLine();
			char[] n = moji.toCharArray();
			String temp = "";
			for(int j = 0; j < 26; j++){
				for(int i = 0; i < n.length; i++){
					if('a' <= n[i] && n[i] <= 'z')
						if(n[i] == 'z')
							n[i] = 'a';
						else
							n[i]++;
				}
				temp = String.valueOf(n);
				if(temp.contains("that") || temp.contains("this") || temp.contains("the")){
					System.out.println(temp);
					break;

				}
			}
		}
	}
}

Measured memory_bytes: 26328
import collections

N = int(input())

W = []

ns = ""
tflag = False
for count in range(N):
    W.append(str(input()))
    if ns == "":
        ns = W[count]
    else:
        if ns[len(ns)-1] != W[count][0]:
            tflag = True
        else:
            ns = W[count]


ls = collections.Counter(W)

for ccount in ls.values():
    if ccount > 1:
        tflag = True
        break
if tflag == True:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3316
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#define maxn 400010
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll tree[maxn*4],lazy[maxn*4];
ll ans=0;
int tp[2];
ll st[2][maxn];
struct node {
	ll x,y;
} p[maxn];
bool cmp(node a,node b) {
	return a.x < b.x;
}
void pu(int rt) {
	tree[rt] = max(tree[rt*2], tree[rt*2+1]);
}
void pd(int rt) {
	if(lazy[rt]) {
		lazy[rt*2] += lazy[rt];
		lazy[rt*2+1] += lazy[rt];
		tree[rt*2] += lazy[rt];
		tree[rt*2+1] += lazy[rt];
		lazy[rt] = 0;
	}
}
void upd(int rt,int l,int r,int al,int ar,ll val) {
	if(al <= l && ar >= r) {
		tree[rt] += val;
		lazy[rt] += val;
		return;
	}
	pd(rt);
	int mid = l+r>>1;
	if(al <= mid) upd(rt*2,l,mid,al,ar,val);
	if(ar > mid) upd(rt*2+1,mid+1,r,al,ar,val);
	pu(rt);
}
int n, w, h;
void solve() {
	memset(tree,0,sizeof(tree));
	memset(lazy,0,sizeof(lazy));
	tp[0] = tp[1] = 0;
	st[0][0] = st[1][0] = 0;
	upd(1, 1, n, 1, n, h*2);
	for(int i=2; i<=n; i++) {
		upd(1, 1, n, 1, i-1, (p[i].x - p[i-1].x)*2);
		ans=max(ans,tree[1]);
		if(p[i].y >= h/2) {
			upd(1, 1, n, st[0][tp[0]], i-1, -h*2 + p[i].y*2);
			
			while(tp[0] > 0 && p[st[0][tp[0]]].y >= p[i].y ) {
				upd(1, 1, n, st[0][tp[0] - 1], st[0][tp[0]] - 1, (p[i].y - p[st[0][tp[0]]].y)*2);
				tp[0]--;
			}
			st[0][++tp[0]] = i;
		}else {
			upd(1, 1, n, st[1][tp[1]], i-1, (- p[i].y)*2);
			while(tp[1] > 0 && p[st[1][tp[1]]].y <= p[i].y) {
				upd(1, 1, n, st[1][tp[1] - 1], st[1][tp[1]] - 1, -(p[i].y - p[st[1][tp[1]]].y)*2);
				tp[1]--;
			}
			st[1][++tp[1]] = i;
		}
	}
}
int main() {

	cin >> w >> h >> n;
	n++;
	for(int i=2; i<=n; i++) {
		scanf("%lld%lld",&p[i].x,&p[i].y);
	}
	p[++n].x = w;
	p[n].y = h;
	sort(p+2,p+1+n,cmp);
	solve();
	swap(w, h);
	for(int i=1; i<=n; i++) swap(p[i].x, p[i].y);
	sort(p+2,p+1+n,cmp);
	solve();
	printf("%lld\n",ans);
}

Measured memory_bytes: 35712