akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//毎回合計が２ずつ増えていく
//A,B,C→X,X,Xなら(3X-(A+B+C))/2が答え
//3X=A+B+C(mod2)
//X>=max{A,B,C}
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int m=max(a,max(b,c));
    int ans=0;
    if(m%2==(a+b+c)%2){
        ans = (3*m-a-b-c)/2;
        cout << ans << endl;
        return 0;
    }
    else{
        m += 1;
        ans = (3*m-a-b-c)/2;
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 3588
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=[-1]*n
for s,c in sc:
    s=s-1
    if ans[s]<0:
        ans[s]=c
    elif ans[s]!=c:
        print(-1)
        exit()
t=''
for i in range(n):
    if i==0 and n>1:
        if ans[i]<0:
            t+='1'
        elif ans[i]==0:
            print(-1)
            exit()
        else:
            t+=str(ans[i])
    else:
        if ans[i]<0:
            t+='0'
        else:
            t+=str(ans[i])
print(t)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

struct StronglyConnectedComponents {
  vector<vector<int>> g, rev_g, h;
  vector<int> seen, ord, root;
  StronglyConnectedComponents(vector<vector<int>> &g) : g(g) {
    int n = g.size();
    rev_g.resize(n);
    seen.resize(n, false);
    root.resize(n, -1);
    rep(i, n) for (int j : g[i]) rev_g[j].push_back(i); // 逆辺を張る
    // Kosaraju
    rep(i, g.size()) dfs(i);
    reverse(ord.begin(), ord.end());
    int sz = 0; // 圧縮後のグラフの頂点数
    for (int i : ord)
      if (root[i] < 0) rev_dfs(i, sz++);
    h.resize(sz);
    rep(i, g.size()) for (int j : g[i]) {
      int _i = root[i], _j = root[j];    // 連結成分の代表元
      if (_i != _j) h[_i].push_back(_j); // 多重辺もありうる
    }
  }
  void dfs(int i) {
    if (not seen[i]) {
      seen[i] = true;
      for (int j : g[i])
        dfs(j);
      ord.push_back(i);
    }
  }
  void rev_dfs(int i, int rt) {
    if (root[i] < 0) {
      root[i] = rt;
      for (int j : rev_g[i])
        rev_dfs(j, rt);
    }
  }
};

int main() {

  // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  rep(_, m) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  StronglyConnectedComponents scc(g);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    cout << (scc.root[a] == scc.root[b]) << endl;
  }
  return 0;
}

// https://codeforces.com/contest/999/problem/E



Measured memory_bytes: 5064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
 
using namespace std;
 
#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
 
int solve(int a[],int v[])
{
    int sum=accumulate(a,a+10,0);
    int s=0;
    rep(i,10){
        s+=a[i];
        if(v[1]*s>=v[0]*(sum-s))
            return i+1;
    }
    return 10;
}
 
