akhauriyash/Code-Regression huggingface dataset:
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

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

        
    ll n,k;
    cin>>n>>k;

    set<ll> s;

    ll a;
    string st;
    int count = 0;
    map<ll,ll> m;
    forn(i,0,k)
    {
        cin>>a>>st;
        if(st == "AC")
        {
            s.insert(a);
        }
        else
        {
            if(s.find(a) == s.end())
            {
                m[a]++;
            }
        }
    }



    forv(i,m)
    {
        if(s.find(i.ff) != s.end())
        {
            count += i.ss;
        }
    }  
        
    cout<<s.sze<<" "<<count;    












    return 0;
}       

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>

using namespace std;

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

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

  sort(d, d + n);

  int tmp = d[0];
  int count = 1;
  for(int i = 0; i < n; i++) {
    if(tmp < d[i]) {
      tmp = d[i];
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc129/tasks/abc129_c
# 典型的なDP

MOD = 10**9 + 7
import numpy as np
# dp[i]をi段目までの通りの数とする。
N, M = list(map(int, input().split()))
to_zero = np.full((N + 1), False, dtype=bool)
for _ in range(M):
    to_zero[int(input())] = True  # 床が抜けているところ

# dpテーブルの用意
dp = np.full((N + 1), -1, dtype='int64')
dp[0] = 1
dp[1] = 0 if to_zero[1] else 1
for i in range(2, N + 1):
    dp[i] = 0 if to_zero[i] else dp[(i - 2):i].sum()
    if dp[i] > MOD:
        dp[i] %= MOD

print(dp[-1])


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

void SME(int a,int b,int c);

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    SME(a,b,c);
    return 0;
}

void SME(int a,int b,int c){
    if(a<b && b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3096
#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <vector>
 #include <iostream>
using namespace std;

int top;
vector<int> S(1000);

void push(int x){
    top++;
    S.at(top)=x;
    return;
}

int pop(){
    top--;
    return S.at(top+1);
}

int main() {
    
    top=0;
    int a=0,b=0;
    vector<string> c(5);
    
    while(cin>>c.at(0)){
        if(c.at(0)=="+"){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(c.at(0)=="-"){
            a=pop();
            b=pop();
            push(b-a);
        }
        else if(c.at(0)=="*"){
            a=pop();
            b=pop();
            push(a*b);
        }
        else{
            push(stoi(c.at(0)));
        }
    }
    cout<<pop()<<endl;
    
}




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

int main(){
    int n; cin >> n;
    vector<int> h(n);
 
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
 
    //dp[i] gives the minimum possible cost to reach ith stone
    //Initialize dp[i] with infinity for all i
    vector<int> dp(n, INT_MAX);
    
    //Base Cases
    //To reach 0th stone we dont need to jump from any cells so total cost is 0
    //To reach 1st stone we can jump from 0th cell with total cost = abs(h[1] - h[0])
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
 
    //Iterate from 2 to (n -1)th stone in a bottom up manner
    for(int i = 2; i < n; i++){
       
       //ith stone can be reached either from (i - 1)th stone or (i - 2)th stone
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                    dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    
    //Print cost to reach (n -1)th stone
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define EPS (1e-8)
using namespace std;
typedef complex<double> P;

struct Circle{
  P c; //中心点
  double r; //半径
  Circle(P c=P(0,0), double r=0):c(c),r(r){}
};

int IntersectionCC(Circle a,Circle b){
  int res=0;
  double dis=abs(a.c-b.c),R=a.r+b.r;
  if(dis>R+EPS)res++;
  if(dis>R-EPS)res++;
  if(dis>abs(a.r-b.r)+EPS)res++;
  if(dis>abs(a.r-b.r)-EPS)res++;
  return res;
}

int main(){
  int a,b;
  Circle c[2];
  for(int i=0;i<2;i++){
    cin>>a>>b>>c[i].r;
    c[i].c=P(a,b);
  }
  cout<<IntersectionCC(c[0],c[1])<<endl;
  return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
            double[] input = Input.InputMultipleNum();
            double W = input[0], H = input[1], x = input[2], y = input[3];
            double maxS = W * H/2;
            int b;
            if (2*x == W && 2*y == H) b = 1; else b = 0;
            Console.WriteLine($"{maxS} {b}");
        }

    }

    static class Input
    {
        static public double[] InputMultipleNum() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }

    }
}


Measured memory_bytes: 13396
#include<stdio.h>

int main(void){
	int n,i;
	char y[10] = {};
	float x[10] = {},sum=0;
	scanf("%d",&n);
	for (i = 0; n > i; i++) {
		scanf("%f %s", &x[i], &y[i]);
	}
	for (i = 0; i < n; i++) {
		if (y[i] == 'B')
			sum = x[i] * 380000.0 + sum;
		else
			sum = sum + x[i];
	}
	printf("%f\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 998244353
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u % m;
}

long long powMod(long long x, long long n, long long m) {
    long long res = 1;
    while (n > 0) {
        if ((n & 1) == 1) res = res * x % m;
        x = x * x % m;
        n >>= 1;
    }
    return res;
}

int main() {

    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> dp(S + 1, 0);
    dp[0] = 1;
    rep(i,N) {
        for (int j = S; j >= 0; j--) {
            if (j - A[i] >= 0) {
                dp[j] += dp[j - A[i]] * modinv(2, MOD);
                dp[j] %= MOD;
            }
        }
    }

    cout << dp[S] * powMod(2, N, MOD) % MOD << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll A,V,B,W,T;
  cin >> A >> V >> B >> W >> T;
  if(W < V && (V-W) * T >=  abs(A - B)) cout << "YES" << endl;
  else cout << "NO" << endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

bool visited[120][120];
char field[120][120];

int main(){
    int h,w,i;

    while( cin >> h >> w, h|w ){
        // init
        memset(visited, false, sizeof(visited));

        // input
        rep(i,h) cin >> field[i];

        int x = 0, y = 0;
        visited[y][x] = true;
        while( true ){
            switch( field[y][x] ){
            case '>': x++; break;
            case '<': x--; break;
            case '^': y--; break;
            case 'v': y++; break;
            default: break;
            }
            if( field[y][x] == '.' ){
                printf("%d %d\n",x,y);
                break;
            }
            if( visited[y][x] ){
                puts("LOOP");
                break;
            }
            visited[y][x] = true;
        }
    }

    return 0;
}

Measured memory_bytes: 0
const input=require("fs").readFileSync("/dev/stdin","utf8"),lines=input.trim().split("\n");for(;line=lines.shift();){const[i,e]=line.split(" ").map(Number);if(0===i&&0===e)break;const t=lines.shift().split(" ").map(Number);let n=0;for(let s=0;s<=i;s++)for(let l=0;l<=i;l++){if(!t[s]||!t[l]||s===l)continue;const i=t[s]+t[l];i<=e&&i>n&&(n=i)}console.log(`${n||"NONE"}`)}


Measured memory_bytes: 18268
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect

def main():
    N = II()
    A = LI()
    A.sort()
    zero = 1 + bisect(A[1:-1], 0)
    ans = sum(A[zero:]) - sum(A[:zero])
    print(ans)
    x = A[0]
    for i in A[zero:-1]:
        print(x, i)
        x -= i
    y = A[-1]
    print(y, x)
    y -= x
    for i in A[1:zero]:
        print(y, i)
        y -= i
    return

main()

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

int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> W(100001);
  for (int i = 0, a ,b; i < N && cin >> a >> b; i++) W.at(a).push_back(b);

  int ans = 0;

  priority_queue<int> Q;
  for (int i = 1; i <= M; i++) {
    for (int j = 0; j < W.at(i).size(); j++) Q.push(W.at(i).at(j));
    if (Q.size()) ans += Q.top(), Q.pop();
  }

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

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int x,a,b;
cin>>x>>a>>b;
cout<<(x-a)%b<<endl;
//system("pause");
return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int n, k;
	cin >> n >> k;

	bool a[n+1] = {0};
	int d, ip;

	for (int i = 0; i < k; i++) {
		cin >> d;
		for (int j = 0; j < d; j++) {
			cin >> ip;
			a[ip] = true;
		}
	}

	int c = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == 0)
			c++;

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  map<int, int> mp;
  for(int i=0; i<n; i++){
    mp[a[i]] = 0;
  }
  sort(a.begin(), a.end());
  for(int i=0; i<n; i++){
    mp[a[i]]++;
  }
  int ans = 0;
  for(int i=0; i<n; i++){
    if(mp[a[i]]>=a[i]){
      ans += mp[a[i]] - a[i];
      mp.erase(a[i]);
    }
    else{
      ans += mp[a[i]];
      mp.erase(a[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> //std::priority_queue<int> que; // 4, 3, 2, 1 (defualt, less) : 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;


int main (void) {
  int N; 
  std::cin >> N;
  std::vector<int> C,S,F;
  C.resize(N);  S.resize(N);  F.resize(N);
  for(int i=0; i<N-1; i++) std::cin >> C[i] >> S[i] >> F[i];

  for(int i=0; i<N; i++) {
    int t = 0;
    for(int j=i; j<N-1; j++) {
      if ( t<S[j] ) t = S[j];
      else if ( t % F[j] == 0 ) ;
      else t += F[j] - t%F[j];
      t += C[j];
    }
    std::cout << t << std::endl;
  }
  return 0;
}


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

public class Main {
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int X = fs.nextInt();
    while (!isPrime(X)) X++;
    System.out.println(X); 
  }

  public static boolean isPrime(int n) {
    if(n < 2) return false;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(int i = 3; i * i <= n; i += 2) {
      if(n % i == 0) return false;
    }
    return true;
  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
    return buffer[ptr++];
    else
    return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
    ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
    throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
    throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
      throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
    throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 21460
fn main() {
    let n:usize = read();
    println!("{}", n * 800 - n / 15 * 200);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let s: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().unwrap()
}


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

int main () {
    string str; cin >> str;
    string std = "hi";
    bool flag = true;
    if (str.size () & 1) {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < str.size () ; i += 2) {
        if (str[i] != std[0] || str[i + 1] != std[1])
            flag = false;
    }
    if (flag)
        cout << "Yes";
    else 
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define endl '\n'

using namespace std;

void solve()
{
    long long n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    long long answer = 1000000000000000000LL;

    typedef pair<long long, long long> state;
    priority_queue<state, vector<state>, greater<state>> pq;
    map<long long, long long> visited;

    pq.push({0, n});
    visited[n] = 0;

    auto check = [&](long long num, long long cost) {
        if (cost > answer)
        {
            return;
        }

        auto it = visited.lower_bound(num);

        if (it == visited.end() || it->first != num || cost < it->second)
        {
            visited[num] = cost;
            pq.push({cost, num});
        }
    };

    while (!pq.empty())
    {
        long long cost, num;
        tie(cost, num) = pq.top();
        pq.pop();

        if (num <= (answer - cost) / d)
        {
            answer = min(answer, d * num + cost);
        }

        auto r2 = num % 2, r3 = num % 3, r5 = num % 5;

        if (r2 || r3 || r5)
        {
            check(num - 1, cost + d);
            check(num + 1, cost + d);
        }

        if (r2 == 0)
        {
            check(num / 2, cost + a);
        }

        if (r3 == 0)
        {
            check(num / 3, cost + b);
        }

        if (r5 == 0)
        {
            check(num / 5, cost + c);
        }
    }

    cout << answer << endl;
}

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

    int t;
    cin >> t;

    for (int i = 0; i < t; ++i)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7768
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll a, b, k;
    cin >> a >> b >> k;
    if(a >= k){
        a -= k;
        cout << a << " " << b << "\n";
        return;
    }
    k -= a;
    a = 0;
    if(b >= k){
        b -= k;
        cout << a << " " << b << "\n";
        return;
    }
    cout << 0 << " " << 0 << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int k=s.nextInt();
		
		ArrayList<Long> list=new ArrayList<>();
		
		for(long i=0;i<10;i++)
		{
			list.add(i);
		}
		
		int curr=1;
		
		for(long i=10;i<100010;i++)
		{
			if(list.get(curr)%10==0)
			{
				long val1=list.get(curr)*10+0;
				long val2=list.get(curr)*10+1;
				
				list.add(val1);
				list.add(val2);
				
				curr++;
			}
			else if(list.get(curr)%10==1)
			{
				long val1=list.get(curr)*10+0;
				long val2=list.get(curr)*10+1;
				long val3=list.get(curr)*10+2;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==2)
			{
				long val1=list.get(curr)*10+1;
				long val2=list.get(curr)*10+2;
				long val3=list.get(curr)*10+3;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==3)
			{
				long val1=list.get(curr)*10+2;
				long val2=list.get(curr)*10+3;
				long val3=list.get(curr)*10+4;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==4)
			{
				long val1=list.get(curr)*10+3;
				long val2=list.get(curr)*10+4;
				long val3=list.get(curr)*10+5;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==5)
			{
				long val1=list.get(curr)*10+4;
				long val2=list.get(curr)*10+5;
				long val3=list.get(curr)*10+6;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==6)
			{
				long val1=list.get(curr)*10+5;
				long val2=list.get(curr)*10+6;
				long val3=list.get(curr)*10+7;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==7)
			{
				long val1=list.get(curr)*10+6;
				long val2=list.get(curr)*10+7;
				long val3=list.get(curr)*10+8;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==8)
			{
				long val1=list.get(curr)*10+7;
				long val2=list.get(curr)*10+8;
				long val3=list.get(curr)*10+9;
				
				list.add(val1);
				list.add(val2);
				list.add(val3);
				
				curr++;
			}
			else if(list.get(curr)%10==9)
			{
				long val1=list.get(curr)*10+8;
				long val2=list.get(curr)*10+9;
				
				list.add(val1);
				list.add(val2);
				
				curr++;
			}
		}
		
		System.out.println(list.get(k));
		
	}
	
}

Measured memory_bytes: 40660
#include<iostream>

using namespace std;
int main()
{
    int n,a,b,sum=0,total=0;
    
    cin>>n>>a>>b;
    
    for(int i=1;i<=n;i++)
	{
        int p=i; 
        sum=0;
        while(p!=0)
		{
            sum+=p%10;
            p/=10;
        }
        if(sum>=a&sum<=b)total+=i;
    }
    
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))

Measured memory_bytes: 7028
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int dx4[4] = { 0, -1, 1, 0 };
const int dy4[4] = { -1, 0, 0, 1 };
const int dx5[5] = { 0, -1, 0, 1, 0 };
const int dy5[5] = { -1, 0, 0, 0, 1 };
const int dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int i = 0; i < K; ++i)
#define REPYX() for (int y = 0; y < H; ++y) for (int x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)


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

    uint64_t N;
    cin >> N;

    uint64_t count = 0;
    auto find_zs = [&](uint64_t factors) {
        uint64_t p_count = 0;
        uint64_t found = 1;
        for (; p_count + found <= factors; ++found) {
            p_count += found;
        }
        return found - 1;
    };
    auto process_p = [&](uint64_t p) {
        uint64_t factors = 0;
        while (N % p == 0) {
            N /= p;
            ++factors;
        }
        count += find_zs(factors);
    };
    //REP(i, 50) { cout << i << " : " << find_zs(i) << endl; }

    // 2, 3, 5, 7, 9, .. sqrt(N)
    const uint64_t pmax = sqrt(N + 1);

    process_p(2);
    for (uint64_t p = 3; p <= pmax && p <= N; p+=2) {
        process_p(p);
    }
    if (N != 1) process_p(N);

    cout << count << endl;


    return 0;
}



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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

void Test(int n,string res,string s){
	FOR(i,1,n-1){
		if(res[i]=='S'){
			if(s[i]=='o')
				res[i+1]=res[i-1];
			else
				res[i+1]=res[i-1]=='S'?'W':'S';
		}else{
			if(s[i]=='x')
				res[i+1]=res[i-1];
			else
				res[i+1]=res[i-1]=='S'?'W':'S';
		}
	}
	if(res[0]=='S'){
		if(s[0]=='o'&&res[1]!=res[n-1])
			return;
		if(s[0]=='x'&&res[1]==res[n-1])
			return;
	}else{
		if(s[0]=='x'&&res[1]!=res[n-1])
			return;
		if(s[0]=='o'&&res[1]==res[n-1])
			return;
	}
	if(res[n-1]=='S'){
		if(s[n-1]=='o'&&res[0]!=res[n-2])
			return;
		if(s[n-1]=='x'&&res[0]==res[n-2])
			return;
	}else{
		if(s[n-1]=='x'&&res[0]!=res[n-2])
			return;
		if(s[n-1]=='o'&&res[0]==res[n-2])
			return;
	}
	cout<<res<<endl;
	exit(0);
}

signed main(){
	int n=read();
	string s=readString();
	{
		string res(n,'$');
		res[0]='S';
		res[1]='S';
		Test(n,res,s);
	}
	{
		string res(n,'$');
		res[0]='S';
		res[1]='W';
		Test(n,res,s);
	}
	{
		string res(n,'$');
		res[0]='W';
		res[1]='S';
		Test(n,res,s);
	}
	{
		string res(n,'$');
		res[0]='W';
		res[1]='W';
		Test(n,res,s);
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 2824
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
  /// Return `true` if the slice was permuted, `false` if it is already
  /// at the last ordered permutation.
  fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
  /// Original author in Rust: Thomas Backman <serenity@exscape.org>
  fn next_permutation(&mut self) -> bool {
    // These cases only have 1 permutation each, so we can't do anything.
    if self.len() < 2 { return false; }

    // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
    let mut i = self.len() - 1;
    while i > 0 && self[i-1] >= self[i] {
      i -= 1;
    }

    // If that is the entire vector, this is the last-ordered permutation.
    if i == 0 {
      return false;
    }

    // Step 2: Find the rightmost element larger than the pivot (i-1)
    let mut j = self.len() - 1;
    while j >= i && self[j] <= self[i-1]  {
      j -= 1;
    }

    // Step 3: Swap that element with the pivot
    self.swap(j, i-1);

    // Step 4: Reverse the (previously) weakly decreasing part
    self[i..].reverse();

    true
  }
}
fn main() {
  let s: String = read();
  let mut hash = HashMap::new();
  for i in s.chars() {
    let count = hash.entry(i).or_insert(0);
    *count += 1;
  }
  if hash.len() != 2 { println!("No"); }
  else {
    for (_, v) in hash {
      if v != 2 {
        println!("No");
        return;
      }
    }
    println!("Yes");
  }
}

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

int main() {
    long long n, h, w, a, b, cnt = 0;
    cin >> n >> h >> w;

    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        if (a >= h && b >= w) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int sx, sy, tx, ty, i, j, k;
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    for (i = sy; i < ty; i++) { //first path
        putchar('U');
    }
    for (i = sx; i < tx; i++) {
        putchar('R');
    }
    for (i = ty; i > sy; i--) { //second path
        putchar('D');
    }
    for (i = tx; i > sx; i--) {
        putchar('L');
    }
    putchar('L');                //third path
    for (i = sy; i < ty + 1; i++) {
        putchar('U');
    }
    for (i = sx - 1; i < tx; i++) {
        putchar('R');
    }
    putchar('D');
    putchar('R');               //fourth path
    for (i = ty; i > sy - 1; i--) {
        putchar('D');
    }
    for (i = tx + 1; i > sx; i--) {
        putchar('L');
    }
    putchar('U');
    putchar('\n');
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a == b)
        cout << "a == b" << endl;
    else if(a < b)
        cout << "a < b" << endl;
    else
        cout << "a > b" << endl;
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin>>s>>t;
    int sLen = s.size();
    int tLen = t.size();
    int ans = INT_MAX;
    for(int i=0;i<sLen; i++) {
        if(i+tLen <= sLen) {
            string temps = s.substr(i, tLen);
            int tempAns = 0;
            for(int j=0;j<temps.size();j++) {
                if(temps[j] != t[j]) tempAns++;
            }
            ans = min(ans, tempAns);
        } else {
            break;
        }
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m;
    cin>>n>>m;
    int a[m];
    rep(i,m)cin>>a[i];
    sort(a,a+m);
    int b[m-1];
    rep(i,m-1)b[i]=a[i+1]-a[i];
    sort(b,b+m-1);
    int ans=0;
    rep(i,max(0,m-n))ans+=b[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n,d;
  while(cin>>n>>d,n||d) {
    stack<int> stk[n];
    int sum[n];
    REP(i,n)sum[i]=0;
    REP(i,n) {
      int m;
      cin >> m;
      REP(j,m) {
        int a; cin >> a;
        stk[i].push(a);
        sum[i] += a;
      }
    }
    bool ok = 0;
    while(1) {
      int ma = 0;
      int ma2 = 0;
      int id = -1;
      int mi = INF;
      REP(i,n) {
        if (sum[i]>ma) {
          ma2=ma;
          ma=sum[i],id=i;
        } else if (sum[i]>ma2) {
          ma2 = sum[i];
        }
        mi = min(mi,sum[i]);
      }
      if (ma-mi > d) break;
      if (id == -1) {
        ok = 1;
        break;
      }
      bool f = 0;
      REP(i,n) {
        if (stk[i].size()==0) continue;
        if (i==id) {
          if (ma2-(sum[i]-stk[i].top())>d) continue;
        } else {
          if (ma-(sum[i]-stk[i].top())>d) continue;
        }
        sum[i]-=stk[i].top();
        stk[i].pop();
        f = 1;
        break;
      }
      // REP(i,n) cout << (stk[i].size()?stk[i].top():-1) << " ";
      // cout << endl;
      // REP(i,n) cout << sum[i] << ":";
      // cout << endl;
      if (!f) break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 952
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)/b;
}

int main(void){
    ll n,a,b;
    cin >> n >> a >> b;

    if(a>b){
        cout<<0;
        return 0;
    }
    else if(a!=b&&n==1){
        cout<<0;
        return 0;
    }
    ll min=a*(n-1)+b;
    ll max=a+b*(n-1);
    cout<<max-min+1;
}
/*

*/


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <stdlib.h>
#include <ctime>
#include <cmath>
#include <complex>
#include <iostream>
#include <cctype>
#include <cstring>
#include <bitset>
#include <stack>
#include <functional>
#include <cassert>
#include <tuple>
#include <iomanip>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ldb long double
#define mt make_tuple
template<typename T> bool ckmn(T &a, T b){ T c=a;a=min(a,b);return a!=c;}
template<typename T> bool ckmx(T &a, T b){ T c=a;a=max(a,b);return a!=c;}

int main()
{
	ll n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	ll dif=b-a;
	if(dif%2==0) printf("%lld\n",dif/2);
	else
	{
		printf("%lld\n",min(n-b,a-1)+1+(dif-1)/2);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long int LL;
 
int main(){
  LL X, Y;
  cin >> X >> Y;
  int ret = 0;
  while(X <= Y) {
    ++ret;
    X *= 2;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define mod  1000000007LL
#define PI 2*acos(0.0)


int main()
{
    io;
    int n;
    cin>>n;
    vi pos(n);
    for(int i = 0; i< n;i++)
    {
        int x;
        cin>>x;
        pos[--x] = i;
    }
    int ans = 1, sor = 1;
    for(int i = 1; i<n; i++)
    {
        if(pos[i] > pos[i-1])
            sor++;
        else
            sor = 1;
        ans = max(ans, sor);
    }
    cout<<n - ans;
    return 0;
}

Measured memory_bytes: 4044
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x=new int[2];
		int[] y=new int[2];
		for(int i=0;i<2;i++){
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
		}
		int xdif=x[1]-x[0];
		int ydif=y[1]-y[0];
		StringBuilder ans=new StringBuilder();
		for(int i=0;i<xdif;i++){
			ans.append("R");
		}
		for(int i=0;i<ydif;i++){
			ans.append("U");
		}
		for(int i=0;i<xdif;i++){
			ans.append("L");
		}
		for(int i=0;i<ydif;i++){
			ans.append("D");
		}
		ans.append("D");
		for(int i=0;i<xdif+1;i++){
			ans.append("R");
		}
		for(int i=0;i<ydif+1;i++){
			ans.append("U");
		}
		ans.append("LU");
		for(int i=0;i<xdif+1;i++){
			ans.append("L");
		}
		for(int i=0;i<ydif+1;i++){
			ans.append("D");
		}
		ans.append("R");
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		sa = br.readLine().split(" ");
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		a[n] = a[0];
		sa = br.readLine().split(" ");
		int[] b = new int[n + 1];
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		b[n] = b[0];
		br.close();

		int[] ax = new int[n * 2 - 1];
		int[] bx = new int[n];
		for (int i = 0; i < n; i++) {
			ax[i] = a[i] ^ a[i + 1];
			bx[i] = b[i] ^ b[i + 1];
		}
		System.arraycopy(ax, 0, ax, n, n - 1);

		MP mp = new MP(bx);
		List<Integer> list = mp.findAllFrom(ax);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i : list) {
			pw.println(i + " " + (a[i] ^ b[0]));
		}
		pw.flush();
	}

	static class MP {
		int n;
		int[] arr;
		int[] a;

		public MP(int[] arr1) {
			arr = arr1;
			n = arr.length;
			a = new int[n + 1];
			a[0] = -1;
			int j = -1;
			for (int i = 0; i < n; i++) {
				while (j >= 0 && arr[i] != arr[j]) {
					j = a[j];
				}
				j++;
				a[i + 1] = j;
			}
		}

		List<Integer> findAllFrom(int[] arr2) {
			List<Integer> ret = new ArrayList<>();
			int j = 0;
			for (int i = 0; i < arr2.length; i++) {
				while (j >= 0 && arr2[i] != arr[j]) {
					j = a[j];
				}
				j++;
				if (j == n) {
					ret.add(i - j + 1);
					j = a[j];
				}
			}
			return ret;
		}
	}
}


Measured memory_bytes: 86856
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

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

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6988
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 998244353;

struct cell{
  int no;
  ll year;
};
bool operator<(const cell& left, const cell& right){
  return left.year < right.year;
}
bool operator>(const cell& left, const cell& right){
  return left.year > right.year;
}

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

int main()
{
  char c[3];
  cin >> c[0] >> c[1] >> c[2];
  for(int i=0;i<3;i++){
    if(c[i] == '1') cout << '9';
    else if(c[i] == '9') cout << '1';
    else cout << c[i];
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int target[3];
  int countF = 0;
  int countS = 0;
  scanf("%d %d %d", &target[0], &target[1], &target[2]);
  
  for (int i = 0; i < 3; i++) {
    if (target[i] == 5) countF++;
    else if (target[i] == 7) countS++;
  }
  if (countF == 2 && countS == 1) printf("YES\n");
  else printf("NO\n");

  return 0;
}


Measured memory_bytes: 256
line = gets.chomp.split(" ").map(&:to_i)
n = line[0]

max = [0, 0]
max_pos = [0, 0]
num_arr = []
n.times do |i|
    number = gets.chomp.to_i
    num_arr.push(number)
    if max[0] < number
        max[1] = max[0]
        max_pos[1] = max_pos[0]
        max[0] = number
        max_pos[0] = i
    elsif max[1] < number
        max[1] = number
        max_pos[1] = i
    end
end

n.times do |i|
    if max_pos[0] == i
        puts max[1]
    else
        puts max[0]
    end
end


Measured memory_bytes: 4860
#include<stdio.h>
 
int main()
{
int a, b;
scanf("%d %d", &a, &b);
while(a || b)
{
if (a < b)
printf("%d %d\n", a, b);
else
printf("%d %d\n", b, a);
scanf("%d %d", &a, &b);
}
 
return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (1LL << 31) - 1LL;

struct SegmentTree {
private:
    int n;
    vector<ll> node;
public:
    SegmentTree(vector<ll>& v) {
        int size = v.size();
        n = 1;
        while (n < size) n *= 2;
        node.resize(2 * n - 1, INF);

        for (int i = 0; i < size; i++) {
            node.at(i + n - 1) = v.at(i);
        }
        for (int i = n - 2; i >= 0; i--) {
            node.at(i) = min(node.at(2 * i + 1), node.at(2 * i + 2));
        }
    }

    void update(int idx, int val) {
        int node_idx = idx + n - 1;
        node.at(node_idx) = val;
        int current_idx = node_idx;
        while (current_idx) {
            current_idx = (current_idx - 1) / 2;
            node.at(current_idx) = min(node.at(2 * current_idx + 1), node.at(2 * current_idx + 2));
        }
    }

    ll get_min(int query_left, int query_right, int cur_idx=0, int cur_left=0, int cur_right=-1) {
        if (cur_right < 0) cur_right = n;
        if (cur_right <= query_left || query_right <= cur_left) return INF;
        if (query_left <= cur_left && cur_right <= query_right) return node.at(cur_idx);
        ll val_from_left = get_min(query_left, query_right, 2 * cur_idx + 1, cur_left, (cur_left + cur_right) / 2);
        ll val_from_right = get_min(query_left, query_right, 2 * cur_idx + 2, (cur_left + cur_right) / 2, cur_right);
        return min(val_from_left, val_from_right);
    }
};


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

    int n, q;
    cin >> n >> q;
    vector<ll> a_list(n, INF);
    SegmentTree segtree = SegmentTree(a_list);
    for (int i = 0; i < q; i++) {
        int op, x, y;
        cin >> op >> x >> y;
        if (op == 0) {
            segtree.update(x, y);
        }
        else {
            cout << segtree.get_min(x, y + 1) << "\n";
        }
    }
}



Measured memory_bytes: 5736
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    if(x>= 400 && x <= 599)
        cout<<"8"<<endl;
    else if(x>= 600 && x <= 799)
        cout<<"7"<<endl;
    else if(x>= 800 && x <= 999)
        cout<<"6"<<endl;
    else if(x>= 1000 && x <= 1199)
        cout<<"5"<<endl;
    else if(x>= 1200 && x <= 1399)
        cout<<"4"<<endl;
    else if(x>= 1400 && x <= 1599)
        cout<<"3"<<endl;
    else if(x>= 1600 && x <= 1799)
        cout<<"2"<<endl;
    else if(x>= 1800 && x <= 1999)
        cout<<"1"<<endl;

    return 0;
}


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

using namespace std;

int a[100001];

int main() {
    int n, m = numeric_limits<int>::max();
    cin >> n;
    long answer = 0;
    int negative = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] < 0) ++negative;
        m = min(m, abs(a[i]));
        answer += abs(a[i]);
    }
    if (negative % 2 == 1) answer -= 2 * m;
    cout << answer << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <set>
#include <iterator>
using namespace std;



int main() {
    int n;
    string input;
    set<string> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> input;
        s.insert(input);
    }
    cout << s.size();
    return 0;
}

Measured memory_bytes: 15728
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n;
int a[200005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int mx=0;
    ll ans=0;
    for(int i=1;i<=n;i++)
        if(mx<=a[i])
            mx=a[i];
        else
            ans+=mx-a[i];
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b, m, s;
    cin >> a >> b;

    m = a * b;
    s = a + a + b + b;

    cout << m << " " << s << endl;
}


Measured memory_bytes: 3092
import math

N=int(input())
result=0
if N==1:
    print(0)
else:
    for i in range(1,int(math.sqrt(N))+1):
        if N%i==0:
            if i>1 and N%(i-1)==N//(i-1):
                result+=i-1
            if N%i!=N//i:
                if N%(N//i-1)==N//(N//i-1):
                    result+=N//i-1
    print(result)

Measured memory_bytes: 3064