akhauriyash/Code-Regression huggingface dataset:
/*
0-1 ナップザック問題
価値が vi 重さが wi であるような N 個の品物と、容量が W のナップザックがあります。次の条件を満たすように、品物を選んでナップザックに入れます：
 
選んだ品物の価値の合計をできるだけ高くする。
選んだ品物の重さの総和は W を超えない。
価値の合計の最大値を求めてください。
 
入力
１行目に２つの整数　N、W　が空白区切りで１行に与えられます。 続く N 行で i 番目の品物の価値 vi と重さ wi が空白区切りで与えられます。
 
出力
価値の合計の最大値を１行に出力してください。
 
制約
1 ≤ N ≤ 100
1 ≤ vi ≤ 1,000
1 ≤ wi ≤ 1,000
1 ≤ W ≤ 10,000
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>
 
 
using namespace std;
 
// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// 各桁の和を計算する関数
int rev(int n) {
  int a[3]={0};
  int i;
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    a[i] = n % 10;
    n /= 10;
    i++;
  }
  if (a[2]!=0) return a[0]*100+a[1]*10+a[2];
  else if (a[1]!=0) return a[0]*10+a[1];
  else return a[0];
}

const int MAX_N =100, MAX_M = 100;
int N, M;
int v[MAX_N], w[MAX_N];
int dp[MAX_N+1][MAX_M+1]; // メモ化テーブル



// i番目以降の品物から重さの総和がj以下になるように選ぶ
int rec(int n, int m){
	int i = n;
	int j = m;
	// printf("case5 %d, %d\n", i, j);
	if (i<j) swap(i, j);
	// printf("case6 %d, %d\n", i, j);
	if (dp[i][j]!=-1){
		// 既に調べたことがあるならばその結果を再利用
		return dp[i][j];
	}
	if (dp[i][j]==5){
		// 既に調べたことがあるならばその結果を再利用
		return 1;
	}
	int res;
	// jが0ならfalse
	if (j==0) res = 0;
	else{
		// printf("case7 %d, %d\n", i, j);
		j = rev(j);
		// printf("case4 %d, %d\n", i, j);
		if (i<j) swap(i, j);
		i = i-j;
		// printf("case1 %d, %d\n", i, j);
		if (i<j) swap(i, j);
		// printf("case2 %d, %d\n", i, j);
		if (i==n && j==m) return dp[n][m] = 1;
		else{
			// printf("rec(%d, %d)\n", i, j);
			dp[n][m] =5;
			res = rec(i,j);
			// printf("here\n");
		}
	}
	return dp[n][m] =res;
	// else printf("case3 %d, %d\n", i, j);
	// return 0;
}
 
int main() {
	// 入力
	ll X, A, B;
	cin >> X >> A >> B;
 
	// 解法
	ll ans = X - A;
	
	while (ans-B>=0){
		ans -= B;
	}
	cout << ans << endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    for(int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		reader.readLine();

		List<String> a = Arrays.asList(reader.readLine().split(" "));
		Collections.reverse(a);

		System.out.println(String.join(" ", a));
	}
}



Measured memory_bytes: 24520
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S >> T;

    int ans = 0;
    string s = "";
    int i = 0;
    while (1) {
        ll len = T.length() + 1LL * (T.length() + 1) * s.length();
        if (S.length() < len) break;

        i++;
        string ss = "";
        fore(c, T) ss += s + c;
        ss += s;
        s = ss;

        int j = 0;
        fore(c, S) {
            if (j < s.length()) {
                if (c == s[j]) j++;
            }
        }
        if (j == s.length()) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
struct card{char suit,value;};
void bubble(struct card a[],int n){
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i;j--){
            if(a[j].value<a[j-1].value){
                card t=a[j];a[j]=a[j-1];a[j-1]=t;
            }
        }
    }
}void selection(struct card a[],int n){
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j].value<a[minj].value){
                minj=j;
            }

        }
        card t=a[i];a[i]=a[minj];a[minj]=t;
    }
}
void print(struct card a[],int n){
    for(int i=0;i<n;i++){
        if(i>0) cout<<" ";
        cout<<a[i].suit<<a[i].value;
    }
    cout<<endl;
}
bool isstable(struct card c1[],struct card c2[],int n){
    for(int i=0;i<n;i++){
        if(c1[i].suit!=c2[i].suit) return false;
    }
    return true;
}
int main(){
    card c1[100],c2[100];
    int n;cin>>n;
    for(int i=0;i<n;i++){
        cin>>c1[i].suit>>c1[i].value;
        c2[i]=c1[i];
    }
    bubble(c1,n);selection(c2,n);
    print(c1,n);
    cout<<"Stable"<<endl;
    print(c2,n);
    if(isstable(c1,c2,n)){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  vector<int> B(n, -1);
  rep(i, n) {
    int a = A[i];
    auto it = lower_bound(B.begin(), B.end(), a);
    --it;
    *it = a;
  }
  int i = 0;
  while (B[i] < 0) ++i;
  int ans = n - i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3996
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long a[200100],n,h[30],ans,sum;
string s;
int main()
{
	cin>>n;
	for(int i=0;i<=27;i++)
	{
		h[i]=i*i*156867156;
		h[i]%=1000000009;
		h[i]*=1768684;
		h[i]%=1000000009;
		h[i]*=h[i];
		h[i]%=10000000009;
	}
	for(int i=0;i<n;i++)
	{
		cin>>s;
		for(int o=0;o<s.size();o++)
		{
			a[i]+=h[s[o]-'a'];
			a[i]%=10000000000009;
		}
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	{
		if(a[i]==a[i+1])
			ans++;
		else 
		{
			sum+=(ans+1)*ans/2;
			ans=0;
		}	
	}
	sum+=(ans+1)*ans/2;
	ans=0;
	cout<<sum<<endl;
} 

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
ll n, x, y;
/******* define variable end *******/
ll solve()
{
    cin >> n >> x >> y;
    vector<vector<ll>> dist(n + 10, vector<ll>(n + 10));
    vector<ll> ans(n + 10);
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = i + 1; j <= n; j++)
        {
            if (i <= x && y <= j)
            {
                dist[i][j] = min(j - i, x - i + 1 + j - y);
            }
            else if (x < i && y <= j)
            {
                dist[i][j] = min((i - x) + 1 + (j - y), j - i);
            }
            else if (i <= x && j < y)
            {
                dist[i][j] = min(j - i, (y - j) + 1 + (x - i));
            }
            else
            {
                dist[i][j] = min(j - i, (i - x) + 1 + (y - j));
            }
            ans[dist[i][j]]++;
        }
    }
    for (ll i = 1; i < n; i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 31872
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=200001;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

ll a[N];

int main(){
  boost;

  int n;
  cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  ll p=0;
  ll ans=INF;
  for(int i=1;i<=n+1;i++){
    ans=min(ans,abs(sum-p-p));
    p+=a[i];
  }
  cout<<ans;
  return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e6 + 5;
int n, q, cnt[N][3], cntM[N], prfSum[N];
string s;
int getID(char c) {
	if (c == 'D') return 0;
	if (c == 'M') return 1;
	if (c == 'C') return 2;
	return -1;
}
int getCnt(int l, int r, char c) {
	l = max(l, 0ll);
	r = min(r, n - 1);
	int id = getID(c);
	return cnt[r][id] - (l ? cnt[l - 1][id] : 0);
}
int getPrfSum(int l, int r) {
	l = max(l, 0ll);
	r = min(r, n - 1);
	return prfSum[r] - (l ? prfSum[l - 1] : 0);
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s >> q;
	fw (i, 0, n) {
		fw (j, 0, 3) cnt[i][j] = i ? cnt[i - 1][j] : 0;
		if (getID(s[i]) != -1) cnt[i][getID(s[i])]++;
	}
	fw (i, 0, n) {
		if (s[i] != 'C') cntM[i] = 0;
		else cntM[i] = cnt[i][getID('M')];
	}
	fw (i, 0, n) prfSum[i] = (i ? prfSum[i - 1] : 0) + cntM[i];
	while (q--) {
		int k;
		cin >> k;
		//Fix d at pos x. Count number of indices i, j so that x < i < j < x + k by inclusion - exclusion.
		int ans = 0;
		fw (i, 0, n) if (s[i] == 'D') {
//			cout << "i = " << i << "\n";
			int cntC = getCnt(i, i + k - 1, 'C');
			int cntMC = getPrfSum(i, i + k - 1);
			//Now get rid of cases which M lies below i.
			int mBelow = cnt[i][getID('M')] * cntC;
			ans += cntMC - mBelow;
//			cout << "CntC = " << cntC << " cntMC = " << cntMC << " mBelow = " << cnt[i][getID('M')] << "\n";
		}
		cout << ans << "\n";
	}
	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  bool isDouble = false;
  if(N%2 == 1) isDouble = false;
  else{
    string S1, S2;
    S1 = S.substr(0,N/2);
    S2 = S.substr(N/2);
    if(S1==S2) isDouble = true;
    else isDouble = false;
  }
  if(isDouble) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

double deg_to_rad( double deg ) {
    return (deg*M_PI)/180;
}

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double hh = 360*h/12+(30*m/60);
    double mm = 360*m/60;

    double deg = abs(hh-mm);
    deg = min(deg, 360-deg);
    deg = deg_to_rad(deg);

    double ans = a*a+b*b-2*a*b*cos(deg);
    ans = sqrt(ans);

    cout << setprecision(20) << ans << endl;
    return 0;
}


Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef double ld;
const int N = 200001;
int a[N], b[N];

int main()
{
   // freopen("in.txt", "r", stdin);
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i], sum -= a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i], sum += b[i];
    ll x = 0, y = 0;
    for (int i = 0; i < n; i++)
        if (a[i] < b[i])
        {
            x += (b[i] - a[i]) / 2;
            if (b[i] % 2 != a[i] % 2)
                y++;
        }
        else
            y += a[i] - b[i];
    x = max(x, y);
    if (sum - x < 0)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 384
#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>;

constexpr lli mod197 = 1000000007LL;
constexpr 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;
}

