akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <iostream>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P2;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int const TREE_SIZE = (1 << 20);

class SegTree{
	public:
	// コンストラクタ
	SegTree(std::function<long long int(long long int, long long int)> monoidFunc_, long long int invalidValue_){
		monoidFunc = monoidFunc_;
		invalidValue = invalidValue_;
	}
	// 値の初期化
	void init(long long int initValue){
		for(int i = 0; i < TREE_SIZE; i++){
			segTree[i] = initValue;
		}
	}
	// a番目(0-indexed)をwに変更する O(log N)
	void change(int a, long long int w){
		change_(a + 1, w);
	}
	// 区間 [a, b] (0-indexed)の値を求める O(log N)
	long long int query(int a, int b){
		return query_(a + 1, b + 2, 1, 0, TREE_SIZE / 2);
	}
	private:
	function<long long int(long long int, long long int)> monoidFunc;
	long long int invalidValue;
	long long int segTree[TREE_SIZE]; // 1-indexed

	// a番目をwに変更する O(log N)
	void change_(int a, long long int w){
		a += TREE_SIZE / 2;
		segTree[a] = w;
		for(int x = a / 2; x > 0; x /= 2){
			segTree[x] = monoidFunc(segTree[2 * x], segTree[2 * x + 1]);
		}
	}
	// 区間 [a, b) の値を求める O(log N)
	// query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	long long int query_(int a, int b, int index, int l, int r){
		if(r <= a || b <= l){
			return invalidValue;
		}
		if(a <= l && r <= b){
			return segTree[index];
		}
		return monoidFunc(query_(a, b, index * 2, l, (l + r) / 2), query_(a, b, index * 2 + 1, (l + r) / 2, r));
	}
};

long long int func(long long int a, long long int b){
	return min(a, b);
}
SegTree segTree(func, INF);

int main(){
	segTree.init(INF);
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < q; i++){
		long long int tp, a, b;
		cin >> tp >> a >> b;
		if(tp == 0){
			segTree.change(a, b);
		}else{
			if(segTree.query(a, b) == INF){
				cout << (1LL << 31) - 1 << endl;
			}else{
				cout << segTree.query(a, b) << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 11332
package main

import "fmt"

const (
	MAX_N = 50
	MAX_A = 50
)

func main() {
	var N, A int
	var x [MAX_N + 1]int

	var dp [MAX_N + 1][MAX_N + 1][MAX_N*MAX_A + 1]int64

	fmt.Scanf("%d %d", &N, &A)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &x[i+1])
	}

	for i := 0; i < N; i++ {
		dp[i][0][0] = 1
	}

	for i := 1; i <= N; i++ {
		for j := 1; j <= i; j++ {
			for k := 1; k <= A*N; k++ {
				if k < x[i] {
					dp[i][j][k] = dp[i-1][j][k]
				} else {
					dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]]
				}
			}
		}
	}

	ans := int64(0)
	for j := 1; j <= N; j++ {
		ans += dp[N][j][j*A]
	}

	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 51328
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n][n];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  int ans=0;
  bool used[n];
  memset(used,0,sizeof(used));
  used[0]=1;
  int cost[n];
  for(int i=0;i<n;i++) cost[i]=a[0][i];
  while(1){
    int v=-1;
    for(int i=0;i<n;i++){
      if(used[i]||cost[i]<0) continue;
      //cout<<i<<":"<<cost[i]<<endl;
      if(v<0||cost[i]<cost[v]) v=i;
    }
    if(v<0) break;
    used[v]=1;
    ans+=cost[v];
    //cout<<v<<endl;
    for(int i=0;i<n;i++){
      if(a[v][i]<0) continue;
      if(cost[i]<0||a[v][i]<cost[i]) cost[i]=a[v][i];
    }
  }
  cout<<ans<<endl;
  return 0;
}



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

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = gcd(c, d);
    ll h = (c / g) * d;
    ll ac = a / c + (a % c != 0);
    ll ad = a / d + (a % d != 0);
    ll bc = b / c;
    ll bd = b / d;
    ll ah = a / h + (a % h != 0);
    ll bh = b / h;
    ll t = b - a + 1;
    ll ta = bc - ac + 1;
    ll tb = bd - ad + 1;
    ll th = bh - ah + 1;
    cout << t - (ta + tb - th) << endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

const int INF = 100000 + 1000;

map<int, bool> factors;

bool isFactor(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (factors.find(n) != factors.end()) return factors[n];

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            factors[n] = false;
            return false;
        }
    }
    factors[n] = true;
    return true;
}

