akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b-1; i >= a; i--)
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

vector<vector<int> > G;

const int MAX_N = 1e5 + 10;
const int INF = 1e9;

int N;
//vector<int> G[MAX_N];
int used1[MAX_N], used2[MAX_N], used3[MAX_N], dist1[MAX_N], dist2[MAX_N], dist3[MAX_N];
bool ng[MAX_N];

void bfs1(int s){
    for(int i = 0; i < N; i++) dist1[i] = 1e9;

    queue<int> Q;
    Q.push(s);
    dist1[s] = 0;

    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        cerr << v << endl;
        used1[v] = 1;
        for(auto nv: G[v]){
            if(used1[nv] == 0){
                dist1[nv] = dist1[v] + 1;
                Q.push(nv);
                //used1[nv] = true;
            }
        }
    }
}

void bfs2(int s){
    for(int i = 0; i < N; i++) dist2[i] = 1e9;

    queue<int> Q;
    Q.push(s);
    dist2[s] = 0;

    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        cerr << v << endl;
        used2[v] = 1;
        for(auto nv: G[v]){
            if(used2[nv] == 0){
                dist2[nv] = dist2[v] + 1;
                Q.push(nv);
                //used1[nv] = true;
            }
        }
    }
}

void bfs3(int s){
    //for(int i = 0; i < N; i++) dist2[i] = 1e9;

    queue<int> Q;
    Q.push(s);
    dist3[s] = 0;

    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        cerr << v << endl;
        used3[v] = 1;
        for(auto nv: G[v]){
            if(used3[nv] == 0 && !ng[nv]){
                dist3[nv] = dist3[v] + 1;
                Q.push(nv);
                //used1[nv] = true;
            }
        }
    }
}

signed main(){
    int u, v; cin >> N >> u >> v;u--, v--;
    G.resize(N);
    rep(i, 0, N-1){
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bfs1(v);
    bfs2(u);
    //rep(i, 0, N) ng[i] = false;
    rep(i, 0, N){
        if(dist1[i] > dist2[i]) ng[i] = false;
        else ng[i] = true;
    }
    rep(i, 0, N) dist3[i] = INF;
    bfs3(u);
    int ans = 0;
    rep(i, 0, N) if(dist3[i] != INF){
        ans = max(ans, dist1[i]);
    }
    cout << ans - 1 << endl;

}

Measured memory_bytes: 8320
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define KDNGU ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first

using namespace std;

typedef long long LL;
typedef long double LD;

const int N = 3e3 + 9, M = 3e3 + 9, OO = 0x3f3f3f, MOD = 1e9 + 7;

LD dp[N][M];

int main(){
    int n;
    cin >> n;
    LD probability[n + 1];
    for (int i = 1; i <= n; ++i) cin >> probability[i];

    dp[1][0] = 1 - probability[1];
    dp[1][1] = probability[1];

    for (int i = 2; i <= n; ++i)
        for (int j = 0; j <= i; ++j){
            dp[i][j] = dp[i - 1][j] * (1 - probability[i]);
            if (j)
                dp[i][j] += dp[i - 1][j - 1] * (probability[i]);
        }
    LD ans = 0;
    for (int i = (n + 1) / 2; i <= n; ++i)
        ans += dp[n][i];
    cout << fixed << setprecision(10) << ans;
}
/*
    GOOD LUCK :*
*/


Measured memory_bytes: 139776
from collections import defaultdict
N, P = map( int, input().split())
A = defaultdict( int)
S = set()
ans = 1
if N == 1:
    ans = P
else:
    T = P
    for i in range(2, int(P**(1/2)) + 1):
        while P%i == 0:
            P //= i
            S.add(i)
            A[i] += 1
    if T == P:
        A[T] += 1
        S.add(T)
    for s in S:
        if A[s] >= N:
            ans *= s**(A[s]//N)
print(ans)

Measured memory_bytes: 3444
N, C, K = map(int, input().split())

T = sorted([int(input()) for _ in range(N)])

x = T[0]
p = 1
b = 1
for i in range(1, N):
    if T[i] <= x + K and p < C:
        p += 1
    else:
        x = T[i]
        b += 1
        p = 1
print(b)

Measured memory_bytes: 8280
#include<bits/stdc++.h>
using namespace std;
int minCostdp(int arr[],int n){
 int dp[n+1]={0};
 dp[1] = 0;
 for(int i=2;i<=n;i++){
    int op1,op2;
    op1 = op2 = INT_MAX;
    if(i-1>0){
      op1 = abs(arr[i]-arr[i-1]) + dp[i-1];
    }
    if(i-2>0){
      op2 = abs(arr[i]-arr[i-2]) + dp[i-2];
    }
    dp[i] = min(op1,op2);
 }
 return dp[n];
}
int main(){
 int n;
 cin>>n;
 int arr[n+1]={0};
 for(int i=1;i<=n;i++){
    cin>>arr[i];
 }
 cout<<minCostdp(arr,n);
}


Measured memory_bytes: 1024
function main(args) {
  	var max = 0;
	var input = args.split(/\s/);
  	var a = input[0] * 1;
  	var b = input[1] * 1;
  	if (a <= b) {
      	max += b;
      	b--;
    } else {
    	max += a;
      	a--;
    }
  	if (a <= b) {
      	max += b;
      	b--;
    } else {
    	max += a;
      	a--;
    }
  	console.log(max);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22204
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;

  
  ll u[n-1],v[n-1],w[n-1];
  for(int i=0;i<n-1;i++)cin >> u[i] >> v[i] >> w[i];

  vector<vector<vector<ll>>> G(n);
  for(int i=0;i<n-1;i++){
    G[u[i]-1].push_back({v[i]-1,w[i]});
    G[v[i]-1].push_back({u[i]-1,w[i]});
  }


  vector<ll> color(n,-1);
  color[0]=0;

  queue<ll> que;
  que.push(0);


  while(!que.empty()){
    ll x=que.front();
    que.pop();

    for(int i=0;i<G[x].size();i++){
      if(color[G[x][i][0]]!=-1)continue;
      color[G[x][i][0]]=abs(G[x][i][1]%2-color[x]);
      que.push(G[x][i][0]);
    }

  }

  for(int i=0;i<n;i++)cout << color[i] << endl;

}

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


#define ll long long
#define ull unsigned ll
#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF (int)1e9
#define EPS 1e-9
#define forall(i, a, b) for(int i=a; i < b; i++)
#define all(a) a.begin(), a.end()
#define in(a,b) ( (b).find(a) != (b).end())
#define pb push_back
#define fill(a,constant) memset(a, constant, sizeof(a))
#define mp make_pair
#define checkbit(n,b) ( (n >> b) & 1)
#define sort(a) sort(all(a))
#define PI acos(-1.0)
#define DEBUG 0

int main ()

{
    fast;
    
    int n;
    cin >> n;
    
    int answer = (n/500)*500*2 + ((n-(n/500)*500)/5)*5;
    
    if (answer < 0) cout << 0 << endl;
    else cout << answer << endl;

    return 0;
}

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

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = in.nextInt();
    }
    Arrays.sort(A);
    System.out.println(A[N / 2] - A[N / 2 - 1]);
  }
}

