akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

typedef long long ll;

const int N = 100000;

bool searchP(int A[], ll P, int k, int n)
{
  int i = 0;
  for(int j = 0;j < k;j++){
    ll st = 0;
    while(st + A[i] <= P){
      st += A[i++];
      if(i == n) return true; //トラックが余分な場合、もしくはk台以内で十分運べる場合
    }
  }
  return false; //トラックが足りない
}

int main()
{
  int n,k;
  int a[N+1]={};

  cin >> n >> k;
  for(int i = 0;i < n;i++) cin >> a[i];
  
  ll left = 0;
  ll right = N*N;
  ll mid_P;
  //二分探索してPを探索する
  
  while(right - left > 1){
    mid_P = (left + right)/2;

    bool result = searchP(a, mid_P, k, n);
    
    if(result) right = mid_P; //pointer shifts to left;
    else left = mid_P; //pointer shifts to right;
  }
  ll ans = right;
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3512
def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    mod = 1000000007
    sum_left = sum(a_list[1:])
    answer = 0
    for i in range(n-1):
        answer += (a_list[i] * sum_left) % mod
        sum_left -= a_list[i+1]
    print(int(answer % mod))


if __name__ == '__main__':
    main()


Measured memory_bytes: 31520
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 
const int N = 2e5+5;

ll a[N];

int main()
{	
	int n;
	ll res = 0;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i) scanf("%lld",&a[i]),res ^= a[i];
	for(int i = 1;i <= n;++i) printf("%lld%c",res^a[i],i == n ?'\n' :' ');
	return 0;
}


Measured memory_bytes: 5308
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)


#define Vi vector
#define pr pair
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

vector<char> prime (10000000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (ld j=i*i; j<=n; j+=i)
					prime[j] = false;
}


vd v1;
vector <bool> visit;
vvd g;
vvd g1;
vd ar;
vvd final;
//ld mind = 1000000006;
vd mind;
ld c;

//for topological sort of a graph
void dfs(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(j=0;j<g[i].size();j++)
	{
		if(!visit[g[i][j]])
		{
			dfs(g[i][j],n);
		}
	}
	v1.pb(i);
}
//next step
//from transposed graph g1,get strongly connected components
void dfs1(ld i,ld n,ld len)
{
	visit[i] = true;
	ld j,k;
	final[len].pb(i);
	mind[len] = min(mind[len],ar[i]);
	rep(j,0,g1[i].size())
	{
		if(!visit[g1[i][j]])
		{
			dfs1(g1[i][j],n,len);
		}
	}
}

vvd dp;

int main(){
	ld N,i,j,k;
	ld W;
	cin >> N >> W;
	ld w[N],v[N];
	rep(i,0,N)
	{
		cin >> w[i] >> v[i];
	}
	dp = vvd(N+1,vd(W+1,0));
	REP(i,1,N)
	{
		REP(j,1,W)
		{
			if(j<w[i-1])dp[i][j] = dp[i-1][j];
			else dp[i][j] = max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}	

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int check = i;
    int cnt = 0;
    while (check != 0) {
      cnt += check % 10;
      check /= 10;
    }
    if (A <= cnt && cnt <= B)
      ans += i;
  }
  cout << ans << endl;
}

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

sum_list = [A[0]]
for i in range(1,N):
	sum_list.append(sum_list[i-1]+A[i])

all_sum = sum(A)
ans = 10**20
for i in range(0,N-1):
	sunuke = sum_list[i]
	araiguma = all_sum - sum_list[i]
	ans = min(ans,abs(sunuke - araiguma))

print(ans)

