akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main(){
	/*input*/
	int n,m;
    cin >> n >> m;
    int a;
    vector<int> s(n+1, true);
    for(int i = 0;i < m; i++){
    	cin >> a;
    	s[a] = false;
    }

	/*calc*/
    long long ans = 0;
    long long sum_method[n+1];
    /*移動方法がない場合*/
//    for(int i = 0; i < m-1; i++){
//    	if(s[i+1] == false && s[i] == false){
//    		cout << 0 << endl;
//    		return 0;
//    	}
//    }
    for (int i = 0; i < n+1; i++){
    	sum_method[i] = 0;
    }
    sum_method[0] = 1;
//    sum_method[1] = 2;
    for (int i = 0; i < n+1; i++){
    	if(s[i+1] == true){
    		sum_method[i+1] += sum_method[i];
    		if(i > 0) sum_method[i+1] += sum_method[i-1];
    	}
    		sum_method[i+1] %= 1000000007;
    }
    ans = sum_method[n];
//    cout << "sum[n];" << sum_method[n-1] << endl;
//    ans = sum_method[n-1] % 1000000007;

	/*output*/
   	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long a[100005],sum[100005],n,m,ans;
long long check(long long x){
    long long res=0;
    for(int i=1;i<=n;i++){
        int k=lower_bound(a+1,a+1+n,x-a[i])-a-1;
        res+=n-k;
    }
    return res;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    }
    long long l=0,r=200001,res=0;
    while(r>=l){
        long long mid=(l+r)/2;
        if(check(mid)>=m) l=mid+1;
        else r=mid-1; 
    }
    //cout<<l<<" "<<r<<endl;
    for(int i=1;i<=n;i++){
        int k=lower_bound(a+1,a+1+n,l-1-a[i])-a-1;//l-1=mid
        //cout<<k<<" ";
        res+=n-k;
       //cout<<res<<" ";
        ans+=sum[n]-sum[k]+(n-k)*a[i];
    }
    //cout<<ans;
    ans+=(m-res)*(l-1);//res-m是多加的次数 
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define fone for(i=0;i<n;i++)
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N          = 5000*100+1;
const ll N2      = 1000*1000;
const ld PI  = 3.14159265;
const ll R   = 250;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
    }

    int main()
    {
        int n,i,count,m;
        m=1000*1000*100;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        count=0;
         for(i=0;i<n;i++)
         {
            m=min(a[i],m);
            if(m==a[i])
            {
                count++;
            }
         }
         cout<<count;
return 0;
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::cout << N * (N + 1) / 2 - (N / 3) * (N / 3 + 1) * 3 / 2 - (N / 5) * (N / 5 + 1) * 5 / 2 + (N / 15) * (N / 15 + 1) * 15 / 2 << std::endl;
  return 0;
}

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

int main(){
  int A,B,C;

  cin >> A >> B >>C;

  int count = 0;
  while(1){
    if(A % 2 == 1
     ||B % 2 == 1
     ||C % 2 == 1){
       break;
    }
    if(A == B && B == C){
      count = -1;
      break;
    }

    int A_ = B / 2 + C / 2;
    int B_ = A / 2 + C / 2;
    C = A /2 + B / 2;
    A = A_;
    B = B_;

    count++;
  }

  cout << count << endl;
}

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

typedef long long ll;
const int maxn = 1e3 + 10;
const ll mod = 1e9 + 7;


string s;

