akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define pb push_back
#define nl cout << "\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c.size())
#define mp make_pair
#define mt make_tuple
#define get(x,c) get<x>(c)
#define trav(a,x) for(auto a=x.begin() ; a!=x.end() ; a++)
#define rep(i,n) for(int i=0 ; i<n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x,ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x,ll ex ,ll md) {ll ans = 1ll;while(ex > 0){if(ex & 1ll) ans = (ans*x)%md; ex >>= 1ll;x=(x*x)%md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e5 + 11;

void solve(){
    ll n;cin>> n;
    map<ll,ll>m;
    for(ll i = 1 ; i <=100 ; i++){
        for(ll j = 1 ; j<=100;j++){
            for(ll k= 1;k<=100;k++){
                ll val = i*i + j*j + k*k + i*j + j*k + k*i;
                m[val]++;
            }
        }
    }
    rep(i,n){
        cout << m[i + 1] <<endl;
    }
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC = 1;
    // cin >> NTC;
    ll PTC = 0;
    while(PTC++ < NTC){
        // cout << "Case #" << PTC << ":" << ' ';
        solve();
        cout << "\n";
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 6144
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
mention=[[] for i in range(N+1)]
for i in range(N):
    a=int(input())
    for k in range(a):
        x,y=nm()
        mention[i+1].append((x,y))

ans=0
consistent=True
for i in range(2**N):
    consistent=True
    count=0
    for j in range(N):
        if((i>>j)&1):
            count+=1
            for k in range(len(mention[j+1])):    
                tmp=mention[j+1][k]
                if(tmp[1]!=((i>>(tmp[0]-1))&1)):
                        consistent=False

    if((consistent==True)):
        ans=max(ans,count)

print(ans)
            



Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long binary_pow(long long x, long long deg){
    long long ans = 1;
    while (deg) {
        if (deg & 1) {
            ans = (ans * x) % MOD;
        }
        x = (x * x) % MOD;
        deg >>= 1ll;
    }
    return ans;
}
long back(long long x){
    return binary_pow(x, MOD - 2);
}
int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long long ans = 0;
    vector <long long> ost(r2 + c2 + 5);
    vector <long long> back_ost(max(r2, c2) + 5);
    ost[0] = 1;
    ost[1] = 1;
    for (int i = 2; i < ost.size(); ++i){
        ost[i] = (ost[i - 1] * (long long)i) % MOD;
    }
    back_ost[0] = 1;
    back_ost[1] = 1;
    for (int i = 2; i < back_ost.size(); ++i){
        back_ost[i] = back(ost[i]);
    }
    for (int i = r1; i < r2 + 1; ++i){
        long long first = ((ost[i + c2 + 1]) * ((back_ost[c2] * back_ost[i + 1]) % MOD)) % MOD;
        long long second = ((ost[i + c1]) * ((back_ost[i + 1] * back_ost[c1 - 1]) % MOD)) % MOD;
        // long long first = (ost[i + c2 + 1] * ((back_ost[c2] * back_ost[i + 1]) % MOD)) % MOD;
        // long long second = (ost[i + c1] * ((back_ost[i + 1] * back_ost[c1 - 1])) % MOD)%MOD;
        ans += (first - second);
        ans = (ans + MOD) % MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 26636
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll N) { // 約数の個数を数える関数
  vector<pair<ll, ll> > res;
  for (ll a = 2; a*a <= N; a++) {
    if (N % a != 0) continue;
    ll ex = 0;
    while (N % a == 0) {  // aが素因数だったらexを加算してNをaで割る
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main() {
  ll N;
  cin >> N;

  const int MOD = 1000000007;
  vector<ll> ex(N+1, 0);  // exp(p) := pの指数
  for (ll n=2; n <= N; n++) {
    const auto& res = prime_factorize(n);  // nの素因数分解
    for (auto p : res) ex[p.first] += p.second;
  }
  ll res = 1;
  for (int p = 2; p <= N; p++) {
    res *= ex[p] + 1;  // 約数の個数は(exp+1)の積
    res %= MOD;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
def nyu():
    N = int(input())
    A = list(map(int,input().split()))

    return N,A

def kansu(LN,LA):
    highflg = False
    lowflg = False
    count = 1

    for n in range(LN-1):
        if LA[n] == LA[n+1]:
            continue
        elif LA[n] < LA[n+1]:
            highflg = True
            if lowflg == True:
                count += 1
                lowflg = False
                highflg = False
        else:
            lowflg = True
            if highflg == True:
                count += 1
                lowflg = False
                highflg = False
    
    print(count)






N,A = nyu()
kansu(N,A)

Measured memory_bytes: 14224
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#define INF 0X3F3F3F3F
#define N 1005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
int n, k;
int main(){
    // IN;
    SCC(n, k);
    if(k == 0){
        cout << 1LL * n * n << endl;
    }else {
        LL ans = 0;
        FF(b, k + 1, n){
            ans += 1LL * (b - k) * (n / b) + (max(0, n % b - k + 1));
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,k = gets.split.map!(&:to_i)

count = Array.new(10**5+1,0)
n.times do
    a,b = gets.split.map!(&:to_i)
    count[a] += b
end

(10**5).times{|i| count[i+1] += count[i]}

puts count.index{|e| e >= k}


Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=998244353;
signed main(){
    int k,n,a[200000];
    cin>>k>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=a[0]+k-a[n-1];
    for(int i=1;i<n;i++)
        ans=max(ans,a[i]-a[i-1]);
    cout<<k-ans<<endl;
}


Measured memory_bytes: 1792
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
A_sum = np.cumsum(A)
B_sum = np.cumsum(B[::-1])[::-1]
li = []
for i in range(N):
    li.append(A_sum[i]+B_sum[i])
print(max(li))

Measured memory_bytes: 13428
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int k,x;
  cin >> k >> x;
  bool ans = 500*k>=x;
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long A, long long B, long long H, long long M) {
    double ax, ay, bx, by;
    static const double pi = 3.141592653589793;
    ax = A * cos(2 * pi / 12 * (H + 1.0 * M / 60));
    ay = A * sin(2 * pi / 12 * (H + 1.0 * M / 60));
    bx = B * cos(2 * pi * (H + 1.0 * M / 60));
    by = B * sin(2 * pi * (H + 1.0 * M / 60));
    printf("%.16f\n", sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)));
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long H;
    scanf("%lld", &H);
    long long M;
    scanf("%lld", &M);
    solve(A, B, H, M);
    return 0;
}


Measured memory_bytes: 4124
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec cs(n);
	unordered_map<string, ll> ump;
	rep(i, n){
		string s;
		ll t;
		cin >> s >> t;
		ump[s] = i;
		cs[i] = t;
		if(i) cs[i] += cs[i-1];
	}
	string t;
	cin >> t;
	ll p = ump[t];
	co(cs[n-1]-cs[p]);

	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
sea = [True]*N
for i in range(N):
    if i >=1:
        if all([H[i] >= H[j] for j in range(i) ] ):
            sea[i] = True

        else:
            sea[i] = False
ans = sum(sea)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int a,b,x; cin>>a>>b>>x;
  cout<<((a<=x&&x<=a+b)? "YES":"NO" );
} 


Measured memory_bytes: 256
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

int main() {
	fastIO;
	int x, y;
	cin >> x >> y;
	if (x % 3 == 0 || y % 3 == 0 || (x + y) % 3 == 0) {
		cout << "Possible";
	}
	else cout << "Impossible";
	return 0;
}

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

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int a[n],b[m];

    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    for(int i=0;i<m;i++){
      cin>>b[i];
    }

    int sumA,sumB;
    sumA = sumB = 0;
    for( int i=0;i<n;i++)sumA += a[i];
    for( int i=0;i<m;i++)sumB += b[i];
    int diff = sumA - sumB;
    sort(a,a+n);
    sort(b,b+m);
    bool flag=true;
    for( int i=0;i<n;i++){
      for(int j=m-1;j>=0;j--){
	if(2*(a[i]-b[j])==diff){
	  cout << a[i] << " " << b[j] << endl;
	  flag=false;
	  break;
	}
      }
      if(flag==false)break;
    }
    if(flag!=false)
      cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll dp[60][60][3000];
ll N,A;
ll x[60];

int main(){
    cin>>N>>A;
    rep(i,N) cin>>x[i];
    rep(i,60) rep(j,60) rep(k,3000) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, N){
        rep(j, N){
            rep(k, 3000){
                if(dp[i][j][k]==0) continue;
                //使わない時
                dp[i+1][j][k] += dp[i][j][k];
                //使う時
                dp[i+1][j+1][k+x[i]] += dp[i][j][k];
            }
        }
    }
    ll ans = 0;
    for(int i = 1;i < N+1;i++){
        ans += dp[N][i][i*A];
    }
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 84608
#include <stdio.h>

int main ()
{
   int x[3000], y[3000];
   int i, j;

   for (i = 0; i < 3000; i++) {
      scanf ("%d %d", &x[i], &y[i]);
         if (x[i] == 0 && y[i] == 0){
            break;
         }
   }

   for (j = 0; j < i; j++) {
      if (x[j] <= y[j]) {
         printf ("%d %d\n", x[j], y[j]);
      } else if (y[j] < x[j]) {
         printf ("%d %d\n", y[j], x[j]);
      }
   }

   return 0;
}

Measured memory_bytes: 620
#include <cstdio>
#include <cstdlib>

using namespace std;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

const int mod = 1000000007;
int a[100000];
long long sum[100000];

int main() {
    int n, i;
    long long ans = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    inverse inv(n, mod);
    
    for (i = 0; i < n; i++) sum[i] = inv.get_inv(i + 1);
    for (i = 1; i < n; i++) sum[i] = (sum[i] + sum[i - 1]) % mod;
    
    for (i = 0; i < n; i++) ans = (ans + (sum[i] + sum[n - i - 1] - 1) % mod * a[i]) % mod;
    
    printf("%lld\n", ans * inv.get_fact(n) % mod);
    
    return 0;
}


Measured memory_bytes: 3712
{-# OPTIONS_GHC -Wall #-}

import           Control.Monad
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as M

readInt :: String -> Int
readInt = read

inf :: Int
inf = 1010000000000000000

lowerBound :: V.Vector Int -> Int -> Int -> Int -> Int
lowerBound v x lo hi
    | lo == hi  = lo
    | otherwise = case compare x y of
        GT -> lowerBound v x (mid+1) hi
        _  -> lowerBound v x lo mid
        where
            y   = v V.! mid
            mid = (lo+hi) `div` 2

calcDp :: Int -> V.Vector Int -> V.Vector Int
calcDp n as = res
    where
        res = V.create $ do
            dp <- M.replicate n inf
            forM_ [0..n-1] $ \i -> do
                dp' <- V.unsafeFreeze dp
                let x   = as V.! i
                let lb  = lowerBound dp' x 0 (i+1)
                M.write dp lb x
            return dp

main :: IO ()
main = do
    n  <- fmap readInt getLine
    as <- fmap (map readInt . words) getContents
    let as' = V.fromList as

    let dp  = calcDp n as'
    let ans = lowerBound dp inf 0 n

    --print dp
    print ans



Measured memory_bytes: 9916
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

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



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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];

  vector<int> pos(3, 0);
  int now = 0;
  while(1) {
    //cout << now << ":" << pos[now] << endl;
    if(pos[now] == SZ(s[now])) break;
    if(s[now][pos[now]] == 'a') {
      pos[now]++;
      now = 0;
    } else if(s[now][pos[now]] == 'b') {
      pos[now]++;
      now = 1;
    } else {
      pos[now]++;
      now = 2;
    }
  }
  
  if(now == 0) cout << "A" << endl;
  else if(now == 1) cout << "B" << endl;
  else cout << "C" << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

int dp[303][303][303];

void modadd(int &a, int b){
	a += b;
	a %= MOD;
}

vector<vector<P>> que(303);

int main(){
	
	ll n,m;cin >> n >> m;
	REP(i,m){
		ll a,b,c;cin >> a >> b >> c;
		que[b].EB(a,c);
	}
	
	dp[0][0][0] = 1;
	
	REP(i,n+1){
		REP(j,n+1){
			REP(k,n+1){
				if(dp[i][j][k] == 0)continue;
				int r = max(i,max(j,k));
				REP(ii,que[r].size()){
					int cou = 0;
					if(i >= que[r][ii].FI)cou++;
					if(j >= que[r][ii].FI)cou++;
					if(k >= que[r][ii].FI)cou++;
					if(cou != que[r][ii].SE)dp[i][j][k] = 0;
				}
				modadd(dp[r+1][j][k], dp[i][j][k]);
				modadd(dp[i][r+1][k], dp[i][j][k]);
				modadd(dp[i][j][r+1], dp[i][j][k]);
			}
		}
	}
	
	int ans = 0;
	REP(i,n+1){
		REP(j,n+1){
			REP(k,n+1){
				int r = max(i,max(j,k));
				if(r == n){
					//cout << "seica " << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
					modadd(ans,dp[i][j][k]);
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
	
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
    int s; read(s);

	vll dp(s + 1, 1);
	dp[0] = dp[1] = dp[2] = 0;
	
	for(int i = 4; i <= s; i++) 
		for(int j = 3; j <= i - 3; j++)
			dp[i] = (dp[i] + dp[i - j]) % MOD;

	println(dp[s]);
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


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

int main(){
  char c;
  rep(i, 1200) {
    scanf("%c", &c);
    if ('a' <= c && c <= 'z') c = c + 'A' - 'a';
    else if ('A' <= c && c <= 'Z') c = c + 'a' - 'A';
    printf("%c", c);
    if (c=='\n') break;
    
  }
  return 0;
}



Measured memory_bytes: 3140
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	double a,s,d;
	int f[5],g[5],h,i,j;
	for(i=0;i<4;i++){
		f[i]=0;
		g[i]=0;
	}
	while(scanf("%lf %lf",&a,&s)!=EOF){
		if(1.1<=a)	f[0]++;
		else if(0.6<=a)	f[1]++;
		else if(0.2<=a) f[2]++;
		else if(0.2>a) f[3]++;
		if(1.1<=s)	g[0]++;
		else if(0.6<=s)	g[1]++;
		else if(0.2<=s) g[2]++;
		else if(0.2>s) g[3]++;
	}
	for(i=0;i<4;i++)	printf("%d %d\n",f[i],g[i]);
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    string S;
    cin >> S;
    if(S == "Sunny") cout << "Cloudy" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int lli;

int main() {
  lli x;
  cin >> x;
  lli ans=(x/(6+5))*2;
  if (x%(6+5)!=0 && x%(6+5)<7) {
    ans++;
  }
  if (x%(6+5)>6) {
    ans+=2;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    if (S == "ABC"){
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}

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


Measured memory_bytes: 3644
#include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<math.h>
    #include<string>
    #include<string.h>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<utility>
    #include<set>
    #include<map>
    #include<stdlib.h>
    #include<iomanip>
     
    using namespace std;
     
    #define ll long long
    #define ld long double
    #define EPS 0.0000000001
    #define INF 1e9
    #define MOD 1000000007
    #define rep(i,n) for(i=0;i<n;i++)
    #define loop(i,a,n) for(i=a;i<n;i++)
    #define all(in) in.begin(),in.end()
    #define shosu(x) fixed<<setprecision(x)
     
    typedef vector<int> vi;
    typedef pair<int,int> pii;
     
    int main(void) {
      int n,m;
      cin>>n>>m;
      int i;
      int path[10][10]={};
      rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        path[a][b]++;
        path[b][a]++;
      }
     
      vi v;
      rep(i,n)v.push_back(i);
     
      int ans=0;
      do{
        if(v[0]!=0)break;
        rep(i,n-1)
          if(path[v[i]][v[i+1]]==0)break;
        if(i==n-1)ans++;
      }while(next_permutation(all(v)));
     
      cout<<ans<<endl;
    }

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

using namespace std;

int main(){
  int q,a,b;
  string str,s;

  cin >> str >> q;
  while(q--){
    cin >> s >> a >> b;
    if(s == "replace"){
      cin >> s;
      str.replace(str.begin()+a, str.begin()+b+1, s);
    }else if(s == "reverse"){
      reverse(str.begin()+a, str.begin()+b+1);
    }else{
      cout << str.substr(a, b-a+1) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3176
import java.util.*;

public class Main {

    static class UnionFind {
        List<Integer> Parent;
        UnionFind(int N) {
            Parent = new ArrayList<Integer>();
            Integer[] values = new Integer[N];
            Arrays.fill(values, -1);
            Parent.addAll(Arrays.asList(values));
        }
        int root(int A) {
            if (Parent.get(A) < 0)
                return A;
            int root = root(Parent.get(A));
            Parent.set(A, root);
            return root;
        }
        int size(int A) {
            return -Parent.get(root(A));
        }

        boolean connect(int A, int B) {
            A = root(A);
            B = root(B);
            if (A == B) {
                return false;
            }

            if (size(A) < size(B)) {
                int temp = A;
                A = B;
                B = temp;
            }

            Parent.set(A, Parent.get(A) + Parent.get(B));
            Parent.set(B, A);

            return true;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
        for (int i=0;i<M;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            list.add(add);
        }
        for (int i=0;i<N;i++) {
            int K = sc.nextInt();
            for (int j=0;j<K;j++) {
                int L = sc.nextInt()-1;
                list.get(L).add(i);
            }
        }
        UnionFind uf = new UnionFind(N);
        for (ArrayList<Integer> l : list) {
            for (int i=0;i<l.size()-1;i++) {
                uf.connect(l.get(i), l.get(i+1));
            }
        }
        if (uf.size(0)==N) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 86128
N, M = [int(x) for x in input().split(' ')]
edges = []
for _ in range(M):
    edges.append([int(x)-1 for x in input().split(' ')])
res = [str(N * (N-1) // 2)]
init = N * (N-1) // 2
f = list(range(N))
cnt = [1] * N
def find(x):
    if x != f[x]:
        f[x] = find(f[x])
    return f[x]
for i in range(M-1, 0, -1):
    a, b = edges[i]
    fx, fy = find(a), find(b)
    if fx == fy:
        res.append(str(init))
    else:
        
        pre = cnt[fx] * (cnt[fx] - 1) // 2 + cnt[fy] * (cnt[fy] - 1) // 2
        if cnt[fx] < cnt[fy]:
            f[fx] = fy
            cnt[fy] += cnt[fx]
            init = init - cnt[fy] * (cnt[fy]-1) // 2 + pre
        else:
            f[fy] = fx
            cnt[fx] += cnt[fy]
            init = init - cnt[fx] * (cnt[fx] - 1) // 2 + pre
        res.append(str(init))
print('\n'.join(res[::-1]))


Measured memory_bytes: 36276
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
l a[200005],b[200005];
l alla,allb;
int main()
{
	l n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	if(n%2!=0)
	{
		int u=n/2;
		int ans=b[u]-a[u]+1;
		cout<<ans<<endl;
		return 0;
	}
	else
	{
		int u=n/2-1,u2=n/2;
		int ans=b[u]+b[u2]-a[u2]-a[u]+1;
		cout<<ans<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 6764
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#ifndef ONLINE_JUDGE
	#define ONLINE_JUDGE
#endif

#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define pb push_back
#define mp make_pair
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,j,n) for(i=j;i<=n;i++)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<int> > graph;
const ll maxn = (ll) 4e5+9;
const ll mod = (ll) 1e9+7;
//ll a[maxn];
//ll dp[1024][1024];
int a[maxn];
void swp(int i,int j);

int main()
{
	std::ios::sync_with_stdio(0);
	ll i,j,k,t,q,m,l,r,n;
	cin>>n>>k;
	q = 2*n-1;
	if(k==1 || k>=(q)){cout<<"No"<<endl;}
	else {
		cout<<"Yes"<<endl;
		repr(i,1,q) {
			a[i]=i;
		}
		swp(n,k);
		swp(n-1,1);
		swp(n+1,q);
		repr(i,1,q)cout<<a[i]<<endl;
	}
}

void swp(int i,int j) {
	int temp = a[i];
	a[i] = a[j];
	a[j] = temp;
}

Measured memory_bytes: 2304
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner scanner = new Scanner(System.in);
                int i = scanner.nextInt();
                int h = i/(60*60);
                int m = (i%(60*60))/60;
                int s = (i%(60));
                System.out.println(h + ":" + m + ":" + s);
        }
}

Measured memory_bytes: 26204
N = int(input())

count_ab = 0
count_fb = 0
count_ea = 0
count_fbea = 0
for i in range(N):
    s = input()
    count_ab += s.count("AB")
    if s[0] + s[-1] == "BA":
        count_fbea += 1
    elif s[0] == "B":
        count_fb += 1
    elif s[-1] == "A":
        count_ea += 1

ans = count_ab
if count_fbea > 0:
    ans += count_fbea - 1
    if count_fb > 0:
        count_fb -= 1
        ans += 1
    if count_ea > 0:
        count_ea -= 1
        ans += 1
ans += min(count_fb, count_ea)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if( a == b && b == c) {
			System.out.println("No");
		} else if(a == b || b == c || a == c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main() {
    int64_t a, b, k;
    cin >> a >> b >> k;

    if(a > k) {
        cout << a - k << " " << b << endl;
    } else if(a + b > k){
        cout << 0 << " " << a + b - k << endl;
    } else {
        cout << "0 0" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
ll solve(int n,ll x){
  if(n == 0) return 1;//レベル0 
  ll len = (1LL<<(n+1)) -3;
  ll num = (1LL<<n) - 1;
  if(x == 1) return 0;
  else if(x <= len+1) return solve(n-1, x-1);
  else if(x <= len+2) return num+1;
  else if(x <= (len+1)*2) return num+1+solve(n-1,x-len-2);
  else return num*2 + 1;

}


int main(){
  int N; long long X;
    cin >> N >> X;
    cout << solve(N, X) << endl;
}

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

const int MAX_WID = 8;
int W, H, C;
int board[MAX_WID][MAX_WID];

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

int count(int y, int x){
	int ret = 0;
	if(board[y][x] == C){
		board[y][x] = 0;
		ret++;
	}
	for(int k=0; k<4; k++){
		int ny = y + dy[k], nx = x + dx[k];
		if(0<=ny && ny<H && 0<=nx && nx<W && board[ny][nx] == C){
			ret += count(ny, nx);
		}
	}
	return ret;
}

void draw(int y, int x, int cur, int tar){
	board[y][x] = tar;
	for(int k=0; k<4; k++){
		int ny = y + dy[k], nx = x + dx[k];
		if(0<=ny && ny<H && 0<=nx && nx<W && board[ny][nx] == cur){
			draw(ny, nx, cur, tar);
		}
	}
}

int dfs(int depth){
	int tmp_board[MAX_WID][MAX_WID];
	memcpy(tmp_board, board, sizeof(board));

	int ret = 0;

	if(depth == 4){
		if(C!=board[0][0]){
			draw(0,0,board[0][0], C);
			ret = count(0,0);
			memcpy(board, tmp_board, sizeof(board));
		}
	}
	else{
		for(int k=1; k<=6; k++)if(k!=board[0][0]){
			draw(0,0,board[0][0], k);
			ret = max(ret, dfs(depth+1));
			memcpy(board, tmp_board, sizeof(board));
		}
	}

	return ret;
}

int main(){
	while(scanf("%d%d%d",&H,&W,&C),H){
		for(int i=0; i<H; i++)for(int j=0; j<W; j++){
			scanf("%d", board[i]+j);
		}
		printf("%d\n",dfs(0));
	}
	return 0;
}

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

int main(){

  int c[3][3];
  for(int i=0;i<3;i++){
  	for(int j=0;j<3;j++) cin >> c[i][j];
  }
  
  int a=c[1][0]-c[0][0],b=c[1][1]-c[0][1],d=c[1][2]-c[0][2];
  int e=c[2][0]-c[1][0],f=c[2][1]-c[1][1],g=c[2][2]-c[1][2];
 
  if(a==b && b==d && e==f && f==g){
  	cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
  

}

Measured memory_bytes: 256
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

d = [[0]*(N) for _ in range(N)]
cnt = 0
for route in permutations(range(1, N+1)):
    for val1, val2 in zip(route[:-1], route[1:]):
        val1, val2 = val1-1, val2-1
        dist = d[val1][val2]
        if dist > 0:
            cnt += dist
        elif dist == 0:
            d[val1][val2] = (pow(xy[val1][0]-xy[val2][0], 2) + pow(xy[val1][1]-xy[val2][1], 2))**(1/2)
            cnt += d[val1][val2]
res = cnt/factorial(N)
print(res)



Measured memory_bytes: 40556
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

bool less_than(char l, char r) {
  const string order = "023456789TJQKA";
  return order.find(l) < order.find(r);
}

int main() {

  for(char trump; cin >> trump;) {
    if(trump == '#') { break; }
    vector<string> cards[4];
    rep(t, 4) rep(i, 13) { string s; cin >> s; cards[t].push_back(s); }

    vector<int> points(4);
    int lead_t = 0;
    rep(i, 13) {
      vector<int> trump_ids;
      rep(t, 4) {
        if(cards[t][i][1] == trump) {
          trump_ids.push_back(t);
        }
      }
      if(trump_ids.size() == 1) {
        points[trump_ids[0]] ++;
        lead_t = trump_ids[0];
      }
      else if(trump_ids.size() > 1) {
        int mxid = -1; char max = '0';
        rep(k, trump_ids.size()) {
          if(less_than(max, cards[trump_ids[k]][i][0])) { max = cards[trump_ids[k]][i][0]; mxid = trump_ids[k]; }
        }
        points[mxid] ++;
        lead_t = mxid;
      }
      else {
        int mxid = -1; char max = '0';
        rep(t, 4) {
          if(cards[lead_t][i][1] == cards[t][i][1]) {
            if(less_than(max, cards[t][i][0])) { max = cards[t][i][0]; mxid = t; }
          }
        }
        points[mxid] ++;
        lead_t = mxid;
      }
//      rep(t, 4) cout << cards[t][i] << " "; cout << endl; rep(t, 4) cout << points[t] << " "; cout << endl;
    }

    if(points[0] + points[2] < points[1] + points[3]) {
      cout << "EW " << points[1] + points[3] - 6 << endl;
    }
    else {
      cout << "NS " << points[0] + points[2] - 6 << endl;
    }

  }
    
  return 0;
}

Measured memory_bytes: 3244
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

print(sum(map(int, list(input()))))


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

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

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

  int ans = k - a.front() - (k - a.back());
  for (int i = 0; i < n - 1; ++i)
    ans = min(ans, k - (a[i + 1] - a[i]));

  cout << ans << endl;
}

Measured memory_bytes: 1024
// 難さんすう すーぱーさんすうと呼ぼう
// Mを素因数分解しといて例えばM=12としてM=(2^2) * (3^1)なるが、それぞれの因数をそれぞれの乗数ぶん振り分ける感じにした組み合わせが答え
// N = 3なら [1, 1, 1]の3つのどれかに振り分ける つまり以下
// 因数2を2つ,因数3を1つ を振り分けて、
//			[2^1, 2^1, 2^0], [3^1, 3^0, 3^0]
// 				-> [1*(2^1 * 3^1)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^0)] = 6*2*1 = 12
// あるいは
//			[2^2, 2^0, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^2 * 3^0)] * [1*(2^0 * 3^0)] * [1*(2^0 * 3^1)] = 4*1*3 = 12
// あるいは
//			[2^1, 2^1, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^1 * 3^0)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^1)] = 2*2*3 = 12
//
// 解説の""計算量はNに依らない""が意味不明だけど、説明してくれないので無視
// すーぱーさんすうの世界ではこれを重複組合せと呼ばうらしい 漢字だね 画数が多い
// n種類のものから重複を許してr個選ぶ場合の数 = nHr = (n+r-1)Cr に帰着できるらしい

// nCr mod Pなので気をつける
package main

import (
	"fmt"
	"math"
)

var MOD int

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	arr := factorization(M)
	// arr := primeFactorization(M)
	ans := 1
	MOD = int(math.Pow10(9)) + 7
	for _, v := range arr {
		// ans *= ncrMod(v+N-1, v, MOD) % MOD
		// ans *= comb(v+N-1, v, MOD) % MOD
		ans = ans * comb(v+N-1, v, MOD) % MOD
	}
	fmt.Println(ans)
}

func factorization(n int) map[int]int {
	a := make(map[int]int)
	for i := 2; i*i <= n; {
		if n%i == 0 {
			a[i]++
			n /= i
		} else {
			i++
		}
	}
	if n > 1 {
		a[n]++
	}
	return a
}

func primeFactorization(x int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			x /= i
			if _, ok := ret[i]; ok {
				ret[i] += 1
			} else {
				ret[i] = 1
			}
		}
	}
	if x > 1 {
		ret[x] += 1
	}
	return ret
}

func ncrMod(n, r, mod int) int {
	// 呼び出すたびにテーブルを作るのは愚
	_n := 1000000
	g1 := make([]int, _n+1)
	g1[0], g1[1] = 1, 1
	g2 := make([]int, _n+1)
	g2[0], g2[1] = 1, 1
	inverse := make([]int, _n+1)
	inverse[0], inverse[1] = 0, 1
	for i := 2; i <= _n; i++ {
		g1[i] = (g1[i-1] * i) % mod
		inverse[i] = mod - inverse[mod%i]*(mod/i)%mod
		g2[i] = (g2[i-1] * inverse[i]) % mod
	}

	return g1[n] * (g2[r] * g2[n-r] % mod) % mod
}

func comb(n, m, MOD int) int {
	return factorial(n, n-m+1, MOD) * pow(factorial(m, 2, MOD), MOD-2, MOD) % MOD
}

func pow(x, n, MOD int) int {
	r := 1
	for ; n > 0; n /= 2 {
		if n%2 == 1 {
			r = r * x % MOD
		}
		x = x * x % MOD
	}
	return r
}

func factorial(n, m, MOD int) int {
	r := 1
	for i := m; i <= n; i++ {
		r = r * i % MOD
	}
	return r
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

		int ans = 0;
		for (int i = 1; i <= 5; i++) {
			if (sc.nextInt() == 0) {
				ans = i;
			}
		}
		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 35736
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});

reader.on('close', () => {

  var n = lines[0]
  var w = [...lines[1].split(' ')]
  for (var k in w) w[k] = parseInt(w[k])

  var math = (ary, t) => {
    var b = ary.slice(0,t)
    var a = ary.slice(t)
    var sum = {
      b: 0,
      a: 0
    }
    for (var v of b) sum.b += v
    for (var v of a) sum.a += v
    return Math.abs(sum.b - sum.a)
  }

  var r = []
  for (var i=1;i<w.length;i++) {
    r.push(math(w, i))
  }

  console.log(Math.min(...r))

});


Measured memory_bytes: 7984
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<int, int>;
using iii = pair<int, ii>;
#define MAXN 1010

char mt[MAXN][MAXN];
int  mem[MAXN][MAXN];
int n, m;

inline bool is_valid(int i, int j, int w){
	return  ((i>=0 and i<n) and (j>=0 and j<m) and (mt[i][j]=='.') and (mem[i][j]==-1 or w<mem[i][j]));
}
int32_t main(){
	ios::sync_with_stdio(0);
	memset(mem, -1, sizeof mem);
	cin >> n >> m;
	int cx, dx, cy, dy;
	cin >> cx >> cy >> dx >> dy;
	--cx; --cy; --dx; --dy;
	for(int i=0; i<n; ++i)
		cin >> mt[i];
	priority_queue<iii> q;
	q.push({0, {cx, cy}});
	while(not q.empty()){
		int w = -q.top().ff;
		int x = q.top().ss.ff;
		int y = q.top().ss.ss; q.pop();
		if(mem[x][y]!=-1 and mem[x][y]<=w) continue;
		mem[x][y] = w;
		if(is_valid(x-1, y, w))
			q.push({-w, {x-1, y}});
		if(is_valid(x+1, y, w))
			q.push({-w, {x+1, y}});
		if(is_valid(x, y-1, w))
			q.push({-w, {x, y-1}});
		if(is_valid(x, y+1, w))
			q.push({-w, {x, y+1}});
		for(int i=x-2; i<=x+2; ++i){
			for(int j=y-2; j<=y+2; ++j){
				if(is_valid(i, j, w+1)){
					q.push({-(w+1), {i, j}});
				}
			}
		}
	}
	cout << mem[dx][dy] << endl;
}


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


int main(){
	set<int> s;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	int q,x;
	cin>>q>>x;
	if(!q){
	s.insert(x);
	cout<<s.size()<<endl;
	}else{
	if(s.find(x)!=s.end())cout<<1<<endl;
	else cout<<0<<endl;
	}


	}


	return 0;
}



Measured memory_bytes: 12516
#include <bits/stdc++.h>
using namespace std;
char s[3010], t[3010];
int dp[3010][3010], tr[3010][3010];
int main() {
	scanf("%s%s", s+1, t+1);
	int sl = strlen(s+1), tl = strlen(t+1);
	for(int i=0; i<=sl; i++)
		for(int j=0; j<=tl; j++) {
			if(i == 0) tr[i][j] = 2;
			else if(j == 0) tr[i][j] = 1;
			else {
				if(s[i] == t[j]) {
					dp[i][j] = dp[i-1][j-1] + 1;
					tr[i][j] = 0;
				} else if(dp[i-1][j] > dp[i][j-1]) {
					dp[i][j] = dp[i-1][j];
					tr[i][j] = 1;
				} else {
					dp[i][j] = dp[i][j-1];
					tr[i][j] = 2;
				}
			}
		}
	int a = sl, b = tl;
	vector<char> res;
	while(a > 0 || b > 0) {
		if(a && b && tr[a][b] == 0) res.push_back(s[a]), a--, b--;
		else if(tr[a][b] == 1) a--;
		else b--;
	}
	reverse(res.begin(), res.end());
	for(auto& it : res) putchar(it);
	return 0;
}

Measured memory_bytes: 70912
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a;
  string s;
  cin >> a >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){
   int n;   cin >> n;
   int a[n],b[n];
   for(int i=0;i<n;i++){
       cin >> a[i] >> b[i];
   }

   for(int i=0;i<=n;i++){
       
       if(a[i] == b[i])cnt++;
       else cnt = 0;
       if(cnt == 3){
           cout << "Yes" << endl;
           return 0;
       }
       
   }
   cout << "No" << endl;
}

Measured memory_bytes: 3632