akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
int n;
double calc(vector<double>&x,vector<double>&y,vector<double>&l,double xs){
    double uy = 100.0;
    double ly = -100.0;
    while(uy-ly>=0.000001){
            double a = (uy*2.0+ly)/3.0; 
            double b = (uy+ly*2.0)/3.0;
            double ma = 100000.0;
            double mb = 100000.0;
            for(int i=0;i<n;i++){
                ma = min(ma,l[i]*l[i]-(x[i]-xs)*(x[i]-xs)-(y[i]-a)*(y[i]-a));
            }
            for(int i=0;i<n;i++){
                mb = min(mb,l[i]*l[i]-(x[i]-xs)*(x[i]-xs)-(y[i]-b)*(y[i]-b));
            }
            if(ma > mb){
                ly = b;
            }else{
                uy = a;
            }
        }
    return (uy+ly)/2.0;
}

int main(){
    while(cin >> n&&n!=0){
        vector<double>x(n),y(n),l(n);
        for(int i=0;i<n;i++)cin >> x[i] >> y[i] >>l[i];
        double ux = 100.0;
        double lx = -100.0;
        double uy = 100.0;
        double ly = -100.0;
        double tmpy = 0.0;
        while(ux-lx>=0.000001){
            double a = (ux*2.0+lx)/3.0; 
            double b = (ux+lx*2.0)/3.0;
            double ma = 100000.0;
            double mb = 100000.0;
            tmpy = calc(x,y,l,a);
            for(int i=0;i<n;i++){
                ma = min(ma,l[i]*l[i]-(x[i]-a)*(x[i]-a)-(y[i]-tmpy)*(y[i]-tmpy));
            }
            tmpy = calc(x,y,l,b);
            for(int i=0;i<n;i++){
                mb = min(mb,l[i]*l[i]-(x[i]-b)*(x[i]-b)-(y[i]-tmpy)*(y[i]-tmpy));
            }
            if(ma > mb){
                lx = b;
            }else{
                ux = a;
            }
        }
        double tmpx = (ux+lx)/2.0;
        tmpy = calc(x,y,l,tmpx);
        double mi = 100000.0;
        for(int i=0;i<n;i++){
            
            mi = min(mi,l[i]*l[i]-(x[i]-tmpx)*(x[i]-tmpx)-(y[i]-tmpy)*(y[i]-tmpy));
            
        }
        cout <<fixed << setprecision(10) << sqrt(mi) << endl;
    }
    return 0;
}


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