int main()
{
    for(int a[10],v[2];cin>>a[0];){
        repi(i,1,10)
            scanf(",%d",a+i);
        rep(i,2)
            scanf(",%d",v+i);
        cout<<solve(a,v)<<endl;
    }
     
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

double point_dist(int a, int b, int x, int y){
  return sqrt((a-x)*(a-x)+(b-y)*(b-y));
}

vector<double> dijkstra(int i, int n, vector<vector<pair<int, double>>> graph) {
  vector<double> d(n, INF);
  d[i] = 0;
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<double, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<double, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  double sx, sy, gx, gy; 
  cin >> sx >> sy >> gx >> gy;

  int N;
  cin >> N;

  vector<double> x(N+2), y(N+2), r(N+2);
  REP(i, N) cin >> x[i+1] >> y[i+1] >> r[i+1];
  x[0] = sx; y[0] = sy; r[0] = 0;
  x[N+1] = gx; y[N+1] = gy; r[N+1] = 0;
  N += 2;

  vector<vector<pair<int, double>>> graph(N);
  REP(i, N) FOR(j, i+1, N){
    if(i == j) continue;
    double d = max(0.0, point_dist(x[i], y[i], x[j], y[j])-r[i]-r[j]);
    graph[i].emplace_back(j, d);
    graph[j].emplace_back(i, d);
  }

  auto dist = dijkstra(0, N, graph);

  cout << dist[N-1] << "\n";

  return 0;
}

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

typedef long long ll;
typedef pair < int , int > Pi;
typedef pair < ll , ll > Pl;

const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;
const ll mod = 1000000007;
struct Edge 
{
    ll to, cost;
    Edge () {}
    Edge (ll to, ll cost) : to(to), cost(cost) {}
};
vector < Edge > G[100005];
ll min_cost[100005];
ll N, M, S, T;
ll A[200005], B[200005], C[200005];
ll memo[2][100005];

void Dijkstra(ll s)
{
    priority_queue < Pl , vector < Pl > , greater < Pl > > pq;
    fill_n(min_cost, 100005, LLINF);
    min_cost[s] = 0;
    pq.push(Pl(0, s));
    while(!pq.empty()) {
        Pl d = pq.top(); pq.pop();
        for(int i = 0; i < G[d.second].size(); i++) {
            ll u = G[d.second][i].to, w = G[d.second][i].cost + d.first;
            if(w < min_cost[u]) {
                min_cost[u] = w;
                pq.push(Pl(w, u));
            }
        }
    }
}
ll dfs(ll v, int k)
{
    if(k == 0 && v == T || k == 1 && v == S) return (1);
    if(memo[k][v] == -1) {
        memo[k][v] = 0;
        for(int i = 0; i < G[v].size(); i++) {
            ll u = G[v][i].to, w = G[v][i].cost;
            if(k == 0 && min_cost[v] + w == min_cost[u] || k == 1 && min_cost[u] + w == min_cost[v]) {
                (memo[k][v] += dfs(u, k)) %= mod;
            }
        }
    }
    return (memo[k][v]);
}
int main()
{
    cin >> N >> M >> S >> T; --S, --T;
    for(int i = 0; i < M; i++) {
        scanf("%lld %lld %lld", &A[i], &B[i], &C[i]); --A[i], --B[i];
        G[A[i]].push_back(Edge(B[i], C[i]));
        G[B[i]].push_back(Edge(A[i], C[i]));
    }
    Dijkstra(S);
    memset(memo, -1, sizeof(memo));
    dfs(S, 0); dfs(T, 1); //T -> v,  S -> v
    ll sum = (memo[0][S] * memo[0][S]) % mod;
    for(int i = 0; i < N; i++) {
        if(min_cost[i] * 2 == min_cost[T]) {
            (sum += mod - (((memo[0][i] * memo[0][i]) % mod) * ((memo[1][i] * memo[1][i]) % mod)) % mod) %= mod;
        }
    }
    for(int i = 0; i < M; i++) {
        if(min_cost[A[i]] + C[i] == min_cost[B[i]] && min_cost[A[i]] * 2 < min_cost[T] && min_cost[B[i]] * 2 > min_cost[T]) {
            (sum += mod - (((memo[1][A[i]] * memo[0][B[i]]) % mod) * ((memo[1][A[i]] * memo[0][B[i]]) % mod)) % mod) %= mod;
        }
        if(min_cost[B[i]] + C[i] == min_cost[A[i]] && min_cost[B[i]] * 2 < min_cost[T] && min_cost[A[i]] * 2 > min_cost[T]) {
            (sum += mod - (((memo[1][B[i]] * memo[0][A[i]]) % mod) * ((memo[1][B[i]] * memo[0][A[i]]) % mod)) % mod) %= mod;
        }
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N,K;
    cin >> N >>K;
    long long NNN;
    if(N==0||N%K==0){
        cout << 0 <<endl;
    }
    else  {
        NNN =N%K;
    cout <<min(NNN,abs(NNN-K))<<endl;
    }
}

Measured memory_bytes: 3628
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
x = 0
ans = 0

for i in range(n):
    t = list(map(int, input().split()))
    a.append(t)

for i in a:
    for k in range(m):
        x += i[k]*b[k]
    else:
        if x+c>0:
            ans +=1
        x=0

print(ans)

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

priority_queue<int> pq1,pq2;
const int maxn = 200000+100;
const int maxl = maxn;
int sz[maxn];
int a[maxn];
int l[maxn],r[maxn];
int ans[maxn];
struct MonoQueueAc{
    pair<int,int> mq[maxl];
    int st,ed;
    void init(){
        st=0,ed=0;
    }
    int size(){
        return ed-st;
    }
    int top(){
        if(size()==0)   throw -1;
        return mq[st].first;
    }
    void pop(){
        if(size()==0)   throw -1;
        ++st;
    }
    void check(int p){
        while(st<ed&&mq[st].second>=p)
            ++st;
    }
    void push(int a,int b){
        while(st<ed&&mq[ed-1].first>=a)
            --ed;
        mq[ed++]=make_pair(a,b);
    }
}ac;
struct MonoQueueDe{
    pair<int,int> mq[maxl];
    int st,ed;
    void init(){
        st=0,ed=0;
    }
    int size(){
        return ed-st;
    }
    int top(){
        if(size()==0)   throw -1;
        return mq[st].first;
    }
    void pop(){
        if(size()==0)   throw -1;
        ++st;
    }
    void check(int p){
        while(st<ed&&mq[st].second<=p)
            ++st;
    }
    void push(int a,int b){
        while(st<ed&&mq[ed-1].first<=a)
            --ed;
        mq[ed++]=make_pair(a,b);
    }
}de;
void pr(int *a,int *b)
{
    while(a<b)
        cout<<*(a++)<<" ";
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    for(int i=1;i<=N;++i)
        cin>>a[i];
    ac.init();
    de.init();
    for(int i=N;i>N-K+1;--i)
        ac.check(i+K),
        ac.push(a[i],i);
    for(int i=N-K+1;i>=1;--i)
    {
        ac.check(i+K);
        ac.push(a[i],i);
        l[i]=ac.top();
    }
    for(int i=1;i<K;++i)
        de.check(i-K),
        de.push(a[i],i);
    for(int i=K;i<=N;++i)
    {
        de.check(i-K);
        de.push(a[i],i);
        r[i]=de.top();
    }
    for(int i=1;i<=N;++i)
        if(a[i-1]<=a[i])
            sz[i]=sz[i-1]+1;
        else sz[i]=1;
    int sztot=0;
    for(int i=1;i<=N;++i)
        if(sz[i]>=K)
            sztot++;
    for(int i=K;i<=N;++i)
    {
        ans[i]=1;
        if(sz[i]>=K||(i>K&&a[i-K]==l[i-K]&&a[i]==r[i])) ans[i]=0;
    }
    //pr(sz+1,sz+N+1);
    //pr(ans+1,ans+1+N);
    int aans = accumulate(ans+1,ans+N+1,0);
    //pr(ans+1,ans+N+1);
    cout<<aans+(sztot>0)<<endl;
    return 0;
}


Measured memory_bytes: 7296
N, A, B = map(int, input().split())
S = input()
yosen = 0
kaigai = 0
for i in S:
    if i == 'a':
        if yosen < A + B:
            yosen += 1
            print('Yes')
        else:
            print('No')
    elif i == 'b':
        if yosen < A + B:
            if kaigai < B:
                kaigai += 1
                yosen += 1
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 52952
/*
  AUTHOR:SOURABH
  CREATED:30:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pii , null_type, less< pii >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i;
    string s;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s;
        n=s.length();
        fn(i,n)
        {
            if(s[i]=='?')
            {
                s[i]='D';
            }
        }
        cout<<s;
    }
    return 0;
}















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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define vll vector<double>
#define pi pair<double, int>
#define tup tuple<double, int, int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const double inf = 900900900100100100;
const int    MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int ba_n, n, m, START, END;
    while (cin >> ba_n >> n >> m >> START >> END, n) {
        int        ba[10] = {};  //馬車
        vector<pi> G[50] = {};
        rep(i, ba_n) cin >> ba[i];

        rep(i, m) {
            int a, b, c;
            cin >> a >> b >> c;
            G[a].pb(mp(c, b));
            G[b].pb(mp(c, a));
        }

        // dijkstra
        priority_queue<tup, vector<tup>, greater<tup>> que;

        vector<vector<double>> d(257, vector<double>(50, inf));
        rep(i, 257) d[i][START] = 0;
        que.push(tup(0.0, START, 0));
        while (!que.empty()) {
            tup p = que.top();
            que.pop();
            double cost = get<0>(p);
            int    v = get<1>(p);
            int    bit = get<2>(p);  //馬券の持っているビット
            if (d[bit][v] < cost) continue;
            rep(i, G[v].size()) {
                pi e = G[v][i];
                rep(k, ba_n) {
                    if (!(bit & (1 << k))) {
                        if (d[bit + (1 << k)][e.se] > d[bit][v] + e.fi / ba[k]) {
                            d[bit + (1 << k)][e.se] = d[bit][v] + e.fi / ba[k];
                            que.push(tup(d[bit + (1 << k)][e.se], e.se, bit + (1 << k)));
                        }
                    }
                }
            }
        }
        double ans = inf;
        rep(i, 1 << ba_n) ans = min<double>(ans, d[i][END]);
        if (ans >= inf)
            cout << "Impossible" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}



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


int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int l[h][w];
  rep(i,h) {
    rep(j,w) {
      if(s[i][j]=='#') l[i][j] = 0;
      else if(j==0) l[i][0] = 1;
      else l[i][j] = l[i][j-1]+1;
    }
  }
  int r[h][w];
  rep(i,h) {
    for(int j = w-1; j >= 0; j--) {
      if(s[i][j]=='#') r[i][j] = 0;
      else if(j==w-1) r[i][j] = 1;
      else r[i][j] = r[i][j+1]+1;
    }
  }
  int u[h][w];
  rep(j,w) {
    rep(i,h) {
      if(s[i][j]=='#') u[i][j] = 0;
      else if(i==0) u[0][j] = 1;
      else u[i][j] = u[i-1][j]+1;
    }
  }
  int d[h][w];
  rep(j,w) {
    for(int i = h-1; i >= 0; i--) {
      if(s[i][j]=='#') d[i][j] = 0;
      else if(i==h-1) d[i][j] = 1;
      else d[i][j] = d[i+1][j] + 1;
    }
  }
  int ans = 0;
  rep(i,h) {
    rep(j,w) {
      if(s[i][j]=='#') continue;
      ans = max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 73720
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

int main() 
{
    int h,w;cin >> h >> w;
    int black = 0, white = 0;
    vector<vector<char> > s(h, vector<char>(w, '#')); 

    rep(i,h) { 
        string tmp; cin >> tmp;
        rep(j,w) { 
            s[i][j] = tmp[j];
            if(s[i][j] == '#') { black++;}
            else               { white++;}
        }
    }
    if(black==h*w ||  white == h*w) { cout <<"Yes" << endl; return 0; }

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

    rep(i,h) { 
        rep(j, w) {
            rep(k,4) {
                if(i+dy[k] > -1 && i+dx[k] > -1 && i+dy[k] < h && i+dx[k] < w) {
                    if((s[i+dy[k]][j+dx[k]] == '#' && s[i][j] == '#') || 
                       (s[i+dy[k]][j+dx[k]] == '1' && s[i][j] == '#') ||
                       (s[i+dy[k]][j+dx[k]] == '#' && s[i][j] == '1')    ){
                        s[i+dy[k]][j+dx[k]] = '1'; s[i][j] = '1';
                    }
                }
            }
        }
    }

    //rep(i,h) { rep(j,w) { cout << s[i][j]; } cout << endl; } 

    rep(i,h) { 
        rep(j,w) { 
            if(s[i][j] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
    } 

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



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll ans = 123;
    for (int i = 0; i < n; i++) {
        ll zans = 0;
        ll a;
        cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            zans++;
        }
        ans = min(ans, zans);
    }
    cout << ans << endl;
}

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


//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n)        for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define PB push_back
#define vvi vector<vi>
#define vvll vector<vll>
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>

#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define GC getchar
#define PC putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()

//policy based data structure
 /*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

*/
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=111111;
void solve()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll first=x%d;
    ll second =d-first;

    if(k<=(x/d))
    {
        cout<<x-k*d<<endl;
        return;
    }
    ll moves=x/d;
    if(moves%2==k%2) cout<<first<<endl;
    else cout<<second<<endl;
}

//Main function

int main(){
IOS;
TIE;     
#ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 
  
#endif   
solve();
}
   


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define LL long long

const int maxn = 2e5+5;
const LL INF = 2e14+1;
const LL MINF = 0;



LL min_max_f[maxn];
LL max_min_f[maxn];

LL A[maxn];
LL sum[maxn];

LL get_num(int l,int r){
    if(l){
        return sum[r] - sum[l-1];
    }
    else return sum[r];
}

LL get_ans(LL a,LL b,LL c,LL d){
    LL min_value = min(a,min(b,min(c,d)));
    LL max_value = max(a,max(b,max(c,d)));
    return max_value - min_value;
}


int main()
{
    int N;scanf("%d",&N);
    _for(i,0,N){
        scanf("%lld",&A[i]);
        sum[i] = A[i];
        if(i) sum[i] += sum[i-1];
    }

    int r = 2;
    int mid = 1;
    int l = 0;
    LL ans = INF;
    while(mid <= N-3){
        LL a1,a2;
        LL b1,b2;
        LL c1,c2;
        LL d1,d2;
        while(l + 1 < mid && get_num(l+1,mid) > get_num(0,l)) l++;
        if(r == mid) r++;
        while(r < N-1 && get_num(r+1,N-1) > get_num(mid+1,r)) r++;
        a1 = get_num(0,l);a2 = get_num(l+1,mid);
        b1 = get_num(mid+1,r); b2 = get_num(r+1,N-1);

        c1 = (l == 0)?INF:get_num(0,l-1);c2 = (l == 0)?0:get_num(l,mid);
        d1 = (r-1 == mid)?INF:get_num(mid+1,r-1);d2 = (r-1 == mid)?0:get_num(r,N-1);

        ans = min(ans,get_ans(a1,a2,b1,b2));
        ans = min(ans,get_ans(a1,a2,d1,d2));
        ans = min(ans,get_ans(c1,c2,b1,b2));
        ans = min(ans,get_ans(c1,c2,d1,d2));

        /*
        if(ans == 15) {
                cout << l <<" "<<mid << " "<<r<<endl;
                cout << a1<< " " << a2 << " "<< b1 <<" "<< b2;
        }
        */
        mid++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int z=a.size(),x=b.size();
	if(z>x){
		cout<<"GREATER"<<endl;
	}
	else if(z<x){
		cout<<"LESS"<<endl;
	}
	else if(a==b){
		cout<<"EQUAL"<<endl;
	}
	else{
		for(int i=0;i<z;i++){
			if(a[i]>b[i]){
				cout<<"GREATER"<<endl;
				break;
			}
			else if(a[i]<b[i]){
				cout<<"LESS"<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
sa = gets.chomp
sb = gets.chomp
sc = gets.chomp
turn = "a"
ia = 0
ib = 0
ic = 0
while true do
  case turn
  when "a"
    if ia >= sa.length
      break
    else
      turn = sa[ia]
      ia += 1
    end
  when "b"
    if ib >= sb.length
      break
    else
      turn = sb[ib]
      ib += 1
    end
  when "c"
    if ic >= sc.length
      break
    else
      turn = sc[ic]
      ic += 1
    end
  end
end
puts turn.upcase


Measured memory_bytes: 1788
////////////////////////////////////
///     Please Give Me AC!!!     ///
////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

const int MOD = 1000000007;

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


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

    ll ans = powmod(10, N) - 2 * powmod(9, N) + powmod(8, N);
    ans %= MOD;
    cout<< (ans + MOD) % MOD << endl;
}

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

int main()
{
	long long int h;
	cin >> h;
	h = h | (h >> 1);
	h = h | (h >> 2);
	h = h | (h >> 4);
	h = h | (h >> 8);
	h = h | (h >> 16);
	h = h | (h >> 32);
	cout << h << endl;
	return 0;
}

Measured memory_bytes: 256
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);
 
impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

/// Searches not for a single target value, but for a continuous slice of target values.
pub fn binary_slice_search<A: Ord>(haystack: &[A], needle: A) -> (usize, usize) {
    use std::cmp::Ordering;

    let start = haystack.binary_search_by(|trial| match trial.cmp(&needle) {
        Ordering::Equal => Ordering::Greater,
        other => other,
    }).expect_err("never succeeds because we never return Ordering::Equal");

    let end = haystack[start..].binary_search_by(|trial| match trial.cmp(&needle) {
        Ordering::Equal => Ordering::Less,
        other => other,
    }).expect_err("never succeeds because we never return Ordering::Equal");

    (start, start+end)
}

fn solve(heights: Vec<usize>) -> usize {
    let mut a = 0;
    let mut magic = Vec::new();
    for (j, &h) in heights.iter().enumerate() {
        magic.push((j+1) as i64 - h as i64);
    }
    magic.sort();

    for i in 1..=heights.len() {
        let i_magic = (heights[i-1] + i) as i64;
        // dbg!(i);
        // dbg!(i_magic);

        let (start, end) = binary_slice_search(&magic, i_magic);
        // dbg!(&magic[start..end]);
        a += end - start;
    }
    a
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n = sc.read();
    let heights = sc.vec(n);

    let ans = solve(heights);
    println!("{}", ans);
}
 


Measured memory_bytes: 6084
import java.util.*;
public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner (System.in);
    	int N = sc.nextInt();
    	switch (N % 10){
      		case 2:
      		case 4:
      		case 5:
      		case 7:
      		case 9:   
      			System.out.println("hon");
      			break;
      		case 0:
      		case 1:
      		case 6:
      		case 8:
        		System.out.println("pon");
        		break;
      		case 3:
        		System.out.println("bon");
            	break;
        }
    }
}

Measured memory_bytes: 27024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<(#a)<<':'<<(a)<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(ll key,ll value){
  return key < value;
}

int binary_search(vector<ll> a,ll key){
  ll ok = a.size();
  ll ng = -1;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  #define int ll
  int n,m;cin>>n>>m;
  vector<pair<int,int>> ab(n);
  rep(i,n)cin>>ab[i].fi>>ab[i].se;
  sort(all(ab));
  ll ans = 0;
  for(int i = 0;m > 0 && i < n;++i){
    ans += ab[i].fi * min(m,ab[i].se);
    m -= ab[i].se;
  }
  print(ans);
  return 0;
} 


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<int> segh(524288, MOD), segv(524288, MOD);

void ruq(vector<int>& V, int s, int t, int v, int k = 1, int l = 0, int r = 262143) {
	if (t < l || r < s)return;
	if (s <= l && r <= t) {
		V[k] = min(V[k], v);
		return;
	}
	if (V[k] <= v)return;

	if (V[k] != MOD) {
		V[k * 2] = min(V[k], V[k * 2]);
		V[k * 2 + 1] = min(V[k], V[k * 2 + 1]);
		V[k] = MOD;
	}
	ruq(V, s, t, v, k * 2, l, (l + r) / 2);
	ruq(V, s, t, v, k * 2 + 1, (l + r) / 2 + 1, r);
}

int gets(vector<int>& V, int x) {
	x += 262144;
	int ans = V[x];
	while (x) {
		x /= 2;
		if (V[x] != MOD)ans = min(ans, V[x]);
	}
	return ans;
}

int main() {
	ll N, Q;
	cin >> N >> Q;
	ruq(segh, 0, N, N);
	ruq(segv, 0, N, N);
	ll x, qn, c, cnt = 0;
	for (int i = 0;i < Q;i++) {
		cin >> qn >> x;
		if (qn == 1) {
			c = gets(segh, x);
			cnt += c - 2;
			ruq(segv, 2, c - 1, x);
		}
		else {
			c = gets(segv, x);
			cnt += c - 2;
			ruq(segh, 2, c - 1, x);
		}
	}
	cout << (N - 2) * (N - 2) - cnt << endl;
}

Measured memory_bytes: 7336
main = solve

solve = answer 1

answer :: Int -> IO ()
answer i = do
    n <- readLn
    printResult i n
    where
        printResult i n
            | n == 0 = return ()
            | otherwise = do
                putStrLn $ "Case " ++ show i ++ ": " ++ show n
                answer . (+1) $ i

Measured memory_bytes: 4128
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int i, j;
	int w;
	int a, b, ah, bh;
	int tempa, tempb;
	scanf("%d %d", &a, &b);
	a--;
	b--;
	w=100;
	ah=50;
	bh=50;
	if(!a and b) ah=0, b++;
	else if(!b and a) bh=0, a++;
	
	printf("%d %d\n", ah+bh, w);
	for(i=1; i<=ah; i++){
		for(j=1; j<=w; j++){
			if(i%3!=1 and i>1 and i<ah and j>1 and j<w and !(i&1)==(j&1) and a){
				putchar('.');
				a--;
			}
			else putchar('#');
		}
		putchar('\n');
	}
	
	for(i=1; i<=bh; i++){
		for(j=1; j<=w; j++){
			if(i%3!=1 and i>1 and i<bh and j>1 and j<w and !(i&1)==(j&1) and b){
				putchar('#');
				b--;
			}
			else putchar('.');
		}
		putchar('\n');
	}
	return 0;
}
/*
........
#.#.#.#.
........
#.#.#.#.
........
*/

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

using namespace std;

template<typename T>
class Dijkstra {
 public:
  int n;
  T INF = numeric_limits<T>::max();
  vector< vector< pair<int,T> > > g;
  vector<T> dis;
  vector<int> prev;
  
  Dijkstra(int _n) : n(_n) {
    g.resize(n);
  }

  void add_edge(int u, int v, T w) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    assert(w >= 0);
    g[u].emplace_back(v, w);
  }

  vector<T> short_path(int s) {
    dis = vector<T>(n, INF);
    prev = vector<int>(n, -1);

    set< tuple<T,int,int> > bag; // cost, vertex, prev
    bag.insert(make_tuple(0, s, -1));
    while (bag.size()) {
      int u, v, p;
      T w, cost;
      tie(cost, u, p) = *bag.begin();
      bag.erase(bag.begin());
      if (dis[u] > cost) {
        dis[u] = cost;
        prev[u] = p;
        for (auto i : g[u]) {
          tie(v, w) = i;
          bag.insert(make_tuple(w + cost, v, u));
        }
      }
    }
    return dis;
  }
};

