akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;


ll getGCD(ll n1, ll n2) {
  while(n1 != n2) {
    if(n1 > n2)
      n1 -= n2;
    else
      n2 -= n1;
  }
  return n1;
}

int main() {
  int n;
  ll p;
  
  cin >> n >> p;
  vector<ll> x(n);

  bool found = false;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] == p) found = true;
  }
  if (!found) x.push_back(p);
  sort(x.begin(), x.end());
  
  int gcd = x[1] - x[0];
  for (int i = 2; i < x.size(); i++) {
    gcd = getGCD(gcd, x[i] - x[i - 1]);
  }
  cout << gcd;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(B%A == 0) {
			System.out.println(A+B);
		}
		else System.out.println(B-A);
		
		//System.out.println();
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define tt long t;cin>>t;while(t--)
#define tez ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define plli pair<lli,lli>
#define vlli vector<lli>
#define vplli vector<plli>
#define pqlli priority_queue <lli>
#define pqplli priority_queue <plli>
#define mplli map<lli,lli>
#define all(v) v.begin(),v.end()
#define alll(s) s.begin(),s.end(),s.begin(), ::tolower
#define allu(s) s.begin(),s.end(),s.begin(), ::toupper

#define mod 1000000007
#define ff first
#define ss second
#define fori(i,a,b)    for(int i=a;i<b;i++)
#define ford(i,a,b)    for(int i=a;i>=b;i--)
#define br cout<<endl
#define sz(v) (long)v.size()
#define YS cout<<"YES"<<endl
#define ys cout<<"yes"<<endl
#define Ys cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define no cout<<"no"<<endl
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define mp make_pair
#define llmn LLONG_MIN
#define llmx  LLONG_MAX
#define stp setprecision
#define fxd fixed
#define tu (char)toupper
#define tl (char)tolower
#define coutv(v) for(lli index=0;index<v.size();index++) {cout<<v[index]<<" ";} br;

using namespace std;

/*
lli count01(string s,char ch){
  lli mx=0,c=0;
  if(ch=='0'){

   fori(i,0,sz(s)){
     if(s[i]=='0'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}

   }

  }
  else{

    fori(i,0,sz(s)){
     if(s[i]=='1'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}

    }

  }
return mx;

}*/
/*
vector<lli> prime(lli n){
  bool a[n+1];
  memset(a,true,sizeof(a));
  for(lli i=2;i*i<=n;i++){
    if(a[i]){
      for(lli j=i*i;j<=n;j+=i)
      {  a[j]=false;}
    }
  }
  vector<lli>v;
  for(lli i=2;i<=n;i++){
    if(a[i]){
      v.pb(i);
    }
  }
  return v;
}

*/
void solve(){
    lli n=0,m;
    string s,ss;
    cin>>n>>m;
    vlli v(n),vv;
    for(lli i=0;i<n;i++){
        cin>>v[i];
    }
    sort(all(v));
    lli ans=0;
    for(lli i=0;i<m;i++){
        ans+=v[i];
    }
    cout<<ans<<endl;
    
    



}

int main(){
tez
    solve();
return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   

    long long ans = -1e18;
    vector<long long>a(2), b(2);
    for(auto &x : a)
        cin>>x;
    for(auto &x : b)
        cin>>x;

    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            long long p = a[i]*b[j];
            ans = max(ans, p);
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3648
n = int(input())
s = [a for a in range(1, 14)]
h = [a for a in range(1, 14)]
c = [a for a in range(1, 14)]
d = [a for a in range(1, 14)]
suits = ['S', 'H', 'C', 'D']
for i in range(n):
  x, y = [z for z in input().split()]
  y = int(y)
  if x == 'S':
    s[y - 1] = 0
  elif x == 'H':
    h[y - 1] = 0
  elif x == 'C':
    c[y - 1] = 0
  else:
    d[y - 1] = 0
data = [s, h, c, d]
for i in range(4):
  for x in data[i]:
    if x != 0:
      print(suits[i], str(x))  
    

Measured memory_bytes: 7708
#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;

typedef vector<ii> vii;
#define int long long 


signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
   // freopen("test.txt","r",stdin);

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

   	vector<char>v;

   	forn(i,n)
   	{
   		if(!v.size())v.pb(s[i]);
   		else if(v.back() == s[i])continue;
   		else v.pb(s[i]);
   	}
   	cout<<v.size();
    
}
    




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