int main() {
    vector<ll> like_2017_sum(INF, 0);
    for (int i = 3; i <= INF; i++) {
        if (isFactor(i) && isFactor((i + 1) / 2)) {
            like_2017_sum[i] = like_2017_sum[i - 1] + 1;
        } else {
            like_2017_sum[i] = like_2017_sum[i - 1];
        }
    }

    int q;
    cin >> q;
    rep(i, q) {
        int l, r;
        cin >> l >> r;

        cout << (like_2017_sum[r] - like_2017_sum[l - 1]) << endl;
    }

}

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


int main() {
  int64_t N;
  scanf("%lld", &N);
  std::string ans;
  while (N > 0) {
  N--;
    ans += 'a' + (N%26);
    N /= 26;
  }
  std::reverse(ans.begin(), ans.end());
  printf("%s\n", ans.c_str());
}


Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>

using namespace std;


int main()
{
	int A, B, M;
	vector<int> a, b, x, y, c;
	
	cin >> A >> B >> M;
	a.resize(A);
	b.resize(B);
	x.resize(M);
	y.resize(M);
	c.resize(M);

	for (int i = 0; i < A; i++)
		cin >> a[i];

	for (int i = 0; i < B; i++)
		cin >> b[i];

	for (int i = 0; i < M; i++)
		cin >> x[i] >> y[i] >> c[i];
	
	vector<int> dc;
	for (int i = 0; i < M; i++)
	{
		dc.push_back(a[x[i]-1] + b[y[i]-1] - c[i]);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	dc.push_back(a[0] + b[0]);
	sort(dc.begin(), dc.end());

	cout << dc[0];

	return 0;
}

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;
int dp[70][2][2][2][2]; // dp[bit][carry][a < b][(a + b) < N][(a ^ b) < N]
int n;

int add(int x, int y) { return (x + y + mod) % mod; }

int solve(int bit = 61, bool carry = false, bool ab = false, bool sm = false, bool xr = false){
    if(bit == -1) return 1 - carry;
    int &ret = dp[bit][carry][ab][sm][xr];
    if(~ret) return ret;
    ret = 0;
    bool state = (((1ll << bit) & n) > 0);
    for(int a = 0 ; a < 2 ; ++a)
        for(int b = a; b < 2; ++b){
            int ans = 0;
            bool axorb = (a ^ b);
            int ad = a + b;
            if(!ab && a > b) continue;
            if(!xr && (axorb > state)) continue;
            if(!ad){
                if(carry) continue;
                ret = add(ret,
                    solve(bit - 1, false, ab | (a < b), sm | state, xr | (axorb < state)));
                if(sm || state) 
                ret = add(ret,
                    solve(bit - 1, true, ab | (a < b), sm, xr | (axorb < state)));
            }else if(ad == 1){
                if(carry){
                    ret = add(ret,
                        solve(bit - 1, true, ab | (a < b), sm | state, xr | (axorb < state)));   
                }else{
                    if(!sm && !state) continue;
                    ret = add(ret,
                    solve(bit - 1, false, ab | (a < b), sm, xr | (axorb < state)));
                }
            }else if(ad == 2){
                if(!carry) continue;
                ret = add(ret,
                    solve(bit - 1, false, ab | (a < b), sm | state, xr | (axorb < state)));
                if(sm || state) 
                ret = add(ret,
                    solve(bit - 1, true, ab | (a < b), sm, xr | (axorb < state)));
            } 
        }
    return ret;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;  
    memset(dp, -1, sizeof dp);
    cout << solve() << '\n';
    return 0;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}


int gcd(int a,int b){
  if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  int a,b;cin>>a>>b;
  int k;cin>>k;
  int z = gcd(a,b);
  vector<int> A;
  for(int i = 1;z >= i*i; i++){
    if(!(z%i)){
      A.push_back(i);
      if(z/i != i)A.push_back(z/i);
    }
  }
  sort(A.begin(),A.end(),greater<int>());
  cout << A[k-1] << endl;
  

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int res = 0;
    for (int i = 0; i < N; i++) res += a[i] - 1;
    cout << res << endl;
  }
  return 0;
}


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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(Solve(n));
        }

        static int Solve(long n)
        {
            long[] divisors = Divisors(n);

            if (divisors.Length % 2 == 1)
            {
                return DigitsCount(divisors[divisors.Length / 2]);
            }
            else
            {
                return Math.Max(DigitsCount(divisors[divisors.Length / 2]), DigitsCount(divisors.Length / 2 - 1));
            }
        }

        static long[] Divisors(long n)
        {
            long sqrt = (long)Math.Ceiling(Math.Sqrt(n));
            var list = new List<long>();

            for (long i = 1; i <= sqrt; i++)
            {
                if (n % i == 0)
                {
                    list.Add(i);
                    list.Add(n / i);
                }
            }

            list.Sort();
            return list.ToArray();
        }

        static int DigitsCount(long n) => (int)Math.Log10(n) + 1;
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;