int main() {
  ios_base::sync_with_stdio(false);

  int k;
  cin >> k;

  Dijkstra<int> g(k);

  for (int i = 0; i < k; i++) {
    g.add_edge(i, (i + 1) % k, 1);
    g.add_edge(i, 10 * i % k, 0);
  }

  auto dis = g.short_path(1);
  cout << dis[0] + 1 << '\n';
  return 0;
}
 


Measured memory_bytes: 15216
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    REP(i, s.length())
    {
        s[i] = 'x';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
n=int(input())
M=[]
for i in range(n):
    x,y=map(int,input().split())
    M.append([x,y])
M.sort(key=lambda x:(x[0],x[1]))
X=[]
Y=[]
for i in range(n-1):
    for j in range(i+1,n):
        a=M[i][0]-M[j][0]
        b=M[i][1]-M[j][1]
        if not [a,b] in Y:
            Y.append([a,b])
            X.append(1)
        else:
            X[Y.index([a,b])]+=1
ans=n
for i in range(len(Y)):
    ans=min(ans,n-X[i])
print(ans)

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

int main()
{
  	int a, b, c;
  
  	cin >> a >> b >> c;
  
  	if(a == 5 && b == 5) {
      if(c == 7) {
        cout << "YES";
      }else {
        cout << "NO";
      }
    }else if(a == 5 && c == 5) {
      if(b == 7) {
        cout << "YES";
      }else {
        cout << "NO";
      }
    }else if(b == 5 && c == 5) {
      if(a == 7) {
        cout << "YES";
      }else {
        cout << "NO";
      }
    }else {
      cout << "NO";
    }
  
  return 0;
}

      
          
      

Measured memory_bytes: 256
M = 2147483647
a = [M for i in range(500000)]

def j_min(x,y):
    if x < y:return x
    else: return y

def find(x,y,i,l,r):
    if r<=x or y<=l:return M
    if x<=l and r<=y: return a[i]
    return j_min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))

