akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//行列演算
Matrix mIdentity(ll n) {
    Matrix A(n, Array(n));
    for(int i = 0; i < n; ++i)
        A[i][i] = 1;
    return A;
}

Matrix mMul(const Matrix &A, const Matrix &B, ll m) {
    Matrix C(A.size(), Array(B[0].size()));
    for(int i = 0; i < C.size(); ++i)
        for(int j = 0; j < C[i].size(); ++j)
            for(int k = 0; k < A[i].size(); ++k)
                (C[i][j] += (A[i][k] % m) * (B[k][j] % m)) %= m;
    return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix &A, ll e, ll m) {
    return e == 0 ? mIdentity(A.size()) : e % 2 == 0 ? mPow(mMul(A, A, m), e / 2, m) : mMul(A, mPow(A, e - 1, m), m);
}

void solve() {
    ll l, a, b, m;
    cin >> l >> a >> b >> m;

    ll num = 9;
    vec<ll> con(19, 0);
    ll pre = 0;
    REP(i, 18) {
        if(num >= a) {
            con[i + 1] = (num - a) / b;
            con[i + 1] -= pre;
            if((num - a) / b >= l - 1) {
                con[i + 1] = l - 1 - pre;
                break;
            }
            pre = (num - a) / b;
        }
        num *= 10;
        num += 9;
    }

    Matrix ans({{a % m}, {(a + b) % m}, {b % m}});
    num = 10;

    rep(i, 1, 19) {

        if(con[i]) {
            Matrix f({{num, 1, 0}, {0, 1, 1}, {0, 0, 1}});
            f = mPow(f, con[i], m);
            ans = mMul(f, ans, m);
        }
        num *= 10;
        num %= m;
    }
    cout << ans[0][0] << en;
}

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

    solve();
    /*
    ll t;
    cin >> t;
    REP(i, t) { solve(); }*/

    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,_a[10005],_b[10005],*a=_a+5000,*b=_b+5000,n1,n2;
