akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(){
  char c[1101];
  int i=0,ans=0,b=1;
  do{
    for(i=0; i<1100; i++){
      scanf("%c",&c[i]);
      if(i==0&&c[0]=='0'){
        b=0;
        break;
      }
      if(c[i]=='\n')break;
      ans+=(c[i]-'0');
    }
    if(b)printf("%d\n",ans);
    ans=0;
  }while(b);
  return 0;
}


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

#define MAX 20000

int top1 = 0,top2 = 0,top3 = 0;
int S1[MAX];
int S2[MAX];
int S3[MAX];

void push1(int x){
	top1++;
	S1[top1] = x;
}

int pop1(){
  int x;
  x = S1[top1];
	top1--;
	return x;
}

void push2( int x ){
	top2++;
	S2[top2] = x;
}

int pop2(){
  int x;
  x = S2[top2];
	top2--;
	return x;
}

void push3( int x ){
	top3++;
	S3[top3] = x;
}

int pop3(){
  int x;
  x = S3[top3];
	top3--;
	return x;
}

int main( void ){

	int i = 0;
	int j;
	char S[MAX];
	int total = 0;
	int ans = 0;

	scanf("%s",S);

	while(S[i] == '\\' || S[i] == '/' || S[i] == '_' ){
		if(S[i] == '\\'){
			push1(i);
		}else if((S[i] == '/') && (top1 != 0)){
			j = pop1();
			total = i - j;
			ans += total;

			while((top2 != 0) && (j <= S2[top2])){
        pop2();
				total += pop3();
			}
			push2(j);
			push3(total);
		}
		i++;
	}

	printf("%d\n", ans );
	printf("%d", top3 );

	for(i = 1; top3 != 0; i++){
		pop3();
		printf(" %d" , S3[i]);

	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
 
const ll Inf = 1e18;

ll mul(ll a, ll b) {
  if (a > Inf / b) return Inf;
  return min(Inf, a * b);
}

ll smart(ll n, ll a) {
  ll ans = Inf;
  for (int cnt = 0; cnt <= 50; ++cnt) {
    int have = cnt + 1;
    ll l = cnt, r = 1e18;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll rs = 1;
      for (int i = 0; i < have; ++i) {
        ll cur = m / have + (m % have > i);
        rs = mul(rs, cur);
      }
      if (rs >= n) r = m;
      else l = m;
    }
    ans = min(ans, r + cnt * a);
  }
  return ans;
}

ll stupid(ll n, ll a) {
  vector <ll> dp(n + 1, Inf);
  dp[1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + i; j <= n; j += i) {
      dp[j] = min(dp[j], dp[i] + j / i + a);
    }
  }
  ll ans = Inf;
  for (int i = 1; i <= n; ++i) {
    ans = min(ans, dp[i] + (n + i - 1) / i);
  }
  return ans;
}
 
void stress() {
  for (int i = 0; i < 50; ++i) {
    ll n = rand() % 10 + 1, a = rand() % 10 + 1;
    ll sm, st;
    if ((sm = smart(n, a)) != (st = stupid(n, a))) {
      cout << n << ' ' << a << '\n';
      cout << sm << ' ' << st << '\n';
      exit(0);
    }
  }
}


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  //stress();
  ll n, a;
  cin >> n >> a;
  cout << smart(n, a) << '\n';
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    pre = None
    X = []
    for s in S:
        if s != pre:
            X.append(s)

        pre = s
    
    print(len(X))






if __name__ == "__main__":
    main()

Measured memory_bytes: 75220
#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <map>
using namespace std;

typedef long long ll;
struct Point{ ll x, y; };
map<pair<ll, ll>, bool> poi;
map<pair<ll, ll>, bool> flg;

ll h, w, n;
struct Point p[100005];
ll ans[10];

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

int main()
{
    scanf("%lld %lld %lld", &h, &w, &n);

    for (ll i = 0; i < n; i++) {
        scanf("%lld %lld", &p[i].y, &p[i].x);
        poi[make_pair(p[i].y, p[i].x)] = true;
    }
    ans[0] = (h - 2) * (w - 2);
    
    for (ll i = 0; i < n; i++) {
        struct Point a = p[i];

        for (ll s = 0; s < 9; s++) {
            ll cnt = 0;
            ll ox = a.x + dx[s];
            ll oy = a.y + dy[s];

            if (ox - 1 < 1 || oy - 1 < 1) continue;
            if (ox + 1 > w || oy + 1 > h) continue;
            if (flg.count(make_pair(ox, oy))) continue;
            flg[make_pair(ox, oy)] = true;

            //            puts("------");
            for (ll j = 0; j < 9; j++) {
                ll x = ox + dx[j];
                ll y = oy + dy[j];

                if (poi.count(make_pair(y, x))) {
                    //      printf("(%lld, %lld)\n", y, x);
                    cnt++;
                }
            }
            //            puts("------");
            ans[cnt]++;
            ans[0]--;
        }
    }
    
    for (int i = 0; i < 10; i++) {
        printf("%lld\n", ans[i]);
    }
    
    return 0;
}


