akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

int main(){
    int r, g; cin >> r >> g;
    cout << 2*g - r << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll c = a+b;
    
    ll x = n/c;

    ll ans = a*x;

    ll y = n - c*x;

    if(y <= a) {
        ans += y;
    } 
    else {
        ans += a;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 len        PIC 9(10) VALUE 3.
01 S          PIC X(3).
01 T          PIC X(3).
01 i          PIC 9(10) VALUE ZERO COMP.
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT S.
  ACCEPT T.
  PERFORM VARYING i FROM 1 BY 1 UNTIL len < i
    IF S(i:1) = T(i:1)
      ADD 1 TO ans
    END-IF
  END-PERFORM.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


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

using namespace std;
#define int long long
#define INF 10e9
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin>>N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int>C(N);
    vector<int> a(N);
    vector<int> b(N);
    vector<int>c(N);
    cin>>a[0]>>b[0]>>c[0];
    A[0]=a[0];B[0]=b[0];C[0]=c[0];
    
    for(int i=1;i<N;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        A[i]=a[i]+max(B[i-1],C[i-1]);
        B[i]=b[i]+max(A[i-1],C[i-1]);
        C[i]=c[i]+max(B[i-1],A[i-1]);
    }
    cout<<max(A[N-1],max(B[N-1],C[N-1]));
    return 0;
    
}

Measured memory_bytes: 4992
import Text.Printf
import Data.Char

ans :: [Char] -> String -> [Int]
ans [] _ = []
ans (c:cs) text =
  (length $ filter (==c) text):(ans cs text)

main = do
  c <- getContents
  let a = ['a'..'z']
      o = ans a $ map toLower c
      t = zip a o
  mapM_ (\(a,b) -> printf "%c : %d\n" a b) t

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
   int k,s;
   cin>>k>>s;
   int ans=0;
   for(int y=0;y<=k;y++)
   {
       int val=s-y;
       for(int j=0;j<=k;j++)
       {
           if((val-j)<=k&&(val-j)>=0)
           {
               //cout<<s<<" "<<y<<" "<<j<<" "<<s-y-j<<"\n";
               ans++;
           }
       }
   }
   cout<<ans<<"\n";
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    int n,w;cin >> n >> w;
    vector<pair<int,int> > v(n);
    for(int i=0;i<n;i++){
	cin >> v[i].first >> v[i].second;
    }
    int dp[n+1][w+1] = {0};
    rep(i,n+1)rep(j,w+1)dp[i][j] = 0;
    for(int i=1;i<=n;i++){
	for(int j=0;j<=w;j++){
	   chmax(dp[i][j],dp[i-1][j]);
	   if(j>=v[i-1].second)  chmax(dp[i][j],dp[i-1][j-v[i-1].second]+v[i-1].first);
	}
    }
    cout << dp[n][w] << endl;
    return 0;
}



Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
int a[2020][2020];
// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};
int main() {
    int h, w; cin >> h >> w;
    UnionFind hf(h*w), wf(h*w);
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '.') a[i][j] = 1;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int num = i * w + j + 1;
            if (a[i][j] && a[i+1][j]) {
                hf.unite(num, num+w);
            }
            if (a[i][j] && a[i][j+1]) {
                wf.unite(num, num+1);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!a[i][j]) continue;
            int num = i*w + j + 1;
            ans = max(ans, (int) (hf.size(num) + wf.size(num)-1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int H,W;
vector<string> field;
vector<vector<int>> dp;

int main() {
  int n,a,b; cin >>n >>a >>b;
  cout <<((b-a) % 2 == 0 ? "Alice" : "Borys") <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	map<int,int> even,odd; //mapで各数列での要素の出現数を記録する
	for(int i = 0; i < n; i++){
		if(i%2==0) odd[v[i]]++;
		else even[v[i]]++;
	}

	int even_1=0,even_2=0,odd_1=0,odd_2=0;
	int e1=0,e2=0,o1=0,o2=0;
	int cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			even_1 = itr->first;
		}
	}
	e1 = cnt;
	cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt && itr->first != even_1){
			cnt = itr->second;
			even_2 = itr->first;
		}
	}
	e2 = cnt;

	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			odd_1 = itr->first;
		}
	}
	o1= cnt;
	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt && itr->first != odd_1){
			cnt = itr->second;
			odd_2 = itr->first;
		}
	}
	o2=cnt;

	if(even_1 == odd_1){
		cout << min(n-e1-o2, n-e2-o1) << endl;
	}else{
		cout << n-e1-o1 << endl;
	}

	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int numRows;
    cin >> numRows;
    int numCols;
    cin >> numCols;
    vector<string> grid;
    for(int i = 0; i < numRows; i++) {
        string row;
        cin >> row;
        grid.push_back(row);
    }

    unsigned long long mod = 1e9 + 7;

    vector<unsigned long long> numPathsTop(numCols, 0);
    int numPathsLeft = 1;

    for(int row = 0; row < numRows; row++) {
        for(int col = 0; col < numCols; col++) {
            if(grid[row][col] == '#') {
                numPathsTop[col] = 0;
            } else {
                numPathsTop[col] = (numPathsLeft + numPathsTop[col]) % mod;
            }
            numPathsLeft = numPathsTop[col];
        }
        numPathsLeft = 0;
    }

    cout << numPathsTop[numCols-1];
    
    return 0;
}

