akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
double maxvel(double left,double right,double now,double v){
    if(now<left){
        return v+(left-now);
    }
    else if(now<right){
        return v;
    }
    else{
        return v+(now-right);
    }
}
int main(void){
    cout<<fixed<<setprecision(6);
    ll n,runtime=0;cin>>n;
    double ans=0,vel=0;
    vector<double> t(n+2),v(n+2),dt(n+2);
    t.at(n)=0;v.at(n)=0;t.at(n+1)=0;v.at(n+1)=0;dt.at(0)=0;
    For1(i,n+1){
        cin>>t.at(i);
        dt.at(i)=dt.at(i-1)+t.at(i);
    }
    For1(i,n+1)cin>>v.at(i);
    runtime=dt.at(n);dt.at(n+1)=dt.at(n);
    for(double i=0;i<=runtime;i+=0.5){
        double m=i;
        For1(j,n+2){
            m=min(m,maxvel(dt.at(j-1),dt.at(j),i,v.at(j)));
        }
        ans+=(vel+m)/4;
        vel=m;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,mx;
int a[maxn],cnt[maxn];

int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]),cnt[a[i]]++;
	REP(i,100000){
		int cur=cnt[i-1]+cnt[i]+cnt[i+1];
		mx=max(mx,cur);
	} 
	printf("%d",mx);
	return 0;
} 

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    ll e = -1;
    map<int, int> m;
    for (int i = N - 1; i >= 0; i--) {
        ++m[A[i]];
        if (m[A[i]] >= 4) {
            cout << A[i] * A[i] << endl;
            return 0;
        }

        if (m[A[i]] >= 2 && e == -1) {
            e = A[i];
        } else if (m[A[i]] >= 2 && A[i] != e) {
            cout << A[i] * e << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 7520
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n,m = inpl()
for i in make_divisors(m):
    if i < n:
        continue
    print(m//i)
    break

Measured memory_bytes: 64236
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

class SegmentTree{
public:
    int n;
    vector<ll> node;

    SegmentTree(vector<ll> v){
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(int x, ll val){
        x += (n - 1);
        node[x] = val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        
        return max(vl, vr);
    }
};

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

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

    SegmentTree seg(vector<ll>(n, 0));
    vector<ll> dp(n+1, 0);
    for(int i=0; i<n; i++){
        ll ma = seg.getmax(0, h[i]);
        dp[i+1] = ma + a[i];
        seg.update(h[i], dp[i+1]);
    }

    cout << seg.getmax(0, n) << endl;

    return 0;
}

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

bool cmp(pair<int,long long> a, pair<int,long long> b){
	return a.second > b.second;
}
int main() {
	int n,k;
	long long cnt = 0, num = 0;
	long long ans = 0, sz;
	cin >> n >> k;
	vector<pair<int,long long>> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end(), cmp);
	map<int,int> mp;
	stack<pair<int,long long>> st;
	
	for(int i = 0; i < n; ++i){
		if(num < k){
			num++;
			cnt+= a[i].second;
			mp[a[i].first]++;
			if(mp[a[i].first] > 1) st.push(a[i]);
		}
		else{
			if(st.size() == 0) break;
			if(mp[a[i].first]) continue;
			cnt-= st.top().second;
			cnt+= a[i].second;
			st.pop();
			mp[a[i].first]++;
		}
		sz = mp.size();
		ans = max(ans, cnt + sz*sz);
	}
	cout << ans;
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

ll mul(ll a, ll b) { return 1LL * a * b % mod; }
ll add(ll a, ll b) { return (a += b) < mod? a : a - mod; }

struct Matrix
{
    vvi A;
    int dim;
    Matrix() {}
    Matrix(int n) : dim(n) { A.assign(n, vi(n));}
    vi &operator [](int n){ return A[n];}
};

Matrix operator *(Matrix A, Matrix B)
{
    int n = A.dim;
    Matrix C(n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                C[i][j] = add(C[i][j], mul(A[i][k], B[k][j])); 
       
    return C;
}

Matrix operator ^(Matrix A, ll k)
{
    int n = A.dim;
    
    Matrix R(n);
    for (int i = 0; i < n; ++i)
        R[i][i] = 1;

    while (k > 0)
    {
        if (k % 2)
            R = R * A;

        A = A * A;
        k /= 2;
    }

    return R;
}

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

	int n;
	ll k;
	cin >> n >> k;
	Matrix G(n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> G[i][j];
		}
	}
	Matrix N = G ^ k;
	ll res = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			res = add(res, N[i][j]);
		}
	}
	cout << res;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int k;

bool visited[MAX_N];
ll dist[MAX_N];

ll ans;

ll solve() {
  fill_n(visited, k + 1, false);
  fill_n(dist, k + 1, INF);

  deque<pair<int, ll>> deq;

  deq.push_front(make_pair(1, 0LL));

  ll ret = 0;

  while (!deq.empty()) {
    auto cur = deq.front();
    deq.pop_front();

    int node = cur.first;
    ll cost = cur.second;

    if (visited[node]) continue;

    visited[node] = true;
    dist[node] = cost;

    if (node == 0) {
      ret = cost;
      break;
    }

    int next_p1 = (node + 1) % k;
    if (dist[next_p1] > cost + 1LL) {
      deq.push_back(make_pair(next_p1, cost + 1LL));
    }
    // if (!visited[next_p1]) {
    //
    // }

    int next_t10 = (node * 10) % k;
    if (dist[next_t10] > cost) {
      deq.push_front(make_pair(next_t10, cost));
    }
    // if (!visited[next_t10]) {
    //
    // }
  }

  return ret + 1LL;
}

int main(void) {
  // Here your code !
  scanf("%d", &k);

  ans = solve();

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

  return 0;
}


Measured memory_bytes: 2048
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);

		String A = scan.next();
		char[] A_char = A.toCharArray();
		int ans = 0;

		for (int i = 0; i < 4; i++) {
			char c = A_char[i];

			if (c == '+') {
				ans++;
			} else {
				ans--;
			}
		}

		System.out.println(ans);
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 26952
import java.util.*;