Measured memory_bytes: 64256
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n;
	char x, y;
	cin >>x>>y;
	if ((x - y) > 0) cout << ">" << endl;
	else if ((x - y) < 0) cout << "<" << endl;
	else cout << "=" << endl;
	return 0;
} 

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

typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;cin>>n;
    vi a(n+1),b(n);
    long long s=0;
    for (int i = 0; i <= n; ++i) {
        cin>>a[i];
        s += a[i];
    }
    for(int i=0;i<n;++i){
        int b;cin>>b;
        if (b>a[i]){
            a[i+1] -= b-a[i];
            a[i+1] = max(0,a[i+1]);
            a[i]=0;
        }else{
            a[i] -= b;
        }
    }
    long long s2=0;
    for(int i=0;i<=n;++i) s2 += a[i];

    cout << s-s2;

}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	string prediction;
  	string actual;
  	int count = 0;
  	cin>>prediction;
  	cin>>actual;
  	for(int i = 0; i < 3; i++){
    	if(prediction[i] == actual[i])count+=1;
    }
  	cout<<count<<"\n";
  return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m){
    cin >> a.at(i);
  }
  int sum = 0;

  rep(i,m) {
    sum += a.at(i);
  }
  
  if (sum > n) {
  cout << -1;
  }
  else {
  cout << n - sum;
  }
}

Measured memory_bytes: 3628
def main():

    N = int(input())
    A = list(map(int, input().split()))
    d = dict()
    for i in range(len(A)):
        d[A[i]] = d.get(A[i], 0) + 1
    for i in range(1, len(A)+2):
        if i in d:
            print(d[i])
        else:
            print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 33540
#include<iostream>

using namespace std;
long long sum(int n){
    if(n==1) return 1;
    if(n==2) return 2;
    return n*sum(n-1);
  
    }
    
    int main(){
        int n;
        cin>>n;
        cout<<sum(n)<<endl; 
        
        return 0;
    }

Measured memory_bytes: 1156
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()
}

fn main() {
    let nk:Vec<i64> = read_vec();
    let mut v :Vec<(i64,i64)> = Vec::new();
    for _ in 0..nk[0] {
        let r:Vec<i64> = read_vec();
        v.push((r[0],r[1]));
    }
    v.sort();
    let mut key = nk[1];
    let mut ans = 0;
    for (a,b) in v{
        key -= b;
        if key <= 0{
           ans =  a;
            break;
        }
    };
    println!("{}",ans);
}

Measured memory_bytes: 6396
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        ArrayList<String> list= new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.next());
        }
        Collections.sort(list);
        for (String ss : list) {
            System.out.print(ss);
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
	for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
		<< " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
	<< " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

// bool sortbysec(const pair<int,int> &a,
//               const pair<int,int> &b)
// {
//     return !(a.first < b.first);
// }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception


const int MAX_N = 1005;
 
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='9'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	string S, T, ans="No";
	cin >> S >> T;
	REP(i, 0, (int)S.size()){
		if(S == T){
			ans = "Yes";
			break;
		}
		reverse(S.begin(), S.end()-1);
		reverse(S.begin(), S.end());
	}
	cout << ans;

}