Measured memory_bytes: 23800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int h=a.length();
    for(int i=0;i<h;i++)
    {
        if(a[i]=='C')
        {
            for(int j=i;j<h;j++)
            {
                if(a[j]=='F')
                {
                	 cout<<"Yes";
                return 0;
				}
               
            }
        }
        else continue;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> A(N), B(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	for (int i=0; i<N; i++)
		cin>>B[i];
	int ret=0;
	ll cur=0;
	multiset<int> mst;
	for (int i=0; i<N; i++) {
		ll val=abs(A[i]-B[i]);
		if(A[i]<B[i]) cur+=val, ret++;
		else mst.insert(val);
	}
	while(!mst.empty()) {
		if(!cur) break;
		ll val=*mst.rbegin(); mst.erase(mst.find(val));
		cur-=min(cur,val); ret++;
	}
	cout<<(!cur?ret:-1)<<"\n";
	return 0;
}

Measured memory_bytes: 5376
// C - Walking Takahashi
#include <bits/stdc++.h>
using namespace std;

int main(){
	int64_t x, k, d; cin>>x>>k>>d;
	x = abs(x);
	if(x > d){
		int64_t c = min(x/d, k);
		x -= d * c;
		k -= c;
	}
	if(k%2) x = d - x;
	cout<< x <<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int t, n, h;

int main(){
	cin >> t;
	REP(i, t){
		cin >> n;
		int UP = 0, DOWN = 0, now;
		REP(j, n){
			cin >> h;
			if (j != 0){
				if (h < now){
					DOWN = max(DOWN, now - h);
				}
				else{
					UP = max(UP, h - now);
				}
			}
			now = h;
		}
		cout << UP << " " << DOWN << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
//#include <tuple>
#include <map>
#include <cmath>
#include <numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef tuple<int, int, int> T;
typedef pair<ll, ll> Pl;
//typedef tuple<ll, ll, ll> Tl;

int main() {
	vector<bool> prime(300000, false);
	vector<int> p;
	for (int i = 6; i <= 300000;) {
		if (!prime[i]) {
			p.push_back(i);
			for (int j = i+i; j <= 300000; j +=i)
				prime[j] = true;
		}
		if (i%7 == 6) i += 2;
		else i += 5;
	}
	while(true) {
		int n;
		cin >> n;
		if (n == 1) break;
		printf("%d:", n);
		for (int i = 0; i < p.size(); i++) {
			if (n % p[i] == 0) {
				printf(" %d", p[i]);
			}
		}
		printf("\n");
	}
}

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

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }
int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > task(N);
    for(size_t i = 0; i < N; i++) {
        cin >> task[i].first >> task[i].second;
    }
    sort(task.begin(), task.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    });
    long long total = 0;
    string ans = "Yes";
    for(size_t i = 0; i < N; i++) {
        total += task[i].first;
        if(total > task[i].second) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int v, e;
   std::cin >> v >> e;
   std::vector<Int> vs[2], cs(e), fs(e);
   rep(i, 2) vs[i].resize(e);
   rep(i, e) {
      std::cin >> vs[0][i] >> vs[1][i] >> cs[i];
   }
   std::vector<std::vector<Int>> es[2];
   rep(i, 2) es[i].resize(v);
   rep(i, 2) {
      rep(k, e) {
         Int s = vs[i][k];
         es[i][s].emplace_back(k);
      }
   }
   Int res = 0;
   Int source = 0, sink = v-1;
   for(;;) {
      std::queue<Int> q;
      std::vector<Int> xs(v);
      std::vector<Int> pes(v, -1);
      q.emplace(source);
      xs[source] = (Int)1 << 53;
      while( not q.empty() ) {
         Int z = q.front(); q.pop();
         rep(r, 2) {
            for(Int i : es[r][z]) {
               Int w = r ? fs[i] : cs[i] - fs[i];
               Int s = z, t = vs[1-r][i];
               guard( pes[t] == -1 );
               guard( w > 0 );
               pes[t] = i;
               xs[t] = std::min(xs[s], w);
               q.emplace(t);
            }
         }
      }
      Int f = xs[sink];
      if( f == 0 ) break;
      for(Int i = sink, k = pes[i]; i != source; i=vs[0][k]+vs[1][k]-i, k=pes[i]) {
         fs[k] += (vs[1][k] == i ? +f : -f);
      }
      res += f;
   }
   printf("%ld\n", res);
}



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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	long long mod=998244353;
	
	vector<vector<long long>> dp(c+1,vector<long long>(d+1));
	dp[a][b]=1;
	for(int i=a;i<=c;i++){
		for(int j=b;j<=d;j++){
			if(i==a && j==b) continue;
			if(i==a){
				dp[i][j]=dp[i][j-1]*i%mod;
			}else if(j==b){
				dp[i][j]=dp[i-1][j]*j%mod;
			}else{
				dp[i][j]=(dp[i-1][j]*j%mod+dp[i][j-1]*i%mod+mod-(i-1)*(j-1)%mod*dp[i-1][j-1]%mod)%mod;
			}
		}
	}
	cout << dp[c][d] << "\n";
	return 0;
}

Measured memory_bytes: 73656
def main():
    robot = int(input())
    right_lim = 0
    answer = 1
    robot_info = []
    for _ in range(robot):
        coordinate, arm_length = map(int, input().split())
        robot_info.append([coordinate - arm_length, coordinate + arm_length])
    robot_info = sorted(robot_info, key=lambda x: x[1])
    for i in range(robot):
        if i == 0:
            right_lim = robot_info[i][1]
        elif right_lim <= robot_info[i][0]:
            right_lim = robot_info[i][1]
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



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

int main(){
  set<int> KagamiMochi;
  int N;
  cin >> N;
  if(N<1 || N>100){
    return 0;
  }
  for (int i=0; i<N; ++i){
    int d;
    cin >> d;
    if(d<1 || d>100){
      return 0;
    }
    KagamiMochi.insert(d);
  }
  cout << KagamiMochi.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, a, W[2000], B[2000], DP[2001][2001], ww[2000][2001], bb[2000][2001], t[4000];
char c;

int main(){
	cin >> N;
	for (int i = 0; i != N + N; ++i) {
		cin >> c >> a;
		if (c == 'W')
			W[a - 1] = i;
		else
			B[a - 1] = i;
	}
	for (int i = 0; i != N; ++i) {
		ww[i][0] = W[i];
		for (int j = 0; j != i; ++j) {
			if (W[j] < W[i])
				--ww[i][0];
		}
		for (int j = 0; j != N; ++j) {
			ww[i][j + 1] = ww[i][j];
			if (B[j] < W[i])
				--ww[i][j + 1];
		}
	}
	for (int i = 0; i != N; ++i) {
		bb[i][0] = B[i];
		for (int j = 0; j != i; ++j) {
			if (B[j] < B[i])
				--bb[i][0];
		}
		for (int j = 0; j != N; ++j) {
			bb[i][j + 1] = bb[i][j];
			if (W[j] < B[i])
				--bb[i][j + 1];
		}
	}
	for (int i = 0; i != N + 1; ++i) {
		for (int j = 0; j != N + 1; ++j) {
			DP[i][j] = 0xe869120;
		}
	}
	DP[0][0] = 0;
	for (int i = 0; i != N + 1; ++i) {
		for (int j = 0; j != N + 1; ++j) {
			if (i != N) {
				DP[i + 1][j] = min(DP[i + 1][j], DP[i][j] + bb[i][j]);
			}
			if (j != N) {
				DP[i][j + 1] = min(DP[i][j + 1], DP[i][j] + ww[j][i]);
			}
		}
	}
	cout << DP[N][N] << endl;
}

Measured memory_bytes: 47232
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    int N;
    cin>>N;
    vector<int>a(N);
    map<int,int>ma;
    rep(i,N){
        cin>>a.at(i);
    }
    for(auto x:a){
        ma[x]++;
    }
    int count=0;
    set<int>p;
    for(auto x:a){
        if(p.count(x)){
            continue;
        }
        if(ma.at(x)>=x){
            count+=ma.at(x)-x;
        }else{
            count+=ma.at(x);
        }
        p.insert(x);
    }
    cout<<count<<endl;


    return 0;
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000


typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 3e3+5;

double arr[N];
double dp[N][N];

int n;

double solve(int idx, int num_heads)
{
    if(idx == n && num_heads > n/2)
        return 1.00;
    if(idx == n)
        return 0.00;
    double & cur = dp[idx][num_heads];
    if(cur != ((double)2.0))
        return cur;
    cur = (1-arr[idx])*solve(idx+1, num_heads) + arr[idx]*solve(idx+1, num_heads+1);
    return cur;
}

int main()
{
    cin >> n;
    lp(i, n){
        cin >> arr[i];
        lp(j, n)
            dp[i][j] = 2.0;
    }
    cout << setprecision(10);
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    int ans = 0;
    rep(i,n){
        set<char> st;
        st.insert(a[i]);
        st.insert(b[i]);
        st.insert(c[i]);
        if(st.size()==2) ans++;
        else if(st.size()==3) ans += 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  while(a>0&&c>0){
  	c-=b;
  	a-=d;
  }
  if(a<=0&&c<=0){
  	cout<<"Yes"<<endl;
  }else if(c<=0){
  	cout<<"Yes"<<endl;
  }else{cout<<"No"<<endl;}
  
}


Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<fstream>
#include<vector>
#include <algorithm>
#include <set>
#include <math.h>
using namespace ::std;
#define int long long 
vector<int > v[3], a[3];

#define INT_MAX 2100000000
signed  main()
{
	int n, k;
	cin >> n;

	v[0].resize(n);
	v[1].resize(n);
	v[2].resize(n);
	a[0].resize(n);
	a[1].resize(n);
	a[2].resize(n);
	int Mx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> v[0][i] >> v[1][i] >> v[2][i];
		Mx = max(Mx, v[0][i]);
		Mx = max(Mx, v[1][i]);
		Mx = max(Mx, v[2][i]);
	}
	a[0][0] = v[0][0];
	a[1][0] = v[1][0];
	a[2][0] = v[2][0];

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			a[j][i] = v[j][i];
			int zx = 0;
			for (int k = j + 1; k < j + 3; k++)
				zx = max(zx, a[k % 3][i - 1]);
			a[j][i] += zx;
			Mx = max(Mx, a[j][i]);
		}
	}
	cout << Mx;
	cin >> n;
}
//   aaaddda

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

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

  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int R = 1e9 + 7; 

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

    ll dp[n + 1], j = 0; dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        if (i <= 2) dp[i] = dp[i - 1] + 1;
        else dp[i] = ( dp[i - 1] + dp[i - 2] ) % R;
        if (i == a[j]) { dp[i] = 0; j++; }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1408