Measured memory_bytes: 4216
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0||i==H-1||j==0||j==W-1){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            cout<<"\n";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    OKawaiiKoto
    char c;
    cin>>c;
    if(c>='A'&&c<='Z') cout<<'A';
    else cout<<'a';
}


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    vll p(30, 0);
    ll mx = 1000000000000001;
    p[1] = 26;
    for (int i = 2; i < 30; i++) {
        p[i] = 26 * p[i - 1];
        if (p[i] > mx) break;
    }
    for (int i = 1; i < 30; i++) {
        p[i] += p[i - 1];
    }
    int en = 0;
    for (int i = 1; i < 30; i++) {
        if (p[i] >= n) {
            en = i;
            break;
        }
    }
    n -= p[en - 1];
    n--;
    int len = en;
    string ans;
    for (int i =  0; i < len; i++) {
        int val = n % 26;
        char c = 'a' + val;
        ans.pb(c);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3652
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-9;
const ll MOD = 100000000;
const int N = 2e6 + 10;
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
vector<int>arr(5);
int vis[5];
int ans = 1e9;
int calc(int i,int t)
{
	if (i == 5)
	{
		ans = min(ans, t);
		return 0;
	}
	while (t % 10 != 0)
		t++;
	int ans = 0;
	for (int j = 0; j < 5; j++)
	{
		if (!vis[j])
		{
			vis[j] = 1;
			calc(i + 1, t + arr[j]);
			vis[j] = 0;
		}
	}
}
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt","w",stdout);
#endif*/
	for (int i = 0; i < 5; i++)
		cin >> arr[i];
	calc(0,0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
# end,cnt
dq = deque()

(n,d,a),*xh = [list(map(int, s.split())) for s in open(0)]
xh.sort()

total_bomb = 0
eff_bomb = 0

for x,h in xh:
    while dq and dq[0][0] < x:
        end, cnt = dq.popleft()
        eff_bomb -= cnt
    resid = h - eff_bomb * a
    if resid > 0:
        cnt = 0--resid//a
        end = x + 2 * d
        dq.append((end,cnt))
        eff_bomb += cnt
        total_bomb += cnt

print(total_bomb)

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

using namespace std;
using ll = long long;

int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (2*c <= a && 2*c <= b) {
        cout << 2 * max(x, y) * c << endl;
    } else if (2*c < a+b) {
        if(x>y)cout << 2 * min(x, y) * c + min(2*c*(x-y),(x - y) * a);
      	else cout << 2 * min(x, y) * c + min(2*c*(y-x),(y - x) * b);
    } else {
        cout << x * a + y * b << endl;
    }
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	LL t[60][3][3];
	if(true) {
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 60 - 1) {
			mat_prod(t[i + 1], t[i], t[i]);
		}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, 60) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i]);
		}
	}
	
	return;
}



LL n, m, x[100002];

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c); }
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a,b,c,tmp;
    scanf("%d%d%d",&a,&b,&c);
    	if (a > b) tmp = a, a = b, b = tmp;
	if (b > c) {
		tmp = b, b = c, c = tmp;
		if (a > b) tmp = a, a = b, b = tmp;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;

}


Measured memory_bytes: 2120
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    item = [tuple(map(int,input().split())) for _ in range(N)]
    dp = [0]*(W + 1)
    for v,w in item:
        for j in range(w,W + 1):
            dp[j] = max(dp[j],dp[j - w] + v)
    print(dp[-1])