int gcd(int a, int b){
        if(b==0) return a;
        return gcd(b,a%b);        
}


int main(){
        int a,b;
        while(cin >> a >> b){
                
                cout << gcd(a,b) << " " << ( a/gcd(a,b) )*b << endl;
        }
        
        
        return 0;
}

Measured memory_bytes: 1160
S = input()

N = len(S)
T = ['A', 'C', 'G', 'T']
ans = 0
now = 0

for a in S:
    isATCG = False
    if a in T:
        isATCG = True

    if isATCG:
        now += 1
        ans = max(ans, now)
    else:
        now = 0
        isATCG = False

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define Set(a, b) memset(a, (b), sizeof(a))
#define F first
#define S second
#define FT front()
#define BK back()
#define PB push_back
#define MP make_pair
#define repi(i, l, r) for (int i=l ; i <= (int)(r) ; ++i)
#define repd(i, r, l) for (int i=r ; i >= (int)(l) ; --i)
#define repv(x, v) for (auto (x) : v)
#define all(cont) cont.begin(), cont.end()
#define Sort(n) sort(all(n))
#define Sortcmp(n) sort(all(n), cmp)
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define nl "\n"

using namespace std;

bool cmp(const pair<long,long> &a,
              const pair<long,long> &b)
{
    return (a.second < b.second || (a.second == b.second && a.first < b.first));
}

bool binarySearch(int arr[], int n, int x){
    int k = 0;
    for (int b = n/2; b >= 1; b/2)
        while (k+b < n && arr[k+b] <= x) k += b;

    if (arr[k] == x) return k;
    return -1;
}

/* ASCII Table */
/* 48 == '0', 57 = '9', 65 == 'A', 90 == 'Z', 97 == 'a', 122 == 'z' */  

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    long n, a;

    vector<long> v;
    cin >> n;

    repi(i, 0, n-1){
        cin >> a;
        v.PB(a);
    }

    Sort(v);
    long sum1 = 0, sum2 = 0, mid1, mid2;

    mid1 = mid2 = n/2;
    if(n%2 == 0)
        mid1--;


    long left = 0;
    long right = n-1;
    repi(i, 0, n-2){
        if(i == 0)
            sum1 += (v[right]-v[mid1]);
        else{
            sum1 += (v[right]-v[left]);
            if(i%2)
                right--;
            else
                left++;
        }
    }

    left = 0;
    right = n-1;
    repi(i, 0, n-2){
        if(i == 0)
            sum2 += (v[mid2]-v[left]);
        else{
            sum2 += (v[right]-v[left]);
            if(i%2)
                left++;
            else
                right--;
        }
    }    

    cout << max(sum1, sum2) << nl;
    return 0;
}

/* Compile */
// g++ -std=c++11 -O2 -Wall test.cpp -o test
 
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("%d\n", ans);
    }
    return 0;
}
 */
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("Case #%d: %d\n", counterT, ans);
    }
    return 0;
}
 */