import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val lengths = readLine().split(' ').map(_.toInt).toSeq
  
  var maxLength: Int = 0
  val sum = lengths.foldLeft(0) { case(s, l) =>
    maxLength = if (maxLength < l) l else maxLength
    s + l
  }
  
  val result = if (maxLength < sum - maxLength) "Yes" else "No"
  println(result)
}

Measured memory_bytes: 54864
n = int(input())
ald = set()
start = input()
ald.add(start)
flag = True
for i in range(1,n):
    nword = input()
    if nword not in ald and start[-1] == nword[0]:
        ald.add(nword)
        start = nword
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

    



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int h, w; cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	vector<vector<int>> b(h, vector<int>(w));
	rep(i, h)rep(j, w)cin >> a[i][j];
	rep(i, h)rep(j, w)cin >> b[i][j];
	int ma = 0;
	rep(i, h)rep(j, w)chmax(ma, abs(a[i][j] - b[i][j]));
	ma *= (h + w); ma++;
	vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(ma, false)));
	dp[0][0][abs(a[0][0] - b[0][0])] = true;
	rep(i, h)rep(j, w)
	{
		if (i + 1 < h)
		{
			rep(k, ma)
			{
				if (dp[i][j][k])
				{
					int d = abs(a[i + 1][j] - b[i + 1][j]);
					dp[i + 1][j][k + d] = true;
					dp[i + 1][j][abs(k - d)] = true;
				}
			}
		}
		if (j + 1 < w)
		{
			rep(k, ma)
			{
				if (dp[i][j][k])
				{
					int d = abs(a[i][j+1] - b[i][j+1]);
					dp[i][j+1][k + d] = true;
					dp[i][j+1][abs(k - d)] = true;
				}
			}
		}
	}
	int ans = 0;
	rep(k, ma)
	{
		if (dp[h - 1][w - 1][k])
		{
			ans = k;
			break;
		}
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 12800
# coding: utf-8

N, M = list(map(int, input().split(' ')))
cards = [int(input().split(' ')[0]) for i in range(M)]
cards = sorted(cards)

cost = 0
for i in range(1, M):
    if cards[i] >= N: break
    cost += N - cards[i]

print(cost)



Measured memory_bytes: 5632
def pushb(n):
    if n[0] > n[1]:
        ans = n[0]
        n[0] -= 1
    else :
        ans = n[1]
        n[1] -= 1
    return ans

nlist = input().split()
nlist = [int(i) for i in nlist]

ans = 0
ans += pushb(nlist)
ans += pushb(nlist)
print(ans) 

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    vector<int> people;
    ll pre = 0,cnt = 0;;
    vector<ll> strip;
    for(int i = 0; i < n;i++){
        if(s[i] == 'L'){
            people.push_back(-1);
            if(pre != -1){
                strip.push_back(cnt);
                cnt = 0;
                pre = -1;
            }
            cnt++;
        }else{
            people.push_back(1);
            if(pre != 1){
                strip.push_back(cnt);
                cnt = 0;
                pre = 1;
            }
            cnt++;
        }
    }
    strip.push_back(cnt);
    ll ans = 0;
    
    for(int i = 1; i < strip.size();i++){
        if(strip[i] != 0){
            ans += strip[i]-1;
        }
        
    }
    if(strip.size()-1 <= 1 + (k*2)){
        cout << n-1 << endl;
        return 0;
    }
    cout << ans + (k*2) << endl;

    return 0;
}

