akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod = 1000000007;

struct mint {
  ll x;
  mint(ll x = 0): x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
  mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll, ll>, pair<int, int>> mp;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0 or (y == 0 and x < 0)) {
      x = -x;
      y = -y;
    }
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y;
      y = -tmp;
    }
    if (rot90) mp[{x, y}].first++;
    else mp[{x, y}].second++;
  }
  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16100
use proconio::input;
use std::collections::VecDeque;
 
fn main() {
  input! { K: u32 }
  let mut queue:VecDeque<u32> = vec![1,2,3,4,5,6,7,8,9].into_iter().collect();
  let mut answer = 0;

  for _ in 0..K {
    let val = queue.pop_front().unwrap();
    answer = val;
    
    let next = val * 10 + val % 10;
    if next % 10 != 0 {
      queue.push_back(next - 1);
    }
    queue.push_back(next);
    if next % 10 != 9 {
      queue.push_back(next + 1);
    }
  }
  println!("{}", answer);
}

Measured memory_bytes: 3028
N = int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))

t = 1000000007
ans = 1000000007
for i in range(N):
    u = abs(A - (T - H[i] * 0.006))
    if t > u:
        t = u
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
def popcount(x):
    x = (x & 0x5555555555555555) + (x >> 1  & 0x5555555555555555)
    x = (x & 0x3333333333333333) + (x >> 2  & 0x3333333333333333)
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4  & 0x0f0f0f0f0f0f0f0f)
    x = (x & 0x00ff00ff00ff00ff) + (x >> 8  & 0x00ff00ff00ff00ff)
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)
    return x

n, m = map(int, input().split())

mask = []
for i in range(m):
    vals = list(map(int, input().split()))
    bits = 0
    for s in vals[1:]:
        bits |= 1 << (s-1)
    mask.append(bits)
p = list(map(int, input().split()))

cnt = 0
for i in range(1 << n):
    if all([popcount(i & mask[j]) % 2 ^ p[j] == 0 for j in range(m)]):
        cnt += 1
print(cnt)
    