if __name__ == '__main__':
    main()



Measured memory_bytes: 5920
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
bool a[55][55];
int n,m;
queue <int> q;
bool qu()
{
    while(!q.empty()) q.pop();
    q.push(0);
    int ji=0;
    bool c[55];
    for(int i=0;i<=m;i++) c[i]=false;
    while(!q.empty())
    {
        int h;
        h=q.front(),q.pop();
        if(c[h]==true) continue;
        c[h]=true;
        ji++;
        for(int i=0;i<m;i++)
        {
            if(!a[h][i]||c[i]) continue;
            q.push(i);
        }
    }
    if(ji==n) return false;
    else return true;

}
int main()
{
    memset(a,false,sizeof(a));

    scanf("%d %d",&n,&m);
    int x[55],y[55];
    for(int i=0;i<m;i++)
    {
        scanf("%d %d",&x[i],&y[i]);
        x[i]--,y[i]--;
        a[x[i]][y[i]]=a[y[i]][x[i]]=true;
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        a[x[i]][y[i]]=a[y[i]][x[i]]=false;
        if(qu()) ans++;
        a[x[i]][y[i]]=a[y[i]][x[i]]=true;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        d=a;
        a=b;
        b=d;
    }if(a>c){
        d=c;
        c=b;
        b=a;
        a=d;
    }if(b>c){
        d=c;
        c=b;
        b=d;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int main(){
  int n,k[10005],a,b;
  while(1){
    a=0;
    b=0;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>k[i];
      if(k[i]>=2)a++;
      if(k[i]==0)b++;
    }
    if(a==0)cout<<"NA"<<"\n";
    else cout<<n+1-b<<"\n";
  }
  return 0;
}



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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //


int main(){

  ll N = il();
  vector<ll> as;
  rep(i, N){
    as.push_back(il());
  }

  // as[i] 以降の数の積
  vector<ll> cumsum(N+1, 0);

  DREP(i, N-1, -1){
    // N-1 ~ 0
    cumsum[i] = cumsum[i+1] + as[i];
    cumsum[i] %= MOD;
  }


  ll ans = 0;
  rep(i, N-1){
    // i : 0 ~ N-2
    ll tmp = as[i] * cumsum[i+1];
    tmp %= MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endk;



}

Measured memory_bytes: 6408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
  os << "{";
  rep(i, v.size()) { if(i) os << ", "; os << v[i]; }
  return os << "}";
}
// template<class t> ostream& operator<<(ostream& os, const set<t>& se) {
//   os << "{";
//   auto itr = se.begin();
//   rep(i, se.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
// template<class t, class u>
// ostream& operator<<(ostream& os, const map<t, u>& mp) {
//   os << "{";
//   auto itr = mp.begin();
//   rep(i, mp.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int X, Y;
  cin >> X >> Y;
  int ans = 0;
  if(X <= 3) ans += (4-X) * 100000;
  if(Y <= 3) ans += (4-Y) * 100000;
  if(X == 1 && Y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int a,b,c;cin>>a>>b>>c;
    int x=a+b+c;
    int m=max(a,max(b,c));
    cout<<m*9+x<<endl;
}


Measured memory_bytes: 3596
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

class BIT():
    # 作りたい要素数nで初期化, 1-index
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n+1)

    #bit_indexにxをO(log(n))で加算する
    def add(self,i,x):
        #if(i<=0 or i>n):return iに0以下の数字は代入しない
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)
    #bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    def sum(self,i):
        s = 0
        #iに0以下の数字は代入しない。
        while i > 0:
            s+=self.bit[i]
            i -= (i & -i)
        return s
    
    def rangesum(self,i,k):
        return self.sum(k) - self.sum(i)
    #a_1 + a_2 + … + a_i >= x となるような最小のiを求める(a_k >= 0)
    #xが0以下の場合は該当するものなし→0を返す
    def lower_bound(self,x):
        if x <= 0:
            return 0
        else:
            i = 0
            r = 1
            #最大としてありうる区間の長さを取得する
            #n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
            while(r<self.n):
                r=r<<1
            len = r
            while len > 0:
                if(i+len<self.n and self.bit[i+len]<x):
                    x-=self.bit[i+len]
                    i+=len
                len = len >> 1
            return i+1