char s[5005],t[5005];
int main()
{
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	if(s[1]!=t[1])a[++n1]=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]!=s[i+1])a[++n1]=i;
		if(t[i]!=t[i+1])b[++n2]=i;
	}
	int m1=n1,m2=n2;
	while(m1<=5000)a[++m1]=n;
	while(m2<=5000)b[++m2]=n;
	int ans=1000000000;
	for(int i=-n1;i<=n2;i++)
	{
		if(i&1)continue;
		int res=0;
		for(int j=-5000;j<=5000;j++)
		{
			if(j+i>=-5000&&j+i<=5000)res+=abs(a[j+i]-b[j]);
			else
			{
				if(j+i<-5000)res+=b[j];
				else res+=n-b[j];
			}
		}
		ans=min(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

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

void solve(long long N, long long M, vector<long long> A) {
    ll sum = 0;
    rep(i, N) { sum += A[i]; }
    ll c = 0;
    ll cr = sum / (4 * M);

    rep(i, N) {
        if ((sum % (4 * M) == 0 && A[i] >= cr) ||
            (sum % (4 * M) != 0 && A[i] > cr))
            c++;
    }
    if (c >= M)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main() {
    long long M;
    long long N;
    scanf("%lld", &N);
    vector<long long> A(N - 1 + 1);
    scanf("%lld", &M);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, M, A);
    return 0;
}


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

int main(){
int n;
cin >> n;
int a[n],b[n];
for(int i=0;i<n;i++){ cin >> a[i]; b[i]=a[i];}
sort(b,b+n);
for(int i=0;i<n;i++)
{
	if(a[i]!=b[n-1])
      cout << b[n-1] << endl;
  	else
      cout << b[n-2] << endl;
}
return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  if(A == B){
  	cout << "Draw" << endl;
  }else if(A == 1){
  	cout << "Alice" << endl;
  }else if(B == 1){
  	cout << "Bob" << endl;
  }else if(A > B){
    cout << "Alice" << endl;
  }else{
  	cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
line = $stdin
lines = line.readlines
line.close

lines.each do |l|
	arr = l.split(",")
	arr_int =  arr[0..9].map{|s| s.to_i}
	dist_sum = arr_int.reduce(:+)
	v1, v2 = arr[10].to_i, arr[11].to_i
	meet_t = dist_sum.to_f / (v1.to_f + v2.to_f)
	meet_l = meet_t * v1
	ans = 0
	for i in 0..9 do
		ans += arr_int[i]
		if ans >= meet_l then
			p i+1
			break
		end
	end
end

Measured memory_bytes: 6116
#include<bits/stdc++.h>
using namespace std;
int main()
{
        long long int x1,x2,x3,x4,x5,r=0,ans=0,i,j,n,x=0;
        cin>>x1>>x2>>x3>>x4>>x5;
        if(x1==0)
            cout<<1<<endl;
        else if(x2==0)
            cout<<2<<endl;
        else if(x3==0)
            cout<<3<<endl;
        else if(x4==0)
            cout<<4<<endl;
        else if(x5==0)
            cout<<5<<endl;
   return 0;
}









Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;


int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	 // int t ;
	 // cin>>t;
	 // whln(t){
  	ll n,sum=0;
  	cin>>n;
  	map<ll,ll>m;
  	vector<ll>a(n);
  	rep(i,n){
  		cin>>a[i];
  		sum+=a[i];
  		m[a[i]]++;
  	}
  	ll q,k;
  	cin>>q ;
  	vector<pair<ll,ll>>v(q);
  	rep(i,q){
  		cin>>v[i].first>>v[i].second;
  		sum = sum - m[v[i].first]*(v[i].first -v[i].second);
  		k  = m[v[i].first];
  		m[v[i].first]= 0;
  		m[v[i].second]+= k ;
  		cout<<sum<<"\n";
  	}

}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

Measured memory_bytes: 11324
#include <bits/stdc++.h>  
using namespace std;  
typedef unsigned long long ll; 
typedef long double ld;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;  
const int N = 100000 + 5;

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	while(a > 0 && c > 0){
		c = c - b;
		if(c <= 0){
			cout << "Yes" << endl;
			break;
		}
		a = a - d;
		if(a <= 0){
			cout << "No" << endl;
			break;
		}
	}
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int n;
string s;
string make(string t){
  for(int i = 1;i < n-1;i++){
    if(t[i] == 'S'){
      if(s[i] == 'o')t += t[i-1];
      else t += (t[i-1] == 'S' ? 'W' : 'S');
    }else{
      if(s[i] == 'o')t += (t[i-1] == 'S' ? 'W' : 'S');
      else t += t[i-1];
    }
  }
  return t;
}
bool check(string t,bool is){
  if(is){
    if(t[0] == 'S' && s[0] == 'o')return t[1] == t.back() ? true : false;
    else if(t[0] == 'S' && s[0] == 'x')return t[1] == t.back() ? false : true;
    else if(t[0] == 'W' && s[0] == 'o')return t[1] == t.back() ? false : true;
    else return t[1] == t.back() ? true : false;
  }else{
    if(t.back() == 'S' && s.back() == 'o')return t[0] == t[n-2] ? true : false;
    else if(t.back() == 'S' && s.back() == 'x')return t[0] == t[n-2] ? false : true;
    else if(t.back() == 'W' && s.back() == 'o')return t[0] == t[n-2] ? false : true;
    else return t[0] == t[n-2] ? true : false;
  }
}

int main(){
  
  cin >> n >> s;
  {
    string t = make("SS");
    if(check(t,true) && check(t,false)){
      cout << t << endl;
      return 0;
    }
    
  }
  {
    string t = make("SW");
    if(check(t,true) && check(t,false)){
      cout << t << endl;
      return 0;
    }
    
  }
  {
    string t = make("WW");
    if(check(t,true) && check(t,false)){
      cout << t << endl;
      return 0;
    }
    
  }
  {
    string t = make("WS");
    if(check(t,true) && check(t,false)){
      cout << t << endl;
      return 0;
    }

  }
  cout << -1 << endl;
  


  return 0;
}

Measured memory_bytes: 796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    int n, m; sc(n), sc(m);
    int left, right, tmp1, tmp2; sc(left), sc(right);
    for (int i = 2; i <= m; i++){
        sc(tmp1), sc(tmp2);
        left = max(left, tmp1);
        right = min(right, tmp2);
    }
    if (left > right) cout << 0 << endl;
    else cout << right - left + 1 << endl;
    return 0;
}

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

//ABC157A
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d", &n);
  printf("%d", (n+1)/2);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;
int a[3001];

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n; i++){
			cin >> a[i];
			sum += a[i];
	}
	cout << sum - n << endl;
	return 0;
}


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