Measured memory_bytes: 68000
using System;
class p
{
  static void Main()
  {
    string N = Console.ReadLine();
    int sum = 0;
    for (int i = 0; i < N.Length; i++) {
      sum += int.Parse(N[i].ToString());
    }
    Console.WriteLine(int.Parse(N) % sum == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 13140
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll dp[150][SZ], w[150], v[150];

    ll solve(){
      ll n,we;
      cin >> n >> we;
      rep(i, 1, n+1 ) cin >> w[i] >> v[i];
      rep(i, 1, n + 1)
        rep(j, 1, we + 1) {
          if(w[i] <= j) dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
          else dp[i][j] = dp[i-1][j];
        }
        cout << dp[n][we] << endl;
    } 
    
   int main() {
       fastio
       solve();
    }


Measured memory_bytes: 79360
import itertools

n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
p = tuple(p)
q = tuple(q)
x = itertools.permutations(range(1,n+1))
x = list(x)
a = x.index(p)
b = x.index(q)
print(abs(a-b))

Measured memory_bytes: 44656
#include<iostream>
using namespace std;
int main(){
	int d,n;
  cin>>d>>n;
  if(n==100)n++;
  if(d==1)cout<<n<<"00"<<endl;
  else if(d==2)cout<<n<<"0000"<<endl;
  else cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	double n;
	scanf("%lf",&n);
	if ((int)n%2==0){
		printf("%.10f",(n/2.0)/n);
	}
	else{
		printf("%.10f",(int)(n/2.0+1)/n);
	}
	
	return 0; 
}

Measured memory_bytes: 128
def modinv(a,m):
    return pow(a,m-2,m)

n,k = map(int,input().split())
r = n-k+1
A = [0 for i in range(k+1)]
B = [0 for i in range(k+1)]
A[1] = r
B[1] = 1

mod = 10**9+7

for i in range(2,min(r+1, k+1)):
    A[i] = A[i-1]*(r-i+1)*modinv(i,mod)%mod

for i in range(2,min(r+1, k+1)):
    B[i] = B[i-1]*(k-i+1)*modinv(i-1,mod)%mod

for i in range(1,k+1):
    print(A[i]*B[i]%mod)


Measured memory_bytes: 3444
N = int(input())
for h in range(1,3501):
  for n in range(1,3501):
    bs = 4*h*n - N*n -N*h
    if bs > 0 and (N*h*n)%bs == 0:
      print(h,n,N*h*n//bs)
      exit()
    

Measured memory_bytes: 67548
# import configparser
# import time


# class GetTime():
#     now = time.ctime()

    
#     def debug(self):
#         print('-------debug-begin---------------')
#         print(self.now)
#         parsed = time.strptime(self.now)
#         print(time.strftime("%a %b %d %H:%M:%S %Y", parsed))
#         print('-------debug-end---------------')


# class Person():
#     def __init__(self, name, id):
#         self.name = name
#         self.id = id


# class Greet(Person):
#     def morning(self):
#         print('Good morning ' + self.name)

#     def night(self):
#         print('Good night ' + self.name)


# hunter = Person('Hoge Fugo', 1)

# print('name:%s   id:%s' % (hunter.name, hunter.id))

# o = Greet('Bob', 4)
# o.morning()


# t = GetTime()
# t.debug()

# ##

# poem = 'Hello,friends'
# fout = open('relavity','wt')
# # print(poem, file=fout)
# fout.close()

# ##





# # config.read('exe.ini')
# # print(MySQL_setting['Port'])
# # config.read('exe.ini')
# # print(MySQL_setting['Port'])

# class init_setting():
#     def input(self):
#         print('input port number:')
#         port=input()
#         print('input user name:')
#         user=input()

#         print(port,user)

        
#         with open('example.ini','w') as conf:
#             config.write(conf)

#         config=configparser.ConfigParser()
#         config['MySQL_setting']={}
#         MySQL_setting=config['MySQL_setting']


#         MySQL_setting['Port']=port
#         MySQL_setting['user']=user

#         config.sections()


# MakeSetting=init_setting()
# MakeSetting.input()


# MySQL_setting['Port']=port
# # MySQL_setting['user']=user

# empty_list = []
# print(empty_list)

# weekdays=['monday','Tuesday','Wednesday','Thursday','Friday']

# for i in weekdays:
#     print(weekdays)

# print(weekdays[0])

# for i in weekdays:
# 	print(i)

# a_tuple=('ready','fire','class')


# list('cat')


#! bin/env/python python3
# -*- coding:utf-8 -*-

d,n = map(int, input().split())


# print(d)
# print(n)

if d == 0:
	if n ==100:
		print(101)
	else:
		print(n)
elif d == 1:
	if n ==100:
		print(10100)
	else:
		print(n*100*d)


elif d == 2:
	if(n == 100):
		print(1010000)
	else:
		print(n*10000)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x,a,b;
    cin>>x;
    a=-1*400;
    b=1*400;
    for(long long int i=a;i<=b;i++)
    {
       // cout<<i<<'\n';
        int t=4;
        long long A=i;
        while(t--)
        A*=i;
        long long k=A-x;
       // cout<<A<<" "<<k<<'\n';
        for(long long int j=a;j<=b;j++)
        {
            t=4;
            long long B=j;
            while(t--)
            B*=j;
          //  cout<<B<<'\n';
            if(k==B)
            {
                cout<<i<<" "<<j;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main() {
  int n,h,w; cin >> h >> w >> n;

  h=max(h,w);
  cout << (n+h-1)/h << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  
  int menu[5], sum=0, div=10, i;
  
  if(scanf("%d", &menu[0])==0) return -1;
  if(scanf("%d", &menu[1])==0) return -1;
  if(scanf("%d", &menu[2])==0) return -1;
  if(scanf("%d", &menu[3])==0) return -1;
  if(scanf("%d", &menu[4])==0) return -1;

  for(i=0;i<5;i++){	
    if(menu[i]%10==0) sum+=menu[i];
  	else sum+=(menu[i]+(10-menu[i]%10));
  }
  for(i=0;i<5;i++){
    if(menu[i]%10==0) continue;
    else if(menu[i]%10<div) div=menu[i]%10;
  } 
  
  printf("%d", sum-10+div);
  
  return 0;
}

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

using Graph = vector<vector<int>>;
Graph G;
void dfs(int u, int p, vector<int> &ans){
  if(p != -1) ans[u] += ans[p];
  for(auto v: G[u]){
    if(v == p) continue;
    dfs(v, u, ans);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  G.resize(n);
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> ans(n, 0);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0, -1, ans);
  rep(i,n){
    cout << ans[i] << (i == n - 1 ? "\n" : " ");
  }
}

Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

constexpr ll LNF = 1e15;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    int p = 0, q = INF;
    rep(i,0,n){
        cin >> a[i];
        chmax(p,a[i]);
        chmin(q,a[i]);
    }
    int d = p-q;
    if(d>=2){
        cout << "No" << endl;
        return 0;
    } else if(d==1){
        int c = 0;
        rep(i,0,n){
            if(a[i]==q){
                c++;
            }
        }
        n -= c;
        p -= c;
        debug(n,p);
        if(n>=2*p && 0<p){
            cout << "Yes" << endl;
        } else{
            cout << "No" << endl;
        }
    } else{
        if(n>=2*p || n-1==p){
            cout << "Yes" << endl;
        } else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
using namespace std; typedef long long ll; const int INF=100; typedef pair<int,int> P;
const int ld=10;

int main() {
  int n; cin>>n;
  int a[ld]; fill(a,a+ld,0);
  //cout<<n<<endl;
  int i=0;
  while(i<n) {
    //cout<<n<<" "<<endl;
    int jj=-1;
    for(int j=ld-1;j>=0;j--) {
      if (a[j] != 9) {
        a[j]++; jj=j; break;
      }
    }
    if (jj==-1) return 0;
    for(int j=jj+1;j<ld;j++) {
      a[j]=max(0,a[j-1]-(j-jj));
    }
    bool ng=false;
    for(int j=1,st=0;j<ld;j++) {
      if (a[j-1]!=0) st=1;
      if (st && abs(a[j-1]-a[j]) > 1) {ng=true; break;}
    }
    if (!ng) i++;
  }
  for(int i=0,st=0;i<ld;i++) {
    if(a[i]!=0) st++;
    if(st) cout<<a[i];
  } cout<<endl; 
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
char str[maxn];
int nxt[26];
int trie[maxn][26];
int vis[maxn], parent[maxn];
int M(){
    if(!~scanf("%s", str))
        return 0;
    int len = strlen(str);
    memset(nxt, -1, sizeof(nxt));
    memset(trie, -1, sizeof(trie));
    memset(vis, 0, sizeof(vis));
    for(int e = len-1; e >= 0; e--){
        for(int f = 0; f < 26; f++)
            trie[e + 1][f] = nxt[f];
        nxt[str[e] - 'a'] = e + 1;
    }
    for(int f = 0; f < 26; f++)
        trie[0][f] = nxt[f];
    queue<int> q;
    q.push(0);
    string ans = "";
    while(!q.empty()){
        int cur = q.front(); q.pop();
        // cout << cur << endl;
        for(int f = 0; f < 26; f++){
            if(trie[cur][f] != -1){
                if(!vis[trie[cur][f]]){
                    q.push(trie[cur][f]);
                    vis[trie[cur][f]] = 1;
                    parent[trie[cur][f]] = cur;
                }
            } else {
                ans.push_back(f + 'a');
                while(cur){
                    int iv = parent[cur];
                    for(int f = 0; f < 26; f++)
                        if(trie[iv][f] == cur){
                            ans.push_back('a' + f);
                            break;
                        }
                    cur = iv;
                }
                reverse(ans.begin(), ans.end());
                cout << ans << endl;
                return 1;
            }
        }
    }
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 22400
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 20
#define int long long
#define MOD 998244353

int32_t main()
{
	IOS
	double a,b,n;cin>>a>>b>>n;
	double q = a*min((b-1),n);
	double p = floor(q/b);
	cout<<p;
	return 0;
}

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



int main() {
  int n;
  
  cin>>n;
  int z=0;
  rep(i,n){
    int next1,next2;
    cin>>next1>>next2;
    if(next1==next2)z+=1;
    else z=0;
    if(z==3){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  
  cout<<"No"<<endl;
  return 0;
}



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

const int Maxn = 200;

int n;
int res[Maxn];
int L, R;

int Ask(int l, int r)
{
    printf("?");
    for (int i = l; i <= r; i++)
        printf(" %d", i);
    printf("\n"); fflush(stdout);
    string res; cin >> res;
    return res == "Red"? -1: 1;
}

int Ask(int x)
{
    printf("? %d", x);
    for (int i = 1; i <= 2 * n; i++)
        if (i != L && i != R && (L < i && i < R) != (L < x && x < R))
            printf(" %d", i);
    printf("\n"); fflush(stdout);
    string res; cin >> res;
    return res == "Red"? -1: 1;
}

int main()
{
    scanf("%d", &n);
    int prv = Ask(1, n);
    int lef = 2, rig = n;
    while (lef <= rig) {
        int mid = lef + rig >> 1;
        if (Ask(mid, mid + n - 1) == prv) lef = mid + 1;
        else rig = mid - 1;
    }
    lef--;
    L = lef; R = lef + n;
    res[L] = prv; res[R] = -prv;
    for (int i = 1; i <= 2 * n; i++)
        if (i != L && i != R) res[i] = Ask(i);
    printf("! ");
    for (int i = 1; i <= 2 * n; i++)
        printf("%c", res[i] == -1? 'R': 'B');
    printf("\n"); fflush(stdout);
    return 0;
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
ll a[200009];
ll n;ll k;
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    sort(a,a+n);
    ll l=-1e18,r=1e18;
    while(r-l>1)
    {
        ll mid=(l+r)/2;ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]>0){
                cnt+=upper_bound(a,a+n,(long double)mid/a[i])-a;
            }
            else if(a[i]<0){
                cnt+=n-(lower_bound(a,a+n,(long double)mid/a[i])-a);
            }
            else if(mid>=0)cnt+=n;
            if(a[i]*a[i]<=mid)cnt--;
        }
        if(cnt>=k*2)r=mid;
        else l=mid;
    }
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 1792
def combi(n):
  cmb = []
  end = 2 ** n
  for i in range(end):
    b = list(bin(i).replace('0b', ''))
    b = '0' * n + ''.join(b)
    b = b[-n:]
    cmb.append(list(b))
  return cmb


str = input()

n = len(str) - 1
cmb = combi(n)
sentences = []
for c in cmb:
  s = str
  for i in range(n - 1, -1, -1):
    if c[i] == '1':
      i += 1
      s = s[:i] + '+' + s[i:]
  sentences.append(s)

sum = 0
for sentence in sentences:
  nums = sentence.split('+')
  for num in nums:
    sum += int(num)
    
print(sum)

Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
mat=limii()

a=max(mat)


# 初期化（ABC035Cオセロだと最初はすべて黒と仮定される）
arr = [0] * (a+3)

# いもす法の加算処理
for jj in range(n):
    l, r = mat[jj],mat[jj]+2  # 区間[l, r]の入力を受け取る
    arr[l] += 1
    if r+1 != a+3:
        arr[r+1] -= 1
#print(arr)
# いもす法の累積和（構築処理）
cum = [0] * (a+3)
for i in range( a+3):
    cum[i] += cum[i-1] + arr[i]
#print(cum)
# 答えを出力
ans = max(cum[1:])
print(ans)


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
//#define FAST ios::sync_with_stdio(0);cin.tie(),cout.tie();
using namespace std;
int main()
{
   // FAST
    int n, m,i;
    scanf("%d", &n);
    vector<int>v;
    for( i=0; i<n; i++)
    {
        cin>>m;
        v.pb(m);
    }
    sort(v.begin(),v.end());
    ///int k=0,x,y,mid1=(n/2)-1,mid2=n/2;
    cout<<v[(n/2)]-v[(n/2)-1]<<endl;
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

int main()
{
	int N, K;
	char S[100];

	scanf("%d%d", &N, &K);
	scanf("%s", S);

	S[K - 1] -= 'A' - 'a';

	printf("%s", S);
		
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  
  int num3 = 0;
  
  for(int i = 1;i <= N;++i){
    int num2 = 0;
    for(int num = 1;num <= i;++num){
      if(i % 2 == 1){
        if(i % num == 0){
          num2++;
        }
      }
    }
    if(num2 == 8){
      num3++;
    }
  }
  
  cout << num3 << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $Q);
fscanf(STDIN, "%s", $S);
$sum = array_pad(array(), $N, 0);
for ($i = 1; $i < $N; $i++) {
    $sum[$i] = $sum[$i - 1] + ($S[$i - 1] . $S[$i] === 'AC');
}
for ($i = 0; $i < $Q; $i++) {
    fscanf(STDIN, "%d %d", $l, $r);
    echo $sum[$r - 1] - $sum[$l - 1] . PHP_EOL;
}


Measured memory_bytes: 9336
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
const ll N = 1e6;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod = 1e9+7;
const ll INF = 1e14;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pld pair<ld,ld>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
void mul(std::vector<vector<ll>> &a,std::vector<vector<ll>> b){
    ll n = a.size();
    std::vector<std::vector<ll>> c;
    c = a;
    // for(int i = 0;i<n;i++){
    //     for(int j = 0;j<n;j++){
    //         cout<<b[i][j]<<" ";
    //     }
    //     cout<<'\n';
    // }
    // cout<<'\n';

    // for(int i = 0;i<n;i++){
    //     for(int j = 0;j<n;j++){
    //         cout<<a[i][j]<<" ";
    //     }
    //     cout<<'\n';
    // }
    // cout<<'\n';
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            a[i][j] = 0;
            for(int k = 0;k<n;k++){
                 a[i][j]+=c[i][k]*b[k][j];
                 a[i][j]%=mod;
            }
        }
    }   

    // for(int i = 0;i<n;i++){
    //     for(int j = 0;j<n;j++){
    //         cout<<a[i][j]<<" ";
    //     }
    //     cout<<'\n';
    // }
    // cout<<'\n';
}
void matrix_exp(std::vector<vector<ll>> &mat,ll k){
    std::vector<std::vector<ll>> te = mat;
    while(k){
        // cout<<k<<'\n';
        if(k%2){
            mul(mat,te);
        }
        k/=2;
        mul(te,te);
    }
}
int main() {   
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin>>t; 
    while(t--){
        ll n,k;cin>>n>>k;
        std::vector<vector<ll>> adj(n,vector<ll>(n));
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++){
                cin>>adj[i][j];
            }
        }
        matrix_exp(adj,k-1);
        ll ans = 0;
        for(int i =0;i<n;i++){
            for(int j = 0;j<n;j++){
                ans+=adj[i][j];
                ans%=mod;
            }
        }
        cout<<ans<<'\n';
    }
}              

Measured memory_bytes: 384
from collections import Counter
 
N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)
 
S = 0
for c in cntA.values():
    S += c * (c - 1) // 2
 
ans = []
for a in A:
    ans.append(S - (cntA[a] - 1))
print(*ans, sep='\n')

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

using namespace std;

int main() {
    int64_t X;
    cin >> X;

    int64_t balance = 100;
    int64_t i = 0;
    while (balance < X) {
        i++;
        balance *= 1.01;
    }

    cout << i << endl;

    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;

  int sum = 0;
  for(int i=A; i<=B ; i++){
    if(i%10 == i/10000 && (i/10)%10 == (i/1000)%10){
      sum++;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define brep(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define orep(i, n) for (int i =  1; i <= (int)n; i++)
#define vec vector
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ll long long

int main(void)
{
	ll n;
	cin >> n;

	ll left = 1;
	ll right = n;
	while(1) {
		ll mid = (left + right) / 2;
		if (mid * (mid + 1) / 2 < n) {
			left = mid + 1;
		} else right = mid;
		if (right == left) break;
	}
	while(1) {
		cout << left << endl;
		n -= left;
		if (n == 0) break;
		if (n < left) left = n;
		else left--;
	}
	return 0;
}

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

const static int MOD = (1e+9)+7;

int modpow(int a,int n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    int t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    int n,m;cin>>n>>m;
    vector<P> ans;
    int i = 1;
    int j = n;
    int cnt = 0;
    set<int> lst;
    while(cnt<m){
        if(lst.count(j-i) || lst.count(n - (j-i)) || j-i == n-j+i){
            j--;
        }else{
            ans.push_back(make_pair(i,j));
            lst.insert((j-i));
            lst.insert(n-(j-i));
            i++,j--;
            cnt++;
        }
    }
    rep(i,m){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}

Measured memory_bytes: 12328
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut res:i64 = 0;
    let mut mx = a[0];
    for i in 1..n {
        if a[i]>mx {
            mx = a[i];
        } else {
            res += (mx-a[i]) as i64;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, T; cin >> N >> T;
    vector<int> A(N), B(N);
    REP(i, 0, N) cin >> A[i] >> B[i];

    vector<vector<int>> dp1(N + 1, vector<int>(T, 0));
    vector<vector<int>> dp2(N + 1, vector<int>(T, 0));
    REP(i, 0, N) {
        REP(j, 0, T) {
            dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j]);
            if (j + A[i] < T) dp1[i + 1][j + A[i]] = max(dp1[i + 1][j + A[i]], dp1[i][j] + B[i]);
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        REP(j, 0, T) {
            dp2[i][j] = max(dp2[i][j], dp2[i + 1][j]);
            if (j + A[i] < T) dp2[i][j + A[i]] = max(dp2[i][j + A[i]], dp2[i + 1][j] + B[i]);
        }
    }

    int ans = 0;
    REP(i, 0, N) {
        REP(j, 0, T) {
            // cout << "# j : " << j << ", T - j - 1 : " << T - j - 1 << endl;
            // cout << "--> " << dp1[i][j] << " " << dp2[i + 1][T - j - 1] << endl;
            ans = max(ans, dp1[i][j] + dp2[i + 1][T - j - 1] + B[i]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 73648
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll r(ll a,ll b){
	if(a%b!=0)return a/b+1;
	else return a/b;
}
int main(){
	fast;
	ll h,w,n;
	cin>>h>>w>>n;
	cout<<min(r(n,h),r(n,w))<<endl;
	return 0; 
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	x := solve(n, a, b)
	fmt.Println(x)
}

func solve(n, a, b int) int {
	d := b - a
	if d%2 == 0 {
		return d / 2
	}

	da := a - 1
	db := n - b
	if da > db {
		return db + 1 + (((n - a) - db - 1) / 2)
	}
	return da + 1 + ((b - da - 1) / 2)
}


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

main()
{
    int n,k; cin>>n>>k;
    vector f(n,1);
    for(int i=0; i<k; ++i)
    {
        int m; cin>>m;
        while(m--)
        {
            int a; cin>>a; --a;
            f[a]=0;
        }
    }
    cout << accumulate(begin(f),end(f),0) << "\n";
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int l;
	string s;
	cin >> s;
	l = s.l_ength();
	cout << (((s[0]==s[l-1])^(l%2))?"First":"Second") << endl;
	return 0;
}


Measured memory_bytes: 512
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
#define exist_in(list, value) (list.end() != std::find(all(list),value))
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
//template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
//template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
//template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
//template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
//template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }
//template<class T1, class T2> bool exist_in(const T1& list, const T2& v) { return (list.end() != std::find(list.begin(), list.end(), v)); }
//template<class T> bool exist_in(const T& c, const typename T::value_type& v) {	return (c.end() != std::find(c.begin(), c.end(), v));}

/*****/

void Main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a != b && a != c)
		cout << a;
	if (b != a && b != c)
		cout << b;
	if (c != a && c != b)
		cout << c;
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


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

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

    double cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (i%2 == 1) cnt++;
    }

    double ans = cnt/(double)n;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()

l = ["A","C","G","T"]
res = 0

for i in range(len(s)):
    #print(i)
    tmp = 0
    #print(s[i:])
    for j in s[i:]:
        if j in l:
            tmp += 1
        else:
            res = max(res,tmp)
            #print(res)
            break
    else:
        res = max(res,tmp)
else:
    print(res)


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    ull N, K;

    std::cin >> N >> K;

    vector<int> dest = fetch_vec<int>(N);

    unordered_map<int, int> seq;
    int curr = 1;
    int count = 0;

    while (K > 0 && seq.count(curr) == 0) {
        --K;
        ++count;
        seq[curr] = count;

        curr = dest[curr-1];
    }

    if (K == 0) return curr;

    K %= (count - seq[curr] + 1);

    while (K > 0) {
        --K;
        curr = dest[curr-1];
    }

    return curr;
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

Measured memory_bytes: 11024
def f(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr

  
A, B = list(map(int, input().split()))
a = f(A)
b = f(B)

if a == [1] and b == [1]:
  print(1)
else:
  print(len(set(a) & set(b))+1)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

	ll n, k;
	cin>>n;
	ll a[n], b[n], c[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=1;i<n;i++){
		a[i] += max(b[i-1], c[i-1]);
		b[i] += max(a[i-1], c[i-1]);
		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: 2560
<?php
$array = array();

while(true){
	$input = trim(fgets(STDIN));
	
	if($input == 0) break;
	
	$array[] = $input;
}

$count = count($array);

for($i = 0; $i < $count; $i++){
	$case = $i + 1;
	
	if($i == $count - 1) echo 'Case'," ","$case".':'.' '."$array[$i]";
	else echo 'Case'," ","$case".':'.' '."$array[$i]"."\n";
}

?>

Measured memory_bytes: 10956
n=int(input())
a=list(map(int,input().split()))
b=0
for _ in a:
    for i in range(n-1,0,-1):
        if a[i]<a[i-1]:
            a[i],a[i-1]=a[i-1],a[i]
            b+=1
print(*a)
print(b)

Measured memory_bytes: 7616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long a, b, c, k;

	std::cin >> a >> b >> c >> k;

	long long ans = 0;

	ans += std::min(a, k);
	k = std::max(0LL, k - a);

	ans += 0;
	k = std::max(0LL, k - b);

	ans -= std::min(k, c);
	
	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 3636
n=gets.to_i

arr1=gets.chomp.split("")

countw=arr1.count("W")
counte=n-countw

arr2=[]

ans=1000000

if arr1[0]=="W"
    arr2<<[0,0,countw-1,counte]
else
     arr2<<[0,0,countw,counte-1]
 end
 
ans=[ans,arr2[-1][0]+arr2[-1][3]].min


i=1
(n-1).times{
    
    if arr1[i]=="W" 
       arr2<<[arr2[-1][0],arr2[-1][1],arr2[-1][2]-1,arr2[-1][3]]
   
   else 
       arr2<<[arr2[-1][0],arr2[-1][1],arr2[-1][2],arr2[-1][3]-1]
       
   end
   
   if arr1[i-1]=="W"
   
    arr2[-1][0]+=1
else
    arr2[-1][1]+=1
    
end

ans=[ans,arr2[-1][0]+arr2[-1][3]].min

i+=1
}

p  ans




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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;


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

    int a,b;
    cin >> a >> b;

    int ans = 1;

    int cnt=0;
    while(ans<b){
        cnt++;
        ans += (a-1);
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    S = input()
    logging.info("Hello!")

    if S == "SUN":
        print(7)
    elif S == "MON":
        print(6)
    elif S == "TUE":
        print(5)
    elif S == "WED":
        print(4)
    elif S == "THU":
        print(3)
    elif S == "FRI":
        print(2)
    elif S == "SAT":
        print(1)
        
        
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  fix20;
  int n,m;
  cin >> n >> m;
  vvi Graph(n);
  vector<double> dist(n,0);
  rep(i,m){
    int s,t;
    cin >> s >> t;
    Graph.at(s-1).push_back(t-1);
  }
  vi next(n);
  next.at(n-1) = n-1;
  for(int v=n-2;v>=0;v--){
    int len = Graph.at(v).size();
    double sum = 0;
    int maxarg = -1;
    double E = -1.0;
    for(int nv : Graph.at(v)){
      if(dist.at(nv) > E){
        E = dist.at(nv);
        maxarg = nv;
      }
    }
    for(int nv : Graph.at(v)){
      sum += 1.0*(dist.at(nv) + 1.0)/len;
    }
    dist.at(v) = sum;
    next.at(v) = maxarg;
  }
  //rep(i,n) cout << next.at(i) << endl;
  double ans = dist.at(0);
  for(int i=n-2;i>=0;i--){
    int len = Graph.at(i).size();
    int skip = next.at(i);
    if(len == 1) continue;
    for(int v=n-2;v>=0;v--){
      double sum = 0;
      int path = Graph.at(v).size();
      if(v == i) path--;
      for(int nv : Graph.at(v)){
        if(v == i && nv == skip) continue;
        sum += 1.0*(dist.at(nv) + 1.0)/path;
      }
      dist.at(v) = sum;
    }
    ans = min(ans,dist.at(0));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<lli> vi;
typedef vector<vector<lli>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n;
    cin>>n;
    lli ans=0;
    vvi ma(9,(vi(9,0)));
    for(int i=1;i<=n;i++){
        if(i%10==0) continue;
        int l=log10(i);
        if(l==0){
            ma[i-1][i-1]+=1;
            continue;
        }
        else{
            int u,r,c;
            c=pow(10,l);
            u=i/c;
            r=i%10;
            ma.at(u-1).at(r-1)+=1;
        }
    }
    rep(i,9){
        rep(j,9){
        ans+=ma[i][j]*ma[j][i];
        }
    }
    out(ans);
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/abc067/tasks/abc067_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    ll sum = 0;
    REP(i, n) {
        cin >> v[i];
        sum += v[i];
    }
    ll minv = 1e18;
    ll now = 0;
    REP(i, n - 1) {
        now += v[i];
        minv = min(minv, abs(sum - 2 * now));
    }
    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<ctype.h>
int main()
{
     char a[200];
     int i,j,k,s=1,q=0;
     for(i=0;i>=0;i++)
     {
         scanf("%c",&a[i]);
         if(isspace(a[i]))
         {
             break;
         }
     }
     for(j=0;j<i;j++)
     {
         for(k=0;k<i;k++)
         {
              if(a[k]>a[j])
              {
                   char tmp=a[j];
                   a[j]=a[k];
                   a[k]=tmp;
              }
         }
     }
     for(j=0;j<i-1;j++)
     {
         if(a[j]==a[j+1])
         {
             s++;
         }
         else
         {   
             if(s%2!=0)
             {
                 q++;
                 printf("No\n");
                 break;
             }
             else
             {
                 s=1;
             }
         }
     }
     if(q==0)
     {
     if(s%2==0)
     {
         printf("Yes\n");
     }
     else
     {
         printf("No\n");
     }
     }
     return 0;
}

Measured memory_bytes: 1648
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 100000+5;
int n;
int mem[maxn];

int solve()
{
	sort(mem, mem+n);
	int p1 = n/2 - 1;
	int p2 = p1 + 1;

	if(mem[p2] <= mem[p1]) return 0;
	else 
	{
		return mem[p2]-mem[p1];
	}
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> mem[i];
	}
	printf("%d\n", solve());
} 

Measured memory_bytes: 640