Measured memory_bytes: 1400
#include <stdio.h>
#include <iostream>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    string s;
    getline(cin, s);
    rep (i, s.size()) if (s[i] == '.' || s[i] == ',') s[i] = ' ';
    istringstream sin(s);
    bool f = false;
    string w;
    while (sin >> w) if (w.size() >= 3 && w.size() <= 6) {
        if (f) cout << ' ';
        f = true;
        cout << w;
    }
    cout << endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    each (i, a) cin >> i;
    sort(a.begin(), a.end());
    cout << (a.back() - a.front()) << endl;
  }
  
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    ll A[n+1],B[n],C[n+1],ans=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;i++) cin >> C[i];
    A[n] = 1 << 30;
    C[n] = 1 << 30;
    sort(A,A+n+1); sort(C,C+n+1);
    for(int i=0;i<n;i++) {
        ll l = lower_bound(A,A+n+1,B[i])-A;
        ll r = n-(lower_bound(C,C+n+1,B[i]+1)-C);
        ans += l*r;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
struct edge{int to,cost;};
int n,m,s,t,u,v,a,b;
vector<edge> yen[100010];
vector<edge> snuuk[100010];
int d1[100010],d2[100010];
void dijkstra(int s,bool f){
	if(f){
		fill(d1,d1+n+1,INF);
		d1[s]=0;
	}
	else{
		fill(d2,d2+n+1,INF);
		d2[s]=0;
	}
	priority_queue<P,vector<P>,greater<P>> q;
	q.push({s,0});
	while(!q.empty()){
		P p=q.top();
		q.pop();
		if(f){
			if(p.second>d1[p.first])continue;
			for(edge e:yen[p.first]){
				if(p.second+e.cost<d1[e.to]){
					d1[e.to]=p.second+e.cost;
					q.push({e.to,d1[e.to]});
				}
			}
		}
		else{
			if(p.second>d2[p.first])continue;
			for(edge e:snuuk[p.first]){
				if(p.second+e.cost<d2[e.to]){
					d2[e.to]=p.second+e.cost;
					q.push({e.to,d2[e.to]});
				}
			}
		}
	}
}
signed main(){
	cin>>n>>m>>s>>t;
	rep(i,m){
		cin>>u>>v>>a>>b;
		yen[u].push_back({v,a});
		yen[v].push_back({u,a});
		snuuk[u].push_back({v,b});
		snuuk[v].push_back({u,b});
	}
	dijkstra(s,1);
	dijkstra(t,0);
	priority_queue<P,vector<P>,greater<P>> q;
	for(int i=1;i<=n;i++){
		q.push({d1[i]+d2[i],i});
	}
	for(int i=1;i<=n;i++){
		P p;
		while(true){
			p=q.top();
			if(p.second>=i)break;
			q.pop();
		}
		cout<<(int)pow(10,15)-p.first<<endl;
	}
    return 0;
}

Measured memory_bytes: 25204
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin >> n;
    int l = 0;
        l = n%10;
    //cout<< l <<endl;
    if(l==2 || l==4 || l==5 || l==7 || l==9) cout<<"hon"<<endl;
    else if(l==3) cout<<"bon"<<endl;
    else cout<<"pon"<<endl;
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();


        int n = N/X;

        if (N % X > 0) {
            n++;
        }

        int result = n * T;
        System.out.println(result);


    }
}

Measured memory_bytes: 35616
2
3
4
5
6
7
8
9
while 1:
    (H,W) = [int(i) for i in input().split()]
    if H==W==0:
        break
    print('#'*W)
    for i in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#'*W)
    print('')


Measured memory_bytes: 5620
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int _gcd(int m, int n){
    int a = max(m, n);
    int b = min(m, n);

    while(b != 1 && b != 0){
        a %= b;
        swap(a, b);
    }
    return b == 1 ? 1 : a;
}

int main(void){
    ll N, X;
    ll xs[MAX_N];
    ll answer;

    cin >> N >> X;
    rep(i, N){
        ll x;
        cin >> x;
        xs[i] = abs(x - X);
    }

    answer = xs[0];
    rep(i, N - 1){
        answer = _gcd(answer, xs[i + 1]);
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> a(N);
  for (auto& ai: a) scanf("%d", &ai);
  std::sort(a.begin(), a.end());

  printf("%d\n", a.back()-a.front());
}

Measured memory_bytes: 632
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

const INF: i64 = 1 << 40;

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: usize,
    w: usize,
    fld: [chars; h],
  }
  let mut adj = vec![vec![INF; h * w]; h * w];
  for i in 0 .. h * w {
    adj[i][i] = 0;
  }
  for i in 0 .. h {
    for j in 0 .. w - 1 {
      if fld[i][j] == '.' && fld[i][j+1] == '.' {
        adj[i*w+j][i*w+j+1] = 1;
        adj[i*w+j+1][i*w+j] = 1;
      }
    }
  }
  for i in 0 .. h - 1 {
    for j in 0 .. w {
      if fld[i][j] == '.' && fld[i+1][j] == '.' {
        adj[i*w+j][(i+1)*w+j] = 1;
        adj[(i+1)*w+j][i*w+j] = 1;
      }
    }
  }
  for k in 0 .. h * w {
    for i in 0 .. h * w {
      for j in 0 .. h * w {
        adj[i][j] = cmp::min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
  }
  let mut ans = 0;
  for i in 0 .. h * w {
    for j in 0 .. h * w {
      if adj[i][j] != INF {
        ans = cmp::max(ans, adj[i][j]);
      }
    }
  }

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include <cstdio>

int main()
{
        for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                        printf("%dx%d=%d\n", i + 1, j + 1, (i + 1) * (j + 1));
                }
        }

        return 0;
}

