akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;


int main() {
    ll x;
    cin >> x;
    
    ll m = 100;
    double l;

    int i;
    for (i = 0; m < x; i++) {
        l = m * (101.0/100.0);
        ll k = l;
        m = k;
    }    

    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3596
n=int(input())
b,u=map(int,input().split())
x,c,v=1,1,1
for i in range(n-1):
  a,t=map(int,input().split())
  c=b if b%a==0 else (b//a+1)*a
  v=u if u%t==0 else (u//t+1)*t
  x=max(c//a,v//t)
  b=a*x
  u=t*x
print(b+u)

Measured memory_bytes: 3064
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm;

void main() {
    uint c = to!uint(readln().chomp);
    for (uint i = 0; i < c; ++i) {
        double[] dx = map!(to!double)(readln().chomp.split).array;
        double[] ap = dx[0..2];
        double[] bp = dx[3..5];
        double ar = dx[2];
        double br = dx[5];
        double d = dist(ap, bp);
        if (d > (ar+br)^^2) {
            writeln(0);
        }else if (d < (ar-br)^^2) {
            if (br < ar) {
                writeln(2);
            } else {
                writeln(-2);
            }
        } else {
            writeln(1);
        }
    }
}

double dist(double[] ax, double[] bx) {
    return (ax[0]-bx[0])^^2 + (ax[1]-bx[1])^^2;
}

Measured memory_bytes: 1064
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll x;
	cin >> x;

	ll sho   = x / 11;
	ll amari = x % 11;

	if (amari == 0) {
		out(sho * 2);
	}
	else if (amari <= 6) {
		out(sho * 2 + 1);
	}
	else {
		out(sho * 2 + 2);
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
char S[2002],T[2002];
int M,N;
int dp[2002][2002][2];//[a][b][c] S???a,T???b?????§?????£?????¨????????????????????????????????????c(0=I,1=O)??§????????¨?????????????????????
class IOItrain{
    public:
    void initialize(){
        fill(dp[0][0],dp[2002][0],0);
    }
    int solve(){
        int ans=0;
        scanf("%d %d",&M,&N);
        scanf("%s",S);
        scanf("%s",T);
        rep(i,M+1){
            rep(j,N+1){
                if(i==0&&j==0){
                    continue;//???????????£?????????????????§0
                }
                if(i==0){
                    dp[i][j][0]=( T[j-1]=='I' ? dp[i][j-1][1] : -1)+1;
                    dp[i][j][1]=( T[j-1]=='O'&&dp[i][j-1][0]>0 ? dp[i][j-1][0] : -1)+1;
                }
                if(j==0){
                    dp[i][j][0]= (S[i-1]=='I' ? dp[i-1][j][1] : -1)+1;
                    dp[i][j][1]= (S[i-1]=='O'&&dp[i-1][j][1]>0 ? dp[i-1][j][1] : -1)+1;
                }
                if(i!=0&&j!=0){
                    dp[i][j][0]=max( (S[i-1]=='I' ? dp[i-1][j][1] : -1) , ( T[j-1]=='I' ? dp[i][j-1][1] : -1) )+1;
                    dp[i][j][1]=max( (S[i-1]=='O'&&dp[i-1][j][0]>0 ? dp[i-1][j][0] : -1) , ( T[j-1]=='O'&&dp[i][j-1][0]>0 ? dp[i][j-1][0] : -1) )+1;
                }
                ans=max(ans,dp[i][j][0]);
            }
        }
        
        return ans;//-(ans%2 ? 1 : 0 );//??¶??°?????????1?????????????\???°?????????(I??§???????????????)
    }
};
signed main(){
    IOItrain ans;
    ans.initialize();
    printf("%d\n",ans.solve());
    return 0;
}

Measured memory_bytes: 34068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

bool palindrome(string s) {
    string tmp = s;
    reverse(all(tmp));
    return s == tmp;
}

int main() {
    string s; cin >> s;
    int n = s.size();
    string s_;
    rep(i,n) {
        if (s[i] != 'x') s_ += s[i];
    }
    if (palindrome(s_)) {
        s += '.';
        int n_x = 0;
        vint n_xs;
        rep(i,n+1) {
            if (s[i] == 'x') n_x++;
            else {
                n_xs.push_back(n_x);
                n_x = 0;
            }
        }
        int n_ = n_xs.size();
        int ans = 0;
        for (int i = 0; i < n_/2; i++) {
            ans += max(n_xs[i],n_xs[n_-i-1]) - min(n_xs[i],n_xs[n_-i-1]);
        }
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 4112
n,m=map(int,input().split())
ab=[]
for i in range(m):
    a,b=[int(x) -1 for x in input().split()]
    ab.append((a,b))
ab=sorted(ab,key=lambda x: x[1])
ans=0
last_bridge=-1
for a,b in ab:
    # print(a,b)
    if last_bridge<a:
        last_bridge=b-1
        ans+=1
print(ans)

Measured memory_bytes: 18996
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;

int keta(int n){
    if(n==0){return 1;}
    int ret =0;
    while(n){
        ret++;
        n/=10;
    }
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,s,c,ans=-1,f;
    cin>>n>>m;
    vector<P>d(m);
    rep(i,0,m){
        cin>>s>>c;
        s--;
        d[i].first=s,d[i].second=c;
    }
    rep(i,0,1000){
        f=1;
        if(n==keta(i)){
            string s = to_string(i);
            rep(j,0,m){
                if(s[d[j].first]!=('0'+d[j].second)){f=0;}
            }
            if(f){cout<<i;return 0;}
        }
    }
    cout<<-1;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int x;
  cin >> x;
  if(x < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}


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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;
using Graph = vector<vector<int> >;

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

void solve_D(){
    int n, x, y;
    cin >> n >> x >> y;

    Graph G(n);
    int graph[n][n];
    REP(i,n){
        REP(j,n){
            graph[i][j] = 0;
        }
    }
    REP(i,n-1){
        //graph[i][i+1] = graph[i+1][i] = 1;
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    //graph[x-1][y-1] = graph[y-1][x-1] = 1;
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);

    int ans[n];
    REP(i,n) ans[i] = 0;

    REP(start,n){
        int dist[n];
        REP(i,n) dist[i] = -1;
        queue<int> que;

        dist[start] = 0;
        que.push(start);
        while(!que.empty()){
            int v = que.front();
            que.pop();

            /*
            for(int j = start; j < n; j++){
                if(dist[j] != -1) continue;

                if(graph[v][j] != 0){
                    dist[j] = dist[v] + 1;
                    que.push(j);
                }
            }
            */

            for(int nv : G[v]){
                if (dist[nv] != -1) continue;

                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        
        REP(i,n){
            if(dist[i] < 0) continue;
            ans[dist[i]]++; //k:1-index(k=0は意味なし)
        }
        
    }
    
    REP(i,n){
        if(i == 0) continue;
        cout << ans[i]/2 << endl;
    }
    
}

int main(void){
    solve_D();
    
    return 0;
}

Measured memory_bytes: 16000
#include <stdio.h>

int main()
{
	long long a[200032];
	int b[200032];
	int f[200032];
	int N;
	scanf( "%d", &N );
	for ( int i = 0 ; i < N+1 ; i++ ) {
		b[i] = 0;
		f[i] = 0;
	}
	for ( int i = 0 ; i < N ; i++ ) {
		int t;
		scanf( "%d", &t );
		a[i] = (long long)t;
		b[t]++;
		f[t] = 1;
	}
	long long d = 0;
	for ( int i = 0 ; i < N ; i++ ) {
		if ( f[a[i]] == 1 )
		{
			f[a[i]] = 0;
			long long c = b[a[i]];
			if ( c > 1 )
				d += c*(c-1)/2;
		}
	}
	for ( int i = 0 ; i < N ; i++ ) {
		long long c = b[a[i]];
		long long e = d;
		if ( c > 1 ) {
			e -= c*(c-1)/2;
			e += (c-1)*(c-2)/2;
		}
		printf( "%lld\n", e );
	}
}


Measured memory_bytes: 5632
#include <iostream>

#define N 1000000

using namespace std;

int main() {
	int n;
	bool p[N];
	for(int i = 0; i <= N; i++) p[i] = 0;
	for(int i = 3; i <= N; i += 2) p[i] = 1;
	p[2] = 1;
	for(int i = 0; i < N; i++){
		if(!p[i]) continue;
		for(int j = 2 * i; j < N; j += i) p[j] = 0;
	}

	while(cin >> n){
		int j = 0;
		for(int i = 0; i <= n; i++){
			if(p[i]) j++;
		}
		cout << j << endl;
	}	
	return 0;
}

Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define ll long long
ll tmp;
struct edge{
	int to,next,v;
}e[N*2];
int head[N],v[N],sz[N];
int n,tot,ans;
int cen,mx[N];
void add(int x,int y,int v){
	e[++tot]=(edge){y,head[x],v};
	head[x]=tot;
}
void dfs(int x,int fa){
	sz[x]=1; mx[x]=0;
	for (int i=head[x];i;i=e[i].next)
		if (e[i].to!=fa){
			v[e[i].to]=e[i].v;
			dfs(e[i].to,x);
			sz[x]+=sz[e[i].to];
			mx[x]=max(mx[x],sz[e[i].to]);
		}
	mx[x]=max(mx[x],n-sz[x]);
	if (mx[x]*2<n) cen=x; 
	tmp+=2ll*min(sz[x],n-sz[x])*v[x];
	if (sz[x]*2==n) ans=v[x];
}
int main(){
	scanf("%d",&n); ans=2e9;
	for (int i=1;i<n;i++){
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		add(x,y,v); add(y,x,v);
	}
	dfs(1,0);
	if (ans==2e9)
		for (int i=head[cen];i;i=e[i].next)
			ans=min(ans,e[i].v);
	printf("%lld",tmp-ans);
}

Measured memory_bytes: 8192
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int num[26],ans1,ans2,k;
void print(int x,int y)
{
	if(ans2>(x/2)) {printf("No");return;}
	else {printf("Yes");return;}
}
int main()
{
	memset(num,0,sizeof(num));
	char c;
	int n,m;
	scanf("%d%d\n",&n,&m);
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
		{
			if(j==m-1) scanf("%c\n",&c);
			else scanf("%c",&c);
			++num[c-'a'];
		}
	for(int i=0;i<26;++i)
		if(num[i]!=0)
		{
			k+=(num[i]/4);
			if(num[i]%4==1) ++ans1;
			if(num[i]%4==2) ++ans2;
			if(num[i]%4==3) {++ans1;++ans2;}
		}
	if(ans1>1) {printf("No");return 0;}
	if(m%2==0&&n%2==0)
	{
		if(ans1==0&&ans2==0) printf("Yes");
		else printf("No");
		return 0;
	}
	if(m%2==0&&n%2!=0) {print(m,n);return 0;}
	if(m%2!=0&&n%2==0) {print(n,m);return 0;}
	if(m%2!=0&&n%2!=0)
	{
		if(ans2>(m/2+n/2)) printf("No");
		else printf("Yes");
		return 0;
	}
}

Measured memory_bytes: 256
#include <iostream>

int sum(int n){
	int result = 0;
	while(n){
		result += n%10;
		n/=10;
	}
	return result;
}

int main()
{
	int N;
	int min=100000;
	std::cin>>N;
	for(int i=1;i<=N/2;++i){
		int j=N-i;
		if(sum(i)+sum(j)<min)
			min=sum(i)+sum(j);
	}
	std::cout<<min<<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;

const uint32_t M = 998244353;
using modint = uint32_t;

#define mul(a, b) (modint)((uint64_t)a * b % M)

modint power_mod(modint a, modint p) {
	modint x = 1;
	while (p) {
		if (p & 1) {
			x = mul(x, a);
		}
		a = mul(a, a);
		p >>= 1;
	}
	return x;
}

modint divide(modint a, modint b) {
	return mul(a, power_mod(b, M - 2));
}

const int N = 3e5 + 64;
modint fa[N];

modint cnk(int n, int k) {
	assert(0 <= k && k <= n && n < N);
	return divide(fa[n], mul(fa[k], fa[n - k]));
}

int main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	fa[0] = 1;
	for (int i = 1; i < N; ++i) {
		fa[i] = mul(fa[i - 1], i);
	}
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
	modint answer = 0;
	for (int x = 0; x <= n && a * x <= k; ++x) {
		ll l = (k - a * x);
		if (l % b) {
			continue;
		}
		int y = l / b;
		if (y < 0 || y > n) {
			continue;
		}
		answer += mul(cnk(n, x), cnk(n, y));
		answer %= M;
	}
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 1408
//package src;
import java.io.*;
//import javafx.util.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main (String[] args)
	 {
	 //code
	 Scanner sc =new Scanner(System.in);
	 int n=sc.nextInt(),k=sc.nextInt();
	 int a[]=new int[n];
	 int dp[]=new int[n];
	 for(int i=0;i<n;i++) {
		 a[i]=sc.nextInt();
	 }
	
	 dp[0]=0;
	 dp[1]=Math.abs(a[1]-a[0]);
	 for(int i=2;i<n;i++) {
		 int min=Integer.MAX_VALUE;
		 for(int k1=1;k1<=k&&k1<=i;k1++) {
		 min=Math.min(Math.abs(a[i]-a[i-k1])+dp[i-k1],min);
		 
		//if(i==9) System.out.print(dp[i]+" "+min+" d");
		 }
		 dp[i]=min;
	 }
	 System.out.print(dp[n-1]);
	 //}
	}
}

Measured memory_bytes: 57864
package main
import "fmt"
func main() {
  var s string
  fmt.Scan(&s)
  n := len(s)
  y := map[string]int{}
  for i:=0;i<n;i++ { y[s[i:i+1]]++ }
  x := ""
  for k,v := range y {
    if v%2 == 1 {
      if x == "" { x = k;continue }
      fmt.Println(-1);return
    }
  }
  t := ""
  z := map[string]int{}
  w := make(map[string][]int)
  for i:=0;i<n;i++ {
    z[s[i:i+1]]++
    if s[i:i+1] == x && z[s[i:i+1]] < (y[s[i:i+1]]+1)/2 ||
    s[i:i+1] != x && z[s[i:i+1]] <= y[s[i:i+1]]/2 { t += s[i:i+1] }
    w[s[i:i+1]] = append(w[s[i:i+1]],i)
  }
  t = t+x+reverse(t)
  bit := NewFenwickTree(n)
  a := make([]int,n)
  z = map[string]int{}
  for i:=0;i<n;i++ {
    a[i] = w[t[i:i+1]][z[t[i:i+1]]]+1
    z[t[i:i+1]]++
  }
  m := int64(0)
  for i:=0;i<n;i++ {
    m += int64(i)-bit.Sum(a[i])
    bit.Add(a[i],1)
  }
  fmt.Println(m)
}
func reverse(s string) string {
  n,r := len(s),[]rune(s)
  for i:=0;i<n-i;i++ { r[i],r[n-i-1] = r[n-i-1],r[i] }
  return string(r)
}
type FenwickTree struct { bit []int64 }
func NewFenwickTree(n int) FenwickTree { return FenwickTree{make([]int64,n)} }
func(b FenwickTree) Add(i int,v int64) {
  for x:=i;x<=len(b.bit);x+=x&-x { b.bit[x-1] += v }
}
func(b FenwickTree) Sum(i int) int64 {
  r := int64(0)
  for x:=i;x>0;x-=x&-x { r += b.bit[x-1] }
  return r
}
func(b FenwickTree) Update(i int,v int64) {
  for x:=i;x<=len(b.bit);x+=x&-x {
    if b.bit[x-1] < v { b.bit[x-1] = v }
  }
}
func(b FenwickTree) Max(i int) int64 {
  r := int64(0)
  for x:=i;x>0;x-=x&-x {
    if r < b.bit[x-1] { r = b.bit[x-1] }
  }
  return r
}

Measured memory_bytes: 11136
#include <stdio.h>
int main(void)
{int A,B,C,D,N,K,S,Y,Z,k,l,tmp;
	long long int x,m,i;
	scanf("%lld",&x);
	m=x/11;
	i=x%11;
	if(i==0)
	printf("%lld",m*2);
	else if(i>=7)
	printf("%lld",m*2+2);
	else
	printf("%lld",m*2+1);
		
	


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

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

constexpr double EPS = 1e-15;

int K, R, L;
double P, E, T;

VT( double ) ps;
double solve( const int k, const double l, const double r )
{
	const double t = ( l + r ) / 2;

	if ( k == K )
	{
		return abs( t - T ) <= E + EPS;
	}

	if ( T < l - E - EPS || r + E + EPS < T )
	{
		return 0;
	}
	if ( T - E - EPS <= l && r <= T + E + EPS )
	{
		return 1;
	}

	if ( T - EPS <= t )
	{
		return P * solve( k + 1, t, r ) + ( 1 - P ) * solve( k + 1, l, t );
	}
	else
	{
		return P * solve( k + 1, l, t ) + ( 1 - P ) * solve( k + 1, t, r );
	}
}

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

	cin >> K >> R >> L;
	cin >> P >> E >> T;

	cout << setprecision( 9 ) << fixed << solve( 0, R, L ) << endl;

	return 0;
}

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

int main()
{
    long long H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
    }
    else {
        cout << (H * W) - (H * W / 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
NMAX = 10**5+1

is_prime = [True]*NMAX
for i in range(2, NMAX):
    if is_prime[i]:
        for j in range(2*i, NMAX, i):
            is_prime[j] = False

sim_2017 = [0]*NMAX
for i in range(3, NMAX, 2):
    if is_prime[i] and is_prime[(i+1)//2]:
        sim_2017[i] += 1
for i in range(1, NMAX):
    sim_2017[i] += sim_2017[i-1]

q = int(input())
for _ in range(q):
    l, r = list(map(int, input().split()))
    ans = sim_2017[r] - sim_2017[l-1]
    print(ans)

Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  auto c = s[k - 1];
  if (c == 'A')
    s[k - 1] = 'a';
  else if (c == 'B')
    s[k - 1] = 'b';
  else
    s[k - 1] = 'c';

  cout << s << endl;
}


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

int main() {
  //input
  int N;
  cin >> N;
  int h[N];
  for(int i=0; i<N; i++){cin >> h[i];}
  
  //main
  int INF = 1e9;
  int memo[N] = {INF};
  memo[0] = 0;
  
  for(int i=0; i<N-1; i++) {
    if(i==0){memo[i+1] = memo[i]+ abs(h[i+1]-h[i]);}
    else memo[i+1] = min( memo[i]+abs(h[i+1]-h[i]), memo[i-1]+abs(h[i+1]-h[i-1]) );
  }
  
  
  //output  
  cout << memo[N-1] << endl;
}

Measured memory_bytes: 1024
import heapq

def main():       
    n,q=(int(x) for x in input().split())
    Q=[[] for i in range(n)]
    for i in range(q):
        query=list(map(int,input().split()))
        if query[0]==0:
            heapq.heappush(Q[query[1]],-1*query[2])
        elif query[0]==1:
            if len(Q[query[1]])!=0:
                print(-1*Q[query[1]][0])
        else:
            if len(Q[query[1]])!=0:
                heapq.heappop(Q[query[1]])

if __name__=='__main__':
    main()



Measured memory_bytes: 13184
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    ans = 0
    for a in range(1, 10**3+1):
        if a ** 2 >= N:
            continue
        b_num = N // a - a
        if a * (N // a) == N:
            b_num -= 1
        ans += b_num
    ans *= 2
    ans += int(math.sqrt(N))
    if int(math.sqrt(N)) ** 2 == N:
        ans -= 1
    print(ans)
main()



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

int main(){
    ll N;
    cin >> N;
    ll ans = (N-1)*N/2;
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector <int>v(3);
  cin >>v[0]>>v[1]>>v[2];
  sort(v.begin(),v.end());
  int a=v[2]-v[1];
  if((v[2]-v[0]-a)%2==0){
    a=a+(v[2]-v[0]-a)/2;
  }else{
    a=a+(v[2]-v[0]-a)/2+2;
  }
cout<<a<<endl;
}


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

int a[100];
int ans=2000000000;

int main(){

    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=-100;i<=100;i++){
        int val=0;
        for(int j=0;j<n;j++){
            val += (i-a[j])*(i-a[j]);
        }
        ans=min(ans,val);
    }
    cout<<ans<<endl;
    
    return 0;
}

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

class Program
{
    static int R;
    static void Main(string[] args)
    {
        var s = new Scanner();

        R = s.ReadInt();

        Solve();
    }

    static void Solve()
    {
        var ans = 3 * Math.Pow(R, 2);
        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int high[N];
    int cnt=0;
    for(int i=0;i<N;i++){
        cin>>high[i];
        if(high[i]>=K)cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> cost(n);
	vector<vector<int>> algo(n, vector<int>(m));
	for (int i = 0; i < n; ++i) {
		cin >> cost[i];
		for (int j = 0; j < m; ++j) {
			cin >> algo[i][j];
		}
	}
	int min_res = 2e9;
	for (int bit = 0; bit < (1 << n); ++bit) {
		vector<int> knowledge(m, 0);
		int res = 0;
		for (int i = 0; i < n; ++i) {
			if (bit & (1 << i)) {
				res += cost[i];
				for (int j = 0; j < m; ++j) {
					knowledge[j] += algo[i][j];
				}
			}
		}
		int min_k = *min_element(knowledge.begin(), knowledge.end());
		if (min_k >= x) {
			min_res = min(min_res, res);
		}
	}
	if (min_res == 2e9) cout << -1;
	else cout << min_res;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<int> bl(n);
  vector<int> wh(n);
  int cnt=0;
  rep(i,n){
    if(s[i]=='#') cnt++;
    bl[i]=cnt;
  }
  cnt=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='.') cnt++;
    wh[i]=cnt;
  }  

  int ans=999999;
  rep(i,n-1){
    chmin(ans,bl[i]+wh[i+1]);
  }

  chmin(ans,wh[0]);
  chmin(ans,bl[n-1]);

  cout << ans << endl;
}

Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%3d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int l[101];
int n, K, v[200], ans = 0, A[200], b;

int main() {
    cin >> n >> K;
    rep(i, n) cin >> v[i];
    rep(i, min(n, K) + 1)
        rep(j, min(i, K - i) + 1)
            rep(k, i) {
                b = 0;
                rep(l, i) {
                    A[l] = v[(l - k + n) % n];
                    b += A[l];
                }
                sort(A, A + i);
                rep(l, j) {
                    if (A[l] < 0)
                        b -= A[l];
                }
                ans = max(ans, b);
            }
    cout << ans;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second

ll f(ll b, ll n){
   if(n<b)return n;
    return f(b,n/b)+n%b;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,s ;
    cin>>n>>s;
    ll d = n-s;
    if(d==0){
        cout<<n+1<<endl;
        return 0;
    }
    if(d<0){
        cout<<-1<<endl;
        return 0;
    }
    vector<ll>ans;
    for(ll i=1;i*i<=d;i++){
        if(d%i)continue;
        ll trt = f(i+1,n);
        if(trt==s)ans.pb(i+1);
        trt = f(d/i+1,n);
        if(trt==s)ans.pb(d/i+1);
    }
    sort(ans.begin(),ans.end());
    if(ans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
L1=set()
Ln=set()
for i in range(m):
  a,b=map(int,input().split())
  if a==1 or b==1:
    L1.add(a if b==1 else b)
  if a==n or b==n:
    Ln.add(a if b==n else b)
print('POSSIBLE' if len(L1&Ln)!=0 else 'IMPOSSIBLE')

Measured memory_bytes: 18892
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main() {
	int N;
	cin >> N;
	if (N < 1000) cout << "ABC"<<endl;
	else cout << "ABD" << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

ll a[100005];
ll b[100005];
ll c[100005];

struct tri{
    ll i, j, k;
    ll val() const{
        return a[i] + b[j] + c[k];
    }
    bool operator < (const tri & d) const{
        if(val() < d.val()) return 1;
        if(d.val() < val()) return 0;
        if(i < d.i) return 1;
        if(d.i < i) return 0;
        if(j < d.j) return 1;
        if(d.j < j) return 0;
        return k < d.k;
    }
};

map <tri, int> ima;

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    for(ll i=1; i<=x; i++){
        cin >> a[i];
    }
    for(ll i=1; i<=y; i++){
        cin >> b[i];
    }
    for(ll i=1; i<=z; i++){
        cin >> c[i];
    }
    sort(a+1, a+1+x);
    reverse(a+1, a+1+x);
    sort(b+1, b+1+y);
    reverse(b+1, b+1+y);
    sort(c+1, c+1+z);
    reverse(c+1, c+1+z);
    priority_queue <tri> q;
    q.push({1, 1, 1});
    while(k--){
        while(ima[q.top()]) q.pop();
        tri g = q.top();
        cout << g.val() << "\n";
        q.pop();
        ima[g] = 1;
        if(g.i < x){
            q.push({g.i+1, g.j, g.k});
        }
        if(g.j < y){
            q.push({g.i, g.j+1, g.k});
        }
        if(g.k < z){
            q.push({g.i, g.j, g.k+1});
        }
    }
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b){
    if(a < b) return gcd(b, a);
    else if(b == 0) return a;
    else return gcd(b, a % b);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int T[110];
    rep(i, N) cin >> T[i];
    int ans = 1;
    rep(i, N) {
        ans = ans / gcd(ans, T[i])  * T[i];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int>x(n);
    for (int i = 0; i < n; i++) cin >> x.at(i);
    long long ans = 1 << 18;
    for (int p = 1; p <= 100; p++) {
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            tmp += pow((x.at(i) - p), 2);
        }
        ans = min(ans, (long long)tmp);
    }
    cout << ans << endl;
}

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

public class S
{

    private const long DP_INIT_MINUS1 = -1;

    private static long[] dp;
    private static List<long>[] paths;


    public static void Main()
	{
		/*
        var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        var N = input[0];
        var M = input[1];
        */
        var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        var N = input[0];
        var M = input[1];

        solver(N,M);
    }

    public static void solver(long nodeCount, long pathCount){

        /*
            dp[nodeCount]


            // メモか再帰らしい
        
         */

        dp = new long[nodeCount+1];
        paths = new List<long>[nodeCount+1];

        long[] input;
        long from, dest;

        for(int i = 0; i <= nodeCount; i++){
            dp[i] = DP_INIT_MINUS1;
            paths[i] = new List<long>();
        }

        for(int i = 0; i < pathCount; i++){
            input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            paths[input[0]].Add(input[1]);
        }

        for(int i = 0; i < nodeCount; i++){
            explore(i+1);
        }

        


        Console.WriteLine(dp.Max());


    }

    private static long explore(long from){

        if(dp[from] != DP_INIT_MINUS1){
            return dp[from];
        }

        if(paths[from].Count == 0){
            dp[from] = 0;
            return 0;  // 閉路を含まないなら必ずいきどまりがある。
        }

        long max = int.MinValue;
        foreach(var tgt in paths[from]){
            max = Math.Max(max, explore(tgt)+1);
        }
        dp[from] = max;
        return dp[from];

    }

}

Measured memory_bytes: 32768
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           ll a , b , c , d;
           cin >> a >> b >> c >> d;
           
           ll ans = max(a * c , max(a * d , max(b * c , b * d)));
           cout << ans << endl;
        }
    }



Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	private static void solve(FastScanner fr) {
		int n = fr.nextInt();
		int m = fr.nextInt();
		Map<Integer, Set<Integer>> group = new HashMap<>();
		int max = 1;
		for(int i=0; i<m; i++) {
			int a = fr.nextInt();
			int b = fr.nextInt();
			Set<Integer> ag = group.get(a);
			Set<Integer> bg = group.get(b);
			if(ag==null && bg==null){
				Set<Integer> set = new HashSet<>();
				set.add(a);
				set.add(b);
				group.put(a, set);
				group.put(b, set);			
			} else if(ag==null && bg!=null){
				bg.add(a);
				group.put(a, bg);
			} else if(ag!=null && bg==null){
				ag.add(b);
				group.put(b, ag);
			} else if(ag!=null && bg!=null){
				if(ag!=bg) {
					Set<Integer> bigger = ag.size()>bg.size() ? ag : bg;
					Set<Integer> smaller = ag.size()>bg.size() ? bg : ag;
					for(int v : smaller) {
						group.put(v, bigger);
						bigger.add(v);
					}
				}
			}
			max = Math.max(max, group.get(a).size());
		}
		sout(max);
	}
    public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = 1;
		// int n = fs.nextInt();
		while (n-- > 0)	{
			solve(fs);
        }
    }

    private static void sout()          { System.out.println();  }
    private static void sout(String s)  { System.out.println(s); }
    private static void sout(int s)     { System.out.println(s); }
    private static void sout(long s)    { System.out.println(s); }
    private static void sout(double s)  { System.out.println(s); }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }
			return st.nextToken();
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


Measured memory_bytes: 99308
#include<bits/stdc++.h>
using namespace std;
map<int,int>q;
long long h,m;
char s;
int main()
{
    scanf("%lld %c %lld",&h,&s,&m);
    if(s=='+')
    {
        printf("%lld\n",h+m);
    }
    else
    {
         printf("%lld\n",h-m);
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	//0030 start
	//0050 cording end
	int ans, w,h;
	//0が右
	int [][] vx = {
			{1,1,1,1,  1, 2, 2,  2,3},
			{-1,-1,-1,-1,-1, -2,-2,-2, -3}
	};
	int [][] vy = {
			{2,1,0,-1,-2, 1, 0, -1,0},
			{2,1,0,-1,-2   , 1, 0, -1,0}
	};
	int INF = 1 << 24;
	
	class C implements Comparable<C>{
		int x, y, cost;
		int digit;
		public C(int x, int y, int digit, int cost) {
			this.x = x;
			this.y = y;
			this.digit = digit;
			this.cost = cost;
		}
		@Override
		public int compareTo(C o) {
			if(this.cost < o.cost) return -1;
			if(this.cost > o.cost) return 1;
			return 0;
		}
		@Override
		public String toString() {
			return "C [x=" + x + ", y=" + y + ", cost=" + cost + ", digit="
					+ digit + "]";
		}
		
	}

	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			PriorityQueue<C> open = new PriorityQueue<C>();
			int [][] data = new int[h][w];
			//System.out.println("w = " + w + " h = " + h);
			for(int i = 0; i < h; i++){
				for(int j = 0;j < w; j++){
					char c =sc.next().charAt(0);
					switch(c){
					case 'X':
						data[i][j] = INF;
						break;
					case 'S':
						open.add(new C(j, i, 0, 0));
						open.add(new C(j, i, 1, 0));
						data[i][j] = INF;
						break;
					case 'T':
						data[i][j] = 0;
						break;
					default :
						data[i][j] = c - '0';
					}
				}
			}
			
			int [][][] close = new int[h][w][2];
			for(int i = 0; i < h; i++){
				for(int j = 0 ; j < w; j++){
					close[i][j][0] = INF;
					close[i][j][1] = INF;
				}
			}
			
			int ans = -1;
			while(! open.isEmpty()){
				C now = open.poll();
				//System.out.println(now);
				//System.out.println("y = " + now.y + " x= " + now.x + "cost  = " + now.cost);
				if(data[now.y][now.x] == 0){
					
					ans = now.cost;
					break;
					
				}
				for(int i = 0; i < vx[now.digit].length; i++){
					int xx = now.x + vx[now.digit][i];
					int yy = now.y + vy[now.digit][i];
					if(! isOK(xx, yy)) continue;
					if(data[yy][xx] == INF) continue;
					int nextcost = now.cost + data[yy][xx];
					int nextdigit = (now.digit + 1) % 2;
					if(close[yy][xx][nextdigit] <= nextcost) continue;
					//System.out.println("next = " + new C(xx, yy, nextdigit, nextcost));
					open.add(new C(xx, yy, nextdigit, nextcost));
					close[yy][xx][nextdigit] = nextcost;
				}
			}
			System.out.println(ans);
			
		}//while end
	}

	private boolean isOK(int xx, int yy) {
		if(0 <= xx && xx < w && 0 <= yy && yy < h){
			return true;
		}
		return false;
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

int n;
long long int a[51];
int p = 0, q = 0;
int main()
{
    a[0] = 0;
    cin >> n;
    for(int i = 1; i < n + 1; i++)
    {
        cin >> a[i];
        if(a[i] >= 0 && a[i] >= a[p])
        {
            p = i;
        }
        if(a[i] <= 0 && a[i] <= a[q])
        {
            q = i;
        }
    }
    if(p != 0 && q != 0 && a[p] + a[q] >= 0)
    {
        cout << 2*(n-1) << endl;
        for(int i = 1; i <= n-1; i++)
        {
            a[i+1] = a[i] + a[p] + a[i+1];
            cout << i << " " << i+1 << endl;
            cout << p << " " << i+1 << endl;
        }
    }
    else if(p != 0 && q != 0 && a[p] + a[q] <= 0)
    {
        cout << 2*(n-1) << endl;
        for(int i = n; i >= 2; i--)
        {
            a[i-1] = a[i] + a[q] + a[i-1];
            cout << i << " " << i-1 << endl;
            cout << q << " " << i-1 << endl;
        }
    }
    else if(q == 0)
    {
        cout << 2*(n-1) << endl;
        for(int i = 1; i <= n-1; i++)
        {
            a[i+1] = a[i] + a[p] + a[i+1];
            cout << i << " " << i+1 << endl;
            cout << p << " " << i+1 << endl;
        }
    }
    else if(p == 0)
    {
        cout << 2*(n-1) << endl;
        for(int i = n; i >= 2; i--)
        {
            a[i-1] = a[i] + a[q] + a[i-1];
            cout << i << " " << i-1 << endl;
            cout << q << " " << i-1 << endl;
        }
    }
    return 0;
    
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

Ch += 1
Cw += 1
Dh += 1
Dw += 1

lim = 10**6

S = ['#'*(W+4)]
S.append('#'*(W+4))
for k in range(H):
  S.append('##' + input() + '##')
S.append('#'*(W+4))
S.append('#'*(W+4))

foo = [[-1 for _ in range(W+4)] for _ in range(H+4)]
for k in range(2, H+2):
  for j in range(2, W+2):
    if S[k][j] == '.':
      foo[k][j] = lim
    

foo[Ch][Cw] = 0

now = deque([])
new = deque([(Ch, Cw)])
while len(new) > 0:
  item = new.pop()
  now.append(item)
  x = item[0]
  y = item[1]
  if foo[x+1][y] == lim:
    foo[x+1][y] = 0
    new.append((x+1, y))
  if foo[x][y+1] == lim:
    foo[x][y+1] = 0
    new.append((x, y+1))
  if foo[x-1][y] == lim:
    foo[x-1][y] = 0
    new.append((x-1, y))
  if foo[x][y-1] == lim:
    foo[x][y-1] = 0
    new.append((x, y-1))


ans = 0
while foo[Dh][Dw] == lim:
  if len(now) == 0:
    print(-1)
    exit() 
  ans += 1
  while len(now) > 0:
    item = now.pop()
    x = item[0]
    y = item[1]
    if foo[x+2][y+2] > ans:
      foo[x+2][y+2] = ans
      new.append((x+2, y+2))
    if foo[x+2][y+1] > ans:
      foo[x+2][y+1] = ans
      new.append((x+2, y+1))
    if foo[x+2][y] > ans:
      foo[x+2][y] = ans
      new.append((x+2, y))
    if foo[x+2][y-1] > ans:
      foo[x+2][y-1] = ans
      new.append((x+2, y-1))
    if foo[x+2][y-2] > ans:
      foo[x+2][y-2] = ans
      new.append((x+2, y-2))
    if foo[x+1][y+2] > ans:
      foo[x+1][y+2] = ans
      new.append((x+1, y+2))
    if foo[x+1][y-2] > ans:
      foo[x+1][y-2] = ans
      new.append((x+1, y-2))
    if foo[x][y+2] > ans:
      foo[x][y+2] = ans
      new.append((x, y+2))
    if foo[x][y-2] > ans:
      foo[x][y-2] = ans
      new.append((x, y-2))
    if foo[x-2][y+2] > ans:
      foo[x-2][y+2] = ans
      new.append((x-2, y+2))
    if foo[x-2][y+1] > ans:
      foo[x-2][y+1] = ans
      new.append((x-2, y+1))
    if foo[x-2][y] > ans:
      foo[x-2][y] = ans
      new.append((x-2, y))
    if foo[x-2][y-1] > ans:
      foo[x-2][y-1] = ans
      new.append((x-2, y-1))
    if foo[x-2][y-2] > ans:
      foo[x-2][y-2] = ans
      new.append((x-2, y-2))
    if foo[x-1][y+2] > ans:
      foo[x-1][y+2] = ans
      new.append((x-1, y+2))
    if foo[x-1][y-2] > ans:
      foo[x-1][y-2] = ans
      new.append((x-1, y-2))
    if foo[x-1][y-1] > ans:
      foo[x-1][y-1] = ans
      new.append((x-1, y-1))
    if foo[x-1][y+1] > ans:
      foo[x-1][y+1] = ans
      new.append((x-1, y+1))
    if foo[x+1][y+1] > ans:
      foo[x+1][y+1] = ans
      new.append((x+1, y+1))
    if foo[x+1][y-1] > ans:
      foo[x+1][y-1] = ans
      new.append((x+1, y-1))
      
  while len(new) > 0:
    item = new.pop()
    now.append(item)
    x = item[0]
    y = item[1]
    if foo[x+1][y] == lim:
      foo[x+1][y] = 0
      new.append((x+1, y))
    if foo[x][y+1] == lim:
      foo[x][y+1] = 0
      new.append((x, y+1))
    if foo[x-1][y] == lim:
      foo[x-1][y] = 0
      new.append((x-1, y))
    if foo[x][y-1] == lim:
      foo[x][y-1] = 0
      new.append((x, y-1))
print(ans)

Measured memory_bytes: 99548
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(call(1, 0, 0, 0, 0, n));

    }

    private static int call(int base, int c3, int c5, int c7, int num, int n) {
        int res = 0;
        if(c3>0 && c5>0 && c7>0 && num <= n) res++;
        if(base == 1000000000) return res;
        res += call(base * 10, c3 + 1, c5, c7, num + 3 * base, n);
        res += call(base * 10, c3, c5+1, c7, num + 5 * base, n);
        res += call(base * 10, c3, c5, c7+1, num + 7 * base, n);
        return res;
    }

}


Measured memory_bytes: 23252
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
void solve()
{
    vector<ll> dp;
	ll k=-130;
	while(k<130)
	{
	dp.push_back(k*k*k*k*k);
	k++;
	}
	ll t;
	cin>>t;
	bool flag=false;
	ll ans1=0;
	ll ans2=0;
	int cnt=0;
	for (int i = 0; i <=dp.size(); ++i)
	{
	    cnt++;
		for(int l=0;l<=dp.size();l++)
		{
		    cnt++;
			ll diff=dp[i]-dp[l];
			if(diff==t)
			{
				ans1=i-130;
				ans2=l-130;
				flag=true;
				break;
			}
		}	
			if(flag)
				break;		
	}
	if(cnt<-1) return ;
	cout<<ans1<<" "<<ans2<<endl;
}
int main()
{
	
	solve();
}

Measured memory_bytes: 3632