int main(){
    vector<char> c1(3), c2(3);
    for(int i=0; i<3; i++) cin >> c1[i];
    for(int i=0; i<3; i++) cin >> c2[i];
    
    reverse(c1.begin(),c1.end());
    if(c1==c2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, M, Q = map(int, input().split())

    check = np.zeros((N+1, N+1))

    for i in range(M):
        l, r = map(int, input().split())
        check[r][l] += 1

    # print(check)
    for i in range(1, N+1):
        check[i] += check[i-1]
    for i in range(1, N+1):
        check[:,i] += check[:,i-1]
    # print(check)

    for i in range(Q):
        p, q = map(int, input().split())
        print(int(check[q][q] - check[q][p-1] - check[p-1][q] + check[p-1][p-1]))

if __name__ == "__main__":
    main()


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


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

    vi p(n);
    rep(i, n) cin >> p[i];

    int min = p[0];
    int cnt = 0;

    rep(i, n) {
        if (p[i] <= min) {
            cnt++;
            min = p[i];
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    map<int,int> mapa;
    int n;cin>>n;
    int niz[n];
    ll suma=0;
    for(int i=0;i<n;i++){
        cin >> niz[i];
        suma+=niz[i];
        mapa[niz[i]]++;
    }
    int q;cin>>q;
    int b,c;
    for(int i=0;i<q;i++){
        cin>>b>>c;
        suma+=(c-b)*mapa[b];
        mapa[c]=mapa[c]+mapa[b];
        mapa[b]=0;
        cout << suma<<endl;
    }

}


Measured memory_bytes: 8324
#include<stdio.h>

int main()
{
    int N,A,m=0,n=0;
    scanf("%d\n%d",&N,&A);
    n=N*N;
    if((1 <= N && N <= 100) && (0 <= A && A<=n))
    {
     m = n - A;
     printf("\n%d\n",m);
    }
return 0;
}

Measured memory_bytes: 1644
#include<stdio.h>

int main(void)
{
	int i,n,m,min=0,max=100000,l,r;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&l,&r);
		if(l>min)
			min=l;
		if(r<max)
			max=r;
	}
	if(max<min)
		printf("0");
	else
		printf("%d",max-min+1);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func gcd(a, b int) int {
	r := a % b
	if r == 0 {
		return b
	}
	return gcd(b, r)
}

func gcdMulti(xs []int) int {
	ans := xs[0]
	for i := 1; i < len(xs); i++ {
		ans = gcd(ans, xs[i])
	}
	return ans
}

func main() {
	var N, X int
	fmt.Scan(&N, &X)
	ds := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range ds {
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		ds[i] = abs(X - t)
	}
	fmt.Println(gcdMulti(ds))
}


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

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    ve<string> fi(h);
    rep(i,h) cin >> fi[i];
    int ans = 0;
    rep(i,1<<h)rep(j,1<<w){
        int cnt = 0;
        ve<bool> g(h,false), r(w,false);
        rep(k,h) if((i>>k) & 1) g[k]=true;
        rep(k,w) if((j>>k) & 1) r[k]=true;
        rep(x,h)rep(y,w){
            if(g[x])continue;
            if(r[y])continue;
            if(fi[x][y] == '#') cnt++;
        }
        if(cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
n = gets.to_i
s = gets.strip.chars
 
count = 0
 
0.upto(n-2) do |i|
  (i+1).upto(n-1) do |j|
    k = 2 * j - i
    next if k >= n
 
    if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
      count += 1
    end
  end
end
 
r = s.count { |c| c == 'R' }
g = s.count { |c| c == 'G' }
b = s.count { |c| c == 'B' }
 
puts r * g * b - count

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> R(n);
    for(int i = 0; i < n; i++){
        cin >> R[i];
    }

    int minv = R[0], ans = -1e9;
    for(int i = 1; i < n; i++){
        ans = max(ans, R[i]-minv);
        minv = min(minv, R[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
   string s;
string t;
cin>>s;
cin>>t;
int z;
z=s.length();


    int j=0;

   for(int i=0;i<=z-1;i++){

        if(s[i]!=t[i])
 j++;
   }

cout<<j;

}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int x;
    scanf("%d", &x);
    int a, b;
    int ans_a = 0;
    int ans_b = 0;
    for(a = -119; a < 120; a++){
        for(b = -119; b < 120; b++){
            if((a*a*a*a*a - b*b*b*b*b) == x){
                ans_a = a; 
                ans_b = b;
            }
        }
    }
    printf("%d %d", ans_a, ans_b);
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, a;
    cin >> n >> a;
    OP(n * n - a);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<double> A(N);
  rep(i, N) cin >> A[i];
  rep(i, N) A[i] = 1 / A[i];

  double ans = 1 / accumulate(A.begin(), A.end(), 0.0);
  printf("%.6f\n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <unordered_map>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define ll long long
#define INF ((1<<30)-1)
#define NEG (-1)
#define MOD 1000000007
#define MAXN 100100
#define EPS 1e-9
#define INFLL 1e18
using namespace std;
FILE *in,*out;

ll N,M,K;
pair<ll,ll> pos[100100];

int read()
{
    ll i,j,k;
    cin >> N >> M;    
    for(i=0;i<N;i++)
    {
        cin >> j;
        pos[i].f = j;
        if(i>0)
            pos[i].f += pos[i-1].f;
        pos[i].f %= M;
        pos[i].s = i;
    }
    pos[N].f = 0;
    pos[N].s = 0;
    N++;
    sort(pos,pos+N);
    ll ans = 0;
    for(i=0;i<N;i++)
    {
        for(j=i;j<N;j++)
            if(pos[i].f != pos[j].f)
                break;
        // printf("%lld %lld\n",i,j);
        ans += (j-i)*(j-i-1)/2;
        i = j-1;
    }
    cout << ans << endl;
    return 0;
}

int main()
{
    // in = fopen("A.in","r");
    // out  = fopen("A.out","w");
    in = stdin;
    out = stdout;
    read();
    return 0;
}
//////////// Local Snippets
// forx
// fory
// vectorx
// pairx
// sizex

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

int N, M;
map<string, int> s, t;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string x;
        cin >> x;
        s[x]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string x;
        cin >> x;
        t[x]++;
    }

    int ans=0;
    for (auto itr = s.begin(); itr != s.end(); ++itr)
    {
        ans = max(ans, itr->second - t[itr->first]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) {
    cin >> p[i];
  }
  vector<int> dp(n+5,0);
  int maxlen = 0;
  rep(i,n) {
    dp[p[i]] = dp[p[i] - 1] + 1;
    chmax(maxlen, dp[p[i]]);
  }
  cout << n - maxlen << endl;
  return 0;
}

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

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

  ll a, b, c, k; cin >> a >> b >> c >> k;
  ll ans;
  if(k%2 == 0) ans = a-b;
  else ans = b-a;

  if(abs(ans) > 1e18) {
    cout << "Unfair" << '\n';
    return 0;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include<stack>
#include <unordered_map>

using namespace std;

int abs(int x) { return x < 0 ? -x : x; }

int main() {
	string s;
	cin >> s;
	if (s.find("AC") == -1) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    vector<string> s(3);
    rep(i, 3) cin >> s[i];
    cout << s[0][0] << s[1][0] << s[2][0];
}


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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  string scopy = s;
  int i;
  int countl = 0;
  int countr = 0;
  bool search = false;
  int check;
  int prev = 0;
  int now;
  while(true)
  {
    search = false;
    for(i = 0; i < n; i++)
    {
      if(s.at(i) == '(')
      {
        search = true;
        check = i;
      }
      if(search && s.at(i) == ')')
      {
        s.at(i) = '.';
        s.at(check) = '.';
        search = false;
      }
    }
    now = 0;
    for(i = 0; i < n; i++)
    {
      if(s.at(i) == '.')
      {
        now++;
      }
    }
    if(now == prev) break;
    else prev = now;
  }
  for(i = 0; i < n; i++)
  {
    if(s.at(i) == '(')countl++;
    else if(s.at(i) == ')')countr++;
  }
  for(i = 0; i < countr; i++)
  {
    cout << '(';
  }
  cout << scopy;
  for(i = 0; i < countl; i++)
  {
    cout << ')';
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < m/2; i++){
			System.out.println((i + 1) + " " + (m - i));
		}

		for(int i = 0; i < m - m/2 ; i++){
			System.out.println((m + i + 1) + " "+ (2*m + 1 - i));
		}

	}

}


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

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

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    for (int i = 0; i < Q; i++) {
        cin >> A[i];
        A[i]--;
    }
    map<int, int> M;
    for (int i = 0; i < Q; i++) {
        M[A[i]]++;
    }
    for (int i = 0; i < N; i++) {
        if (Q - M[i] >= K) cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }

    return 0;
}


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

int main() {
    int D;
    cin >> D;
    string ans = "Christmas";
    string eve = " Eve";
    for (int i = 0; i < 25-D; i++) ans += eve;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    int n, m = 0;
    cin >> n;
    bool flag = false;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        if(a == b) m++;
        else m = 0;
        if (m >= 3) flag = true;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 2*1e13;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll x;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>x;
    ll ans = 0;
    ans += (x/500)*1000;
    x %= 500;
    ans += (x/5)*5;
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,a,b,result;
    char com;
    while(1){
        scanf("%d %c %d",&a,&com,&b);
        if(com == '+')result = a + b;
        else if(com == '-')result= a - b;
        else if(com == '/')result= a / b;
        else if(com == '*')result= a * b;
        else if(com == '?')break;
        else {
            printf("error value : %c\n",com);
            break;
        }
        printf("%d\n",result);
    }
    return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int x = N*A, y = B; 
  
  if (x <= y) {
    cout << x << endl;
  }
  else {
    cout << y << endl;
  }
}



Measured memory_bytes: 256
#!/usr/bin/perl

use strict;
use warnings;

my ($m1, $d1);
{
    my $in = <STDIN>;
    ($m1, $d1) = split(" ", $in);
}
my ($m2, $d2);
{
    my $in = <STDIN>;
    ($m2, $d2) = split(" ", $in);
}
print "0\n" if $d2!=1;
print "1\n" if $d2==1;

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

vll d(100, -1), f(100, -1);
vvll edges(100, vll());
ll n;

ll dfs(ll i, ll t) {
  if (d.at(i) != -1) return t-1;
  d.at(i) = t;
  REP(toi, edges.at(i).size()) {
    t = dfs(edges.at(i).at(toi), ++t);
  }
  return f.at(i) = t+1;
}

int main() {
  cin >> n;
  REP(i, n) {
    ll u, k; cin >> u >> k;
    REP(j, k) {
      ll to; cin >> to;
      edges.at(u-1).push_back(to-1);
    }
  }
  ll t = 0;
  REP(i, n) {
    t = dfs(i, t+1);
  }
  REP(i, n) {
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }
  return 0;
}



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

int main() {
  int minv = 1000000;
  int maxv = -1000000;
  LL sum = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i ++) {
    int x; cin >> x;
    sum += x;
    minv = min(minv, x);
    maxv = max(maxv, x);
  }

  cout << minv << " " << maxv << " " << sum << endl;
}



Measured memory_bytes: 3104
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] numofmatch = {10000000,2,5,5,4,5,6,3,7,6};
        int[] ar = new int[m];
        for (int i = 0; i < m; i++) {
            ar[i] = sc.nextInt();
        }
        BigInteger[] dp = new BigInteger[n+1];
        // max number made by just n-cost 
        BigInteger test = new BigInteger("-1");
        
        BigInteger shift = BigInteger.TEN;
        for (int i = 0; i <= n; i++) {
            dp[i] = test;
        }
        dp[0] = BigInteger.ZERO;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (dp[i].compareTo(test) == 0) {
                    continue;
                }
                if (i + numofmatch[ar[j]] > n) {
                    continue;
                }else{
                    if (dp[i + numofmatch[ar[j]] ]
                                .compareTo((dp[i].multiply(shift)).add(new BigInteger(Integer.toString(ar[j]))) ) > 0 ) {
                        dp[i + numofmatch[ar[j]]] = dp[i + numofmatch[ar[j]]];
                    } else {
                        dp[i + numofmatch[ar[j]]] = (dp[i].multiply(shift)).add(new BigInteger(Integer.toString(ar[j])));
                    }
                }
            }
        }
        System.out.println(dp[n]);


        sc.close();
    }
}