/**
 * PrintTestCase
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;

        out_of_loop: while (true) {
            int a = Integer.parseInt(sc.next());
            i++;

            if (a == 0) {
                break out_of_loop;
            }

            System.out.println("Case " + i + ": " + a);
        }
        sc.close();
    }
}


Measured memory_bytes: 41112
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    if n%k==0:
        print(0)
    else:
        print(1)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

ll choose(ll n){
   return n*(n-1)/2;
}
 
int main() {
   int n; cin >> n;
   vector<int> a(n),cnt(n);
   rep(i,n){
      cin >> a[i];
      a[i]--;
      cnt[a[i]]++;
   }
   ll tot=0;
   rep(i,n){
      tot += choose(cnt[i]);
   }
   rep(i,n){
      ll ans=tot;
      ans -= choose(cnt[a[i]]);
      ans += choose(cnt[a[i]]-1);
      cout << ans << endl;
   }
}



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

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

use std::cmp::{max, min};
use std::collections::VecDeque;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();

  let mut ans = String::from("");

  // aまでの排他的論理和を求める
  let v2 = calc(b, 0);
  let v = calc(a - 1, v2.len());

  // println!("{:?}", v);
  // println!("{:?}", v2);

  for i in 0..v2.len() {
    if v[i] + v2[i] == 1 {
      ans.push('1')
    } else {
      ans.push('0')
    }
  }

  // println!("{}", ans);
  let intval = isize::from_str_radix(&ans, 2).unwrap();
  println!("{}", intval);
}


fn calc(a: i64, size: usize) -> VecDeque<i64> {
  let mut v = VecDeque::new();
  if a % 4 == 0 {
    v.push_front(0);
    v.push_front(0);
  } else if a % 4 == 1 {
    v.push_front(1);
    v.push_front(0);
  } else if a % 4 == 2 {
    v.push_front(1);
    v.push_front(1);
  } else {
    v.push_front(0);
    v.push_front(0);
  }

  let mut w = 4;
  while a % w != a {
    w = w * 2;
    if a % w < w / 2 || (a % w) % 2 == 1 {
      v.push_front(0);
    } else {
      v.push_front(1);
    }
  }

  if size != 0 {
    let v_len = v.len();

    for _ in 0..(size - v_len) {
      v.push_front(0);
    }
  }


  return v;
}



Measured memory_bytes: 4352
#include<cstdio>
using namespace std;

int n,x,vis[200001],res[200001];

int main() {
	scanf("%d %d",&n,&x);
	  if (x==1 || x==2*n-1) return puts("No"),0;
	puts("Yes");
	  if (x==2) {
	  	int k=2*n-1; k=k/2+1;
	  	int p=1;
	  	res[k]=2; vis[2]=1; res[k+1]=1; vis[1]=1;
	  	res[k-1]=3; vis[3]=1;
	  	  for (int i=1;i<=n*2-1;++i) 
	  	    if (res[i]) printf("%d\n",res[i]);
	  	      else {
	  	      	  while (vis[p]) p++;
	  	      	  printf("%d\n",p); vis[p]=1;
				}
	  }
	  else {
	  	int k=2*n-1; k=k/2+1;
	  	int p=1;
	    res[k]=x; vis[x]=1; res[k-1]=x-1; vis[x-1]=1;
	    res[k+1]=x+1; vis[x+1]=1; res[k+2]=x-2; vis[x-2]=1;
	    for (int i=1;i<=2*n-1;++i) 
	      if (res[i]) printf("%d\n",res[i]);
	        else {
	          while (vis[p]) p++;
	          printf("%d\n",p); vis[p]=1;
			}
	  }
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int n,l,a[100200];
int main() {
	
	cin>>n>>l;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
	    if(a[i]+a[i+1]>=l){
            cout<<"Possible\n";	        
            for(int j=1;j<=i;j++){
                cout<<j<<" ";
            }
            for(int j=n-1;j>=i+2;j--){
                cout<<j<<" ";
            }
            cout<<i+1;
            return 0;
	    }
	}
	cout<<"Impossible";
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define inf 2147483647
using namespace std;

int n,m,a,b,x=0,y=inf;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i)
	{
		scanf("%d%d",&a,&b);
		x=max(x,a);
		y=min(y,b);
	}
	if(y>=x) cout<<y-x+1;
	else cout<<0;
	return 0;
} 

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

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

    if(a * b > c * d) cout << a * b << endl;
    else if(a * b < c * d) cout << c * d << endl;
    else cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t LL;
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7;
int main()
{
  int N;
  LL A=0,x;
  cin>>N;
  vector<LL> bit(60,0);
  while(cin>>x){rep(i,60)bit.at(i)+=x>>i&1;}
  rep(i,60){A=fmod(A+fmod(((N-bit.at(i))*bit.at(i)%MOD*pow(2,i)),MOD),MOD);}
  return cout<<A<<endl,0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main()
{
	string S;
	cin >> S;
	
	if(S.find("A")!=std::string::npos&&S.find("B")!=std::string::npos) {

		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

}

Measured memory_bytes: 256
module Main where

isBeautiful :: (Num a, Eq a) => a -> a -> a -> [Char]
isBeautiful a b c = if (a-b)==(b-c) then "YES" else "NO"

main = do
    [a, b, c] <-(map read.words) <$> getLine
    putStrLn $ isBeautiful a b c


Measured memory_bytes: 508
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n, ans;
ll l, r;
inline void read(ll &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;	
} 
int main()
{
	read(l); read(r);
	while(l<=r)
	{
		ans++;
		l<<=1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int N; cin >> N;
  string S[2]; cin >> S[0] >> S[1];

  vector<int> num(N);

  bool is_vert;
  int i = 0;
  if (S[0][0] == S[1][0]) {
    num[0] = 3;
    is_vert = true;
    i += 1;
  } else {
    num[1] = 6;
    is_vert = false;
    i += 2;
  }

  while (i < N) {
    if (S[0][i] == S[1][i]) {
      if (is_vert) {
        num[i] = mod(num[i-1] * 2);
      } else {
        num[i] = mod(num[i-1] * 1);
      }
      is_vert = true;
      i += 1;
    } else {
      if (is_vert) {
        num[i+1] = mod(num[i-1] * 2);
      } else {
        num[i+1] = mod(num[i-1] * 3);
      }
      is_vert = false;
      i += 2;
    }
  }

  cout << num[N-1] << endl;

  return 0;
}


Measured memory_bytes: 256
/*****************Bismillahir Rahmanir Rahim***********************/

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

