akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)

  ll r, c, k;
  cin >> r >> c >> k;
  vector<vector<ll>> item(r, vector<ll>(c, 0));
  for (int i = 0; i < k; i++) {
    ll u, v, p;
    cin >> u >> v >> p;
    u--, v--;
    item[u][v] = p;
  }

  vector<vector<vector<ll>>> dp(r, vector<vector<ll>>(c, vector<ll>(4))); //dp[i][j][k]: (i, j)にたどり着いた時点でその行でちょうどのこりk個取れるとき

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (1) { //全部の場合では？
        for (int k = 0; k < 4; k++) {
          //cout << "!!1" << endl;
          if (j+1 < c) dp[i][j+1][k] = max(dp[i][j][k], dp[i][j+1][k]);
          if (i+1 < r) dp[i+1][j][3] = max(dp[i][j][k], dp[i+1][j][3]);
        }
      }
      if (item[i][j] != 0) {
        for (int k = 1; k < 4; k++) {
          //cout << "!!2" << endl;
          if (j+1 < c) dp[i][j+1][k-1] = max(dp[i][j][k] + item[i][j], dp[i][j+1][k-1]);
          if (i+1 < r) dp[i+1][j][3] = max(dp[i][j][k] + item[i][j], dp[i+1][j][3]);
        }
        //k=0のとき
        //cout << "!!3" << endl;
        if (j+1 < c) dp[i][j+1][0] = max(dp[i][j][0] + 0, dp[i][j+1][0]);
        if (i+1 < r) dp[i+1][j][3] = max(dp[i][j][0] + 0, dp[i+1][j][3]);
      }
    }
  }

  /*
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      for (int k = 0; k < 4; k++) {
        cout << dp[i][j][k] << ",";
      }
      cout << "  ";
    }
    cout << endl;
  }

  cout << "ok" << endl;
  */

  if (item[r-1][c-1] == 0) {
    ll ans = 0;
    for (int k = 0; k < 4; k++) {
      //cout << dp[r-1][c-1][k] << " ";
      ans = max(ans, dp[r-1][c-1][k]);
    }
    cout << ans << endl;
    return 0;
  }
  else {
    ll ans = dp[r-1][c-1][0];
    for (int k = 1; k < 4; k++) {
      ans = max(ans, dp[r-1][c-1][k] + item[r-1][c-1]);
    }
    cout << ans << endl;
    return 0;
  }
}


Measured memory_bytes: 706724
def abc147_b():    
    s = input()

    check_str_list = []
    chesk_str_list_reverse = []
    rev_cnt = 0

    for i in range(len(s) // 2):
        check_str_list.append(s[i])
        rev_cnt -= 1
        chesk_str_list_reverse.append(s[rev_cnt])

    result = 0

    for i in range(len(check_str_list)):
        if check_str_list[i] != chesk_str_list_reverse[i]:
            result += 1

    print(result)
if __name__ == '__main__':
    abc147_b()

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    string A, B, C;
    cin >> A >> B >> C;

    int d, e, f;
    d = A.size();
    e = B.size();
    f = C.size();

    if (A[d - 1] == B[0] && B[e - 1] == C[0]) { cout << "YES" << endl; }
    else { cout << "NO" << endl; }

}

Measured memory_bytes: 256
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a - 1
let flags = Array.make n false
let rec loop acc i =
  if flags.(i) then (print_endline "-1"; exit 0)
  else if i = 1 then (Printf.printf "%d\n" acc; exit 0)
  else (flags.(i) <- true; loop (acc + 1) a_s.(i))
let _ = loop 0 0

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int x, y;
	cin >> x >> y;

	bool ok = false;
	for (int t = 0; t <= x; ++t) {
		int c = x - t;
		if (t * 4 + c * 2 == y) {
			ok = true;
			break;
		}
	}

	cout << (ok ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long int
#define vi vector<int>
#define vl vector<LL>
#define pb push_back
#define all(V) V.begin(),V.end()
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%I64d",&x)
#define pii pair<int,int>
#define cmax(a,b) ((a) = (a) > (b) ? (a) : (b))
#define cmin(a,b) ((a) = (a) < (b) ? (a) : (b))
#define debug(x)  cerr << #x << " = " << x << endl
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};