Measured memory_bytes: 1860
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int MAXN = 2e5 + 1;
vector<int> adj[MAXN];
int cnt[MAXN];

void dfs(int u, int p) {
	cnt[u] += cnt[p];
	for (int v : adj[u]) {
		if (v == p) continue;
		dfs(v, u);
	}
}

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

	int n, q;
	cin >> n >> q;

	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	while (q-- > 0) {
		int p, x;
		cin >> p >> x;
		cnt[p] += x;
	}

	dfs(1, 0);
	for (int u = 1; u <= n; u++) cout << cnt[u] << ' ';
	cout << endl;
}


Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	long long int X,Y; 
	cin >> X >> Y;
	long long int a = Y/X;
	int b = 1;
	while(a>1){
        a = a/2;
	b=b+1;
}
		cout << b << endl;
return 0;
    }

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

int main(){
	string o;
	cin>>o;
	int n=0,s=0,w=0,e=0;
	rep(i,o.size()){
		if(o[i]=='N')n++;
		else if(o[i]=='S')s++;
		else if(o[i]=='W')w++;
		else if(o[i]=='E')e++;
	}
	if(((n>0&&s>0)||(s==0&&n==0))&&((e>0&&w>0)||(e==0&&w==0)))puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int mod = 998244353;

long long dp[3001][3001];

int main() {
    int a, b, c, d, i, j;
    
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    dp[a][b] = 1;
    for (i = a; i <= c; i++) {
        for (j = b; j <= d; j++) {
            if (i == a && j == b) continue;
            dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i) % mod;
            dp[i][j] -= dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod;
            if (dp[i][j] < 0) dp[i][j] += mod;
        }
    }
    
    printf("%lld\n", dp[c][d]);
    
    return 0;
}