/************************Start Of Template*************************/

/******** Mahin Shefat - GhOstMan *************/


#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     check           printf("check")
#define     sqr(x)          (x)*(x)
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     Pair            pair<ll,ll>
#define     MAX             1000000000000014
#define     MIN             -1000000000000014
#define     endl            '\n'
#define     Fread           freopen("inputdur.txt","r",stdin)
#define     Fwrite          freopen("output.txt","w",stdout)

/************************End Of Template*************************/
ll h[300005] , dp[300005];
int main(){
	
	int n , k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> h[i];
		dp[i] = MAX;
	}
	dp[n] = 0;
	for(int i = n - 1; i >= 1; i--){
		for(int j = 1; j <= k; j++){
			if(i + j > n) break;
			int id = i + j;
			dp[i] = min(dp[i] , dp[id] + (abs(h[i] - h[id])));
			//cout << dp[i] << " " << dp[id] << " " << i << " " << id << endl;
		}
	}
	cout << dp[1] << endl;
	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<iomanip>

using namespace std;
using ll=long long;

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

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  //モンスターの体力が 1なら、そのモンスターの体力は 0になる
  //モンスターの体力が X>1なら、そのモンスターは消滅し、
  //体力が ?X/2?のモンスターが新たに 2体現れる
  ll h,cnt=1,bit=1;
  cin>>h;
  while(h>1){
    h/=2;
    bit*=2;
    cnt+=bit;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int han(char s[],int gen){
		int i;
		for(i=0;i<gen/2;i++){
				if(s[i]!=s[i+gen/2])return 0;
		}
		return 1;
}

int main(){
		int i,gen=0;
		char s[201];
		scanf("%s",s);
		while(s[gen]!=0)gen++;
		for(i=gen-1;i>=0;i--){
				if(i%2==0){
						if(han(s,i)==1){
								printf("%d\n",i);
								return 0;
						}
				}
		}
		return 0;
}


Measured memory_bytes: 128
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)
    return arr