Measured memory_bytes: 50556
#include<stdio.h>
#include<stdlib.h>
main(){
int N,K,*p;
int i,j,temp,sum=0;
scanf("%d",&N);
scanf("%d",&K);
p=(int *) malloc (sizeof(int)*N);

for(i=0;i<N;i++){
scanf("%d",&p[i]);
}
for(i=0;i<N;i++){
for(j=0;j<N-1;j++){
if(p[j]>p[j+1]){
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}

for(i=0;i<K;i++){
sum+=p[i];
}
printf("%d",sum);return 0;
return 0;
}






Measured memory_bytes: 1704
number_of_flowers = int(input())

intended_height = [int(x) for x in input().split(' ')]

times = 0

stop = False

while True:
    times = times + 1
    watered = False
    # print('ready water')
    for i in range(0, len(intended_height)):
        if intended_height[i] != 0:
            intended_height[i] = intended_height[i] - 1
            # print(intended_height)
            watered = True
        else:
            if watered:
                break
    # print(sum(intended_height))
    if not watered:
        times -= 1
        break

print(times)


Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;


int main() {
	string s;
	cin >> s;
	if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = [0] * 100007
count = 0
total = 0

for i in range(N):
    if A[i] < 100007:
        C[int(A[i])] += 1

for i in range(1, len(C)):
    count += C[i]
    if C[i] < i:
        total += C[i]
    if C[i] > i:
        total += C[i] - i

print(total + N - count)

Measured memory_bytes: 14492
#include<stdio.h>
#include<math.h>
int main(){
  double x1,x2,y1,y2;
  double len;

  scanf("%lf %lf",&x1,&y1);
  scanf("%lf %lf",&x2,&y2);
  x2 -= x1;
  y2 -= y1;

  len = sqrt(x2*x2 + y2*y2);
  printf("%.4f\n",len);
  return 0;
}



Measured memory_bytes: 2148
n = int(input())
a = list(map(int, input().split()))
sums=[0 for i in range(n)]
sums[0]=a[0]
for i in range(1,n):
    sums[i] = sums[i-1]+a[i]

res=[0 for i in range(n-1)]

for i in range(0,n-1):
    res[i] = abs(2*sums[i]-sums[-1])
        
print(min(res))
  

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

const int MAX_V = 1e2;
vector<int> graph[MAX_V];
bool used_v[MAX_V], used_e[MAX_V][MAX_V];
int ord[MAX_V], lowlink[MAX_V];
int k = 0;
int N, M;

void dfs(int v){
    used_v[v] = true;
    ord[v] = lowlink[v] = k++;
    for(int i = 0; i < graph[v].size(); i++){
        if(!used_v[graph[v][i]]){
            used_e[v][graph[v][i]] = true;
            dfs(graph[v][i]);
            lowlink[v] = min(lowlink[v], lowlink[graph[v][i]]);
        }else if(!used_e[graph[v][i]][v]){
            lowlink[v] = min(lowlink[v], ord[graph[v][i]]);
        }
    }
    return;
}

/*
辺e(u,v)が橋　== ord[u] < lowlink[v] である
↑
これはe(u,v)(uがvの親とする)を取り除いた時に、グラフは二つに分かれるが
、これが後退辺によって繋がれていれば橋ではない。
後退辺は先祖と子孫の関係にある頂点同士を結んでいるのでDFS木について
上の関係式が得られる.
以下では橋の数を数えている。(O(V + E)で得られる)
*/

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b; a--,b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(0);
    int ans = 0;
    for(int v = 0; v < N; v++){
        for(int j = 0; j < graph[v].size(); j++){
            int nv = graph[v][j];
            if(ord[v] < ord[nv]){
                if(ord[v] < lowlink[nv]) ans++;
            }
        }
    }
    cout << ans <<endl;
}

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

using namespace std;


typedef long long ll;

const int MAX = 1e5+5;
ll dp[MAX+MAX];

int n , W;



int main()
{

    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>W;

    for( int j = 0 ; j < MAX+MAX ; j++ )
        dp[j] = LONG_LONG_MAX;


    dp[0] = 0;
    ll ans = 0;
    for( int i = 1; i <= n ; i++ ) {


        ll w , v;
        cin>>w>>v;

        for( int j = MAX ; j >= 0 ; j-- ) {

            if( dp[j] != LONG_LONG_MAX ) {

                dp[j+v] = min( dp[j+v] , dp[j]+w );
                if( dp[j+v] <= W )
                ans = max( ans , j+v );

            }

        }

    }

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


Measured memory_bytes: 1792
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int N = 0, T = 0, tr = 0, cr = 0, i = 0, route = 10001;

    scanf("%d %d", &N, &T);

    for (i = 0; i < N; i++) {
        scanf("%d %d", &cr, &tr);
        route = ((cr < route) && (tr <= T)) ? cr : route;
    }

    if (route == 10001) {
        printf("TLE\n");
    } else{
        printf("%d\n", route);
    }
    return 0;
}


Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a,b = MAP()
print(max(a+b, a-b, a*b))

Measured memory_bytes: 60012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

vector<ll> memo(87, -1);

ll L(ll i) {
    if(memo[i] != -1) {
        return memo[i];
    }

    if(i == 0) {
        memo[i] = 2;
    } else if(i == 1) {
        memo[i] = 1;
    } else {
        memo[i] = L(i - 1) + L(i - 2);
    }

    return memo[i];
}

int main() {
    ll N;
    cin >> N;
    cout << L(N) << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  string s;
  cin >> n;
  map<string, int> m;

  for(int i = 0; i < n; i++){
    cin >> s;
     if(m.count(s)){
      m[s]++;
    }else{
      m[s] = 1;
    }
  }

  int max_i = 0;
  for(auto p : m){
    max_i = max(max_i, p.second);
  }
  vector<string> vec;
  for(auto p : m){
    if(max_i == p.second){
      vec.push_back(p.first);
    }
  }
  sort(vec.begin(), vec.end());
  for(auto ss : vec){
    cout << ss << endl;
  }
}

Measured memory_bytes: 26868
/******************************************
* AUTHOR : AMAN SAXENA *
* Nick : blue-meth *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

ll amanpower(ll a, ll b) {
    ll r = 1;
    while (b > 0) 
    {
        if (b & 1) r = r * a;
        a = a * a;
        b >>= 1;
    }
    return r;
}


ll amanlcm(ll a, ll b)
{
     return a*(b/__gcd(a,b));
}


//********* CODE START *********

void solve()
{
    int n;
  	cin >> n;
  	cout << ((n >= 30)? "Yes":"No");
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    
    // test();
    solve();

    
    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int r1,c1,r2,c2;
int mo = 1e9 + 7;
int F[2000025];
int IF[2000025];

int expo( int a, int b ){
	if ( b == 0 ) return 1;
	int half = expo(a,b/2);
	half = ( 1LL * half * half ) % mo;
	if (b & 1) half = ( half * 1LL * a )% mo;
	return half;
}

LL C( int a, int b ){
	LL ans = F[a];
	ans = ( ans * 1LL * IF[b]) % mo;
	ans = ( ans * 1LL * IF[a-b]) % mo;
	return ans;
}

LL f( int r, int c ){
	LL ans = 0;
	for ( int i = 0; i <= c && r >= 1 ; i++ ){
		ans = ( ans + i + 1 ) % mo;
	}
	// printf("= %lld\n",ans);
	for ( int i = 2; i <= r; i++ ){
		ans = (ans+ C(i+c+1,c)) % mo;
	}
	ans = ( ans + c + 1) % mo;
	// printf("%d %d %lld\n",r,c,ans);
	return ans;
}

int main(){
	F[0] = 1;
	IF[0] = 1;
	for ( int i = 1; i <= 2000000+5; i++ ) {
		F[i] = (F[i-1] * 1LL * i) % mo;
		IF[i] = expo(F[i],mo-2);
	}
	scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
	
	// printf("%lld\n",f(1,1));

	LL ans = f(r2,c2);
	ans = ( ans + f(r1-1,c1-1) ) % mo;
	ans = ( ans - (f(r2,c1-1)%mo) + mo ) % mo; 
	ans = ( ans - (f(r1-1,c2)%mo) + mo ) % mo;
	ans = ( ans % mo);
	ans = ( ans + mo ) % mo;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;



int main()
{
    FAST
    ll a,b,c,k;cin>>a>>b>>c>>k;
    while(b<=a) b*=2,k--;
    while(c<=b) c*=2,k--;
    if(k<0) cout<<"No\n";
    else cout<<"Yes\n";
}


Measured memory_bytes: 3636
N = int(input())
result = N
for i in range(N+1):
    c = 0
    t = i
    while t > 0:
        c += t % 6
        t //= 6
    t = N - i
    while t > 0:
        c += t % 9
        t //= 9
    result = c if result > c else result

print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<typename T>
struct BinaryIndexedTree{
    vector<T> data;
    int sz;

    BinaryIndexedTree(int n){
        sz = n + 1;
        data.assign(sz, 0);
    }

    void add(int i, T x){
        ++i;
        while(i < sz){
            data[i] += x;
            i += i & -i;
        }
    }

    // [0, i] の区間和
    T sum(int i){
        T res = 0;
        ++i;
        while(i > 0){
            res += data[i];
            i -= i & -i;
        }
        return res;
    }

    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }

    // val 以上を満たす 0-indexed の位置を返す
    int lower_bound(T val){
        // if(val <= 0)    return -1;
        int res = 0;
        int n = 1;
        while(n < sz)   n <<= 1;
        for(int k = n >> 1; k > 0; k >>= 1){
            if(res + k < sz && data[res + k] < val){
                val -= data[res + k];
                res += k;
            }
        }
        return res;     // 1-indexed であれば、res + 1 を返す
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<P> table(n);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        table[i] = P(a, b);
    }
    sort(table.begin(), table.end(), [](const P& p1, const P& p2){
        if(p1.second == p2.second){
            return p1.first < p2.first;
        }
        return p1.second > p2.second;
    });

    BinaryIndexedTree<int> bit(m + 5);
    for(int i = 1; i <= m; ++i) bit.add(i, 1);
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(table[i].first > m)  continue;
        int sum = bit.sum(m) - bit.sum(table[i].first - 1);
        if(sum == 0)    continue;
        int p = bit.lower_bound(bit.sum(table[i].first - 1) + 1);
        bit.add(p, -1);
        ans += table[i].second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(0, min(B, D) - max(A, C)) << endl;

    return 0;
}


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


ll gcd(ll x,ll y)
{
    ll r;
    if(x < y){
        swap(x,y);
    }
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main()
{
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll k = a[0];
    for(int i = 1; i < n; i++){
        k = gcd(k,a[i]);
    }
    cout << k;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n>=s.size()){
        cout<<s;
    }
    else{
        for(int i=0; i<n ;i++){
            cout<<s[i];

        }
         cout<< "...";

    }
    cout<< endl;

    }




Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<lint> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
lint f(const lint a)
{
    lint res = 0;
    if (a % 2 == 0)
    {
        int cc = a / 2;
        if (cc % 2 == 0)
        {
            res = a;
        }
        else
        {
            res = (1 ^ a);
        }
    }
    else
    {
        if (((a - 1) / 2) % 2 == 0)
        {
            res = 1;
        }
        else
        {
            res = 0;
        }
    }
    return res;
}
int main()
{
    lint a, b;
    cin >> a >> b;
    lint aa = f(a - 1);
    lint bb = f(b);
    lint ans;
    ans = aa ^ bb;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sin = new Scanner(System.in);
		
		int a, b, c;
		a = sin.nextInt();
		b = sin.nextInt();
		c = sin.nextInt();
		
		if(a < b && b < c){
			System.out.println("Yes");
		
		}else{
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 26304
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int n,k;
int v[200005];


signed main(){
    FASTER;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>v[i];
    
    for(int j=1;j<=min(44ll,k);j++){
        int pre[n+2]={0};
        for(int i=1;i<=n;i++){
            pre[max(i-(v[i]),1ll)]+=1;
            pre[min(i+(v[i])+1,n+1)]-=1;
        }
        for(int i=1;i<=n;i++)pre[i]+=pre[i-1];
        for(int i=1;i<=n;i++)v[i]=min(pre[i],n);
    }
    for(int i=1;i<=n;i++){
        cout<<v[i]<<" ";
    }
}

Measured memory_bytes: 6724
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
    long long r,l;
    int a[100000];
    int n;
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    r=2; l=2;
    for(int i=1;i<=n;i++){
        if(l%a[n-i]!=0 && (((l/a[n-i]+1)*a[n-i]) > r)){
            cout << "-1" << endl;
            return 0;
          
        }else{
        l = l%a[n-i]==0 ? l : (l/a[n-i]+1)*a[n-i];
        r = r/a[n-i] * a[n-i] + a[n-i] -1;
       
        }
    }
    cout << l << " " << r << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.buffer.readline

N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7
SIZE = 10 ** 6 + 1

g1 = [1, 1]      # 元テーブル
g2 = [1, 1]      # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル

def comb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

for i in range(2, SIZE + 1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def comb(N, X):
    bunbo = 1
    for x in range(X):
        bunbo = (bunbo * (N - x)) % MOD
    return (bunbo * g2[X]) % MOD

answer = (pow(2, N, MOD) - 1 - comb(N, A) - comb(N, B)) % MOD

print(answer)

Measured memory_bytes: 125056
#create date: 2020-07-20 13:38

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    d = na()
    d.sort()
    dl = d[n//2-1]
    dr = d[n//2]
    if dl == dr:
        print(0)
    else:
        print(dr - dl)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20624
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    string s0,s1;
    cin >> s0 >> s1;
    reverse(s1.begin(),s1.end());
    cout << (s0==s1 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

bool match(char x, char y) {
    return (x == '?' || y == '?' || x == y);
}

void solve() {
	string a, b, c; cin >> a >> b >> c;
    int n = (int)a.size(), m = (int)b.size(), l = (int)c.size();
    int ans = n + m + l;
	bool ab[10000], bc[10000], ac[10000];
	rep(i, 10000) {
		ab[i] = 1;
		rep(j, m) {
			if(i + j - 4000 >= 0 && i + j - 4000 < n) {
				if(!match(b[j], a[i + j - 4000])) {
					ab[i] = 0;
				}
			}
		}
	}
	rep(i, 10000) {
		bc[i] = 1;
		rep(j, l) {
			if(i + j - 4000 >= 0 && i + j - 4000 < m) {
				if(!match(c[j], b[i + j - 4000])) {
					bc[i] = 0;
				}
			}
		}
	}
	rep(i, 10000) {
		ac[i] = 1;
		rep(j, l) {
			if(i + j - 4000 >= 0 && i + j - 4000 < n) {
				if(!match(c[j], a[i + j - 4000])) {
					ac[i] = 0;
				}
			}
		}
	}

	rep(i, 10000) {
		rep(j, 10000) {
			int mi = min({i, j, 4000}), ma = max({4000 + n, i + m, j + l});
			if(ab[i] && ac[j] && bc[4000 + j - i]) {
				chmin(ans, ma - mi);
			}
		}
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int N,M;
vector<int> G[100010];
bool used[100010];

deque<int> ans;

void dfs1(int v) {
    used[v] = true;
    REP(i,G[v].size()) {
        if (!used[G[v][i]]) {
            ans.push_front(G[v][i]);
            dfs1(G[v][i]);
            return;
        }
    }
}

void dfs2(int v) {
    used[v] = true;
    REP(i,G[v].size()) {
        if (!used[G[v][i]]) {
            ans.push_back(G[v][i]);
            dfs2(G[v][i]);
            return;
        }
    }
}

int main() {

    cin >> N >> M;

    int A,B;
    REP(i,M) {
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    REP(i,100010) used[i] = false;
    used[A] = used[B] = true;
    ans.push_back(A);
    ans.push_back(B);

    dfs1(A);
    dfs2(B);

    cout << ans.size() << endl;

    while (ans.size() != 0) {
        cout << ans.front() << " ";
        ans.pop_front();
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 6784
import fractions
a,b = map(int,input().split())
c = fractions.gcd(a,b)

ans = [1]
while c % 2 == 0:
  ans.append(2)
  c //= 2
i = 3
while c >= i ** 2:
  if c % i == 0:
    ans.append(i)
    c //= i
  else:
    i += 2
if c != 1:
  ans.append(c)
print(len(set(ans)))

Measured memory_bytes: 5300
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	vector<ll> asum(n+1), bsum(m+1);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++){
		asum[i] = asum[i-1] + a[i-1];
	}
	for (int i = 1; i <= m; i++){
		bsum[i] = bsum[i-1] + b[i-1];
	}
	int ans = 0;
	for (int i = 0; i <= n; i++){
		if (k >= asum[i]){
			ll temp = k - asum[i] + 1;
			auto it = lower_bound(bsum.begin(), bsum.end(), temp);
			int tmp = i + it - bsum.begin() - 1;
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll maze[1005][1005];

void show_table(ll I, ll J) {
  for (ll i = 0; i <= I; i++) {
    for (ll j = 0; j <= J; j++) {
      if (maze[i][j] == INF) {
        cout << "@ ";
      } else {
        cout << maze[i][j] << " ";
      }
    }
    cout << "" << endl;
  }
  cout << "" << endl;
}

int main() {
  ll H, W;
  scanf("%lld %lld", &H, &W);

  ll Ch, Cw;
  scanf("%lld %lld", &Ch, &Cw);
  Ch--;
  Cw--;

  ll Dh, Dw;
  scanf("%lld %lld", &Dh, &Dw);
  Dh--;
  Dw--;

  for (ll y = 0; y < H; y++) {
    string s;
    cin >> s;

    for (ll x = 0; x < s.size(); x++) {
      if (s[x] == '#') {
        maze[y][x] = -1;
      } else {
        maze[y][x] = INF;
      }
    }
  }
  // show_table(H, W);

  // priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, less<pair<ll, pll>>>
  //     que;  // -> 9,8,7,...

  deque<pll> que;

  que.push_front(make_pair(Ch, Cw));
  maze[Ch][Cw] = 0;

  for (;;) {
    if (que.empty()) {
      break;
    }

    auto pos = que.front();
    que.pop_front();
    ll y = pos.first;
    ll x = pos.second;

    // cout << "y:" << (y) << ",x:" << (x) << endl;

    ll c = maze[y][x];

    for (ll oy = -2; oy <= 2; oy++) {
      for (ll ox = -2; ox <= 2; ox++) {
        ll ty = y + oy;
        ll tx = x + ox;

        ll dist = abs(oy) + abs(ox);
        if (dist == 0) {
          continue;
        }
        if (ty >= 0 && ty < H && tx >= 0 && tx < W && maze[ty][tx] > c) {
          if (dist == 1) {
            maze[ty][tx] = c;
            que.push_front(make_pair(ty, tx));
          } else {
            maze[ty][tx] = c + 1;
            que.push_back(make_pair(ty, tx));
          }
        }
      }
    }
  }

  // show_table(H, W);

  ll a = maze[Dh][Dw];

  if (a == INF) {
    cout << (-1) << endl;
  } else {
    cout << (a) << endl;
  }
}


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

using namespace std;

int main() {

    int n;
    cin>>n;
    string s, t;
    cin>>s;
    cin>>t;
    string ans;
    for (int i = 0;i < (int)s.size();++i) {
        ans.append(1, s[i]);
        ans.append(1, t[i]);
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int n;
string s;
bool F;

int main(){
	cin >> n;
	REP(i, n){
		F = 0;
		cin >> s;
		if (s[0] == '>'&&s[s.size() - 1] == '~'){
			if (s[1] == '\''){
				int icnt = 0;
				bool f = 1;
				FOR(j, 2, s.size() - 1){
					if (s[j] == '='){
						if (f){
							icnt++;
						}
						else{
							icnt--;
						}
					}
					else if (s[j] == '#'){
						if (f)f = 0;
						else {
							F = 1;
							break;
						}
					}
					else{
						F = 1;
						break;
					}
				}
				if (F == 0 && icnt == 0 && s.size() >= 6){
					cout << "A" << endl;
				}
				else {
					cout << "NA" << endl;
				}
			}
			else if (s[1] == '^'&&s.size() % 2 == 0 && s.size() >= 6
				&& s[s.size() - 1] == '~'&&s[s.size() - 2] == '~'){
				FOR(j, 2, s.size() - 2){
					if (j % 2 == 0){
						if (s[j] != 'Q'){
							F = 1;
							break;
						}
					}
					else{
						if (s[j] != '='){
							F = 1;
							break;
						}
					}
				}
				if (F){
					cout << "NA" << endl;
				}
				else{
					cout << "B" << endl;
				}
			}
			else {
				cout << "NA" << endl;
			}
		}
		else{
			cout << "NA" << endl;
		}
	}
}

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

using namespace std;

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

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

  double sum = 0;
  for(int i = 0; i < n; i++) {
    sum += a[i];
  }
  int ave = round(sum / n);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    ans += (a[i] - ave) * (a[i] - ave);
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b,c;
  
  scanf("%d %d %d", &a, &b, &c);
  if((a!=b && b!=c && a!=c) || (a==b && b==c)){
    printf("No");
  }
  else
    printf("Yes");


  return 0;

}






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

#define ll long long
using namespace std;


void solve()
{
	int N;
	cin>>N;
	vector<ll> A(N);
	for(auto &a: A)
		cin>>a;

	ll money = 1000;
	ll low = A[0];
	for(int i=0; i<N; ++i)
	{
		if(A[i]<=low)
			low=A[i];
		else
		{
			ll stocks = money/low;
			money += stocks*(A[i]-low);
			low = A[i];
		}
		
	}
	cout<<money<<endl;
}


int main()
{
	//xyz();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int T;
	//cin>>T;
	//while(T--)
		solve();
		
	return 0;
}


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

string s;
long long n,dp[100005];

void check(int i)
{
    if(s[i]=='d'&&s[i+1]=='r'&&s[i+2]=='e'&&s[i+3]=='a'&&s[i+4]=='m')
    {
        dp[i+4]=1;
        if(s[i+5]=='e'&&s[i+6]=='r')
            dp[i+6]=1;
    }
    if(s[i]=='e'&&s[i+1]=='r'&&s[i+2]=='a'&&s[i+3]=='s'&&s[i+4]=='e')
    {
        dp[i+4]=1;
        if(s[i+5]=='r')
            dp[i+5]=1;
    }
}

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

    cin>>s;
    n=s.size();
    s+="xxxxxxxxxx";
    check(0);
    for(int i=0;i<n;i++)
    {
        if(dp[i]==1)
            check(i+1);
    }

    if(dp[n-1]==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}


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

int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int tmp = 0;
  tmp = X;
  X = Y;
  Y = tmp;
  tmp = X;
  X = Z;
  Z = tmp;
  cout << X << " ";
  cout << Y << " ";
  cout << Z << " ";
  return 0;
}

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

using namespace std;

int n;

int main() {
  scanf("%d", &n);
  int nx = 0;
  int ny = 0;
  int ns = 0;
  for (int i = 0; i < n; ++i) {
    int s, x, y;
    scanf("%d %d %d", &s, &x, &y);
    int ds = s - ns;
    int dt = abs(nx - x) + abs(ny - y);
    if (dt > ds) {
      puts("No");
      return 0;
    }
    ds -= dt;
    if (ds & 1) {
      puts("No");
      return 0;
    }
    nx = x;
    ny = y;
    ns = s;
  }
  puts("Yes");
  return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int[] A;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.A = new int[N+2];
        for (int i = 1; i <= N; i++) {
        	this.A[i] = sc.nextInt();
        }
    }
    
    //解答処理
    private List<Integer> solve() {
    	List<Integer> answer = new ArrayList<Integer>();
    	int sum = 0;
    	
    	for (int i = 1; i < N+2; i++) {
    		//全て訪れたときの総額を求める
    		sum += Math.abs(A[i] - A[i-1]);
    	}
    	
    	for (int i = 1; i < N+1; i++) {
    		//A[i] ⇒ 観光を取りやめる場所
    		//求める金額 = 総金額 - A[i+1]からA[i]に行くための金額 - A[i]からA[i+1]に行くための金額 +　A[i-1]からA[i+1]に行くための金額
    		int ans = sum - Math.abs(A[i]-A[i-1]) - Math.abs(A[i+1]-A[i]) + Math.abs(A[i+1]-A[i-1]);
    		answer.add(ans);
    	}
        
        return answer;
    }
    
    //出力
    public void show(List<Integer> answer) {
    	for (int i = 0; i < answer.size(); i++) {
    		System.out.println(answer.get(i));
    	}
    }

}


Measured memory_bytes: 64532
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
int dp[6060][6060];
i64 oksa[6060], oksb[6060], oksc[6060], oksd[6060];

int main()
{
	scanf("%d%d", &N, &M);

	for (int i = 0; i <= 2 * N; ++i) dp[0][i] = 0;
	dp[0][0] = 1;

	for (int i = 1; i <= 2 * M; ++i) {
		for (int j = 0; j <= 2 * N; ++j) {
			dp[i][j] = ((j > 0 ? dp[i - 1][j - 1] : 0) + (j != 2 * N ? dp[i - 1][j + 1] : 0)) % MOD;
		}
	}

	for (int i = 0; i <= 2 * M; ++i) {
		int s = 0;
		for (int j = 0; j <= 2 * N; ++j) {
			ADD(s, dp[i][j]);
		}
		oksa[i] = s;
	}

	for (int i = 0; i <= 2 * N; ++i) dp[0][i] = 0;
	dp[0][0] = 1;

	for (int i = 1; i <= 2 * M; ++i) {
		dp[i][0] = 0;
		for (int j = 1; j <= 2 * N; ++j) {
			dp[i][j] = ((j > 0 ? dp[i - 1][j - 1] : 0) + (j != 2 * N ? dp[i - 1][j + 1] : 0)) % MOD;
		}
	}

	for (int i = 0; i <= 2 * M; ++i) {
		int s = 0;
		for (int j = 0; j <= 2 * N; ++j) {
			ADD(s, dp[i][j]);
		}
		oksb[i] = s;
		//printf("%d %lld %lld\n", i, oksa[i], oksb[i]);
	}

	for (int i = 0; i <= 2 * N; ++i) dp[0][i] = 0;
	dp[0][0] = 1;

	for (int i = 1; i <= 2 * M; ++i) {
		for (int j = 0; j <= 2 * N - 1; ++j) {
			dp[i][j] = ((j > 0 ? dp[i - 1][j - 1] : 0) + (j != 2 * N - 1? dp[i - 1][j + 1] : 0)) % MOD;
		}
	}

	for (int i = 0; i <= 2 * M; ++i) {
		int s = 0;
		for (int j = 0; j <= 2 * N - 1; ++j) {
			ADD(s, dp[i][j]);
		}
		oksc[i] = s;
	}

	for (int i = 0; i <= 2 * N; ++i) dp[0][i] = 0;
	dp[0][0] = 1;

	for (int i = 1; i <= 2 * M; ++i) {
		dp[i][0] = 0;
		for (int j = 1; j <= 2 * N - 1; ++j) {
			dp[i][j] = ((j > 0 ? dp[i - 1][j - 1] : 0) + (j != 2 * N - 1 ? dp[i - 1][j + 1] : 0)) % MOD;
		}
	}

	for (int i = 0; i <= 2 * M; ++i) {
		int s = 0;
		for (int j = 0; j <= 2 * N - 1; ++j) {
			ADD(s, dp[i][j]);
		}
		oksd[i] = s;
		//printf("%d %lld %lld\n", i, oksa[i], oksb[i]);
	}

	i64 ret = 0;
	for (int i = 0; i <= 2 * M; ++i) {
		if (i % 2 == 0) {
			ADD(ret, oksa[i] * oksb[2 * M - i]);
		} else {
			ADD(ret, oksc[i] * oksd[2 * M - i]);
		}
	}

	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 143616
import java.io.*;
import java.util.Scanner;


public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int H = 0;
        int W = 0;
        String w = "";
        String h = "";
        int judge = 0;
        while(judge == 0){
            H = scan.nextInt();
            W = scan.nextInt();
            //w,hは繰り返し使うので、その都度初期化する
            if(judge == 0){
                w = "";
                h = "";
            }
            if(H == 0 && W == 0){
                judge = 1;
            }else{
                for(int i = 0;i <= W - 1;i++){    
                   switch(i % 2){
                       case 0:
                           w = w + "#";
                           h = h + ".";
                           break;
                       case 1:
                           w = w + ".";
                           h = h + "#";
                           break;
                       }
                   }
                }
                for(int I = 0;I <= H - 1;I++){
                    switch(I % 2){
                      case 0:
                          System.out.println(w);
                          break;
                      case 1:
                          System.out.println(h);
                          break;
                    }
                    if(I == H - 1){
                        System.out.println("");
                    }
            } 
        }
    }
}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNIQUE(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

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

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N;
string S;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> S;
  N = SZ(S);
  stack<int> st;
  int ans = 0;
  REP(i, N) {
    if (S[i] == '1') {
      if (!st.empty() && st.top() == 0) {
        st.pop();
        ans += 2;
      } else {
        st.EMP(1);
      }
    } else {
      if (!st.empty() && st.top() == 1) {
        st.pop();
        ans += 2;
      } else {
        st.EMP(0);
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int main(){
	int e;
	while( cin >> e , e ){
		int ans = 1e+8;
		
		for(int y=0 ; y <= 1000 ; y++ ){
			for(int z=0 ; z <= 100 ; z++ ){
				int x = e - y*y - z*z*z;
				if( x < 0 ) continue;
				ans = min( ans , x+y+z );
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 868
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*N for _ in [0]*N]
for i in range(N):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(M)]
ans = 0
 
for a,b,c in d:
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
for a,b,c in d:
        if dp[a-1][b-1] != c:
            ans += 1
print(ans)


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

using ll = long long;

int main() {
    int n; cin >> n;
    vector<ll> cnt(n), sum(n + 1);
    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        a--;
        ++sum[++cnt[a]];
    }
    for(int i = 0; i < n; ++i) {
        sum[i + 1] += sum[i];
    }

    for(int k = 1; k <= n; ++k) {
        ll lb = 0, ub = n + 1;
        while(ub - lb > 1) {
            const ll mid = (ub + lb) / 2;
            (sum[mid] >= k * mid ? lb : ub) = mid;
        }
        cout << lb << endl;
    }
}


Measured memory_bytes: 5504
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	if (N == 1&&M==1) {
		cout << 1 << endl;
		return 0;
	}
	if (N == 1) {
		cout << M - 2 << endl;
		return 0;
	}
	if (M == 1) {
		cout << N - 2 << endl;
		return 0;
	}
	cout << (N - 2)*(M - 2) << endl;
	return 0;
}

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

int main(){
int A,B;
  cin>>A>>B;
  
  int count=0;
  for(int i=A; i<=B; i++){
   if(i/10000==i%10 && i/1000%10==i/10%10){count++;}
  }
  
  cout<<count;
}

Measured memory_bytes: 256