def main():
    N, Q = MI()
    X, Y = BIT(N), BIT(N)
    xmin = N-2
    ymin = N-2
    X.add(1, N-2)
    X.add(N-1, -(N-2))
    Y.add(1, N-2)
    Y.add(N-1, -(N-2))

    res = (N-2)**2
    for i in range(Q):
        a, b = MI()
        if a == 1:
            x = X.sum(b-1)
            if ymin > b-2:
                temp = Y.sum(1)
                Y.add(1, b-2-temp)
                Y.add(xmin+1, -(b-2-temp))
                ymin = b-2
            res -= x
        else:
            y = Y.sum(b-1)
            if xmin > b-2:
                temp = X.sum(1)
                X.add(1, b-2-temp)
                X.add(ymin+1, -(b-2-temp))
                xmin = b-2
            res -= y
            
    print(res)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 77592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
 
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
 
#include <functional>
#include <cassert>
 
typedef long long ll;
using namespace std;
 
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010
 
 
int main(){
  int n;
  vector<int> G[200];
  
  scanf("%d", &n);
 
  for(int i=0;i<n;i++){
    int u, k, v;
 
    scanf("%d%d", &u, &k);
    u--;
     
    for(int j=0;j<k;j++){
      scanf("%d", &v);
      v--;
      G[u].push_back(v);
    }
  }
 
  queue<int> q1, q2;
  bool visited[200] = {};
  int ans[200];
 
  for(int i=0;i<n;i++) ans[i] = -1;
   
  q1.push(0);
 
  for(int i=0;q1.size();i++){
 
    while(q1.size()){
      int p = q1.front();
      q1.pop();
 
      if(visited[p]) continue;
      visited[p] = true;
 
      ans[p] = i;
       
      for(int j=0;j<G[p].size();j++){
        q2.push(G[p][j]);
      }
    }
 
    q1 = q2;
    q2 = queue<int>();
  }
 
  for(int i=0;i<n;i++)
    printf("%d %d\n", i+1, ans[i]);
   
  return 0;
}



Measured memory_bytes: 3268
#include <iostream>
using namespace std;
int main() {
    int A, B, C;
    while (cin >> A >> B >> C) {
        if ((A == B && A != C) || (A == C && A != B) || (B == C && B != A))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; }
template<class T, class U> bool chmin(T &a, U b) { if (a > b) a = b; return true; }

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

constexpr ll MOD = 1000000007;

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

  int n; cin >> n;
  string s; cin >> s;

  int r = 0;
  rep(i, n) if (s[i] == 'R') ++r;

  int ans = 0;
  rep(i, r) if (s[i] == 'W') ++ans;

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3732
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    int n, c = 0;
    for (;;) {
        n += ++c;
        if (n == N) break;
        if (n > N) {
            writeln("No");
            return;
        }
    }

    int[][] r;
    r.length = c+1;
    int i;
    n = 0;
    while (n < N) {
        auto m = n + 1;
        foreach (d; m..m+c) r[i] ~= d;
        foreach (j; i+1..i+c+1) r[j] ~= m++;
        n += c;
        c--;
        i++;
    }
    writeln("Yes");
    writeln(r.length);
    foreach (l; r) {
        writeln(l.length, " ", l.to!(string[]).join(" "));
    }
}

Measured memory_bytes: 9596
import java.util.Scanner;

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

		while(true){
			int H = stdIn.nextInt();
			int W = stdIn.nextInt();

			if( H == 0 && W == 0) {
				break;
			}

			for (int i = 0; i < H; i ++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
		stdIn.close();

	}
}



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

int main(){
  char aph[26]{};
  string s;
  cin >> s;
  for(char c:s)aph[c-'a']++;
  for(int i=0; i<26; i++){
    if(!aph[i]){
      cout << (char)(i+'a');
      return 0;
    }
  }
  cout << "None";
  return 0;
}

Measured memory_bytes: 512
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes = sieve(50000)
ret = [0] * 50001
for i in xrange(len(primes)):
    for j in xrange(i, len(primes)):
        tmp = primes[i] + primes[j]
        if tmp > 50000:
            break
        ret[tmp] += 1
while 1:
    n = int(input())
    if n == 0:
        break
    print ret[n]

Measured memory_bytes: 4984
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    if "RRR" in S:
        ans = 3
    elif "RR" in S:
        ans = 2
    elif "R" in S:
        ans = 1
    else:
        ans = 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9004
/*
ID:xmydada1
LANG:C++
TASK:
*/
#include<bits/stdc++.h>
#define reg register