n=int(input())
li=fac(n)

ans=0
y=0
if n==1:
    ans=0
else:
    for x in range(1,1000):
        y=y+x
        ans=ans+len([i for i in li if i >= y])
        if len([i for i in li if i >= y])==0:
            break
print(ans)

Measured memory_bytes: 9496
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n,r;
    cin >> n >> r;
    int x=r;
    if(n<10) x+=100*(10-n);
    cout << x;
    return 0;
}

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

using namespace std;

const int N = 2005;

int n, m;
int res;
int sum[N];
int fr[N], to[N];
int h[N], p[11][N];
int color[N * 2];
vector<int> G[N], G2[N * 2];
set< pair<int, int> > S[N];
vector< pair<int, int> > vdel[N];

int lca(int u, int v) {
	if (h[u] > h[v]) swap(u, v);
	for (int i = 10; i >= 0; --i) if (h[p[i][v]] >= h[u]) v = p[i][v];
	for (int i = 10; i >= 0; --i) if (p[i][v] != p[i][u]) v = p[i][v], u = p[i][u];
	return (u == v) ? u : p[0][u];
}

void dfs(int u) {
	for (int i = 1; i <= 10; ++i) {
		p[i][u] = p[i - 1][p[i - 1][u]];
	}
	for (auto v : G[u]) if (p[0][u] != v) {
		p[0][v] = u, h[v] = h[u] + 1, dfs(v);
	}
}

void solve(int u) {
	int pmx = 0;
	for (auto v : G[u]) if (p[0][u] != v) {
		solve(v);
		if (S[v].size() == 1) res++;
		if (S[v].size() > 1) {
			res += 2;
			if (!sum[v]) {
				auto p0 = S[v].begin();
				auto p1 = ++S[v].begin();
				G2[p0 -> second].push_back(p1 -> second);
				G2[p1 -> second].push_back(p0 -> second);
				int x = p0 -> first;
				int y = p1 -> first;
				if (h[x] > h[y]) swap(x, y);
				sum[v]++, sum[y]--;
			}
		}
		sum[u] += sum[v];
		if (!pmx || S[pmx].size() < S[v].size()) pmx = v;
	} 
	if (pmx) swap(S[u], S[pmx]);
	for (auto v : G[u]) if (p[0][u] != v) {
		for (auto i : S[v]) S[u].insert(i);
	}
	for (auto i : vdel[u]) S[u].erase(i);
}

void dfscolor(int u) {
	for (auto v : G2[u]) {
		if (color[v]) {
			assert(color[v] == 3 ^ color[u]);
			continue;
		}
		color[v] = 3 ^ color[u], dfscolor(v);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v), G[v].push_back(u);
	}
	p[0][1] = 1, dfs(1);
	for (int i = 0; i < m; ++i) {
		cin >> fr[i] >> to[i];
		if (h[fr[i]] > h[to[i]]) swap(fr[i], to[i]);
		int tmp = lca(fr[i], to[i]);
		if (tmp == fr[i]) {
			S[to[i]].insert({tmp, i * 2});
			vdel[tmp].push_back({tmp, i * 2});
		}
		else {
			S[to[i]].insert({tmp, i * 2});
			S[fr[i]].insert({tmp, i * 2 + 1});
			G2[i * 2].push_back(i * 2 + 1);
			G2[i * 2 + 1].push_back(i * 2);
			vdel[tmp].push_back({tmp, i * 2});
			vdel[tmp].push_back({tmp, i * 2 + 1});
		}
	}
	solve(1);
	for (int i = 0; i < m * 2; ++i) {
		if (!color[i]) color[i] = 1, dfscolor(i);
	}
	cout << res << '\n';
	for (int i = 0; i < m; ++i) {
		if (color[i * 2] == 1) cout << fr[i] << ' ' << to[i] << '\n';
		else cout << to[i] << ' ' << fr[i] << '\n';
	}
}

