akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}

template<typename T>
struct BIT{
  ll n;
  ll k=1;
  vector<T>data;
  BIT(ll size):n(size){
    data.assign(n,0);
    while(k*2<=n)k*=2;
  }
  void add(ll a,T w){
    for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w;
  }
  T sum(ll a){
    T ret = 0;
    for(ll i=a+1;i>0;i-=i&-i)ret+=data[i-1];
    return ret;
  }
  ll search(ll x){
    ll ret=0;    
    for(ll i=k;i>0;i/=2){
      if(ret+i<=n&&data[ret+i-1]<x){
        x-=data[ret+i-1];
        ret+=i;
      }
    }
    return ret;
  }
};

template<typename T>
map<T,ll> compress(vector<T> v){
  auto t=v;
  sort(ALLR(t));
  t.erase(unique(ALL(t)),t.end());
  map<T, ll> ret;
  for(ll i=0;i<(ll)t.size();i++)
    ret[t[i]]=i;
  return ret;
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)a[i]-=k;
  vector<ll>b(n);
  b[0]=a[0];
  rep(i,1,n)b[i]=b[i-1]+a[i];
  auto m=compress(b);
  struct BIT<ll> bit(n+1);
  rep(i,0,n)bit.add(m[b[i]],1);
  ll sumbuf=0;
  rep(i,0,n){
    auto itr=m.lower_bound(sumbuf);
    if(itr!=m.end())res+=bit.sum(itr->se);
    sumbuf+=a[i];
    bit.add(m[b[i]],-1);
  }
  cout<<res<<endl;
  return 0;
}

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

using namespace std;

int main(){
    int a;

    string s,p;

    cin>>a>>s>>p;

    for (int i = 0; i < a; i++)
    {
        cout<<s[i]<<p[i];
    }
    cout<<"\n";
    
    return 0;
}

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

int main(){
	string s, t, str;
	vector<string> vs;
	
	cin >> s;
	for(int i=0 ; i < s.size() ; ){
		if( s[i] == 'e' ){
			t.push_back( 'e' );
			i += 3;
		}else if( s[i] == 'c' ){
			t.push_back( 'c' );
			i += 7;
		}
	}
	
	for(int i=0 ; i < t.size() ; i++ ){
		str.push_back( t[i] );
		if( (i+1 < t.size() && t[i] == t[i+1]) || i+1 == t.size() ){
			vs.push_back( str );
			str.clear();
		}
	}
	int m = vs[0].size();
	for(int i=1 ; i < vs.size() ; i++ ){
		m = max( m , (int)vs[i].size() );
	}
	char ans;
	for(int i=0 ; i < vs.size() ; i++ ){
		if( m == vs[i].size() ){
			ans = vs[i][vs[i].size()-1];
			break;
		}
	}
	if( ans == 'c' ){
		cout << "chicken" << endl;
	}else{
		cout << "egg" << endl;
	}
}

Measured memory_bytes: 0
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b) = scan "%d %d" Tuple2.make

let () =
  Printf.printf "%d" (a*b)


Measured memory_bytes: 5492
import Foundation
func readInts() -> [Int] {
    return readLine()!.components(separatedBy: " ").map { Int($0)! }
}

code_block: do {
    let x_y = readInts()

    for turu in 0 ... x_y[0] {
        let kame = x_y[0] - turu
        if x_y[1] == turu * 2 + kame * 4 {
            print("Yes")
            break code_block
        }
    }

    print("No")
}