int main()
{

  int dp[4001][5];
  for(int i=1;i<5;i++)
    for(int j=0;j<4001;j++)
      dp[j][i] = i==1&&j<=1000?1:0;

  for(int i=2;i<=4;i++)
    for(int j=0;j<=4000;j++)
      for(int k=0;k<=j && k<=1000;k++)
	dp[j][i] += dp[j-k][i-1];

  int n;
  while(cin >> n)
    cout << dp[n][4] << endl;
    
  return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<cmath>
typedef long long ll;
using namespace std;
ll ans[100005] = {};
int main() {
	ll x, y;
	cin >> x>>y;
	ll count = 0;
	while (x <= y) {
		x = x * 2;
		count++;
	}
	cout << count << endl;
	return 0;
}

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

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i,0,n) cin >> d[i];
    sort(d.begin(), d.end(), greater<ll>());
    unique(d.begin(),d.end());

    ll prev(LL_MAX), cnt(0);
    for (ll i=0; i<n; i++)
    {
        if (prev <= d[i])
            break;
        prev = d[i];
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _k: usize,
      _a: [[usize; n]; n]
   }
   let mut k = _k;
   let mut a = _a;
   let mut dp = vec![vec![0; n]; n];
   for i in 0..n {
      dp[i][i] = 1;
   }
   while k > 0 {
      let mut b = vec![vec![0; n]; n];
      if k & 1 == 1 {
         let mut dp2 = vec![vec![0; n]; n];
         db(&dp, &a, &mut dp2);
         dp = dp2;
      }
      db(&a, &a, &mut b);
      a = b;
      k >>= 1;
   }
   let mut ans = 0;
   for i in 0..n {
      for j in 0..n {
         ans += dp[i][j];
         ans %= MOD;
      }
   }
   println!("{}", ans);
}

const MOD: usize = 1000000007;

fn db(a: &Vec<Vec<usize>>, b: &Vec<Vec<usize>>, c: &mut Vec<Vec<usize>>) {
   let n = a[0].len();
   for i in 0..n {
      for j in 0..n {
         for k in 0..n {
            c[i][j] += a[i][k] * b[k][j];
            c[i][j] %= MOD;
         }
      }
   }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, num = 0;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    num += r - l + 1;
  }
  cout << num << endl;
}

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

using ll=long long;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }
 
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

int gcd(int a,int b){
  return a?gcd(b%a,a):b;
}