Measured memory_bytes: 72000
# include <bits/stdc++.h>
# define f first
# define s second
using namespace std;
const int N = 1e6;
long long n, x, y, ans;
pair <long long, long long> a[N],b[N];
int main()
{
      scanf("%lld", &n);
      for(int i = 1;i <= n;i ++)
      {
             scanf("%lld %lld", &a[i].f, &a[i].s);
             if(a[i].f > a[i].s)
                 swap(a[i].s, a[i].f);
             b[i].f = a[i].s;
             b[i].s = a[i].f;
      }

      sort(b + 1, b + n + 1);
      sort(a + 1, a + n + 1);

      ans = (a[n].f - a[1].f) * (b[n].f - b[1].f);
      long long r = a[n].f;
      long long l = 1e9;
      for(int i = 1;i < n;i++)
      {
             l = min(a[i].s, l);
             r = max(r, a[i].s);
             ans = min(ans, (b[n].f - a[1].f) * (r - min(l, a[i + 1].f)));
      }
      printf("%lld\n",ans);
}

Measured memory_bytes: 10496
N, K = map(int, input().split())
MOD = 10 ** 9 + 7


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


def f(x, mod):
    if K - 1 < x - 1:
        return 0
    else:
        return mod_cmb(N - K + 1, x, mod) * mod_cmb(K - 1, x - 1, mod) % mod


