akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e18 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n, q;
int c[500001];
int l[500001], r[500001];

int m[500001];
int k = 0;
void add(int v) {
    if (m[c[v]] == 0) k++;
    m[c[v]]++;
}

void del(int v) {
    m[c[v]]--;
    if (m[c[v]] == 0) {
        k--;
    }
}

void solve() {
    int sq = (int)sqrt(n);
    vector<T> qi(q);
    for (int i = 0; i < q; i++) {
        qi[i] = T(l[i]/sq, r[i], i);
    }
    sort(ALL(qi));

    int nl = 0, nr = 0;
    int res[q];
    for (T& t : qi) {
        int i = get<2>(t);
        while (nr < r[i]) {
            add(nr);
            nr++;
        }
        while (nl > l[i]) {
            nl--;
            add(nl);
        }
        while (nl < l[i]) {
            del(nl);
            nl++;
        }
        while (nr > r[i]) {
            nr--;
            del(nr);
        }
        res[i] = k;
    }

    for (int i = 0; i < q; i++) {
        printf("%d\n", res[i]);
    }
}

void input() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++) scanf("%d", c+i);
    for (int i = 0; i < q; i++) {
        scanf("%d%d", l+i, r+i);
        l[i]--;
    }
}

int main() {
    input();
    solve();
}


Measured memory_bytes: 19316
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int N;
    cin>>N;
    vector<string> s(N);

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

    unordered_map<string, long long> mp;

    for(auto& string : s){
        sort(string.begin(), string.end());
        mp[string]++;
    }

    long long answer=0;
    for(auto& factor : mp){
        answer+=factor.second*(factor.second-1)/2;
    }

    cout<<answer<<endl;

    return 0;
}

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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  ll x, k, d;
  cin >> x >> k >> d;

  x = abs(x);
  ll reqto0 = (x + d - 1) / d;
  if (k >= reqto0) {
    k -= reqto0;
    x -= reqto0*d;
    if (k % 2) cout << x + d;
    else cout << abs(x);
  } else {
    cout << abs(x - k * d);
  }
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // }

  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,K,G,H,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;
vector<ll> V;