int main(void) {

	lli N;
	cin >> N;

	COUT(N * (N + 1) / 2);

	return 0;
}

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

int N, M;
int k[11];
int s[11][11];
int p[11];
int main(){
	
  	cin >> N >> M;
  	for(int i=0; i<M; i++){
    	cin >> k[i];
        for(int j=0; j<k[i]; j++){
        	cin >> s[i][j];
          	s[i][j]--;
        }
    }
    for(int i=0; i<M; i++){
    	cin >> p[i];
    }
  	int ans = 0;
  	for (int i=0; i<(1<<N); i++){
      	int cnt = 0;
        for(int j=0; j<M; j++){
          	int tmp=0;
         	for(int l=0; l<k[j]; l++){
            	if((1<<s[j][l]) & i){
            		tmp++;
            	}
            }
          	if(tmp % 2 == p[j]){
            	cnt++;
            }
        }
      	if(cnt == M) ans++;
    }
    cout << ans << endl; 
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

map<Pi, Pi> futon;
map<Pi, int> dir;

#define HEAD 0
#define FOOT 1

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

bool bfs(map<Pi, Pi>::iterator it)
{
  queue< map<Pi, Pi>::iterator > que; // Head pos
  que.push(it);
  dir[it->F] = HEAD;
  dir[it->S] = FOOT;
  while(!que.empty()) {
    auto itr = que.front(); que.pop();
    Pi p = itr->F, q = itr->S;
    //cout << p.F << " " << p.S << " " << q.F << " " << q.S << endl;
    rep(i, 4) {
      Pi r = Pi(p.F+dx[i], p.S+dy[i]);
      if(r == q) continue;
      if(futon.find(r) == futon.end()) continue;
      if(dir.find(r) == dir.end()) {
	auto itr2 = futon.find(r);
	que.push(itr2);
	dir[itr2->F] = HEAD;
	dir[itr2->S] = FOOT;
      } else {
	auto itr2 = dir.find(r);
	//cout << (itr2->F).F << " " << (itr2->F).S << endl;
	if(itr2->S == FOOT) return false;
	else continue;
      }
    }
    rep(i, 4) {
      Pi r = Pi(q.F+dx[i], q.S+dy[i]);
      if(r == p) continue;
      if(futon.find(r) == futon.end()) continue;
      if(dir.find(r) == dir.end()) {
	auto itr2 = futon.find(r);
	auto itr3 = futon.find(itr2->S);
	que.push(itr3);
	dir[itr3->F] = HEAD;
	dir[itr3->S] = FOOT;
      } else {
	auto itr2 = dir.find(r);
	//cout << (itr2->F).F << " " << (itr2->F).S << endl;
	if(itr2->S == HEAD) return false;
	else continue;
      }
    }
  }
  return true;
}

int main()
{
  int n;
  while(cin >> n, n) {
    futon.clear();
    dir.clear();
    rep(i, n) {
      int x, y; char d;
      cin >> x >> y >> d;
      if(d == 'x') {
	futon[Pi(x, y)] = Pi(x+1, y);
	futon[Pi(x+1, y)] = Pi(x, y);
      } else if(d == 'y') {
	futon[Pi(x, y)] = Pi(x, y+1);
	futon[Pi(x, y+1)] = Pi(x, y);
      }
    }
    bool flag = true;
    for(auto it = futon.begin(); it != futon.end() && flag; it++) {
      if(dir.find(it->F) == dir.end()) {
	if(!bfs(it)) flag = false;
      }
    }
    cout << (flag ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 8124
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int H,W,h,w;
    cin >> H >> W >> h >> w;

    if(H%h==0 && W%w==0){
        cout << "No" << endl;
        return 0;
    }

    ll a[H][W];
    ll sum = 0;
    rep(i,H){
        rep(j,W){
            if((i+1)%h==0 && (j+1)%w==0){
                a[i][j] = -100000000;
            }else if(i%h==0 && j%w==0){
                a[i][j] = 99999999;
            }else{
                a[i][j] = 0;
            }
            sum += a[i][j];
        }
    }

    if(sum<=0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        rep(i,H){
            rep(j,W){
                if(j==W-1){
                    cout << a[i][j] << endl;
                }else{
                    cout << a[i][j] << ' ';
                }
            }
        }
    }


    return 0;
}
 
 


Measured memory_bytes: 4608
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int l= sc.nextInt();
      	int r = sc.nextInt();
      	int d = sc.nextInt();
      	int p;
      	if(l%d==0){p=l/d-1;}
      	else{p=l/d;}
      	System.out.println(""+((r/d)-p));
}
}

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

using namespace std;

int main(){
    int K, S;
    cin >> K >> S;

    int res = 0;
    for (int i = 0; i <= K; i++){
        for (int j = 0; j <= K; j++){
            int z = S - i - j;
            if (z >= 0 && z <= K)
                res++;
        }
    }


    cout << res << endl;
}



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

int main(void){
	int i,j;
  	int count = 0;
  	int flag = 0;
	char S[101];
  	scanf("%s",&S);
  	int D[strlen(S)];
  	for(i=0;i<strlen(S);i++){
    	for(j=0;j<strlen(S);j++){
        	if(S[i]==S[j])count++;
        }
      D[i]=count;
      count=0;
    }
  
  	for(i=0;i<strlen(S);i++){
    	if(D[i]%2!=0)flag=1;
    }
  	
  	if(flag==0)printf("Yes\n");
  	else printf("No\n");
  	return 0;
}


Measured memory_bytes: 1660
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_PRM_MAX		1000									// 最大素数
#define D_MOD			1000000007								// 除数

// 内部構造体 - 素数情報
typedef struct Prm {
	int miVal;													// 値
	int miCnt;													// 数
} Prm;

// 内部変数
static int siN;													// 整数N
static Prm sz1Prm[D_PRM_MAX];									// 素数リスト
static int siPCnt;												// 素数リスト数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 素数で割れるかチェック
int
fChkDiv(
	int piVal					// <I> 値
)
{
	int i;

	for (i = 0; i < siPCnt; i++) {
		if (piVal % sz1Prm[i].miVal == 0) {
			return i;
		}
	}

	return -1;
}

// 素数リストの作成
int
fMakePrm(
)
{
	int i;

	// 初期値
	siPCnt = 0;

	// 2
	if (siN < 2) {
		return 0;
	}
	sz1Prm[0].miVal = 2;
	sz1Prm[0].miCnt = 1;
	siPCnt = 1;

	// 順にチェック
	for (i = 3; i <= siN; i++) {
		int liVal = i;

		// 素数で割れるかチェック
		while (1) {
			int liNo = fChkDiv(liVal);
			if (liNo < 0) {					// 割れない
				break;
			}

			// 割る
			liVal /= sz1Prm[liNo].miVal;
			sz1Prm[liNo].miCnt++;
		}
		if (liVal != i) {				// 割れた
			continue;
		}

		// 素数追加
		sz1Prm[siPCnt].miVal = liVal;
		sz1Prm[siPCnt].miCnt = 1;
		siPCnt++;
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// N取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siN);

	// 素数リストの作成
	fMakePrm();

	// パターン数
	long long llPtn = 1;
	for (i = 0; i < siPCnt; i++) {
		llPtn *= (long long)(sz1Prm[i].miCnt + 1);
		llPtn %= (long long)D_MOD;
	}

	// 結果セット
	sprintf(lc1Out, "%lld\n", llPtn);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

int main(){
    int N;
    cin >> N;
    int count = 0;
    for(int i = 0;i < N;i++){
        int ai;
        cin >> ai;
        if(ai&1) count++;
    }
    if(count&1) cout << "NO" << endl;
    else    cout << "YES" << endl;
}

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

int main()
{
    int64_t ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    int64_t ans =
        (ai / 2 * 2) + ao + (aj / 2 * 2) + (al / 2 * 2);

    if (ai > 0 && aj > 0 && al > 0) {
        int64_t cur = ((ai - 1) / 2 * 2) + ao + ((aj - 1) / 2 * 2) + ((al - 1) / 2 * 2) + 3;
        ans = max(ans, cur);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	  String s=sc.next();
	  int freq[]=new int[27];
	  for(int i=0;i<s.length();i++) {
	    freq[s.charAt(i)-'a']++;
	  }
	  for(int i=0;i<27;i++) {
	    if(freq[i]>1) {
	      System.out.println("no");
	      return;
	    }
	  }
	  System.out.println("yes");
	}

static long nCr(int n, int r, 
    int p) 
{ 


if (r == 0) 
return 1; 


int[] fac = new int[n + 1]; 
fac[0] = 1; 

for (int i = 1; i <= n; i++) 
fac[i] = fac[i - 1] * i % p; 

return (fac[n] * modInverse(fac[r], p) 
% p * modInverse(fac[n - r], p) 
% p) 
% p; 
} 
static long modInverse(int n, int p) 
{ 
    return pow(n, p - 2)%mod; 
} 
static long pow(long x,long y) {
  long res=1l;
  while(y!=0) {
    if(y%2==1) {
      res=x*res%mod;
    }
    y/=2;
    x=x*x%mod;
  }
  return res;
} 
}




Measured memory_bytes: 35856
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define INF (1<<30)+100
using namespace std;
ifstream fin("");
ofstream fout("");
 
int n, k, x, y, z;
vector<int> v;

int main() {
	cin>>n>>k;
	for(int i=0; i<n; i++)
	{
		cin>>x;
		y+=x;
		v.pb(x);
	}
	sort(v.begin(), v.end(), greater<int>() );
	
	if(v[k-1] < ceil(1.0*y/(4.0*k)))
		cout<<"No\n";
	else
		cout<<"Yes\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
char s[200], t[300];
int main() {
	scanf("%s%s", s+1, t+1);
	int n = strlen(s+1);
	for(int i=1;i<=n;i++)t[i+n] = t[i];
	for(int i=1;i<=n;i++) {
		bool flag = 0;
		for(int j=i+1, k = 1;j<=i+n;j++, k ++ ) {
			if(s[k] != t[j]) flag = 1;
		}
		if(!flag) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 256
//LETS START AGAIN
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = '@'+s;
    int b[n+1]={};
    int ans = 1e18;
    int aa = 0,bb = 0;
    for(int i=1;i<=n;i++)
    {
        if(s[i] == '#')
        {
            b[i] = b[i-1]+1;
            bb++;
        }
        else 
        {
            b[i] = b[i-1];
            aa++;
        }
    }
    for(int i=0;i<=n;i++)
    {
        int wleft = i-b[i];
        int bleft = b[i];
        int wright = aa-wleft;
        int bright = bb - bleft;
        int cnt = bleft+wright;
        ans = min(ans,cnt);
    }
    cout<<ans;
} 



Measured memory_bytes: 2128
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

a = 0
b = 0
idx = 1
for i in list(itertools.permutations(range(1, n+1))):
  if p == list(i):
    a = idx
  if q == list(i):
    b = idx
    
  if a > 0 and b > 0:
    break
  idx+=1
  
print(abs(a-b))
  

Measured memory_bytes: 8052
import java.util.Scanner;

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

		long[] num = new long[6];

		loop: while (true) {
			for (int i = 0; i < num.length; ++i) {
				num[i] = Integer.parseInt(sc.next());
			}
			if (max(num) != 0) {
				System.out.println(lcm(calc(num)));
			} else {
				break loop;
			}
		}
	}

	private static long[] calc(long... num) {
		long[] no = new long[(int)num.length / 2];
		for (int i = 0; i < num.length; i += 2) {
			long val = 1;
			int a = i, m = i + 1, count = 0;
			do {
				val = (num[a] * val) % num[m];
				++count;
			} while (val != 1);
			no[i / 2] = count;
		}
		return no;
	}

	private static long lcm(long... num) {
		long max = max(num);
		for (long i = 2; i <= max; ++i) {
			long[] no = mod0(i, num.clone());
			if (no != null) {
				return i * lcm(no);
			}
		}
		long sum = 1;
		for (long n : num) {
			sum *= n;
		}
		return sum;
	}

	private static long[] mod0(long n, long... num) {
		long flag = 0;
		for (int i = 0; i < num.length; ++i) {
			if (num[i] % n == 0) {
				num[i] /= n;
				++flag;
			}
		}
		if (1 < flag) {
			return num;
		} else {
			return null;
		}
	}

	private static long max(long... num) {
		long max = 0;
		for (long n : num) {
			if (max < n) {
				max = n;
			}
		}
		return max;
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
double w,h,x,y;
  cin >>w>> h>> x >> y;
auto ans = w*h/2;
  
  if(x==w/2.0 && y==h/2.0)
    cout << ans << " "<< 1  <<endl;
  else
    cout << ans << " "<<0<<endl;
}


Measured memory_bytes: 256
// MOHIT KUMAR 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pin;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

#define ff(i, a, b) for ( ll i=a; i<(b); i++)
#define ffd(i, a, b) for ( ll i=a; i<= b; i++)
#define fr(i, a, b) for ( ll i = (b)-1; i >= a; i--)
#define ffr(i, a, b) for ( ll i = b ; i >= a; i--)
#define vl vector < ll > 
#define vp vector < pl > 
#define endl "\n"
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const ld pi = acos(-1) ;
const ll maxn = 1e5 + 5 ;
const int mod = 1073741824 ;
const ll INF = 1e18 ;
const int MX = 2000000001 ; // check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0) ,cin.tie(0);
  ll t, q, n, a, b, c, d, k = 0, l, m, r,  x = 0, y = 0, z = 0 , sum = 0, ans = 0, temp = 0, res = 1 ;
  cin >> n >> m ;
 cout << n * m ;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes" : "No");
}





Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
ll ar[40];
bool use[40];
bool table[40][40];
int n;

void solv() {
	
	ll n;
	cin >> n;
	ll a[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll b[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> b[i];
	}

	ll ar[100010];
	for (size_t i = 0; i < n; i++)
	{
		ar[i] = a[i] - b[i];
	}
	sort(ar, ar + n);
	reverse(ar, ar + n);
	ll f = 0;
	ll t = n - 1;
	ll use[100010];
	fill(use, use + n, false);
	while (f < t)
	{
		while (ar[f] > 0)
		{
			if (ar[t] >= 0) break;
			ll v = min(ar[f],abs(ar[t]));
			ar[f] -= v;
			ar[t] += v;
			use[f] = true;
			use[t] = true;

			if (ar[t] >= 0) t--;
		}

		f++;
	}
	ll res = 0;

	for (size_t i = 0; i < n; i++)
	{
		if (ar[i] < 0) {
			cout << -1 << endl;
			return;
		}
		res += use[i];
	}
	cout << res << endl;
}




int main() {
	solv();

	return 0;
}


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

using namespace std;

void dfs(int n, vector<vector<int> > &G, int s, int *d, int *f, int &t) {
    d[s] = t++;
    for (int i = 0; i < G[s].size(); i++) {
        int v = G[s][i];
        
        if (d[v] != -1)
            continue;

        dfs(n, G, v, d, f, t);
    }
    f[s] = t++;
}

int main() {
    int n, u, k, v;
    cin >> n;
    vector<vector<int> > G(n);
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[i].push_back(v-1);
        }
    }

    int *f = new int[n], *d = new int[n];
    for (int i = 0; i < n; i++)
        f[i] = d[i] = -1;

    int t = 1;
    for (int i = 0; i < n; i++) {
        if (d[i] == -1)
            dfs(n, G, i, d, f, t);
    }

    for (int i = 0; i < n; i++) 
        cout << i+1 << " " << d[i] << " " << f[i] << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

void solve()
{
   ll n,k;
   cin>>n>>k;
   ll arr[n+1];
   for(int i=0;i<n;i++)
    cin>>arr[i];
   sort(arr,arr+n);
   ll sum=0,i=0;
   while(k--)
   {
       sum+=arr[i++];
   }
   cout<<sum<<endl;

}
int main()
{

    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



}





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

int main(void)
{
    int N;
    cin >> N;
    vector<int> a(N+1);
    for (size_t i = 1; i < a.size(); i++) {
        cin >> a[i];
    }

    vector<int> c(N+1, 0);
    vector<int> s(N+1, 0);
    for (size_t n = N; n > 0; n--) {
        // ボールを入れる
        if (s[n] % 2 != a[n]) {
            c[n]++;
            for (size_t i = 1; i*i <= n; i++) {
                if (n % i == 0) {
                    s[i]++;
                    if (i * i != n) s[n/i]++;
                }
            }
        }
    }
    vector<int> b;
    for (size_t i = 1; i < c.size(); i++) {
        if (c[i] == 1) b.push_back(i);
    }
    cout << b.size() << endl;
    for (size_t i = 0; i < b.size(); i++) {
        if (i == b.size() - 1) cout << b[i] << endl;
        else cout << b[i] << " ";
    }

    return 0;
}



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

#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;

ll N;
ll cnt;
ll p[55];
ll s[55];


int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

bool c=true;
rep(i,N){
	cin>>p[i];
	if(p[i]!=i+1) c=false;
}
if(c){
	cout<<"YES"<<endl; 
	return 0;
}


rep(i,N){
	rep(j,N){
		if(i<j){
			rep(k,N){
				s[k]=p[k];
			}
			swap(s[i],s[j]);
			bool chk=true;
			rep(k,N){
				if(s[k]!=k+1){
					chk=false;
				}
			}
			if(chk){
				cout<<"YES"<<endl; 
				return 0;
			}
		}
	}
}

cout<<"NO"<<endl;

}
	


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    H, W = [int(item) for item in input().split()]
    grid = [input() for _ in range(H)]
    
    print('#'*(W+2))
    for line in grid:
        print('#' + line + '#')
    print('#'*(W+2))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9192
import sys

#+++++
		
def main():
	h,w = map(int, input().split())
	print('#'*(w+2))
	for _ in range(h):
		s = '#'+input()+'#'
		print(s)
	print('#'*(w+2))		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> S(N + 1);
    for(int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        A--;
        S[i + 1] = (S[i] + A) % K;
    }

    map<int, int> mp;
    int j = 0;
    ll ans = 0;
    for(int i = 0; i <= N; ++i) {
        if(i - j >= K) {
            mp[(S[j] % K + K) % K]--;
            j++;
        }
        int tmp = (S[i] % K + K) % K;
        ans += mp[tmp];
        mp[tmp]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10368
input_lines2 = gets.chop.split("").map(&:to_s)
mozi = ""
finish = true
for row  in 0...input_lines2.size
    mozi = input_lines2[row]
    if mozi != "U" && mozi != "D" 
        if (mozi != "R" && row%2 == 0) || (mozi != "L" && row%2 == 1)
            finish = false
        end
    end
end

if finish
    puts "Yes"
else
    puts "No"
end
    

Measured memory_bytes: 1788
N,M,K=map(int,input().split())
mod=998244353

  
def genCombinationFunction(max_k,mod):
    modinv_table = [-1] * (max_k+1)
    modinv_table[1] = 1
    for i in range(2, max_k+1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

    def binomial_coefficients(n, k):
        ans = 1
        for i in range(k):
            ans *= n-i
            ans *= modinv_table[i + 1]
            ans %= mod
        return ans
    return binomial_coefficients,modinv_table
f,table=genCombinationFunction(10**6,mod)

ans=0
C=1
for i in range(K+1):
  base=M*pow(M-1,N-i-1,mod)
  if i:
    C*=N-i
    C*=table[i]
    C%=mod
  ans+=C*base
  #print((f(N-1,i)%mod)==C,f(N-1,i),C,)
  ans%=mod
print(ans)

Measured memory_bytes: 48392
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int dp[2005][2005];

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

    int n; cin >> n;
    std::vector<ll> a(n+1); rep(i,n+1) cin >> a[i];
    std::vector<ll> b(n); rep(i,n) cin >> b[i];


    std::vector<ll> temp_a = a;
    std::vector<ll> temp_b = b; temp_b.push_back(0LL);

    ll lft = 0LL, rgt = 0LL;

    rep(i,n+1){
        lft+=min(temp_a[i], temp_b[i]);
        if(temp_b[i] > temp_a[i] && i != n){
            if(temp_a[i+1] >= temp_b[i]-temp_a[i]){
                temp_a[i+1] -= temp_b[i]-temp_a[i];
                lft += temp_b[i]-temp_a[i];
            } else {
                lft += temp_a[i+1];
                temp_a[i+1] = 0;
            }
        }
    }


    temp_a = a; reverse(temp_a.begin(), temp_a.end());
    temp_b = {0LL}; rep(i,n){temp_b.push_back(b[i]);} reverse(temp_b.begin(), temp_b.end());


    rep(i,n+1){
        rgt+=min(temp_a[i], temp_b[i]);
        if(temp_b[i] > temp_a[i] && i != n){
            if(temp_a[i+1] >= temp_b[i]-temp_a[i]){
                temp_a[i+1] -= temp_b[i]-temp_a[i];
                rgt += temp_b[i]-temp_a[i];
            } else {
                rgt += temp_a[i+1];
                temp_a[i+1] = 0;
            }
        }
    }

    //cout << lft << " " << rgt << endl;
    
    cout << max(lft, rgt) << endl;

    return 0;
}

Measured memory_bytes: 4224
import sys
import numpy as np
from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    house_list = []
    for i in range(N):
        house_list.append(int(input_raw[i]))

    house_list.sort(reverse=True)
    dist = 0
    for i in range(N - 1):
        dist += house_list[i] - house_list[i + 1]

    print dist



if __name__ == '__main__':
    main()


Measured memory_bytes: 19180
fun main(args: Array<String>) {
    val (a, b, c, k) = readLine()!!.split(' ').map { it.toLong() }
    var d = k
    var ans = Math.min(a,d)

    d -= a
    d -= b
    if (d > 0) {
        ans -= d
    }

    println(ans)

}


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

int main() {
    
  while(true){
    int H,W;
    cin >> H >>W;
    
    if(H==0 && W==0) break;
    
    for(int i= 0; i < H; i++){
      for(int j=0; j < W; j++){
        if(j==W-1) cout << "#" << endl;
        else cout << "#";
      }
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int N,D;
	cin >> N >> D;
	vector<vector<int>> vec(N,vector<int> (D));
	for(int i = 0;i < N;i++) {
		for(int j = 0;j < D;j++) {
			cin >> vec.at(i).at(j);
		}
	}
	int answer = 0;
	for(int i = 0;i < N - 1;i++) {
		for(int j = i + 1;j < N;j++) {
			int count = 0;
			for(int k = 0;k < D;k++) {
				count += (vec.at(i).at(k) - vec.at(j).at(k)) * (vec.at(i).at(k) - vec.at(j).at(k));
			}
			if(floor(sqrt(count)) * floor(sqrt(count)) == count ) {
				answer++;
			}
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n;
    cin >> n;
    int cnt = 0, x = 0, y = 0, z = 0;
    rep(i,n){
        string s;
        cin >> s;
        int m = s.size();
        rep(j,m-1){
            if (s[j] == 'A' && s[j+1] == 'B'){
                cnt++;
            }
        }
        if (s[0] == 'B' && s.back() == 'A') {
            y++;
        } else if (s.back() == 'A') {
            x++;
        } else if (s[0] == 'B') {
            z++;
        }
    }
    if (y >= 1) {
        cnt += y-1;
        // y = 1;
        if (x) {
            x--;
            cnt ++;
        }
        if (z) {
            z--;
            cnt ++;
        }
    }
    cnt += min(x,z);
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
const double EPS = 1e-10;
const double PI = acos(-1.0);



const int n = 151;
vector<vector<int>> a(n, vector<int>(n));

void init(){
	for(int i=1;i<n;++i) for(int j=i+1;j<n;++j){
		a[i][j] = i * i + j * j;
	}
}

bool solve(){
	int h, w;
	cin>> h>> w;
	if(!h && !w) return false;

	int x = h * h + w * w;
	pii ans(n, n);
	for(int i=1;i<n;++i){
		for(int j=i+1;j<n;++j){
			int y = i*i + j*j;
			if((i <= h && y == x) || y < x) continue;
			if(y < ans.first * ans.first + ans.second * ans.second){
				int j = (int)sqrt(y - i * i);
				ans = pii(i, j);
			}
		}
	}
	cout<< ans.first<< " "<< ans.second<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	init();
	while(solve());
	return 0;
}

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

int d[50];

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

	long long sum=0;
	for(int i=0;i<n;i++){
		for(int j=i+1; j<n;j++){
			sum+=(d[i]*d[j]);
		}
	}
	cout<<sum<<endl;


	return 0;
}


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

using namespace std;

int N, col[109];
char sir[109];
long long ans = 0;

int nodes = 1, son[6000009][26], cnt[6000009];

void add (vector < int > &curr, bool type)
{
    int q = 1;
    if (type == 0)
    {
        /*printf ("+ ");
        for (auto j : curr)
            printf ("%d", j);
        printf ("\n");*/
        for (auto j : curr)
        {
            if (son[q][j] == 0)
                son[q][j] = ++nodes;
            q = son[q][j];
        }
        cnt[q] ++;
    }
    else
    {
/*        printf ("Q ");
        for (auto j : curr)
            printf ("%d", j);*/
        for (auto j : curr)
        {
            if (son[q][j] == 0)
            {
                //printf ("\n");
                return ;
            }
            q = son[q][j];
        }
        ans += cnt[q];
//        printf ("-> %d\n", cnt[q]);
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n%s", &N, sir + 1);
for (int i=1; i<=2 * N; i++)
    sir[i] -= 'a';
for (int msk = 0; msk < (1 << N); msk ++)
{
    for (int i=0; i<N; i++)
        col[i + 1] = (msk >> i) & 1;
    vector < int > curr;
    int l = 0;
    for (int i=1; i<=N; i++)
        if (col[i]) curr.push_back (sir[i]), l ++;
    for (int i=N; i>=1; i--)
        if (!col[i]) curr.push_back (sir[i]);
    curr.push_back (l);
    add (curr, 0);
}
for (int msk = 0; msk < (1 << N); msk ++)
{
    for (int i=0; i<N; i++)
        col[i + 1 + N] = (msk >> i) & 1;
    vector < int > curr;
    int l = 0;
    for (int i=2 * N; i>N; i--)
        if (!col[i]) curr.push_back (sir[i]), l ++;
    for (int i=N + 1; i<=2 * N; i++)
        if (col[i]) curr.push_back (sir[i]);
    curr.push_back (l);
    add (curr, 1);
}
printf ("%lld\n", ans);
return 0;
}


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

int main()
{
	int a,b,c,d,sum=0;
	string s;

	cin>>s;
    int acnt=0,bcnt=0,ccnt=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='a')acnt++;
        if(s[i]=='b')bcnt++;
        if(s[i]=='c')ccnt++;
    }
	if(acnt<=1 && bcnt<=1 && ccnt<=1)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
	return 0;
}
	

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

const int N = 100000;
int a[N] = { 0 };

int main() {
    int t, d, l, x, ans;
    while(cin >> t >> d >> l, t){
        ans = 0;
        for(int i = 0;i < t;++i){
            cin >> x;
            if(x >= l) {
                a[i] = d;
            }
            else {
                a[i] = i > 0 ? a[i - 1] - 1 : 0;
            }
        }
        for(int i = 0;i < t - 1;++i){
            if(a[i] > 0) {
                ++ans;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,k,q,A[200001],ans=1e18;
    cin>>n>>k>>q;
    rep(i,n) cin>>A[i];
    rep(i,n){
        vec B,C;
        ll a=0;
        rep(j,n){
            if(A[j]>=A[i]) B.push_back(A[j]);
            if(A[j]<A[i]||j==n-1){
                sort(all(B));
                rep(l,max(0,int(B.size()-k+1))) C.push_back(B[l]);
                B.clear();
            }
        }
        sort(all(C));
        if(C.size()>=q){
            rep(j,q) a=max(a,C[j]);
            ans=min(ans,a-A[i]);
        }
    }
    cout<<ans;
}

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

using namespace std;

int main()
{
	long long n,a,b;
	cin >> n >> a >> b;
	if((n==1&&a!=b)||(a>b))
		cout << 0 << endl;
	else
		cout << (a+(n-1)*b)-(b+(n-1)*a)+1 << endl;
}

Measured memory_bytes: 256
import math

D,G = map(int,input().split())
pc = [list(map(int,input().split()))for _ in range(D)]

digit = "0"+str(D)+"b"
ans = float('INF')
for i in range(2**D):
    flags = list(str(format(i,digit)))
    point = 0
    count = 0
    last0 = -1
    for j in range(D):
        if flags[j] == "1":
            point += pc[j][0]*100*(j+1) + pc[j][1]
            count += pc[j][0]
        else:
            last0 = j
    if point >= G:
        ans = min(ans,count)
    else:
        if last0 != -1:
            r = G - point
            if math.ceil(r/(100*(last0+1))) < pc[last0][0]:
                count += math.ceil(r/(100*(last0+1)))
                ans = min(ans,count)

print(ans)



Measured memory_bytes: 3064