akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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() {
  int n;
  cin >> n;
  int t[n];
  int sum = 0;
  rep (i, n) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  int p, x;
  int diff[m];
  rep (i, m) {
    cin >> p >> x;
    diff[i] = x - t[p - 1];
  }

  rep (i, m) {
    P(sum + diff[i]);
  }


  return 0;
}

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

using namespace std;

int n, t;
int a[111111];
int mn[111111], mx[111111];
map<int, int> mp;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&n,&t);
	for(int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	mn[1] = a[1];
	mx[n] = a[n];
	for(int i = 2; i <= n; ++i) mn[i] = min(mn[i - 1], a[i]);
	for(int i = n - 1; i >= 1; --i) mx[i] = max(mx[i + 1], a[i]);
	int cur = 0;
	for(int i = 1; i < n; ++i){
		cur = max(cur, mx[i + 1] - mn[i]);
	}
	for(int i = 1; i <= n; ++i){
		if (!mp[a[i]]) mp[a[i]] = i;
	}
	int an = 0;
	for(int i = 1; i <= n; ++i){
		if (mp[a[i] + cur] && mp[a[i] + cur] > mp[a[i]]) ++an;
	}
	printf("%d",an);
	return 0;
}

Measured memory_bytes: 10752
#include<stdio.h>
int main(void){
        int x,y,tmp;
        while(1){
                scanf("%d %d",&x,&y);
                if(x == 0 && y == 0){
                        break;
                }
                if(x>y){
                        tmp = x;
                        x = y;
                        y = tmp;
                }
                printf("%d %d\n",x,y);
        }
        return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main()
{
    int n, i, x, max;
    char s[101];
    scanf("%d", &n);
    scanf("%s", s);
    max = 0;
    x = 0;
    for (i=0; i<n; i++)
    {
        if (s[i] == 'I') {
            x ++;
        } else {
            x --;
        }
        if (x > max) {
            max = x;
        }
    }
    printf("%d\n", max);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main()
{
  int a, b, c,temp;
  scanf("%d%d%d", &a, &b, &c);
  temp=b;
  b=a;
  a=temp;
  temp=c;
  c=a;
  a=temp;
  printf("%d %d %d", a, b,c);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h> 
#include <math.h>

int main(void)
{	
	int n, x[1000], y[1000],i;
	double p1 = 0, p2 = 0, p3 = 0, p = 0;

	scanf("%d",&n);

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

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

	for(i=0; i<n; i++)
	{
		if(x[i] < y[i])
		{
			p1 = p1 + y[i] - x[i];
			p3 = p3 + (y[i] - x[i]) * (y[i] - x[i]) * (y[i] - x[i]);
		}
		if(x[i] > y[i])
		{
			p1 = p1 + x[i] - y[i];
			p3 = p3 + (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
		}

		p2 = p2 + (x[i] - y[i]) * (x[i] - y[i]);

		if(x[i] < y[i])
		{
			if(p < y[i] - x[i])
			{
				p = y[i] - x[i];
			}
		}
		if(x[i] > y[i])
		{
			if(p < x[i] - y[i])
			{
				p = x[i] - y[i];
			}
		}
	}

	printf("%f\n%f\n%f\n%f\n", p1, pow(p2, 1.0/2.0), pow(p3, 1.0/3.0), p);
	return 0;
}

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

int n;
vector<set<int> > to;
vector<pair<int, int> > edges;

int minColorful;
int minLeaf;

void do_calc(set<int> centroidInit)
{
    vector<bool> treated(n, false);
    set<int> centroid = centroidInit;
    
    int colorNum = 0;
    vector<int> prod(1, centroidInit.size());
    while (!centroid.empty())
    {
        colorNum++;
        if (colorNum > minColorful) break;
        set<int> centroidNext;
        for (auto i : centroid)
        {
            treated[i] = true;
        }
        int maxBranch = 0;
        for (auto i : centroid)
        {
            int branch = 0;
            for (auto j : to[i])
            {
                if (treated[j] == false)
                {
                    branch++;
                    centroidNext.insert(j);
                }
            }
            maxBranch = max(maxBranch, branch);
        }
        centroid = centroidNext;
        if (maxBranch > 0) prod.push_back(maxBranch);
    }

    long long leaf = 1;
    for (auto i : prod) leaf *= i;
    if (colorNum < minColorful)
    {
        minColorful = colorNum;
        minLeaf = leaf;
    }
    else if (colorNum == minColorful)
    {
        if (leaf < minLeaf) minLeaf = leaf;
    }
}

int main()
{
    cin >> n;
    edges.resize(n-1);
    to.resize(n);
    
    if (n <= 3)
    {
        cout << n-1 << " 2\n";
        return 0;
    }
    
    for(int i=0; i<n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].insert(b);
        to[b].insert(a);
        edges[i] = make_pair(a, b);
    }

    minColorful = n;
    minLeaf = n;

    for (int i=0; i<n; i++)
    {
        set<int> hoge{i};
        do_calc(hoge);
    }

    for (int i=0; i<n-1; i++)
    {
        set<int> hoge{edges[i].first, edges[i].second};
        do_calc(hoge);
    }

    cout << minColorful << " " << minLeaf << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n, x, a[30]; bool dp[1000001], prime[1000001];
int main() {
	for(int i = 2; i <= 1000000; i++) prime[i] = true;
	for(int i = 2; i <= 1000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 1000000; j += i) prime[j] = false;
	}
	while(scanf("%d%d", &n, &x), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		for(int i = 0; i < x; i++) dp[i + 1] = false; dp[0] = true;
		for(int i = 1; i <= x; i++) {
			for(int j = 0; j < n; j++) {
				if(i - a[j] >= 0 && dp[i - a[j]]) {
					dp[i] = true; break;
				}
			}
		}
		bool flag = false;
		for(int i = x; i >= 1; i--) {
			if(dp[i] && prime[i]) {
				printf("%d\n", i); flag = true; break;
			}
		}
		if(!flag) printf("NA\n");
	}
}

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

int main() {
  int n,cnt = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  for(int i = 0;i < n;i++){
    for(int j = n-1;j > i;j--){
      if(data[j] < data[j-1]){
        int a = data[j],b = data[j-1];
        data[j] = b;
        data[j-1] = a;
        cnt++;
      }
    }
  }
  for(int i = 0;i < n;i++){
    cout << data[i];
    if(i == n-1) cout << "" << endl;
    else cout << " ";
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3116
$n,m=gets.split.map &:to_i
a=Array.new($n).map{|i|Array.new}
m.times do
  b,c=gets.split.map &:to_i
  a[b-1]<< c-1
  a[c-1]<< b-1
end
$a=a
def d e,f
  c=0
  $a[f].length.times do |i|
    g=$a[f][i]
    if !e.include?(g)
      c+=d(e+[g],g)
    end
  end
  if e.sort==[*0..$n-1]
    c+=1
  end
  c
end
p d [0],0

Measured memory_bytes: 2044
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
         int n,k;
         cin>>n>>k;
         int p[n];
         for(int i=0;i<n;i++)cin>>p[i];
         int ans=0,mans;
         for(int i=0;i<k;i++)ans+=(p[i]+1);
         mans=ans;
         for(int i=k;i<n;i++){
             ans-=(p[i-k]+1);
             ans+=p[i]+1;
            mans=max(mans,ans);
         }
         if(mans%2)cout<<mans/2<<".5";
         else cout<<mans/2;

        }


Measured memory_bytes: 1792
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,i;
inline void solve(){
  IN3(A,B,C);
  for(i=A;i<=B*A;i+=A){
    if(i%B==C){
      OUT("YES");
      return;
    }
  }
  OUT("NO");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)

N = int(input())


class Node:
    def __init__(self, index):
        self.index = index
        self.edges = []

class Edge:
    def __init__(self, index, a, b):
        self.a = a
        self.b = b
        self.index = index
        self.color = 0

    def to(self, fm):
        if fm == self.a:
            return self.b
        elif fm == self.b:
            return self.a
        else:
            return None


nodes = [Node(i) for i in range(N)]
edges = []
for i in range(N-1):
    a, b = map(int, input().split())
    edge = Edge(i, a-1, b-1)
    edges.append(edge)
    nodes[a-1].edges.append(i)
    nodes[b-1].edges.append(i)

passed = set()


def rec(node, via_color, K):
    passed.add(node.index)
    color = 1
    for edge_index in node.edges:
        edge = edges[edge_index]
        to_node_index = edge.to(node.index)
        if to_node_index in passed:
            continue
        if color == via_color:
            color += 1
        edge.color = color
        K = rec(nodes[to_node_index], color, K)
        color += 1
    return max(color-1, K)


K = rec(nodes[0], 0, 1)
print(K)
for edge in edges:
    print(edge.color)

Measured memory_bytes: 125724
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) V(3);
    READVEC(V);
    string Answer(N, '_');
    bool good = true;
    VEC(string) ops(N);
    READVEC(ops);

    for (int ii = 0;ii < N; ){
        string op = ops[ii];

        int i = op[0] - 'A', j = op[1] - 'A';
        if (V[i] == 0 && V[j] == 0) {
            good = false;
            break;
        } else if (V[i] == 0) {
            V[i]++;
            V[j]--;
            Answer[ii] = char('A' + i);
            ii++;
        } else if (V[j] == 0 || ii == N - 1) {
            V[j]++;
            V[i]--;
            Answer[ii] = char('A' + j);
            ii++;
        } else {
            // Both positive and ii < N - 1.
            int o = 3 - i - j;
            if (ops[ii + 1] == ops[ii]) {
                Answer[ii] = char('A' + j);
                Answer[ii + 1] = char('A' + i);
                ii += 2;
            } else {
                // next involves o;
                int i2 = ops[ii + 1][0] - 'A', j2 = ops[ii + 1][1] - 'A';
                if (i2 != o)
                    swap(i2, j2);

                // i2 == 0
                i2 = i + j - j2;
                Answer[ii] = char('A' + j2);
                V[j2]++;
                V[i2]--;
                ii++;
            }
        }
    }

    if (!good) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        FOR(i, 0, N)
            cout << Answer[i] << endl;
    }
    return 0;
};


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
	VL a = {3,5,7};
	int n;
	cin >> n;
	int ans = 0;
	LL m = LL(pow(3,10));
	for (int i = 3; i < m; i++) {
		LL tmp = i,keta = 1,num = 0;
		set<LL> st;
		while (tmp != 0) {
			st.insert(tmp%3);
			num += a[tmp%3] * keta;
			keta *= 10;
			tmp /= 3;
		}
		while (num <= n) {
			if (st.size() == 3) {
				ans++;
			}
			num += 3*keta;
			st.insert(0);
			keta *= 10;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

    vector<pair<long int, long int>> AB(N);

    for (int i = 0; i < N; i++)
    {
        cin >> AB.at(i).first >> AB.at(i).second;
    }
    sort(AB.begin(), AB.end());

    long int res = 0;
    int m = M;
    for (int i = 0; i < N; i++)
    {
        if (AB.at(i).second >= m)
        {
            res += (AB.at(i).first * m);
            break;
        }
        else
        {
            m -= AB.at(i).second;
            res += (AB.at(i).first * AB.at(i).second);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		int a = 0;
		for(var i=0;i<N;i++){
			if(A[i]==a+1){
				a++;
			}
		}
		int ans = -1;
		if(a>0){
			ans = N-a;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 33116
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,char>;
using ll=long long;

int main() {
  int N;
  cin >> N;
  set<int> ss;
  vector<int> V(0);
  map<int,int> M;
  int A;
  for (int i=0; i<N; i++) {
    cin >> A;
    M[A]++;
    if (!ss.count(A)) {
      V.push_back(A);
      ss.insert(A);
    }
  }
  
  int S=0;
  for (int i=0; i<V.size(); i++) {
    if (M[V[i]]%2==1) {
      S++;
    }
  }
  cout << S << endl;
}
 

Measured memory_bytes: 12964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> v(n),c(n);
    rep(i,n){
      cin>>v[i];
    }
    rep(i,n){
      cin>>c[i];
    }
    int ans=0;
    rep(i,n){
      if(v[i]-c[i]>0){
        ans+=v[i]-c[i];
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int r, g, b, N; cin >> r >> g >> b >> N;
	int ans = 0;
	for (int i = 0;i < N + 1;i += r) {
		for (int j = 0; j < N + 1;j += g) {
			if (N - i - j < 0)continue;
			if ((N - i - j) % b == 0)++ans;
		}
	}
	cout << ans << "\n";

	return 0;
}

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

class UnionFind{
    vector<int>p,sz;
public:
    UnionFind(int n){
        p.resize(n,-1);
        sz.resize(n,1);
    }
    int find(int x){
        if(p[x] == -1)return x;
        else return p[x] = find(p[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        if(sz[x] > sz[y])swap(x,y);
        p[x] = y;
        sz[y] += sz[x];
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--; b--;
        uf.unite(a,b);
    }
    set<int>ans;
    rep(i,n){
        ans.insert(uf.find(i));
    }
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 8656
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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; }

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n;
  cin >> n;

  ll ans = 1; 
  rep(i,n) {  
    ans*=i+1;
    ans =  ans % MOD; 
  }

  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    long long int k;
    string s;
    cin>>s>>k;
    for(int i=0;s.length();i++){
        if(s[i]=='1'){
                k--;
            if(k==0){
                cout<<1<<endl;
                break;
            }
            continue;
        }
        else{
            cout<<s[i]<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	int i,j,maxago=Integer.MIN_VALUE,min,max=Integer.MIN_VALUE;
	
	Scanner sca = new Scanner(System.in);
	i=sca.nextInt();
	int[] hai= new int[i];
	hai[0]=sca.nextInt();
	min=hai[0];
	for(i=1;i<hai.length;i++){//i->max(assuming)
	    hai[i]=sca.nextInt();
	    if(hai[i]-min>maxago){
		max=hai[i];
		maxago=max-min;
	    }
	    if(hai[i]<min){
		min=hai[i];
	    }
	    
	}
	System.out.println(maxago);
    }
}



Measured memory_bytes: 101288
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int getX(int num, int d){
    int tmp = num >> d;
    return (tmp % 2);
}

int getS(int num, int d){
    int ans = 0;
    REP(i, d){
        ans += getX(num, i);
    }
    return ans;
}

int main() {

    int N;
    cin >> N;
    vector<vector<P>> A(N);
    REP(i, N){
        int a;
        cin >> a;
        REP(j, a){
            int b, c;
            cin >> b >> c;
            A[i].push_back(P(b-1, c));
        }
    }
    int ans = 0;
    REP(i, (1<<N)){
        bool flag = true;
        REP(j, N){
            //if (i == 4 && j == 2) cout <<getX(i, j);
            if (getX(i, j) == 0) continue;
            for(auto iter : A[j]){
                //if (i == 4) cout << getX(i, iter.first) << iter.second << endl;
                if (getX(i, iter.first) != iter.second){
                    flag = false;
                    break;
                }
            }
            if (!flag) break;
        }
        //cout << i << " " << flag << " " << getS(i, N)<< endl;
        if (flag) ans = max(ans, getS(i, N));
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    ans=[-1]*N
    dame=False
    for i in range(M):
        if N!=1 and s[i]==1 and c[i]==0: dame=True
        if ans[s[i]-1]!=-1 and ans[s[i]-1]!=c[i]: dame=True
        ans[s[i]-1]=c[i]
    for i in range(N):
        if ans[i]==-1:
            if N!=1 and i==0: ans[i]=1
            else: ans[i]=0
        
    print(-1 if dame else "".join(map(str,ans)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include <iomanip>
using namespace std;
 
typedef long long ll;


int main(){
	int n;
	cin >> n;
	vector<double> v(n);
	for(int i=0;i<n;++i){
		cin >> v[i];
	}
	double res = 0;
	
	for(int i=0;i<n;++i){
		res += 1/v[i];
	}
	cout <<  std::setprecision(100)<<1/res <<endl;
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
// import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        int num = sc.nextInt();

        ArrayList<Integer> array = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            int tmp = sc.nextInt();
            array.add(tmp);
        }

        int num_query = sc.nextInt();

        for (int i = 0; i < num_query; i++) {
            int query_type = sc.nextInt();
            int left = sc.nextInt();
            int right = sc.nextInt();

            if (query_type == 0) {
                int tmp = Integer.MAX_VALUE;
                for (int j = left; j < right; j++) {
                    tmp = Math.min(tmp, array.get(j));
                }
                sb.append(String.format("%d\n", tmp));
            } else {
                int tmp = Integer.MIN_VALUE;
                for (int j = left; j < right; j++) {
                    tmp = Math.max(tmp, array.get(j));
                }
                sb.append(String.format("%d\n", tmp));
            }
        }

        System.out.print(sb);
        
        sc.close();
    }
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1'000'000'100;
int S, R;
std::vector<P> G[100100];
int A, B, Q;
std::vector<int> Q1[100100], Q2[100100];
int distA[100100], distB[100100], order[100100];
std::bitset<400> visited[100100];
bool exists[40100];

std::priority_queue<P, std::vector<P>, std::greater<P>> pq;

void dijkstra(int A, int (&dist)[100100]){
    std::fill(dist + 1, dist + 1 + S, INF);

    pq.emplace(0, A);
    dist[A] = 0;

    until(pq.empty()){
        int d, u;
        std::tie(d, u) = pq.top();
        pq.pop();

        if(d > dist[u]){
            continue;
        }

        for(auto &e : G[u]){
            int v, w;
            std::tie(v, w) = e;

            if(dist[v] > d + w){
                dist[v] = d + w;
                pq.emplace(dist[v], v);
            }
        }
    }
}

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

    std::cin >> S >> R;

    for(int i=0;i<R;++i){
        int u, v, w;
        std::cin >> u >> v >> w;

        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
    }

    std::cin >> A >> B >> Q;

    for(int i=0;i<Q;++i){
        int c, d;
        std::cin >> c >> d;

        Q1[c].emplace_back(i);
        Q2[d].emplace_back(i);
    }

    dijkstra(A, distA);
    dijkstra(B, distB);

    std::iota(order, order + S, 1);
    std::sort(order, order + S, [&](int l, int r){return distA[l] < distA[r];});

    for(int i=0;i<Q;i+=400){
        for(int j=1;j<=S;++j){
            visited[j].reset();
        }

        for(int u : order){
            for(auto q : Q2[u]){
                if(i <= q && q < i + 400 &&
                   visited[u].test(q - i) && distA[u] + distB[u] == distA[B]){
                    exists[q] = true;
                }
            }

            for(auto q : Q1[u]){
                if(i <= q && q < i + 400){
                    visited[u].set(q - i);
                }
            }

            for(auto &e : G[u]){
                int v, w;
                std::tie(v, w) = e;

                if(distA[v] == distA[u] + w){
                    visited[v] |= visited[u];
                }
            }
        }
    }

    for(int i=0;i<Q;++i){
        if(exists[i]){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }
}


Measured memory_bytes: 21924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K;cin>>K;
    
    ll ans=0;
    
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                ans+=gcd(gcd(i,j),k);
            }
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define REV(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/*---------------------template----------------------*/
/*----------------------end--------------------------*/
/* --------------------ライブラリ--------------------*/
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
/*---------------------臨時--------------------------*/
/*----------------------end-------------------------*/
signed main(){
  vd A(3);rep(i,3)cin>>A[i];
  double sum=0;
  rep(i,3)sum+=A[i];
  double X=sum/2;
  sort(all(A));
  if(binary_search(all(A),X))puts("Yes");
  else puts("No");
}


Measured memory_bytes: 3780
# B - Can you solve this?
#行列の入力方法を習得する 2020/08/07
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

'''
A = []
for o in range(N):#文字列の行列を入力
    a = input().split()
    A.append(a)
print(A)

A_list = []
for p in range(N):
    box = []
    for q in range(M):
        aa = int(A[p][q])
        box.append(aa)
    A_list.append(box)
print(A_list)
'''
A_list = []#任意の列数の行列の入力
for o in range(N):
    A = list(map(int, input().split()))
    A_list.append(A)
    
count = 0
for i in  range(N):
    judge = C
    for j in range(M):
        judge += A_list[i][j]*B[j]
    if judge > 0:
        count += 1
print(count)

Measured memory_bytes: 9232
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s;
	cin>>s;
	ll res = 0, cnt = 0;
	int n = s.size();
	rep(i, n){
		if(s[i]=='T') cnt++;
		else cnt--;
		chmax(res, cnt);
	}
	cout<<2*res<<endl;
	return 0;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
from bisect import bisect_left
INF = 10 ** 11

def main():
    A, B, Q = map(int, readline().rstrip().split())
    S = [-INF] + [int(readline()) for _ in range(A)] + [INF]
    T = [-INF] + [int(readline()) for _ in range(B)] + [INF]

    for _ in range(Q):
        x = int(readline())
        s_right_idx = bisect_left(S, x)
        s_left,  s_right = S[s_right_idx - 1], S[s_right_idx]
        
        t_right_idx = bisect_left(T, x)
        t_left,  t_right = T[t_right_idx - 1], T[t_right_idx]

        s_left_d, s_right_d = x - s_left, s_right - x
        t_left_d, t_right_d = x - t_left, t_right - x

        res1 = max(s_right_d, t_right_d)
        res2 = max(s_left_d, t_left_d)
        res3 = min(s_right_d * 2 + t_left_d, t_right_d * 2 + s_left_d)
        res4 = min(s_right_d + t_left_d * 2, t_right_d + s_left_d * 2)
        res = min(res1, res2, res3, res4)
        print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 12816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int main(){
	ll a,b,c; cin>>a>>b>>c;
	ll x=min(a,c);
	ll ans=0;
	ans+=x;
	a-=x;
	c-=x;
	x=min(c,b);
	ans+=2*x;
	c-=x;
	b-=x;
	if(c>0) ans++;
	ans+=max((ll)0,b);
	cout<<ans;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>

struct Point {
	double x,y;
};

void koch(int n,Point a, Point b);


int main(){
	Point a,b;
	int n;

	scanf("%d",&n);
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n", b.x,b.y);

	return 0;
}


void koch(int n,Point a, Point b){

	Point s,t,u;

	if(n == 0) return;
	double th = M_PI * 60.0 / 180.0;

	s.x=(a.x * 2.0 + b.x) / 3.0; 
	s.y=(a.y * 2.0 + b.y) / 3.0; 
	t.x=(a.x + b.x * 2.0) / 3.0; 
	t.y=(a.y + b.y * 2.0) / 3.0; 
	u.x=((t.x - s.x) * cos(th) - (t.y - s.y) * sin(th)) + s.x; 
	u.y=((t.x - s.x) * sin(th) + (t.y - s.y) * cos(th)) + s.y;

	koch(n-1,a,s); printf("%.8f %.8f\n",s.x,s.y); 
	koch(n-1,s,u); printf("%.8f %.8f\n",u.x,u.y); 
	koch(n-1,u,t); printf("%.8f %.8f\n",t.x,t.y); 
	koch(n-1,t,b);

}	














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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, d, x;

    cin >> n;
    cin >> d >> x;

    int a;
    int ans = 0;

    int i, j;

    rep(i, n) {
        cin >> a;

        reps(j, d, a) ans++;
    }

    Out(ans + x);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j;
  long k=0;
  
  int N;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d ",&j);
    k += j-1;
  }
  
  printf("%ld\n",k);
  return 0;
}

Measured memory_bytes: 128
import itertools


def main():
    n = int(input())
    p = tuple(input().split())
    q = tuple(input().split())

    a = list(itertools.permutations([str(i+1) for i in range(n)]))
    print(abs(a.index(q)-a.index(p)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 7924
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=5005;
int n,A,B;
int a[maxn];
ll dp[maxn][maxn];
bool have[maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d%d",&n,&A,&B);
	REP(i,n)scanf("%d",&a[i]);
	REP(i,n){
		int cnt=0;
		REP(j,n){
			if(j>a[i])cnt+=have[j];
			if(a[i]>j)dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=dp[i-1][j]+(cnt?B:0);
				dp[i][j]=min(dp[i][j],dp[i-1][a[i]]+1LL*cnt*A);
			}
		}
		have[a[i]]=true;
	}
	printf("%lld\n",dp[n][n]);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vi a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 0;
    rep(i, n-1) {
        sum -= a[i];
        ll r = (ll)a[i] * (sum % mod);
        r %= mod;
        ans += r;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4012
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int w=sc.nextInt();
		int n=sc.nextInt();
		int[] values=new int[w];
		for(int i=0;i<values.length;i++){
			values[i]=i+1;
		}
		for(int i=0;i<n;i++){
			String str=sc.next();
			String[] ab=str.split(",");
			int a=Integer.parseInt(ab[0])-1;
			int b=Integer.parseInt(ab[1])-1;
			int c=values[a];
			values[a]=values[b]; values[b]=c;
		}
		for(int i=0;i<values.length;i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 25840
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int n,a,b;
    cin>>n>>a>>b;

    if((n*a)<b){
        cout<<n*a;
    }else{
        cout<<b;
    }

    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
N=gets.to_i
as =[]
for i in 0...N
  as << gets.to_i
end
as.reverse!
color_min=[as[0]]
for i in 1...N
  s=color_min.size
  judge = (0..s-1).bsearch{|j|as[i] < color_min[j]}

  if judge
    color_min[judge]=as[i]
  else
    color_min << as[i]
  end
end
puts color_min.size


Measured memory_bytes: 5044
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  string S;

  cin >> N >> S;

  string a = S.substr(0, N / 2);

  string b = S.substr(N / 2, N / 2);

  if (N % 2 == 0) {
    if (a == b)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else
    cout << "No" << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin>>n;
    vi b;
    if (n>0){
        while(n){
            b.pb(n%2);
            n/=2;
        }
        rep(i,b.size()){
            if (b[i]==2){
                b[i]=0;
                if (i==b.size()-1) b.pb(0);
                b[i+1]++;
            }
            if (i&1 && b[i]==1){
                if (i==b.size()-1) b.pb(0);
                b[i+1]++;
            }
        }
        RFOR(i,b.size()-1,0) cout<<b[i];
        cout<<endl;
    }else if(n<0){
        n=-n;
        while(n){
            b.pb(n%2);
            n/=2;
        }
        rep(i,b.size()){
            if (b[i]==2){
                b[i]=0;
                if (i==b.size()-1) b.pb(0);
                b[i+1]++;
            }
            if (i%2==0 && b[i]==1){
                if (i==b.size()-1) b.pb(0);
                b[i+1]++;
            }
        }
        RFOR(i,b.size()-1,0) cout<<b[i];
        cout<<endl;
    }else{
        cout<<"0\n";
    }
    return 0;
}


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

int q, a, b;
string str, order, rep, sub;
char temp;

int replace(void); int reverse(void); int print(void);

int main(void){
    cin >> str >> q;
    for (int i = 0; i < q; i++){
        cin >> order;
        if (order == "replace") replace();
        if (order == "reverse") reverse();
        if (order == "print") print();
    }
    return 0;
}

int replace(void){
    scanf("%d%d", &a, &b);
    cin >> rep;
    str.replace(a, b - a + 1, rep);
    return 0;
}

int reverse(void){
    scanf("%d%d", &a, &b);
    sub = str.substr(a, b - a + 1);
    for (int i = 0; i < sub.size() / 2; i++){
        temp = sub[i];
        sub[i] = sub[sub.size() - i - 1];
        sub[sub.size() - i - 1] = temp;
    }
    str.replace(a, b - a + 1, sub);
    return 0;
}

int print(void){
    scanf("%d%d", &a, &b);
    sub = str.substr(a, b - a + 1);
    cout << sub << endl;
    return 0;
}

Measured memory_bytes: 3264
#include <algorithm>
#include <vector>
#include <iostream>
#include <cmath>
#include <set>
#include <string>
using namespace std;



int main()
{
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  int mina, minb;

  cin >> a[0];
  mina = a[0];
  for (int i = 1; i < A; i++)
  {
    cin >> a[i];
    if (mina > a[i]) mina = a[i];
  }

  cin >> b[0];
  minb = b[0];
  for (int i = 1; i < B; i++)
  {
    cin >> b[i];
    if (minb > b[i]) minb = b[i];
  }

  int min = mina + minb;
  int x, y, c;
  for (int i = 0; i < M; i++)
  {
    cin >> x >> y >> c;
    if (min > a[x-1] + b[y-1] - c)
      min = a[x-1] + b[y-1] - c;
  }

  cout << min << endl;
}


Measured memory_bytes: 1024
#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 <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;

const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}
template<class tt> struct counter {
	map<tt, int>mp;
	bool add(tt t, int xx) {
		if (!mp.count(t)) {
			mp[t] = xx;
			return true;
		}
		mp[t] += xx;
		if (!mp[t]) {
			mp.erase(t);
		}
		return false;
	}

};

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int k, s,ans=0;
	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s - i - j >= 0 && s - i - j <= k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;

int n;
ll x[N], A, B, res;

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> A >> B;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  for (int i = 2; i <= n; ++i) {
    res += min((x[i] - x[i - 1]) * A, B);
  }
  cout << res;
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int2(a, b);
    if ((b - a + 1) % 2) {
        std::cout << "Alice" << std::endl;
    } else {
        std::cout << "Borys" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256