int main(){
  int N; cin>>N;
  SegmentTree<int> seg(N,[](int a,int b){return gcd(a,b);},0);
  for(int i=0;i<N;++i){
    int A; cin>>A;
    seg.update(i+1,A);
  }
  int ans=1;
  for(int i=0;i<N;++i){
    if(i==0){
      ans=max(ans,seg.query(i+2,N+1));
    }
    else if(i==N-1){
      ans=max(ans,seg.query(1,N));
    }
    else{
      ans=max(ans,gcd(seg.query(1,i+1),seg.query(i+2,N+1)));
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1280
n, x, m = [int(i) for i in input().split(" ")]

vis = [-1] * m
sq = [(i*i)%m for i in range(m)]

cur = x
y = x
flag = False
for i in range(n):
  if vis[cur] >= 0:
    flag = True
    break
  vis[cur] = i
  cur = (cur*cur)%m

cycle = max(vis) - vis[cur] + 1

ans = 0
if not flag:
  for i in range(n):
    ans += y
    y = (y*y)%m
    # print("hi")
  print(ans)
elif n <= vis[cur]:
  for i in range(min(n, vis[cur])):
    ans += x
    x = (x*x)%m
  # print("hi")
  print(ans)
else:
  for i in range(min(n, vis[cur])):
    ans += x
    x = (x*x)%m
  y = x
  rem = n - vis[cur]
  cyclesum = 0
  for i in range(cycle):
    cyclesum += y
    y = (y*y)%m
  total = rem//cycle
  extra = rem - cycle*total
  ans += cyclesum*total
  # print("cyclesum", cyclesum)
  for i in range(extra):
    ans += y
    y = (y*y)%m
  print(ans)

Measured memory_bytes: 74520
#include<iostream>
#include<vector>

using namespace std;
int main() {

	int N,level=0;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	level = H[0];

	for (int i = 1; i < N; i++)
	{

		if (H[i-1]-1 > H[i]||level>H[i])
		{
			cout << "No";
			return 0;
		}

		if (H[i] > level)
		{
			level = H[i] - 1;

		}
	}
	cout << "Yes";
}

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

int gcd(int a, int b) {
	return a % b ? gcd(b, a % b) : b;
}

struct s {
	int dst, rev, cap;
	s(){}
	s(int d, int r, int c){
		dst=d; rev=r; cap=c;
	}
};

void add(int src, int dst, int cost, vector<vector
 >& G) {
	G[src].push_back(s(dst,G[dst].size(),cost));
	G[dst].push_back(s(src,G[src].size()-1,0));
}

int dfs(int n, int dst, int flow, vector<vector
 > &G, bool* vis) {
	if(vis[n]) return 0;
	if(n == dst) {
		return flow;
	}
	vis[n] = true;
	for(int i = 0; i < G[n].size(); i++) {
		if(G[n][i].cap > 0) {
			int res = dfs(G[n][i].dst, dst, min(flow,G[n][i].cap), G, vis);
			if(res) {
				G[n][i].cap -= res;
				G[G[n][i].dst][G[n][i].rev].cap += res;
				return res;
			}
		}
	}
	return 0;
}

int maxf(int src, int dst, vector<vector
 > &G) {
	int res = 0;
	bool f = true;
	while(f) {
		f = false;
		bool vis[1100] = {};
		int tmp = dfs(src, dst, 100, G, vis);
		if(tmp) {
			f = true;
			res += tmp;
		}
	}
	return res;
}

int main() {
	int m, n;
	while(cin >> m >> n, m || n) {
		vector<int> b(m), r(n);
		vector<vector
 > G(m+n+2);
		for(int i = 0; i < m; i++) cin >> b[i];
		for(int i = 0; i < n; i++) cin >> r[i];

		for(int i = 0; i < m; i++) {
			for(int j = 0; j < n; j++) {
				if(gcd(b[i],r[j]) > 1) {
					add(i+1, j+m+1, 1, G);
				}
			}
		}
		for(int i = 0; i < m; i++) add(0,i+1,1,G);
		for(int i = 0; i < n; i++) add(i+1+m,n+m+1,1,G);
		cout << maxf(0,n+m+1,G) << endl;
	}
}

Measured memory_bytes: 7340
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<vector<ll>> a(8,vector<ll>(n));
    rep(i,0,n){
        ll x,y,z; cin >> x >> y >> z;
        a[0][i] = x+y+z;
        a[1][i] = x-y+z;
        a[2][i] = x-y-z;
        a[3][i] = x+y-z;
        a[4][i] = -(x+y+z);
        a[5][i] = -(x-y+z);
        a[6][i] = -(x-y-z);
        a[7][i] = -(x+y-z);
    }
    rep(i,0,8){
        sort(rall(a[i]));
    }
    ll ans = -INF;
    rep(i,0,8){
        ll s = 0;
        rep(j,0,m){
            s += a[i][j];
        }
        chmax(ans,s);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 384
while True:
	a, b, c = map(int, raw_input().split())
	if (a == -1) and (b == -1) and (c == -1):
		break
	if (a == -1) or (b == -1):
		print "F"
	elif (a + b) >= 80:
		print "A"
	elif (a + b) >= 65:
		print "B"
	elif (a + b) >= 50:
		print "C"
	elif (a + b) < 30:
		print "F"
	elif c >= 50:
		print "C"
	else:
		print "D"

Measured memory_bytes: 4220
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
   
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);


        var s = Console.ReadLine();
        var c = s.ToCharArray();
        var count = 0;
        for(int i = 0; i < s.Length / 2 + 1; i++)
        {
            if (c[i] != c[s.Length - 1 - i])
            {
                count++;
                c[i] = c[s.Length - 1 - i];
            }
        }

        Console.WriteLine(count);


        Console.Out.Flush();

    }
}

Measured memory_bytes: 11092
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map(String::toInt)
    val sorted = list.sorted()
    var diff = 0
    for (i in 0 until list.size) {
        if (list[i] != sorted[i]) {
            diff++
        }

        if (3 <= diff) {
            println("NO")
            return
        }

    }
    if (diff == 2 || diff == 0) {
        println("YES")
    } else {
        println("NO")
    }
}


Measured memory_bytes: 37928
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
dp = Array.new(n, 0)
dp[0] = a[0]
(1...n).each do |i|
  dp[i] = dp[i - 1] + a[i]