Measured memory_bytes: 162204
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
ll powK[300010];
ll powS[300010];

void solve() {
	cin >> K >> N;
	if(K % 2 == 0) {
		cout << (K + 1) / 2 << " ";
		rep(i, 0, N - 1) {
			cout << K << " ";
		}
		return;
	}
	memset(powK, -1, sizeof(powK));
	memset(powS, -1, sizeof(powS));

	powK[0] = 1;
	powS[0] = 0;
	rep(i, 1, N + 1) {
		powK[i] = powK[i - 1] * K;
		powS[i] = powS[i - 1] + powK[i];
		if((powS[i] + 1) / 2 > N) break;
	}
	int at = 0, off = 0;
	while(powS[N - at] == -1) {
		cout << (K + 1) / 2 << " ";
		off += (N - at - 1) % 2;
		at++;
	}
	ll m = (powS[N - at] + 1) / 2 - 1 - off;
	while(true) {
		ll xnext = powS[N - at] / K;
		cout << (m / xnext) + 1 << " ";
		m %= xnext;
		if(m == 0) return;
		else m--;
		at++;
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 7040
//In The Name Of God
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<vii> vvii;

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define forn(i, n) for (ll i = 0; i < n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define forne(i, x, n) for (ll i = x; i < n; i++)
#define forre(i, x, n) for (int i = n; i >= x; i--)
#define all(a) (a).begin(), (a).end()
#define eps 1e-9


int main() {
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int sm = n * (n + 1) / 2;
    for (int i = 2; i <= sm; i++) {
        if (sm % i == 0) {
            sm /= i;
            break;
        }
    }
    vvi tod;
    vi vis(n + 1);
    for (int i = n; i >= 1; i--) if (!vis[i]) {
        tod.push_back(vi());
        tod.back().push_back(i);
        int cur = i;
        for (int j = i - 1; j >= 1; j--) if (!vis[j] && cur + j <= sm)
            cur += j, vis[j] = 1, tod.back().push_back(j);
    }
    vii edges;
    forn(i, tod.size()) {
        for (int j = i + 1; j < tod.size(); j++) {
            for (auto &e : tod[i]) for (auto &ee : tod[j])
                edges.push_back({e, ee});
        }
    }
    cout << edges.size() << endl;
    for (auto &e : edges) cout << e.first << ' ' << e.second << endl;

    return 0;
}

Measured memory_bytes: 384
n, q = map(int, input().split())
sss = list(input())
cnt = [0] * n
for i in range(1, n):
    if sss[i - 1] == 'A' and sss[i] == 'C':
        cnt[i] += cnt[i - 1] + 1
    else:
        cnt[i] += cnt[i - 1]

for _ in range(q):
    li, ri = map(int, input().split())
    print(cnt[ri-1] - cnt[li-1])

Measured memory_bytes: 8356
while True:
  n,k = list(map(int,input().split()))
  if n == 0 and k == 0:
    break
  a=[]
  for i in range(n):
    a.append(int(input()))
  s = sum(a[0:k])
  ss=[s]
  for i in range(k,n):
    s = s +a[i]- a[i-k]
    ss.append(s)
  print(max(ss))


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

int N;
int A_1[107];
int A_2[107];

int main(){
    cin >> N;

    for(int i = 1;i < N+1;i++){
        cin >> A_1[i];
    }
    for(int i = 1;i < N+1;i++){
        cin >> A_2[i];
    }

    int true_ans = 0;
    int ans = 0;
    bool IsDown = false; // 下に行くフラグ
    // i回目で下に行く
    for(int i = 1;i < N+1;i++){
        ans = 0;
        IsDown = false;

        for(int j = 1;j < N+1;j++){
            if(i == j){
                ans += A_1[j];
                IsDown = true;
            }

            if(IsDown){
                ans += A_2[j];
            }else{
                ans += A_1[j];
            }
        }

        if(ans > true_ans){
            true_ans = ans;
        }

    }

    cout << true_ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    vector<int> cnt(n,0);
    rep(i,n-1){
        int a;
        cin >> a;
        cnt.at(a-1)++;
    }
    rep(i,n) cout << cnt.at(i) << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  set<string> st;
  rep(i, k) {
    rep(j, n - i) {
      string t = s.substr(j, i + 1);
      st.insert(t);
    }
  }
  auto it = st.begin();
  rep(i, k - 1) it++;
  cout << *it << endl;
}

Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
using namespace std;


int main(){
int n,m;cin>>n>>m;
vi d(n);
rep(i,n)d.at(i)=i+1;
vv (a,m,2);
rep(i,m)rep(j,2)cin>>a.at(i).at(j);
int ans=0;
do{
    if(d.at(0)!=1)break;
    int flag=0;
    for(int i=1;i<n;i++){
        rep(j,m){
        if((d.at(i-1)==a.at(j).at(0))||(d.at(i-1)==a.at(j).at(1))){
            if((d.at(i)==a.at(j).at(1))||(d.at(i)==a.at(j).at(0))){
                flag++;
                break;
            }
        }
    }
    }
    if(flag==(n-1)){
        if(flag<=m)ans++;
    }
}while(next_permutation(all(d)));
cout<<ans<<endl;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (a == c && a != b)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (c == b && a != c)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
const int NIL = -1;
struct Point {
	int x, y, id;
	Point() {}
	Point(int x, int y, int id = 0) :x(x), y(y), id(id) {};
	bool operator<(const Point &p) {
		return id < p.id;
	}
	void print() { printf("%d\n", id); }
};
bool lessX(const Point &p1, const Point &p2) {
	return (p1.x == p2.x) ? (p1.y < p2.y) : (p1.x < p2.x);
}
bool lessY(const Point &p1, const Point &p2) {
	return (p1.y == p2.y) ? (p1.x < p2.x) : (p1.y < p2.y);
}
struct KDtree {
	struct Node {
		int index, l, r;
		Node() {};
		Node(int index, int l = NIL, int r = NIL) :index(index), l(l), r(r) {};
	};

	vector<Point>points; vector<Node>nodes; int n, np, root;
	KDtree(vector<Point>&p) :n(p.size()), points(p), np(0) {
		nodes.resize(n);
		root = makeKDtree(0, n, true);
	}
	int makeKDtree(int l, int r, bool is_x_base) {
		if (!(l < r))return NIL;
		int mid = (l + r) / 2, t = np++;
		vector<Point>::iterator first = points.begin() + l,
			nth = points.begin() + mid, last = points.begin() + r;
		if (is_x_base)nth_element(first, nth, last, lessX);
		else nth_element(first, nth, last, lessY);
		nodes[t] = Node(mid, makeKDtree(l, mid, !is_x_base), makeKDtree(mid + 1, r, !is_x_base));
		return t;
	}
	bool inrange(const Point &p, const Point &s, const Point &t) {
		return s.x <= p.x&&p.x <= t.x&&s.y <= p.y&&p.y <= t.y;
	}
	vector<Point>ret;
	vector<Point>find(const Point &s, const Point &t) {
		ret.clear();
		return find(root, true, s, t);
	}
	vector<Point> find(int v, bool is_x_base, const Point &s, const Point &t) {
		auto p = points[nodes[v].index];
		if (inrange(p, s, t))ret.emplace_back(p);
		if (is_x_base) {
			if (nodes[v].l != NIL && s.x <= p.x)find(nodes[v].l, !is_x_base, s, t);
			if (nodes[v].r != NIL && p.x <= t.x)find(nodes[v].r, !is_x_base, s, t);
		}
		else {
			if (nodes[v].l != NIL && s.y <= p.y)find(nodes[v].l, !is_x_base, s, t);
			if (nodes[v].r != NIL && p.y <= t.y)find(nodes[v].r, !is_x_base, s, t);
		}
		return ret;
	}
};
signed main() {
	int n; scanf("%d", &n);
	vector<Point>p(n);
	rep(i, 0, n) {
		int x, y; cin >> x >> y;
		p[i] = Point(x, y, i);
	}
	KDtree tree(p);
	int q; scanf("%d", &q);
	rep(i, 0, q) {
		int sx, tx, sy, ty; scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		auto u = tree.find(Point(sx, sy), Point(tx, ty));
		sort(all(u));
		rep(i, 0, u.size())printf("%d\n", u[i].id);
		puts("");
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> altar(3, vector<int>(n));
	for (auto&& altari : altar)
	{
		for (auto&& altarii : altari) cin >> altarii;
		sort(altari.begin(), altari.end());
	}
	vector<vector<long long>> dp(3, vector<long long>(n, 0));
	for (int i = 0; i < n; i++) dp[0][i] = i + 1;
	for (int i = 1; i < 3; i++)
	{
		auto k = lower_bound(altar[i-1].begin(), altar[i-1].end(), altar[i][0]) - altar[i-1].begin();
		dp[i][0] = k == 0 ? 0 : dp[i-1][k-1];
		for (int j = 1; j < n; j++)
		{
			auto l = lower_bound(altar[i-1].begin(), altar[i-1].end(), altar[i][j]) - altar[i-1].begin();
			dp[i][j] = l == 0 ? 0 : dp[i-1][l-1];
			dp[i][j] += dp[i][j-1];
		}
	}
	cout << dp[2][n-1] << endl;
	return 0;
}


Measured memory_bytes: 4600
import kotlin.math.min

fun main() {

    val (n,m,x) = readLine()!!.split(" ").map { it.toInt() }
    val subject = Array(n){IntArray(m+1) }

    for(i in 0 until n) {
        subject[i] = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    }

    fun dfs(idx:Int, learn:IntArray, cost:Int): Int {
        var isOk = true
        var ans = Int.MAX_VALUE

        for(i in 1..m) {
            if(learn[i] < x) {
                isOk = false
                break
            }
        }

        if(isOk) {
            return cost
        }

        for(select in idx until n) {
            for(j in 1..m) {
                learn[j] += subject[select][j]
            }
            ans = min(ans, dfs(select + 1, learn, cost + subject[select][0]))
            for(j in 1..m) {
                learn[j] -= subject[select][j]
            }
        }
        return ans
    }

    var ans = dfs(0, IntArray(m+1), 0)
    if(ans == Int.MAX_VALUE) {
        ans = -1
    }
    print(ans)





}

Measured memory_bytes: 38920
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b ,c;
    cin >> a>> b >> c;
    if(a + b == c || a + c == b || b+ c == a)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}

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

int top, S[1000];

void push(int);
int pop();

int main(void)
{
    top = 0;

    char str[100];
    int x, y;

    while (scanf("%s", str) != EOF) {
        if (str[0] == '+') {
            x = pop();
            y = pop();
            push(x + y);
        } else if (str[0] == '-') {
            y = pop();
            x = pop();
            push(x - y);
        } else if (str[0] == '*') {
            x = pop();
            y = pop();
            push(x * y);
        } else {
            push(atoi(str));
        }
    }
    printf("%d\n", pop());

    return 0;
}

void push(int x)
{
    S[top++] = x;
}

int pop()
{
    return S[--top];
}


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

int main(){
  int W, H, x, y;
  cin >> W >> H >> x >> y;

  int ans = 0;
  if ( ((W / 2.0) == x) and ((H / 2.0) == y) )
    ans = 1;

  cout << setprecision(30) << (long double)W * H * 0.5 << " " << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue> //priority queue
#include <stack>
#include <map> // multimap
#include <set> //multiset
#include <list> 
#include <utility> // pair
#include <iterator>
#include <deque> // insertion as both ends
#include <string>
// g1=s.substr(0,n/2);
// g2=s.substr(n/2+n%2,n/2);
#include <cctype> //isaplha
#include <iomanip>      // std::setprecision
#include <algorithm> //binary_search,sort, next_permutation in lexicographically greater permutation, fill(it1,it2,val)
#include <cmath>
#include <limits.h> //INT_MIN,INT_MAX
#include <numeric>  //iota,partial_sum,inner_product,accumulate(begin,end,num)
#include <functional>  //Arithmetic, comparators, logical
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h> 
#include <cstring>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define pi 3.14159
#define mod 1000000007

#define ll long long 
#define ull unsigned long long
#define pb push_back
#define pf push_front //deque
#define mp make_pair
#define PQ priority_queue

#define f first
#define s second
#define pii pair< int, int >
#define piii pair<int,pair<int,int> >
#define vi vector<int> 
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = s; 
    for (int i=1; i<n;i++) 
        s += s1;
    return s; 
}
string getString(char x) {
    string s(1, x); 
    return s;    
} 

void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
}

vector<ll> primeFactors(ll n)  { 
    vector<ll> v;
    if(n%2==0) v.pb(2); 
    while (n % 2 == 0)  {  
        n = n/2;  
    }  
    for (ll i = 3; i <= sqrt(n); i = i + 2) {  
        if(n%i==0) v.pb(i);
        while (n % i == 0) {  
            n = n/i;  
        }  
    } 
    if (n > 2)  v.pb(n);
    return v;
}  
bool isPrime(ll n){
    if (n <= 1)  return false; 
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

int main(){
    optimizeIO();
    ll n;
    cin>>n;

    std::vector<ll> v(n);
    rep(i,0,n) cin>>v[i];
    ll s=accumulate(v.begin(),v.end(),0*1LL);
    ll till=0;
    ll ans=LONG_LONG_MAX;
    rep(i,0,n){
        till+=v[i];
        ans=(ans*1LL< 1LL*abs(s-2*till))?ans:1LL*abs(s-2*till);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort()

hoge = max(0, N - K)
ans = sum(H[:hoge])
print(ans)


Measured memory_bytes: 88908
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
ll dp[200005][2],t[800005],hell=998244353;
void update(ll v,ll tl,ll tr,ll pos,ll val){
  if(tl==tr)
    t[v]=val;
  else{
    ll tm=(tl+tr)/2;
    if(pos<=tm)
      update(2*v,tl,tm,pos,val);
    else
      update(2*v+1,tm+1,tr,pos,val);
    t[v]=max(t[2*v],t[2*v+1]);
  }
}
ll query(ll v,ll tl,ll tr,ll l,ll r){
  if(l>r)
    return -1;
  else if(l==tl&&r==tr)
    return t[v];
  ll tm=(tl+tr)/2;
  return max(query(2*v,tl,tm,l,min(r,tm)),query(2*v+1,tm+1,tr,max(l,tm+1),r));
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin>>n;
  vector<p2> v(n);
  for(ll i=0;i<n;i++)
    cin>>v[i].first>>v[i].second;
  sort(v.begin(),v.end());
  vector<ll> x;
  for(ll i=0;i<n;i++)
    x.push_back(v[i].first);
  dp[n-1][0]=dp[n-1][1]=1;
  update(1,1,n,n,n);
  for(ll i=n-2;i>=0;i--){
    dp[i][0]=(dp[i+1][0]+dp[i+1][1])%hell;
    auto it=lower_bound(x.begin(),x.end(),v[i].first+v[i].second);
    --it;
    ll j=(ll)(it-x.begin());
    j=max(j,query(1,1,n,i+1,j+1)-1);
    if(j!=i)
      dp[i][1]=dp[j][1];
    else
      dp[i][1]=dp[i][0];
    update(1,1,n,i+1,j+1);
  }
  dp[0][0]+=dp[0][1];
  dp[0][0]%=hell;
  cout<<dp[0][0];
}

Measured memory_bytes: 14448
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>


int32_t main(){ fast;
	int n; cin>>n;
	if(n % 1000 == 0){
		cout<<0<<endl;
	}
	else{
		int n1  = n;
		while(n % 1000 != 0){
			n++;
		}
		cout<<n - n1<<endl;
	}
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;
//abc165d

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,b,n;
    cin>>a>>b>>n;
    cout<<(a*min(b-1,n))/b<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=2e6+5;

int main()
{
    DeltaCube23
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    lli res=n+(n*n)+(n*n*n);
	    cout<<res<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3648
<?php
	$a=fgets(STDIN);
	$b=$a%100;
	$a=floor($a/100);
	$a=0<$a&&$a<13;
	$b=0<$b&&$b<13;
	echo $a?$b?AMBIGUOUS:MMYY:($b?YYMM:NA);


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[55],sum=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-k+1;i--)
    sum+=a[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
int arr [50000000];
void Eratosthenes(int N) {//N?????§????´???°??¨
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = i * 2; j <= N; j += i) {
				arr[j] = 0;
			}
		}
	}

	int cou = 0;
	for (int i = 2; N > i; i++) {
		if (arr[i]) {
			arr[cou] = i;
			cou++;
		}
	}
}
int main() {
	Eratosthenes(1000000);

	int a, b,n;
	while (scanf("%d %d %d", &a, &b, &n)) {
		if (!a && !b && !n)
			return 0;

		int cou = 0;
		for(int i = 0; ; i++) {
			if (arr[i] - a < 0)continue;
			if (!((arr[i] - a) % b)) cou++;
			if (cou == n) {
				printf("%d\n", arr[i]);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 7032
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
N = int(input())
for i in range(N):
    g.add_edge(i, (i+1)%N, 1)
    g.add_edge(i, (10 * i) % N, 0)

d = Dijkstra(g, 1)
print(d.dist[0]+1)


Measured memory_bytes: 62368
H, W = map(int, input().split())

a = []
for i in range(H):
    a.append(list(map(int, input().split())))

onestroke = []

for i in range(H):
    for j in range(W):
        if i%2==0:
            onestroke.append([i, j])
        else:
            onestroke.append([i, W-j-1])

list = []
N = 0

for i in range(H*W-1):
    if a[onestroke[i][0]][onestroke[i][1]]%2!=0:
        list.append([onestroke[i][0]+1, onestroke[i][1]+1, onestroke[i+1][0]+1, onestroke[i+1][1]+1])
        N += 1
        a[onestroke[i+1][0]][onestroke[i+1][1]] += 1

print(N)
for i in range(N):
    print(list[i][0], list[i][1], list[i][2], list[i][3])

Measured memory_bytes: 59816