akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use proconio::marker::Chars;
use std::collections::HashSet;
use std::iter::Iterator;

fn main() {
    input! {
    a: i64,
    b: i64,
    c: i64,
    k: i64,
    }

    let mut ans = 0;
    let mut zan = 0;

    if a < k {
        ans = ans + a;

        zan = k - a;
        if b < zan {
            ans = ans;
            zan = zan - b;
            if c < zan {
                ans = zan - c;
            } else {
                ans = ans - zan;
            }
        } else {
            ans = ans;
        }
    } else {
        ans = 1 * k;
    }

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


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

// 最大公約数
int64_t gcd(int64_t x, int64_t y) {
    if (x < y) swap(x, y);
    while (y > 0) {
        int64_t r = x % y;
        x = y;
        y = r;
    }
    return x;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
    return (a * b) / gcd(a, b);
}

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

    int64_t A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = new int[N + 2];
        A[0] = 0;
        for (int i = 1; i <= N; i++)
        {
            A[i] = cin.nextInt();
        }
        A[N + 1] = 0;

        int[] l = new int[N + 2];
        int[] r = new int[N + 2];

        for (int i = 1; i < N + 2; i++)
        {
            l[i] = l[i - 1] + Math.Abs(A[i] - A[i - 1]);
            r[N + 1 - i] = r[N + 2 - i] + Math.Abs(A[N + 1 - i] - A[N + 2 - i]);
        }

        for (int i = 1; i <= N; i++)
        {
            Console.WriteLine(l[i - 1] + r[i + 1] + Math.Abs(A[i + 1] - A[i - 1]));
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 24668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		if (a + b >= c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		scanner.close();

	}

}


Measured memory_bytes: 21844
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())