for i in range(1, K + 1):
    print(f(i, MOD))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int D,N;
    cin >> D >> N;
    if(N==100) N++;
    if(D==0){
        cout << N <<endl;
    }else if(D==1){
            cout << N*100 <<endl;
    }else {
        cout << N*10000 << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int solve(int n, int x, int mod, const vi &d, int m){
	ll sum = 0;
	int res = n - 1;
	rep(i, m){
		int r = d[i] % mod, k = (n - 2 + m - i) / m;
		sum += (ll)k * r;
		if(!r) res -= k;
	}
	res -= (sum + x) / mod - x / mod;
	return res;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int k, q; cin >> k >> q;
	vi d(k);
	rep(i, k) cin >> d[i];
	
	rep(it, q){
		int n, x, m; cin >> n >> x >> m;
		cout << solve(n, x, m, d, k) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let abc = read_vec::<u64>();
    let (a,b,c) = (abc[0],abc[1],abc[2]);
    for j in 0..b+1{
        if (a*j ) % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO")
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll N, P;
int c[3];

int main() {
    string s;
    cin >> s;
    REP(i, s.size())c[s[i] - 'a']++;
    REP(i, 3) {
        REP(j, 3) {
            REP(k, 3) {
                if (i == j || j == k || i == k)continue;
                vector<int> v(3), b(3);
                b[0] = i, b[1] = j, b[2] = k;
                int p = 0;
                REP(u, s.size()) {
                    if (p > 2)p = 0;
                    v[b[p++]]++;
                }
                bool yes = true;
                REP(u, 3) if (v[u] != c[u])yes = false;

                if (yes) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstring>
#include <cctype>
#include <iostream>
#include <cstdio>
using namespace std;

int exp(char* & p);

int num(char* & p) {
    int ret = 0;
    while (isdigit(*p)) {
        ret *= 10;
        ret += *p - '0';
        p++;
    }
    return ret;
}

int fac(char* & p) {
    int ret = 0;
    if (*p == '(') {
        p++;
        ret += exp(p);
        p++;
    } else {
        ret += num(p);
    }
    return ret;
}

int term(char* & p) {
    int ret = fac(p);
    while(1) {
        if (*p == '*') {
            p++;
            ret *= fac(p);
        } else if (*p == '/') {
            p++;
            ret /= fac(p);
        } else {
            break;
        }
    }
    return ret;
}

int exp(char* & p) {
    int ret = term(p);
    while(1) {
        if (*p == '+') {
            p++;
            ret += term(p);
        } else if (*p == '-') {
            p++;
            ret -= term(p);
        } else break;
    }
    return ret;
}

int eval(const string & s){
    char* p = (char*)s.c_str();
    return exp(p);
}

int eval(const char* str){
    char* p = (char*)str;
    return exp(p);
}

using namespace std;

int main(){
  int n; cin >> n;
  cin.ignore();
  while(n--){
    char str[128];
    gets(str);
    cout << eval(str) << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5],k;
    for(int i=0;i<5;i++)
    cin>>a[i];
    cin>>k;
    bool res=false;
    for(int i=1;i<5;i++){
        if(a[i]-a[0]>k) res=true;
    }
    if(!res) cout<<"Yay!";
    else cout<<":(";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int ketanowa(int n){
        int ans = 0;
        while(n >= 10){
                ans += n%10;
                n /= 10;
        }
        return ans+n;
}
int min(int a, int b){return(a<b)?a:b;}
int main(){
        int N;
        scanf("%d",&N);
        int minans = 100;
        for(int i = 1; i < N; i++){
                minans = min(minans, ketanowa(i)+ketanowa(N-i));
        }
        printf("%d\n",minans);
}

Measured memory_bytes: 128
#copy for experience
# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)


Measured memory_bytes: 3440
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let H = get!(Vec<i64>);

    // 左のマスから貪欲になるべくマスの高さを小さくすればよい
    let ans = match H.iter()
        .fold(
            (true, 0),
            |(res, x), &h| {
                (
                    res && x <= h,
                    if x < h {
                        h - 1
                    } else {
                        h
                    }
                )
            }
        ) {
            (true, _) =>  "Yes",
            (false, _) => "No"
        };

    println!("{}", ans);
}


Measured memory_bytes: 8444
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
int a,b,c,k;
int main(){
    read(a),read(b),read(c),read(k);
    int ans=min(a,k);k-=a;
    k-=b;
    if(k>=0)ans-=k;
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3632
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  VI A(3);
  REP(i, 3) {
    cin >> A[i];
  }

  int ans = INF;
  REP(i, 3) {

    int cnt = 0;
    REP(j, 2) {
      int p = (j + i + 1) % 3;
      if (A[p] - A[i] <= 0) {
        cnt += (A[i] - A[p]) / 2 + (A[i] - A[p]) % 2 * 2;
      } else {
        cnt += A[p] - A[i];
      }
    }
    ans = min(ans, cnt);
  }

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

Measured memory_bytes: 256
<?php

$line = fgets(STDIN);

$lines = explode(" ", $line);

$lines[0] = trim($lines[0]);
$lines[1] = trim($lines[1]);

while(True){
    if($lines[0] < $lines[1]){
        $tmp = $lines[0];
        $lines[0] = $lines[1];
        $lines[1] = $tmp;
    }
    
    if($lines[0] % $lines[1] == 0){
        echo $lines[1];
        break;
    }else{
        $lines[0] = $lines[0] % $lines[1];
    }
}

?>

Measured memory_bytes: 15456
import scala.io.StdIn
object Main extends App {
  main()
  def main() {
    val in = StdIn.readLine()
    val even = "RUD"
    val odd = "LUD"
    for ((c, i) <- in.zipWithIndex) {
      if ((i % 2 == 0 && !even.contains(c)) || (i % 2 != 0 && !odd.contains(c))) {
        println("No")
        return
      }
    }
    print("Yes")
  }
}


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

#define rep(i,n) for(ll i=0;i<ll(n);++i)
#define repr(i,n) for(ll i=ll(n);i-->0;)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

namespace ate{
  using i64 = int64_t;
  std::tuple<i64,i64,i64> ext_gcd(i64 a,i64 b){
    if(b==0){
      return {a,1,0};
    }
    auto [d,y,x] = ext_gcd(b,a%b);
    y -= a/b * x;
    return {d,x,y};
  }
  std::pair<i64,i64> crt1(i64 b1,i64 m1,i64 b2,i64 m2){
    auto [d,p,q] = ext_gcd(m1,m2);
    if((b2-b1)%d)return {0,-1};
    i64 lcm_m = m1/d*m2;
    i64 s = (b2-b1)/d;
    i64 x = b1+s*m1*p;
    return {x,lcm_m};
  }
  std::pair<i64,i64> crt(std::vector<i64> const& b,std::vector<i64> const& m){
    assert(std::size(b)==std::size(m));
    i64 r = 0, lcm_m = 1;
    for(int i=0;i<std::size(b);++i){
      auto const& b_i = b[i], m_i = m[i];
      auto [d,p,q] = ext_gcd(lcm_m,m_i);
      if((b_i-r)%d)return {-1,-1};
      i64 tmp = (b_i-r)/d*p%(m_i/d);
      r += lcm_m*tmp;
      lcm_m *= m_i/d;
    }
    r = (r%lcm_m+lcm_m)%lcm_m;
    return {r,lcm_m};
  }
}

std::vector<int64_t> divisor(int64_t n){
  std::vector<int64_t> div;
  for(int64_t p=1;p*p<=n;++p){
    if(n%p==0){
     div.push_back(p);
     if(p*p!=n)div.push_back(n/p);
    }
  }
  std::sort(div.begin(),div.end());
  return div;
}

signed main(){

  ll n;
  cin>>n;
  ll ans = INF;
  for(ll x:divisor(2*n)){
    ll y = 2*n/x;
    auto[k,mod] = ate::crt1(0,x,-1,y);
    if(k>0)chmin(ans,k);
    if(k<0)chmin(ans,k+mod);
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll n;
    cin >> n;
    ll a = n%10;
    if(a==2||a==4||a==5||a==7||a==9)
        cout << "hon" << endl;
    else if(a==0||a==1||a==6||a==8)
        cout << "pon" << endl;
    else if(a==3)
        cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3632
# ITP1_11_B: Dice 2

class Dice
  Side = Struct.new :neighbors

  module Dir
    TOP    = 0
    RIGHT  = 1
    BOTTOM = 2
    LEFT   = 3
  end

  class << self
    #     n
    # w center e (back)
    #     s
    def layout_sides(labels, center, n, e, s, w)
      back = ( labels - [center, n, e, s, w] ).first
      Hash.new.tap do |sides|
        sides[center] = Side.new [n, e, s, w]
        sides[back]   = Side.new [s, e, n, w]
        sides[n]      = Side.new [center, w, back, e]
        sides[e]      = Side.new [center, n, back, s]
        sides[s]      = Side.new [center, e, back, w]
        sides[w]      = Side.new [center, s, back, n]
      end
    end
  end

  def initialize(
    labels,
    upper_side = labels[0],
    neighbors  = [ labels[4], labels[2], labels[1], labels[3] ]
  )
    @sides      = Dice.layout_sides labels, upper_side, *neighbors
    @upper_side = upper_side
    @neighbors  = neighbors
  end

  def upper_side
    @upper_side
  end

  def number_on(dir_id)
    @neighbors[dir_id]
  end

  def roll_to(direction)
    dir_id      = dir_to_id direction
    next_side   = opposite_side dir_id
    @neighbors  = spin_neighbors_of next_side, @upper_side, dir_id
    @upper_side = next_side
    self
  end

  def change_upper(center, top)
    @neighbors  = spin_neighbors_of center, top
    @upper_side = center
    self
  end

  def opposite_side(dir_id)
    di_rid = (dir_id + 2) % @neighbors.size
    @neighbors[di_rid]
  end

  private

  # Rotate the neighbors of +center+.
  def spin_neighbors_of(center, a_side, dir_id = 0)
    neighbors = @sides[center].neighbors
    org_dir   = neighbors.index(a_side)
    step = (org_dir - dir_id) % neighbors.size
    neighbors.map.with_index do |n, idx|
      neighbors[ (idx + step) % neighbors.size ]
    end
  end

  def dir_to_id(dir_id)
    case dir_id
    when 'N' then Dir::TOP
    when 'E' then Dir::RIGHT
    when 'S' then Dir::BOTTOM
    when 'W' then Dir::LEFT
    end
  end
end


labels  = gets.chomp.split.map &:to_i
dice    = Dice.new labels
n_pairs = gets.to_i

n_pairs.times do
  top, center = gets.chomp.split.map &:to_i
  puts dice.change_upper(center, top).number_on(Dice::Dir::RIGHT)
end

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

int main()
{
	int a, b;
	
	
	cin >> a >> b;
		
	if (a < b)
	{
		cout << "a < b"<< endl;
	}
	else if (a > b)
	{
		cout << "a > b" << endl;
	}
	else if (a == b)
	{
		cout << "a == b" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3088
N=int(input())
flag=True

for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h !=0:
      if (N*h*n)%(4*h*n-N*n-N*h)==0:
        w=(N*h*n)//(4*h*n-N*n-N*h)
        if w>0:
          print(h,n,w)
          flag=False
          break
  if flag==False:
    break

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

main() {
    string S; cin >> S; bool can=true;
    map<char,int>m;
    rep(i,S.size()){
        m[S[i]]++;
    }
    for(auto p:m){
        if(p.second%2==1) {can = false; break;}
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	string s, t;
	cin >> n >> s >> t;
	rep (i, n) cout << s[i] << t[i];
	cout << endl;
    
    return 0;
}



Measured memory_bytes: 3660