Measured memory_bytes: 1536
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
a = na()
cb = []
for i in range(m):
    b, c = na()
    cb.append([c, b])

a.sort()
cb.sort(reverse=True)

cur = 0
for i in range(n):
    if cur >= len(cb):
        break
    c, b = cb[cur]
    if a[i] < c:
        a[i] = c
        b -= 1
        cb[cur][1] = b
        if b == 0:
            cur += 1
    else:
        break

print(sum(a))

Measured memory_bytes: 69016
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    string s;
    cin >> s;
    int ans = 0;
    map<char, int> mp;
    for(auto c: s) mp[c]++;
    for(auto p: mp) {
        ans += p.second * (s.size()-p.second);
    }
    cout << ans/2+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "V"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
const int N=100010;
int n,m,cnt,M;
int f[N],g[N];
vector<int> ad[N];
void dfs1(int u,int p)
{
    forv(v,ad[u]) if(v!=p) dfs1(v,u),f[u]=f[u]*(f[v]+1)%M;
}
void dfs2(int u,int p)
{
    m=0,cnt=0;
    vector<int> a,l,r;
    forv(v,ad[u]) if(v!=p) cnt++;
    a.reserve(cnt+5);
    l.reserve(cnt+5);
    r.reserve(cnt+5);
    forv(v,ad[u]) if(v!=p) a[++m]=v;
    l[0]=r[m+1]=1;
    forinc(i,1,m) l[i]=l[i-1]*(f[a[i]]+1)%M;
    fordec(i,m,1) r[i]=r[i+1]*(f[a[i]]+1)%M;
    forinc(i,1,m)
    {
        int v=a[i];
        g[v]=(g[u]*l[i-1]%M*r[i+1]%M+1)%M;
        dfs2(v,u);
    }
}
main()
{
    fasty;
    cin>>n>>M;
    forinc(i,2,n)
    {
        int u,v;cin>>u>>v;
        ad[u].pb(v);
        ad[v].pb(u);
    }
    forinc(i,1,n) f[i]=g[i]=1;
    dfs1(1,1);
    dfs2(1,1);
    forinc(i,1,n) cout<<f[i]*g[i]%M<<"\n";
}
/**
    we have to re-root the tree, as for every node, we will have to print out the
    numbers of way to paint the tree. As the root is colored black, and every black
    nodes must be connected, we define F[u] : numbers of ways to color the subtree of u
    if node u is black, then the answer for each 'node' is F['node'] after the re-root

    If we only have to output the answer for only a node, the dp works like this
    F[u] = product of (F[v] + 1) for each direct-child v of u
           F[v] : numbers of ways to color the subtree black and
           1    : leave it white

    now, back to the actual problem
    We define G[u] : numbers of ways to colors the nodes out side of u's subtree with
    the direct parent of u is colored black
    So the answer for a 'node' is F['node'] * (G['node'] + 1)
    G[u] can be calculated as folows :
    G[u] = (G[p] + 1) * product of (F[v] + 1) with all v as direct-child of p and v!=u
    this can be done O(n) by using partial product
*/


Measured memory_bytes: 32256
until (given = gets.split.map(&:to_i)) == [0, 0]
  n, m = given
  edge = Array.new(m) {[]}
  h = Array.new(m) {[]}
  n.times do
    a, b, cost, time = gets.split.map(&:to_i)
    a -= 1
    b -= 1
    edge[a][b] = edge[b][a] = [cost, time]
    h[a] << b
    h[b] << a
  end
  
  gets.to_i.times do
    p, q, r = gets.split.map(&:to_i)
    p -= 1
    q -= 1
  
    shortest = Array.new(m, Float::INFINITY)
    done = m.times.map(&:itself)
    shortest[p] = 0
    
    while !done.empty?
      u = done.min {|a, b| shortest[a] <=> shortest[b]}
      done.delete(u)
      
      h[u].each do |v|
        if (a = shortest[u] + edge[u][v][r]) < shortest[v]
          shortest[v] = a
        end
      end
    end
    
    puts shortest[q]
  end
end


