akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int n,y[100],m[100],d[100],i,a,b,p,q,r;
    scanf("%d",&n);
    a=(20*5+19*5)*666+20*10*333+1;
    for (i=0;i<n;i++) {
        scanf("%d %d %d",&y[i],&m[i],&d[i]);
        p=y[i]/3;
        q=y[i]%3;
        r=m[i]/2;
        if (q!=0) {
            if (m[i]%2==0) {
                b=590*p+195*(q-1)+39*(r-1)+20+d[i];
            }
            else {
                b=590*p+195*(q-1)+39*r+d[i];
            }
        }
        else {
            b=590*(p-1)+390+20*(m[i]-1)+d[i];
        }
        printf("%d\n",a-b);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


bool solve(string s) {

	if (s[0] == 'A' && std::toupper(s[1]) != s[1] && std::toupper(s[s.size() - 1]) != s[s.size() - 1]) {

		string t = s.substr(2, s.size() - 3);

		int count = 0;
		for (int i = 0; i < t.size(); i++) {
			if (std::toupper(t[i]) == t[i]) {
				count++;
				if (t[i] != 'C') {
					return false;
				}
			}
		}

		if (count == 1) {
			return true;
		}
	}

	return false;
}

int main(void) {
	
	string s;
	cin >> s;

	if (solve(s)) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
typedef long long ll;
typedef pair<int,int> P;

int main(){
   string s;
   cin >> s;
   int cnt=0;
   for(int i=0;i<s.size();i++){
      for(int j=i+1;j<s.size();j++){
         if(s[i]==s[j]) cnt++;
      }
   }
   if(cnt==2) cout << "Yes" << endl;
   else cout << "No" << endl;
}


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

int main(){
  int N,K;
  int a[1100];
  cin >> N >> K;
  for (int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a, a+N);
  int ans =0;
  for(int i=0;i<K;i++){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define MOD 1000000007

int main(){
  ll N;
  cin >> N;
  ll result = N * (N-1) / 2;
  cout << result << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p[2000005];
ll a;
bool check(ll mid,ll k)
{
    ll ans=0;
    if(mid==0)
    {
        for(ll i=0;i<a;i++)
            ans+=p[i]*3;
    }
    else{
    for(ll i=0;i<a;i++)
    {
long double m =(p[i]*1.0/(1.0*mid));
      ans+=ceil(m)-1;
    }
    }

    if(ans<=k)
        return true;
    else
        return false;
}
int main()
{
   ll b,c,d,k=0;
   cin>>a>>b;
   for(ll i=0;i<a;i++){
    cin>>p[i];
    k=max(k,p[i]);
   }
    ll l = 1, r =k+100, mid;
    while(l < r)
      {
        mid = (l + r) >> 1;
        if(check(mid,b)) r = mid;
        else l = mid + 1;
      }

      cout<<l<<endl;

    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
  double m = 0;
  int n, sum = 0, sum2 = 0;
  cin >> n;
  int x[n];
  for(int i=0; i<n; i++) {
    cin >> x[i];
    m += x[i];
  }
  m /= n;
  // cout << m << endl;
  if (m-(int)m != 0) {
    m = floor(m);
  }
  for(int i=0; i<n; i++) {
    sum += pow(x[i] - m, 2);
  }
  for(int i=0; i<n; i++) {
    sum2 += pow(x[i] - (m + 1), 2);
  }
  cout << min(sum, sum2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<char,int>;

int main(){
   int a,b,c,x,y;
   cin >> a >> b >> c >> x >> y;
   auto c_2 = a+b;
   ll sum = 0;
   
   for (int i = 1; i <= min(x,y); i++)
   {
      sum +=min(c_2,c*2);
   }
   
   sum += x>y ? min(a,c*2)*(x-y) : min(b,c*2)*(y-x);
   
   cout << sum;
}
  
  

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n, k;
  cin>>n>>k;
  cout<<min(n%k, k-(n%k))<<'\n';
  return 0;
}


Measured memory_bytes: 256
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  var data = chunk.replace( '\n', '' ).split( ' ' ).map( Number );
  var cnt = 0;
  for( var i=data[0]; i<=data[1]; i++ ) {
    if( 0 == data[2]%i ) cnt++;
  }
  console.log( cnt  );
});

Measured memory_bytes: 7644
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B, ll C) {
  bool pred = A <= C && B >= C;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 100010
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n;
ll a,b,ans=0;
ll x[MAX];

int main()
{
  cin>>n>>a>>b;
  FOR(i,0,n)cin>>x[i];
  FOR(i,1,n){
   if((x[i]-x[i-1])*a<b)ans+=(x[i]-x[i-1])*a;
   else ans+=b;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	while (cin >> N) {
		cout << (N - 1) * (N + 2) / 2 + 2 << endl;
	}
}


Measured memory_bytes: 2992
#include<vector>
#include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	if (n < 2 || n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) {
		if (n%i == 0)return false;
	}
	return true;
}
int main() {
	int n; cin >> n;
	int x, cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (isprime(x))cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    d[a] = d.get(a, 0) + 1
ans = sum([v * (v - 1) // 2 for v in d.values()])
for a in A:
    print(ans - d[a] + 1)


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

using namespace std;

int main(){
        int g;
        cin>>g;
        int a[4];
        a[0]=g/1000, a[2]=(g/10)%10, a[1]=(g/100)%10, a[3]=g%10;
        string ans;
        string s[100];
        for(int i=0;i<10;i++){
                s[i]+=a[0]+'0';
        }
        for(int i=0;i<10;i++){
                if(i%2==0){
                        s[i]+="+";
                }
                else{
                        s[i]+="-";
                }
        }
        for(int i=0;i<10;i++){
                s[i]+=a[1]+'0';
        }
        for(int i=0;i<10;i++){
                if((i/2)%2==0){
                        s[i]+="+";
                }
                else{
                        s[i]+="-";
                }
        }
        for(int i=0;i<10;i++){
                s[i]+=a[2]+'0';
        }
        for(int i=0;i<10;i++){
                if((i/4)%2==0){
                        s[i]+="+";
                }
                else{
                        s[i]+="-";
                }
        }
        for(int i=0;i<10;i++){
                s[i]+=a[3]+'0';
        }
        for(int i=0;i<8;i++){
                int now=a[0];
                //cout<<s[i]<<endl;
                for(int j=1;j<(int)s[i].length();j+=2){
                        if(s[i][j]=='+'){
                                now+=a[j/2+1];
                        }
                        else{
                                now-=a[j/2+1];
                        }
                }
                //cout<<now<<endl;
                if(now==7){
                        ans=s[i];
                        ans+="=7";
                        break;
                }
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N,K,j;
int main(){
    int i=1;
    cin>>N>>K;
    if(N>=K){
       j=N/K;
    do{
       j=j/K;
        i++;}while(j>=K);
    i++;
        cout<<i<<endl;}
    else{
        cout<<i<<endl;
    }
    return 0;
    
}
     

Measured memory_bytes: 256
import math
def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True
X=int(input())
i=X
while True:
    if isPrime(i)==True:
        print(i)
        break
    i+=1

Measured memory_bytes: 9124
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 
#include <numeric>
#include <cctype>

using namespace std; 

const long long mod=1e9+7;


int main(){

    int n;
    cin>>n;

    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());

    vector<bool> dp(1000001,true),calced(1000001,false);

    for(int i=0;i<n;i++){
        if(calced[a[i]]) continue;
        calced[a[i]]=true;
        if(i+1<n && a[i]==a[i+1]) dp[a[i]]=false;
        for(int j=2*a[i]; j<=1000000; j+=a[i]) dp[j]=false;
    }

    int res=0;
    for(int i=0;i<n;i++){
        if(dp[a[i]]){
            res++;
            dp[a[i]]=false;
        }
    }
    cout<<res<<endl;

    return 0;
}


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

using namespace std;

bool palin(string s, int l, int r){
  for(int i=l;i<=r;i++){
    if(s[i]!=s[r-i]) return false;
  }
  return true;
}

int main(){
  string s;
  cin>>s;
  int n = s.size();
  if(palin(s,0,(n-1)/2 - 1) && palin(s,(n-1)/2 + 1,n-1)){
    cout<<"Yes"<<endl;
  } else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

int d[55];

int main()
{
	int n;
	read(n);
	for (int i=1;i<=n;i++) read(d[i]);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++) ans+=d[i]*d[j];
	cout<<ans;
	return 0;
}









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

long long mod = 1e9 + 7;
long long fact_arr[2007], inv_fact_arr[2007];

long long pow(long long n, long long r){
    if(r == 0){
        return 1;
    }
    n %= mod;
    if(r % 2){
        return pow(n * n % mod, r / 2) %mod * n % mod;
    }else{
        return pow(n * n % mod, r / 2) % mod;
    }
}

long long inv(long long n){
    return pow(n % mod, mod - 2) % mod;
}


long long comb(long long n, long long k){
    if(n < k || n < 0){
        return 0;
    }
    return fact_arr[n] * inv_fact_arr[n - k] % mod * inv_fact_arr[k] % mod;
}

int K, N;

int main(){
    cin >> N >> K;
    fact_arr[0] = 1;
    inv_fact_arr[0] = 1;
    for(int i = 1; i < 2007; i++){
        fact_arr[i] = i * fact_arr[i - 1] % mod;
        inv_fact_arr[i] = inv(fact_arr[i]);
    }
    
    for(int i = 1; i <= K; i++){
        // 青い玉の配置: K個のボールを空でないi個のグループにわける
        // K - i 個のボールを空でもよいi個のグループにわける
        // comb(K - i + (i - 1), i - 1)
        long long blue_comb = comb(K - 1, i - 1);
        // 赤い玉の配置: N - K 個のボールを、i - 1個の空でないグループと2個の空でもよいグループにわける
        // N - K - (i - 1)個のボールを i + 1個の空でもよいグループにわける
        // comb(N - K - i + 1 + i + 1 - 1, i)
        long long red_comb = comb(N - K + 1, i);
        cout << blue_comb * red_comb % mod << endl;
    }
}


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

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007

    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}


     int solve()
     {
         int a,b;
         cin>>a>>b;
         cout<<max(a+b,max(2*a-1,2*b-1));
     }
    signed main()
    {   
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
ll b[111],ans;
/*======================================================================*/
int main()
{
  /*
	ios_base::sync_with_stdio(0);
	cin(tie);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  ll t=read();
  rep(i,t-1)
  {
  	b[i]=read();
  }
  b[t]=1e9;
  forn(i,1,t-1)
  {
  	ans+=min(b[i],b[i-1]);
  }
  cout<<ans+b[0]+b[t-2];
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		double tmp=i*1.08;
		int t=(int)floor(tmp);
		if(n==t)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<":("<<endl;
	return 0;
 } 
 /*

*/

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

using namespace std;

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

	vector<int> A;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
	}

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

	cout << A[N - 1] - A[0] << endl;

}




Measured memory_bytes: 256
import math

a,b,x=map(int,input().split())

if a*a*b==x:
    print(0)
elif (b*a*a)/2>=x:
    t=((2*x)/(a*b))
    s=b
    print(math.degrees(math.atan(s/t)))
else:
    s=(2*((a*a*b)-x))/(a**2)
    t=a
    print(90-math.degrees(math.atan(t/s)))

Measured memory_bytes: 3064
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

def modperm(m, n, mod):
    p = 1
    for i in range(n):
        p = p * (m - i) % mod
    return p

def modcomb(m, n, mod):
    if n > m - n:
        n = m - n
    p = modperm(m, n, mod)
    q = pow(modperm(n, n, mod), mod - 2, mod)
    return p * q % mod

total = modcomb(H + W - 2, W - 1, MOD)

tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp

for i in range(B - 1):
    a = H - A + i
    b = i + 1
    c = W - i - 1
    d = W + A - 2 - i
#     print(a,b,c,d)
    tmp = tmp * a * c % MOD
    tmp = tmp * pow(b, MOD - 2, MOD) % MOD
    tmp = tmp * pow(d, MOD - 2, MOD) % MOD
#     print(tmp)
    total = (total - tmp) % MOD

print(total)

Measured memory_bytes: 68016
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

D = collections.Counter(A)
s=sum(A)
for i in range(Q):
  s=s-B[i]*D[B[i]]
  D[C[i]]+=D[B[i]]
  s=s+C[i]*D[B[i]]
  D[B[i]]=0
#  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(s)

Measured memory_bytes: 30228
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
prev = a[0]
count = 0
for i in range(n - 1):
    now = a[i + 1]
    if now + prev > x:
        count += now + prev - x
        prev = max(0, x - prev)
    else:
        prev = now
print(count)

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

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  while (true) {
    string Str;
    getline(cin,Str);
    if (Str=="END OF INPUT") {
      break;
    }
    if (Str=="") {
      cout<<0<<endl;
      continue;
    }
    int wordcnt=0;
    for (int i=0; i<Str.length(); i++) {
      if (Str[i]!=' ') {
	wordcnt++;
      }
      if (Str[i]==' ') {
	cout<<wordcnt<<flush;
	wordcnt=0;
      }
    }
    cout<<wordcnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3068
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main(){
 string s1,s2,s3;
   cin >> s1 >>s2 >>s3;
   
  cout << "A" << s2[0] << "C" << endl;
 return;
 }
  
int main(){
 cin.tie(nullptr);
 ios_base::sync_with_stdio(false);
 cout << fixed << setprecision(15);
 Main();
 return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  ll a = 1000000007;
  ll n,k;
  cin >> n >> k;
  ll sum = 0;
  rep(i,k,n+2){
      ll m = ((i-1)%a)*i/2%a;
      //cout << m << endl;
      ll M = ((2*n-i+1)%a)*i/2%a;
      if(M>m){
          sum += (M-m+1)%a;
      }else{
          sum += (M-m+1+a)%a;
      }
      
  }
  cout << sum %a<< endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    string s;
    cin>>n>>s;
    int ans = 0, i1 = 0, i2 = n-1;
    while(i1 < i2)
    {
        if(s[i1] == 'W')
        {
            while(i1 < i2 && s[i2] == 'W') --i2;
            if(i1 < i2 && s[i2] == 'R') {++ans; --i2;}
            else break;
        }
        ++i1;
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3756
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

int main() {
  int H, W;
  scanf("%d %d", &H, &W);

  for (int i=0; i<H; ++i) {
    char S[128];
    scanf("%s", S);

    int cur=-1;
    for (int j=0; j<W; ++j) {
      if (S[j] == 'c') {
        cur = 0;
      } else if (cur > -1) {
        ++cur;
      }

      printf("%d%c", cur, j+1<W? ' ':'\n');
    }
  }

  return 0;
}

Measured memory_bytes: 2712
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is = System.in;
	static String INPUT = "";

	public static void main(String[] args) throws Exception
	{
		int n = ni();
		int M = 1000001;
		int W = (M>>>6)+1;
		long[] f1 = new long[W];
		long[] f2 = new long[W];
		long[] ex = new long[W];
		for(int i = 0;i < n;i++){
			int v = ni();
			if(f1[v>>>6]<<~v>=0){
				f1[v>>>6] |= 1L<<v;
			}else{
				f2[v>>>6] |= 1L<<v;
			}
		}
		if(f1[0]<<~1<0){
			System.out.println((f2[0]>>>1&1)^1);
			return;
		}
		for(int i = 1;i*2 <= M;i++){
			if((f1[i>>>6]&~ex[i>>>6])<<~i<0){
				for(int j = i*2;j < M;j+=i){
					ex[j>>>6] |= 1L<<j;
				}
			}
		}
		int ans = 0;
		for(int i = 0;i < W;i++){
			ans += Long.bitCount((f1[i]^f2[i])&~ex[i]);
		}
		System.out.println(ans);
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
//		boolean minus = false;
//		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
//		if(b == '-'){
//			minus = true;
//			b = readByte();
//		}
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9')));
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return num;
//				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 33956
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

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

  string a, b;
  cin>>a>>b;

  for (int i=0; i<n; i++)
    cout<<a[i]<<b[i];
  cout<<endl;
}

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

  int t = 1;
  //cin>>t;

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

  return 0;
}



Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
main = do
  xs <- BS.getLine
  putStrLn $ if solve $ BS.reverse xs then "YES" else "NO"

solve :: BS.ByteString -> Bool
solve xs
  | BS.empty == xs = True
  | (BS.unpack $ BS.take 5 xs) == reverse "dream" = solve $ BS.drop 5 xs
  | (BS.unpack $ BS.take 7 xs) == reverse "dreamer" = solve $ BS.drop 7 xs
  | (BS.unpack $ BS.take 5 xs) == reverse "erase" = solve $ BS.drop 5 xs
  | (BS.unpack $ BS.take 6 xs) == reverse "eraser" = solve $ BS.drop 6 xs
  | otherwise = False

Measured memory_bytes: 1276
using System;

public class amon{
  public static void Main(){
    string[] str = Console.ReadLine().Split(' ');
    int n, a, b;
    n = int.Parse(str[0]);
    a = int.Parse(str[1]);
    b = int.Parse(str[2]);
    
    int cnt = Math.Min( a*n, b );
    Console.WriteLine(cnt);
  }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

#define MOD 1000000007

// (h-a+b+i-2)C(h-a-1)*(a+w-b-i-1)C(a-1)
// nCk=n!/(n-k)!k!

LL power(LL x,LL y){
  LL ans=1;
  for(int i=0;i<31;i++){
    if(y&(1<<i)) ans=ans*x%MOD;
    x=x*x%MOD;
  }
  return ans;
}

int main(){
  LL h,w,a,b;
  cin >> h >> w >> a >> b;
  LL ans=0;
  LL c1,c2;
  c1=c2=1;
  for(int i=2;i<=h-a+b-2;i++){
    c1=c1*i%MOD;
  }
  for(int i=2;i<=h-a-1;i++){
    c1=c1*power(i,MOD-2)%MOD;
  }
  for(int i=2;i<=b-1;i++){
    c1=c1*power(i,MOD-2)%MOD;
  }
  for(int i=2;i<=a+w-b-1;i++){
    c2=c2*i%MOD;
  }
  for(int i=2;i<=a-1;i++){
    c2=c2*power(i,MOD-2)%MOD;
  }
  for(int i=2;i<=w-b;i++){
    c2=c2*power(i,MOD-2)%MOD;
  }
  // cout << c1 << " " << c2 << endl;
  for(int i=1;i<=w-b;i++){
    c1=c1*(h-a+b+i-2)%MOD*power(b+i-1,MOD-2)%MOD;
    c2=c2*power(a+w-b-i,MOD-2)%MOD*(w-b-i+1)%MOD;
    // cout << c1 << " " << c2 << endl;
    ans=(ans+c1*c2%MOD)%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*  ABC145_B */
#include <stdio.h>

int main(void){
	int N = 0;
	char S[101] = "";
	scanf("%d",&N);
	scanf("%s",S);
	int i;
	if(N%2 == 1){
		printf("No");
		return 0;
	}
	int h = N/2;
	for(i=0;i<h;i++){

		if(S[i]!=S[i+h]){
			break;
		}
		if(i+1==h){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    vector<int> a(26), b(26);

    for (int i = 0; i < s.size(); i++) {
        a[s[i] - 'a']++;
        b[t[i] - 'a']++;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    bool isok = true;
    for (int i = 0; i < 26; i++)
        if (a[i] != b[i])
            isok = false;
    
    if (isok)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 916
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)1000000007
// Big two primes 
#define X 1011001110001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int int
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vii vector<pi>
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
bool compare(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int main()
{
    fio;
 
    int r;
    cin>>r;

    double d = 2 * (3.14) * r;

    cout<<d<<endl;
    rr;
}

Measured memory_bytes: 3804
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let r = it.next().unwrap();
    let g = it.next().unwrap();
    let b = it.next().unwrap();
    let rgb = r * 100 + g * 10 + b;
    if rgb % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
N=int(input())
hen={i:set([]) for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    hen[a].add(b)
    hen[b].add(a)

parent={i:-1 for i in range(1,N+1)}
parent[1]=0
q=set([])
sub=set([])
q.add(1)
while q:
    while q:
        x=q.pop()
        for p in hen[x]:
            if parent[p]==-1:
                parent[p]=x
                sub.add(p)

        if not q:
            q=sub
            sub=set([])
            break

subtreesize={i:1 for i in range(1,N+1)}
q=set([])
for i in range(1,N+1):
    if i!=1 and len(hen[i])==1:
        q.add(i)
sub=set([])
flag={i:0 for i in range(1,N+1)}
while q:
    while q:
        x=q.pop()
        p=parent[x]
        if p!=1:
            subtreesize[p]+=subtreesize[x]
            flag[p]+=1
            if flag[p]==len(hen[p])-1:
                sub.add(p)
        else:
            subtreesize[1]+=subtreesize[x]

        if not q:
            q=sub
            sub=set([])
            break

s=N
load=[N]
while s!=1:
    s=parent[s]
    load.append(s)


depth=len(load)
white=subtreesize[load[depth//2-1]]
black=N-white
if white>=black:
    print('Snuke')
else:
    print('Fennec')

Measured memory_bytes: 105060
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
      a
    } else {
      gcd(b, a % b)
    }
  }  

fn main() {
    let (a, b) = input_tuple();
    println!("{}", a * b / gcd(a, b));
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

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

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(""));
            List<Integer> numbers = new ArrayList<>();

            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }
            
            String result = "Good";
            for (int i = 0; i < numbers.size() - 1; i++) {
                if (numbers.get(i) == numbers.get(i + 1)) {
                    result = "Bad";
                    break;
                }
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22996
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,K = MI()
mod = 10**9+7

B = [i for i in range(int(N**.5)+1)]
C = [N//i for i in range(1,int(N**.5)+1)]
C.reverse()

if B[-1] == C[0]:
    del C[0]

D = B+C
A = [D[i+1]-D[i] for i in range(len(D)-1)]
a = len(A)
dp = [[0]*a for _ in range(K)]
for i in range(K):
    if i == 0:
        for j in range(a):
            if j == 0:
                dp[i][j] = A[j]
            else:
                dp[i][j] = dp[i][j-1] + A[j]
                dp[i][j] %= mod
    else:
        for j in range(a):
            if j == 0:
                dp[i][j] = dp[i-1][a-j-1]
            else:
                dp[i][j] = dp[i][j-1] + dp[i-1][a-j-1]*A[j]
                dp[i][j] %= mod

print(dp[-1][-1])


Measured memory_bytes: 126872
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(w + 1)] for _ in range(n)]

for i in range(n):
    for j in range(w + 1):
        dp[i][j] = max(dp[i-1][j], dp[i][j])
        w_ = j - wv[i][0]
        if w_ >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][w_] + wv[i][1])
print(dp[-1][-1])


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

int main() {
  string s;
  cin >> s;
  int n = s.size(), u = 1, v = 1;
  bool b = false;
  rep(i, n / 2) if(s[i] != s[n - 2 - i]) b = true;
  if(b || s[0] != '1' || s[n - 1] != '0') {
    cout << -1 << endl;
    return 0;
  }
  rep(i, n / 2 + 1) s[n / 2 + 1 + i] = '0';
  reverse(all(s));
  rep(i, n - 1) {
    v++;
    cout << u << ' ' << v << '\n';
    if(s[i + 1] == '1') u = v;
  }
}

Measured memory_bytes: 3768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


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



vector<pair<int,double> > E[100];
int n;

double prim(){
  bool used[n];
  memset(used,0,sizeof(used));
  priority_queue<pair<double,int> > Q;
  Q.push(mp(0,0));
  double ret=0;
  while(!Q.empty()){
    double cc=-Q.top().F;
    int from=Q.top().S;
    Q.pop();
    if(used[from])continue;
    used[from]=true;
    ret+=cc;
    
    rep(i,E[from].size()){
      int to=E[from][i].F;
      double co=E[from][i].S;
      if(used[to])continue;
      Q.push(mp(-co,to));
    }
  }
  return ret;
}

main(){

  while(cin>>n,n){
    double x[n],y[n],z[n],r[n];
    rep(i,n)E[i].clear();

    rep(i,n)cin>>x[i]>>y[i]>>z[i]>>r[i];

    rep(i,n){
      rep(j,i){
	double tx=x[j]-x[i],ty=y[j]-y[i],tz=z[j]-z[i];
	double len=sqrt(tx*tx+ty*ty+tz*tz);
	double cost=len-r[i]-r[j];
	if(cost<0)cost=0;
	E[i].pb(mp(j,cost));
	E[j].pb(mp(i,cost));
      }
    }

    printf("%.3f\n",prim());
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const LL INF = 1LL<<50;
const double eps = 1e-13;

int main(){
	DRI(n);
	deque<int> dq;
	REP(i,n){
		DRI(x);
		if(i%2)dq.push_front(x);
		else dq.PB(x);
	}
	if(n%2)reverse(ALL(dq));
	REP(i,n){
		if(i)printf(" ");
		printf("%d",dq[i]);
	}
}


Measured memory_bytes: 2944
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a,b,c,k,n,i;

scanf("%d%d%d",&a,&b,&c);
  scanf("%d",&k);
  
  if(c>b&&b>a){
      printf("Yes");
        return 0;
      }
  
	for(i=0;i<k;i++){
      
      
if(b<=a){
b=2*b;
  continue;
}
      if(c<=b){
      c=c*2;
        continue;
      }
      
      	}
  
  if(c>b&&b>a){
      printf("Yes");
        return 0;
      }
	printf("No");
return 0;
}


Measured memory_bytes: 1724
def solve():
    X, N = map(int, input().split())
    ps = list(map(int, input().split()))

    candidates = set(range(102))

    for p in ps:
        candidates.discard(p)

    nearest = 0
    distance = X
    for c in candidates:
        d = abs(X-c)
        if distance > d:
            nearest = c
            distance = d

    return nearest


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
#include <iostream>
#include <math.h>
#include <cstdio>

bool IsSquareNumber(int number);

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

    int N;
    std::cin >> N;

    int answer_num;
    for(answer_num = 1 ; answer_num * answer_num <= N ; answer_num++ );
    printf("%d\n",(int)pow(answer_num-1,2));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = Math.min(b / a, c);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
package main

import "fmt"

type P struct {
	f int
	l int
}

func first(num int) int {
	res := 0
	for num != 0 {
		res = num % 10
		num /= 10
	}
	return res
}

func last(num int) int {
	return num % 10
}

func main() {
	var N int
	fmt.Scan(&N)
	m := make(map[P]int)
	for a := 1; a <= N; a++ {
		f := first(a)
		l := last(a)
		m[P{f, l}]++
	}
	res := 0
	for a := 1; a <= N; a++ {
		f := first(a)
		l := last(a)
		p := P{l, f}
		res += m[p]
	}
	fmt.Println(res)
}


Measured memory_bytes: 512