Measured memory_bytes: 928
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int a, b, area, perimeter;
        Scanner scan = new Scanner(System.in);
        
        a = scan.nextInt();
        b = scan.nextInt();
        area = a * b;
        perimeter = (a + b) * 2;
        
        System.out.print(area);
        System.out.print(' ');
        System.out.println(perimeter);
        
        
    }
}


Measured memory_bytes: 25976
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<ll> trade;
  bool ud = true;
  ll temp = 1000;
  rep(i, n){
    ll a;
    cin >> a;
    if (ud){ // 谷探し
      if (a <= temp) temp = a;
      else {
        ud = false;
        trade.push_back(temp);
        temp = a;
      }
    }
    else { // 山探し
      if (a >= temp) temp = a;
      else {
        ud = true;
        trade.push_back(temp);
        temp = a;
      }
    }
  }
  if (!ud) trade.push_back(temp);
  ll money = 1000;
  ll m = trade.size() / 2;
  rep(i, m){
    money += (money / trade[i*2]) * (trade[i*2+1] - trade[i*2]);
  }
  cout << money << endl;
  
  return 0;
}
    
    

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <typename T>
class Segment {
    using u32 = uint_fast32_t;
    u32 n;
    vector<T> node;
    T e;                  // 単位元∧初期値
    function<T(T, T)> f;  // 更新
    function<T(T, T)> g;  // 取得

   public:
    Segment(u32 N, T e, function<T(T, T)> f, function<T(T, T)> g, vector<T> v = vector<T>())
        : e(e), f(f), g(g) {
        n = 1;
        while (n < N) n *= 2;
        node.assign(2 * n - 1, e);
        if (N == (u32)v.size()) {
            for (int i = 0; i < N; i++) node[i + n - 1] = v[i];
            for (int i = n - 2; i >= 0; i--) {
                node[i] = g(node[2 * i + 1], node[2 * i + 2]);
            }
        }
    }

    // k番目をaで更新
    void update(u32 k, T a) {
        k += n - 1;
        node[k] = f(node[k], a);
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = g(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    // [a,b)の区間取得
    T get(u32 a, u32 b, u32 k, u32 l, u32 r) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return e;  // 含まない
        if (a <= l && r <= b)            // 完全に含む
            return node[k];
        else {
            T vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
            return g(vl, vr);
        }
    }
    T get(u32 a, u32 b) { return get(a, b, 0, 0, n); }

    T operator[](u32 i) { return node[i + n - 1]; }
};

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        v[i] = (1 << (S[i] - 'a'));
    }
    auto f = [](int a, int b) { return b; };
    auto g = [](int a, int b) { return a | b; };
    Segment<int> tree(N, 0, f, g, v);
    for (int i = 0; i < Q; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            int j;
            char c;
            cin >> j >> c;
            j--;
            tree.update(j, 1 << (c - 'a'));
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int y = tree.get(l, r);
            bitset<26> bs(y);
            cout << bs.count() << endl;
        }
    }
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  if (n % 2 != 0)
  {
    cout << (n / 2 + 1);
  }
  else
  {
    cout << n / 2;
  }

  return 0;
}

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