Measured memory_bytes: 256
/*
 * Click `Run` to execute the snippet below!
 */

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), M = sc.nextInt();
    int arr[] = new int[M];
    for(int i = 0; i<M; i++){
      arr[i] = sc.nextInt(); 
    }
    Arrays.sort(arr);
    int dif[] = new int[M-1];
    for(int i = 0; i<M-1; i++){
      dif[i] = arr[i+1] - arr[i];
    }
    Arrays.sort(dif);
    int ans = arr[M-1] - arr[0];
    for(int i = M-2; i>M-2-N+1 && i >= 0; i--){
      //System.out.println(dif[i]);
      ans -= dif[i];
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 60344
#include <bits/stdc++.h>
 
using namespace std;
int main(){	
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n;
	    cin >> n;
	    vector< int > a(n), b(n) , c(n);
	    for(int i = 0 ; i < n ; i++)
	    	cin >> a[i];
	    for(int i = 0 ; i < n ; i++)
	    	cin >> b[i];
	    for(int i = 0; i < n ; i++)
	    	c[i] = i + 1;
	    int  i = 0 , p , q;
	    do{	
	    	if(a == c)
	    		p = i;;
	    	if(b == c)
	    		q = i;
	    	i++;
	    }while(next_permutation(c.begin() , c.end()));
	    cout << abs(p - q) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e6+10;
struct w
{
    int cost, v;
} w[100];
int dp[30005], sum[30005];

int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",n*n);
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    map<char, bool> MP;
    for (int i = 0; i < S.length(); i++) MP[S[i]] = true;
    if (MP['S'] && MP['N']) {
        if ((MP['E'] && MP['W']) || (!MP['E'] && !MP['W'])) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    else if (MP['E'] && MP['W']) {
        if ((MP['S'] && MP['N']) || (!MP['S'] && !MP['N'])) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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


int main(void){
	int a,b;
	int ans=0;
	scanf("%d %d" ,&a,&b);
	if(a>b){
		ans+=a;
		a--;
	}else{
		ans+=b;
		b--;
	}

	if(a>b){
		ans+=a;
		a--;
	}else{
		ans+=b;
		b--;
	}

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int a[105], s[105], p;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({p + q, p + r, q + r}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

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


int main()
{
	int N, M;
	int P[100000], Y[100000];
	vector<int> yd[100001];

	cin >> N >> M;

	rep(i, M) {
		cin >> P[i] >> Y[i];
		yd[P[i]].push_back(Y[i]);
	}

	rep(i, N) 	sort(yd[i + 1].begin(), yd[i + 1].end());

	rep(i, M) {
		printf("%012lld\n", (long long)(P[i]) * 1000000 +
			int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i])
				- yd[P[i]].begin()) + 1);
	}

               
               return 0;
}


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

long long N;
string S;
int P;

long long solve() {
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main() {
    cin >> S;
    N = S.size();
    P = 2019; 
    cout << solve() << endl;
}

Measured memory_bytes: 3764
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long K = sc.nextLong();
    sc.close();

    long mod = N % K;
    long ans = Math.min(mod, K - mod);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;


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

    double a;
    cin >> a;
    cout << round(a/2) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int d, n;
	cin >> d >> n;
	int ans = 1, count = 0;
	while(1){
		int co = 0;
		int temp = ans;
		while(temp != 0 && temp % 100 == 0){
			temp /= 100;
			co++;
		}
		if(co == d){
			count++;
		}
		if(count == n){
			cout << ans << endl;
			return 0;
		}
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
n, X = map(int, input().split())
x = sorted([int(i) for i in input().split()] + [X])
diff_x = [x[i + 1] - x[i] for i in range(n)]
if len(diff_x) == 1:
    print(diff_x[0])
else:
    d = gcd(diff_x[0], diff_x[1])
    for i in range(2, n):
        d = gcd(d, diff_x[i])
    print(d)

Measured memory_bytes: 16276
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e30;
const ll MOD = 1e9 + 7;

int main(){
	ll N, Z, W;
	vll A;
	cin >> N >> Z >> W;
	ll i, j;
	for (i = 0; i < N; i++){
		ll a;
		cin >> a;
		A.push_back(a);
	}
	if (N > 1){
		cout << max(abs(A[N - 1] - A[N - 2]), abs(A[N - 1] - W)) << endl;
	}
	else{
		cout << abs(A[0] - W) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

ntom = [0,2,5,5,4,5,6,3,7,6]

mtoa = {}
for a in sorted(A):
    mtoa[ntom[a]] = a

ms = sorted(mtoa.keys(), key=lambda x: mtoa[x], reverse=True)
dp = [0] + [float('-inf')] * N
for i in range(min(ms), N+1):
    dp[i] = max(dp[i-x] for x in ms if i >= x) + 1

ans = []
left = N
while left:
    for m in ms:
        if left >= m and dp[left] == dp[left - m] + 1:
            left -= m
            ans.append(mtoa[m])
            break
        
print(*ans, sep='')

Measured memory_bytes: 4340
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rb_tree>
*/
#define mem(x,y) memset(x,y,sizeof(x))
//#define P(x) cout<<#x<<" = "<<x<<endl;
#define PN(x,n) cout<<'{'<<x[0];for(int i=1;i<n;i++)cout<<','<<x[i];cout<<'}'<<endl;
#define RP(i,n) for(int i=0;i<n;i++)
#define RP2(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define P pair<int,int>
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define dinf 1e99
#define OJ
#define ite iterator
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
using namespace std;/*
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;
const double PI = acos(-1.0);  
const double eps = 1e-5;
const double T = 5; //t of fire
const double delta = 0.99; //decreasing speed of t
const int INF = 1000000000;*/
const int maxn=1005;
bool vis[maxn][maxn];
int d[maxn][maxn];
int ans,n,m,k,sx,sy;
int lx[maxn],ly[maxn],G[maxn][maxn];
char bf;
queue<P> q;
int bfs(int sx,int sy,int ex,int ey){
    mem(vis,0);
    q.push(mp(sx,sy));
    vis[sx][sy] = 1;
    d[sx][sy] = 0;
    while(!q.empty()){
	P u = q.front(); q.pop();
	for(int dr=0;dr<4;dr++){
	    P v=mp(u.fi+dx[dr],u.se+dy[dr]);
	    if(v.fi<1 || v.se<1 || v.fi>n || v.se>m || vis[v.fi][v.se] || G[v.fi][v.se]) continue;
	    d[v.fi][v.se]=d[u.fi][u.se] + 1;
	    vis[v.fi][v.se] = 1;
	    q.push(v);
	}
    }
    return d[ex][ey];
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	    cin>>bf;
	    if(bf=='.') G[i][j] = 0;
	    else if(bf == 'S') sx = i, sy = j, G[i][j] = 0;
	    else if(bf=='X') G[i][j] = 1;
	    else lx[bf-48] = i, ly[bf-48]=j;
	}
    }
    for(int i=1;i<=k;i++){
	ans += bfs(sx,sy,lx[i],ly[i]);
	sx=lx[i], sy=ly[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, N) for (int i = 0; i < (N); i++)
#define REP(i, a, N) for (int i = a; i < (N); i++)
#define rrep(i, N, k) for (int i = (N); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1), revG(N + 1);
    vector<int> count(N + 1, 0);
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        revG[t].push_back(s);
        count[s]++;
    }
    vector<double> dp(N + 1, 0);
    auto calc = [&](pi stop) {
        dp[N] = -1;
        for (int i = N; i > 1; i--) {
            dp[i]++;
            for (int next : revG[i]) {
                double power = 1 / (double) count[next];
                if (stop.first == next && stop.second == i) continue;
                dp[next] += dp[i] * power;
            }
        }
    };
    calc({-1, -1});
    vector<int> maxIdx(N + 1, -1);
    for (int i = 1; i < N; i++) {
        set<pair<double, int>> temp;
        for (int next : G[i]) temp.emplace(dp[next], next);
        if (temp.size() > 1) maxIdx[i] = temp.rbegin()->second;
    }
    double ans = dp[1];
    for (int i = 1; i < N; i++) {
        if (maxIdx[i] == -1) continue;
        dp = vector<double>(N + 1, 0);
        count[i]--;
        calc({i, maxIdx[i]});
        count[i]++;
        if (dp[1] != 0) ans = min(ans, dp[1]);
    }
    cout << fixed << setprecision(10) << ans + 1 << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>

int fibonacci(int);

int F[45];

int main(){

  int n;
  int ans;

  scanf("%d",&n);

  ans = fibonacci(n);

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

  return 0;
}

int fibonacci(int n){

  if(n==0 || n==1) return F[n] = 1;

  if(F[n]!=0) return F[n];

  return F[n] = fibonacci(n-2) + fibonacci(n-1);
}

Measured memory_bytes: 596
#include<stdio.h>
#include<algorithm>
using namespace std;
int x1[12];
int x2[12];
int y1[12];
int y2[12];
int ret[12];
int num=0;
int n;
void solve(int a){
	while(a){
		int at=0;
		int x=9999999;
		int y=9999999;
		for(int i=0;i<n;i++){
			if(a&(1<<i)){
				if(x>x1[i]||(x==x1[i]&&y>y1[i])){
					at=i;
					x=x1[i];y=y1[i];
				}
			}
		}
		ret[at]=num++;
		a-=(1<<at);
		bool chg=false;
		int now=110000;
		for(int i=0;i<n;i++){
			if(y1[i]<y2[at]&&y2[at]<y2[i]&&x2[at]<=x1[i]){
				now=min(now,x1[i]);
			}
		}
		int to=0;
		for(int i=0;i<n;i++){
			if(a&(1<<i)){
				if(y2[i]<=y2[at]&&x2[i]<=now){
					to+=(1<<i);
				}
			}
		}
		solve(to);
		a-=to;
	}
}
int main(){
	int a;
	bool blank=false;
	while(scanf("%d",&a),a){
		if(blank)printf("\n");
		blank=true;
		n=a;
		for(int i=0;i<a;i++){
			scanf("%d%d%d%d",x1+i,y1+i,x2+i,y2+i);
			if(x1[i]>x2[i])swap(x1[i],x2[i]);
			if(y1[i]>y2[i])swap(y1[i],y2[i]);
		}
		for(int i=0;i<a;i++)ret[i]=-1;
		num=0;
		solve((1<<n)-1);
		for(int i=0;i<a;i++){
			printf("%d\n",ret[i]+1);
		}
	}
}

Measured memory_bytes: 1032
import java.io.*;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int train = Integer.parseInt(strs[0]);
    int bus = Integer.parseInt(strs[1]);
    
    System.out.println(train + bus / 2);
  }
}

Measured memory_bytes: 21332
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def main():
    n, k = ns()

    # 使い方
    facts, invs = prepare(k, MOD)

    ans = 0
    for i in range(k):
        tmp = pow(k - i, n, MOD) * (facts[k] * invs[i] * invs[k - i] % MOD)
        tmp %= MOD
        if i % 2:
            ans -= tmp
        else:
            ans += tmp
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7312
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pdi = pair<double, int>;

int D;
vector<ll> v, w;

int main() {
	cin >> D;
	string s;
	switch (D)
	{
	case 25:
		s = "Christmas";
		break;
	case 24:
		s = "Christmas Eve";
		break;
	case 23:
		s = "Christmas Eve Eve";
		break;
	case 22:
		s = "Christmas Eve Eve Eve";
		break;
	default:
		break;
	}
	cout << s << endl;
	return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> h;
  int count=0;
  for(int i=0;i<n;i++){
    int x; cin>>x;
    h.push_back(x);
    sort(h.begin(),h.end());
    count++;
    if(x<h.at(i)){
      count--;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <list>
using std::cout;
using std::cin;
using std::endl;
int main()
{
	short t = 10;
	int a;
	std::list<int> v;
	while (t --)
	{
		cin >> a;
		v.push_back(a);
	}
	v.sort();
	std::list<int>::const_iterator le = v.end();
	t = 3;
	while (t--)
	{
		--le;
		cout << *le << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> st(h);
  for(Int i=0;i<h;i++) cin>>st[i];

  vector<Int> us,vs;
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(st[i][j]!='B') continue;
      us.emplace_back(i+j);
      vs.emplace_back(i-j);
    }
  }
  sort(us.begin(),us.end());
  sort(vs.begin(),vs.end());

  cout<<max(us.back()-us.front(),vs.back()-vs.front())<<endl;
  return 0;
}



Measured memory_bytes: 3272
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <string.h>

int main()
{
    char a[105], b[105];
    int i=0,j=0;
    do {
        scanf("%c",&a[i++]);
    } while (a[i-1]!='\n');
    
    do {
        scanf("%c",&b[j++]);
    } while (b[j-1]!='\n') ;
    
    i--;j--;
    
    int flag=0;
    for(int k=0;k<i;k++) {
        if (a[k]==b[0]) {
            flag=0;
            for(int p=k,q=0;q<j;p++,q++) {
                if (p==i) p=0;
                if (a[p]!=b[q]) {
                    flag=1;
                    // printf("p: %d, q: %d, a[p]: %c, b[q]: %c\n",p,q,a[p],b[q]);
                    break;
                }
                continue;
            }
            if (flag==0) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    // printf("%s\n%s",a,b);

}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
map<char,vector<ll> > mp;
unordered_set<char> st;
int main()
{
	ios;
	vector<ll>::iterator it;
	ll n,i,d,sum=0,j,f,p;
	char ch;
	string s;
	cin>>n>>s;
	for(i=0;i<n;i++)
		mp[s[i]].push_back(i);
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				st.clear();f=0;
				st.insert('R');st.insert('G');st.insert('B');
				st.erase(s[i]);st.erase(s[j]);
				d=j-i;
				ch=*st.begin();
				it=lower_bound(mp[ch].begin(),mp[ch].end(),j+d);
				p=mp[ch].end()-lower_bound(mp[ch].begin(),mp[ch].end(),j);
				if(it!=mp[ch].end()&&*it==j+d)
					f=1;
				sum+=(p-f);
			}
		}
	}
	cout<<sum<<endl;
}


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

typedef long long int ll;
#define size 100002
ll n;
ll a[size],dp[size];

ll func(ll i)
{
	if(dp[i]!=-1)
		return dp[i];
	dp[i] = min(func(i-1)+abs(a[i-1]-a[i]),func(i-2)+abs(a[i-2]-a[i]));
	return dp[i];
}


int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	ll i,j;
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		dp[i]=-1;
	}
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	ll ans = func(n);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <regex>
#include <cmath>
#include <bitset>
#include <array>
#include <deque>
#include <list>
#include <stack>
#include <iterator>
#include <random>
#include <cctype>

#define DEBUG_OUTPUT 0

#if DEBUG_OUTPUT
#define debug(...) debug_output(__VA_ARGS__)
#define debug_output_matrix(...) debug_output_matrix_impl(__VA_ARGS__)
#else
#define debug(...)
#define debug_output_matrix(...)
#endif

using namespace std;

using s32 = int32_t;
using u32 = uint32_t;
using s64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;

// ==== I/O
const char newline = '\n';

template<class T>
void input(T& val) {
    cin >> val;
}

template<class Head, class... Args>
void input(Head& val, Args&... args){
    input(val);
    input(args...);
}

template<class T>
T input() {
    T val;
    input(val);
    return val;
}

template<class T>
std::vector<T> input_vector(int n) {
    std::vector<T> res;
    for(int i=0;i<n;i++){
        res.emplace_back(input<T>());
    }
    return res;
}

template<class T>
void output(const T& val){
    cout << val;
}
template<class T1,class T2>
void output(const T1& val, const T2& val2){
    output(val);
    if(val2 != newline)
        output(' ');
    output(val2);
}

template<class T1, class T2, class... Args>
void output(const T1& val, const T2& val2, Args&&... args){
    output(val);
    output(' ');
    output(val2, args...);
}

#if DEBUG_OUTPUT
template<class T>
void debug_output(const T& val){
    cerr << val;
}
template<class T1,class T2>
void debug_output(const T1& val, const T2& val2){
    debug_output(val);
    if(val2 != newline)
        output(' ');
    debug_output(val2);
}

template<class T1, class T2, class... Args>
void debug_output(const T1& val, const T2& val2, Args&&... args){
    debug_output(val);
    debug_output(' ');
    debug_output(val2, args...);
}
#endif

template<class T>
vector<vector<T>> make_matrix2(T val, int a, int b){
    return vector<vector<T>>(
        a, vector<T>(b, val)
    );
}

template<class T>
void debug_output_matrix_impl(const vector<vector<T>>& v) {
    cerr << "========" << endl;
    for(const auto& a: v){
        for(const auto& b : a){
            cerr << b << " ";
        }
        cerr << endl;
    }
    cerr << endl;
}

// === math
s64 gcd(s64 a, s64 b) {
    return b?gcd(b,a%b):a;
}
s64 lcm(s64 a, s64 b) {
    return a / gcd(a, b) * b;
}

// =======================
vector<s64> res;
const vector<s64> walk = {
    -1, 0, 1
};

void dfs(s64 val) {
    res.push_back(val);

    if(3234566667 <= val)
        return;

    for(auto& w : walk){
        auto next = val % 10 + w;
        if(0 <= next && next <= 9){
            dfs(val * 10 + next);
        }
    }
}

int main(){
    for(s32 i=1;i<=9;i++){
        dfs(i);
    }
    std::sort(res.begin(), res.end());

    cout << res[input<s32>()-1] << endl;
    return 0;
}



Measured memory_bytes: 7252
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1162&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
#include<iomanip>
#include<queue>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const double INF = 10e9; 

struct state
{
	int pos, prev, speed;
	double time;
	state(int p, int pr, int sp, double t)
		:pos(p), prev(pr), speed(sp), time(t) {}

	bool operator<(const state& s) const {
		return time > s.time;
	}
};

struct edge
{
	int to, cost, limit;
	edge(int t, int c, int l) : to(t), cost(c), limit(l) {}
};

vector<vector<edge>> graph;
double dp[31][31][31];//[pos][prev][speed] = time

double dijkstra( int s, int g )
{
	double res=-1.0;
	fill_n((double *)dp, sizeof(dp) / sizeof(double), INF);
	
	priority_queue<state> pq;
	rep( i, graph[s].size()){
		edge e = graph[s][i];
		pq.push( state( e.to, s, 1, e.cost ) );
		dp[e.to][s][1] = e.cost;
	}

	while( !pq.empty() )
	{
		state st = pq.top();
		pq.pop();

		if( dp[st.pos][st.prev][st.speed] != st.time){
			continue;
		}

		if( st.pos == g && st.speed == 1){
			res = st.time;
			return res;
		}

		rep( i, graph[st.pos].size() )
		{
			edge e = graph[st.pos][i];
			if( e.to == st.prev ){ continue; } //Uターンは禁止
			REP( j, -1, 2 )
			{ 
				if( st.speed + j > 0 && st.speed + j <= e.limit ){ 
					double time = st.time + (double)e.cost / (st.speed + j);
					if( dp[e.to][st.pos][st.speed + j] > time){
						dp[e.to][st.pos][st.speed + j] = time;
						pq.push( state( e.to, st.pos, st.speed + j, time ) );
					}
				}
			}
		}
	}
	return res;
}

int main()
{
	cout << setprecision(6) << fixed;
	int n,m,s,g;
	while( cin >> n >> m, n )
	{
		graph = vector<vector<edge>>( n+1 );
		cin >> s >> g;
		
		int x,y,d,c;
		rep( i, m )
		{
			cin >> x >> y >> d >> c;
			graph[x].push_back( edge(y,d,c) );
			graph[y].push_back( edge(x,d,c) );
		}

		double ans = dijkstra( s, g );
		if(ans < 0){
			cout << "unreachable" << endl;			
		}else{
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1996
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if ((i < b && j >= a) || (i >= b && j < a)) {
                cout << 1;
            } else {
                cout << 0;
            }
        }
        cout << endl;
    }
}

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

const int N=2010;
bool mp[N][N],good[N][N];
int deep[N][N];
int L[N],R[N];
int s[N],top;
char ss[N];
int H,W,ans=0;

int main()
{
    scanf("%d%d",&H,&W);
    for(int i=1;i<=H;i++)
    {
        scanf("%s",ss+1);
        for(int j=1;j<=W;j++)
            mp[i][j]=(ss[j]=='#');
    }
    for(int i=1;i<H;i++)
        for(int j=1;j<W;j++)
        {
            int cnt=mp[i][j]+mp[i+1][j]+mp[i][j+1]+mp[i+1][j+1];
            good[i][j]=!(cnt&1);
        }
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            deep[i][j]=good[i][j]?deep[i-1][j]+1:0;
    for(int i=1;i<=H;i++)
    {
        s[top=1]=0;
        for(int j=1;j<W;j++)
        {
            while(top&&deep[i-1][s[top]]>=deep[i-1][j]) top--;
            L[j]=s[top];s[++top]=j;
        }
        s[top=1]=W;
        for(int j=W-1;j>=1;j--)
        {
            while(top&&deep[i-1][s[top]]>=deep[i-1][j]) top--;
            R[j]=s[top];s[++top]=j;
        }
        for(int j=1;j<W;j++)
            ans=max(ans,(deep[i-1][j]+1)*(R[j]-L[j]));
    }
    ans=max(ans,max(H,W));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

#define INF (1e5)
#define MOD 1000000007
typedef long long unsigned int ll;




int main()
{
	ll N;
	cin >> N;
	ll a[5];

	int index = 0;
	REP(i, 5)
	{
		cin >> a[i];
		if(a[index]>a[i]){
			index = i;
		}
	}

	ll left[5];
	ll count = 4;
	ll maxbefore = 0;
	if(N%a[index]==0){
		count += N / a[index];
	}else{
		count += N / a[index] + 1;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower)
#define upper(a) transform(a.begin(),a.end(),a.begin(),::toupper)
//#define min(a) *min_element(a.begin(),a.end())
//#define max(a) *max_element(a.begin(),a.end())
#define pdd pair<long double,long double>
#define prnt(a) for(auto x:a) cout<<x<<" ";
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define PI 3.1415926535897932385
#define INF 1000000000000000
#define M 1000000007
#define ve  vector<ll>;
ll n;
vector<ll>a(1e5);
vector<ll>dp(1e5+1,-1);
ll k;



ll fun(ll i)
{
	if(i==n-1)
	{
		return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	ll mi=INT_MAX;
	for(ll j=1;j<=k;j++)
	{
		if(j+i<=n-1)
		{
			mi=min(fun(i+j)+abs(a[i]-a[i+j]),mi);
		}
	}
	return dp[i]=mi;


}

 int main()
 {
 	cin>>n;
 	cin>>k;
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 	}
 	cout<<fun(0)<<endl;
 	
 	return 0;

 	}

Measured memory_bytes: 9548
N,M,C = map(int,input().split())
B = [int(x) for x in input().split()]
 
count = 0
for i in range(N):
  temp = [int(x) for x in input().split()]
  total = [B[i]*temp[i] for i in range(M)]
  if((sum(total) + C) > 0 ):
    count+=1
print(count)
  

Measured memory_bytes: 3064
use v5.18;
use warnings;
use utf8;
use Data::Dumper;
use List::Util qw( sum );
use Test::More;

sub line { chomp(my $str = <>); $str; }
sub split_line { (split / /, line) }

my ($n1, $n2) = split_line;
say( ($n1 + $n2) % 24 );


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

int main(void){
    int n, l, r;
    while (cin >> n >> l >> r) {
        if (n == 0) return 0;
        
        int a[55];
        for (int i = 0; i < n; i++) cin >> a[i];
        
        int ans = 0;
        for (int i = l; i <= r; i++) {
            int idx = n + 1;
            for (int j = 0; j < n; j++) {
                if (i % a[j] == 0) idx = min(idx, j + 1);
            }
            if (idx % 2) ans++;
        }
        cout << ans << endl;
        
    }
}



Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, k, ans = 0;
	vector<int> u;
	set<ll> m;
	map<ll, int> a;
	cin >> n >> k;
	FOR(i, n){
		int M;
		cin >> M;
		m.insert(M);
		a[M]++;
	}
	int cnt = m.size() - k;
	if (cnt>0){
		auto itr = m.begin();
		FOR(i, m.size()){
			u.push_back(a[*itr]);
			*itr++;
		}
		SORT(u);
		FOR(i, cnt)ans += u[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 23288
import java.io.*;
import java.util.*;
 
 
public class Main implements Runnable {

  public void run() {
    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    long[] aa = new long[3 * n];
    for (int i = 0 ; i < 3 * n ; i ++) {
      aa[i] = scanner.nextLong();
    }
    Arrays.sort(aa);

    long res = 0;
    for (int i = 0 ; i < n ; i ++) {
      res += aa[3 * n - 2 * i - 2];
    }
    System.out.println(res);
  }

  public static void main(String[] args) {
    Main main = new Main();
    main.run();
  }
 
  public static class BetterScanner {
 
    private InputStream stream;
    private byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufferLength = 0;
 
    public BetterScanner(InputStream stream) {
      this.stream = stream;
    }
 
    private boolean updateBuffer() {
      if (pointer >= bufferLength) {
        pointer = 0;
        try {
          bufferLength = stream.read(buffer);
        } catch (IOException exception) {
          exception.printStackTrace();
        }
        return bufferLength > 0;
      } else {
        return true;
      }
    }
 
    private int read() {
      if (updateBuffer()) {
        return buffer[pointer ++];
      } else {
        return -1;
      }
    }
 
    public boolean hasNext() {
      skipUnprintable();
      return updateBuffer();
    }
 
    private void skipUnprintable() { 
      while (updateBuffer() && !isPrintableChar(buffer[pointer])) {
        pointer ++;
      }
    }
 
    public String next() {
      if (hasNext()) {
        StringBuilder builder = new StringBuilder();
        int codePoint = read();
        while (isPrintableChar(codePoint)) {
          builder.appendCodePoint(codePoint);
          codePoint = read();
        }
        return builder.toString();
      } else {
        throw new NoSuchElementException();
      }
    }
 
    public long nextLong() {
      if (hasNext()) {
        long number = 0;
        boolean minus = false;
        int codePoint = read();
        if (codePoint == '-') {
          minus = true;
          codePoint = read();
        }
        if (codePoint >= '0' && codePoint <= '9') {
          while (true) {
            if (codePoint >= '0' && codePoint <= '9') {
              number *= 10;
              number += codePoint - '0';
            } else if (codePoint < 0 || !isPrintableChar(codePoint)) {
              return (minus) ? -number : number;
            } else {
              throw new NumberFormatException();
            }
            codePoint = read();
          }
        } else {
          throw new NumberFormatException();
        }
      } else {
        throw new NoSuchElementException();
      }
    }
 
    public int nextInt() {
      long number = nextLong();
      if (number >= Integer.MIN_VALUE && number <= Integer.MAX_VALUE) {
        return (int)number;
      } else {
        throw new NumberFormatException();
      }
    }
 
    private boolean isPrintableChar(int codePoint) {
      return codePoint >= 33 && codePoint <= 126;
    }
 
  }
 
}


Measured memory_bytes: 98196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	void solve() throws IOException {
		solve(nl(), nl(), nl());
	}

	private void solve(long n, long m, long d) {

		if (2 * d >= n || d == 0)
			out.printf("%.10f\n", (double) (m - 1) / n);
		else
			out.printf("%.10f\n", (double) (2 * d + (n - 2 * d) * 2) * (m - 1) / n / n);

	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

Measured memory_bytes: 21332
import java.util.Scanner;
    
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String str = scanner.nextLine();
        String strArr[] = str.split(" ");
        int line[] = new int[n];
        
        int cnt = 0;
        for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(strArr[i]);
		}
		
        boolean flag = true;		
        while(flag){
            flag = false;
            for(int j=(n-1); j>0; j--){
                if(line[j] < line[j-1] ){
                    int tmp = line[j];
                    line[j] = line[j-1];
                    line[j-1] = tmp;
                    cnt++;
                    flag=true;
                }
            }
        }
        
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(cnt);
    }

}



Measured memory_bytes: 26312
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int N;cin >> N;
  int A,B;cin >> A >> B;
  string S;cin >> S;
  int acnt=0,bcnt=0;
  repeat(i,S.length()){
    bool isok;
    if(S[i]=='a'){
      isok = acnt+bcnt<A+B;
      if(isok)acnt++;
    }else if(S[i]=='b'){
      isok = acnt+bcnt<A+B&&bcnt<B;
      if(isok)bcnt++;
    }else{
      isok = false;
    }
    cout << (isok? "Yes":"No")<<endl;
  }
  return 0;
}


Measured memory_bytes: 896
k = int(input())
q = []

for i in range(1, 10):
    q.append(i)

while True:
    if k <= len(q):
        print(q[k-1])
        break
    k = k - len(q)
    old_q = q[:]
    q = []

    for x in old_q:
        for i in range(-1, 2):
            d = x%10 + i
            if d < 0 or d > 9:
                continue
            nx = x*10 + d
            q.append(nx)


Measured memory_bytes: 11304