const string MINF="-";

void chmax(string &a, string b) {
    if (a == MINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}
string dp[10010];
int match[10]={2,5,5,4,5,6,3,7,6};



int main(int argc, char const *argv[]) {
  int n,m;
  cin >> n >> m;
  vector<int> A(m);
  rep(i,m) cin >> A[i] ;
  rep(i,10010) dp[i]=MINF;
  dp[0]="";

  for(int i=0; i<=n; i++){
    if(dp[i]==MINF) continue;
    for(auto a:A) chmax(dp[i+match[a-1]],dp[i]+(char)('0' + a));
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 43776
a,b,x=map(int,input().split())
if a%x==0 and b%x==0:
    print(b//x-a//x+1)
elif a%x!=0 and b%x==0:
    print(b//x-a//x)
elif a%x==0 and b%x!=0:
    print(b//x-a//x+1)
else:
    print(b//x-a//x)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<vector<int>> a(n,vector<int>(m,0));
  vector<int> c(n);
  rep(i,n){
    cin>>c.at(i);
    rep(j,m){
      cin>>a.at(i).at(j);
    }
  }
  in ans=INF;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<12> s(tmp);
    // ビット列を出力
    vector<in> sum(m,0);
    in sum_c=0;
    rep(i,n){
      if(s.test(i)){
        sum_c+=c.at(i);
        rep(j,m){
          sum.at(j)+=a.at(i).at(j);
        }
      }
    }
    bool check=true;
    rep(i,m){
      if(sum.at(i)<x)
        check=false;
    }
    if(check){
      ans=min(sum_c,ans);
    }
    
  }
  if(ans==INF)
    cout<<-1<<endl;
  else
    cout<<ans<<endl;
}

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

#define ll long long int 
#define ld long double 
#define pb push_back
#define mk make_pair
#define ii pair<int,int>

using namespace std;
double pi=2*acos(0.0);

/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

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

void solve(){
    string s,t; 
    cin>>s>>t;
    int n=s.size();
    int ans=0;
    for (int i=0;i<n;i++){
        if (s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}

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

    int test_cases=1; 
    //cin>>test_cases;

    for (int tc=1;tc<=test_cases;tc++){
        
        solve();
        //cout << "Case " << tc << ": " << solve() <<endl;
        //printf("Case %d: %.10lf",tc,ans);
    }
    return 0;
}
/*
    problems are the sign of life
*/


Measured memory_bytes: 3892
S = input()
list_S = [int(x) for x in S]

N = len(S)
if N % 2 == 0:
  op1 = [0, 1] * int(N//2)
  op2 = [1, 0] * int(N//2)
else:
  op1 = [0, 1] * int(N//2) + [0]
  op2 = [1, 0] * int(N//2) + [1]
  
cnt_op1 = 0
cnt_op2 = 0
for i in range(N):
  if list_S[i] != op1[i]:
    cnt_op1 += 1
  if list_S[i] != op2[i]:
    cnt_op2 += 1

print(min(cnt_op1, cnt_op2))


Measured memory_bytes: 6244
def main():
    N = int(input())
    S = input()

    x = 0
    maxval = 0

    for i in range(N):
        if S[i] == "I":
            x += 1
            if maxval < x:
                maxval = x
        elif S[i] == "D":
            x -= 1
            if maxval < x:
                maxval = x
    print(maxval)
main()

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (auto& i : h) {
        cin >> i;
    }
    cout << count_if(h.begin(), h.end(), [K](int a){return a >= K;}) << endl;
}

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


int main()
{
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  double d = 2;
  printf("%.10lf ", w * h / d);
  if (x * 2== w && y * 2 == h)
    printf("1\n");
  else
    printf("0\n");
  return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    map <int, int> a;
    int x;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> x;
        ++a[x];
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << endl;
    }
    
}

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

typedef long long ll;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll B_sum = 0;
  for(auto c : S) if(c=='B') B_sum++;

  ll ans = 0;
  for(ll i=0; i<N; ++i){
    for(ll j=0; j<N; ++j){
      if(!(S[i]=='R' && S[j]=='G')) continue;
      ans += B_sum;

      ll k1 = min(i,j)-abs(i-j);
      if(k1>=0) if(S[k1]=='B') ans--;

      ll k2 = max(i,j)+abs(i-j);
      if(k2<N)  if(S[k2]=='B') ans--;

      ll k3 = (i+j)/2;
      if((i+j)%2==0) if(S[k3]=='B') ans--;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define fst first
#define snd second
#define mp make_pair
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define per(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()

template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {return (x>y ? (x=y,true):false);}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {return (x<y ? (x=y,true):false);}

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

const int N = (int)1e6+3;
const int INF = (int)1e9+17;
const ll mod = (ll)1e9+7;
const ll LLINF = (ll)1e18+17;
const ld pi = (ld)acos(-1.0);


int n, m;
int cEquals;
int cGreater;
vector<int> g[N];


void dfs(int v, int p, int dist, int remember) {
    if (dist == remember) ++cEquals;
    if (dist > remember) ++cGreater;
    for(int to:g[v]) if (to != p) dfs(to, v, dist+1, remember);
}

int solve(int v) {
    int mx = 0;
    int ret = 0;
    for(int to:g[v]) {
        cEquals = cGreater = 0;
        dfs(to, v, 1, (m+1)/2);
        ret += cGreater + (m%2 ? cEquals : 0);
        umax(mx, cEquals);
    }
    return ret - (m%2 ? mx : 0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    rep(i, 1, n) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int res = INF;
    rep(v, 0, n) umin(res, solve(v));
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << endl;

	return 0;
}


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

struct T{
  int s,e,c;
  T(int _s,int _e,int _c){
    s = _s; e = _e; c = _c;
  };

  bool operator < (const T& t)const{
    return s < t.s;
  }
};

const int MAX_N = 1001;
const int DAY = 366;
int N;

int dp[2][DAY][DAY];
vector<T>vec;

void input(){
  for(int i = 0 ; i < N ; i++){
    int s,e,c;
    cin >> s >> e >> c;
    vec.push_back(T(s,e,c));
  }
  sort(vec.begin(),vec.end());
  /*
  for(int i = 0 ; i < vec.size() ; i++){
    cout << "i = " << i << " vec[i].s = " << vec[i].s << endl;
  }
  */
}

void init(){
  vec.clear();
  for(int i = 0 ; i < 2 ; i++){
    for(int j = 0 ; j < DAY ; j++){
      for(int k = 0 ; k < DAY ; k++){
	dp[i][j][k] = 0;
      }
    }
  }
}

void solve(){
  init();
  input();

  int res = 0;
  int now = 0;
  int next = 1;

  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < DAY ; j++){
      for(int k = 0 ; k < DAY ; k++){
	dp[next][j][k] = max(dp[next][j][k],dp[now][j][k]);
	int a,b,c; a = b = c = 0;
	if(j < vec[i].s)a = dp[next][vec[i].e][k] = max(dp[next][vec[i].e][k],dp[now][j][k] + vec[i].c);
	if(k < vec[i].s)b = dp[next][j][vec[i].e] = max(dp[next][j][vec[i].e],dp[now][j][k] + vec[i].c);
	res = max(res,max(a,max(b,c)));
      }
    }

    for(int j = 0 ; j < DAY ; j++){
      for(int k = 0 ; k < DAY ; k++){
	dp[now][j][k] = dp[next][j][k];
	dp[next][j][k] = 0;
      }
    }

  }
  cout << res << endl;
}

int main(){
  while(cin >> N,N){
    solve();
  }
  return 0;
}

Measured memory_bytes: 2268
#include<stdio.h>

int main(void){
  int n,i,j,cnt;

  while(scanf("%d",&n),n){
    for(i=1,cnt=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	if((j*(j+1)-i*(i-1))/2==n)cnt++;
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[n];
    int sum = 0;
    int count = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      sum += a[i];
    }
    for(int i = 0; i < n; i++){
      if(a[i]*4*m >= sum){
        count += 1;
      }
    }
    if(count >= m) {
    	System.out.println("Yes");
    }
    else {
    	System.out.println("No");
    }
  }
}

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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int x[n],y[n],a[n];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> a[i];
    }
    bool p[101][101] = {};

    for(int i = 0; i < n; i++){
        if(a[i] == 1){
            for(int j = 1; j <= x[i]; j++){
                for(int k = 1; k <= h; k++){
                    p[j][k] = 1;
                }
            } 
        }
        else if(a[i] == 2){
            for(int j = x[i]+1; j <= w; j++){
                for(int k = 1; k <= h; k++){
                    p[j][k] = 1;
                }
            } 
        }
        else if(a[i] == 3){
            for(int j = 1; j <= y[i]; j++){
                for(int k = 1; k <= w; k++){
                    p[k][j] = 1;
                }
            } 
        }
        else if(a[i] == 4){
            for(int j = y[i]+1; j <= h; j++){
                for(int k = 1; k <= w; k++){
                    p[k][j] = 1;
                }
            } 
        }
    }

    int count = 0;
    for(int i = 1; i <= w; i++){
        for(int j = 1; j <= h; j++){
            if(p[i][j] == 0){
                count++;
            }
            //cout << p[i][j] << " ";
        }
        //cout << endl;
    }
    cout << count << endl;
    return 0;
}

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

int main(void){
        string s;
        string p;
        cin>>s;
        cin>>p;
        s+=s;
        if((int)s.rfind(p)==-1) {
                cout<<"No"<<endl;
        }
        else{
                cout<<"Yes"<<endl;
        }
        return 0;
}



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

int main() {
    int m, d;
    int ans = 0;

    cin >> m >> d;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= d; j++) {
            if ((j % 10) >= 2 && (j / 10) >= 2 && i == (j / 10) * (j % 10)) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);vector<int> t(n);
    string x;
    rep(i,n)cin >> s[i] >> t[i];
    cin >> x;
    int a;
    rep(i,n){
        if(x==s[i]){
            a=i;
        }
    }
    int ans=0;
    for(int i=a+1;i<n;++i){
        ans+=t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
///"Bismillahir Rahmanir Raheem"///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;
const int LOGN = 20;
const int N = 110;
const int W = 100010;
long long int dp[N][W];
int main(){
    int n,w;
    cin>>n>>w;
   // vector<int> dp(n+1,0);
    vector<int> pf(N);
    vector<int> wt(N);

    f1(i,n){
        cin>>wt[i]>>pf[i];
        }

    f1(i,n){
        f1(j,w){
            if(j-wt[i]>=0)
            dp[i][j] = max(dp[i-1][j],(dp[i-1][j-wt[i]]+pf[i]));
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;
    /*for(int i = 0; i<=n; i++){
        for(int j =0;j<=bw;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
return 0;
}



Measured memory_bytes: 79360
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int M = stdIn.nextInt();
        int[] s = new int[M];
        int[] c = new int[M];
        for (int i = 0; i < M; i++) {
            s[i] = stdIn.nextInt();
            c[i] = stdIn.nextInt();
        }
        stdIn.close();
        
        int count;
        int result = -1;
        // N = 3のとき
        if (N == 3) {
            for (int i = 100; i < 1000; i++) {
                count = 0;
                for (int j = 0; j < M; j++) {
                    if (s[j] == 1) {
                        if (i / 100 == c[j]) count++;
                    }
                    if (s[j] == 2) {
                        if ((i % 100) / 10 == c[j]) count++;
                    }
                    if (s[j] == 3) {
                        if (i % 10 == c[j]) count++;
                    }
                }
                if (count == M) {
                    result = i;
                    break;
                } 
            }
        }
        // N = 2のとき
        if (N == 2) {
            for (int i = 10; i < 100; i++) {
                count = 0;
                for (int j = 0; j < M; j++) {
                    if (s[j] == 1) {
                        if (i / 10 == c[j]) count++;
                    }
                    if (s[j] == 2) {
                        if (i % 10 == c[j]) count++;
                    }
                }
                if (count == M) {
                    result = i;
                    break;
                } 
            }
        }
        // N = 1のとき
        if (N == 1) {
            for (int i = 0; i < 10; i++) {
                count = 0;
                for (int j = 0; j < M; j++) {
                    if (i == c[j]) count++;
                }
                if (count == M) {
                    result = i;
                    break;
                } 
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			long a1=cin.nextInt();
			long m1=cin.nextInt();
			long a2=cin.nextInt();
			long m2=cin.nextInt();
			long a3=cin.nextInt();
			long m3=cin.nextInt();
			if((a1|a2|a3|m1|m2|m3)==0){
				break;
			}
			long cnt1=cnt(a1,m1);
			long cnt2=cnt(a2,m2);
			long cnt3=cnt(a3,m3);
			long a = (cnt1*cnt2)/l(cnt1,cnt2);
			long b = (cnt3*a)/l(cnt3,a);
			System.out.println(b);
		}
		
	}
	static long l(long a,long b){
		if(a<b){
			long tmp=a;
			a=b;
			b=tmp;
		}
		if(b==0)return a;
		return l(b,a%b);
	}
	static long cnt(long a,long b){
		long x=1,cnt=0;
		
		do{
			x=(x*a)%b;
			cnt++;
		}while(x!=1);
		return cnt;
	}
}

Measured memory_bytes: 20376
#include <stdio.h>
#include <vector>

using namespace std;

typedef struct _Node {
    int color = 0;
    vector<struct _Node*> next;
    int d = -1;
} Node;

void query(Node* node, int d, int c) {
    if (node->d >= d) {
        return ;
    }
    
    node->d = d;

    if (node->color == 0) {
        node->color = c;
    }
    
    for (vector<Node*>::iterator it = node->next.begin();
         it != node->next.end(); it++) {
        query((*it), d-1, c);
    }
}

int main(void) {
    int n, m, q;
    int *a, *b, *v, *d, *c;
    Node *nodes;

    scanf("%d %d", &n, &m);
    
    nodes = new Node[n];
    a = new int[m];
    b = new int[m];

    for (int i = 0; i < m; i++) {
        scanf("%d %d", &a[i], &b[i]);
        nodes[a[i]-1].next.push_back(&nodes[b[i]-1]);
        nodes[b[i]-1].next.push_back(&nodes[a[i]-1]);
    }

    scanf("%d", &q);

    v = new int[q];
    d = new int[q];
    c = new int[q];

    for (int i = 0; i < q; i++) {
        scanf("%d %d %d", &v[i], &d[i], &c[i]);
    }

    for (int i = q-1; i >= 0; i--) {
        query(&nodes[v[i]-1], d[i], c[i]);
    }

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

    return 0;
}


Measured memory_bytes: 10356
#include<stdio.h>
#define N 44

int fibonacci(int);

int main(){

  int i,n;

  scanf("%d",&n);

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

int fibonacci(int n){

  int F[n],i;
  F[0]=1;
  F[1]=1;

  for( i=2 ; i<=n ; i++)
    F[i] = F[i-2] + F[i-1]; 

  return F[n];
 

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,x,t,p,sum=0,i;
    map<ll,ll>a;
    cin>>n;
   for(i=1; i<=n; i++)
   {
       cin>>a[i];

   }
   t=a[1];
   for(i=2; i<=n; i++)
   {
       if(t>a[i])
       {
           sum=sum+(t-a[i]);

       }
       else if(t<a[i])
       {
           t=a[i];
       }
   }
   cout<<sum;
}





Measured memory_bytes: 16092
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define l first
#define r second
#define int long long

using namespace std;

const int maxn = 1e6 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] acopy = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
            acopy[i] = a[i];
        }
        Arrays.sort(a);

        for(int i =0;i < n;i++){
            /*if(a[n-1] == acopy[i]){
                System.out.println(a[n-2]);
            }else{
                System.out.println(a[n-1]);
            }*/
            System.out.println(a[n-1] != acopy[i] ? a[n-1] : a[n-2]);
        }

    }
}

Measured memory_bytes: 91812
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int N;
const int maxn=2002;
int arr[maxn];
int a[maxn][maxn];
int getGreatestSum()
{
    int prev_max = 0;
    for (int j = 0; j < N; j++)
        if (prev_max < a[N - 1][j])
            prev_max = a[N - 1][j];

    // Comparing it with the elements of above rows
    cout << prev_max << endl;
    int sum = prev_max;
    for (int i = N - 2; i >= 0; i--) {

        // Maximum of current row.
        cout << prev_max << endl;
        int curr_max = INT_MIN;
        for (int j = 0; j < N; j++)
            if (prev_max > a[i][j] && a[i][j] > curr_max)
                curr_max = a[i][j];

        // If we could not an element smaller
        // than prev_max.
        if (curr_max == INT_MIN)
            return -1;

        prev_max = curr_max;
        sum += prev_max;
    }
    return sum;
}
int main() {
    int N;
    cin >> N;
    vector<pair<ll, int>> A(N);
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        A[i] = {temp, i + 1};
    }
    sort(A.rbegin(), A.rend());
   // for(int i=0;i<N;i++)cout << A[i].first << " "<< A[i].second << endl;
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int right = 0; right <= i; right++) {
            int left = i - right;
            ///cout << i << "  <<i::right>>  "<< right << " left>>  "<< left<< " :: a[i].second:: "<< A[i].second <<endl;
            dp[left + 1][right] = max(dp[left + 1][right], dp[left][right] + A[i].first * abs((left + 1) - A[i].second));
           /// cout << A[i].first*abs((left+1)-A[i].second )<< "    "<< A[i].first * abs((N-right) - A[i].second)<< endl;
            dp[left][right + 1] = max(dp[left][right + 1], dp[left][right] + A[i].first * abs((N - right) - A[i].second));
          /*  for(int i=0;i<N;i++){
                for(int j=0;j<N;j++){
                    cout << dp[i][j] << " ";
                }
                cout << endl;
            }
            cout << endl << endl;*/
        }
    }
    ll ans = 0;

    for (int i = 0; i <= N; i++) ans = max(ans, dp[i][N - i]);
    cout << ans << endl;
}
///Alhamdulillah


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

using namespace std;
using ll = long long;

const int N = 3e5 + 5;

mt19937 rnd(51515);

int a[N];

main() {
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios :: sync_with_stdio(0);
  cin.tie(0);
  ll h, n;
  cin >> h >> n;
  for (int i = 1; i <= n; ++i)
  {
    cin >> a[i];
  }
  ll sum = 0;
  for (int i = 1; i <= n; ++i)
  {
    sum += a[i];
  }
  if (sum >= h)
  {
    cout << "Yes";
  }
  else 
  {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,k;
  cin >> a >> b >> k;
  vector<int> c(0);
  for (int i=0; i<100; i++) {
    if (a%(i+1) == 0) {
      if (b%(i+1) == 0) {
        c.push_back(i+1);
      }
    }
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  cout << c[k-1] << endl;
}
        

Measured memory_bytes: 256
n=int(input())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=[[0,0]for i in range(n)]
p=0
mod=10**9+7
d=1
for i in range(n,0,-1):
    if a[i-1]!=a[i]:
        c[i-1]=[1,a[i]]
    else:
        c[i-1]=[0,a[i]]
for i in range(n):
    if b[i]!=b[i+1]:
        if c[i][0]==1:
            if b[i]!=c[i][1]:
                print(0)
                break
        else:
            if b[i]<=c[i][1]:
                c[i]=[1,b[i]]
            else:
                print(0)
                break
    else:
        if c[i][0]!=1:
            c[i]=[0,min(b[i],c[i][1])]
        else:
            if c[i][1]>b[i]:
                print(0)
                break
    if c[i][0]!=1:
        d=d*c[i][1]%mod
else:
    print(d)

Measured memory_bytes: 21608
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  string s;
  cin >> s;
  int ans = 1000;
  for(int i=0;i+2<s.size();i++){
    int a = s.at(i) - '0';
    int b = s.at(i+1) - '0';
    int c = s.at(i+2) - '0';
    int x = 100*a+10*b+c;
    ans = min(ans,abs(x-753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/* long long or int */
/* xx 396*/

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

typedef long long ll;

const int MAX_N=1e5+10;
const ll MOD=1e9+7;
const int mod=13;

string s;
int a[MAX_N],n;
ll dp[MAX_N][15];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	a[0]=1;
	for(int i=1;i<MAX_N;i++) a[i]=(a[i-1]*10)%mod;
	cin>>s;
	dp[0][0]=1; n=s.size();
	for(int i=0;i<s.size();i++){
		if(s[i]!='?'){
			int x=s[i]-'0'; x=(x*a[n-i-1])%mod;
			for(int j=0;j<13;j++){
				dp[i+1][(j+x)%mod]=(dp[i+1][(j+x)%mod]+dp[i][j])%MOD;
			}
		}
		else{
			for(int j=0;j<10;j++){
				int x=(j*a[n-i-1])%mod;
				for(int k=0;k<13;k++){
					dp[i+1][(k+x)%mod]=(dp[i+1][(k+x)%mod]+dp[i][k])%MOD;
				}
			}
		}
	}
	cout<<dp[n][5]<<endl;
	return 0;
}

Measured memory_bytes: 12624
var Main = input => {
    input = input.split("\n");
    tmp1 = input[0].split(" ");
    var N = parseInt(tmp1[0], 10);
    var D = parseInt(tmp1[1], 10);
    var X = [];
    for(var i = 0; i < N; i++) {
        X[i] = input[i + 1].split(" ");
    }

    var count = 0;
    for (var i = 0; i < N; i++) {
        for (var j = 0; j < N; j++) {
            if (i === j) {
                break;
            } else {
                var diff = [];
                var value = 0;
                for (var k = 0; k < D; k++) {
                    diff[k] = Math.pow(X[i][k] - X[j][k], 2);
                }
                value = Math.sqrt(diff.reduce((total, data) => {return total + data}));
                if (Number.isInteger(value)){count++;}
            }
        }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#pragma region
// Author: Wenxing Mei
//   Date: 2018-09-02 16:55
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define per(i, r, l) for (int i = (int)(r); i >= (int)(l); --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)
#define sf(_) scanf("%lf", &_)
#define sff(_, __) scanf("%lf%lf", &_, &__)
#define sfff(_, __, ___) scanf("%lf%lf%lf", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%lf%lf%lf%lf", &_, &__, &___, &____)
#define sl(_) scanf("%lld", &_)
#define sll(_, __) scanf("%lld%lld", &_, &__)
#define slll(_, __, ___) scanf("%lld%lld%lld", &_, &__, &___)
#define sllll(_, __, ___, ____) scanf("%lld%lld%lld%lld", &_, &__, &___, &____)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define sz(x) (int)(x).size()
#define boost                                                                                                          \
  ios_base::sync_with_stdio(0);                                                                                        \
  cin.tie(0);
#define mid(a, b) (((a) + (b)) >> 1)
#define lfg(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define all(container) container.begin(), container.end()
//#define MOD 19260817
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#pragma endregion

// Read the question correctly
// What are the exact constraints?
// Look out for SPECIAL CASES (n=1? n=1000000000?) and overflow (ull vs int?)

int main() {
  int l;
  sd(l);

  int n = log2(l) + 1;
  int m = 2 * (n - 1) + __builtin_popcount(l) - 1;

  printf("%d %d\n", n, m);

  // 1 -> 2 -> 3 -> ... -> n
  rep(i, 1, n) {
    printf("%d %d 0\n", i, i + 1);
    printf("%d %d %d\n", i, i + 1, (int)pow(2, n - i - 1));
  }

  ll p = l - pow(2, n - 1);
  int k = n - 1;
  while (p > 0) {
    int r = log2(p);
    printf("%d %d %d\n", 1, n - r, l - p);
    p -= pow(2, r);
  }

  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort()
money = 0
cnt = 0
i = 0
while cnt < m:
    if cnt + a[i][1] >= m:
        money += (m-cnt)*a[i][0]
        cnt += m-cnt
    else:
        money += a[i][0]*a[i][1]
        cnt += a[i][1]
    i += 1
print(money)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  cout << b/c - (a-1)/c +(a==0&&c!=1?1:0)<< endl;
  return 0;
}


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

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

        String[] in = br.readLine().split(" ");
        int k = Integer.parseInt(in[1]);
        char[] s = br.readLine().toCharArray();
        s[k - 1] = (char) (s[k - 1] - 'A' + 'a');
        System.out.println(String.valueOf(s));

        br.close();
    }
}

Measured memory_bytes: 21076
a,b,c=map(int,input().split())
if a==b and b==c and a==c: #全部一緒のとき
    print("1")
elif a!=b and b!=c and a!=c: #全部違うとき
    print("3")
elif a==b and b!=c:
    print("2")
elif a==c and c!=b:
    print("2")
elif c==b and a!=c:
    print("2")

Measured memory_bytes: 3060
x = int(input())

if x <= 599:
  print("8")
elif x <= 799:
  print("7")
elif x <= 999:
  print("6")
elif x <= 1199:
  print("5")
elif x <= 1399:
  print("4")
elif x <= 1599:
  print("3")
elif x <= 1799:
  print("2")
elif x <= 1999:
  print("1")
else:
  pass
    

Measured memory_bytes: 9168
# include <cstring>
# include <cstdio>
# include <iostream>
# include <queue>
# define N 100050
# define M 200050 
# define WQD 0x7f7f7f7f
int n;
int m;
struct Edge{int next,to, w;}  e[M<<1];
int head[N+1]; 
int dis[N+1];
bool vis[N+1];
bool book[ N + 1 ] ;
bool spfa(int s);
using namespace std;
int main()
{
	memset(dis,0x7f,sizeof(dis));
	memset(book,0,sizeof(book));
	ios::sync_with_stdio ( false ) ;
	int u,v,w;
	memset(head,-1,sizeof(head));
	cin>>n>>m;
	for(int i=1; i<=m; i++)
	{
		cin>>u>>v>>w;
		e[i]=(Edge){head[u],v,w};head[u]=i;
		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;
	}
	for(int i=1; i<=n; i++)
		if(!vis[i]) 
		{
			vis[i]=1;
			if(!spfa(i))  {cout<<"No";return 0;}
		}
	cout<<"Yes";
	return 0;
}
bool spfa(int s)
{
 	queue<int>q;
//	memset(book,0,sizeof(book));
//	memset(dis,0x7f,sizeof(dis));
	dis[s]=0;
	q.push(s);book[s]=1;
	while(q.size()>0)
	{
		int k=q.front();q.pop();
		book[k]=0;
		for(int i=head[k]; i!=-1; i=e[i].next)
		{
			int v=e[i].to;
			if(dis[v]==WQD ) 
			{				
				dis[v]=dis[k]+e[i].w;
				if( ! book[v])	{q.push(v);	book[v]=1;}
				vis[v]=1;
			}
			else if(  (dis[v]!=dis[k]+e[i].w) )	return false;
		}		
    }
	return true;
}

Measured memory_bytes: 6400
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int A,B,K,count=0;
  cin >> A >> B >> K;
  for(int i=A;i<=B;i++)
    if(i < A + K || B - K < i)
      cout << i << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  string s, t;
  cin >> s >> t;
  int ans = 0;
  REP(i,s.size()){
    if(s[i] != t[i]){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3816