using namespace std;

int m,n,ans=0,sum=0,p;

inline int read() {
reg int s = 0, t = 0; reg char ch = getchar();
while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return t ? -s : s;
}

inline void print(reg long long x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	m=read();n=read();
	if(m<n)cout<<0;
	if(m>=n)cout<<10;

return 0;
}



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

using namespace std;

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

    vector<int> P(0);
    for (int i = 0; i < N; i++) {
        int tmpP;
        cin >> tmpP;
        P.push_back(tmpP - 1);
    }

    vector<int> Q(0);
    for (int i = 0; i < N; i++) {
        int tmpQ;
        cin >> tmpQ;
        Q.push_back(tmpQ - 1);
    }

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

    int counter = 0;
    int a = 0;
    int b = 0;
    do {
        if (P == onePermutationCase) {
            a = counter;
        }
        if (Q == onePermutationCase) {
            b = counter;
        }
        counter++;
    } while (next_permutation(onePermutationCase.begin(), onePermutationCase.end()));

    int res = abs(a - b);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
n, k  = map(int, input().split())
a = list(map(int, input().split()))
def check(x):
    res = 0
    for i in range(n):
        res +=  (a[i]-1) // x
    if res <= k:
        return True
    else:
        return False
r = 1000000000
if check(1):
    print(1)
    exit()
else:
    l = 1
    while r > l+1:
        mid = (r+l)//2
        if check(mid):
            r = mid
        else:
            l = mid
    print(r)

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  for(int i=0;i<n-2;i++){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pii;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


const ll N = 1e18;
int main(int argv, char* argc[])
{
    FASTIO

    ll n;
    cin>>n;
    vll v(n);
    bool f=1;
    rep(i,n)
    {
        cin>>v[i];
        if(!v[i])
            f=0;
    }
    if(!f)
    {
        cout<<0;
        return 0;
    }

    ll p=1;
    rep(i,n)
    {
        if(N/p<v[i])
        {
            cout<<-1;
            return 0;
        }
        p*=v[i];
    }
    cout<<p;



    return 0;
}



Measured memory_bytes: 3996
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};

ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){a=b;b=r;r=a%b;}
    return b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d;cin>>a>>b>>c>>d;
  if(a==c||b==d){cout<<0<<endl;return 0;}
  ll ma=max(abs(d-b),abs(c-a));
  ll mi=min(abs(d-b),abs(c-a));
  cout<<ma+mi-gcd(ma,mi)<<endl;
  return 0;
}


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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int a[N] , good[N] , bad[N];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , k;
   cin >> n >> k;
   for(int i = 0 ; i < n ; i++){
      cin >> a[i];
   }
   while(k){
      bool done = false;
      for(int i = 0 ; i < n ; i++){
         good[max(i - a[i] , 0)]++;
         bad[min(i + a[i] + 1 , n)]++;
      }
      int nw = 0;
      for(int i = 0 ; i < n ; i++){
         nw += good[i];
         nw -= bad[i];
         a[i] = nw;
         if(a[i] != n)
            done = true;
      }
      if(!done)
         break;
      for(int i = 0 ; i < n ; i++){
         good[i] = 0;
         bad[i] = 0;
      }
      k--;
   }
   for(int i = 0 ; i < n ; i++)
      cout << a[i] << " ";
   return 0;
}


Measured memory_bytes: 5964
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