Measured memory_bytes: 7776
n = int(input())
residents = [0]*4*3*10
#list[0-29]:第1棟  list[30-59]:第2棟  list[60-89]:第3棟  list[90-119]:第4棟
#list[0-9]:第1棟一階  list[10-19]:第1棟二階  list[20-29]:第1棟三階
for i in range(n):
  info = list(map(int, input().split()))
  room_num = (info[0]-1)*30 + (info[1]-1)*10 + info[2] -1
  residents[room_num] += info[3]

for i in range(4):
  for j in range(3):
    for k in range(10):
      room_num = i*30 + j*10 + k
      print('',residents[room_num],end='')
    print('')
  if i != 3:
    print('####################')


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define le 100005
using namespace std;
int dp[le], n[le];
int main(){
    //freopen("input.txt", "r", stdin);
    int len;
    scanf("%d", &len);
    for(int i = 0; i < len; i++){
        scanf("%d", &n[i]);
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 0; i < len; i++){
        for(int j = i + 1; j < 2 + i + 1; j++){
            if(j == len) break;
            dp[j] = min(dp[j], (dp[i] + abs(n[j] - n[i])));
        }
    }
    cout << dp[len - 1] << endl;
    return 0;
}



Measured memory_bytes: 4544
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

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

    vector<int> a(n*3);
    for ( int i = 0 ; i < n*3 ; i++ ){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());

    int64_t ans = 0;
    for ( int i = 1 ; i < n*2 ; i+=2){
        ans += a.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        String x = scanner.next();

        if(x.contains("ABC")) System.out.println("ARC");
        else System.out.println("ABC");
    }
}


Measured memory_bytes: 35732
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << "\t";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

vector<int> w;
vector<vector<int>> dp;
int n;

int f(int i, int j) {
    if (dp[i][j] != -1) return dp[i][j];
    assert(i <= j);
    if (i + 1 >= j) {dp[i][j] = 0; return 0;}
    int ans = max(f(i, j - 1), f(i + 1, j));
    for (int k = i; k < j - 1; ++k) {
        if (abs(w[j - 1] - w[k]) <= 1) {
            if (f(k + 1, j) != j - (k + 1) - 1) continue;
            ans = max(ans, f(i, k) + f(k + 1, j - 1) + 2);
        }
    }
    dp[i][j] = ans;
    return ans;
}

void solve() {
    dp = vector<vector<int>>(n + 1, vector<int>(n + 1, -1));
    cout << f(0, n) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        cin >> n;
        if (n == 0) break;
        w.resize(n);
        REP(i, n) cin >> w[i];
        solve();
    }
}