void solve(){
    int n, k;
    sci(n); sci(k);
    vi A(k);
    for(int &x : A) sci(x);
    set<int> S; for(int &x : A) S.insert(x);
    auto check = [&](int x){
        while(x){
            if(S.count(x%10)) return false;
            x /= 10;
        }
        return true;
    };
    for(int i = n; ; i++){
        if(!check(i)) continue;
        cout << i << endl;
        return;
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("Local.in","r",stdin);
    freopen("ans.out","w",stdout);
    #endif
    solve();
    return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
//#define push push_back
//#define pop pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
// ll mod(ll a, ll b)
// {
// 	if(a%b<0)
// 	{
// 		return a%b + b;
// 	}
// 	return a%b;
// }
 
 
// ll mod_exp(ll a, ll b, ll c)
// {
// 	ll res=1;
// 	a=a%c;
// 	while(b>0)
// 	{
// 		if(b%2==1)
// 		{
// 			res=(res*a)%c;
// 		}
// 		b/=2;
// 		a=(a*a)%c;
// 	}
// 	return res;
// }
// ll mymod(ll a,ll b)
// {
//     return ((a%b)+b)%b;
// }
// bool prime[200001];
// void SieveOfEratosthenes() 
// { 
//     memset(prime, true, sizeof(prime)); 
//     prime[1]=false;
//     for (int p=2; p*p<=200000; p++) 
//     { 
//         if (prime[p] == true) 
//         { 
//             for (int i=p*p; i<=200000; i += p) 
//                 prime[i] = false; 
//         } 
//     } 
//     return;
// }
// ll powe[200005];
// void power()
// {
//     powe[0]=1;
//     REP(i,1,200005)
//     {
//         powe[i]=mymod(2*powe[i-1],num);
//     }
// }
// ll gcdExtended(ll,ll,ll *,ll *);
// ll modInverse(ll a, ll m) 
// { 
//     ll x, y; 
//     ll g = gcdExtended(a, m, &x, &y); 
//         ll res = (x%m + m) % m;
//         return res;
// } 
// ll gcdExtended(ll a, ll b, ll *x, ll *y) 
// { 
//     if (a == 0) 
//     { 
//         *x = 0, *y = 1; 
//         return b; 
//     } 
//     ll x1, y1; 
//     ll gcd = gcdExtended(b%a, a, &x1, &y1); 
//     *x = y1 - (b/a) * x1; 
//     *y = x1; 
//     return gcd; 
// } 
// ll facto[200005];
// void f()
// {
// 	facto[0]=1;
// 	REP(i,1,200005)
// 	{
// 		facto[i]=mymod((i*facto[i-1]),num);
// 	}
// }
string ans="";
void dfs(set<ll> adj[], ll a, bool def[], ll parent=-1)
{
    def[a]=true;
    for(auto x: adj[a])
    {
        if(parent!=-1 && x!=parent && def[x])
        {
            cout<<"Impossible\n";
            exit(0);
        }
        if(!def[x])
        {
            dfs(adj,x,def,a);
        }
    }
    ans+=(char)(a+97);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    set<char> st;
    REP(i,0,s.size())
    {
        st.insert(s[i]);
    }
    if(st.size()>1)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
	return 0;
}

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

using namespace std;

int main()
{
    vector<int> num(10001, 0);
    int n, i, res;
    cin >> n;
    for (int x=1 ; x<=100 ; x++)
    {
        for (int y=1 ; y<=100 ; y++)
        {
            if (x*x + y*y + x*y > n)
                break;
            for (int z=1 ; z<=100 ; z++)
            {
                res = x*x + y*y + z*z + x*y + x*z + y*z;
                if (res > n)
                    break;
                num[res]++;
            }
        }
    }
    for (i=1 ; i<=n && i<num.size() ; i++)
    {
        cout << num[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


K = int(input())
count = 0
for i in range(K):
    n = int(input())
    if is_prime(n):
        count += 1
print(count)



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

using ll=long long;
ll dp[100010][3];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll p[100010][3];
  rep(i,n){
    rep(j,3){
      cin >> p[i][j];
    }
  }
  rep(i,3) dp[0][i] = p[0][i];
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(j==k) continue;
        dp[i+1][j] = max(dp[i+1][j], dp[i][k] + p[i+1][j]);
      }
    }
  }
  ll ans = 0;
  n--;
  rep(i,3) ans = max(ans, dp[n][i]);
  cout << ans << endl;  
}

Measured memory_bytes: 4992
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    let ret;
    from_line!(w: i32, h: i32, x: i32, y: i32, r: i32);
    if x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h {
        ret = "Yes";
    }
    else {
        ret = "No";
    }

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



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

int main() {
  string s; cin>>s;
  int ans=1e9;
  rep(i,s.size()-2) {
    ans=min(ans,abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753));
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
from math import gcd

def lcm(a,b):
    return (a*b)//gcd(a,b)
N,M=map(int, input().split())
S=input()
T=input()

L=lcm(N,M)

i=0
j=0
while 0<=i<N and 0<=j<M:
    nowi=i*(L//N)
    nowj=j*(L//M)
    #print(i,j,nowi,nowj)
    if nowj==nowi:
        if S[i]!=T[j]:

            print(-1)
            exit()

    if nowi>nowj:
        j+=1
    elif nowi<nowj:
        i+=1
    else:
        i+=1
        j+=1
print(L)

Measured memory_bytes: 9180
N,M=map(int,input().split())
A=[]
for i in range(M):
  a,b=map(int,input().split())
  A.append([a,b])
A.sort()

ans=1
l=A[0][0]
r=A[0][1]

for i in range(1,M):
  a,b = A[i]
  if r <= a or l >= b:
    ans+=1
    l=a
    r=b
  else:
    l=a
    r=min(r,b)

print(ans)


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void sw(string& s, int l, int r) {
    REP(i, (r - l + 1) / 2) {
        swap(s[l + i], s[r - i]);
    }
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    REP(i, sz(s)) {
        cout << (char)(((int)(s[i] - 'A') + n) % 26 + 'A');
    }
    cout << EOL;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    int a, b;
    int d, r;
    double f;

    scanf("%d", &a);
    scanf("%d", &b);

    d = a / b;
    r = a % b;
    f = (double)a / b;

    printf("%d %d %.5f\n", d, r, f);

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main() {
  int A=0, B=0, C=0, D=0;
  cin >> A >> B >> C >> D;
  int lower, upper = 0;
  lower = max(A, C);
  upper = min(B, D);
  cout << max(upper - lower, 0) << endl;
}

Measured memory_bytes: 256
"use strict"
function Main(input) {
  input = input.trim().split(' ').map(Number);
  const A = input[0];
  const B = input[1];
  let ret = 0;

  for(let i=1; i<=B;i++){
    let tmp = A * i;
    if(tmp%B === 0){
      ret = tmp;
      break;
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main () {
  long long N,A,B;
  cin >> N >> A >> B;
  
  if (A > B){
    cout << 0 << endl;
    return 0;
  }
  if (A != B && N == 1){
    cout << 0 << endl;
    return 0;
  }
  long long M = (B-A)*(N-2) + 1;
  cout << M << endl;
}
  

Measured memory_bytes: 3636
h,w=map(int, input().split())
s = [list(map(int, input().split())) for i in range(h)]
count=0
step=[]
for i in range(h):
    for j in range(w):
        if s[i][j]%2==1:
            if (j+1)==w:
                if (i+1)!=h:
                    step.append([i+1,j+1,i+2,j+1])
                    s[i+1][j]+=1
                    count+=1
            else:
                step.append([i+1,j+1,i+1,j+2])
                s[i][j+1]+=1
                count+=1
print(count)
for i in step:
    print(' '.join(list(map(str,i))))

Measured memory_bytes: 31164
#include <iostream>

using namespace std;

int main() {
  int N, T, l = 0, r = 0, sum = 0;
  cin >> N >> T;

  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    if (r < t) {
      sum += r - l;
      l = t;
    }
    r = t + T;
  }
  sum += r - l;

  cout << sum << endl;
}


Measured memory_bytes: 3588
N=int(input())
info1=list(map(int,input().split()))
info2=list(map(int,input().split()))
ans=0
if info1[-1]!=info2[0]: #お互いの最高記録が一致していないのは矛盾
    print(ans)
else:
    a=[[0,info1[0]]]
    highest=info1[0]
    for i in range(1,N):
        if highest<info1[i]:
            highest=info1[i]
            a.append([0,info1[i]])
        else:
            a.append([1,highest])
    b=[[0,info2[-1]]]
    highest=info2[-1]
    for i in range(1,N):
        if highest<info2[-(i+1)]:
            highest=info2[-(i+1)]
            b.append([0,info2[-(i+1)]])
        else:
            b.append([1,highest])
    flag=True
    c=[]
    for i in range(N): #二つの範囲を組み合わせる
        if a[i][0]==0 and b[-(i+1)][0]==0:
            if a[i][1]==b[-(i+1)][1]:
                c.append([0,a[i][1]])
            else:
                flag=False
                break
        elif a[i][0]==1 and b[-(i+1)][0]==1:
            c.append([1,min(a[i][1],b[-(i+1)][1])])
        else:
            if a[i][0]==0:
                if a[i][1]<=b[-(i+1)][1]:
                    c.append([0,a[i][1]])
                else:
                    flag=False
                    break
            else:
                if b[-(i+1)][1]<=a[i][1]:
                    c.append([0,b[-(i+1)][1]])
                else:
                    flag=False
                    break
    if flag:
        mod=10**9+7
        ans=1
        for i in range(N):
            if c[i][0]==1:
                ans=(ans*c[i][1])%mod
        print(ans)
    else:
        print(0)

Measured memory_bytes: 113124
#include <bits/stdc++.h>
#include <map>
#include <string.h>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(a) (a).begin(), (a).end()
using namespace std;

int main(){
    string s;
    cin >> s;
    int a = 0, b = 0;
    rep(i,s.size()){
        if(s.at(i) == '0')a++;
        else if(s.at(i) == '1')b++;
    }
    cout << min(a,b) * 2 << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int L;
    scanf("%d", &L);
    int curr = 0;
    int val = 1;
    int i;

    vector<int> a;
    while (L) {
        a.push_back(L % 2);
        L /= 2;
    }

    a.pop_back();
    vector<pair<pair<int, int>, int> > v;
    while (!a.empty()) {
        int tmp = a.back();
        a.pop_back();
        curr++;
        val *= 2;
        if (tmp == 0) {
            int siz = v.size();
            for (i = 0; i < siz; i++) {
                v[i].second *= 2;
            }
            v.push_back(make_pair(make_pair(curr - 1, curr), 0));
            v.push_back(make_pair(make_pair(curr - 1, curr), 1));
        }
        else {
            int siz = v.size();
            for (i = 0; i < siz; i++) {
                v[i].second *= 2;
            }
            v.push_back(make_pair(make_pair(curr - 1, curr), 0));
            v.push_back(make_pair(make_pair(curr - 1, curr), 1));
            v.push_back(make_pair(make_pair(0, curr), val));
        }
        val += tmp;
    }

    int m = (int)v.size();
    int n = curr+1;
    printf("%d %d\n", n, m);
    for (i = 0; i < m; i++) {
        printf("%d %d %d\n", v[i].first.first + 1, v[i].first.second + 1, v[i].second);
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

#define Solved int main()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, n) for(int i = 1; i <= n; i++)
#define rep(i, x, y) for(int i = x; i <= y; i++)
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mii map<int, int>
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
using namespace std;

inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

const int maxn = 1e9;
const ll inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int N = 1e5 + 10;

int n, W, w[101], v[101];
ll dp[101][100001];

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

    forn (i, n)
        cin >> w[i] >> v[i];

    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= 100000; j++) {
            dp[i][j] = inf;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 100000; j++) {
            dp[i][j] = dp[i - 1][j];

            if (j >= v[i]) dp[i][j] = min(dp[i][j], w[i] + dp[i - 1][j - v[i]]);
        }
    }

    dp[n][0] = 1;
    for (int i = 100000; i >= 0; i--) {
        if (dp[n][i] <= W) cout << i, exit(0);
    }

}

Solved {
    SpeedForce;
	int tt = 1;
    //cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}

}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
  int n,ans;
  cin>>n;
  vector<int> v(n),a;
  rep(i,n) cin>>v[i];
  for(int i=1;i<=n;i++) a.push_back(i);
  for(int i=0;i<n;i++){
    if(a[i]!=v[i]) ans++;
  }
  if(ans==2 || ans==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))

P.sort(reverse=1)
Q.sort(reverse=1)
R.sort(reverse=1)

ans = P[:x]+Q[:y]
if len(ans)< x+y:
  ans = ans + R[:x+y-len(ans)]
  R = R[x+y-len(ans):]

ans.sort(reverse =1)

ANS = 0
for r in R:
  if ans[-1] < r:
    ans.pop(-1)
    ANS += r
  else:
    break
print(sum(ans) + ANS)
    

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

int main(void){
    int n;
    cin >> n;
    int a[n],b[n],c[n],sum = 0;;
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n;i++)cin >> b[i];
    for(int i = 0;i < n-1;i++)cin >> c[i];
    for(int i = 1;i < n;i++){
        sum += b[i];
        if(a[i] == (a[i-1]+1)){
            sum += c[a[i-1]-1];
        }
    }
    sum += b[0];
    cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int main() {
	int n,m,ans =0;
	int hoge[3] = {-1,-1,-1};
	bool f = false;
	cin >> n >> m;
	if (m == 0 && n == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (m == 0) {
		cout << pow(10,(n-1)) << endl;
		return 0;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (hoge[a - 1] == -1 || hoge[a - 1] == b ) {
			hoge[a - 1] = b;
		}
		else {
			f = true;
		}
	}
	if ((hoge[0] == 0 && n > 1)|| f) {
		cout << -1 << endl;
		return 0;
	}
	if (hoge[0] == -1) {
		hoge[0] = 1;
	}
	for (int i = 0; i < 3; i++) {
		if (hoge[2 - i] == -1)continue;
		ans += hoge[2-i] * pow(10, i);
	}
	cout << ans/pow(10,3-n) << endl;

}

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

int main() {

    std::string S;
    std::cin >> S;
    char prev = 0;
    bool ans = false;
    for (auto& v : S) {
        if (prev == v)ans = true;
        prev = v;
    }
    std::cout << (ans ? "Bad" : "Good") << std::endl;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	if(a > b){
		cout << "a > b" << endl;
	}
	else if(a < b){
		cout << "a < b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
const int maxn=3e5+100;
int n,k,x,p[maxn],y,a;
int main()
{
	k=read();n=read();
	if (k%2==0)
	{
		printf("%d ",k/2);
		for (int i=2;i<=n;i++) printf("%d ",k);
		return 0;
	}
	if (k==1)
	{
		for (int i=1;i<=(n+1)/2;i++) printf("1 ");
		return 0;
	}
	x=n/2;y=(k+1)/2;
	for (int i=1;i<=n;i++) p[i]=y;
	while (x--)
	{
		a=n;
		while (p[a]==0) a--;
		if (p[a]==1)
		{
			p[a]=0;
	//		if (a<=6)
	//		{for (int i=1;i<=n;i++) if (p[i]==0) break; else printf("%d ",p[i]);
	//		printf("\n");}
			continue;
		}
		a=n;
		p[a]--;
		while (p[a]==-1||(p[a]==0&&p[a+1]!=0))
		{
			p[a]=k;a--;p[a]--;
		}
//		for (int i=1;i<=n;i++)
//		{
//			if (p[i]==0) break;
//			printf("%d ",p[i]);
//		}putchar('\n');
	}

	for (int i=1;i<=n;i++) if (p[i]==0) break; else printf("%d ",p[i]);
	return 0;
	//http://arc084.contest.atcoder.jp/tasks/arc084_c
}


Measured memory_bytes: 3456
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()

cnt = 0
for i in range(1,N+1):
  if len(str(i))%2 != 0:
    cnt += 1

print(cnt)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int a[100005];
int dp[100005][2];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	rep(i, 1, n + 1) cin >> a[i];
	const int INC = 0, DEC = 1;
	dp[1][INC] = dp[1][DEC] = 1;
	
	rep(i, 2, n + 1) {
		dp[i][INC] = min(dp[i - 1][INC], dp[i - 1][DEC]) + 1;
		dp[i][DEC] = min(dp[i - 1][INC], dp[i - 1][DEC]) + 1;
		if (a[i] <= a[i - 1])
			dp[i][DEC] = min(dp[i][DEC], dp[i - 1][DEC]);
		if (a[i] >= a[i - 1])
			dp[i][INC] = min(dp[i][INC], dp[i - 1][INC]);
	}

	cout << min(dp[n][INC], dp[n][DEC]) << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

void solve(){
    int n;
    cin >> n;
    cout <<fixed<<setprecision(2) << 2*pi*n;
}

int main(){
    #ifdef KAZAKH
        //freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3804
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a;
        int n, i;
        n = sc.nextInt();
        a = new int[n];
        for(i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        for (i = n - 1; i >= 0; i--) {
            System.out.printf("%d",a[i]);
            if(i>0&&i<n){
                System.out.printf(" ");
            }
        }
        System.out.printf("\n");
    }
}


Measured memory_bytes: 26588
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<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
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
LL powm(LL base,LL power, LL mod){
  LL ret=1;
  while(power){
    if(power&1) ret=(ret*base)%mod;
    base=(base*base)%mod;
    power>>=1;
  } return ret;
}
int main(){
  int n,m;si(n);si(m); 
  int ans=1;
  for(int i=1;i*i<m;i++){
    if(m%i==0){
      ans=max(ans,m/i>=n?i:0);
      ans=max(ans,i>=n?m/i:0);
    }
  }
  dout(ans);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

l, r = map(int, input().split())

# prime_factor = 3, 673
mod = 2019

for i in range(l, r + 1):
    if i % 2019 == 0:
        print(0)
        sys.exit(0)

ans = mod
for i in range(l, r + 1):
    imod = i % mod
    for j in range(i + 1, r + 1):
        jmod = j % mod
        ans = min(ans, (imod * jmod) % mod)
        if ans == 0:
            break
    if ans == 0:
        break

print(ans)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
 {  fast();
	int t, n, k,count=0;
	cin >> n >>k;
  VI arr(n+1,0);
	while(k--) {
      int d;
	    cin >> d;
      fore(i,d){
        int x;
        cin>>x;
        arr[x]++;
      }
      }
    fore1(i,1,n+1){
      if(arr[i]==0)
        count++;}
  cout<<count<<endl;}

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

typedef long long ll;
const int maxn = 2e5 + 3;
const ll mo = 1e9 + 7;

int n, k, p[maxn], pl;
bool isc[maxn];
ll mu[maxn], cnt[maxn];

ll mpow(ll u, ll k) {
    ll ans = 1;
    for(; k > 0; k >>= 1) {
        if(k & 1)
            ans = ans * u % mo;
        u = u * u % mo;
    }
    return ans;
}

int main() {
    mu[1] = 1;
    for(int i = 2; i < maxn; ++i) {
        if(!isc[i]) {
            p[pl++] = i;
            mu[i] = -1;
        }
        for(int j = 0; j < pl && i * (ll)p[j] < maxn; ++j) {
            isc[i * p[j]] = true;
            mu[i * p[j]] = -mu[i];
            if(i % p[j] == 0) {
                mu[i * p[j]] = 0;
                break;
            }
        }
    }
    scanf("%d%d", &n, &k);
    ll ans = 0;
    for(int i = 1; i <= k; ++i) {
        ll w = i - cnt[i];
        ans = (ans + w % mo * mpow(k / i, n)) % mo;
        for(int j = 1; i * (ll)j <= k; ++j) {
            cnt[i * j] += w;
        }
    }
    ans = (ans + mo) % mo;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6452
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int mini,maxi,midi;
	mini=min(a,min(b,c));
	maxi=max(a,max(b,c));
	midi = a+b+c-maxi-mini;
	int count=0;
	while(mini<maxi-1){count++;mini+=2;}
	while(midi<maxi-1){count++;midi+=2;}
	a=max(mini,max(midi,maxi));
	if(mini==maxi && maxi==midi) {cout << count;return 0;}
	else if(abs(a-maxi)+abs(a-midi)+abs(a-mini) == 1) {cout << count+2;return 0;}
	else {cout << count+1;return 0;}
			
	
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

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

const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;

int a[22], b[22];
class BResale {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in>>n;
		for(int i = 0; i < n; ++i){
			in>>a[i];
		}
		for(int i = 0; i < n; ++i){
			in>>b[i];
		}
		int res = 0;
		for(int i = 0; i < n ;++i){
			if(a[i] > b[i]){
				res += a[i]-b[i];
			}
		}
		out<<max(0, res)<<endl;

	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	BResale solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main(){
    
    int N,X,L,S=0,ans=1;

    cin >> N>>X;

    for(int i=1;i<=N;i++){

        cin >> L;

        S+=L;

        if(S>X){
            break;
        }else{
            ans+=1;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void){
	int n;
	int c[501], s[501], f[501];
	int dp[502] = {};

	cin >> n;
	FOR(i, 1, n-1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	dp[n] = 0;

	FOR(i, 1, n-1) {
		int time = 0;
		FOR(t, i, n-1) {
			FOR(u, max(time, s[t]), 1000000) {
				if (u%f[t] == 0) {
					time = u + c[t];
					break;
				}
			}
		}
		dp[i] = time;
	}

	FOR(i, 1, n) {
		cout << dp[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
let n=Int(readLine()!)!
let b=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var a : [Int] = []

a.append(b[0])

var i = 0

for i in 1..<n - 1 {
  a.append( min( b[i-1], b[i] ) )
}

a.append(b[n-2])
//print( a )
print( a.reduce(0, combine: + ) )



Measured memory_bytes: 4208
#include <algorithm>
#include <iostream>

int main(void) {
  int n, m, l, r;
  std::cin >> n >> m;

  int min, max;
  min = 1;
  max = n;

  for (int i = 0; i < m; i++) {
    std::cin >> l >> r;
    min = min < l ? l : min;
    max = max > r ? r : max;
  }

  std::cout << std::max(0, max - min + 1) << std::endl;

  return 0;
}


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

int main(){
  int x;
  cin >> x;
  bool f = false;
  if(x == 3) f = true;
  if(x == 5) f = true;
  if(x == 7) f = true;
  if(f) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 

int main()
{
    char a[101][101];
    int sum[100][100]={0};
    int j,i,n,m;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
            scanf("%s",a[i]);getchar();
    }

       
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(a[i][j]=='#')
            {sum[i][j]=-1;  continue;
            } 
            if(a[i-1][j-1]=='#')
                 sum[i][j]++;
            if(a[i-1][j]=='#')
                 sum[i][j]++;
            if(a[i-1][j+1]=='#')
                 sum[i][j]++;
            if(a[i][j-1]=='#')
                 sum[i][j]++;
            if(a[i][j+1]=='#')
                 sum[i][j]++;
            if(a[i+1][j-1]=='#')
                 sum[i][j]++;
            if(a[i+1][j]=='#')
                 sum[i][j]++;
            if(a[i+1][j+1]=='#')
                 sum[i][j]++;                           
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(sum[i][j]!=-1)
                printf("%d",sum[i][j]);
            else putchar('#');
        }
        putchar('\n');
    }
    return 0;
}

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

ll k, m, ans, a, b;
ll t[1 << 17], d[1 << 17];
vector<ll> u, v;

int main(){
    cin >> k >> a >> b;
    ans = 1;
    if (a + 1 >= b || a > k - 1) ans = k + 1; 
    else{
        ans = b;
        k -= a + 1;
        ans += (b - a) * (k / 2) + k % 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

void rek(int fre, int dec, int s, int t){
	if(__builtin_popcount(fre) == 1){
		cout << s << ' ' << t << ' ';
	} else {
		int p = 1;
		while(!(fre&p) || !((s^t)&p) )
			p <<= 1;
		int q = 1;
		while(p == q || !(fre&q))
			q <<= 1;
		rek(fre^p, dec ^ (s&p), s, s^q);
		rek(fre^p, dec ^ (t&p), s^q^p, t);
	}
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n, a, b;
	cin >> n >> a >> b;
	if(__builtin_popcount(a^b) % 2 == 0){
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		rek((1<<n)-1, 0, a, b);
		cout << endl;
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 d,t,s;
    cin >> d >>t >>s;
    if (d/t <= s) {
        if (d%t!=0 && d/t==s) cout << "No";
        else cout << "Yes";
    } else cout << "No";

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(){
  int a,b,c,x,ans=0;
  scanf("%d%d%d%d",&a,&b,&c,&x);
  int i,j,k;
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if(x==i*500+j*100+k*50) ans++;
      }
    }
  }
  
  printf("%d\n",ans);
  return 0;
}


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

int n, h[100005], dp[100005];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++) cin >> h[i];

    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    for(int i=3; i<=n; i++) {
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
        //cout << dp[i] << ' ';
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1024
def gcd(x, y):
    x, y = max(x, y), min(x, y)
    while x % y > 0:
        x, y = y, x % y
    return y

A, B = list(map(int, input().split()))
g = gcd(A, B)
answer = int(A*B/g)
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template< typename T >
struct edge {
  int from, to;
  T cost;

  edge(int to, T cost) : from(-1), to(to), cost(cost) {}

  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  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);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


template< typename T >
struct MinimumSpanningTree {
  T cost;
  Edges< T > edges;
};

template< typename T >
MinimumSpanningTree< T > kruskal(Edges< T > &edges, int V) {
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return a.cost < b.cost;
  });
  UnionFind tree(V);
  T total = T();
  Edges< T > es;
  for(auto &e : edges) {
    if(tree.unite(e.from, e.to)) {
      es.emplace_back(e);
      total += e.cost;
    }
  }
  return {total, es};
}

int main() {
    ll V, E;
    cin >> V >> E;
    Edges<ll> es;
    rep(i, E) {
        ll s, t, w;
        cin >> s >> t >> w;
        es.emplace_back(s, t, w);
    }
    cout << kruskal(es, V).cost << endl;
}



Measured memory_bytes: 4932
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9+7

combs = [1]*(N-K+1)

for i in range(1,N-K+1):
    combs[i] = (combs[i-1]*(i+K-1)*pow(i,mod-2,mod))%mod

A.sort()
combs = combs[::-1]
ans = 0
for i in range(N-K+1):
    ans += combs[i]*(A[-(i+1)]-A[i])
ans %= mod
print(ans)

Measured memory_bytes: 63912
module Main where

import Control.Applicative
import Numeric
import Data.Char


main :: IO ()
main = loop

loop :: IO()
loop = do
    {[n] <- getIntegers
    ; if n == 0 then return ()
      else do
      { print (sum (map digitToInt (show n)))
       ;loop
      }
    }


--
getIntegers :: IO[Integer]
getIntegers = map read. words <$> getLine

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words  <$> getLine

putDoubles :: [Double] -> IO()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""




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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;


const  int MAXn= 3e5+5;
const  long long INF= 98547321;
const long long mod= 1e9+7;

ll dp[1001][5000]; // dp having states i: keys till used j=mask for treasures unlocked
ll cost[1001]; // cost of keys
ll key_treasure[1001]; // chest that key opens
int n,m;
ll total; // bits representing treasure

ll solve(ll key,ll treasure){
	
	if(key==m){
		if(treasure==total) return 0;
		else return INF;
	}
	
	if(dp[key][treasure]!=-1) return dp[key][treasure];
	
	ll a= solve(key+1, treasure | key_treasure[key]) + cost[key];
	ll b= solve(key+1,treasure);
	
	ll ans= min(a,b);
	dp[key][treasure]=ans;
	
	return ans;
	
}
	

int main(){
        cin>>n>>m;
        
        memset(dp,-1,sizeof(dp));
        
        for(int i=0;i<n;i++)
			total |= (1<<i); // masking total into bits;
        
        for(int i=0;i<m;i++){
			int q;
			cin>>cost[i]>>q;
			
			int treasure;
			
			while(q--){
				cin>>treasure;
				
				key_treasure[i] |= 	1<<(treasure-1);
			}
		}
		
		ll ans= solve(0,0);
		
		if(ans==INF) cout<<-1;
		else cout<<ans;
	}
		
		
				
			
    


Measured memory_bytes: 39552
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans=0;
    if(a-k >= 0){
        ans = k;
    }else{
        ans = a;
        k -= a;
        k -= b;
        if(k > 0){
            ans -= k;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3624