int main()
{
    double l;
    cin >> l;
    double x = l / 3.0;
    double ans = x * x * x;
    printf("%.6lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
using namespace std;
int main(void)
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    double con=0;
    int w,s;
    for(int i=0;i<=30;i++){
        for(int j=0;j<=30;j++){
            for(int y=0;y<=100;y++){
                for(int z=0;z<=100;z++){
                    int ww=a*i+b*j;
                    int sw=c*y+d*z;
                    int total=100*ww+sw;
                    if(total<=f&&sw<=ww*e){
                        if(con<(double)sw/total){
                            con=(double)sw/total;
                            w=100*ww;
                            s=sw;
                        }
                    }
                }
            }
        }
    }
    if(con == 0) w= 100*a;
	cout <<w+s<< " " <<s<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int a[110];
int cnt[9];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N) {
    cin >> a[i];
    a[i] = min(a[i], 3200LL);
    cnt[a[i]/400]++;
  }
  int base = 0;
  REP(i, 8) base += (cnt[i] > 0);
  int mx = base + cnt[8];
  int mn = max(1LL, base);
  cout << mn << " " << mx << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  string s;
  cin >> s;
  int l = s.size(),ans = INF;
  rep(i,0,26){
    char c = 'a' + i;
    int now = 0;
    Vi a(0);
    rep(j,0,l){
      if(s[j]!=c) now++;
      else {
        a.pb(now);
        now = 0;
      }
    }
    a.pb(now);
    ans = min(ans,*max_element(ALL(a)));
  }
  cout << ans  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(ll num, ll idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
string st;
int vis[30];
int main(){
     ll n,a,b;
     cin>>n>>a>>b;
     ll sum=a+b;
     ll F= n/sum;
     ll ans=F*a+min(a,n%sum);
     cout<<ans<<endl;
}














































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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    vector<vector<int>> c(3, vector<int>(3));
    REP(i, 3) {
        REP(j, 3) {
            cin >> c[i][j];
        }
    }
    vector<int> a(3);
    vector<int> b(3);
    REP(i, 3) {
        a[i] = c[i][0] - c[0][0];
    }
    REP(j, 3) {
        b[j] = c[0][j];
    }

    REP(i, 3) {
        REP(j, 3) {
            if(c[i][j] != a[i] + b[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//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 fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    cout<< (n*(n-1))/2 + (m*(m-1))/2;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
vector<int>pos;
bool check(int start){
	for(int i=0; i<t.length(); i++){
		int s_curr = start+i;
		if(s[s_curr]=='?') continue;
		else{
			if(s[s_curr]!=t[i]) return false; 
		}
	}
	return true;
}
void restore(int start){
	for(int i=0; i<t.length(); i++){
		s[start+i] = t[i];
	}
}
int main(){
	cin>>s>>t;
	int fin = s.length()-t.length();
	for(int i=0; i<=fin; i++){
		if(check(i)) pos.push_back(i);
	}
	if(pos.size()==0) cout<<"UNRESTORABLE";
	else{
		restore(*pos.rbegin());
		for(int i=0; s[i]; i++){
			if(s[i]=='?') cout<<'a';
			else cout<<s[i];
		}
	}
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
map<long long,long long>mp;
long long a,b,c,d;
long long solve(long long x)
{
	if(!x)
		return 0;
	if(x==1)
		return d;
	if(mp.count(x))
		return mp[x];
	long long l2=x/2*2,r2=(x+1)/2*2,l3=x/3*3,r3=(x+2)/3*3,l5=x/5*5,r5=(x+4)/5*5,res=1e18;
	if(x<res/d)
		res=x*d;
	res=min(res,llabs(l2-x)*d+a+solve(l2/2));
    res=min(res,llabs(r2-x)*d+a+solve(r2/2));
    res=min(res,llabs(l3-x)*d+b+solve(l3/3));
    res=min(res,llabs(r3-x)*d+b+solve(r3/3));
    res=min(res,llabs(l5-x)*d+c+solve(l5/5));
    res=min(res,llabs(r5-x)*d+c+solve(r5/5));
    mp[x]=res;
    return res;
}
int main()
{
	int t;
	long long n;
	cin>>t;
	while(t--)
	{
		mp.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<solve(n)<<endl;
	}
	return 0;
}

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

int main(){
  string s;
  int k;
  cin >> s >> k;
  set<string> ans;
  for(int i=1; i<k+1; i++){
    for(int j=0; j<s.size()-(i-1); j++){
      ans.insert(s.substr(j,i));
    }
  }
  for(int i=0; i<k-1; i++){
    ans.erase(*begin(ans));
  }
  cout << *begin(ans) << endl;
}

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

int main() {
 
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) { cin >> p.at(i); }
  
  int tmp = p.at(0);
  int ans = 1;
  for(int i = 0; i < n; i++) {
    if(tmp > p.at(i)) {
      tmp = p.at(i);
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 500;
int H,W,d;
char c[7] = "RYGB";

int main(){
	cin >> H >> W >> d;
	int z = 0;
	repp(i,0,H){
		repp(j,0,W){
			int x = i+j+MC , y = i-j+MC;
			cout << c[(x/d%2)*2+(y/d%2)];
		}
		cout << endl;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;

ll A, B;

ll fact[64] = {};

ll solve() {
    if(A == B) { return A; }

    // fact の計算
    fact[0] = 1;
    for(ll i = 1; i < 64; ++i) { fact[i] = fact[i-1] * 2; }

    ll ans = 0;
    // 一桁目の計算
    {
        ll cnt = 0;
        if(A % 2 == 0) {
            if(B % 2 == 0) { cnt = (B - A) / 2; }
            else { cnt = (B - A + 1) / 2; }
        }
        else {
            if(B % 2 == 0) { cnt = (B - A + 1) / 2; }
            else { cnt = (B - A + 2) / 2; }
        }
        ans = (cnt % 2 == 0) ? 0 : 1;
    }
    for(ll i = 1; i < 60; ++i) {
        // i 桁目の 0/1 入れ替わりスパン
        ll span = fact[i];
        // A から先の i 桁目 1 の数(次に 0 が出るまでの領域)
        ll a_one = 0;
        if((A / span) % 2 == 1) {
            // span で割った時に奇数なら 1 の数が
            // 奇数になる可能性がある
            a_one = span - (A % span);
        }
        // B までの i 桁目の 1 の数(次に 0 が出るまでの領域)
        ll b_one = 0;
        if((B / span) % 2 == 1) {
            b_one = (B % span) + 1;
        }
        // 以上の 2 つを足したものが奇数ならこの桁は 1
        if((a_one + b_one) % 2 == 1) {
            ans |= (1LL << i);
        }
    }
    return ans;
}

signed main()
{
    cin >> A >> B;
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}


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


int main(){
    ll N, K ,ans = 0;
    cin >> N >> K; 
    ll x[N];
    for(int i = 0; i < N; i++) cin >> x[i];
    
    for(int i = 0; i < N; i++){
        ans += 2 * min(abs(x[i]), abs(x[i] - K));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a, b = [], []

for i in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)

ans = 0
for i in range(n):
    aa = a[n-i-1]
    bb = b[n-i-1]
    if (aa+ans)%bb != 0:
        t = (bb)-(aa+ans)%bb
        ans += t

print(ans)



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

int main(){
  string cards;
  string ans;

  while(1){
  cin >> cards;
  if(cards[0]=='-'){
    break;
  }

  int m;

  cin >> m;

  for(int i=1; i<= m; i++){
    int h;
    cin >> h;
    
  string  s = cards.substr(0,h);
  // cout << s << '1' << endl;
  string f = cards.erase(0,h);
  // cout << f << '2' << endl;
   cards= f+s; 
   // cout << cards << '3' << endl;

      // s.erase(s.begin()+1,s.begin()+h);
    //  strcpy(s, cards);
    // strncat(s, cards, h);
    // s.erase(1,h);
  }

  cout << cards << endl;

  }

  return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n=1;
  int m=1;
  int count=0;
  vector<int> sum(50000, 0);
  vector<int> flg(50000, 0);

  while(n!=0&&m!=0)
    {
      cin >> n >> m;
      if(n==0&&m==0)
	{
	  break;
	}
      vector<int> a(n);
      for(int i=0;i<n;i++)
	{
	  cin >> a[i];
	}
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  if(a[i]+a[j]>sum[count] && a[i]+a[j]<=m && i!=j)
	    {
	      sum[count] = a[i]+a[j];
	      flg[count] = 0;
	    } 
	  else
	    {
	      if(sum[count]==0)
		{
		  flg[count]=1;
		}
	    }
	}
      }
      count++;
    }
  for(int i=0;i<count;i++)
    {
        if(flg[i]==0)
	{
	  cout << sum[i] << endl;
	}
      if(flg[i]==1)
	{
	  cout << "NONE" << endl;
	}
    }
  return 0;
}





Measured memory_bytes: 3336
#include<bits/stdc++.h>
#define MOD 1000000007

long long DP[105][100005];
int arr[105];
int n,K;
long long dp(int pos, int tot){
	if(DP[pos][tot]!=-1) return DP[pos][tot];
	printf(">> %d %d\n",pos,tot);
	if(tot==K) return dp(pos,tot-1)+1;
	if(tot<0) return 0;
	if(pos==n) return 0;
	
	long long ret =0;
	return DP[pos][tot] = dp(pos,tot-1) + dp(pos+1,tot+arr[pos]) - dp(pos+1,tot-1);
}

int main(){
//	memset(DP,-1,sizeof DP);
	scanf("%d%d",&n,&K);
	for (int i =1;i<=n;i++){
		scanf("%d",&arr[i]);
	}
	
	for(int i =0;i<=n;i++){
		for(int j = 0; j<=K;j++){
			if(i==0){
				DP[i][j] =0;
			} else if(j==0) DP[i][j] = 1; 
			else if(i==1){
				if(j<=arr[i])DP[i][j] = DP[i][j-1]+1;
				else DP[i][j] = DP[i][j-1];	
			} else {
				DP[i][j] = ((DP[i][j-1] + DP[i-1][j]) %MOD- (j-arr[i]-1>=0?DP[i-1][j-arr[i]-1]:0)+MOD)%MOD;
			}
//			printf("%lld ",DP[i][j]);
		}
//		printf("\n");
	}
	printf("%lld\n", (DP[n][K]-(K-1>=0?DP[n][K-1]:0)+MOD)%MOD);
//	printf("%lld\n",dp(0,0));
	return 0;
}

Measured memory_bytes: 80128
import java.io.*;
// import java.math.*;
import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String S = reader.readLine();
        String[] W = {"Sunny", "Cloudy", "Rainy"};
        System.out.println (W[(Arrays.asList (W).indexOf (S) + 1) % 3]);
        return;
    }
}

Measured memory_bytes: 32508
#include<stdio.h>

int main(){

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

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3 - i; j++){

            if(s[j] > s[j + 1]){
                int tmp = s[j];
                s[j] = s[j + 1];
                s[j + 1] = tmp;
            }

            //printf("%s\n", s);
        }
    }

    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]

def funci(d,j):
    ret=0
    for i in range(len(d)-1):
        ret+=c[d[i]][d[i+1]]
    ret+=c[d[-1]][j]
    return ret

def bfs(i):#i!=1,i->1 minimum
    ret=c[i][1]
    todo=deque([[i,j] for j in range(10) if j!=i and j!=1])
    while len(todo)>0:
        d=todo.popleft()
        ret=min(ret,funci(d,1))
        for k in [j for j in range(10) if j not in d and j!=1]:
            f=d.copy()
            x=funci(f,k)
            if funci(f,k)<ret:
                f.append(k)
                todo.append(f)
    return ret
g=[bfs(i)for i in range(10)]
ans=0
for ai in a:
    for aij in ai:
        ans+=g[aij] if aij != -1 else 0
print(ans)
#print(g)


Measured memory_bytes: 3696
import java.io.*;
class Main{
  public static void main(String[]z){
    try{
      String s;
      Map<Integer,Integer> map=new TreeMap<Integer,Integer>();
      int id,mul=1;
      InputStreamReader y=new InputStreamReader(System.in);
      BufferedReader x=new BufferedReader(y);
      while((s=x.readLine())!=null){
        if(s.length()==0){mul=100;continue;}
        id=Integer.parseInt(new StringTokenizer(s,",").nextToken());
        map.put(id,mul+(map.containsKey(id)?map.get(id):0));
      }
      Iterator<Map.Entry<Integer,Integer>> it=map.entrySet().iterator();
      while(it.hasNext()){
        Map.Entry<Integer,Integer>m=it.next();
        int a=m.getValue()/100,b=m.getValue()%100;
        if(a>0&&b>0)System.out.println(m.getKey()+" "+(a+b));
      }
    }catch(Exception e){}
  }
}

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

using namespace std;

int main() {
  int num[5];

	scanf("%d%d%d", num, num + 1, num + 2);
	sort(num, num + 3);
	if (num[0] + num[1] == num[2]) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}

  return 0 ;
}

Measured memory_bytes: 256
N = int(input())
l = [input().split() for _ in range(N)]

a = 0
b = 0
for i in range(N):
    if l[i][0] > l[i][1]:
        a += 3
    elif l[i][0] < l[i][1]:
        b += 3
    else:
        a += 1
        b += 1
print(a,b)
    


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

int main() {
  string N;
  cin >> N;
  string ans="No";
  if(N[0]==N[1]) {
	if(N[0]==N[2]) ans="Yes";
  }
  else {
	if(N[1]==N[2]&&N[2]==N[3]) ans="Yes";
  } 
  cout << ans << endl;
  return 0;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define rep(i, n) for(int i = 0; i < n; i++)
#define irep(i,n) for(int i = n-1; i>=0; i--)
#define FOR(a,b) for(int i=a; i<b+1; i++)
using namespace std;
typedef long long ll;

int main() {
    ll n,h;
    cin >> n >> h;
    ll max=-114514;
    queue<ll> q;
    vector<ll> v(n);
    rep(i,n){
        ll nage,huri;
        cin >> huri >> nage;
        if(max<huri){
            max=huri;
        }
        v[i]=nage;
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    rep(i,n){
        if(v[i]>max){
            q.push(v[i]);
        }
    }
    ll ans=0;
    while(h>0){
        if(!q.empty()){
            h-=q.front();
            ans++;
            q.pop();
        }
        else{
            h-=max;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

fn main() {
    let (h, w) = {
        let i = read();
        (i[0], i[1])
    };

    let table: Vec<Vec<char>> = read_char_table(h);

    let mut ans = "Yes";

    if h < 2 || w < 2 {
        if table[0][0] == '#' {
            println!("No");
        } else {
            println!("Yes");
        }
        return;
    }

    for i in 0..h {
        for j in 0..w {
            // 塗対象でなければ無視
            if table[i][j] == '.' {
                continue;
            }

            let up = if i != 0 { table[i - 1][j] } else { '.' };
            let down = if i != h - 1 { table[i + 1][j] } else { '.' };
            let left = if j != 0 { table[i][j - 1] } else { '.' };
            let right = if j != w - 1 { table[i][j + 1] } else { '.' };

            if up == '.' && down == '.' && left == '.' && right == '.' {
                ans = "No";
                break;
            }
        }
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

struct Node{
  int key;
  Node *prev, *next;
};

Node *nil;

Node* search(int k){
  Node *x = nil->next;

  while(x != nil && x->key != k) x = x->next;

  return x;
}

void insert(int k){
  Node *x = (Node *)malloc(sizeof(Node));

  x->key = k;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

void deleteNode(Node *x){
  if(x == nil) return;
  x->prev->next = x->next;
  x->next->prev = x->prev;

  free(x);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

int main(){

  int n, k;
  char command[20];

  nil = (Node *)malloc(sizeof(Node));
  nil->prev = nil;
  nil->next = nil;

  scanf("%d", &n);
  for(int i = 0;i < n;i++){
    scanf("%s", command);
    if(strcmp(command, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }else if(strcmp(command, "delete") == 0){
      scanf("%d", &k);
      deleteNode(search(k));
    }else if(strcmp(command, "deleteFirst") == 0){
      deleteFirst();
    }else if(strcmp(command, "deleteLast") == 0){
      deleteLast();
    }
  }

  k = 0;
  Node *x = nil->next;
  while(x != nil){
    printf((k?" ":""));
    printf("%d", x->key);
    k++;
    x = x->next;
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 34388
#include <stdio.h>
#include <string.h>

int main(void)
{
    int N;
    char S[10001];
    int i;
    
    
    scanf("%d", &N);
    scanf("%s", S);
    
    
    for(i=0; i<strlen(S); i++)
        printf("%c", 65+((int)S[i]-65+N)%26);
    
    printf("\n");
    
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
long A[200000]; 
void Calc(){
	int N = rei();
	long sum = 0;
	for(int i=0;i<N;i++){
		A[i] = rel();
		sum += A[i];
	}
	long ans = sum;
	long temp = 0;
	for(int i=0;i<N;i++){
		temp += A[i];
		ans = min(ans,abs(temp*2-sum)); 
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>

using namespace std;

int a[200000];

int main() {
    int n, m, l, r, mid, ans = 0, i, j;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n * 2; i++) scanf("%d", &a[i]);
    
    sort(a, a + n * 2);
    
    l = -1, r = n, mid = (l + r) / 2;
    
    while (r - l > 1) {
        for (i = mid * 2, j = n * 2 - 1; i < j; i++, j--) {
            if (a[i] + a[j] < m) break;
        }
        
        if (i < j) {
            l = mid;
            mid = (l + r) / 2;
        } else {
            r = mid;
            mid = (l + r) / 2;
        }
    }
    
    for (i = 0, j = r * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j]);
    for (i = r * 2, j = n * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j] - m);
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>

using namespace std;

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

	int s = 0;
	for (auto c : N) {
		s = (s + (c - '0')) % 9;
	}
	if (s == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3716
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int n2 = sc.nextInt();
        System.out.println((n1*n2)+" "+(n1+n1+n2+n2));
    }
}


Measured memory_bytes: 26184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll x,y;
int main(){
	x=read(),y=read();
	printf("%lld",x*y/__gcd(x,y));
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = scanner.nextInt();
    }
    Arrays.sort(h);

    int diff = Integer.MAX_VALUE;
    for (int i = 0; i <= N - K; i++) {
      int d = h[i + K - 1] - h[i];
      diff = Math.min(d, diff);
    }
    System.out.println(diff);
  }
}


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

int N;

int func( int bef, int sum ) {
  if( sum == N ) return 1;
  if( sum > N ) return 0;
  return func( bef + 1, sum + bef + 1 );
}

int main()
{
  while( cin >> N, N ) {
    int ans = 0;
    for(int i=1; i<=N/2; i++) {
      ans += func( i, i );
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 2996
a,b=map(int,input().split())
ListS = []
for i in range (a):
  ListS.append(list(map(int, input().split())))
ListP = []
for i in range (b):
  ListP.append(list(map(int, input().split())))
List = [100]*a
mid = 0
dist = 10000000000000000000
for i in range(a):
  for j in range(b):
    mid = abs(ListP[j][0]-ListS[i][0])+abs(ListP[j][1]-ListS[i][1])
    if dist > mid:
      dist = mid
      List[i] = j+1
    elif mid == dist:
      List[i] = min(List[i],j+1)
    else:
      pass
  dist = 10000000000000000000
for element in List:
  print(element)

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<long>A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    set<long>X;
    for(int j=0;j<N;j++){
        X.insert(A[j]);
    }
    if(A.size()!=X.size()){
        cout << "NO" <<endl;
    }else{
        cout << "YES" << endl;
    }
}



Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
 
    string S;
    cin >> S;
    
    int ans = 0;
    int count = 0;
    
    for(int i = 0; i < S.size(); i++){
        
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            count++;
            ans = max(ans, count);
        }
        else{
        count = 0;
        }
    }
    
    cout << ans << endl;
}


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

int main() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    int x[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    int y[M];
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }
    for (int i = X + 1; i <= Y; i++) {
        bool willStartWar = false;
        for (int j = 0; j < N; j++) {
            if (x[j] >= i) {
                willStartWar = true;
            }
        }
        for (int k = 0; k < M; k++) {
            if (y[k] < i) {
                willStartWar = true;
            }
        }
        if (!willStartWar) {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}


Measured memory_bytes: 3548
from decimal import *
N = int(input())
A = []
for _ in range(N):
  A.append(int(Decimal(input()) * 10**9))

KMAX = 20
#X[i][j] 2の約数をi個、5の約数をj個もつ。9以上は9でよい
X = [[0 for _ in range(KMAX)] for _ in range(KMAX)]

for a in A:
  i,j = 0,0
  wk = a
  for i in range(KMAX):
    if a%2 == 0:
      a = a // 2
    else:
      break
  for j in range(KMAX):
    if a%5 == 0:
      a = a // 5
    else:
      break
  #print(wk,i,j)
  X[i][j] += 1
  
#print(A)
#for x in X:
 # print(x)
  
cnt = 0
for i in range(KMAX):
  for j in range(KMAX):
    for k in range(KMAX):
      for l in range(KMAX):
        if i+k < 18 or j+l < 18:
          continue
        if X[i][j] * X[k][l] == 0:
          continue
        #print(i,j,k,l, X[i][j] , X[k][l])
        if i==k and j==l:
          cnt += X[i][j] * (X[i][j] - 1)
        else:
          cnt += X[i][j] * X[k][l]
print(cnt//2)

Measured memory_bytes: 17740
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    int d=max({a,b,c});
    int coun=(d-a)+(d-b)+(d-c);
    if(coun%2==0){
        cout<<coun/2<<endl;
    }
    else{
        cout<<(coun+3)/2<<endl;
    }
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    s = sc.strarr()[0]
    ans = ''
    before = s[0]
    for i in range(1, n):
        c = s[i]
        if before != c:
            ans += before
            before = c

    ans += before
    print(len(ans))


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3316
from fractions import *
n = int(input())
a = [0]+list(map(int, input().split()))+[0]
b = [0]*(n+2)
c = [0]*(n+2)
for i in range(1, n+1):
	b[i] = gcd(b[i-1], a[i])
for i in range(n, 0, -1):
	c[i] = gcd(c[i+1], a[i])

ans=1
for i in range(1, n+1):
    x1 = b[i-1]
    x2 = c[i+1]
    ans=max(ans, gcd(x1, x2))

print(ans)

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

signed main() {
	int n;
	string s;
	cin >> n >> s;
	int cnt = 0;
	for (int i = 2; i < n; ++i) {
		if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C')++cnt;
	}
	cout << cnt << endl;
}

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

int main() {
	int N;
  	cin >> N;
  	vector<int> light(N);
    for(int i = 0; i < N ; i++){
    	cin >> light.at(i);
    }
  	int next = 1;
    bool check = false;
  	int counter = 0;
  	for(int i = 0; i < N ; i++){
        counter++;
    	next = light.at(next - 1);
      	if(next == 2){
        	check = true;
          	break;
        }
    }
  	if(check == false){
    	cout << -1 << endl;
    }else{
    	cout << counter << endl;
    }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dp[3010][3010];

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

  int N;
  cin >> N;
  VL xs(N);
  cin >> xs;

  REP(i,N){
    dp[i][i+1] = (N % 2 ? 1 : -1) * xs[i];
  }

  for(int len=2;len<=N;++len){
    int turn = (N - len) % 2; // 0 -> L, 1 -> R
    for(int b=0,e=len;e<=N;++b,++e){
      if(turn == 0){ // L
        dp[b][e] = max(dp[b+1][e] + xs[b], dp[b][e-1] + xs[e-1]);
      }
      else{ // R
        dp[b][e] = min(dp[b+1][e] - xs[b], dp[b][e-1] - xs[e-1]);
      }
    }
  }

  cout << dp[0][N] << endl;

  return 0;
}


Measured memory_bytes: 70016
input1 = gets
input2 = gets
inArr = input1.chomp!.split(" ")
inArr.concat(input2.chomp!.split(" "))
inArr = inArr.map { |str| str.to_i}
litter = inArr[4]
litterKin = [inArr[0]*4,inArr[1]*2,inArr[2]].min
if (litter%2==1) then
    # odd
    if (litterKin*2 > inArr[3])
        puts ((litter-1)/2) * inArr[3] + litterKin
    else
        puts litter * litterKin
    end
else
    # even
    puts (litter/2) * [litterKin*2,inArr[3]].min
end

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

int main(){
   int N;
   cin >> N;
   vector<int> a(N);
   for (int i=0; i<N; i++){
      cin >> a.at(i);
   }
   int temp = 1;
   map<int, int> list;
   int cnt = 0;
   bool flag = true;
   while (temp != 2){
      if (list[temp] != 0){
         flag = false;
         break;
      }
      list[temp]++;
      temp = a.at(temp-1);
      cnt++;
      //for (auto x: list){
      //   cout << x.first << ":" << x.second << endl;
      //}
   }
   if (flag)
      cout << cnt << endl;
   else
      cout << -1 << endl;

}



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

using namespace std;

typedef long long ll;

const int MAXN = 3000;

int N;
ll dp[MAXN][MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> dp[i][i];
    for (int w = 2; w <= N; w++)
        for (int l = 0, r = w - 1; r < N; l++, r++)
            dp[l][r] = max(dp[l][l] - dp[l + 1][r], dp[r][r] - dp[l][r - 1]);
    cout << dp[0][N - 1] << endl;
}


Measured memory_bytes: 70016
#include <stdio.h>

int main() {
  int N;
  int max = -1, min = 1111;
  int i;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    int a;
    scanf("%d", &a);
    if(max < a) max = a;
    if(min > a) min = a;
  }
  
  printf("%d\n", max - min);
  
  return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld,ld> pt;

int main(){
int n;
  cin>>n;
  vector<pt>v(n);
  for(auto&x:v)cin>>x.first>>x.second;
  vector<int>ind;
  for(int i=0;i<n;i++)ind.push_back(i);
  ld s=0;
  int cnt=0;
  do{
    cnt++;
    ld l=0;
    for(int j=0;j<n-1;j++){
      int i=ind[j];
      int ii=ind[j+1];
        ld dx=v[i].first-v[ii].first;
        ld dy=v[i].second-v[ii].second;
        l+=sqrtl(dx*dx+dy*dy);
    }
    s+=l;
  }while(next_permutation(ind.begin(),ind.end()));
cout<<fixed<<setprecision(12)<<s/cnt;
         }


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long a , b;
        cin >> a >> b;
        if( (a * b) % 2 == 0){
            cout <<  "Even"  << endl;
        }else{
            cout <<  "Odd"  << endl;
        }
        
        
        
        return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h;
	int w;
	int a;
	int b;
	
	scanf("%d %d", &h, &w);
	
	while (1){
		if ((h == 0) && (w == 0)){
			break;
		}
		for (a = 1; a <= h; a++){
			for (b = 1; b <= w; b++){
				if ((a % 2 == 0) && (b % 2 == 0)){
					printf("#");
				}
				else if ((a % 2 == 0) && (b % 2 == 1)){
					printf(".");
				}
				else if ((a % 2 == 1) && (b % 2 == 0)){
					printf(".");
				}
				else if ((a % 2 == 1) && (b % 2 == 1)){
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}
	
	return (0);
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;

int main(){
	int n;
	cin>>n;
	vi a(n+1);
	vi dp(n+1,inf);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[1]=0;dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n];

	return 0;
}

Measured memory_bytes: 1024
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};

int N,M,ans;
bool visited[10];
int G[10][10];

void dfs(int from, int cnt){
  if(cnt==N){
    ans++;
    return;
  }

  visited[from]=1;
  for(int i=0; i<N; i++) if(!visited[i] && G[from][i]) dfs(i,cnt+1);
  visited[from]=0;

}

int main(int argc, char const *argv[]) {
  std::cin >>  N >> M;
  for(int i=0; i<M; i++){
    int a,b; std::cin >> a >> b;
    G[a-1][b-1]=G[b-1][a-1]=1;
  }

  dfs(0,1);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VL a(n);
  REP(i, 0, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  pair<ll, ll> mi(1e16, -1);
  REP(i, 1, n) {
    ll dif = abs(a[0] - 2 * a[i]);
    mi = min(mi, make_pair(dif, a[i]));
  }
  cout << a[0] << " " << mi.second << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

//  結局、123 | 345 | 567 | 789 | 9 10 |
//  のような両端が被ってるエリア分けを作って、1の入っているエリアから両サイドに広がっていくしかない。
//  なので、あらかじめ、このエリア分けがどのように行われるかをチェック。
//  エリア分けのエリア数がそのまま答えになる。
//  というか、Aの入力はでたらめでもN,Kの数で答えが決まる。

int main(){
    int N,K; cin >> N >> K;
    int ans;
    int tmp;
    while(true){
        if(tmp == 0){
            ans++;
            tmp += K;
        }
        else{
            ans++;
            tmp += K-1;
        }
        if(tmp >= N)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.rbegin(),a.rend()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vl A(a), B(b), C(c);
	for(int i=0;i<a;i++)cin>>A[i];
	for(int i=0;i<b;i++)cin>>B[i];
	for(int i=0;i<c;i++){cin>>C[i];}
	sort(all(A));
	sort(all(B));
	vi k;
	for(int i=0;i<x;i++)k.pb(A[i]);
	for(int i=0;i<y;i++)k.pb(B[i]);
	for(int i=0;i<c;i++)k.pb(C[i]);
	sort(k.rbegin(), k.rend());
	ll ans = 0;
	for(int i=0;i<x+y;i++)ans+=k[i];
	cout<<ans;	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846


    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    void solve(){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int w=0,r=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')
                r++;
            else
                w++;
        }
        int swap=0;
        for(int i=0;i<r;i++){
            if(s[i]=='W')
                swap++;
        }
        cout<<min({swap,r,w});
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3752
N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f:
  if(f<0)&(i<j)|(f>0)&(i>j):a+=1;f=0
 else:f=(i<j)-(i>j)
print(a+1)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  int ans = 0;
  for (int i = 0; i < B - A + 1; i++) {
    if ((A + i) % K == 0) {
      ans++;
    }
  }
  
  if (ans == 0) {
    cout << "NG" << endl;
  }
  
  else {
    cout << "OK" << endl;
  }
}


Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0
for i in range(N-1):
    cnt += B[A[i]-1]
    if A[i] + 1 == A[i+1]:
        cnt += C[A[i]-1]
    
cnt += B[A[N-1]-1]
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve(){	
	int k;
	string s;
	
	cin >> k;
	cin >> s;
	
	string ans = s.substr(0, k);
	if(s.size() > k) ans += "...";
	cout << ans << endl;
}

int main(){
	fastcin
	solve();      
	return 0;
}
	


Measured memory_bytes: 3648