end
puts dp.map {|i| ((dp[n - 1] - i) - i).abs }.min

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

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

    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
        a[i]--;
    }
    vector<bool> v(n,false);
    ll now = 0;
    ll c = 0;
    ll x = 0;

    while (true){
        v[now] = true;
        c++;
        now = a[now];
        if (v[now]){
            x = now;
            break;
        }
        else{
            v[now] = true;
        }
    }
    //cout << x << endl;
    //cout << c << endl;
    now = 0;
    ll s = 0;
    while(true){
        if (now == x){
            break;
        }
        else{
            s++;
            now = a[now];
        }
    }
    //cout << s << endl;
    ll loop = c-s;
    ll z = (max(k-s,0LL))%loop;
    ll ans = 0;
    now = 0;
    if (k >= s){
        for (ll i = 0; i < s+z; i++){
            now = a[now];
        }
    }
    else{
        for (ll i = 0; i < k; i++){
            now = a[now];
        }
    }
    cout << now+1 << endl;
}

Measured memory_bytes: 4748
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int n;
int a[100050];

int main()
{
    scanf ("%d",&n);
    for (int i=1;i<=n;i++)
        scanf ("%d",&a[i]);
    sort(a+1,a+1+n);
    int maxn=0,maxnn=0;
    for (int i=n;i>=1;i--)
        {
        if (maxn==0 && a[i]==a[i-1])
            {
            maxn=a[i];
            i--;
            }
        else if (a[i]==a[i-1] && maxn!=0)
                {
                maxnn=a[i];
                break;
                }
        }
    if (maxnn!=0) printf ("%lld",(long long)maxn*(long long)maxnn);
    else printf ("0");
}


Measured memory_bytes: 640
#include <stdio.h>

char X[200010];

int main(void)
{
	int i = 0, char_count = 0, deletable_count = 0 ,delete_count = 0;
	scanf("%s", X);

	while (X[i] != '\0') {
		char_count++;
		if (X[i] == 'S') {
			deletable_count++;
		} else {
			if (deletable_count > 0) {
				deletable_count--;
				delete_count += 2;
			}
		}
		i++;
	}

	printf("%d\n", char_count - delete_count);

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

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

    int n, a, b;
    cin  >> n >> a  >> b;
    
    int temp = 0;
    int sum = 0;
    int total = 0;
    for (int i = 1; i <= n; ++i)
    {
        temp = i;
        sum = (temp % 10);
        temp /= 10;
        sum += (temp % 10);
        temp /= 10;
        sum += (temp % 10);
        temp /= 10;
        sum += (temp % 10);
        temp /= 10;
        sum += (temp % 10);
        if (sum >= a && sum <= b) total += i;
    }
    cout << total << endl;

    return 0;
}

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

int main()
{
  string s,t,u;
  cin >> s >> t;
  u=t.substr(0,s.size());
  if (s==u && t.size()-s.size()==1)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  
}


Measured memory_bytes: 3572
#include<iostream> 
#include<vector>
#include<string>
using namespace std;
 