int main(){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]) count++;
    }
    cout<<count<<endl;


}



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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int d, t, s;
    cin >> d >> t >> s;

    if (d <= t * s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3648
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
string st,stt;
int i=0;
int main()
{   
    cin>>st>>stt;
    if(st.size()!=stt.size())
	{
	for(i=0;i<st.size()-1;i++)
    {
    	cout<<st[i]<<stt[i];
    }
	cout<<st[i];	
	}
	else
	{
	for(i=0;i<st.size();i++)
    {
    	cout<<st[i]<<stt[i];
    }	
	}
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    hs = list(map(int, input().split(" ")))
    dps = [0] * N

    dps[0] = 0
    dps[1] = abs(hs[1] - hs[0])
    for i in range(2, N):
        dps[i] = min(dps[i-1]+abs(hs[i]-hs[i-1]), dps[i-2]+abs(hs[i]-hs[i-2]))
    
    print(dps[-1])

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 52108
//
// Created by rajshah9914 on 29/03/20.
//

#include <bits/stdc++.h>
using namespace std;
vector<long long>adj[100001];
stack<long long>s,tt,temp;
//vector<long long>visited(100000,0);
set<long long>visited;

void topo(long long u)
{
    visited.insert(u);
    for(long long i:adj[u])
    {
        if(visited.find(i)==visited.end())
            topo(i);
    }
    s.push(u);
//    tt.push(u);
}
//
set<long long>vis;
void dfs(long long u)
{
    vis.insert(u);
    for(long long i:adj[u])
    {
        if(vis.find(i)==vis.end())
            dfs(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
   long long n,m;
   cin>>n>>m;
   long long x,y;
   long long sx;
   long long mum=m-1;
   for(;m--;)
   {
       cin>>x>>y;
       adj[x].push_back(y);
   }
   vector<long long>p;
   for(long long i=0;i<=n;i++)
   {
       if(vis.find(i)==vis.end())
       {
           p.push_back(i);
           dfs(i);
       }
   }
//   for(int i=0;i<p.size();i++)
//       cout<<p[i]<<" ";
//   cout<<endl;
   for(long long i=0;i<p.size();i++)
   {
       if(p[i]!=0)
       adj[0].push_back(p[i]);
   }
   for(long long i=0;i<=n;i++)
   {
       if(visited.find(i)==visited.end())
           topo(i);
   }
   long long dist[1000000];
   long long ans=0,q=1;
   for(long long i=0;i<=n;i++)
       dist[i]=INT_MIN;
   dist[0]=0;
   while(!s.empty())
   {
       long long top=s.top();
       s.pop();
       if(dist[top]!=INT_MIN)
       {
           for(long long x:adj[top])
           {
               if(dist[x]<dist[top]+1)
                   dist[x]=dist[top]+1;
           }
       }
   }
    for(long long i=0;i<=n;i++)
    ans=max(ans,dist[i]);
    cout<<ans-1<<endl;
}

Measured memory_bytes: 21248
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define pb push
#define mp make_pair
#define X first
#define Y second
#define Mad(a,b) a=(a+b)%mod;
typedef long long ll;

using namespace std;
typedef pair<ll,ll> P;
queue<P> Q;
#define N 3010
ll n,m,d[N];string s;
int main(){
    cin>>n>>m>>s;
    Q.pb(mp(0,0));
    while(m--){
	ll a,b;cin>>a>>b;
	if(Q.back().Y<b)Q.pb(mp(a,b));
    }
    lol(i,N)d[i]=0;d[0]=1;
    for(ll i=0,rnd=0;i<=n;i++){
	ll cnt=0;
	while(!Q.empty()){
	    if(not(Q.front().X<=i))break;
	    for(ll j=max(i-1,rnd);j<Q.front().Y;j++)cnt+=s[j]-'0';
	    rnd=Q.front().Y;Q.pop();
	}
	for(ll j=N-1;j>=0;j--)d[j]=(j-cnt>=0?d[j-cnt]:0);
	ll lim=max(0LL,rnd-i);
	for(ll j=0;j<=lim;j++)Mad(d[j],d[j+1]);
	for(ll j=lim+1;j<N;j++)d[j]=0;
    }
    cout<<d[0]<<endl;
    return 0;
}


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

int main()
{
    int x, y, i;
    bool flag = false;
    cin >> x >> y;

    for (i = 0; i <= x; i++)
    {
        if (2 * i + 4 * (x - i) == y)
        {
            flag = true;
            break;
        }
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3676
using System;

namespace ABC119A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            DateTime dateTime  = DateTime.Parse(S);
            DateTime threshold  = DateTime.Parse("2019/04/30");
            if (dateTime.CompareTo(threshold) > 0)
            {
                Console.WriteLine("TBD");
                return;
            }
            Console.WriteLine("Heisei");
        }
    }
}

Measured memory_bytes: 11616
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll poc(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
bool cmp(ppll a,ppll b){
    return a.first.first+a.first.second<b.first.first+b.first.second;
}
int main(){
    //ios::sync_with_stdio(false);cin.tie(0);
    ll n;scanf("%lld",&n);
    vector<ppll> v;
    rep(i,0,n){
        ll w,s,vv;scanf("%lld %lld %lld",&w,&s,&vv);
        v.push_back({{s,w},vv});
    }
    sort(v.begin(),v.end(),cmp);
    ll dp[20001];
    fill(dp,dp+20001,-inf);
    ll ans=0;
    dp[0]=0;
    rep(i,0,n){
        ll s=v[i].first.first,w=v[i].first.second,co=v[i].second;
        rrep(j,s,0){
            ll ne=j+w;
            Max(dp[ne],dp[j]+co);
            
        }
    }
    rep(i,0,20001)Max(ans,dp[i]);
    printf("%lld",ans);
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  int ans = 0;
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  sort(a.begin(), a.end());
  for (int i = 0 ; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
        if (a[i] + a[j] > a[k]) {
          ans++;
          //cout << a[i] << " " << a[j] << " " << a[k] << "\n";
        }
      }
    }
  }
  cout << ans << "\n";
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int h, w, n, sr, sc;
  string s, t;
  cin >> h >> w >> n >> sr >> sc >> s >> t;

  bool ok = true;
  {
    int x = sc;
    rep(i, 0, n) {
      if(s[i] == 'L') x--;
      if(x == 0) ok = false;
      if(t[i] == 'R' && x + 1 <= w) x++;
    }
  }
  {
    int x = sc;
    rep(i, 0, n) {
      if(s[i] == 'R') x++;
      if(x == w + 1) ok = false;
      if(t[i] == 'L' && x - 1 >= 1) x--;
    }
  }
  {
    int y = sr;
    rep(i, 0, n) {
      if(s[i] == 'U') y--;
      if(y == 0) ok = false;
      if(t[i] == 'D' && y + 1 <= h) y++;
    }
  }
  {
    int y = sr;
    rep(i, 0, n) {
      if(s[i] == 'D') y++;
      if(y == h + 1) ok = false;
      if(t[i] == 'U' && y - 1 >= 1) y--;
    }
  }
  if(ok) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 920
n=int(input())
i=0
while True:
    j=0
    if i*4+j*7>n:
        break
    while True:
        if i*4+j*7==n:
            print("Yes")
            exit()
        j+=1
        if i*4+j*7>n:
            break
    i+=1

print("No")


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

int N;
const int MAX_N = 1.0e5 + 10;
int a[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];

    int odd = 0;
    int two = 0;
    int four = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] % 4 == 0) {
            four++;
        }
        else if (a[i] % 2 == 0) {
            two++;
        }
        else {
            odd++;
        }
    }

    if (two == 0) {
        if (four >= odd - 1) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (four >= odd) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long inf = 1ll << 61;
int a[200006];
string res[] = { "Second","First" };
int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	if (n % 2) {
		int e = 0;
		rep(i, n)if (!(a[i] & 1))e++;
		if (e & 1)cout << res[e & 1] << endl;
		else {
			int cnt = 0;
			while (n - e == 1) {
				int C;
				rep(i, n) {
					if (a[i] & 1) {
						C = a[i]; a[i]--;
					}
				}

				if (C == 1) {
					cout << res[(e + cnt) & 1] << endl; return 0;
				}

				int g = a[0];
				rep(i, n)g = gcd(g, a[i]);
				rep(i, n)a[i] /= g;
				e = 0;
				rep(i, n)if (!(a[i] & 1))e++;
				cnt++;
			}
			cout << res[(e+cnt) & 1]<<endl;
		}
	}
	else {
		int s = 0;
		rep(i, n)s += a[i];
		cout << res[s & 1] << endl;
	}
}