int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> X;
    V.pb(X);
  }
  sort(ALL(V));
  rep(i,N){
    if(i<N-K){
      M+=V[i];
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 2932
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

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

	string s;
	cin >> s;

	int cnt = 0;
	rep(i, sz(s)) {
		if (s[i] == '1') {
			cnt++;
		}
	}

	out(cnt);

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){
    cout << "Yes" << endl;
}
void no(){
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n , k ;
    cin >> n >> k ;
    ll ans ;
    ll a,b ;
    a = b = 0 ;
    FOR(i,1,n+1){
        if(i%k==0){
            a++ ;
        }
        else if(k%2==0 && i%k == k/2){
            b++ ;
        }
    }
    if(k==1){
        ans = pow(n,3) ; 
    }
    else if(k%2==1){
        ans = pow(a,3) ;
    }
    else{
        ans = pow(a,3) + pow(b,3) ;
    }

    cout << ans <<endl ;
    

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


// min m s.t. a^m = 1 mod n (a, n are coprime)
template<typename T>
T carmichael_lambda(T n){
  auto lcm=[](auto a,auto b){return a/__gcd(a,b)*b;};
  T res=1;
  if(n%8==0) n/=2;
  for(Int i=2;i*i<=n;i++){
    if(n%i==0){
      T tmp=i-1;
      for(n/=i;n%i==0;n/=i) tmp*=i;
      res=lcm(res,tmp);
    }
  }
  if(n!=1) res=lcm(res,n-1);
  return res;
}


template<typename T>
Int isprime(T x){
  if(x<=1) return 0;
  for(T i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}


template<typename T>
T totient(T n){
  T res=n;
  for(T i=2;i*i<=n;i++){
    if(n%i==0){
      res=res/i*(i-1);
      for(;n%i==0;n/=i);
    }
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}


template<typename T>
T mod_pow(T a,long long n,T mod){
  using ll = long long;
  T res(1);
  while(n){
    if(n&1) res=(ll)res*a%mod;
    a=(ll)a*a%mod;
    n>>=1;
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;

  if(isprime(n)) drop(1);

  Int x=carmichael_lambda(n);
  n%=x;
  if(__gcd(n,x)!=1) drop(-1);

  Int phi=totient(x);
  vector<Int> cand;
  for(Int p=2;p*p<=phi;p++){
    if(phi%p) continue;
    cand.emplace_back(p);
    cand.emplace_back(phi/p);
  }

  for(auto c:cand)
    while(phi%c==0 and mod_pow(n,phi/c,x)==1) phi/=c;
  cout<<phi<<endl;
  return 0;
}



Measured memory_bytes: 3224
#include <stdio.h>

int main() {
  long n, m, x;

  scanf("%ld %ld", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%ld", &x);
    n = n - x;
  }

  if (n < 0)
    printf("-1\n");
  else
    printf("%ld\n", n);

  return 0;
}

Measured memory_bytes: 1688
#include <iostream>

int main(){
	int r, g, b;

	std::cin >> r >> g >> b;

	int a = 100*r + 10*g + b;

	if(a % 4 == 0){
		std::cout << "YES" << std::endl;
	}
	else{
		std::cout << "NO" << std::endl;
	}

	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ll N,X;
  cin>>N>>X;
  vector<ull>dp(N+1);
  dp[0]=1;
  for(int i=0;i<N;i++)dp[i+1]=1+dp[i]+1+dp[i]+1;
  vector<ull>p(N+1);
  p[0]=1;
  for(int i=0;i<N;i++)p[i+1]=p[i]+1+p[i];
  ull ans=0;
  for(int i=N;i>=0;i--){
    if(i==0){
      ans++;
      break;
    }
    if(X<=1){
      break;
    }
    else if(X<=dp[i-1]+1){
      X--;
    }
    else if(X==dp[i-1]+2){
      ans+=p[i-1]+1;
      break;
    }
    else if(X<=dp[i-1]+dp[i-1]+2){
      ans+=p[i-1]+1;
      X-=dp[i-1]+2;
    }
    else{
      ans+=p[i];
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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


int main(void){
    
    long long Q,H,S,D;
    long long N;
    
    cin >> Q >> H >> S >> D;
    cin >> N;
    
    S = min (S, H * 2 );
    S = min (S, Q * 4 );
    
    if(N%2 == 0){
        
        cout << min(N*S,(N/2)*D);
        
        
    }else{
        
        cout << min(N*S,(N/2)*D+S);
        
        
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())

signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a % 2 && b % 2 && c % 2)
        cout << min(a * b, min(b * c, a * c)) << "\n";
    else 
        cout << "0\n";

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

struct P {
    int x, y; string s;
    P(string &s, int x, int y) : s(s), x(x), y(y){};
};

int main() {
    int n, q;
    while(cin >> n >> q, n){
        vector<P> v;
        for (int i = 0; i < n; ++i) {
            int x, y; string s;
            cin >> s >> x >> y;
            v.emplace_back(s, y-x+1, y);
        }

        for (int i = 0; i < q; ++i) {
            int ok = 0;
            int p; cin >> p;
            for (auto &&e : v) {
                if(e.x <= p && p <= e.y){
                    cout << e.s << " " << p-e.x+1 << "\n";
                    ok = 1;
                    break;
                }
            }
            if(!ok) puts("Unknown");
        }
    }
    return 0;
}


Measured memory_bytes: 3140
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	long long int a[n], b[n];

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

	map<long long int,long long int> mp;

	for (int i = 0; i < n; i++) {
		mp[a[i]]+=b[i];
	}
  long long int ans=0;
  for(pair<long long int,long long int> x:mp){
    if(x.second<=m){
      ans+=x.first*x.second;
      m-=x.second;
    }
    else{
      ans+=m*x.first;
      break;
    }
  }
  
  cout<<ans<<endl;
      


}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int N,M;
vector<int> a,z;
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){ int x; cin >> x;  z.push_back(x);}
		sort(z.begin(),z.end());
	for(int i=1;i<M;i++){
		a.push_back( abs(z[i]-z[i-1]));
		//cout << abs(z[i]-z[i-1]) << " ";
	}
	//cout << endl;
	sort(a.begin(),a.end(),greater<int>() );
	//for(auto itr=a.begin(); itr<a.end();itr++)printf("%d ",*itr);
	long long ans = 0;

	for(auto itr=a.begin()+N-1; itr<a.end();itr++){ans+=*itr;}
		cout << ans << endl;
	return 0;

}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 1;
  char c = s.at(0);
  for(int i = 0; i < n; i++){
    if(c != s.at(i)){
      c = s.at(i);
      cnt++;
    }
  }
  cout << cnt << endl;
}
  

Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Cake[] cakes = new Cake[n];
		for (int i = 0; i < n; i++) {
		    cakes[i] = new Cake(new long[]{sc.nextLong(), sc.nextLong(), sc.nextLong()});
		}
		long max = Long.MIN_VALUE;
		for (int i = 0; i < 4; i++) {
		    Cake.type = i;
		    Arrays.sort(cakes);
		    max = Math.max(max, getMax(cakes, m));
		}
		System.out.println(max);
    }
    
    static long getMax(Cake[] cakes, int count) {
        long fore = 0;
        long reer = 0;
        for (int i = 0; i < count; i++) {
            fore += cakes[i].getValue();
            reer += cakes[cakes.length - i - 1].getValue();
        }
        return Math.max(Math.abs(fore), Math.abs(reer));
    }
    
    static class Cake implements Comparable<Cake> {
        static int[][] sw = new int[][]{{1, 1, 1}, {-1, 1, 1}, {1, -1, 1}, {1, 1, -1}};
        static int type;
        long[] values;
        
        public Cake(long[] values) {
            this.values = values;
        }
        
        public long getValue() {
            long ans = 0;
            for (int i = 0; i < 3; i++) {
                ans += sw[type][i] * values[i];
            }
            return ans;
        }
        
        public int compareTo(Cake another) {
            long x = getValue();
            long y = another.getValue();
            if (x == y) {
                return 0;
            } else if (x < y) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}



Measured memory_bytes: 27744
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

#include <bits/stdc++.h>
using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define TRUE (0)
#define FALSE (1)

// This value shold be close to used maximum value.  
// #define NUM_MAX 2003001

// void sort(uint32_t *num, uint32_t size);

int main()
{   
    uint32_t array[100];
    uint32_t num;
    uint32_t even_num = 0;
    int32_t i;
    string str;

    cin >> num;

    for (i = 0; i < num; i++) {
        cin >> array[i];
    }

    for (i = 0; i < num; i++) {
        if (array[i] % 2 == 0) {
            if ((array[i] % 3 != 0) && (array[i] % 5 != 0)) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    return 0;
}

// void sort(uint32_t *num, uint32_t size) {
//     uint32_t i, j, k;
//     uint32_t sorted_num;
//     uint32_t array[NUM_MAX] = {0};

//     for (i = 1; i < size + 1; i++) {
//         array[num[i - 1]]++;
//     }

//     sorted_num = 0;

//     for (i = 0; i < NUM_MAX; i++) {
//         for (j = 0; j < array[i]; j++) {
//             num[j + sorted_num] = i;
//         }
//         sorted_num += j;
//         j = 0;
//     }

//     return;
// }


Measured memory_bytes: 256
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


const ll MAX_N = 50;

ll n, m;
vector<ll> a(MAX_N);
vector<ll> b(MAX_N);
vector<vector<bool>> g(MAX_N, vector<bool>(MAX_N, false));
vector<bool> visited(MAX_N);

void dfs(ll v1){
    visited[v1] = true;
    for(ll v2 = 0; v2 < n; v2++){
        if(!(g[v1][v2])) continue;
        if(visited[v2]) continue;
        dfs(v2);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll res = 0;
    cin >> n >> m;
    for(ll i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    for(ll i = 0; i < m; i++){
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        for(ll j = 0; j < n; j++) visited[j] = false;
        bool bridge = false;
        dfs(0);
        for(ll j = 0; j < n; j++){
            if(!(visited[j])) bridge = true;
        }
        if(bridge) res++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <iomanip>
#include <math.h>
#include <mutex>

//#include "Data.h"


using namespace std;


int main()
{
	unsigned long long H, N, sum_damage = 0;
	cin >> H >> N;

	for (unsigned long long i = 0; i < N; i++)
	{
		unsigned int A;
		cin >> A;

		sum_damage += A;
	}

	cout << ((H <= sum_damage) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
def smaller(x, y):
	if x < y: return x
	else: return y

S = raw_input()
n = len(S)
tile = ['0', '1']
cnt1 = 0
cnt2 = 0
for i in range(0, n):
	if tile[i%2] == S[i]:
		cnt1 += 1
	else: cnt2 += 1
print smaller(cnt1, cnt2)

Measured memory_bytes: 5892
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
string a[200005];
int main()
{
	int t,n,i,j,flag=1,max=0,k,s,c[200005]={0};
	cin>>n;

	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+1+n);
	i=1;


	while(i<=n)
	{
		s=1;
		if(a[i]!=a[i-1]) i++;
		while(a[i]==a[i-1]) 
		{
			s++;i++;
		}
		if(s>max)  max=s;
	 c[i-1]=s;	

	}

	for(i=1;i<=n+1;i++)
	{
	
		if(c[i-1]==max)
		{
			cout<<a[i-1]<<endl;
		  }  
	}
 } 

Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);
    if(x<=a*a*b/2)
    {
        double tmp=2*x/(a*b);
        printf("%lf",90-acos(b/sqrt(b*b+tmp*tmp))*180/M_PI);
    }
    else
    {
        double tmp=2*x/(a*a)-b;
        printf("%lf",90-acos((b-tmp)/sqrt(a*a+(b-tmp)*(b-tmp)))*180/M_PI);
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

long long int gcd(long long int a, long long int b) {
	while (a % b != 0 && b % a != 0) {
		if (a > b)
			a %= b;
		else
			b %= a;
	}
	return min(a, b);
}

int main(int argc, char *argv[]) {
	long long int a, b;
	cin >> a >> b;
	long long int c = gcd(a, b);
	cout << a * b / c << endl;
}









Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	
	int n;
	cin>>n;
	char T[100],H[100];
	int t=0;
	int h=0;
	for(int i=0;i<n;i++){
		cin>>T;
		cin>>H;
		if(strcmp(T,H)>0)
			t+=3;
		if(strcmp(T,H)==0){
			t+=1;
			h+=1;
		}
		if(strcmp(T,H)<0)
			h+=3;
	}
	cout<<t<<" "<<h<<endl;

	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int main(void)
{
    int train[16];
    int n;
    int len = 0;

    while (scanf("%d", &n) != EOF){
        if (n == 0){
            printf("%d\n", train[len]);
            len--;
        }
        else {
            len++;
            train[len] = n;
        }
    }

    return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

struct UF{
  std::vector<ll> par, dep, dat;
  vector<deque<ll>> pre;
  UF(int n){
    par.resize(n+1), dep.resize(n+1), dat.resize(n+1);
    pre.resize(n+1);
    init(n);
  }
  void init(int nu){for(int iu=0;iu<=nu;iu++) par[iu] = iu, dep[iu] = 0;}
  ll get(ll a){return dat[find(a)];}
  bool same(int xu, int yu){return find(xu) == find(yu);}
  ll find(int xu){return (par[xu]==xu?xu:find(par[xu]));}

  void unite(int xu, int yu){
    xu=find(xu), yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]){
      par[xu] = yu;
      dat[yu] += dat[xu];
      pre[yu].push_front(xu);
    }else{
      par[yu] = xu;
      dat[xu] += dat[yu];
      pre[xu].push_front(yu);
      if(dep[xu] == dep[yu]) dep[xu]++;
    }
  }

  void decompose(ll a){
    ll parent = find(a);
    ll t = pre[parent].front();pre[parent].pop_front();
    par[t] = t;
    dat[parent] -= dat[t];
  }
};

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vll x(n+1);re(i, n) scanf("%lld",&x[i+1]);
  vvl e = vv(m, 3, 0, ll);
  re(i, m) scanf("%lld %lld %lld", &e[i][1], &e[i][2], &e[i][0]);
  sort(all(e));
  UF uf(n+1);
  rep(i, 1, n+1) uf.dat[i] = x[i];
  vvl br = vv(m, 2, 0, ll);
  re(i, m){
    ll a = e[i][1], b = e[i][2];
    if(!uf.same(a, b)) br[i][0] = uf.get(a), br[i][1] = uf.get(b);
    else br[i][0] = -1, br[i][1] = uf.get(a);
    uf.unite(a, b);
  }
  set<ll> lock;
  ll ans = 0;
  for(int i=m-1;i>=0;i--){
    //std::cout << i << " " << e[i][0] << '\n';
    //if(br[i][0]==-1) std::cout << -1 << " " << uf.get(e[i][1]) << '\n';
    //else std::cout << uf.get(e[i][1]) << " " << uf.get(e[i][2])  << '\n';
    if(lock.find(e[i][1])!=lock.end()) continue;


    if(br[i][0]==-1){
      if(uf.get(e[i][1])<e[i][0]) ans++;
      else lock.insert(uf.find(e[i][1]));
    }else{
      if(uf.get(e[i][1])<e[i][0]) {
        ans++;
        uf.decompose(e[i][1]);
      }else lock.insert(uf.find(e[i][1]));
    }
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int v[n];
  rep(i,n)
  cin >> v[i];
  sort(v,v+n);
  double ans=v[0];
  rep(i,n-1){
    ans=(ans+v[i+1])/2;
  }
  printf("%.10f\n",ans);
}

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

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXS 2000100
#define MAXT 5243000

PLL tree[MAXT]; //{max,nakl}

vector<PLL> zb[MAXS];
vector<LL> mk[MAXS];

LL wyn=0;
int n,m;

void upd(int v,int a,int b,int l,int r,LL val){
	
	if(a>r||b<l)
		return;
		
	if(l<=a&&b<=r){
		tree[v].ST+=val;
		tree[v].ND+=val;
		return;
	}

	tree[v*2].ND+=tree[v].ND;
	tree[v*2+1].ND+=tree[v].ND;
	tree[v*2].ST+=tree[v].ND;
	tree[v*2+1].ST+=tree[v].ND;
	tree[v].ND=0;
	
	int sr=(a+b-1)/2;
	upd(v*2,a,sr,l,r,val);
	upd(v*2+1,sr+1,b,l,r,val);
	
	tree[v].ST=max(tree[2*v+1].ST,tree[2*v].ST);	
}

LL query(int v,int a,int b,int l,int r){
	
	if(a>r||b<l||v>=MAXT)
		return LONG_LONG_MIN;
	
	if(l<=a&&b<=r)
		return tree[v].ST;
	
	tree[v*2].ND+=tree[v].ND;
	tree[v*2+1].ND+=tree[v].ND;
	tree[v*2].ST+=tree[v].ND;
	tree[v*2+1].ST+=tree[v].ND;
	tree[v].ND=0;
	
	int sr=(a+b-1)/2;
	return max(query(v*2,a,sr,l,r),query(v*2+1,sr+1,b,l,r));	
}



int main(){ 
	
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	
	int szer=1;
	while(szer<=n)
		szer*=2;
	szer*=2;
		
	REP(I,m){
		int t1,t2,a1;
		cin>>t1>>t2>>a1;
		zb[t2].PB({t1,a1});
		mk[t1].PB(a1);
	}
	
	LL wyn=0;
	
	FOR(i,1,n){
		
		for(auto x:mk[i])
			upd(1,0,szer-1,0,i-1,x);
			
		LL val=query(1,0,szer-1,0,i-1);
		wyn=max(wyn,val);
		upd(1,0,szer-1,i,i,val);
		
		for(auto x:zb[i]) 
			upd(1,0,szer-1,0,x.ST-1,-x.ND);
		
	}
	
	cout<<wyn;
		
	return 0;
}


Measured memory_bytes: 119296
#include<cstdio>
using namespace std;
bool check(long long n, long long m, long long x) {
    if(n < x) {
        long long target = x - n;
        m -= target * 2;
    }
    return m >= x * 2;
}
int main() {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long l = 0, r = m;
    while(l<r) {
        long long mid = (l+r+1)/2;
        if(check(n, m, mid)) {
            l = mid;
        } else {
            r = mid-1;
        }
    }
    printf("%lld\n", l);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main()
{
	int n, x;
	int m[110];
	int total = 0;
	int min = 1000;
	int ans;
 
	cin >> n >> x;
	for (int i = 0; i < n; ++i)
	{
		cin >> m[i];
		total += m[i];
		if (m[i] < min)
		{
			min = m[i];
		}
	}
 
	ans =  n + (x-total)/min;
 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int N;
   cin >> N;
   int h[N];
   for (int i = 0; i < N; i++) {
      cin >> h[i];
   }
   int dp[N];
   dp[0] = 0;
   dp[1] = dp[0] + abs(h[1] - h[0]);
   for (int i = 2; i < N; i++) {
      int tmp1 = dp[i - 1] + abs(h[i] - h[i - 1]);
      int tmp2 = dp[i - 2] + abs(h[i] - h[i - 2]);
      dp[i] = min(tmp1, tmp2);
   }
   cout << dp[N - 1] << endl;
   return 0;
}


Measured memory_bytes: 1024
N=int(input())
A_list = list(map(int, input().split()))

if N == 0:
    print(1 if A_list[0] == 1 else -1)
    exit()
    
if A_list[0] >=1:
    print(-1)
    exit()


# 成り立つ木が作れるか判定してみる
en = [0]
en[0] = 1

for a in A_list:
    tmp = en[-1] - a
    if tmp < 0:
        print(-1)
        exit()
    en.append(tmp * 2)

en = en[:-1]

branch = A_list[-1]
res = A_list[-1]
nodes = en[-1]
for a, ena in zip(A_list[-2::-1], en[-2::-1]):
    branch = min(branch+a, ena)
    res += branch

print(res)


Measured memory_bytes: 676120
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll t,a,b;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>t;
    if(t == 1) cout<<"Hello World";
    else{
        cin>>a>>b;
        cout<<a + b;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,maxm=1e6+10,inf=0x3f3f3f3f;
int S,T,ans;
struct MAX_FLOW{
	int e,n,Begin[maxn],Next[maxm],to[maxm],w[maxm],d[maxn],cur[maxn];
	inline void add_edge(int x,int y,int z){
		to[++e]=y;
		Next[e]=Begin[x];
		Begin[x]=e;
		w[e]=z;
	}
	inline void add(int x,int y,int z){
		add_edge(x,y,z),add_edge(y,x,0);
	}
	bool bfs(){
		REP(i,1,n) d[i]=-1;
		queue<int> q;
		q.push(S);
		d[S]=0;
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(int i=Begin[u];i;i=Next[i]) if(w[i] && d[to[i]]==-1){
				d[to[i]]=d[u]+1;
				if(to[i]==T) return 1;
				q.push(to[i]);
			}
		}
		return 0;
	}
	int dfs(int x,int Min){
		if(!Min || x==T) return Min;
		int num,Flow=0;
		for(int &i=cur[x];i;i=Next[i])
			if(w[i] && d[to[i]]==d[x]+1 && (num=dfs(to[i],min(Min,w[i])))){
				Flow+=num,Min-=num;
				w[i]-=num,w[i^1]+=num;
				if(!Min) break;
			}
		return Flow;
	}
	void work(){
		while(bfs()){
			REP(i,1,n) cur[i]=Begin[i];
			ans+=dfs(S,inf);
		}
	}
}MF;
vector<int> ve[maxn],num[maxn];
int vis[maxn],w[maxn],fr[maxn];
struct point{
	int x,y;
}E[maxn];
int main(){
	int n=read();
	MF.e=1;
	MF.n=2*n-1;
	S=++MF.n,T=++MF.n;
	REP(i,1,n-1){
		int m=read();
		while(m--){
			int x=read();
			ve[x].push_back(i);
			MF.add(i+n,x,1);
			num[x].push_back(MF.e);
		}
		MF.add(S,i+n,1);
	}
	REP(i,2,n) MF.add(i,T,1);
	MF.work();
	if(ans!=n-1) return printf("-1\n"),0;
	REP(i,2,n) REP(j,0,ve[i].size()-1) if(MF.w[num[i][j]]) w[ve[i][j]]=i;
	queue<int> q;
	int cnt=0;
	for(auto v:ve[1]) vis[v]=1,q.push(v),fr[v]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		E[u]=(point){fr[u],w[u]};
		++cnt;
		for(auto v:ve[w[u]]) if(!vis[v]) q.push(v),vis[v]=1,fr[v]=w[u];
	}
	if(cnt!=n-1) return printf("-1\n"),0;
	REP(i,1,n-1) printf("%d %d\n",E[i].x,E[i].y);
	return 0;
}


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

int main(){
    int N,Y;
    cin >> N >> Y ;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            int sum = 10000*i + 5000*j + 1000*(N-i-j);
            if(sum==Y){
                cout << i << " " << j << " "<< (N-i-j)<<endl;
                return 0;
            }
        }
    }
    cout <<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s[200001]={0},*p1,*p2;
  scanf("%s",s);
  p1 = strchr(s,'A');
  p2 = strrchr(s,'Z');
  printf("%d",p2-p1+1);
  return 0;
}


Measured memory_bytes: 1928
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define ll long long
#define inf 1e17
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
char s[201],t[201];
int len[201],len1,len2,tot;
string ans[201];
inline bool check(int x)
{
	For(i,1,len2)
		if(s[i+x-1]=='?')	continue;
		else	if(s[i+x-1]!=t[i])	return 0;
	return 1;
}
inline void out(int x)
{
	++tot;
	For(i,1,x-1)	if(s[i]=='?')	ans[tot]+='a';else ans[tot]+=s[i];
	For(i,1,len2)	ans[tot]+=t[i];
	For(i,x+len2,len1)	if(s[i]=='?')	ans[tot]+='a';else ans[tot]+=s[i];
}
int main()
{
	scanf("\n%s",s+1);
	scanf("\n%s",t+1);
	len1=strlen(s+1);len2=strlen(t+1);
	Dow(i,1,len1-len2+1)
		if(check(i))	out(i);
	if(!tot)	{puts("UNRESTORABLE");return 0;}
	sort(ans+1,ans+tot+1);
	cout<<ans[1]<<endl;
}
/*
?tc?????
coder
*/

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ret = 0
monsters = A[0]
N.times do |i|
  if monsters <= B[i]
    power = B[i] - monsters
    ret += monsters
    if A[i + 1] <= power
      monsters = 0
      ret += A[i + 1]
    else
      monsters = A[i + 1] - power
      ret += power
    end
  else
    monsters = A[i + 1]
    ret += B[i]
  end
end
puts ret

Measured memory_bytes: 15380
# coding: utf-8
# Your code here!
 
A, B = map(int,input().split())
tmp = A
ctr = 1
if B == 1:
    print(0)
else:
    while True:
        if tmp >= B:
            print(ctr)
            break
        else:
            tmp += A - 1
            ctr += 1

Measured memory_bytes: 3060
from collections import deque
n, a, b = int(input()), list(map(int, input().split())), deque()
append, appendleft = b.append, b.appendleft
flag = True
for i in range(n):
    if flag: append(a[i])
    else: appendleft(a[i])
    flag = not flag
if not flag: b.reverse()
print(" ".join(list(map(str, b))))

Measured memory_bytes: 29124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define ln printf("\n")
const int N=1e5+50;
const int MOD=1e9+7;
const int inf=0x7f7f7f7f;
using namespace std;
int n,x;
char s[N];
double num=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
	  scanf("%d",&x);
	  num+=(double)1/x;
    }
    printf("%.6lf",(double)1/num);
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

x,k,d=MI()
if x>0:
    c=(x+d-1)//d
    if k<c:
        ans=abs(x-d*k)
    else:
        if k&1==c&1:
            ans=abs(x-d*c)
        else:
            ans=abs(x-d*(c-1))
else:
    c=(-x+d-1)//d
    if k<c:
        ans=abs(x+d*k)
    else:
        if k&1==c&1:
            ans=abs(x+d*c)
        else:
            ans=abs(x+d*(c-1))
print(ans)


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

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

  string s;cin>>s;

  map<ll, ll> mp;
  map<ll, ll> div;
  div[0] = 0;
  int k = s[s.size()-1]-'0';
  div[1] = k % 2019;
  mp[div[0]]++;
  mp[div[1]]++;
  ll kake=10;
  ll j=2;
  for(int i=s.size()-2;i>=0;i--){
    // cout<<i<<':'<<div[j]<<endl;
    k = s[i]-'0';
    div[j] = (k * kake + div[j-1]) % 2019;
    mp[div[j]]++;
    kake = kake * 10 % 2019;
    j++;
  }
  ll ans=0;
  for (auto& kv : mp) {
    // cout<<"mp: "<<kv.first<<':'<<kv.second<<endl;
    ans += kv.second * (kv.second-1) / 2;
  }
  cout<<ans<<endl;
 
  return 0;
}


Measured memory_bytes: 16248
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
    nfs
    int i, j, n;
    double p, out[3000] = {}, ans = 0.0;
    out[0] = 1.0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> p;
        for (j = i + 1; j; j--)
            out[j] = out[j-1] * p + out[j] * (1-p);
        out[0] = out[0] * (1 - p);
    }

    for (i = n/2 + 1; i<=n; i++)
        ans += out[i];
        
    printf("%.9f", ans);
}

Measured memory_bytes: 3860
from sys import stdin
def readLine_int_list():return list(map(int, stdin.readline().split()))
def readAll_int(): return list(map(int, stdin))

    
def main():
    n = int(input())
    s = sorted(readAll_int())
    ans = sum(s)
     
    if ans % 10 == 0:
        for i in range(n):
            if s[i] % 2 != 0:
                ans -= s[i]
                break
        if ans % 10 != 0:
            print(ans)
        else:
            print(0)
    else:
        print(ans)
    
if __name__ == "__main__":
    main()
    

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

static const int MAX = 1e5;
static const int INF = 1e9;

// 隣接リストを用いた幅優先探索 O(|V|+|E|)
vector<int> d(MAX, INF); // d[i]:始点sから頂点iまでの最短距離
vector<int> from(MAX, -1);

void bfs(const vector<vector<int>> &G, int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      if (d[G[u][i]] == INF) {
        d[G[u][i]] = d[u] + 1;
        from[G[u][i]] = u;
        q.push(G[u][i]);
      }
    }
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  bfs(G, 0);
  
  cout << "Yes\n";
  for (int i = 1; i < n; i++) cout << from[i] + 1 << '\n';
}

Measured memory_bytes: 10592
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int a = sc.nextInt();
		int b = sc.nextInt();
		for(int i = a; i <= b; i++){
			int digit = String.valueOf(i).length();
			boolean bool = true;
			for(int j = 0; j <= digit/2; j++){
				int low = (int) ((i / Math.pow(10, j)) % 10);
				int up = (int) ((i / Math.pow(10, digit - j - 1)) % 10);
				if(!(bool = low == up)) break;
			}
			if(bool) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 28756
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using GraphC = vector<vector<char>>;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int N, M, K, a;
  cin >> N >> M;
  vector<int> v(M, 0);
  rep(i, 0, N) {
    cin >> K;
    rep(j, 0, K) {
      cin >> a;
      a--;
      v[a]++;
    }
  }

  int ans = 0;
  rep(i, 0, M) if (v[i] == N) ans++;
  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   ll n;
   cin >> n;
   vec<ll> v(n+2);
   repp (i, 1, n+1) { 
      cin >> v[i]; 
   }
   ll sum = 0;
   repp (i, 1, n+2) {
      sum += abs(v[i] - v[i-1]);
   }

   vec<ll> can(n);
   repp (i, 1, n+1) {
      ll s = abs(v[i+1] - v[i]) + abs(v[i] - v[i-1]);
      ll t = abs(v[i-1] - v[i+1]);
      can[i-1] = s - t;
   }

   rep (i, n) {
      cout << sum - can[i] << endl;
   }

   return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>

int solve(int i, int m, int s[],int n){
	int res;
	
	if (m == 0){
		return 1;
	}
	
	if (i >= n){
		return 0;
	}
	res = solve(i + 1, m, s, n) || solve(i + 1, m - s[i], s, n);
	return res;
}

int main(void){

	int n;
	int q;
	
	scanf("%d",&n);
	
	int i;
	int S[n];

	for(i=0;i<n;i++){
	
		scanf("%d",&S[i]);
	
	}
	
	scanf("%d",&q);
	
	int T[q];
	
	for(i=0;i<q;i++){
	
		scanf("%d",&T[i]);
	
	}
	
	for(i=0;i<q;i++){
		if(solve(0,T[i],S,n)==0) printf("no\n");
		else printf("yes\n");
	}
	

	return 0;
}



Measured memory_bytes: 2128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define N_MAX 100000
using namespace std;

typedef pair<int, int> P;

class Factorial {
    private:
        vector<long long int> fac;
    public:
        Factorial(long long int n_max);
        long long int getFactorial(long long int n);
};

Factorial::Factorial(long long int n_max) {
    fac.push_back(1);
    fac.push_back(1);
    for (long long int i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}

long long int Factorial::getFactorial(long long int n) {
    return fac[n];
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<P> pfactors;
    if (M == 1) {
        cout << 1 << endl;
        return 0;
    }
    int M2 = M;
    for (int i = 2; i * i <= M ; i++) {
        int count = 0;
        while (M2 % i == 0) {
            M2 = M2 / i;
            count ++;
        }
        if (count > 0) {
            P temp;
            temp.first = count;
            temp.second = i;
            pfactors.push_back(temp);
        }
    }
    if (M2 > 1) {
        P temp;
        temp.first = 1;
        temp.second = M2;
        pfactors.push_back(temp);
    }
    if (pfactors.size() <= 0) {
        cout << N << endl;
        return 0;
    }

    Factorial fact(N_MAX * 2);

    long long int res = 1;

    for (int i = 0; i < pfactors.size(); i++) {
        res = res * fact.getFactorial(N - 1 + pfactors[i].first) % MOD * modinv(fact.getFactorial(N - 1), MOD) % MOD * modinv(fact.getFactorial(pfactors[i].first), MOD) % MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3444
// sala saste wale 2 q chut gaye contest ke dauran :/
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

// char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
//        'j','k','l','m','n','o','p','q','r','s','t','u','v',
//        'w','x','y','z'};

int32_t main(){
 	fastIO;
 	string s,t;cin>>s>>t;
 	for(int i=0;i<s.size();i++){
 		if(s[i]!=t[i]){
 			cout<<"No"<<endl;
 			return 0;
 		}
 	}
 	cout<<"Yes"<<endl;
} 			



Measured memory_bytes: 3652