#define INF 1000000000000

signed main() {
   int n,m;
   cin>>n>>m;
   int ans=0;
   vector<vector<int> >s(m,vector<int>(0));
   rep(i,m){
     int k;
     cin>>k;
     rep(j,k){
       int t;
       cin>>t;
       s[i].push_back(t);
     }
   }
     int zyouken[m];
     rep(i,m){
       cin>>zyouken[i];
     }

   for(int bit=0;bit<(1<<n);++bit){
            vector<bool> onof(n);
     rep(i,n){
       if(bit & (1<<i)){
         onof[i]=true;
       }
     }
       rep(i,m){
         int guuki=0;
         rep(j,s[i].size()){
           if(onof[s[i][j]-1]){guuki++;}
         }
         if(guuki%2==zyouken[i]&&i!=m-1){continue;}
         else if(guuki%2==zyouken[i]&&i==m-1){ans++;}
         else break;
       }
     }

cout<<ans;
}


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

int main(){
  int n, a, b, ans = 0;
  cin >> n >> a >> b;
  for(int i = 1; i <= n; i++) {
    int c = 0;
    for(int j = i; j; j /= 10) c += j % 10;
    if (a <= c && c <= b) ans += i;
  }
  cout << ans << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,W;
  cin>>n>>W;
  ll w[n],v[n];
  REP(i,n)cin>>w[i]>>v[i];

  ll V=1e3;
  ll dp[n*V+1];
  REP(i,n*V+1)dp[i]=LLINF;
  dp[0] = 0;


  REP(i,n){
    for(ll j=n*V; j-v[i]>=0; j--)
      dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
  }


  ll ans = 0;
  for(ll j=n*V; j>=0; j--){
    if(dp[j] <= W){
      ans = j;
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

        
Q = int(input())
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    
max_r = max(r)+1
er_list = eratosthenes(max_r)
count = [0] * max_r


for i in range(len(er_list)):
    if (er_list[i]+1)//2 in er_list:
        count[er_list[i]] = 1
            
count = list(accumulate(count))
for i in range(Q):
    print(count[r[i]] - count[l[i]-1])


Measured memory_bytes: 21916
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  long long int N, tmp;
  std::vector<long long int> X;

  scanf("%lld", &N);

  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    X.push_back(tmp);
  }

  long long int ans = 1e15;
  

  for(long long pos = 1; pos <= 100; pos++){
    tmp = 0;
    for(long long int j = 0; j < N; j++){
      tmp += (X[j]-pos)*(X[j]-pos);
    }
    if(ans > tmp){
      ans = tmp;
    }
    else{
      break;
    }
  }

  std::cerr << "ANswer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;


  int a = std::stoi(S.substr(0, 2)), b = std::stoi(S.substr(2));

  bool y1 = true;
  bool m1 = 1 <= a && a <= 12;
  bool y2 = true;
  bool m2 = 1 <= b && b <= 12;

  bool f1 = y1 && m2;
  bool f2 = y2 && m1;

  if (f1 && f2) {
    std::cout << "AMBIGUOUS" << std::endl;
  }
  else if (f1) {
    std::cout << "YYMM" << std::endl;
  }
  else if (f2) {
    std::cout << "MMYY" << std::endl;
  }
  else {
    std::cout << "NA" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 760
from collections import Counter

N = int(input())
a = list(map(int, input().split()))

s = list(Counter(a).items())

ans = 0

for i in range(len(s)):
    if s[i][0] > s[i][1]:
        ans += s[i][1]
    elif s[i][0] < s[i][1]:
        ans += s[i][1] - s[i][0]
        
print(ans)

Measured memory_bytes: 21232
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int64_t> A(N);
	int64_t sum = 0;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}

	vector<int64_t> X(N);
	for (int i = 1; i < N - 1; i+=2) {
		X[0] += 2 * A[i];
	}
	X[0] = sum - X[0];

	for (int i = 1; i < N; i++) {
		X[i] = 2 * A[i - 1] - X[i - 1];
	}

	for (int i = 0; i < N; i++) {
		if (i) cout << ' ';
		cout << X[i];
	}
	cout << endl;
}

Measured memory_bytes: 4860
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var H = int.Parse(Console.ReadLine());
            var W = int.Parse(Console.ReadLine());
            var N = int.Parse(Console.ReadLine());

            var painted = 0;
            var count = 0;
            while (painted < N)
            {
                if (H > W)
                {
                    // 高さ大 => 列を塗る
                    painted += H;
                    W--;
                }
                else
                {
                    // 幅大 => 行を塗る
                    painted += W;
                    H--;
                }

                count++;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b){
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b){
	int res=1;
	while(b){
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=100002;

 
void solve(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<2*n;i++){
		if(i%2){
			cout<<t[i/2];
		}
		else{
			cout<<s[i/2];
		}
	}
	
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

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

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void Main() {
  int N, M; cin >> N >> M;
  vector<pii> V(M);
  rep(i, 0, M){
    int A; cin >> A;
    int B; cin >> B;
    int C = 0;
    rep(j, 0, B){
      int tmp; cin >> tmp;
      tmp--;
      C ^= (1 << tmp);
    }
    V[i].first = A;
    V[i].second = C;
  }
  vector<vector<int>> dp(M + 1, vector<int>((1 << N), INF));
  rep(i, 0, M + 1) dp[i][0] = 0;
  rep(i, 1, M + 1){
    dp[i] = dp[i - 1];
    rep(j, 0, (1 << N)){
      chmin(dp[i][V[i - 1].second | j], dp[i - 1][j] + V[i - 1].first);
    }
  }
  if(dp[M][(1 << N) - 1] == INF){
    cout << -1 << endl;
  }else{
    cout << dp[M][(1 << N) - 1] << endl;
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 24192
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		var list = new List<int>();
		for(var i=B-A+1;i<=B+A-1;i++){
			list.Add(i);
		}
		Console.Write(list[0]);
		for(var i=1;i<list.Count;i++){
			Console.Write(" "+list[i]);
		}
	}
}

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

using namespace std;

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

    priority_queue<pair<int64_t, int64_t>> q;
    int64_t a, b;
    for (int64_t i = 0; i < N; i++) cin >> a >> b, q.push(make_pair(-b, a));

    int64_t s = 0;
    bool f = true;
    while (!q.empty()) {
        s += q.top().second;
        if (q.top().first > -s) f = false;
        q.pop();
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int x;
	cin >> x;
	if (x >= 30)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int len;
string s1;

int main(){
	cin>>s1;
	len=s1.length();
	for(int i=0;i<len;i++)
		if((s1[i]=='b' && s1[len-i-1]!='d') || (s1[i]=='d' && s1[len-i-1]!='b') || (s1[i]=='q' && s1[len-i-1]!='p') || (s1[i]=='p' && s1[len-i-1]!='q')){
			printf("No");
			return 0;
		}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
string s;
int main() {
    DAU
    cin >> s;
    if (s == "AAA" || s == "BBB")
        cout << "No";
    else cout << "Yes";
    PLEC
}


Measured memory_bytes: 256
import sys

N = int(input())
H_list = [ i for i in map(int, input().split()) ]
ans = 1

for i in range(1, N):
    for j in range(N):
        if j >= i:
            break
        if H_list[i] < H_list[j]:
            break
        if j == i-1:
            ans += 1

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n, k, d;
    cin >> n >> k >> d;
    n = abs(n);
    ll need = n / d;
    if (need > k)
    {
        n -= d * k;
        cout << n << endl;
    }
    else
    {
        n -= need * d;
        k -= need;
        //cout<<n<<" "<<k<<" "<<d<<endl;
        ll a = n;
        ll b = abs(n - d);
        //cout<<a<<" "<<b<<endl;
        if (k & 1)
        {
            cout << b << endl;
        }
        else
            cout << a << endl;
    }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9


int main()
{
    fastio;
    int n,k;
    cin >> n >> k;
    vector<int>v(n);
    int sum=0;
    for(int i=0;i<n;i++)
        cin >> v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<k;i++)
        sum+=v[i];
    cout << sum << endl;
}

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

using namespace std;

const int MAX = 100050;
vector<vector<int>> g;
bool visited[MAX];

void dfs(int v) {
    visited[v] = true;
    for (int to : g[v]) {
        if (!visited[to]) {
            dfs(to);
        }
    }
}

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

    int nVertices, nEdges;
    cin >> nVertices >> nEdges;
    g.resize(nVertices + 1);
    for (int i = 0; i < nEdges; ++i) {
        int u, v, _;
        cin >> u >> v >> _;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int cnt = 0;
    for (int v = 1; v <= nVertices; ++v) {
        if (!visited[v]) {
            dfs(v);
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  int a[n][n-1],b[n];
  for(int i=0;i<n;i++) 
    b[i] = 0;
  for(int i=0;i<n;i++) {
    for(int j=0;j<n-1;j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  // for(int i=0;i<n;i++) {
  //   for(int j=0;j<n-1;j++) {
  //     cerr << a[i][j] << ' ';
  //   }
  //   cerr << '\n';
  // }
  int num_matches = (n*(n-1))/2;
  // cerr << "NUm mathces: " << num_matches << '\n';
  int num_days = 0;
  int days[n] = {0};
  while(num_matches > 0) {
    bool flag = false;
    for(int i=0;i<n;i++) {
      if (b[i] >= n-1) continue;
      auto &oth = a[i][b[i]];
      if (b[oth] < n-1) {

        if (a[oth][b[oth]] == i) {
          days[i] = days[oth] = max(days[i],days[oth]) + 1;
          b[i]++;
          b[oth]++;
          flag = true;
          num_matches--;
          
        }
      }
    }
    num_days ++;
    if (not flag) break;
  }
  if (num_matches == 0) {
    int mxdays = 0;
    for(int i=0;i<n;i++) 
      mxdays = max(mxdays,days[i]);
    cout << mxdays;
  } else {
    cout << -1;
  }
  // if (num_matches)
  // cout << num_matches;
  return 0;
}

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

int main(){
  int N,M;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++){
    cin >> T.at(i);
  }
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; i++){
    cin >> P.at(i) >> X.at(i);
  }
  int ans = 0;
  for (int i = 0; i < M; i++){
    for (int j = 0; j < N; j++){
      if (j == (P.at(i) - 1)){
        ans += X.at(i);
      }
      else{
        ans += T.at(j);
      }
    }
    cout << ans << endl;
    ans = 0;
  }
}

Measured memory_bytes: 256
import numpy as np
from numba import njit

@njit
def update(a):
  n = len(a)
  b = np.zeros_like(a)
  for i,x in enumerate(a):
    l = max(0, i-x)
    r = min(n-1, i+x)
    b[l] += 1
    if r+1 < n:
      b[r+1] -=1
  b = np.cumsum(b)
  return b

n,k = map(int, input().split())
a = np.array(list(map(int, input().split())))

k = min(k, 100)

for _ in range(k):
  a = update(a)
print(' '.join(map(str,a)))


Measured memory_bytes: 129200
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
plus=[[] for i in range(2**(n-1))]
for i in range(2**(n-1)):
    for j in range(n-1):
        x=(i>>j) %2
        #print(x,end=" ")
        if x==1:
            plus[i].append(j+1)
            #print(j)
    plus[i].append(n)
#print(plus)
ans=0
strs=[]
for i in range(2**(n-1)):
    strs=[]
    start=0
    endi=plus[i][0]
    '''print(start,end=" ")
    print(endi,end=" ")
    print(int(s[start:endi]))'''
    #print(endi)
    #len(plus[i])!=0:
    strs.append(int(s[start:endi]))
    for j in range(len(plus[i])-1):
        start=endi
        endi=plus[i][j+1]
        '''print(start,end=" ")
        print(endi,end=" ")
        print(int(s[start:endi]))'''
        strs.append(int(s[start:endi]))
    ans+=sum(strs)
print(ans)

Measured memory_bytes: 42328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = n % k;
  ans = min(ans, abs(k-ans));
  cout << ans << endl;
  return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n, k;

ll gcdSearch(vll a, ll gcd){
  vll modPlus(n), modMinus(n);
  ll A, B;
  A = B = 0;
  REP(i, n){
    modPlus[i] = a[i] % gcd;
    //modMinus[i] = gcd - a[i] % gcd;
    B += gcd - modPlus[i];
  }
  sort(modPlus.begin(), modPlus.end());
  //sort(modMinus.begin(), modMinus.end());

  ll mpIndex, mmIndex, counter, kCounter;
  mpIndex = mmIndex = counter = kCounter = 0;
  ll need = LLINF;
  REP(i, n){
    A += modPlus[i];
    B -= gcd - modPlus[i];
    need = min(need, max(A, B));

    //if(modPlus[mpIndex] > modMinus[mmIndex]){
    //  modPlus[mpIndex] -= modMinus[mmIndex];
    //  kCounter += modMinus[mmIndex];
    //  mmIndex++;
    //  counter++;
    //}
    //else if(modPlus[mpIndex] < modMinus[mmIndex]){
    //  modMinus[mmIndex] -= modPlus[mpIndex];
    //  kCounter += modPlus[mpIndex];
    //  mpIndex++;
    //  counter++;
    //}
    //else{
    //  kCounter += modPlus[mpIndex];
    //  mmIndex++;
    //  mpIndex++;
    //  counter += 2;
    //}
    //if(kCounter > k)
    //  return false;
    //if(counter == n)
    //  return true;
  }
  return need;

}

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

  cin >> n >> k;
  vll a(n);
  ll sum = 0;
  REP(i, n){
    cin >> a[i];
    sum += a[i];
  }
  set<ll> gcd;
  for(ll i = 1; i*i <= sum; i++){
    if(sum % i == 0){
      gcd.insert(i);
      gcd.insert(sum/i);
    }
  }

  ll ans = 1;
  for(ll x : gcd){
    if(gcdSearch(a, x) <= k)
      ans = max(ans, x);
  }

  cout << ans << "\n";
  
  
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in); 
		String str = sc.next();
		String[] strArray = new String[str.length()];
		for (int i = 0; i < str.length(); i++) {
			String str2 = String.valueOf(str.charAt(i));
			strArray[i] = str2;
		}		
			for (int i = 0; i < strArray.length; i++) {
				if(strArray[i].equals("D")||strArray[i].equals("P")) {
					strArray[i] = strArray[i];
				}else if(strArray[i].equals("?")) {
					strArray[i] = "D";
				}
			}
		for (int i = 0; i < strArray.length; i++) { //表示
			System.out.print(strArray[i]);
		}
		System.out.println();
		sc.close();
	}
}


Measured memory_bytes: 58316
#include<iostream>
#include<math.h>
#include<queue>
#include<string>
using namespace std;
int main(){
	int n;cin>>n;
	string s;cin>>s;
	int ans=0;
	for(int i=0;i<n;i++){
		int hoge=0;
		for(int j=0;j+i+1<n;j++){
			if(s[j]==s[j+i+1]){hoge++;}
			else{ans=max(ans,min(hoge,i+1));hoge=0;}
		}
		ans=max(ans,min(hoge,i+1));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
const ll MOD = 1e9 + 7;
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vector<ll> >
#define ins insert
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
	ll n , ans = 0;
	cin >> n;
	ll ar[n];
	for( ll i = 0; i < n; i++ ) cin >> ar[i];
	for( ll i = 1; i < n-1; i++ ){
		debug(ar[i-1],ar[i],ar[i+1],ans);
	if((ar[i]>ar[i-1]&&ar[i]<ar[i+1])||(ar[i]<ar[i-1]&&ar[i]>ar[i+1]))ans++;	
	}
	cout << ans << endl;
	
	
	
	
	
	
	





return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int maxi=max(A,max(B,C));
  int res=A+B+C-maxi;
  int ans=maxi;
  rep(i,K){
    ans*=2;
  }
  cout<<ans+res<<endl;
 
}
  





Measured memory_bytes: 256