Measured memory_bytes: 14076
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<int> d;
    UF(int size):d(size,-1){}
    bool u(int x,int y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(int x,int y){
        return r(x) == r(y);
    }
    int r(int x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    int s(int x){
        return -d[r(x)];
    }
};

//const ll MAX_PRIME = 200000;
//vector<int> primes;
//vector<int> is_prime(MAX_PRIME + 1,true);
//void init_primes(){
//    is_prime[0] = is_prime[1] = false;
//    for(int i = 2; i <= MAX_PRIME;i++){
//        if(is_prime[i]){
//            primes.push_back(i);
//            for(int j = i*2;j<=MAX_PRIME;j+=i) is_prime[j] = false;
//        }
//    }
//}
//void solveF(){
//    init_primes();
//    ll N,P;
//    vector<ll> sum;
//    while(cin >> N >> P){
//        if(N == -1 && P == -1) break;
//        sum.clear();
//        auto idx = upper_bound(primes.begin(),primes.end(),N) - primes.begin();
//        for(int i = 0; i <= P;i++){
//            for(int j = i; j <= P;j++){
//                ll S = primes[idx+i] + primes[idx+j];
//                sum.push_back(S);
//            }
//        }
//        sort(sum.begin(),sum.end());
//        cout << sum[P-1] << endl;
//    }
//}


double func(ll P,ll A,ll B,ll C,ll D,ll E,ll F,ll S,ll M){
    double ret = 0;
    ll sum = M*F*S;
    ll kouritu = sum - P;
    ll T = A + B + C + D + E + (D + E)*(M-1);
    ret = kouritu/(double)T;
    return ret;
}
void solveG(){
    int N;
    while(cin >> N,N){
        vector<pair<double,string>> ans(N);
        for(int i = 0; i < N;i++){
            string L; cin >> L;
            ll P,A,B,C,D,E,F,S,M; cin >> P >> A >> B >> C >> D >> E >> F >> S >> M;
            ans[i] = {pair<double,string>{-func(P,A,B,C,D,E,F,S,M),L}};
        }
        sort(ans.begin(),ans.end());
        for(int i = 0; i < N;i++){
            cout << ans[i].second << endl;
        }
        cout << "#" << endl;
    }
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    //solveF();
    solveG();
    return 0;
}



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

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
string S,T;cin >> S >> T;
bool flag = false;
int x = S.size();
rep(i,x) S.push_back(S[i]);
for(int i = 0; i < x; i++){
	if(S.substr(i,x) == T) flag = true; 
}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char s[4];
	char a, b;
	int i, s1, s2;
	
	s1 = s2 = 0;
	
	scanf("%s", s);
	
	a = s[0];
	
	for(i = 0; i < 4; i++){
		if(s[0] != s[i]){
			b = s[i];
		}
	}
	
	for(i = 0; i < 4; i++){
		if(a == s[i]){
			s1++;
		}
		else if(b == s[i]){
			s2++;
		}
	}
	
	if(s1 == 2 && s2 == 2){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	/*printf("%d %d", s1, s2);*/
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  int a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  for(int x = 1; x <= 5; x++)
  {
    if(a[x - 1] == 0)
    {
      cout << x;
      break;
    }      
  }  
  return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(abs(a - c) <= d ||
     (abs(a - b) <= d && abs(b - c) <= d))
    {
      cout << "Yes" << endl;
    }
  else
    {
      cout << "No" << endl;
    }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X,Y) for(long int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

long int QA[100100],QC[100100],PA[100100],PC[100100];

long int memo[100100];
long int func(long int Q,long int P){
  if(!Q)return P%INF;
  return (((memo[Q-1]*Q)%INF)+(P*memo[Q])%INF)%INF;
}

int main(){
  memo[0] = 1;
  FOR(i,1,100100)memo[i] = (3*memo[i-1])%INF;
  string S;
  cin >> S;
  FOR(i,1,S.size()+1){
    if(S[i-1] == '?')QA[i] = QA[i-1]+1;
    else QA[i] = QA[i-1];
    if(S[i-1] == 'A')PA[i] = PA[i-1]+1;
    else PA[i] = PA[i-1];
  }
  REP(i,1,S.size()){
    if(S[i] == '?')QC[i-1] = QC[i]+1;
    else QC[i-1] = QC[i];
    if(S[i] == 'C')PC[i-1] = PC[i]+1;
    else PC[i-1] = PC[i];
  }
  long int ans = 0;

  FOR(i,1,S.size()-1){
    if(S[i] == 'B' || S[i] == '?')ans += (func(QA[i],PA[i]) * func(QC[i],PC[i]))%INF;
    ans %= INF;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4352
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
bc = []
m.times do
  bc.push gets.split.map(&:to_i)
end
sa = a.sort
sbc = bc.sort_by { |e| -e.last }
s = []
count = 0
flag = false
sbc.each do |e|
  b = e.first
  c = e.last
  b.times do
    s.push c
    count += 1
    if count == n
      flag = true
      break
    end
  end
  break if flag
end
s.size.times do |i|
  sa[i] = [s[i], sa[i]].max
end
puts sa.reduce(:+)


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

#define lli long long int
#define ld long double
#define DEFO(n) lli n = 0;
#define MAX_L lli max = 9000000000000000000;
#define MIN_L lli min = 9000000000000000000;
#define MAX_D ld max = 4500;
#define MIN_D ld min = -4500;
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LD(n)  \
  ld n;        \
  cin > n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define LLIV2(a, b, n)            \
  vector<lli> a(n), b(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i) >> b.at(i);           \
  };
#define LDV(a, n)            \
  vector<ld> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define sum(n) accumulate(n.begin(), n.end(), 0);
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli KSum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(N)
  if(N % KSum(N) == 0) {yes}
  no
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
p0=0
ans=0
for i in range(n):
  if p[i]==i+1 and p0==0:
    ans+=1
    p0=1
  elif p[i]==i+1 and p0==1:
    p0=0
  else:
    p0=0
print(ans)
    




Measured memory_bytes: 14008
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
 
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int n, ma, mb;
int a[40], b[40], c[40];
int dp[41][401][401];

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

int main() {
	cin >> n >> ma >> mb;
	REP(i, n) scanf("%d %d %d", a + i, b + i, c + i);
	
	fill(dp[0][0], dp[41][0], INF);
	dp[0][0][0] = 0;
	
	REP(i, n) {
		REP(j, 401) REP(k, 401) {
			chmin(dp[i + 1][j][k], dp[i][j][k]);
			
			if (j + a[i] > 400 || k + b[i] > 400) continue;
			if (dp[i][j][k] == INF) continue;
			
			chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
		}
	}
	
	int ans = INF;
	FOR(i, 1, 401) FOR(j, 1, 401) {
		int g = gcd(i, j);
		
		if (i / g == ma && j / g == mb) chmin(ans, dp[n][i][j]);
		
	}
	if (ans == INF) ans = -1;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 25984
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 105
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rev(a,n) reverse(a,a+n)
using namespace std;
int main() {
	ll n,y;
	cin>>n>>y;
	rep1(i,0,n) rep1(j,0,n-i) {
		int k=n-i-j;
		if(10000*i+5000*j+1000*k==y){
			cout<<i<<" "<<j<<" "<<k;
			return 0;
		} 
	}
	cout<<"-1 -1 -1"; 
	return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int xd = c - a;
    int yd = d - b;
    int x_3 = c - yd;
    int y_3 = d + xd;
    int x_4 = x_3 - xd;
    int y_4 = y_3 - yd;
    cout << x_3 << ' ' << y_3 << ' ' << x_4 << ' ' << y_4 << '\n';
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll n,x=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		ll t;
		cin>>t;
		if(i%2==1 && t%2==1)
			x++;
	}
	cout<<x;
	return;        
}       
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3580
/* ex6_2
   key_tree */

#include <stdio.h>
// 文字列操作に関する関数が定義されたヘッダファイル
#include <string.h>
// 文字列の長さ制限
#define SIZE 101

int main(void){
    int length;
    char message[SIZE];
    // 文字列を取得
    scanf("%s", &message);
    // 文字列の長さ
    length = strlen(message);
    // 文字列の最後にnull文字があることに注意して、題意の略字を求める
    printf("%c%d%c\n", message[0], length - 2, message[length - 1]);

    return 0;
}

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

int main(){
  int R;
  cin>>R;
  if(R<1200){
    cout<<"ABC"<<endl;
  }else if(R<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

template <class T>
class SegmentTree {
    public:
        int N;
        vector<T> dat;
        T def;
        std::function<T(T, T)> operation;

        SegmentTree(int _n, T _def=1001001001, function<T(T, T)> _operation=[](T a, T b){return min(a, b);});
        T query(int a, int b, int k=0, int l=0, int r=-1);
        void update(int k, T a);
};

template <class T>
SegmentTree<T>::SegmentTree(int _n, T _def, function<T(T, T)> _operation):
    def(_def), operation(_operation) {
    N = 1;
    while (N < _n) N *= 2;
    dat = vector<T>(2*N-1, def);
}

template <class T>
T SegmentTree<T>::query(int a, int b, int k, int l, int r) {
    if (r < 0) r = N;

    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return operation(vl, vr);
}

template <class T>
void SegmentTree<T>::update(int k, T a) {
    k += N - 1;
    dat[k] = a;

    while (0 < k) {
        k = (k - 1) / 2;
        dat[k] = operation(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int main(){
    int N, M;
    string S;
    cin >> N >> M >> S;

    SegmentTree<int> st(N + 1);
    st.update(N, 0);

    vector<int> dp(N + 1);
    dp[N] = 0;
    repr(i, N) {
        if (S[i] == '1') {
            dp[i] = INF;
            st.update(i, INF);
            continue;
        }
        dp[i] = st.query(i+1, min(N + 1, i + M + 1)) + 1;
        st.update(i, dp[i]);
    }

    if (dp[0] < INF) {
        int x = 0;
        while (x < N) {
            int dx = 1;
            while (dp[x + dx] == INF || dp[x] == dp[x + dx]) dx++;
            cout << dx << " ";
            x += dx;
        }
        cout << endl;
    } else {
        puts("-1");
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int a, p;
	cin >> a >> p;
	p += 3*a;
	cout << p/2 << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
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;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m,c;
  cin >> n>>m >> c;
  ll b[m];
  for(int i=0;i<m;i++)cin >> b[i];

  ll s=0;
  for(int i=0;i<n;i++){
    ll t=0;
    for(int i=0;i<m;i++){
      ll a;
      cin >> a;
      t+=a*b[i];
    }
    if(t+c>0)s++;
  }

  cout << s << endl;

}

Measured memory_bytes: 3552
#include <iostream>
using namespace std;
 
int main() {
	int n, t[110], m, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	
	cin >> m;
	for (int i = 1; i <= m; i++) {
		int p, x;
		cin >> p >> x;
		cout << sum - t[p] + x << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
let time = Number(input[0])
let aCount = 0;
let bCount = 0;
for (let i=1; i<time+1; i++) {
  let [a, b] = input[i].split(/\s/);
  if(a < b) {
      bCount += 3;
    } else if(a > b) {
      aCount += 3;
    } else {
        aCount++;
        bCount++;
    }
}
 console.log(aCount + " " + bCount);



Measured memory_bytes: 16752
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # value of pre & cycle
sum_p = 0 # sum of pre + cycle
X = [False] * m # for cycle check
for _ in range(mn):
    if X[x]:
        pre_len = P.index(x)
        cyc_len = len(P) - pre_len
        nxt_len = (n - pre_len) % cyc_len
        cyc = sum(P[pre_len:]) * ((n - pre_len) // cyc_len)
        remain = sum(P[:pre_len + nxt_len])
        print(cyc + remain)
        exit()
    X[x] = True
    P.append(x)
    sum_p += x
    x = x*x % m
print(sum_p)


Measured memory_bytes: 12096
#include <stdio.h>

int  main () {
  int N,i,flag,tmp,count=0;

  scanf("%d",&N);

  int A[N];

  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }
  flag=1;
  while(flag) {
    flag=0;
  for(i=N-1;i>=1;i--) {
    if(A[i] < A[i-1]) {
      tmp = A[i];
      A[i] = A[i-1];
      A[i-1]=tmp;
      flag=1;
      count++;
    }
  }
  }
  
 
  for(i=0;i<N;i++) {
    if(i==0) printf("%d",A[i]);

    else printf(" %d",A[i]);
    if(i==N-1) printf("\n");
  }
  printf("%d\n",count);

  return 0;
  }
      
  
      



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

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

int main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	a--; b--; c--; d--;

	bool res = true;
	rep(i, max(c, d) - a) {
		if(s[a+i] == '#' && s[a+i+1] == '#')
			res = false;
	}
	if(c > d && res) {
		bool ok = false;
		rep(i, d - b + 1) {
			if(s[b+i-1] == '.' && s[b+i] == '.' && s[b+i+1] == '.')
				ok = true;
		}
		res = ok;
	}
	if(res) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int a[12][12];

int main(void){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    loop(i,n){
        cin>>c[i];
        loop(j,m){
            cin>>a[i][j];
        }
    }

    int ans=INT_MAX;
    loop(s,1<<n){
        int cost=0;
        vector<int> d(m);
        loop(i,n){
            if(s>>i&1){
                cost+=c[i];
                loop(j,m){
                    d[j]+=a[i][j];
                }
            }
        }
        bool ok=true;
        loop(j,m){
            if(d[j]<x){
                ok=false;
            }
        }
        if(ok==true){
            ans=min(ans,cost);
        }
    }
    if(ans==INT_MAX){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import sys
from collections import deque,defaultdict
from fractions import gcd
from math import ceil

def N():
    return int(sys.stdin.readline())
def NK():
    return map(int,sys.stdin.readline().split())
def LS_I():
    return [int(x) for x in sys.stdin.readline().split()]
def LS_S():
    return list(input())
def main():
    n =N()
    for i in range(1,10):
        if n%i==0 and 1<=(n//i)<=9:
            print("Yes")
            exit()
    print("No")
                
if __name__ == "__main__":
    main()

Measured memory_bytes: 66028
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

string s,t;

int main(){
	for(int i=0;i<3;i++){
		cin>>s;
		t+=toupper(s[0]);
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
var   a:array[0..100] of qword;
         x,i:longint;
begin
     a[0]:=2;
     a[1]:=1;
       readln(x);
     for i:=2 to x do
       a[i]:=a[i-1]+a[i-2];
    writeln(a[x]);
end.

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
const ll INF = 100000000000000000;

int main(){
    string o,e;
    cin>>o>>e;
    rep(i,0,o.length()-1){
        cout<<o[i];
        if(i<=e.length()-1) cout<<e[i];
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 


void func() {
  LL N;
  cin >> N;
  LL M;
  cin >> M;
  string S;
  cin >> S;

  LL cnt = 0;
  REP(i,S.length()){
    if(S[i]=='0'){
      cnt=0;
    }
    else{
      cnt ++;
    }
    if(cnt>=M){
      cout << -1;
      return;
    }
  }

  LL idx = N;
  VLL D;
  while(idx!=0){
    for(LL j=M; j>=1;j--){
      if(idx-j>=0 && S[idx-j]=='0'){
        D.push_back(j);
        idx -= j;
        break;
      }
    }
  }
  reverse(ALL(D));
  //PRINTSP(D);
  for(auto d : D){
    cout << d <<" ";
  }


  return;
}

 
int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int ans=0;
    char now='-';
    rep(i,n) {
        if(now!=s[i]) {
            ans++;
            now=s[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    ll x, y; cin >> x >> y;
    ll c = 1;
    while(1){
        x *= 2;
        if (x <= y) {
            ++c;
        }else{
            break;
        }
    }
    cout << c << endl;
    return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    if (a > b) swap(a,b);
    cout << (b+w*t > a+v*t ? "NO" : "YES") << newl;
}

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

int main() {
    string s;
    cin >> s;

    int ans1 = -1, ans2 = -1;
    for (int i = 0, sz = s.size(); i < sz - 1; ++i) {
        if (i < sz - 2 && s[i] == s[i+2]) {
            ans1 = i+1, ans2 = i+3;
            break;
        }
        if (s[i] == s[i+1]) {
            ans1 = i+1, ans2 = i+2;
            break;
        }
    }
    
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 512
from collections import defaultdict as dd
N,X,Y = map(int, input().split())
D = dd(int)
for i in range(1,N):
  for j in range(i+1,N+1):
    D[min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)] += 1 
for k in range(1,N):
  print (D[k])

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

  vector<pair<int, int>> ab(N);
  for (int i = 0; i < N; i++) {
    cin >> ab[i].first >> ab[i].second;
  }

  vector<pair<int, int>> cd(M);
  for (int i = 0; i < M; i++) {
    cin >> cd[i].first >> cd[i].second;
  }

  vector<int> answer(N);

  for (int i = 0; i < N; i++) {
    answer[i] = 0;
    int minD = abs(ab[i].first - cd[0].first) + abs(ab[i].second - cd[0].second);
    for (int j = 1; j < M; j++) {
      int d = abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second);
      if (d < minD){
        minD = d;
        answer[i] = j;
      }
    }
    
  }

  for (int i = 0; i < N; i++) {
    cout << answer[i] + 1 << endl;
  }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){
  
  string s;
  cin >> s;

  int len = s.length();
  int d = 0;
  REP(i,len){
    if(s[i] == '*'){
     cout << d << endl;
     break;
    }else if(s[i] == '('){
      d++;
    }else{
      d--;
    }
  }
  return 0;
}




Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

// Most important thing in CP - Have Fun :)

void solve(){
	//write here
    int n,k;
    cin>>n>>k;
    vi arr(n);
    rep(i,0,n)cin>>arr[i];
    vi dp(n,INT_MAX);
    dp[0] = 0;
    for (int i = 1 ; i<n ; i++){
        for (int j = i-1 ; j>=max(0,i-k); j--){
            dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return;
}

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	
		solve();
	return 0;
}

Measured memory_bytes: 3948
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 998244353

typedef vector<int> vi;
typedef pair<int, int> pii;


template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}


void solve() {
    ll n, k;
    cin >> n >> k;

    n = n % k;

    cout << min(n, k-n);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    if (0) {
        int tests;
        cin >> tests;
        for (int i=1; i<= tests; i++) {
            //cout << "Case #" << i << ": ";
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

ll n;
int ans =0;

void dfs(ll x,int a,int b,int c){
    if(x>n){
        return;
    }
    if(a&b&c){
        ans++;
    }
    dfs(10*x+3,1,b,c);
    dfs(10*x+5,a,1,c);
    dfs(10*x+7,a,b,1);
    
}

int main(void){
    cin >> n;
    dfs(0,0,0,0);
    cout << ans <<endl;
    
    return 0;
}













































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

// @@ !! LIM(mod)
// --> f:gcd mod
// ---- inserted function gcd from util.cc
// g = eGCD(a, b, s, t)  --->  sa + tb = g
ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

// gcd(0, x) = x, gcd(-x, y) = gcd(x, y)
ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(abs(a), abs(b), dummy1, dummy2);
}
// ---- end gcd
// ---- inserted library file mod.cc

ll MOD = 1e9 + 7;
// ll MOD = 998244353;

struct Fp {
  ll val;

  Fp(ll t = 0) {
    if      (t >= MOD)  val = t % MOD;
    else if (t >= 0)    val = t;
    else if (t >= -MOD) val = t + MOD;
    else {
      ll v = t % MOD;
      if (v == 0) val = 0;
      else        val = v + MOD;
    }
  }

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

class Comb {
  int nMax;
  vector<Fp> vFact;
  vector<Fp> vInvFact;
public:
  Comb(int nm) : nMax(nm), vFact(nm+1), vInvFact(nm+1) {
    vFact.at(0) = 1;
    for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i-1);
    vInvFact.at(nMax) = vFact.at(nMax).inv();
    for (int i = nMax; i >= 1; i--) vInvFact.at(i-1) = i * vInvFact.at(i);
  }
  Fp fact(int n) { return vFact.at(n); }
  Fp comb(int n, int r) {
    return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n-r);
  }
  // The number of permutation extracting r from n.
  Fp perm(int n, int r) {
    return vFact.at(n) * vInvFact.at(n-r);
  }
};

// ---- end mod.cc
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  Fp ans = 0;
  for (ll k = K; k <= N+1; k++) {
    ans += Fp(k) * (Fp(N) - Fp(k) + Fp(1)) + Fp(1);
  }
  cout << ll(ans) << endl;

  return 0;
}



Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]B = new int[N];
		for(var i=0;i<N;i++){
			B[i] = int.Parse(str[i]);
		}
		int[]A = new int[N];
		bool flag = true;
		for(var i=N-1;i>=0;i--){
			int ct = 0;
			bool flag2 = false;
			for(var j=0;j<N;j++){
				if(A[j]==0){
					ct++;
				}
				if(B[i]==ct){
					if(A[j]==0){
						A[j]=B[i];
						flag2 = true;
						break;
					} else {
						flag=false;
						break;
					}
				}
			}
			if(!flag2){
				flag = false;
				break;
			}
			if(!flag){
				break;
			}
		}
		if(!flag){
			Console.WriteLine("-1");
		} else {
			for(var i=0;i<N;i++){
				Console.WriteLine(A[i]);
			}
		}
	}
}

Measured memory_bytes: 13140
N = int(input())
S = input()

# Sに'ABC'がいくつ含まれているか

count = 0

for i in range(N - 2):
  if S[i] == 'A':
    if S[i + 1] == 'B':
      if S[i + 2] == 'C':
        count += 1

print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

ll getmin(ll a, ll b) { return (a < b) ? a : b; }

int main() {
    int n, w;
    cin >> n >> w;
    int *weight = new int[n + 1];
    int *value = new int[n + 1];
    for (int i = 0; i < n; i++) {
        cin >> weight[i] >> value[i];
    }
    ll **dp = new ll *[n + 1];
    for (int i = 0; i < n + 1; i++) {
        dp[i] = new ll[(n + 1) * 1000];
    }
    for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < (n + 1) * 1000; j++) {
            dp[i][j] = INF;
        }
    }

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

    for (int i = 0; i < n; i++) {
        for (int sum_v = 0; sum_v < (n + 1) * 1000; sum_v++) {
            if (sum_v >= value[i]) {
                dp[i + 1][sum_v] = getmin(dp[i + 1][sum_v],
                                          dp[i][sum_v - value[i]] + weight[i]);
            }
            dp[i + 1][sum_v] = getmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }
    ll ans = 0;
    for (int sum_v = 0; sum_v < (n + 1) * 1000; sum_v++) {
        if ((dp[n][sum_v] <= w) && w != 0) {
            ans = sum_v;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 83576
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

int gate[100010];

int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int l,r;
        cin>>l>>r;
        gate[l]+=1;
        gate[r+1]-=1;
    }
    int ans=0;
    for(int i=1;i<=n;++i){
        gate[i]+=gate[i-1];
        if(gate[i]==m)++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (auto&& i : a) {
		cin >> i;
		sum += i;
	}
	sort(rbegin(a), rend(a));
	for (int i = 0; i < m; i++) {
		if (4 * m * a[i] < sum) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n,m;
#define Maxn 100010
struct Data{
	int a,b;
	bool operator <(const Data &z)const{return a<z.a;}
}data[Maxn];
vector<int> g[Maxn];
int sum[Maxn];
int Ans=0;
void Add(int k,int l,int r,int pos,int id){
	sum[k]++;
	if(l==r){
		g[k].push_back(id);
		return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid)Add(k<<1,l,mid,pos,id);
	else Add(k<<1|1,mid+1,r,pos,id);
}
void Query(int k,int l,int r){
	if(l==r){
		Ans+=l;
		g[k].pop_back();
		sum[k]--;
		return;
	}
	int mid=(l+r)>>1;
	if(sum[k<<1|1])Query(k<<1|1,mid+1,r);
	else Query(k<<1,l,mid);
	sum[k]--;
}
int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;++i){
		scanf("%d%d",&data[i].a,&data[i].b);
	}
	sort(data+1,data+n+1);
	int last=0;
	for(register int i=1;i<=m;++i)
	if(i>=data[1].a){
		int l=1,r=n;
		while(l<r){
			int mid=(l+r)>>1;
			if(i>=data[mid+1].a)l=mid+1;
			else r=mid;
		}
		for(register int j=last+1;j<=l;++j)Add(1,1,10000,data[j].b,i);
		last=l;
		if(sum[1])Query(1,1,10000);
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 4352
//code by lynmisakura.wish to be accepted
/****************************/
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
/***************************/

int main(void){
	int n;cin >> n;
	vector<string> a(n);
	rep(i,n){
		cin >> a[i];
		sort(all(a[i]));
	}
	sort(all(a));
	//for(auto i : a) cout << i << endl;
	ll res = 0;
	ll c = 1;
	for(int i = 1;i < n;i++){
		bool k = true;
		for(int j = 0;j < 10;j++){
			if(a[i][j] != a[i-1][j]){
				k = false;
				break;
			}
		}
		if(k){
			c++;
		}else{
			res += (c*(c-1))/2;
			c = 1;
		}
	}
	res += (c*(c-1))/2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 7296