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

int digitsSum(int number) {
  string number_string = to_string(number);
  int digits_sum = 0;
  for (char c : number_string) {
    digits_sum += c - 48;
  }
  return digits_sum;
}

int main() {
  int N;
  cin >> N;
  int min_digits_sum = numeric_limits<int>::max();
  for (int a = 1; a < N; ++a) {
    int b = N - a;
    int digits_sum = digitsSum(a) + digitsSum(b);
    min_digits_sum = min(min_digits_sum, digits_sum);
  }
  cout << min_digits_sum << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>

int main()
{
    int num[100], n;
    std::cin>> n;

    for(int i = 0; i < n; i++)
        std::cin>> num[i];

    n -= 1;
    for(; n >= 0; n--)
        if(n > 0)
            std::cout<< num[n] << " ";
        else
            std::cout<< num[n];

    std::cout<< std::endl;

    return 0;
}

Measured memory_bytes: 3064
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(readline())
A,B = map(int, readline().split())

flag = False
for i in range(A,B+1):
    if i%K == 0:
        flag = True

print('OK') if flag else print('NG')



Measured memory_bytes: 9244
n = int(input())
p = list(map(float,input().split()))
x = [0]*(n+1)
x[0] = 1
for i in range(n):
  y = [0]*(n+1)
  for j in range(i+1):
    y[j] += x[j]*(1-p[i])
    y[j+1] += x[j]*p[i]
  x = y
print(sum(x[n//2+1:]))

Measured memory_bytes: 48220
s = input()
n = len(s)
mod = 10**9+7
qcnt = [[0,0]for i in range(n)]#それより左の？、右の？のこすう
Acnt = [0]*n#それより左のAのこすう
Ccnt = [0]*n#それより右のCの個数
q = 0
for i in range(n-1):
    if s[i] == '?':
        q += 1
        qcnt[i+1][0] += 1
    elif s[i] == 'A':
        Acnt[i+1] += 1
    qcnt[i+1][0] += qcnt[i][0]
    Acnt[i+1] += Acnt[i]
    qcnt[i+1][0]%=mod
    Acnt[i+1]%=mod
if s[-1] == '?':q += 1
for i in range(n-1,0,-1):
    if s[i] == '?':
        
        qcnt[i-1][1] += 1
    elif s[i] == 'C':
        Ccnt[i-1] += 1
    qcnt[i-1][1] += qcnt[i][1]
    Ccnt[i-1] += Ccnt[i]
    qcnt[i-1][1]%=mod
    Ccnt[i-1]%=mod
ans = 0
for i in range(n):
    
    if s[i] == 'B' or s[i] == '?':
        if qcnt[i][0]+qcnt[i][1]-2 <0:
            val = -(qcnt[i][0]+qcnt[i][1]-2)
            p = pow(3,val,mod)
            q = pow(p,mod-2,mod)
            ans +=q%mod*(3*Acnt[i] + qcnt[i][0])*(3*Ccnt[i]+ qcnt[i][1])%mod
        
        else:ans +=pow(3,qcnt[i][0]+qcnt[i][1]-2,mod)%mod*(3*Acnt[i] + qcnt[i][0])*(3*Ccnt[i]+ qcnt[i][1])%mod
        ans %= mod
    
    
print(ans%mod)


    


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

class sqrt_decomposition{
    public:
    const int B=1000;
    int n;
    vector<int> data,lazy;
    vector<bool> flag;
    sqrt_decomposition(int n,int init):n(n),data(n,init),lazy((n+B-1)/B),flag((n+B-1)/B){}


    void propagate(int i){
        assert(flag[i]);
        flag[i]=false;
        rep(j,0,B){
            if(i*B+j>=n) break;
            data[i*B+j]=lazy[i];
        }
    }

    //[s,t)
    void update(int s,int t,int x){
        while(s<t and s%B!=0){
            if(flag[s/B]) propagate(s/B);
            data[s]=x;
            ++s;
        }
        while(s<t and t%B!=0){
            --t;
            if(flag[t/B]) propagate(t/B);
            data[t]=x;
        }

        while(s<t){
            int i=s/B;
            flag[i]=true;
            lazy[i]=x;
            s+=B;
        }
    }

    int at(int i){
        if(flag[i/B]) return lazy[i/B];
        return data[i];
    }
};

void solve(){
    int n,q;
    cin >> n >> q;
    sqrt_decomposition sd(n,(1LL<<31)-1);

    rep(i,0,q){
        int k;
        cin >> k;
        if(k==0){
            int s,t,x;
            cin >> s >> t >> x;
            ++t;
            sd.update(s,t,x);
        }else{
            int i;
            cin >> i;
            cout << sd.at(i) << endl;
        }
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
#define fastio		ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define For(i,a,b)               for(int i=a;i<b;i++)
#define input(a,n)	For(i,0,n)cin>>a[i]
#define pb                          push_back
#define minimum(a)					*min_element(a.begin(), a.end())
#define maximum(a)					*max_element(a.begin(), a.end())
#define f 	first
#define s 	second
#define nl cout<<endl
#define print(a,n)	For(i,0,n){cout<<a[i]<<' ';}nl
#define pii pair<int,int>
using namespace std;
typedef long long ll;

int main()
{
	fastio;
	int n,res,k;
	cin>>n>>k;
	int a[n],b[n];
	input(a,n);
	b[0]=0, b[1]=abs(a[0]-a[1]);
	For(i,2,n)
	{
		res=b[i-1]+abs(a[i]-a[i-1]);
		For(j,2,min(i,k)+1)
			res=min(res,b[i-j]+abs(a[i]-a[i-j]));
		b[i]=res;
	}
	cout<<b[n-1];
	return 0;
}

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

int main(){
    //入力
    int K,S;
    cin >> K >> S;

    //出力
    int ans=0;
    for(int X=0;X<K+1;X++){
        for(int Y=0;Y<K+1;Y++){
            if((S-X-Y<=K)&&(S-X-Y>=0)){
                ans++;
            }
        }
    }   
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

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

	int x; cin >> x;

	cout << 1-x << '\n';

	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}


int main() {
    int h, w; int n;
    scanf("%d %d %d", &h, &w, &n);
    using P = pair<int, int>;
    set<P> s;
    set<P> check;
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d", &b, &a); a--; b--;
        s.insert(P(a, b));
        for (int x = -2; x <= 0; x++) {
            for (int y = -2; y <= 0; y++) {
                int na = a+x, nb = b+y;
                if (!(0 <= na && na <= w-3)) continue;
                if (!(0 <= nb && nb <= h-3)) continue;
                check.insert(P(na, nb));
            }
        }
    }
    ll co[10] = {};
    for (P p: check) {
        int c = 0;
        for (int x = 0; x <= 2; x++) {
            for (int y = 0; y <= 2; y++) {
                if (s.count(P(p.first+x, p.second+y))) c++;
            }
        }
        co[c]++;
    }
    co[0] = ll(h-2)*(w-2);
    for (int i = 1; i <= 9; i++) {
        co[0] -= co[i];
    }
    for (int i = 0; i <= 9; i++) {
        printf("%lld\n", co[i]);
    }
    return 0;
}

Measured memory_bytes: 47104
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var NW = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = NW[0];
        var W = NW[1];
        var items = new Item[N];

        for (int i = 0; i < N; i++)
        {
            var item = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            items[i] = new Item(item[0], item[1]);
        }

        var problem = new KnapsackProblem(items);
        var dp = problem.Solve(W);

        Console.WriteLine(dp.Last().Last());
    }
}

public struct Item
{
    public int Value { get; }
    public int Weight { get; }

    public Item(int value, int weight)
    {
        Value = value;
        Weight = weight;
    }
}

public class KnapsackProblem
{
    private Item[] _items;

    public KnapsackProblem(IEnumerable<Item> items)
    {
        _items = items.ToArray();
    }

    public int[][] Solve(int W)
    {
        int N = _items.Length;

        var dp = new int[N + 1][].Select(t => t = new int[W+1]).ToArray();

        // DP初期条件
        for (int j = 0; j < W; j++) dp[0][j] = 0;

        // DPループ
        for (int i = 0; i < N; i++)
        {
            for (int w = 0; w <= W; w++)
            {
                if (w >= _items[i].Weight) dp[i + 1][w] = Math.Max(dp[i][w - _items[i].Weight] + _items[i].Value, dp[i][w]);
                else dp[i + 1][w] = dp[i][w];
            }
        }

        return dp;
    }
}


Measured memory_bytes: 21912
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  uint16_t A[N], B[N], C[N];

  for (int n=0; n<N; ++n)
    cin >> A[n] >> B[n] >> C[n];

  uint64_t dp[N][3];

  dp[0][0] = A[0];
  dp[0][1] = B[0];
  dp[0][2] = C[0];
  for (int n=1; n<N; ++n) {
    dp[n][0] = A[n] + max(dp[n-1][1], dp[n-1][2]);
    dp[n][1] = B[n] + max(dp[n-1][0], dp[n-1][2]);
    dp[n][2] = C[n] + max(dp[n-1][0], dp[n-1][1]);
  }

  cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;

  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
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;}

int main(){
	multimap<int,string,greater<int> > data;
	bool ok = false;
	while(1){
		data.clear();
		int n;
		cin >> n;
		if(n==0) break;
		string tmp;
		int a,b,c;
		if(ok) cout << endl; 
		if(ok==false) ok = true;
		REP(i,n){
			cin >> tmp >> a >> b >> c;
			data.insert(multimap<int,string>::value_type(a*3+c,tmp));
		}
		for(multimap<int,string>::iterator it = data.begin();it != data.end(); it++){
			cout<<(*it).second<<","<<(*it).first<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1212
def greatestdivisor(x, y):
    if y>x:
        tmp = x
        x = y
        y = tmp
        
    while y>0 :
        r = x%y
        x = y
        y = r
    print(x)
    
A=input().split(" ")
greatestdivisor(int(A[0]), int(A[1]))




Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int dp[101][100001];
vector<pair<int,int>> vp;
int solve(int n,int target)
{
    if(n==0 || target<=0)
        return 0;
    else if(dp[n][target]!=-1)
        return dp[n][target];
    else 
    {
        if(vp[n-1].F > target)
            return dp[n][target]=solve(n-1,target);
        else
        {
            return dp[n][target]=max(vp[n-1].S + solve(n-1,target-vp[n-1].F),
                solve(n-1,target));
        }
    }
}
int32_t main()
{
    fast;
    int n;cin>>n;
    int target;cin>>target;

    int u,v;
    for(int i=0;i<n;i++){
        cin>>u>>v;
        vp.pb({u,v});
    }

    memset(dp,-1,sizeof(dp));
    cout<<solve(n,target)<<endl;

    return 0;
}

// 1 1 2 2 2 3 3 4 5 6 

Measured memory_bytes: 82568
#include <iostream>
using namespace std;
typedef long long ll;

ll K;
ll A[50];
int main(){
	cin >> K;
	ll a = K/50;
	K %= 50;
	for(int i=0;i<50;i++){
		A[i] = a + i;
	}
	for(int i=0;i<K;i++){
		A[i] += 50;
		for(int j=i+1;j<50;j++){
			A[j]--;
		}
	}
	cout << 50 << endl;
	for(int i=0;i<50;i++){
		if(i!=49) cout << A[i] << " ";
		else cout << A[i] << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
class lazy_segtree {
    private:
        int size;
        vector<long long> node,lazy;
    public:
        lazy_segtree(int n_) {
            size=1;
            while (size<n_) size*=2;
            node.resize(2*size, 0);
            lazy.resize(2*size, 0);
        }
  
        void setlazy(int k,long long v,int l, int r) {
            lazy[k] += v;
            node[k] += v*(r-l);
        }
  
        void push(int k,int l,int r) {
            if (lazy[k] == 0) return ;
            setlazy(k*2+1,lazy[k],l,(r+l)/2);
            setlazy(k*2+2,lazy[k],(r+l)/2,r);
            lazy[k] = 0;
        }
  
        void merge(int k){
            node[k]=node[k*2+1]+node[k*2+2];
        }
  
        void range_add(int queryL,int queryR,int val,int k=0,int nodeL=0,int nodeR=-1) {
            if (nodeR==-1) nodeR=size;
            if (nodeR<=queryL || queryR<=nodeL) return ;
            if (queryL<=nodeL && nodeR<=queryR) {
                setlazy(k,val,nodeL,nodeR);
                return ;
            }
            else {
                push(k,nodeL,nodeR);
                int nodeM=(nodeL+nodeR)/2;
                range_add(queryL,queryR,val,k*2+1,nodeL,nodeM);
                range_add(queryL,queryR,val,k*2+2,nodeM,nodeR);
                merge(k);
                return ;
            }
        }
  
        long long get_node(int queryL,int queryR,int k=0,int nodeL=0,int nodeR=-1) {
            if (nodeR==-1) nodeR=size;
            if (nodeR<=queryL || queryR<=nodeL) return 0;
            if (queryL<=nodeL && nodeR<=queryR) return node[k];
            else {
                push(k,nodeL,nodeR);
                int nodeM=(nodeL+nodeR)/2;
                long long vl=get_node(queryL,queryR,k*2+1,nodeL,nodeM);
                long long vr=get_node(queryL,queryR,k*2+2,nodeM,nodeR);
                return vl+vr;
            }
        }
};
  
int n,q;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> q;
    lazy_segtree ls(n);
    for (int i=0; i<q; i++) {
        int que,s,t,x,idx;
        cin >> que;
        if (que==0) {
            cin >> s >> t >> x;
            ls.range_add(s-1,t,x);
        }
        else {
            cin >> s;
            cout << ls.get_node(s-1,s) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7076
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    
    int sum=A, ans=1;
    if(B==1) {
        cout << 0 << endl;
        return 0;
    }
    
    while(sum<B) {
        sum += A-1;
        ans++;
    }
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<functional>//greaterの使用
using namespace std;
#define MAX_LIST 60000

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int primelist[60000];
	int j=0;
	for(int i=0;i<MAX_LIST;i++){
		if(prime[i]==1){
			primelist[j]=i;
			j++;
			if(j>60000){
				break;
			}
		}
	}
	int in;
	while(cin>>in,in){
		int ans=0;
		for(int i=0;primelist[i]*2<=in;i++){
			if(prime[in-primelist[i]]==1){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e18
#define mod 1000000007

struct edge{
  ll f,t,c;
};

ll n,m,s,t;
ll d1[101010],cnt1[101010];
ll d2[101010],cnt2[101010];
vector<P> g[101010];
vector<edge> es;
bool used[101010];

int main(){
  cin>>n>>m>>s>>t;
  s--; t--;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    g[a].push_back(P(b,c));
    g[b].push_back(P(a,c));
    es.push_back((edge){a,b,c});
  }
  {
    rep(i,n)d1[i]=INF;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));
    d1[s]=0;
    cnt1[s]=1;
    while(que.size()){
      ll nd=que.top().fi,v=que.top().se; que.pop();
      if(d1[v]<nd)continue;
      for(P e : g[v]){
        ll u=e.fi,c=e.se;
        if(d1[u]==nd+c){
          (cnt1[u]+=cnt1[v])%=mod;
        }else if(d1[u]>nd+c){
          d1[u]=nd+c;
          cnt1[u]=cnt1[v];
          que.push(P(nd+c,u));
        }
      }
    }
  }
  {
    rep(i,n)d2[i]=INF;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,t));
    d2[t]=0;
    cnt2[t]=1;
    while(que.size()){
      ll nd=que.top().fi,v=que.top().se; que.pop();
      if(d2[v]<nd)continue;
      for(P e : g[v]){
        ll u=e.fi,c=e.se;
        if(d2[u]==nd+c){
          (cnt2[u]+=cnt2[v])%=mod;
        }else if(d2[u]>nd+c){
          d2[u]=nd+c;
          cnt2[u]=cnt2[v];
          que.push(P(nd+c,u));
        }
      }
    }
  }
  ll tot=d1[t];
  ll res=cnt1[t]*cnt2[s]%mod;
  rep(i,n){
    if(d1[i]*2==tot){
      ll cnt=(cnt1[i]*cnt2[i])%mod;
      res=(res-((cnt*cnt)%mod)+mod)%mod;
    }
  }
  rep(i,es.size()){
    ll u=es[i].f,v=es[i].t,c=es[i].c;
    if(d1[u]>d1[v])swap(u,v); // d1[u] < d1[v];
    if(d1[u]*2<tot&&tot<d1[v]*2&&d1[u]+d2[v]+c==tot){
      ll cnt=(cnt1[u]*cnt2[v])%mod;
      res=(res-((cnt*cnt)%mod)+mod)%mod;
    }
  }
  cout<<res<<endl;
  return 0;
}


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

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

using namespace std;



int main(){
    int N,K;
    
    cin >> N >> K;
 
    int h;
    int ans=0;
    rep(i,N){
        cin >> h;
        if(h>=K){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

def comb(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
x,y = MAP()

if (x+y)%3!=0:
    print(0)
    exit()

n = (2*y - x)//3
m = (2*x -y)//3
if n<0 or m<0:
    print(0)
    exit()
print(comb(n+m,min(n,m),MOD))

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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll ox = x;
  if (x > 0) {
    x -= min(x / d, k) * d;
  } else {
    x += min(abs(x) / d, k) * d;
  }
  if (ox / d < k) {
    if ((k - ox / d) % 2 == 1) {
      ll t1 = x + d, t2 = x - d;
      if (abs(t1) <= abs(t2))
        x = t1;
      else
        x = t2;
    }
  }
  cout << abs(x) << endl;
  return 0;
}


Measured memory_bytes: 3632
def main():

    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    connected = dict()
    for _ in range(M):
        A, B = map(int, input().split())
        if A not in connected:
            connected[A] = H[B-1]
        else:
            connected[A] = max(connected[A], H[B-1])
        if B not in connected:
            connected[B] = H[A-1]
        else:
            connected[B] = max(connected[B], H[A-1])

    ans = 0
    for i in range(1, N+1):
        if i not in connected:
            ans += 1
        elif H[i-1] > connected[i]:
            ans += 1
    return ans

if __name__ == '__main__':
    print(main())


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

using namespace std;

const long mod = 1e9 + 7;

void solve()
{
	long N;
	string S;
	cin >> N >> S;
	map<char, long> cnt;
	for (char c : S)
	{
		cnt[c]++;
	}
	long ans = 1;
	for (auto p : cnt)
	{
		ans *= p.second + 1;
		ans %= mod;
	}
	ans += mod-1;
	ans %= mod;
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

const int maxn = 2e5+100;
const LL mod = 998244353;
const LL INF=1e9;

int a[maxn],b[maxn],a1[maxn],b1[maxn];
int get_ans(int k,int n,int a[],int b[])
{
    int x=1<<k,y=1<<k+1;
    int z=x+y;
    LL cnt=0;
    int i1=n,i2=n,i3=n;
    for(int j=1;j<=n;j++)
    {
        //printf("j=%d ",j);
        while(i1>0&&b[j]>=x-a[i1])
        {
            cnt+=n-j+1;
            i1--;
            //printf("+%d ",n-j+1);
        }
        while(i2>0&&b[j]>=y-a[i2])
        {
            cnt-=n-j+1;
            i2--;
            //printf("-%d",n-j+1);
        }
        while(i3>0&&b[j]>=z-a[i3])
        {
            cnt+=n-j+1;
            i3--;
            //printf("*%d ",n-j+1);
        }
        //printf("\n");
    }
    //printf("k=%d cnt=%d\n",k,cnt);
    cnt=cnt&1;
    return cnt<<k;
}
int main()
{
    int n,i,j,k,x,y;
    int T;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    int ans=0;
    for(k=0;k<30;k++)
    {
        for(j=1;j<=n;j++)
        {
            a1[j]=a[j]&((1<<(k+1))-1);
            b1[j]=b[j]&((1<<(k+1))-1);
        }
        sort(a1+1,a1+1+n);
        sort(b1+1,b1+1+n);
        ans^=get_ans(k,n,a1,b1);
    }
    printf("%d\n",ans);
    return 0;
}

/**

*/


Measured memory_bytes: 3328
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}


int main() {
  int n; cin >> n;
  set<string> s;
  rep(i, n) {
    string t; cin >> t;
    s.insert(t);
  }

  int ans = s.size();
  cout << ans << endl;
}


Measured memory_bytes: 19220
#include <iostream>
#include <string>
using namespace std;
string s;
int main()
{
	cin >> s;
	if (s == "SUN") cout << "7";
	if(s=="MON") cout << "6";
	if (s == "TUE")cout << "5";
	if (s == "WED")cout << "4";
	if (s == "THU")cout << "3";
	if (s == "FRI")cout << "2";
	if (s == "SAT")cout << "1";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int N,K,Q;
int A[100000];

int main(){
    cin>>N>>K>>Q;
    rep(i,Q){
        int id;
        cin>>id;
        A[id-1]++;
    }

    rep(i,N){
        if(K-Q+A[i]>0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 1024
n,l = gets.chomp.split(" ").map(&:to_i)
sum = 0
if l >= 0
    sum = n*(n-1)/2 + l*(n-1)
else
    tn = l + n -1
    if tn <= 0
        sum = -n*(n-1)/2 + tn*(n-1)
    else
        sum = -l*(l-1)/2 + tn*(tn+1)/2
    end
end
puts sum

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i,n) for(int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class T> ostream &operator<<(ostream& os, set<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.FI << "," << P.SE << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 300001;
int t[MAX],sum = 0;
int n;
void pri(int dif){
  cout << (sum + dif) / 2 << " " << (sum - dif) / 2 << "\n";
  exit(0);
}
bool spr(int x){
  int naj = 0;
  R(i,n){
    if(i % 2 == 0){
      naj += t[i];
    }else{
      int pom = naj - t[i];
      if(naj >= x){
        naj = max(pom,0ll);
      }else{
        naj = pom;
      }
    }
  }
  return naj >= x;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    cin >> t[i];
    sum += t[i];
  }
  int res = 0;
  R(i,n){
    res += (i % 2 ? 1 : -1) * t[i];
  }
  if(n % 2 == 0){
    pri(abs(res));
  }
  int po = 0, ko = 1e9;
  while(po + 1 != ko){
    int m = (po + ko) / 2;
    if(spr(m)){
      po = m;
    }else{
      ko = m;
    }
  }
  pri(res + 2 * po);
}




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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int n;
    cin>>n;
    int ans=0;
    ans += (n/500)*1000;
    n%=500;
    ans += (n/5)*5;


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

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 3588
s = input()
n = len(s)
ans = 0

def dfs(i, f):
    #print(f)
    if  i == n - 1:
        return sum(list(map(int, f.split('+'))))
    return dfs(i+1, f+s[i+1]) + dfs(i+1, f+'+'+s[i+1])

print(dfs(0, s[0]))


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    //const int MOD = 1000000007;
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        int max = 101010;
        Scanner cin = new Scanner();
        int n = cin.NextInt();
        int d = cin.NextInt();
        int range = d * 2 + 1;
        if (n % range == 0)
        {
            Console.WriteLine(n / range);
        }
        else
        {
            Console.WriteLine(n / range + 1);
        }
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
int mi[26];
int INF = 1000000000;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	fill(mi, mi+26, INF);
	FOR(i, n) {
		int num[26];
		fill(num, num+26, 0);
		string s;
		cin >> s;
		FOR(j, s.size()) num[s[j]-'a']++;
		FOR(j, 26) mi[j] = min(mi[j], num[j]);	
	}
	string ans;
	FOR(i, 26) {
		if (mi[i]) {
			FOR(j, mi[i]) ans += 'a'+i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())

signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int cnt=0;
	int x,y;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(x==y)
			cnt++;
		else
			cnt=0;
		if(cnt>=3)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

long long gcd(long long a, long long b){
    // 最大公約数
    // ユークリッドの互除法
    if(a < b){
        long long temp = a;
        a = b;
        b = temp;
    }
    long long r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


int main(){
    long long n, ans = 0;
    cin >> n;
    vector<long long> dp(n+1, 2);
    dp[1] = 1;
    // エラトステネスのふるいぽく
    for(long long i = 2; i <= n; i++){
        long long tmp = i + i;
        while(tmp <= n){
            dp[tmp]++;
            tmp += i;
        }
    }
    for(long long i = 1; i <= n; i++){
        // cout << dp[i] << endl;
        ans += i * dp[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 81400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    
    vector<vector<int>> vec(n,vector<int>(3,0));
    for(int i =0;i<n;i++){
        for(int j =0;j<3;j++){
            int x;
            cin >> x;
            vec[i][j] = x;
        }
    }
    vector<vector<int>> dp(n,vector<int>(3,0));
    
    dp[0] = vec[0];
    for(int i=1;i<n;i++){
        for(int j = 0;j<3;j++){
           if(j == 0){
               dp[i][j] = max(dp[i-1][j+1],dp[i-1][j+2]) + vec[i][j];
           }
           else if(j == 1){
               dp[i][j] = max(dp[i-1][j-1],dp[i-1][j+1]) + vec[i][j];
           } 
           else{
               dp[i][j] = max(dp[i-1][j-2],dp[i-1][j-1]) + vec[i][j];
           } 
        }
    }
    cout << *max_element(dp[n-1].begin(),dp[n-1].end());
}









Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	ll ans=0,n,i;
	cin>>n;
	ll a[n];
	for(i=0;i<n;++i)cin>>a[i];
	for(i=0;i<n;++i){
		while(a[i]%2==0){
			a[i]/=2;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
/******************************************************/
/******************************************************/
/**                                                  **/
/**            BISMILLAHIR RAHMANIR RAHIM            **/
/**         REAZ AHAMMED CHOWDHURY - reaziii         **/
/**  Department of Computer Science and Engineering  **/
/*         INSTITUTE OF SCIENCE AND TECHNOLOGY       **/
/**                                                  **/
/******************************************************/
/******************************************************/



#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos);
ll setbitt(ll num, ll pos);
ll resetbitt(ll num, int pos);
const ll mod =       1e9 + 7;
const ll N =     1e6 + 10;


//.................___Start from here___.................//
//.................._____________________................//




int solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll a = min(x / d, k);
	x -= d * a;
	k -= a;
	k &= 1;
	if (k) {
		ll p = x + d;
		ll q = x - d;
		x = min(abs(p), abs(q));
	}

	cout << x << endl;




	return 0;
}
int main() {
#ifndef ONLINE_JUDGE
	input;
	output;
#endif
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#endif
	int cs = 1;
	int cn = 1;
	//cin>>cs;
	while (cs--) {
		solve();

	}
}


bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}



Measured memory_bytes: 3616
#include <cstdio>

int main(){
    int debt=100000,n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        debt = debt * 1.05;
        if(debt - (debt/1000)*1000 > 0){
            debt = (debt/1000)*1000 + 1000;
        }
    }

    printf("%d\n",debt);
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
    using namespace std;
                
      int main() {
        int N, M;
        vector<int> A(N);
        int soutoku=0;
        int hantei=0;

        cin >> N >> M;
          for(int i=0; i<N; i++){
            cin >> A.at(i);
        //    soutoku += A[i];
          }
                
        sort(A.begin(), A.end());
        reverse(A.begin(), A.end());

        //sort(A.begin(),A.end(),std::greater<int>);
         
        for(int i=0; i<N; i++){
          soutoku=soutoku+A.at(i);
        }

        
 
        for(int i=0; i<M; i++){
          if(A.at(i)>=(double)soutoku/(4*M)){
            hantei++;
          }
        }

        if(hantei<M){
          cout << "No" << endl;
        }
        else{
          cout << "Yes" << endl;
          }
        return 0;
        }

Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define N 400000+5


int main () 
{
/////////////////////////////////////
    
    fastio;

    lli n,l;
    cin>>n>>l;

    lli a[n+1];

    lli sum=0;
    loopl(i,1,n+1) { a[i] = l+i-1; sum+=a[i];}

    lli ans=inf;
    loopl(i,1,n+1)
    {
        if(abs(sum-(sum-ans)) > abs(sum-(sum-a[i])))
            ans = a[i]; 
    }


    cout<<sum-ans;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int A,B,C;

  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);

  if(A == B){
    printf("%d",C);
  }else if(A == C){
    printf("%d",B);
  }else{
    printf("%d",A);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  ll A,B,C,K;
  cin>>A>>B>>C>>K;
  if(K%2==0){
    cout<<A-B<<endl;
  }else{
    ll x=B+C;
    ll y=C+A;
    cout<<x-y<<endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

int main(){
  long ii,jj,kk;

  int a,b,d;
  char c[1000];
  while(cin >> a >> b){
    //cout << a + b;
    sprintf(c,"%d",a+b);
    cout << strlen(c) << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3116
import numpy as np

n = int(input())
hs = list(map(int, input().strip().split()))

# これまでを単調非減少にできるか
dp = np.zeros(n, dtype=np.bool)
dp[0] = True

for idx in range(1, n):
    if not dp[idx - 1]:
       dp[idx] = False
    elif hs[idx - 1] == hs[idx]:
        dp[idx] = True
    elif hs[idx - 1] < hs[idx]:
        dp[idx] = True
        hs[idx] -= 1
    else:
        dp[idx] = False

if dp[-1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 23128
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let s:Vec<char> = read::<String>().chars().collect();

    let mut ans:i32 = 0;
    for &ch in s.iter() {
        ans += match ch {
            '+' => 1,
            '-' => -1,
            _ => 0,
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N; cin >> N; 
	int A[22] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	int ans = 0; 
	for(int i = 1; i < N-1; i++){
		if((A[i] - A[i-1]) * (A[i] - A[i+1]) < 0) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <cstdio>
int main(){
  int n, m, i, j, res;
  scanf("%d %d", &n, &m);
  int arr1[n][m], arr2[m];
  
  for (i=0; i<n; i++) {
    for (j=0; j<m; j++) {
      scanf("%d", &arr1[i][j]);
    }
  }

  for (i=0; i<m; i++) {
    scanf("%d", &arr2[i]);
  }

  for (i=0; i<n; i++) {
    res=0;
    for (j=0; j<m; j++) {
      res+=arr1[i][j]*arr2[j];
    }
      printf("%d\n", res);
  }
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,d,x,y; cin>>n>>d;
    int cnt=0;
	auto dst=[&](ll x,ll y){ return sqrt(x*x+y*y); };
	for(int i=1;i<=n;i++)  { cin>>x>>y; double e=dst(x,y); if(e<=d)cnt++; }
	cout<<cnt<<endl;
}
	


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    queue<int> q;
    vector<int> dis(n, -1), ans(n);
    q.push(0);
    dis[0] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        rep(i, (long long)graph[v].size()){
            int u = graph[v][i];
            if(dis[u] == -1){
                dis[u] = dis[v] + 1;
                ans[u] = v;
                q.push(u);
            }
        }
    }

    bool ok = true;
    rep(i, n){
        if(dis[i] == -1){
            ok = false;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
        return 0;
    }

    REP(i, 1, n){
        cout << ans[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 13712
import Control.Arrow

main :: IO ()
main = print . solve =<< getLine

solve :: String -> Int
solve = iter 0 0 . runlen
  where
    iter s _ [] = s
    iter s _ (('<',n) : rs) = iter (s + n * succ n `div` 2) n rs
    iter s m (('>',n) : rs) = iter (s + s') 0 rs
      where
        s' = n * pred n `div` 2 + if m < n then n - m else 0
        
runlen :: String -> [(Char, Int)]
runlen ""     = []
runlen (c:cs) = case spanCount (c ==) cs of
  (m, rs) -> (c, succ m) : runlen rs

spanCount :: (a -> Bool) -> [a] -> (Int, [a])
spanCount _ [] = (0, [])
spanCount p xxs@(x:xs) 
  | p x       = first succ $ spanCount p xs
  | otherwise = (0, xxs)


Measured memory_bytes: 37244
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> c(4,0);
  rep(i,n){
    string s;cin>>s;
    if(s=="AC")c[0]+=1;
    if(s=="WA")c[1]+=1;
    if(s=="TLE")c[2]+=1;
    if(s=="RE")c[3]+=1;
  }
  printf("AC x %lld\n",c[0]);
  printf("WA x %lld\n",c[1]);
  printf("TLE x %lld\n",c[2]);
  printf("RE x %lld\n",c[3]);
  return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<vector<ll> > a(n,vector<ll>(n-1,0));
    vector<queue<ll> > que(n);
    rep(i,n){
        rep(j,n-1){
            cin>>a.at(i).at(j);
            a.at(i).at(j)--;
        }
    }
    rep(i,n){
        for(int j=n-2;j>=0;j--){
            que.at(i).push(a.at(i).at(j));
        }
    }
    ll cnt = n*(n-1)/2;
    ll tmp1,tmp2;
    ll days[n]={};    
    while(cnt>0){
        ll cur = 0;
        bool flg=false;
        while(cur<n){
            if(que[cur%n].size()!=0&&que[que[cur%n].front()].front()==cur%n){
                tmp1 = que[que[cur%n].front()].front();
                tmp2 = que[cur%n].front();
                days[tmp1] = days[tmp2] = max(days[tmp1],days[tmp2])+1;
                que[que[cur%n].front()].pop();
                que[cur%n].pop();
                cnt--;
                flg = true;
            }else{
                cur++;
            }
        }
        if(!flg){
            cout << -1 << endl;
            return 0;
        }
    }
    ll res=0;
    rep(i,n){
        res = max(res,days[i]);
    }
    cout << res << endl;
    return 0;
}


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int a[n+1];
  a[1]=1;
  for(int i=2;i<=n;i++)
    cin>>a[i];
  map<int,int>mp;
   for(int i=2;i<=n;i++)
   {
    mp[a[i]]++;
   }
   for(int i=1;i<=n;i++)
    cout<<mp[i]<<endl;

  return 0;
}

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

signed main(){
    int N;
    cin >> N;
    long long a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    int count = 0;
    for(int j = 0; j < N; j++){
        for(int i = 0; i < 100; i++){
            if(a[j] % 2 == 0){
                count++;
              	a[j] = a[j] / 2;
            }else{
                break;
            }
        }
    }

    cout << count << endl;
  
  	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	int e;
	while( cin >> e , e ){
		int ans = 1e+8;
		for(int y=0 ; y <= 1000 ; y++ ){
			for(int z=0 ; z <= 100 ; z++ ){
				int x = e - y*y - z*z*z;
				int m = x + y + z;
				if( x >= 0 ){
					ans = min(ans, m);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160