Measured memory_bytes: 1024
local mfl = math.floor
local function getor(x, y)
  local ret = 0
  local mul = 1
  while(0 < x or 0 < y) do
    if((x % 2) + (y % 2) ~= 0) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end

local n, m = io.read("*n", "*n")
local tot = 1
for i = 1, n do
  tot = tot * 2
end
local t = {}
for i = 1, tot do
  t[i] = -1
end
t[1] = 0
for i = 1, m do
  local a, b = io.read("*n", "*n")
  local c = {}
  for j = 1, b do
    c[io.read("*n")] = true
  end
  local val = 0
  local v = 1
  for j = 1, n do
    if c[j] then
      val = val + v
    end
    v = v * 2
  end
  for src = tot, 1, -1 do
    if 0 <= t[src] then
      local dst = 1 + getor(src - 1, val)
      if t[dst] == -1 or t[src] + a < t[dst] then
        t[dst] = t[src] + a
      end
    end
  end
end
print(t[tot])


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a;
  int x,y,z,w;
  w=100000000;
  z=2;
  x=0;
  y=0;
  //----------------------------------------
   for (int i=0;i<n;i++){
     cin >> a;
     x=a;
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     while (x%2==0 && x!= 0){
       x=x/2;
       y++;
     }
  
        z=y;
    if (w<=z){
      w=w;
    }
    else {
      w=z;
    }
   
     y=0;
     //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   }
   //--------------------------------------
   
    cout << w << endl;
 
}

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