if __name__=='__main__':
    n, m = (int(x) for x in input().split())
    t=1
    while t<n :t *= 2

    for i in range(m-1,-1,-1):
        com,x,y = (int(x) for x in input().split())
        if com :
            #continue
            print(find(x,y+1,1,0,t))
        else:
            x+=t
            a[x]=y
            while isinstance(x, int) or x >= 2:
               a[int(x/2)]=j_min(a[int(x)],a[int(x)^1])
               x/=2



Measured memory_bytes: 11160
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

int solve(const vi& d,int f){
    int N = d.size();
    int head = 0;
    int tail = N-1;
    int ret = 0;
    // debug(d);
    // debug(f);
    while(true){
        int mid = (head + tail) / 2;
        ret++;
        // debug(mid);
        // debug(d[mid]);
        // debug(ret);
        if(d[mid] == f){
            // debug(d[mid]);
            return ret;
        }else if(d[mid] < f){
            head = mid + 1;
        }else if(d[mid] > f){
            tail = mid - 1;
        }
        if(head > tail){
            return ret;
        }
    }
    return -1;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vi d(n);
        rep(i,n) cin >> d[i];
        int f;
        cin >> f;
        cout << solve(d,f) << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll k; cin >> k;
    if(k%2 == 0 || k%5 == 0){
        cout << -1 << endl;
        return 0;
    }else{
        ll l = 0;
        if(k%7 == 0) l = k/7*9;
        else l = 9 * k;
        ll t = 10;
        for(ll i = 1; i <= l; ++i){
            if(t%l == 1){
                cout << i << endl;
                return 0;
            }
            t = t%l * 10;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>

int main() {
	int n;
	int a[10000];
	unsigned long long sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
    int min = a[0];
	int max = a[0];
	for (int i = 0; i < n; i++) {
		sum = sum + a[i];
		if (a[i] > max) {
			max = a[i];
		}
		if (a[i] < min) {
			min = a[i];
		}
	}
	printf("%d %d %lld\n", min, max, sum);

	return 0;

}


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

int main() {
  
 int a; cin>>a;
  
 int urebig;
  urebig=a/500;
  
 int uresmall;
  uresmall=(a%500)/5;
  
 int ans;
  ans=urebig*1000+uresmall*5;
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

BCs = []
for _ in range(M):
  b, c = map(int, input().split())
  BCs.append((b,c))
BCs.sort(key=lambda a: -a[1])

length = 0
arr = []
for b, c in BCs:
  l = min(N - length, b)
  arr += [c] * l
  length += l
  if length >= N:
    break

ans = 0
for i in range(N):
  if i < length:
    ans += max(arr[i], A[i])
  else:
    ans += A[i]
print(ans)

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

int main(){
  int h,w;
  cin>>h>>w;
  int map[h][w];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
        cin>>map[i][j];
    }
  }

  int cnt=0;
  vector<int>x,y,x1,y1;
  int k=0;

  for(int i=0;i<h;++i){
    if(i%2==0){
       for(int j=0;j<w;++j){
          if(map[i][j]%2==1&&k==0){
                //memo
            x.push_back(i+1);
            y.push_back(j+1);
            k=1;
          }else if(map[i][j]%2==0&&k==0){
            continue;
          }else if(map[i][j]%2==1&&k==1){
            k=0;
            x1.push_back(i+1);
            y1.push_back(j+1);
            cnt++;
          }else if(map[i][j]%2==0&&k==1){
            x1.push_back(i+1);
            y1.push_back(j+1);
            x.push_back(i+1);
            y.push_back(j+1);
            cnt++;
          }
       }
    }else{
       for(int j=w-1;j>=0;--j){
          if(map[i][j]%2==1&&k==0){
                //memo
            x.push_back(i+1);
            y.push_back(j+1);
            k=1;
          }else if(map[i][j]%2==0&&k==0){
            continue;
          }else if(map[i][j]%2==1&&k==1){
            k=0;
            x1.push_back(i+1);
            y1.push_back(j+1);
            cnt++;
          }else if(map[i][j]%2==0&&k==1){
            x1.push_back(i+1);
            y1.push_back(j+1);
            x.push_back(i+1);
            y.push_back(j+1);
            cnt++;
          }
       }
    }
  }

  cout << cnt << endl;
  for(int i=0;i<x1.size();++i){
    cout << x[i] << " " << y[i] << " " << x1[i] << " " << y1[i] << endl;
  }
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  vector<int> a(s.size(), -1);
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == 'R' && s[i+1] == 'L') {
      int j;
      j = i;
      while (j >= 0 && s[j] == 'R') {
        a[j] = i - j;
        j--;
      }
      j = i + 1;
      while (j < s.size() && s[j] == 'L') {
        a[j] = (i + 1) - j;
        j++;
      }
      if (j < s.size() - 1)
        i = j - 1;
    }
  }
  
  vector<int> b(s.size(), 0);
  for (int i = 0; i < s.size(); i++) {
    int t = i + a[i];
    if (abs(a[i]) % 2 == 1)
      a[i] > 0 ? t++ : t--;
    b[t]++;
  }

  for (int i = 0; i < s.size(); i++) {
    cout << b[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;

public class Main {
	public static void main(String[] a) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> al = new ArrayList<String>();
		String str;

		// 1???????????\?????????????????????????????????
		while ((str = br.readLine()) != null) {
			if (str.length() == 0) {
				break;
			}
			al.add(str);
		}

		BigDecimal[][] ans = new BigDecimal[al.size()][2];

		// ??£???????¨????
		int len = al.size();
		for (int i = 0; i < len; i++) {
			String[] buf = al.get(i).split(" ");

			// ???????????????1??????????????????????????°??????????????????
			double ax = Double.parseDouble(buf[0]);
			double by = Double.parseDouble(buf[1]);
			double c = Double.parseDouble(buf[2]);
			double dx = Double.parseDouble(buf[3]);
			double ey = Double.parseDouble(buf[4]);
			double f = Double.parseDouble(buf[5]);

			// y????±?????????????
			double ansY = yOperation(ax, by, c, dx, ey, f);

			// x????±?????????????
			double ansX = xOperation(ax, by, c, ansY);

			// ?°???°?????\????¬¬??????????????¨?????\???????????????????´?
			BigDecimal bdx = new BigDecimal(ansX);
			ans[i][0] = bdx.setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal bdy = new BigDecimal(ansY);
			ans[i][1] = bdy.setScale(3, BigDecimal.ROUND_HALF_UP);
			
		}

		// ??????
		for (int i = 0; i < ans.length; i++) {
			System.out.printf("%4.3f" + " " + "%4.3f" + "\n", ans[i][0],
					ans[i][1]);
		}
	}

	//y????¨????
	private static double yOperation(double ax, double by, double c,
			double dx, double ey, double f) {
		double ansY;
		try {
			ansY = (f + -(dx * c / ax)) / ((dx * -by / ax) + ey);
		} catch (ArithmeticException ae) {
			ansY = 0;
		}
		return ansY;
	}

	//x????¨????
	private static double xOperation(double ax, double by, double c,
			double y) {
		double ansX;
		try {
			ansX = (c + -(by * y)) / ax;
		} catch (ArithmeticException ae) {
			ansX = 0;
		}
		return ansX;
	}

}

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

int main(){
    int p,q,r;
    cin>>p>>q>>r;
    int ans=p+q+r;
    ans -=max(p,max(q,r));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
s = np.array(list(raw_input()))
e = np.unique(s)
if len(e) % 2 == 1:
    print 'No'
elif len(e) == 2:
    if 'N' in e and 'S' in e:
        print 'Yes'
    elif 'W' in e and 'E' in e:
        print 'Yes'
    else:
        print 'No'
else:
    print 'Yes'

Measured memory_bytes: 14308
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>
 
using namespace std;
 
int main(){
 int A;
 int B;
 cin >> A >> B;
 int ans;
 if(B<=A)ans=1;
 else{
   ans = 2 + (B-A)/(A-1);
   if((B-A)%(A-1)==0)ans--;
   }
 if(B==1)ans=0;
 cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";

		str=bfr.readLine();
		String[] wake=str.split(" ");

		int a=Integer.parseInt(wake[0]);
		int b=Integer.parseInt(wake[1]);

		if(a%2==0 || b%2==0) {
			System.out.println("Even");
		}
		else {
			System.out.println("Odd");
		}

	}
}

Measured memory_bytes: 18772
#include <stdio.h>

int main(){
    
    int k, a, b;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);
    
    for(int i = 1 ; i < 1000 ; i++){
    	int temp = k;
    	temp*=i;
		// printf("Temp number: %d\n", temp);
		if(temp >= a && temp <= b){
    		printf("OK\n");
    		// printf("%d\n", i);
			break;
		}
		else if(temp > b){
			printf("NG\n");
			// printf("%d\n", i);
			break;
		}
	}
    
	
	return 0;
}



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

int main(void){
	string s;
	for(int i=0;i<3;i++) cin >> s[i];
	int cnt=0;
	for(int i=0;i<3;i++){
		if(s[i]=='1') cnt++;
	}
	cout << cnt << endl;
	
	return 0;
		
}

Measured memory_bytes: 256