akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long ll;

const int N = 200010;
const int MOD = 998244353;

ll fen[N];
int n, k, p[N];

void update (int p, ll v) {
  while (p < N) fen[p] = (fen[p] + v) % MOD, p += p & -p;
}

ll pref (int p) {
  ll ret = 0;
  while (p) ret = (ret + fen[p]) % MOD, p -= p & -p;
  return ret;
}

inline ll get (int l, int r) {
  return (pref(r) - pref(l - 1) + MOD) % MOD;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", p + i);
  }
  fenwick_tree <int> f(n + 69);
  ll chance = inv_mod(k, MOD);
  ll offset = (MOD + 1 - chance) % MOD;
  ll half = inv_mod(2, MOD);
  ll ans = 0;
  for (int j = 1; j <= k; ++j) {
    ans += (j - 1) * half, ans %= MOD;
    f.add(p[j], 1);
  }
  for (int j = k + 1; j <= n; ++j) {
    ll cur = pow_mod(offset, j - k, MOD) * half % MOD;
    ll small = f.sum(1, p[j]);
    ans = (ans + small * cur) % MOD;
    ans = (ans + (k - small) * (1 - cur)) % MOD;
  }
  for (int j = 1; j <= k; ++j) {
    f.add(p[j], -1);
  }
  for (int j = k + 1; j <= n; ++j) {
    ll cur = pow_mod(offset, j, MOD) * half % MOD;
    ll big = j - 1 - k - f.sum(1, p[j]);
    ll smallAdd = cur * pref(p[j] - 1) % MOD;
    ll bigAdd = (big - cur * get(p[j] + 1, n)) % MOD;
    ans += smallAdd, ans += bigAdd;
    f.add(p[j], 1); update(p[j], pow_mod(offset, MOD - 1 - j, MOD));
  }
  // for (int j = k + 1; j <= n; ++j) {
  //   int x = p[i], y = p[j];
  //   ll swap = pow_mod(offset, max(0, j - max(i, k)), MOD) * half % MOD;
  //   if (x < y) ans += swap; else ans += 1 - swap;
  // }
  ans %= MOD, ans += MOD, ans %= MOD;
  cout << ans << '\n';
  return 0;
}



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

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

  int a, b, c;
  cin >> a >> b >> c;

  if (c >= a && c <= b) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  cout << "ABC" << n << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=100010;
int n,m;
int a,b;
int cnt[N];

int main() {
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++) {
        scanf("%d%d",&a,&b);
        cnt[a]++;
        cnt[b]++;
    }
    bool flag=true;
    for (int i=1;i<=n;i++) {
        if (cnt[i]%2==1) {
            flag=false;
            break;
        }
    }
    if (flag) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define deba(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void solve(){
    ll n,kk;
    cin>>n>>kk;
    vll v(n);
    fr(i,0,n)cin>>v[i];
    vll ans(n,INT_MAX);
    ans[1]=abs(v[1]-v[0]);ans[0]=0;
    for(int i=2;i<n;i++){
        for(ll k=1;k<=kk && (i-k)>=0;k++){
        ans[i]=min(ans[i-k]+abs(v[i-k]-v[i]),ans[i]);
    }
    }
    cout<<ans[n-1]<<endl;
    
    
}  
int main(){
    ll t=1;
//cin>>t;
while(t--){
     solve();
   //  cout<<endl;
}
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=2e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
int n,a[N];
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>();
}
vector<int>E[N],s[N];
bool vis[N];
priority_queue<int>q;
#define pb push_back
int d[N];
void dfs(int u)
{
	vis[u]=1;
	sort(E[u].begin(),E[u].end());
	for(int v:E[u])if(!vis[v])
	{
		s[u].pb(v),d[v]++;
		dfs(v);
	}
}
void work()
{
	sort(a+1,a+n+1);
	For(i,1,n)For(j,i+1,n)
	{
		if(__gcd(a[i],a[j])!=1)
		{
			E[i].pb(j),E[j].pb(i);		
			//cerr<<i<<' '<<j<<endl;
		}
	}
	For(i,1,n)if(!vis[i])
	{
		dfs(i),q.push(i);
	}
	int u;
	while(!q.empty())
	{
		u=q.top();q.pop();
		write(a[u],' ');
		for(int v:s[u])if(!--d[v])q.push(v);
	}
}
int main()
{
//	file();
	input();
	work();
	return 0;
}

Measured memory_bytes: 17792
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
	int n,cnt=0;
	cin >> n;
	bool flg = false;
	while(n--){
		char c;
		int m;
		scanf(" %c%d",&c,&m);
		if(c == '('){
			cnt+=m;
		}
		else cnt-=m;
		if(cnt < 0) flg = true;
	}
	if(cnt == 0 && !flg)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 1204
#!/usr/bin/env python3
import sys

def show():
    for i in range(100):
        print(i, i**5)

def solve(X: int):
    A = [(i ** 5, i) for i in range(1000)]
    for a, b in A:
        for aa, bb in A:
            if a  - aa == X:
                return b, bb
            if a + aa == X:
                return b, -bb
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(*solve(X))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
    #show()


Measured memory_bytes: 9288
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int a;
string S;

int main() {
	cin >> a >> S;
	if (a < 3200)puts("red");
	else cout << S << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
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; }
using namespace std;

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

    int n; cin>>n;
    vector<int> a(3),b(3);
    rep(i,3)cin>>a[i];
    rep(i,3)cin>>b[i];

    vector<vector<int>> dp(4,vector<int>(n+1,n));
    rep(i,3){
        rep(j,n+1){
            chmax(dp[i+1][j],dp[i][j]);
            if(j-a[i]>=0)chmax(dp[i+1][j],dp[i+1][j-a[i]]+(b[i]-a[i]));
        }
    }

    // rep(i,4){
    //     rep(j,n+1)cout<<setw(3)<<dp[i][j];
    //     cout<<endl;
    // }

    n=dp[3][n];
    dp=vector<vector<int>>(4,vector<int>(n+1,n));
    rep(i,3){
        rep(j,n+1){
            chmax(dp[i+1][j],dp[i][j]);
            if(j-b[i]>=0)chmax(dp[i+1][j],dp[i+1][j-b[i]]+(a[i]-b[i]));
        }
    }
        
    // rep(i,4){
    //     rep(j,n+1)cout<<setw(3)<<dp[i][j];
    //     cout<<endl;
    // }

    cout<<dp[3][n]<<endl;
    return 0;

}