int main(){
  int N; 
  cin >> N;
  string S;
  cin >> S;
  int count;
  for (int i = 0; i < 1000; i++){
    vector<int> d = {i/100, (i%100)/10, i%10};
    int num = 0;
    for (int j = 0; j < N; j++){
      if (S[j] - '0' == d[num]){
        num++;}
      if (num == 3){
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

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

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

using namespace std;



int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a * c, max(a * d, max(b * c, b * d)));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, k;
  cin >> n >> k;
  if (n % k == 0) cout << 0 << endl;
  else cout << 1 << endl;

  
  return 0;
}

Measured memory_bytes: 256
A, V = list(map(int, input().split()))
B, W = list(map(int, input().split()))
T = int(input())

kyori = max(A-B, B-A)

if W>V:
  print("NO")
else:
  if (V-W)*T>=kyori:
    print("YES")
  else:
    print("NO")

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

int main() {
	int n, i, j, k, sum = 0;
	vector<int> vec;
	cin >> n;
	for(i = 0; i < n; i++) {
		int x;
		cin >> x;
		vec.push_back(x);
	}
	for(i = 0; i < n; i++) {
		for(j = i + 1; j < n; j++) {
			sum += (vec[i] * vec[j]);
		}
	}
	cout << sum << endl;
	return 0;
}

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

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

    if (a + b + c >= 22) {
        cout << "bust\n";
    }
    else {
        cout << "win\n";
    }
    return 0;
}


Measured memory_bytes: 256
N, *H = map(int, open(0).read().split())
c = 1
for i, h in enumerate(H):
    b = []
    for j in range(i):
        if H[j] <= h:
            b.append(True)
        else:
            b.append(False)
    
    if not len(b) == 0 and all(b):
        c += 1

print(c)

Measured memory_bytes: 2940
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = long.Parse(Console.ReadLine());

            var happy = ((x / 500) * 1000);
            x = x % 500;

            if(x > 0){
                happy += ((x / 5) * 5);
            }

            Console.WriteLine(happy);
        }
    }
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int D[100000], H[100000];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N;
	cin>>N;
	for(int i=0;i<N;i++) cin>>H[i];
	D[1]=abs(H[1]-H[0]);
	for(int i=2;i<N;i++) {
		D[i]=min(D[i-1]+abs(H[i]-H[i-1]),D[i-2]+abs(H[i]-H[i-2]));
	}
	cout<<D[N-1]<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

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

    string s;
    while(cin >> s) {
        if (s =="-") {
            break;
        }
        int m;
        cin >> m;
        int n = s.size();
        for (int i = 0; i < m; i++) {
            int h;
            cin >> h;
            s = s.substr(h, n - h) + s.substr(0, h);
        }
        cout << s << endl;
    }
    return 0;
}


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