def solve(a: int, s: str):
    if(a >= 3200):
        print(s)
    else:
        print('red')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(a, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <queue>
using namespace std;
int main(){
	long long n;
        int x;
	cin>>n;
	if(n%2==1||n==0){
		cout<<0<<endl;
	}else{
		long long ans=0;
		ans+=n/10;
		n/=10;
		while(n){
			ans+=n/5;
			n/=5;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


#define MAX_N 1000000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
int par[MAX_N],dep[MAX_N];//depはrankのこと
//n要素で初期化
void init(int n){
    for(int i=0;i<=n-1;i++){
        par[i]=i;
        dep[i]=0;
    }
}
//木の根を求める
int find(int x){
    return par[x]==x?x:par[x]=find(par[x]);
}
//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(dep[x]<dep[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(dep[x]==dep[y])dep[x]++;
    }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}
//////////////////////////////////////
struct edge{int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}
vector<edge>es;
int v;//頂点数v
ll kruskal(){
    sort(es.begin(),es.end(),comp);
    init(v);
    int res=0;
    for(auto e:es){
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}
///////////////////////////////////////////

int main(){
    ll e;cin>>v>>e;
    while(e--){
        edge f;cin>>f.u>>f.v>>f.cost;
        es.pb(f);
    }
    cout<<kruskal()<<endl;
    return 0;
}


Measured memory_bytes: 4568
from collections import Counter
N = int(input())
S = input()
conS = Counter(S)
NuE = conS['E']
NuW = conS['W']
def Change(x,lefW,rigE):
    if x == 'W':
        return lefW + rigE -1
    else:
        return lefW + rigE
lefW = 0
rigE = NuE
Ans = N
for i in S:
    if i == 'E':
        rigE -= 1
    else:
        lefW += 1
    Ans = min(Ans, Change(i,lefW,rigE))
print(Ans)

Measured memory_bytes: 9868
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
#define MAXN 105
int a[MAXN];
lli dp[MAXN][100005];
int main(){__
	int n,k;
	cin >> n >> k;
	for(int i=1; i <=n; i++) cin >> a[i];
	dp[0][k] = 1ll;
	for(int i=1; i <= n; i++){
		lli sum = 0ll;
		for(int j =k,tam =0; j >=0; tam++,j--){
			sum = ( sum + dp[i-1][j] ) % mod;
			if(tam > a[i]){
				sum = (sum + mod - dp[i-1][j+a[i]+1]) % mod;
			}
			dp[i][j] = sum % mod;
		}
	}
	cout << dp[n][0]% mod << endl;
	return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <time.h>
#include <assert.h>


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

    ll n;
    cin>>n;
    string s[n];
    ll c1=0,c2=0,c3=0,c4=0;
    For(i,0,n){
        cin>>s[i];
        if(s[i]=="AC")
            c1++;
        if(s[i]=="WA")
            c2++;
        if(s[i]=="TLE")
            c3++;
        if(s[i]=="RE")
            c4++;
    }
    cout<<"AC x "<<c1<<"\n";
    cout<<"WA x "<<c2<<"\n";
    cout<<"TLE x "<<c3<<"\n";
    cout<<"RE x "<<c4<<"\n";
    // cout<<c1<<" "<<c2<<" "<<c3<<" "<<c4;

    
    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 1001, M = 31;

int n, x[N], y[N];

long long my_abs (long long x) {
	return x > 0 ? x : -x;
}
bool check () {
	for (int i = 1; i < n; i++) {
		if (((1ll << M) + x[i] + y[i]) % 2 != ((1ll << M) + x[n] + y[n]) % 2) return false;
	}
	return true;
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);

	if (!check()) printf("-1\n");
	else {
		if (((1ll << M) + x[n] + y[n]) % 2 == 0) printf("%d\n1 ", M + 1);
		else printf("%d\n", M);
		for (int i = 0; i < M; i++) printf("%lld ", 1ll << i);
		printf("\n");
		for (int i = 1; i <= n; i++) {
			string ans;
			bool even = (((1ll << M) + x[i] + y[i]) % 2 == 0);
			if (even) x[i]--;

			for (int j = M - 1; j >= 0; j--) {
				long long len = 1ll << j;
				if (my_abs(x[i] - len) + my_abs(y[i]) < len) {
					ans = 'R' + ans;
					x[i] -= len;
				}
				else if (my_abs(x[i] + len) + my_abs(y[i]) < len) {
					ans = 'L' + ans;
					x[i] += len;
				}
				else if (my_abs(x[i]) + my_abs(y[i] - len) < len) {
					ans = 'U' + ans;
					y[i] -= len;
				}
				else if (my_abs(x[i]) + my_abs(y[i] + len) < len) {
					ans = 'D' + ans;
					y[i] += len;
				}
			}

			if (even) ans = 'R' + ans;
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
M,D = map(int,input().split())

ans = 0
for m in range(1,M+1):
    for d in range(1,D+1):
        if d <10:
            continue
        sd = str(d)
        if int(sd[1]) >= 2 and int(sd[0]) >= 2:
            if int(sd[0])*int(sd[1]) == m:
                ans+=1
print(ans)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    String s1 = s.substring(0,1);
    String s2 = s.substring(1,2);
    String s3 = s.substring(2,3);

    if (s1.equals(s2) || s1.equals(s3) || s2.equals(s3)) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }

  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int res = 0;
    int red = 0;
    vector<int> R;
    vector<int> W;
    rep(i,S.size()) {
        if (S[i] == 'R') {
            red++;
            R.emplace_back(i);
        } W.emplace_back(i);
    }
    int j = 0;
    for (auto i : R) {
        if (i < red) continue;
        int w = W[j];
        swap(S[j], S[i]);
        res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 5200
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin>>s;
	long long N=s.length();
	for(int i=0;i<N-1;i++){
		if(s[i]==s[i+1]){
				cout<<i+1<<endl;
				cout<<i+2<<endl;
				return 0;
		}
		if(i+2<N)
		if(s[i]==s[i+2]){
			cout<<i+1<<endl;
			cout<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	cout<<-1<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int k,l,c=0,p=1;
    string s,t[30000];
    cin>>s>>k;
    l=s.length();
    for(int i=0;i<l;i++){
        for(int j=1;j+i<=l&&j<=5;j++){
            t[c]=s.substr(i,j);
            c++;
        }
    }
    sort(t,t+c);
    for(int i=1;i<=c;i++){
        
        if(p==k){
            cout<<t[i-1]<<endl;
            return 0;
        }else if(t[i]!=t[i-1]){
            //cout<<"["<<p<<"] : "<<t[i-1]<<endl;
            p++;
        }
        
    }
}


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, ll>a,pair<ll,ll>b)
{
    return a.fi>=b.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n; cin>>n;
vi arr(n);
rep(i,0,n)cin>>arr[i];
sort(all(arr),greater<ll>());
ll ans = arr[0];
ll cnt = 1;
ll pos = 1;
n--;
for(ll i =2;i<=n;)
{
    if(i+1<=n)
    {
        ans+=2*arr[pos];
        i+=2;
    }
    else
    {
        ans+=arr[pos];
        i++;
    }
    pos++;
}
cout<<ans<<endl;
return 0;

}
/*
1
8
1 7 3 4 7 6 2 9
*/


Measured memory_bytes: 4764
# coding: utf-8

n = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
kyoukaisen = a_sum /2
left = 0

for i in range(len(a)):
    left += a[i]
    
    if left >= kyoukaisen:
        print(min(abs(a_sum - 2*left),abs( (a_sum - (left-a[i])) - (a_sum-(a_sum - (left-a[i])))) ))
        break

Measured memory_bytes: 26060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <limits.h>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int count = 0;
    for (int i=0; i<S.length(); ++i) {
        auto c = S[i];
        if (c == '+') {
            ++count;
        }
        else {
            --count;
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 760
import math
n = int(input())

ans = {}
for x in range(1,int(math.sqrt(n+1))+1):
    for y in range(1, x+1):
        for z in range(1, y+1):
            k = pow(x, 2) + pow(y, 2) + pow(z, 2) + x*y + x*z + y*z

            if k >n:
                break
            if len(set([x,y,z])) == 3:
                num = 6
            elif len(set([x,y,z])) == 2:
                num = 3
            else:
                num = 1
            if not k in ans:
                ans[k] = num
            else:
                ans[k] += num

for i in range(1, n+1):
    if i in ans:
        print(ans[i])
    else:
        print(0)

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

int INF = 1001001001;
int comp = 0;

void mergex(vector<int> &A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1+1), R(n2+1);
    rep(i, n1){
        L[i] = A[left+i];
    }
    rep(i, n2){
        R[i] = A[mid+i];
    }
    L[n1] = INF;
    R[n2] = INF;

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++){
        if (L[i] <= R[j]){
            A[k] = L[i];
            i += 1;
            comp++;
        } else {
            A[k] = R[j];
            j += 1;
            comp++;
        }
    }
    return;
}

void mergexSort(vector<int> &A, int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergexSort(A, left, mid);
        mergexSort(A, mid, right);
        mergex(A, left, mid, right);
    }
    return;
}

int main() {
    int n; cin >> n;
    vector<int> S(n);
    rep(i, n){
        cin >> S[i];
    }

    mergexSort(S, 0, n);
    rep(i, n){
        cout << S[i];
        if(i == n-1){
            cout << endl;
        } else {
            cout << " ";
        }
    }

    cout << comp << endl;
}


Measured memory_bytes: 6788
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

vector<int> v(3);
pair<int, int> get(const string& s) {
    if (s == "AB") return {0, 1};
    else if (s == "BC") return {1, 2};
    else return {2, 0};
}

char id2str(int i) {
    vector<char> c = {'A', 'B', 'C'};
    return c[i];
}


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

    int N;
    cin >> N;
    REP(i, 3) cin >> v[i];

    vector<string> s(N);
    REP(i, N) cin >> s[i];

    vector<int> ans;
    REP(i, N) {
        int k, l;
        tie(k, l) = get(s[i]);

        if (v[k] == 0 && v[l] == 0) {
            print("No");
            return 0;
        }

        if (v[k] > v[l]) swap(k, l);
        
        if (i == N - 1) {
            ans.pb(k);
            break;
        }

        if (s[i] == s[i + 1]) {
            ans.pb(k);
            v[k]++;
            v[l]--;
            continue;
        } else {
            if (v[k] == 0) {
                ans.pb(k);
                v[k]++;
                v[l]--;
                continue;
            }

            int n0, n1;
            tie(n0, n1) = get(s[i + 1]);

            if (l == n0 || l == n1) {
                ans.pb(l);
                v[l]++;
                v[k]--;
            } else if (k == n0 || k == n1) {
                ans.pb(k);
                v[k]++;
                v[l]--;
            }
        }
    }
    
    print("Yes");
    REP(i, N) print(id2str(ans[i]));


}


Measured memory_bytes: 7028
n,m = map(int,input().split(' '))
aa = list(map(int, input().split(' ')))
A = sorted(aa, reverse=True)
Am = A[:m]
for a in Am:
    if a>=(0.25/m)*sum(aa): continue
    else:
         print('No')
         exit(0)
print('Yes')
         

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    int N;
    cin>>N;
   vector<tuple<string,int,int>> A(N);
    rep(i,N){
        cin >> get<0>(A[i]) >> get<1>(A[i]) ;
        get<2>(A[i]) = i + 1;
        get<1>(A[i]) *= -1;
    }
    sort(A.begin(),A.end());
    rep(i,N){
        cout<<get<2>(A[i])<<endl;
    }
}



Measured memory_bytes: 3640
#include <iostream>
using namespace std;
#define ll long long int
const ll mod = 1e9 + 7;
int main(){
    ll ans = 0;
    ll n, k;
    cin >> n >> k;
    for(ll i = k; i <= n + 1; ++i){
        ll l, r;
        l = (i - 1) * i / 2;
        r = (2 * n - i + 1) * i / 2;
        ll cur = r - l + 1;
        ans += cur;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
const int maxn = 2e5 + 10;
int n, T, a, b;


int main() {
    scanf("%d%d", &a, &b);
    int mm = a+b;
    mm = max(mm, a-b);
    mm = max(mm, a*b);
    printf("%d\n", mm);
    return 0;
}


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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

u64 N, M;

int main(int argc, char *argv[])
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N;
    if (N >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3648
n,k = map(int,input().split())

def calc(n,m):
    y = [1]*(n+1)
    for i in range(n):
        y[i+1] = (y[i]*(i+1))%m
        
    return y

def calc2(n,a,m,y):
    x = (y[a]*y[n-a])%m
    return (y[n]*pow(x, m-2, m))%m

m = 10**9+7
y = calc(2*n-1,m)
if k >= n-1:
    print(calc2(2*n-1, n-1, m, y))
else:
    s = 0
    for i in range(n-k-1):
        s += calc2(n-1,i,m,y)*calc2(n,i+1,m,y)
    print((calc2(2*n-1, n-1, m, y)-s)%m)

Measured memory_bytes: 18804
#include<bits/stdc++.h>
#define LL long long
#define inf 0x3fffffff
using namespace std;

int n,b[2010],w[2010],f[4010][2010],frontw[2010][2010],frontb[2010][2010];

int main()
{
    scanf("%d",&n);
    char ch;int x;
    for (int i=1;i<=2*n;i++)
    {
        ch=getchar();
        while(ch!='B'&&ch!='W') ch=getchar();
        scanf("%d",&x);
        if (ch=='B') b[x]=i;
        else w[x]=i;
    }
    for (int i=1;i<=n;i++)
    {
        int sum=0;
        for (int j=i+1;j<=n;j++)
            if (b[j]<b[i]) sum++;
        frontb[i][n+1]=sum;
        for (int j=n;j>=1;j--)
            if (w[j]<b[i]) frontb[i][j]=frontb[i][j+1]+1;
            else frontb[i][j]=frontb[i][j+1];
        frontb[i][0]=frontb[i][1];
    }
    for (int i=1;i<=n;i++)
    {
        int sum=0;
        for (int j=i+1;j<=n;j++)
            if (w[j]<w[i]) sum++;
        frontw[i][n+1]=sum;
        for (int j=n;j>=1;j--)
            if (b[j]<w[i]) frontw[i][j]=frontw[i][j+1]+1;
            else frontw[i][j]=frontw[i][j+1];
        frontw[i][0]=frontw[i][1];
    }
    for (int i=1;i<=2*n;i++)
        for (int j=0;j<=n;j++)
            f[i][j]=inf;
    f[0][0]=0;
    for (int i=1;i<=2*n;i++)
        for (int j=max(0,i-n);j<=min(i,n);j++)
        {
            if (j>0) f[i][j]=min(f[i][j],f[i-1][j-1]+frontb[j][i-j+1]);
            if (i-j>0) f[i][j]=min(f[i][j],f[i-1][j]+frontw[i-j][j+1]);
        }
    /*for (int i=1;i<=2*n;i++)
        for (int j=0;j<=min(i,n);j++)
            cout<<i<<" "<<j<<" "<<f[i][j]<<endl;*/
    printf("%d\n",f[2*n][n]);
    return 0;
}

Measured memory_bytes: 63232
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> L(M + 1);
    vector<int> R(M + 1);
    for (int i = 1; i <= M; i++)
    {
        cin >> L[i] >> R[i];
    }
    int maxL = L[1], minR = R[1];
    for (int i = 1; i <= M; i++)
    {
        maxL = max(maxL, L[i]);
        minR = min(minR, R[i]);
    }
    if (minR - maxL < 0)
    {
        cout << 0;
    }
    else
    {
        cout << minR - maxL + 1 << endl;
    }
}


Measured memory_bytes: 1024
import java.util.*;

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

        int W = sc.nextInt();
        int H = sc.nextInt();
        int N = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        map.put(1, 0);
        map.put(2, W);
        map.put(3, 0);
        map.put(4, H);

        for (int i=0; i<N; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int a = sc.nextInt();
            switch (a) {
            case 1:
                map.put(a, x > map.get(a) ? x : map.get(a));
                break;
            case 2:
                map.put(a, x < map.get(a) ? x : map.get(a));
                break;
            case 3:
                map.put(a, y > map.get(a) ? y : map.get(a));
                break;
            case 4:
                map.put(a, y < map.get(a) ? y : map.get(a));
                break;
            default:
                ;
            }
        }

        int width = map.get(2) - map.get(1);
        width = width > 0 ? width : 0;
        int height = map.get(4) - map.get(3);
        height = height > 0 ? height : 0;

        System.out.println(width * height);
    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, a, b, m;
	cin >> n >> m;
	vector<int> ct(n + 1, 0);
	while (m--) {
		cin >> a >> b;
		ct[a]++;
		ct[b]++;
	}

	for (i = 1; i <= n; i++) cout << ct[i] << "\n";

	return 0;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
ans = [[0]*n for _ in range(n)]
for i in range(m):
  l, r = map(int, input().split())
  ans[l-1][r-1] += 1

for i in range(n-1, -1, -1):
  for j in range(i+1, n):
    ans[i][j] += ans[i][j-1]
for i in range(n-1, -1, -1):
  for j in range(i+1, n):
    ans [i][j] += ans[i+1][j]

for _ in range(q):
  p, q = map(int, input().split())
  print(ans[p-1][q-1])

Measured memory_bytes: 9332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();

		int ans = 0;

		int pp = 0;
		int qq = 0;

	for(int i = 1 ; i <= N ; i++){
		if(i%K == 0){
			pp++;
		}
		if(i%K == K/2){
			qq++;
		}
	}

	if(K%2!=0){
		System.out.println((long)Math.pow(pp, 3));
	}
	else{
		System.out.println((long)Math.pow(pp,3) + (long)Math.pow(qq, 3));
	}


	}
}



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

#define endl '\n'
#define int long long

const int H = 1009, W = 1009, mod = 1e9+7;
int cache[H][W], h, w;
char grid[H][W];

int dp(int i, int j) {
	if(i == h+1 or j == w+1) 
		return 0;
	if(i == h and j == w)
		return 1;
	int &ans = cache[i][j];
	if(ans != -1)
		return ans;
	ans = 0;
	if(grid[i+1][j] != '#')
		ans = (ans + dp(i+1, j)) % mod;
	if(grid[i][j+1] != '#')
		ans = (ans + dp(i, j+1)) % mod;
	return ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	memset(cache, -1, sizeof cache);
	cin >> h >> w;
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			cin >> grid[i][j];
		}
	}
	int ans = dp(1,1);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9344
#include<stdio.h>
int main(void){
    int a,b;
    char op;
    while(1){
    scanf("%d %c %d",&a,&op,&b);
     if(op=='?')break;
     if(op=='+'){
     printf("%d\n",a+b);
     }else if(op=='-'){
     printf("%d\n",a-b);
            }else if(op=='*'){
     printf("%d\n",a*b);
                }else{
     printf("%d\n",a/b);
                };
            }
return 0;
}

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

int main() {
    int n;
    cin >> n;
    
    int sum;
    int flag = 0;
    for (int i=0; i<100; ++i) {
        for (int j=0; j<100; ++j) {
            sum = 4*i + 7*j;
            if (sum == n) {
                ++flag;
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256