Measured memory_bytes: 3664
#include<cstdio>
#include<algorithm>
long long d[100000];
int main(){
    int n;
    scanf("%d",&n);
    long long b;
    for(int i=0;i<n;i++){
        scanf("%lld",&d[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%lld",&b);
        d[i]-=b;
    }
    std::sort(d,d+n);
    int l=0,r=n-1,l_used=0,r_used=0;
    while(l<=r){
        if(d[l]>=0){
            printf("%d",l+l_used+(n-1-r)+r_used);
            return 0;
        }
        if(d[r]<=0){
            printf("-1");
            return 0;
        }
        if(-d[l]<=d[r]){
            d[r]+=d[l];
            r_used=1;
            d[l]=0;
            l++;
            l_used=0;
        }else{
            d[l]+=d[r];
            l_used=1;
            d[r]=0;
            r--;
            r_used=0;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
int digit(int n,int k){
    int ret=1,cnt=1;
    while(1){
        if(n<=cnt*k-1){
            return ret;
        }
        ret++;
        cnt*=k;
    }
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n;
    cin>>n;
    int ans=LLONG_MAX;
    vector<int> x(n);
    rep(i,n)cin>>x[i];
    rep(i,0,101){
        int cnt=0;
        rep(j,n){
            cnt+=(x[j]-i)*(x[j]-i);
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

ll
find(vector<ll> & a, vector<ll> & sum, vector<vector<ll>> & dp, ll start, ll end) {
  if (start > end) return 0;
  if (start == end) return a[start];

  if (dp[start][end] == -1) {
    ll left = a[start] + sum[end] - sum[start] - find(a, sum, dp, start + 1, end);
    ll right = a[end] + sum[end-1] - sum[start-1] - find(a, sum, dp, start, end - 1);
    dp[start][end] = max(left, right);
  }

  return dp[start][end];
}

void
solve() {
  ll n;
  cin>>n;

  vector<ll> a(n+1), sum(n+1, 0);
  for (ll i=1; i<=n; i++) {
    cin>>a[i];
    sum[i] = sum[i-1] + a[i];
  }

  vector<vector<ll>> dp(n+1, vector<ll>(n+1, -1));
  ll ans = find(a, sum, dp, 1, n);
  cout<< ans - (sum[n] - ans) <<endl;
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 73936
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanLines)
	line := strings.Split(nextLine(), " ")
	h, _ := strconv.Atoi(line[0])
	w, _ := strconv.Atoi(line[1])

	//  i-1,j-1 i-1,j i-1,j+1
	//  i  ,j-1   i,j i  ,j+1
	//  i+1,j-1 i+1,j i+1,j+1
	roundI := []int{-1, -1, -1, 0, 0, 0, 1, 1, 1}
	roundJ := []int{-1, 0, 1, -1, 0, 1, -1, 0, 1}

	arr := make([][]string, h)
	for i := 0; i < h; i++ {
		arr[i] = strings.Split(nextLine(), "")
	}
	ansArr := make([]string, h)
	for i := 0; i < h; i++ {
		var ansStr bytes.Buffer
		for j := 0; j < w; j++ {
			// 自身が#ならスキップ
			if arr[i][j] == "#" {
				ansStr.WriteString("#")
				continue
			} else {
				cnt := 0
				// fmt.Printf("%d %d\n", i, j)
				for n := 0; n < 9; n++ {
					//
					moveI := i + roundI[n]
					moveJ := j + roundJ[n]
					// 配列の要素をはみ出るようならスキップ
					if moveI < 0 || moveJ < 0 || h <= moveI || w <= moveJ {
						// fmt.Printf("x")
						continue
					}
					if arr[moveI][moveJ] == "#" {
						cnt++
						// fmt.Printf("1")
					} else {
						// fmt.Printf("0")
					}
				}
				// fmt.Printf("\n")
				ansStr.WriteString(strconv.Itoa(cnt))
			}
		}
		ansArr = append(ansArr, ansStr.String())
	}

	for i := 0; i < len(ansArr); i++ {
		fmt.Println(ansArr[i])
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];/*
int main(){
  ll a,b,x,ans=0;
  cin>>a>>b>>x;
  irep(i,11,1){
    if(x-i*b>=a*powl(10,i-1)&&x-i*b<=a*powl(10,i))ans=max(ans,(x-i*b)/a);
  }
  cout<<min((ll)1e9,ans);
}*/

int main(){
  string s;
  cin>>s;
  if(s=="SUN")cout<<7;
  else if(s=="MON")cout<<6;
  else if(s=="TUE")cout<<5;
  else if(s=="WED")cout<<4;
  else if(s=="THU")cout<<3;
  else if(s=="FRI")cout<<2;
  else if(s=="SAT")cout<<1;
}




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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int A[200];

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

    int K, T;
    std::cin >> K >> T;

    for(int i=0;i<T;++i){
        std::cin >> A[i];
    }
    
    sort(A, A+T, greater<int>());

    int sum = accumulate(A+1, A+T, 0, plus<int>());
    
    std::cout << (sum >= A[0] - 1 ? 0 : A[0] - sum - 1) << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
vector<int> ga[100100];
int c[100100];
vector<int> path;
int n,u,v;
bool dfs(int u,int p){
	if(u==n){
		path.push_back(u);
		return true;
	}
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v!=p&&dfs(v,u)){
			path.push_back(u);
			return true;
		}
	}
	return false;
}
void color(int x){
	for(int i=0;i<ga[x].size();i++){
		int y=ga[x][i];
		if(c[y]!=0){
			continue;
		}
		c[y]=c[x];
		color(y);
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		ga[u].push_back(v);
		ga[v].push_back(u);
	}
	dfs(1,0);
	reverse(path.begin(),path.end());
	int f=0,s=path.size()-1;
	while(f<s){
		c[path[f]]=1;
		c[path[s]]=2;
		f++;
		s--;
		if(f<s){
			c[path[f]]=1;
			c[path[s]]=2;
			f++;
			s--;
		}
		else if(f==s){
			c[path[f]]=1;
			break;
		} 
		else{
			break;
		}
	}
	for(int i=0;i<path.size();i++){
		color(path[i]);
	}
	int ff=0;
	for(int i=1;i<=n;i++){
		if(c[i]==1)
			ff++;
	}
	if(ff>(n-ff)){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}


Measured memory_bytes: 11384
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    ll N,am = 0,mi = 10000000000;
    cin >> N;
    vector<ll> X(N,0);
    rep(i,N){
        cin >> X[i];
        am = max(am,X[i]);
    }

    vector<ll> DP(am+5,0);

    for(ll j = 1;j <= am;j++){
        for(ll i = 0;i<N;i++){
           DP[j] += (X[i]-j)*(X[i]-j);     
    }
    mi = min(DP[j],mi);
}

    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input){
  input = input.trim().split(' ').map(x=>parseInt(x));
  var a = input[0];
  var b = input[1];
  var c = input[2];
  var k = input[3];
  var ans = 0;
  if (a>k){
    ans = k;
  }else if (a+b>k){
    ans = a;
  }else{
    ans = a - (k-a-b);
  }
  console.log(ans);
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30080
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    map<ll,int> mp;
    REP(i,n){
        ll a;cin>>a;
        mp[a]++;
    }
    int ans=0;
    for(auto x:mp){
        if(x.first==x.second) continue;
        else if(x.first<x.second) ans+=(x.second-x.first);
        else ans+= x.second;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6272
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

    
N,M = map(int,input().split())
P = list(map(int,input().split()))
uf = UnionFind(N)
for i in range(M):
    x,y = map(int,input().split())
    x-=1;y-=1
    uf.union(x,y)
ans = 0
for i in range(N):
    now = P[i]-1
    loc = i
    if uf.is_same(now,loc):
        ans += 1
print(ans)

Measured memory_bytes: 20492
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int N, R;

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> N >> R;
	if (N >= 10)
		cout << R;
	else
		cout << 100*(10 - N) + R;
	
	
}


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

int main() {
  int n;
  cin >> n;
  int bar[n], count = 0;
  for(int i = 0; i < n ;i++) cin >> bar[i];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        int a = bar[i], b = bar[j], c = bar[k];
        if (a != b && b != c && a !=c) {
          if (a < b + c && b < a + c && c < a + b) count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005,INF=1e9;
struct edge
{
	int to,nxt,v;
}e[N<<2]; int n,head[N],cnt=1,p[N],q[N],fp[N],fq[N],cur,s,t;
inline void addedge(CI x,CI y)
{
	e[++cnt]=(edge){y,head[x],1}; head[x]=cnt;
	e[++cnt]=(edge){x,head[y],0}; head[y]=cnt;
}
class Network_Flow
{
	private:
		int q[N],dep[N],cur[N];
		#define to e[i].to
		inline bool BFS(CI s,CI t)
		{
			RI H=0,T=1; memset(dep,-1,t+1<<2);
			dep[q[1]=s]=0; while (H<T)
			{
				int now=q[++H]; for (RI i=head[now];i;i=e[i].nxt)
				if (e[i].v&&!~dep[to]) dep[to]=dep[now]+1,q[++T]=to;
			}
			return ~dep[t];
		}
		inline int DFS(CI now,CI tar,int dis)
		{
			if (now==tar) return dis; int ret=0;
			for (RI& i=cur[now];i&&dis;i=e[i].nxt)
			if (e[i].v&&dep[to]==dep[now]+1)
			{
				int dist=DFS(to,tar,min(dis,e[i].v));
				dis-=dist; ret+=dist; e[i].v-=dist; e[i^1].v+=dist;
			}
			if (!ret) dep[now]=-1; return ret;
		}
		#undef to
	public:
		inline int Dinic(CI s,CI t,int ret=0)
		{
			while (BFS(s,t)) memcpy(cur,head,t+1<<2),ret+=DFS(s,t,INF); return ret;
		}
}NF;
int main()
{
	RI i; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&p[i]),++p[i];
	for (i=1;i<=n;++i) scanf("%d",&q[i]),++q[i];
	for (i=1;i<=n;++i) for (cur=i;!fp[cur];cur=p[cur]) fp[cur]=i;
	for (i=1;i<=n;++i) for (cur=i;!fq[cur];cur=q[cur]) fq[cur]=i;
	for (cur=0,t=(n<<1)+1,i=1;i<=n;++i) if (p[i]==q[i])
	{
		if (p[i]!=i) ++cur,addedge(fp[i],fq[i]+n),addedge(fq[i]+n,fp[i]);
	} else
	{
		++cur; if (p[i]==i) addedge(s,fq[i]+n); else
		if (q[i]==i) addedge(fp[i],t); else addedge(fp[i],fq[i]+n);
	}
	return printf("%d",cur-NF.Dinic(s,t)),0;
}

Measured memory_bytes: 12288
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string s,t;int l;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	if(s[i]!=t[i])l++;
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 3892