int main()
{
    int N;
    cin >> N;
    
    if (N == 1) {
        cout << "Hello World" << endl;
    }else{
        int A,B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll gcd(ll a, ll b) {
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

ll A[1000010];
ll B[1000010];
bool U[1000010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    memset(B, 0, sizeof(B));
    memset(U, 0, sizeof(U));
    REP(i, N) {
        cin >> A[i];
        B[A[i]]++;
    }

    ll g = A[0];
    REP(i, N) {
        g = gcd(g, A[i]);
    }
    if (g > 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    for (ll i = 2; i < 1000005; ++i) {
        if (U[i])
            continue;
        ll m = 0;
        for (ll j = i; j < 1000005; j += i) {
            U[j] = true;
            m += B[j];
        }
        if (m > 1) {
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 20212
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    S = list(map(int, readline().split()))
    T = list(map(int, readline().split()))

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N + 1):
        dp[i][0] = 1
    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD
            if S[i] == T[j]:
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD

    print(dp[N][M])
    return


if __name__ == '__main__':
    main()


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

int64_t Q=1000000007;

int main() {
  int N;
  cin>>N;
  string S,T;
  cin>>S>>T;
  int64_t A=1,Z=3,B=1;
  if(S[0]!=T[0]){
    A=2,Z=6,B=2;
  }
  while(A<N){
    if(S[A]!=T[A]){
      if(B==1){
        Z*=2;
      }
      else{
        Z*=3;
      }
      A+=2,B=2;
    }
    else{
      if(B==1){
        Z*=2;
      }
      A+=1,B=1;
    }
    Z%=Q;
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;

typedef long long ll;
ll INF = 1LL << 60;
ll MAX = 100010;

int
main() 
{
  string s, t;cin >> s >> t;
  map<char, char>dics;
  map<char, char>dict;

  rep(i, 0, s.size()){
    char indexs = s[i];
    if(dics.count(indexs) == 0){
      dics[indexs] = t[i];
    } else {
      if(dics[indexs] == t[i])continue;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
 
  rep(i, 0, t.size()){
    char indext = t[i];
    if(dict.count(indext) == 0){
      dict[indext] = s[i];
    } else {
      if(dict[indext] == s[i])continue;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}




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

int main()
{
	int n, i;
	string s1, s2;
	cin >> n;
	cin >> s1 >>s2;


	for(i=0; i<n; i++){
		printf("%c%c", s1[i], s2[i]);
	}

    return 0;
}


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

int main()
{
  double start_x, start_y, end_x, end_y;
  cin >> start_x >> start_y >> end_x >> end_y;
  double dist_x = abs(end_x - start_x);
  double dist_y = abs(end_y - start_y);
  printf("%.8f\n", sqrt(dist_x * dist_x + dist_y * dist_y));
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define ii pair<int,int>
#define mp make_pair
#define vi vt<int>
#define vvi vt<vi>
#define vii vt<ii>
#define vvii vt<vii>
#define For(i,a,b) for(int i = a; i < b; i++)
#define foR(i,a,b) for(int i = a; i <= b; i++)
#define roF(i,a,b) for(int i = a - 1; i >= b; i--)
#define Rof(i,a,b) for(int i = a; i >= b; i--)
#define NEW 0
#define FOUNDED 1
#define CHECKED 2
#define pb push_back
#define pob pop_back
#define mset(a,b) memset(a,b,sizeof(a))

template<class T1, class T2> ostream& operator<< (ostream& the, pair<T1, T2> a){
	the << a.first << "\t" << a.second << "\n";
	return the;
}
template<class T1> ostream& operator<< (ostream& the, vt<T1> a){
	For(i,0,a.size()) {
		the << a[i] << "\n";
	}
	return the;
}


int main () {

//	freopen("INP.txt","r",stdin);
//	freopen("OUT.txt","w",stdout);
//	freopen(".inp","r",stdin);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//  ifstream fin("in.txt");
//  ofstream fout("out.txt");
//  ifstream dict("dict.txt");
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c+b-a,0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,m;cin>>n>>m;
  vector<vector<char>> a(n,vector<char>(n));
  vector<vector<char>> b(m,vector<char>(m));
  rep(i,n)rep(j,n)cin>>a[i][j];
  rep(i,m)rep(j,m)cin>>b[i][j];
  rep(i,n-m+1)rep(j,n-m+1){
    //n*nの正方形の中にあるm*mの正方形は(n-m+1)*(n-m+1)通り
    bool ans=true;
    rep(k,m)rep(l,m){
      if(a[i+k][j+l]!=b[k][l])ans=false;
    }
    if(ans){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  //input
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector <int> x(N);
  vector <int> y(M);
  rep(i,N) cin >> x[i];
  rep(i,M) cin >> y[i];

  //solve
  string ans = "War";
  for (int i = X + 1; i <= Y; i++){
    if (i > *max_element(all(x)) && i <= *min_element(all(y)) ){
      ans = "No War";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n, m) for (int i = (n), i < (m); i++)

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int
main(int argc, char *argv[])
{

  char s[110];
  scanf("%s", s);

  int x = 0, y = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (i % 2 == 0) {
      if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') x++;
    }
    else {
      if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') y++;
    }
  }

  if (x == 0 && y == 0) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int a,b;
  char c;
  cin >> a >> c >> b;
  if (c == '+') cout << a +b <<endl;
  else cout << a -b << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 1;
  char before = S[0];
  for (int i = 1; i < S.size(); i++) {
    if (S[i] != before) {
      ans++;
      before = S[i];
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def ppp(a, b, m):  # a^b%modを求めたい
    if b == 0:
        return 1
    elif b % 2 == 0:
        return ppp(a, b // 2, m) ** 2 % m
    else:
        return ppp(a, (b - 1) // 2, m) ** 2 * a % m


def knight(x, y):
    mod = 10 ** 9 + 7
    x, y = min(x, y), max(x, y)

    if (x + y) % 3 != 0:
        return 0
    if y > 2 * x:
        return 0

    move = (x + y) // 3
    right = 2 * move - y
    up = move-right

    ans = 1
    tmp = 1
    for i in range(up):
        ans *= (move - i)
        tmp *= i + 1
        ans %= mod
        tmp %= mod
    ans *= ppp(tmp, mod - 2, mod)
    return ans % mod


if __name__ == "__main__":
    x, y = map(int, input().split())
    ans = knight(x, y)
    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int	a[20];
int main() {
	for(int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10, greater<int>());
	for(int i = 0; i < 3; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, M, A[100001] = {}, B, C, CB[100001] = {}, sum = 0, box = 1;

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	for (int i = 1; i <= M; i++) {
		cin >> B >> C;
		CB[i] = C * 1000000 + B;
	}
	stable_sort(A, A + N + 1);
	stable_sort(CB, CB + M + 1,greater<ll>());
	for (int i = 0; i < M; i++) {
		for (int j = 1; j <= CB[i] % 1000000 && box <= N; j++) {
			if (A[box] < CB[i] / 1000000) {
				sum += CB[i] / 1000000 - A[box];
				box++;
			}
			else {
				cout << sum << endl;
				return 0;
			}
		}
		if (box == N) {
			cout << sum << endl;
			return 0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long 
struct mat{
	int x[2][2];
	mat(int a=0,int b=0,int c=0,int d=0){
		x[0][0]=a,x[0][1]=b,x[1][0]=c,x[1][1]=d;
	}
};
mat operator*(mat a,mat b){
	mat c;
	for(int i=0;i<2;i++) for(int j=0;j<2;j++){
		c.x[i][j]=1e18;for(int k=0;k<2;k++) c.x[i][j]=min(c.x[i][j],a.x[i][k]+b.x[k][j]);
	}return c;
}
string s;int n,k;
mat p;
mat qpow(mat x,int y){
	mat res=(0,1e18,1e18,0);
	while(y){
		if(y&1) res=res*x;x=x*x;y=y/2;
		
	}return res;
}
signed main(){
	cin>>s>>k;s=s[s.size()-1]+s;n=s.size();
	p=mat(0,1e18,1e18,0);
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1])p=p*mat(1e18,1,0,1);
		else p=p*mat(0,1,0,1);
	}//p=p*p;
	p=qpow(p,k);
	cout<<min(p.x[1][0],p.x[1][1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
   int n;cin>>n;
   int arr[n][3];
   for(int i=0;i<n;i++){
       for(int j=0;j<3;j++){
           cin>>arr[i][j];
       }
   }
   int dp[n][3]={0};
   dp[0][0] = arr[0][0];
   dp[0][1] = arr[0][1];
   dp[0][2] = arr[0][2];
   for(int i=1;i<n;i++){
       for(int j=0;j<3;j++){
           for(int k=0;k<3;k++){
               if(j!=k){
                   dp[i][j] = max(dp[i-1][k]+arr[i][j],dp[i][j]);
               }
           }
       }
   }
   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 2560
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();


            for (int i = 0; i < list.Count; i++)
            {
                var v = list[i];
                var j = i - 1;
                while (j >= 0 && list[j] > v)
                {
                    list[j + 1] = list[j];
                    j--;
                }
                list[j + 1] = v;
                Console.WriteLine(string.Join(" ", list));
            }
        }
    }
}



Measured memory_bytes: 18360
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

string mult(string S, int x){
    assert(x >= 0 && x < 10);
    string T(SZ(S), '0');

    int t = 0;
    IREP(i, SZ(S)){
        int a = S[i] - '0';
        t += a * x;
        T[i] = '0' + t % 10;
        t /= 10;
    }
    if(t) return to_string(t) + T;
    else return T;
}

string add(string S, int x){
    int i = 0, t = 0;
    string T = "";
    while(true){
        if(t == 0 && x == 0 && i >= SZ(S)) break;

        if(i < SZ(S)) t += S[SZ(S) - 1 - i] - '0';
        t += x % 10;

        T += '0' + t % 10;
        x /= 10;
        t /= 10;
        i++;
    }
    Reverse(T);
    return T;
}

int digitsum(string S){
    int t = 0;
    REP(i, SZ(S)) t += S[i] - '0';
    return t;
}

signed main(){

    string N; cin >> N;
    int k0 = 0, k1 = 5000000;
    while(k1 - k0 > 1){
        int k = (k0 + k1) / 2;
        if(digitsum(add(mult(N, 9), k)) <= k) k1 = k;
        else k0 = k;
    }
    int ans = (k1 + 8) / 9;
    Out(ans);

    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 100010;
int _w;

int n, a[N];
ll s, t, d[N], b[N];

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[i];
		s += a[i];
	}
	t = 1LL * n * (n+1) / 2;
	if( s % t ) return puts("NO"), 0;
	s /= t;
	for( int i = 1; i <= n; ++i )
		if( i == 1 ) d[i] = a[i] - a[n];
		else d[i] = a[i] - a[i-1];
	for( int i = 1; i <= n; ++i ) {
		ll x = d[i] - s;
		if( x > 0 ) return puts("NO"), 0;
		if( abs(x) % n ) return puts("NO"), 0;
		t = abs(x) / n;
		int p = i == 1 ? n : i-1;
		b[1] += t * (n-(p-1));
	}
	for( int i = 2; i <= n; ++i )
		b[i] = b[i-1] + d[i];
	for( int i = 1; i <= n; ++i )
		if( b[i] != a[i] )
			return puts("NO"), 0;
	return puts("YES"), 0;
}


Measured memory_bytes: 2176