Measured memory_bytes: 977024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

string s;
bool pls[13];

ll func(int pos) {
	if (pos == (int)s.length() - 1) {
		ll ret = 0;
		string t = "";
		for (int i = 0; i < (int)s.length(); ++i) {
			t += s[i];
			if (pls[i]) {
				ret += stoll(t);
				t = "";
			}
		}
		return ret;
	}
	ll ret = 0;
	ret += func(pos + 1);
	pls[pos] = true;
	ret += func(pos + 1);
	pls[pos] = false;
	return ret;
}

int main() {
	cin >> s;
	pls[(int)s.length() - 1] = true;
	cout << func(0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
long long a,b,k;main(){std::cin>>a>>b,k=a^b;if(k){for(;k!=(k&-k);k-=k&-k);for(a&=2*k-1,b&=k-1;b!=(b&-b);b-=b&-b);b=b?2*b-1:0,std::cout<<2*k-a+(b<a)*(b+1-a);}else puts("1");}


Measured memory_bytes: 256
import java.util.Scanner;

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

    String ans;

    if (s.equals("Sunny")) {
      ans = "Cloudy";
    } else
    if (s.equals("Cloudy")) {
      ans = "Rainy";
    } else {
      ans = "Sunny";
    }

    System.out.println(ans);

    sc.close(); 
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int n,a,b,c,d;
string S;
bool dp[201010];
bool isok(int s,int t){
    for(int i=s;i<=t;i++) dp[i]=false;
    dp[s]=true;
    for(int i=s;i<=t;i++){
        if(dp[i]){
            for(int d=1;d<=2;d++){
                if(S[i]=='.') dp[i+d]=true;
            }
        }
    }
    return dp[t];
}

int main(){
    
    cin>>n>>a>>b>>c>>d>>S;
    a--,b--,c--,d--;

    if(!isok(a,c)){
        cout<<"No"<<endl;
        return 0;
    }

    if(!isok(b,d)){
        cout<<"No"<<endl;
        return 0;
    }

    if(c<d){
        cout<<"Yes"<<endl;
        return 0;
    } 

    for(int i=b-1;i<d;i++){
        if(S[i]=='.' && S[i+1]=='.' && S[i+2]=='.'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3964
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,a,b;
    cin >> n >> a >> b;
    ll p = n/(a+b);
    cout << p * a +min(a, n%(a+b)) << "\n";
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>

int n;

int main(void) {
	while (std::cin >> n, n) {
		double m = 0;
		double s[n];
		for (int i = 0; i < n; ++i) {
			std::cin >> s[i];
			m += s[i];
		} 
		m /= n;
		double a_2 = 0;
		for (int i = 0; i < n; ++i) a_2 += (s[i] - m) * (s[i] - m) / n;
		std::cout << std::fixed << std::setprecision(15) << sqrt(a_2) << '\n';
	}

	return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

#define pb push_back
#define p pair <int, int>
const int N = 6666;
int n, ans = 1e9;
vector <p> a, b;
char s[N], t[N];

inline void doit() {
    for (int add0 = 0; add0 <= 2 * n + 1; add0++) {
        // if ((add0 + (a.front() == b.front())) % 2 == 0)
        //     continue;
        vector <p> na;
        if (add0 <= n) {
            na = vector <p> (add0, p(0, 1));
            for (p v : a) na.pb(v);
        } else {
            na = vector <p> (add0 - n - 1, p(0, 1));
            for (p v : a) na.pb(v);
        }
        int i = 0, j = 0;
        bool valid = true;
        int now = 0;
        while (!(i == na.size() && j == b.size())) {
            if (i == na.size()) now += n + 1 - b[j++].second;
            else if (j == b.size()) now += n + 1 - na[i++].second;
            else {
                valid &= !na[i].first || na[i].first == b[j].first;
                now += abs(na[i++].second - b[j++].second);
            }
        }
        if (valid) {
            // cout << add0 << " " << now << "\n";
            ans = min(ans, now);
        }
    }
}

int main(void) {
    read(n);
    scanf("%s%s", s + 1, t + 1);
    re0 (i, n) {
        if (s[i + 1] != s[i]) a.pb(p(s[i + 1], i + 1));
        if (t[i + 1] != t[i]) b.pb(p(t[i + 1], i + 1));
    }
    // for (p v : a) cout << v.first << " "; cout << "\n";
    // for (p v : b) cout << v.first << " "; cout << "\n";
    doit();
    swap(a, b);
    doit();
    cout << ans << "\n";
}


Measured memory_bytes: 672
def deque(n, arr):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = arr[i]

    for l in range(n-2, -1, -1):
        for r in range(l+1, n):
            L = arr[l] - dp[l+1][r]
            R = arr[r] - dp[l][r-1]
            dp[l][r] = L if L > R else R
    return dp[0][n-1]

n = int(input())
arr = [int(x) for x in input().split()]
print(deque(n, arr))


Measured memory_bytes: 234176
N, K, Q = map(int, input().split())
A = [int(input()) - 1 for _ in range(Q)]

points = [K] * N

for a in A:
    points[a] += 1

for p in points:
    # print(p - Q)
    if p - Q > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 15644
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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

int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/



int main() {

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

	int a, b;
	cin >> a >> b;

	
	for (int i = 0; i <= 10000 ; i++)
	{
		if (i * 8 / 100 == a && i * 10 / 100 == b) {
			cout << i << endl;
			return 0;
		}

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

	return 0;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n,a,b,c,d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;

    a --;
    b --;
    c --;
    d --;

    bool or2 = true, or3 = true;

    for(int i = a;i < c;i ++){
        if(s.at(i) == '#' && s.at(i+1) == '#') or2 = false;
    }
    for(int i = b;i < d;i ++){
        if(s.at(i) == '#' && s.at(i+1) == '#') or2 = false;
    }

    if(c > d){
        or3 = false;
        for(int i = b-1;i < d;i ++){
            if(s.at(i)=='.'&&s.at(i+1)=='.'&&s.at(i+2)=='.') or3 = true;
        }
    }

    if(or2 && or3) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 592
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int R = scan.nextInt();

		if (N >= 10) {
			System.out.println(R);
		}else{
			int sum = R + 100*(10-N);
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 21460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			int n = Integer.parseInt(br.readLine());
			int k= Integer.parseInt(br.readLine());
			String[] tmp = br.readLine().split(" ");
			int distance = 0;
			for(String t : tmp) {
				int x = Integer.parseInt(t);
				if(k - x < x) {
					distance += (k-x)*2;
				}else {
					distance += x*2;
				}
			}
			System.out.println(distance);
		}
	}
}

Measured memory_bytes: 23508
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
print(N*800-(N//15)*200)


Measured memory_bytes: 2940
k = int(input())
alist = list(map(int, input().split()))

if alist[-1] != 2:
  print(-1)
else:
  mina = 2
  maxa = 3
  is_nn = False
  for a in alist[::-1][1:]:
    mina = a * ((mina + a - 1) // a)
    maxa = a * (maxa // a) + a - 1
    if mina >= maxa or mina // a == maxa == a:
      is_nn = True
      break

  if is_nn:
    print(-1)
  else:
    print(mina, maxa)


Measured memory_bytes: 14252
ans = []
while (n = gets.to_i) != 0
  dice = {:top => 1, :front => 2, :right => 3}
  sum = 1

  n.times do
    direction = gets.chomp!
    top, front, right = dice[:top], dice[:front], dice[:right]

    case direction
    when 'North'
      dice[:top] = front
      dice[:front] = 7 - top
    when 'South'
      dice[:top] = 7 - front
      dice[:front] = top
    when 'East'
      dice[:top] = 7 - right
      dice[:right] = top
    when 'West'
      dice[:top] = right
      dice[:right] = 7 - top
    when 'Right'
      dice[:right] = 7 - front
      dice[:front] = right
    when 'Left'
      dice[:right] = front
      dice[:front] = 7 - right
    else
    end

    sum += dice[:top]
  end

  ans << sum
end

ans.each { |n| puts n }

Measured memory_bytes: 2476
#include<iostream>
#include<vector>
using namespace std;
bool func(vector<int> &check){
	int N;
	cin>>N;
	for(int i=0;i<N;++i){
		int a,b;
		cin>>a>>b;
		for(int i=a;i<b;++i){
			if(check[i]){
				return false;
			}
		}
	}
	return true;
}
int main(){
	int a,b;
	cin>>a>>b;
	vector<int> check(1001,false);
	for(int i=a;i<b;++i){
		check[i]=true;
	}
	cout<<(func(check)?0:1)<<endl;
	return 0;
}

Measured memory_bytes: 3088
input = STDIN.gets.split(' ')
r = input[0].to_i
c = input[1].to_i

ss = Array.new(r + 1) {|i|
        Array.new(c + 1) {|j| 0 }
}
r.times {|i|
        input = STDIN.gets.split(' ')
        c.times{|j|
                ss[i][j] = input[j].to_i
        }
}

r.times {|i|
        c.times{|j|
                ss[i][c] += ss[i][j]
                ss[r][j] += ss[i][j]
        }
}
ss[r][c] = ss[r].inject(:+)

for col in ss
        puts col.join(' ')
end

Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n%2 == 1) {
        puts("No");
        return 0;
    }
    rep(i, n/2) {
        if (s[i] != s[i+n/2]) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}

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

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

struct UnionFind
{
  vector< int > data;
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }
  int size(int k)
  {
    return(-data[find(k)]);
  }
  bool same(int x, int y)
  {
	  x = find(x), y = find(y);
	  if( x == y) return true; 
	  else return false ;
  }
};

struct Query
{
  int a, b, y, type;
  bool operator<(const Query& q)
  {
    if(y == q.y) return(type > q.type);
    return(y > q.y);
  }
};

int main()
{
  int n , m , k ;
  cin >> n >> m >> k ;
  UnionFind tree(n);
  vector<int> friends(n,0);
  rep(i,m){
	  //m組の友達関係
	  int a , b ;
	  cin >> a >> b ;
	  --a , --b ;
	  tree.unite(a,b);
	  friends[a] ++ ;
	  friends[b] ++ ;
  }
  //k組のブロック関係を受け取り！！
  vector<int> ans(n);
  rep(i,n){
	  ans[i] = tree.size(i);
	  ans[i] -= friends[i];
  }
  rep(i,k){
	  int c, d ;
	  cin >> c>> d ;
	  --c, --d ;
	  if(tree.same(c,d)){
		  ans[c] -- ;
		  ans[d] --;
	  }
  }
  rep(i,n){
	  cout << ans[i]-1 <<" " ;
  }
  cout << endl;
}




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

int main() {
  int a,b; cin>>a>>b;
  cout<<a*b;
}
      



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

using namespace std;

const int N = 1e5 + 10;

int n, cnt[N];

int main() {
  scanf("%d", &n);
  int maxp = 0, minp;
  for (int i = 1; i <= n; i++) {
    int vl;
    scanf("%d", &vl);
    cnt[vl]++;
    maxp = max(maxp, vl);
  }
  minp = (maxp + 1) / 2;
  for (int i = 1; i < minp; i++) {
    if (cnt[i]) {
      puts("Impossible");
      return 0;
    }
  }
  if (cnt[minp] != maxp % 2 + 1) {
    puts("Impossible");
    return 0;
  }
  for (int i = minp + 1; i <= maxp; i++) {
    if (cnt[i] < 2) {
      puts("Impossible");
      return 0;
    }
  }
  puts("Possible");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
int gcd(int x,int y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
string s;
int y,m,d;
bool hei=true;
signed main(){
    cin>>s;
    y=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
    m=(s[5]-'0')*10+(s[6]-'0');
    if(y>2019)hei=false;
    else if(y==2019&&m>4)hei=false;
    if(hei==true)puts("Heisei");
    else puts("TBD");
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func removeDuplicated(args []int) []int {
	results := make([]int, 0, len(args))
	encountered := map[int]bool{}
	for i := 0; i < len(args); i++ {
		if !encountered[args[i]] {
			encountered[args[i]] = true
			results = append(results, args[i])
		}
	}
	return results
}

func main() {
	var n int
	fmt.Scan(&n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	b := removeDuplicated(d)
	fmt.Println(len(b))
}


Measured memory_bytes: 1856
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll n = 1;
    while(n <= N){
        n *= 2;
    }
    print(n/2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[305][305];

int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin >> A[i][j];

	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=1;k<=n;k++)
				if(k!=i && k!=j)
					if(A[i][k]+A[k][j]<A[i][j]) {cout << "-1\n"; return 0;}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			bool pick=true;
			for(int k=1;k<=n;k++){
				if(k!=i && k!=j){
					if(A[i][k]+A[k][j]==A[i][j]) pick=false;
				}
			}
			if(pick)ans+=A[i][j];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
#define ll long long

int main(){
    string S;
    int N;
    ll ans=0;
    cin >> S; 
    N = S.length();
    // (n-1)^2のbit全探索
    for(int bit = 0; bit < 1 << (N - 1); bit++){
        // ある種類のbit探索のたびに初期化
        ll sm = 0;
		ll a = S[0] - '0';
        // 文字列を探索する
		for(int j = 0; j < N-1; j++){
            // jのbitが1のとき，jとj+1の間に'+'があるとする
			if (bit & (1 << j)) {
				sm += a;
				a = 0;
			}
			a = a * 10 + S[j + 1] - '0';
		}
        // 最後のaの分を足せていないので足す
		sm += a;
		ans += sm;
    }
    cout << ans <<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    map<ll, int> mp;
    int idx = 0;
    vector<ll> path;
    do
    {
        mp[x] = idx++;
        path.emplace_back(x);
        x = x * x % m;

    }
    while (!mp.count(x));
    int start = mp[x];
    int len = idx - start;
    ll sum = 0;
    for (int i = start; i < idx; ++i)
        sum += path[i];
    ll ans = 0;
    if (n < start)
    {
        for (int i = 0; i < n; ++i)
            ans += path[i];
    }
    else
    {
        for (int i = 0; i < start; ++i)
            ans += path[i];
        ll loop = (n - start) / len;
        ans += loop * sum;
        ll rem = (n - start) % len;
        for (int i = 0; i < rem; ++i)
            ans += path[start + i];
    }
    cout << ans;
}

Measured memory_bytes: 6704
// AOJ 0245: Time Sale
// 2017.12.16 bal4u@uu

#include <stdio.h>
#include <string.h>

#define QMAX 100000
typedef struct { char r, c, t; int d, b; } Q;
Q q[QMAX+2]; int top, end;

#define WALL 64
#define COR  32

typedef struct { int d, s, e; } G;
G sell[10];
char map[22][22];
char mk[22][22][101][1024];
char buf[50], *p;
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int X, Y, r, c, n, i, j, sr, sc, ans;
	int d, t, b, r2, c2;

	while (fgets(p=buf, 10, stdin) && *p != '0') {
		X = in(), Y = in();
		memset(map, WALL, sizeof(map));
		for (r = 1; r <= Y; r++) {
			fgets(p=buf, 50, stdin);
			for (c = 1; c <= X; c++) {
				if (*p == '.') map[r][c] = COR;
				else if (*p == 'P') sr = r, sc = c, map[r][c] = COR;
				else map[r][c] = *p & 0xf;
				p += 2;
			}
		}
		fgets(p=buf, 5, stdin);
		n = *p & 0xf;
		for (i = 0; i < n; i++) {
			fgets(p=buf, 50, stdin);
			j = in();
			sell[j].d = in(), sell[j].s = in(), sell[j].e = t = in();
		}

		ans = 0;
		memset(mk, 0, sizeof(mk));
		q[0].r = sr, q[0].c = sc, q[0].t = 0, q[0].d = 0, q[0].b = 0;
		top = 0, end = 1;
		while (top != end) {
			r = q[top].r, c = q[top].c, t = q[top].t, d = q[top].d, b = q[top].b;
			if (++top == QMAX) top = 0;

			if (mk[r][c][t][b]) continue;
			mk[r][c][t][b] = 1;
			if (d > ans) ans = d;

			for (i = 0; i < 4; i++) {
				r2 = r + mv[i][0], c2 = c + mv[i][1];
				if ((j = map[r2][c2]) > 10) continue;
				if (!(b & (1 << j)) && sell[j].s <= t && t < sell[j].e) {
					d += sell[j].d;
					b |= 1 << j;
				}
			}
			for (i = 0; i < 4; i++) {
				r2 = r + mv[i][0], c2 = c + mv[i][1];
				if (map[r2][c2] & COR) {
					q[end].r = r2, q[end].c = c2, q[end].t = t+1, q[end].d = d, q[end].b = b;
					if (++end == QMAX) end = 0;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 51740
#include<bits/stdc++.h>
using namespace std;
long long x=1000000000000000000,ans=1;
long long a[1000000];
int n;
int main(){
  scanf("%d", &n);
  for(int i=0;i<n;i++) {
      scanf("%lld", &a[i]);
      if(a[i]==0){
	      printf("0"); 
		  return 0;
	  }
  }      
  for(int i=0;i<n;i++){
    if(x<a[i]){ 
	   printf("-1"); 
	   return 0;
	}
    else {
      ans*=a[i];
      x /= a[i];
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 4612
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,val,x;
    cin>>n>>k;
    ld r,ans=0.0;
    for(int i=1;i<=n;i++)
    {
        x = i;
        r=1.0;
        while(x<k)
        {
            r/=2.0;
            x*=2;
        }
        ans+=r;

    }
    cout<<setprecision(20)<<ans/(ld)n;

    return 0;

}




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

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		int count = 0;
		for (int j = 1; j <= n; j++) {
			if (i % j == 0) {
				count++;
			}
		}
		if (count == 8) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

class CommonIO {
public:
    CommonIO() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(false);
    }
    ~CommonIO() {}

    template <class T>
    void scan(T &v) {
        std::cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        std::cout << v;
    }
    template <class T>
    void print(std::vector<T> &v) {
        if (v.size() == 0) return;
        print(*v.begin());
        for (auto it = ++v.begin(); it != v.end(); ++it) {
            print(' ');
            print(*it);
        }
    }
    template <class T>
    void print(std::vector< std::vector<T> > &grid) {
        if (grid.size() == 0) return;
        print(*grid.begin());
        for (auto it = ++grid.begin(); it != grid.end(); ++it) {
            print('\n');
            print(*it);
        }
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(' ');
        print(rest...);
    }

    template <class T>
    void printl(T v) {
        print(v);
        std::cout << '\n';
    }
    template <class T, class... Rest>
    void printl(T v, Rest... rest) {
        print(v);
        print(' ');
        printl(rest...);
    }
} io;



int main() {
    int N, P; io.scan(N, P);
    string s; io.scan(s);

    ll res = 0;

    if (10 % P == 0) {
        REP(i, N) {
            if ((s[i] - '0') % P == 0) {
                res += i + 1;
            }
        }
    }
    else {
        reverse(s.begin(), s.end());
        vector<ll> mods(P, 0);
        mods[0] = 1;
        int mod = 0, mod10 = 1;
        REP(i, N) {
            mod = (mod + (s[i] - '0') * mod10) % P;
            mod10 = (mod10 * 10) % P;
            res += mods[mod];
            //io.printl(s[i] - '0', mod, mods[mod]);
            ++mods[mod];
        }
    }
    
    io.printl(res);

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 5;

void solve() {
    ll n; cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i <= n; ++i) cin >> a[i];

    ll now = 1;
    vector<ll> nodes(n+1);
    for(int i = 0; i <= n; ++i){
        nodes[i] = now;
        if(now - a[i] < 0){
            cout << -1 << endl;
            return;
        }
        now -= a[i];
        if(now < INF64) now *= 2LL;
    }

    ll ans = 0;
    now = 0;
    for(int i = n; i >= 0; --i){
        now += a[i];
        if(nodes[i] - now > 0){
            nodes[i] = now;
        }
        ans += nodes[i];
    }

    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 4844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGuessTheNumber solver = new CGuessTheNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGuessTheNumber {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] s = new int[m];
            char[] c = new char[m];
            for (int i = 0; i < m; i++) {
                s[i] = in.nextInt();
                c[i] = (char) (in.nextInt() + '0');
            }

            for (int i = n == 1 ? 0 : (int) Math.pow(10, n - 1); i < (int) Math.pow(10, n); i++) {
                String test = Integer.toString(i);
                boolean f = true;
                for (int j = 0; j < m; j++) {
                    f = f && (test.charAt(s[j] - 1) == c[j]);
                }
                if (f) {
                    out.println(test);
                    return;
                }
            }

            out.println(-1);

        }

    }
}



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


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int i,c=0,mx=0;
    cin>>s;
    for(i=0;i<s.size();++i)
    {
        if(s[i]=='R')
        {
            c++;
            mx = max(mx,c);
        }
        else c=0;
    }
    cout<<mx;
}

Measured memory_bytes: 3640
n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
d = [abs(x - y) for x, y in zip(x_list, y_list)]

for i in range(1, 4):
    print(sum([j ** i for j in d]) ** (1 / i))
    
print(max(d))


Measured memory_bytes: 5648
# tenka1-2017-beginnerB - Different Distribution
def main():
    N, *AB = map(int, open(0).read().split())
    A = [(i, j) for i, j in zip(*[iter(AB)] * 2)]
    A.sort()
    ans = sum(A[-1])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 25940
import bisect
N=int(input())
L=list(map(int,input().split()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b-1
    else:
      i=i
print(i)

Measured memory_bytes: 3188
#include<cstdio>

using namespace std;

char ch[100];

int main(){
	scanf("%s", ch);
	for(int i = 0; i < 4; ++i){
		printf("%c", ch[i]);
	}
	printf(" ");
	for(int i = 4; i < 12; ++i){
		printf("%c", ch[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <bitset>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m,t; cin >> n >> m >> t;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	a.push_back(0);
	a.push_back(t);
	int ans=0;
	sort(a.begin(),a.end());
	for(int i=0;i<n+1;i++){
		if(i!=0&&i!=n)ans+=max(0,a[i+1]-a[i]-m-m);
		else ans+=max(0,a[i+1]-a[i]-m);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <math.h>
 
int main(void){
  double d, n;
  scanf("%lf%lf", &d, &n);
  double ans = pow(100.0, d);
  if(n == 100) ans *= (n + 1);
  else ans *= n;
  
  printf("%.0lf\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 998244353;


     signed main(){
         

int n,s;
cin>>n>>s;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int dp[n][s+1];for(int i=0;i<n;i++)fill(dp[i],dp[i]+s+1,0);
dp[0][0]=2;if(a[0]<=s)dp[0][a[0]]=1;
for(int i=1;i<n;i++){
     for(int j=0;j<=s;j++)dp[i][j]=(2*dp[i-1][j])%MOD;
     for(int j=0;j+a[i]<=s;j++)dp[i][j+a[i]]=(dp[i][j+a[i]]+dp[i-1][j])%MOD;
}
cout<<dp[n-1][s]<<endl;










 }

 


 






    





      

        


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

struct Node{
    int parent;
    int left;
    int right;
};

int D[100000];
struct Node T[100000];

void print(int u){
    int i,c;
    printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,D[u]);
    if(T[u].parent == -1)cout << "root, ";
    else if(T[u].left == -1)cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for(int i = 0, c = T[u].left;c != -1;i++,c = T[c].right){
        if(i)cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void setdepth(int u,int p){
    D[u] = p;
    if(T[u].right != -1){
        setdepth(T[u].right,p);
    }
    if(T[u].left != -1){
        setdepth(T[u].left,p + 1);
    }
}

int main(){
    int n,v,d,c,l,r;
    cin >> n;
    for(int i = 0;i < n;i++){
        T[i].parent = T[i].left = T[i].right = -1;
    }
    for(int i = 0;i < n;i++){
        cin >> v >> d;
        for(int j = 0;j < d;j++){
            cin >> c;
            if(j == 0)T[v].left = c;
            else T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }
    for(int i = 0;i < n;i++){
        if(T[i].parent == -1)r = i;
    }
    setdepth(r,0);
    for(int i = 0; i < n;i++)print(i);
}


Measured memory_bytes: 7900
N, K = map(int, input().strip().split(" "))
x = [int(i) for i in input().split(" ")]

cur = 0
dist = 1000000000
if K == 1:
    dist = min(x)
elif K == N:
    if (x[0] <= 0) and (x[N-1] > 0):
        dist = min(abs(x[0]) * 2 + x[N-1], abs(x[0]) + x[N-1] * 2)
    elif x[N-1] <= 0:
        dist = abs(x[0])
    else: #x[i] > 0
        dist = x[N-1]
else:
    for i in range(N-K+1):
        cur_dist = 0
        if (x[i] <= 0) and (x[i+K-1] > 0):
            cur_dist = min(abs(x[i]) * 2 + x[i+K-1], abs(x[i]) + x[i+K-1] * 2)
        elif x[i+K-1] <= 0:
            cur_dist = abs(x[i])
        else: #x[i] > 0
            cur_dist = x[i+K-1]
        if dist >= cur_dist:
            dist = cur_dist
        if x[i] > 0:
            break

print(dist)


Measured memory_bytes: 14568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N;
    cin >> N;
    vs(W, N);
    string ans = "Yes";
    rep(i, N) cin >> W[i];
    rep(i, N-1){
        if(lst(W[i]) != fst((W[i+1]))){
            ans = "No";
            break;
        }
    }
    rep(i, N-1){
        for(int j = i+1; j<N; j++){
            if(W[i] == W[j]){
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,m; cin>>n>>m;
    vector<ll>x(m);
    vector<ll>y(m);
    rep(i,m)cin>>x[i]>>y[i];
    Graph G(n);
    rep(i,n)G[i].push_back(1);
    vector<bool>ans(n,false);
    ans[0]=true;
    rep(i,m){
        if(ans[x[i]-1]==true){
            if(G[x[i]-1].size()<=1)ans[x[i]-1]=false;
                G[y[i]-1].push_back(1);
                ans[y[i]-1]=true;
                G[x[i]-1].pop_back();
        }
        else{
            G[y[i]-1].push_back(1);
            G[x[i]-1].pop_back();
        }
    }
    ll sum=0;
    rep(i,n){
        if(ans[i])sum++;
    }
    cout<<sum<<endl;
}



















































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

const int MAX_N = 100005;
typedef long long i64;

class Edge {
public:
  int nxt, to, dir;
} e[MAX_N << 1];

int head[MAX_N], id[MAX_N], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v, 1}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u, -1}, head[v] = cnt;
}

int N, M, num[3], flag, edge_num;
void dfs(int u) {
  num[id[u]]++;
  static int dfn[MAX_N], tot;
  dfn[u] = ++tot;
  for (int i = head[u]; i; i = e[i].nxt)
    if (id[e[i].to] == -1) {
      id[e[i].to] = (id[u] + e[i].dir + 3) % 3, edge_num++;
      dfs(e[i].to);
    } else {
      if (dfn[e[i].to] > dfn[u]) edge_num++;
      if (id[e[i].to] != (id[u] + e[i].dir + 3) % 3) flag = 0;
    }
}

int main() {
  memset(id, -1, sizeof id);
  
  scanf("%d%d", &N, &M);
  for (int i = 1, a, b; i <= M; ++i) {
    scanf("%d%d", &a, &b);
    addedge(a, b);
  }

  i64 res = 0;
  for (int i = 1; i <= N; ++i)
    if (id[i] == -1) {
      flag = 1, id[i] = 1, edge_num = 0;
      memset(num, 0, sizeof num);
      
      dfs(i);
      if (flag) {
	if (num[0] && num[1] && num[2]) {
	  res += 1LL * num[0] * num[1] + 1LL * num[1] * num[2] + 1LL * num[2] * num[0];
	} else {
	  res += edge_num;
	}
      } else {
	i64 tot = num[0] + num[1] + num[2];
	res += tot * tot;
      }
    }

  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
using namespace std;
typedef long long ll;
const int N=1010;
int n,m,a,b,ans[N][N];
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return f*x;
}
inline void write(int x)
{
    if (x<0) putchar('-'),x=-x;
    if (x>9) write(x/10);
    putchar(x%10+'0');
    return;
}
int main()
{
    n=read(),m=read(),a=read(),b=read();
    FOR(i,1,n)
    {
        FOR(j,1,m)
        {
            if (i<=b&&j<=a) ans[i][j]=1;
            else if (i>b&&j>a) ans[i][j]=1;
            else ans[i][j]=0;
        }
    }
    FOR(i,1,n)
    {
        FOR(j,1,m) printf("%d",ans[i][j]);
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 5120
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf') for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
        else:
            break

print(dp[n - 1])


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

bool solve() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    sort(A.begin(), A.end());
    int dif = A[N-1] - A[0];
    if(dif == 0) {
        return A[0] == N - 1 || 2 * A[0] <= N;
    } else if(dif == 1) {
        int x = 0;
        rep(i, 0, N) if(A[i] == A[0]) x++;
        int y = A[N-1] - x;
        return x < A[N-1] && x + 2 * y <= N;
    }
    return false;
}

int main() {
    cout << (solve() ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int a[27];
int s, t;
int main()
{
	s=0;
	t=0;
	for(int i=0; i<28; i++)
	{
		cin >> a[i];
	}
	for(int i=1; i<=30; i++)
	{
		int j=0;
		for(int k=0; k<28; k++)
		{
			if(a[k]==i){j+=1;}
			else{}
		}
		if(j==0)
		{
			if(s!=0)
			{
				t=i;	
			}
			else
			{
				s=i;
			}
		}
		else{}
	}
	cout << s << endl << t << endl;
	return 0;
}

Measured memory_bytes: 1164