#define FUTAGO(x) ((x) ? "Yay!" : ":(")

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 50000; ++i) {
		if (int(i * 1.08) == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e5+20;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int n,m;
char str[maxn];
int lim;
int f[maxn];

inline void CHECK1()
{
	REP(i,1,m)if(str[i]=='B')return;
	f[0]=1;f[1]=1;
	REP(i,2,n)f[i]=(f[i-1]+f[i-2])%mod;
	printf("%d\n",(f[n-2]+f[n])%mod);
	exit(0);
}

inline void init()
{
	n=read();m=read();
	scanf("%s",str+1);
	if(str[1]=='B')
	{
		REP(i,1,m)str[i]=str[i]=='B'?'R':'B';
	}
	CHECK1();
	lim=inf;
	int lstb=0;
	REP(i,1,m)
	{
		if(str[i]=='B')
		{
			int num=i-lstb-1;
			if(lstb==0)chkmin(lim,num+(num+1&1));
			else if(num&1)chkmin(lim,num);
			lstb=i;
		}
	}
	lim=lim+1>>1;
}

inline void doing()
{
	if(n&1)puts("0"),exit(0);
	n>>=1;
	f[0]=1;int s=1;
	REP(i,1,n)
	{
		f[i]=s;
		s=(s+f[i])%mod;
		if(i-lim>=0)s=(s-f[i-lim]+mod)%mod;
	}
	//int ans=f[n>>1];
	int ans=0;
	REP(i,1,lim)ans=(ans+(ll)i*f[n-i])%mod;
	ans=(ll)ans*2%mod;
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main()
{
	int n, m; cin >> n >> m;
	int h[100001] = {};
	vector<int> r[100001];
	for (int i = 1; i <= n; i++)cin >> h[i];
	for (int i = 0; i < m; i++) { 
		int a, b; cin >> a >> b;
		r[a].push_back(b);
		r[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		bool result = true;
		for (auto b : r[i]) {
			if (h[b] >= h[i]) {
				result = false;
			}
		}
		if (result) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9152
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int count,count2;
    int win=0;
    int n;
    int r=0,b=0;
    int maxval=99999,maxnum=0,sum=0;
    int l[105];
    char s[105];
    
    scanf("%d",&n);
    scanf("%s",s);
 
    for(count=0;s[count]!='\0';count++){
        if(s[count]=='R'){r++;}
        else{b++;}
    }
 
    if(r>b){printf("Yes\n");}
    else {printf("No\n");}
    return 0;
}
 
int min(int a,int b){
    int ans;
    if(a>b){return b;}
    else {return a;}
}
 
int max(int a,int b){
    int ans;
    if(a>b){return a;}
    else {return b;}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
const ll ber = 1e18;
const int M = 1000005;

int main(){
  int n, k;
  cin >> n >> k;
  vector <int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  int ans = 0;
  sort(p.begin(), p.end());
  rep(j,k){
    ans += p[j];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    long long T, A;
    cin >> T >> A;

    vector<int> H(n);
    for (int i = 0; i < n; ++i) {
        cin >> H[i];
    }

    pair<long long, int> res{1LL << 60, -1};

    T *= 1000;
    A *= 1000;
    long long p = 6;
    for (int i = 0; i < n; ++i) {
        long long t = T - H[i] * p;
        t = abs(t - A);
        res = min(res, make_pair(t, i));
    }

    cout << res.second + 1 << '\n';

    return 0;
}

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

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << endl;
	}

	return 0;
}

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

int main(){
  int N; cin>>N;
  vector<pair<int,int> > v(N);
  rep(i,N){
    int a; cin>>a;
    v[i]={a,i};
  }
  sort(v.begin(),v.end());
  int ans=0,ma=0;
  rep(i,N-1){
    if(ma<=min(v[i].first,v[N-1].first-v[i].first)){
      ans=v[i].first;
      ma=min(v[i].first,v[N-1].first-v[i].first);
    }
  }
  cout<<v[N-1].first<<" "<<ans<<endl;
  return 0;
}


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
	const int MAXN = 100;
	int n, a[MAXN];
	char A[MAXN], B[MAXN];

	scanf("%d", &n);
	scanf("%s", A + 1);
	scanf("%s", B + 1);

	int k = 0;
	for (int i = 1; i <= n; ++i) {
		if (i < n && A[i] == A[i + 1]) a[++k] = 1, ++i;
		else a[++k] = 0;
	}

	const int MOD = (int) 1e9 + 7;
	int dp[MAXN]; dp[1] = (a[1] == 1) ? 6 : 3;
	for (int i = 2; i <= k; ++i) {
		if (a[i] == 0) dp[i] = LL(a[i - 1] == 0 ? 2 : 1) * dp[i - 1] % MOD;
		else dp[i] = LL(a[i - 1] == 0 ? 2 : 3) * dp[i - 1] % MOD;
	}
	printf("%d\n", dp[k]);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())

def median(X):
  n = len(X)
  X = sorted(X)
  if len(X)%2==0:
    return (X[n//2-1]+X[n//2])*.5
  else:
    return X[n//2]

if N%2==0:
  print(int((median(B)-median(A))*2+1))
else:
  print(int(median(B)-median(A)+1))


Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio (false);
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if (k <= (a + b))
    {
        cout << min (a, k) << endl;
    }
    else
    {
        cout << (a - (k - (a + b))) << endl;
    }
}


Measured memory_bytes: 3648