akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 400010
#define mod 1000000007
#define ll long long
using namespace std;
ll tree[N<<2];
void insert(int u,int l,int r,int p,int v)
{
	if(l==r){tree[u]=(tree[u]+v)%mod;return;}
	int mid=(l+r)>>1;
	if(p<=mid) insert(u<<1,l,mid,p,v);
	else insert(u<<1|1,mid+1,r,p,v);
	tree[u]=(tree[u<<1]+tree[u<<1|1])%mod;
}
ll answer(int u,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return tree[u];
	int mid=(l+r)>>1;
	ll ans=0;
	if(L<=mid) ans+=answer(u<<1,l,mid,L,R);
	if(R>mid) ans+=answer(u<<1|1,mid+1,r,L,R);
	return ans%mod;
}
struct node{
	int x,v,id;
	bool operator <(const node a)const{return x<a.x;}
}p[N];
bool cmp(node a,node b){return a.v<b.v;}
struct ques{
	int l,r;
	bool operator <(const ques a)const{return r==a.r?l<a.l:r<a.r;}
}q[N];
int l[N],r[N],f[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].v);
	
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)p[i].id=i;
	sort(p+1,p+n+1);
	int res=n+1;
	for(int i=n;i;i--)
	{
		res=min(res,p[i].id);
		q[p[i].id].l=res;
	}
	res=0;
	for(int i=1;i<=n;i++)
	{
		res=max(res,p[i].id);
		q[p[i].id].r=res;
	}
	sort(q+1,q+n+1);
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		int p=q[i].l==1;
		(p+=answer(1,1,n,max(q[i].l-1,1),q[i].r))%=mod;
		insert(1,1,n,q[i].r,p);
		if(q[i].r==n) (ans+=p)%=mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 12544
n = int(input())
ab = {i: [] for i in range(n)}
for j in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    ab[a].append((b, j))
    ab[b].append((a, j))


def dfs(a, b, d=[], c=-1):
    if a == b:
        return d
    for i in ab[a]:
        if i[0] == c:
            continue
        e = dfs(i[0], b, d + [i[1]], a)
        if len(e) != 0:
            return set(e)
    return set()


m = int(input())
ms = []
for _ in range(m):
    u, p = [int(i) - 1 for i in input().split()]
    ms.append(dfs(u, p))

ans = 0
for i in range(1 << m):
    k = 0
    a = set()
    for j in range(m):
        if (i >> j) & 1 == 1:
            k += 1
            a |= ms[j]
    if k % 2 == 1:
        ans += 2 ** (n - 1 - len(a))
    elif k != 0:
        ans -= 2 ** (n - 1 - len(a))
            
print(2**(n-1)-ans)




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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 310;
int d[N][N][N];

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	string s;
	int K;
	getline(cin, s);
	cin >> K;
	memset(d, 0, sizeof(d));
	int n = sz(s);
	int ans = 0;
	forn(k, K + 1) {
    	forn(i, n + 1) {
    		forn(j, n + 1) {
    			if (i + j > n) {
					continue;    				
    			}
    			if (i > 0) {
    			 	umx(d[i][j][k], d[i - 1][j][k]);
    			}
    			if (j > 0) {
    			 	umx(d[i][j][k], d[i][j - 1][k]);
    			}
    			if (i > 0 && j > 0 && s[i - 1] == s[n - j]) {
    				umx(d[i][j][k], d[i - 1][j - 1][k] + 1);
    			}
    			if (k > 0 && i > 0 && j > 0) {
    				umx(d[i][j][k], d[i - 1][j - 1][k - 1] + 1);
    			}
    			umx(ans, 2 * d[i][j][k] + (i + j < n));
    		}
    	}
	}
	if (sz(s) == 1) {
		cout << 1 << endl;
		return 0;
	}
	cout << ans << endl;


	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int N, cnt;
    cnt = 0;
    ll A[205];
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    while(true) {
        for(int i = 0; i < N; i++) {
            if(A[i] % 2 != 0) {
                cout << cnt << endl;
                exit(0);
            } else {
                A[i] = A[i] / 2;
            }
        }
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,60) {
    ll x = 0;
    rep(j,n) if (a[j]>>i&1) ++x;
    ll now = x*(n-x)%mod;
    rep(j,i) now = now*2%mod;
    ans += now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

int dp[101][10001] = {};

int main(void) {
    int N, W;
    cin >> N >> W;
    vector<int> v(N);
    vector<int> w(N);
    for(int i=0; i<N; ++i)
        cin >> v[i] >> w[i];

    for(int i=0; i<N; ++i) {
        for(int j=0; j<=W; ++j) {
            dp[i+1][j] = dp[i][j];
            if (w[i] <= j)
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
        }
    }
#if 0
    for(int i=0; i<=N; ++i) {
        for(int j=0; j<=W; ++j) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
#endif

    cout << dp[N][W] << endl;;
    return 0;
}



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

#define int long long
#define F first
#define S second
#define pb push_back
#define pii pair <int,int>

using namespace std;

const int N=3309,MOD=998244353;
int dp[N][N];

int32_t main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    for(int i=a;i<=c;i++){
        for(int j=b;j<=d;j++){
            if(i==a && j==b) continue ;
            dp[i][j]=(dp[i][j-1]*i+dp[i-1][j]*j-dp[i-1][j-1]*(i-1)*(j-1)+MOD*MOD)%MOD;
        }
    }
    cout<<dp[c][d];
    return 0;
}


Measured memory_bytes: 81056
#include<iostream>
using namespace std;
int main(){
 bool t=false;
  int u;
  int A,B;
  cin>>A>>B;
  for ( int i=0; i<50000; i++){
    if ( i*8/100==A && i/10==B){
      u=i;
      t=true;
      break;}
  }
  if(t) cout<<u<<endl;
  else cout<<-1<<endl;
}
  
      

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



namespace Test1 {

    class ClassMain {




        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line) ;
                if (n == 0) { break; }

                int z = 0;
                int min = n;
                for (; z * z * z <= n; z++) {
                    int m = z + make_x_y(n - z * z * z);
                    if ( m < min) {
                        min = m;
                    }
                }
               
                Console.WriteLine(min);






            }
        }

        public static int make_x_y(int n) {
            int x = 0, y = 1;
            for (; y * y <= n; y++) {
            }
            y--;
            n -= y * y;
            x = n;
            return (x + y);
        }

        


    }
}

Measured memory_bytes: 5764
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

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

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	return os;
}

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Q;
	cin >> N >> Q;

	// t = x - D_i と x = X_j (S_j <= t <= T_j) が交わるD_iの範囲を計算しておく
	vector <pair<pair<int, int>, int>> stx(N);
	for (int i = 0; i < N; i++) {
		int s, t, x;
		cin >> s >> t >> x;
		stx[i] = { { max(0, s - x), t - x }, x };
	}
	sort(stx.begin(), stx.end());

	set<pair<int,int>> st;
	vector<int> ans(Q, INF);
	auto first = stx.begin();
	auto last = stx.end();
	for (int i = 0; i < Q; i++) {

		int d;
		cin >> d;

		// add
		last = upper_bound(stx.begin(), stx.end(), make_pair(make_pair(d, INF), INF));
		for (auto itr = first; itr != last; itr++) st.emplace(itr->second, itr->first.second);
		first = last;
		DMP(first - stx.begin());

		DMP(st);
		//erase
		vector<pair<int, int>> memo;
		for (const auto &e : st) {
			if (d < e.second) {
				chmin(ans[i], e.first);
				break;
			}
			else memo.emplace_back(e);
		}
		DMP(memo);
		for (const auto e : memo) st.erase(e);
		DMP(st);

	}

	for (const auto &e : ans) cout << (e == INF ? - 1 : e) << "\n";

	return 0;
}


Measured memory_bytes: 15000
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 3;
ll a,b,g;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b;
    g = (b - 1) / (a - 1) + ((b - 1) % (a - 1) == 0 ? 0 : 1);
    cout<<g;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  ll ans = 0;
  while(a%2==0&&b%2==0&&c%2==0){
    ll a1 = a/2;
    ll b1 = b/2;
    ll c1 = c/2;
    a = b1+c1;
    b = a1+c1;
    c = a1+b1;
    ans++;
    if(ans>50000000){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp;
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    int N, K;

    cin >> N >> K;

    int c = K;
    int i;
    for (i = 1; c <= N; i++) {
        c *= K;
    }

    cout << i;

    return 0;
}



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

int main(){
    int n;
    cin >> n;
    int min = pow(10,9) + 7;
    int max = -1;

    for(int i  = 0; i < n; ++i){
        int a;
        cin >> a;
        if(a < min) min = a;
        if(a > max) max = a;
    }

    cout << max - min << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	priceA := a * n
	priceB := b
	if priceA < priceB {
		fmt.Println(priceA)
	} else {
		fmt.Println(priceB)
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 3e5;
int N, f[MAXN];

int main() {
  std::cin >> N;
  std::map<int,int> m;
  for(int i = 0; i < N; ++i) { int A; std::cin >> A; ++m[A]; }
  int n = 0;
  std::map<int,int> d;
  for(auto s: m) ++d[s.second];
  int64_t sum = 0;
  for(int64_t x = 0; x < N; ++x) {
    if(d.count(x) > 0) sum += x*d[x];
    f[x] = sum/(x+1);
  }
  sum = d[N];
  for(int x = N-1; x >= 0; --x) {
    f[x] += sum;
    if(d.count(x) > 0) sum += d[x];
  }
  int ans = N;
  for(int k = 1; k <= N; ++k) {
    ans = std::min(ans, N/k);
    while(ans > 0 && k > f[ans-1]) --ans;
    std::cout << ans << std::endl;
  }
  return 0;
}


Measured memory_bytes: 15488
import sys
N = int(input())
S = input()
M = N // 2

if N % 2 != 0:
  print('No')
  sys.exit()

else:
  for i in range(0,M):
    if S[i] != S[i + M]:
      print('No')
      sys.exit()
    
  print('Yes')

Measured memory_bytes: 3060
#! /usr/bin/env python3

import sys
from fractions import Fraction

class PotentializedUnionFind(object):
    def __init__(self, n):
        self.tree = [-1 for i in range(n)]
        self.cost = [Fraction(1) for i in range(n)]

    def find(self, v):
        if self.tree[v] < 0: return v
        r = self.find(self.tree[v])
        self.cost[v] *= self.cost[self.tree[v]]
        self.tree[v] = r
        return r

    def unite(self, u, v, w):
        ru = self.find(u)
        rv = self.find(v)

        # w /= self.cost[u] / self.cost[v]
        # w *= self.cost[v] / self.cost[u]
        w = w * Fraction(self.cost[v], self.cost[u])
        if -self.tree[ru] >= -self.tree[rv]:
            ru, rv = rv, ru
            u, v = v, u
            w = 1 / w

        if ru == rv:
            if w != 1:
                # print(f'uniting {u} and {v} with {w}')
                raise ValueError('tsurai')

            return False

        self.tree[rv] += self.tree[ru]
        self.tree[ru] = rv
        self.cost[ru] = w
        return True

def main():
    sys.setrecursionlimit(300000)
    n, m = map(int, input().split())

    puf = PotentializedUnionFind(n)
    for i in range(m):
        a, b, x = map(int, input().split())
        a -= 1
        b -= 1
        try:
            puf.unite(a, b, Fraction(x))
        except ValueError:
            print('No')
            return 0

    print('Yes')
    return 0

main()



Measured memory_bytes: 39344
n = int(input())
money = 1000
maisuu = 0
value = list(map(int, input().split()))
for i in range(0, n-1):
    if value[i] < value[i+1]:
        maisuu += money//value[i]
        money %= value[i]
    else:
        money += maisuu * value[i]
        maisuu = 0
money += maisuu * value[n-1]
print(money)

Measured memory_bytes: 9188
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    first = int(readline())

    ans = first - 1
    p_max = 1

    for _ in range(N - 1):
        cur = int(readline())
        if cur <= p_max:
            continue
        if cur == p_max + 1:
            p_max = cur
        else:
            ans += (cur - 1) // (p_max + 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73744
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,a[100000],b[100000],ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		ans+=(b[i]-a[i])+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
 
typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;
const int MAX=(1<<14)-1;
mouse Q[MAX+1];
int s,num;

mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;

char in[16];
int inum[3];
 
main(){
  int s=0;
  int nums=0;
  do{
    read(0,in+s,1);
    if(isdigit(in[s]))inum[nums]=inum[nums]*10+in[s]-'0';
    else nums++;
  }while(in[s++]!='\n');
  h=inum[0];
  w=inum[1];
  n=inum[2];

  short maxch[h][w];
  char ku[h][w];
  
  rep(i,h)
    read(0,ku[i],w+1);


 
 
  rep(i,h)rep(j,w){
    if(ku[i][j]=='S')cx=i,cy=j;
    maxch[i][j]=-1;
  }
 
 
  Q[s+num++]=(mouse){cx,cy,0,0};
  maxch[cx][cy]=0;
 
  while(true){
    t=Q[s++&MAX];
    num--;
    cx=t.x,cy=t.y,cost=t.cost;
    ch=t.ch;
 
    rep(i,4){
      nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
      if(ku[nx][ny]=='X')continue;
      nch=ch;
      if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
        nch=ch+1;
      }
 
      if(maxch[nx][ny]>=nch)continue;
      if(nch==n){
        printf("%d\n",cost+1);
        return 0;
      }
      maxch[nx][ny]=nch;
      Q[s+num++&MAX]=(mouse){nx,ny,cost+1,nch};
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i=0; i<m; i++){
        cin >> a[i];
    }
    int ans=accumulate(a.begin(), a.end(), 0);
    if(ans<=n){
        cout << n-ans << endl;
    }
    else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3672
import math

a, b, c = [float(i) for i in input().split()]

c = math.radians(c)
h = math.sin(c) * b
s = a*h/2

q = math.sqrt(pow(a,2) + pow(b,2) - 2 * a * b * math.cos(c))

l = a + b + q

print(s)
print(l)
print(h)


Measured memory_bytes: 5696
import java.util.*;
    public class Main {
    	public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
    		// トレーニング回数の入力
    		int N = sc.nextInt();
		// すぬけくんの初期パワー
		long IniPwr = 1;
		//10^9+7
		double a = Math.pow(10,9) + 7;
		// N回トレーニングしたあとのパワー
		for (int i=1 ; 0<i && i<=N ; i++){
			IniPwr = (long)(IniPwr * (long)i)%(long)a;
		}
    		// あまりを出力
    		System.out.println(IniPwr);
    	}
    }

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

typedef long long ll;

const ll mod = 1e9 + 7;

ll dp[100005][2];//0 = まだいける 1 = きつきつ

int main() {
  string s;

  cin >> s;

  int n = s.size();
  dp[0][1] = 1;
  
  for(int i = 0; i < n; i++) {
    dp[i+1][0] = (dp[i+1][0] + (3 * dp[i][0] % mod)) % mod;
    if(s[i] == '1') {
      dp[i+1][1] = (dp[i+1][1] + (2 * dp[i][1] % mod)) % mod;
      dp[i+1][0] = (dp[i+1][0] + dp[i][1]) % mod;
    }
    else {
      dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % mod;
    }
  }

  cout << (dp[n][0] + dp[n][1]) % mod << endl;
  
}
      
    
  
  


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; ++i) cin >> B[i];

  for (int i = 0; i <= N - M; ++i) {
    for (int ii = 0; ii <= N - M; ++ii) {
      bool isValid = true;
      for (int j = 0; j < M; ++j) {
	for (int k = 0; k < M; ++k) {
	  if (A[i + j][k + ii] != B[j][k]) isValid = false;
	}
      }
      if (isValid) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}



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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef unordered_map<ll, ll> ump;

const ll mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, x;
	cin >> a >> b >> c >> x;
	ll ans = 0;
	REP(i, a+1){
		REP(j, b+1){
			REP(k, c+1){
				if (500*i + 100*j + 50*k == x){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i,f=0;
    cin>>s;
    for(i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            f=1;
            break;
        }
    }
    cout<<(f?"Bad":"Good")<<endl;
}


Measured memory_bytes: 3604
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部構造体 - 値情報
typedef struct Val {
	int miVal;													// 値
	int miNo;													// 初期位置 0～
} Val;

// 内部変数
static Val sz1Val[D_ARRAY_MAX];									// 配列
static int siACnt;												// 配列数
static int si1Pos[D_ARRAY_MAX];									// ソート後位置

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ソート関数 - 値昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	Val *lzpVal1 = (Val *)pzpVal1;
	Val *lzpVal2 = (Val *)pzpVal2;

	// 値昇順
	if (lzpVal1->miVal > lzpVal2->miVal) {
		return(1);
	}
	else if (lzpVal1->miVal < lzpVal2->miVal) {
		return(-1);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列取得
	for (i = 0; i < siACnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &sz1Val[i].miVal);
#else
		fscanf(stdin, "%d", &sz1Val[i].miVal);
#endif

		// 初期位置
		sz1Val[i].miNo = i;
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// ソート
	qsort(sz1Val, siACnt, sizeof(Val), fSortFnc);

	// ソート後位置セット
	for (i = 0; i < siACnt; i++) {
		si1Pos[sz1Val[i].miNo] = i;
	}

	// 中間位置
	int liCNo = siACnt / 2;

	// 結果
	for (i = 0; i < siACnt; i++) {

		// ソート後位置
		if (si1Pos[i] < liCNo) {								// 前半
			sprintf(lc1Out, "%d\n", sz1Val[liCNo].miVal);
		}
		else {													// 後半
			sprintf(lc1Out, "%d\n", sz1Val[liCNo - 1].miVal);
		}

		// 結果表示
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
		if (strcmp(lc1Buf, lc1Out)) {
			siRes = -1;
		}
#else
		printf("%s", lc1Out);
#endif
	}

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 4448
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N - 1));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N - 1; j++) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    vector<int> cnt(N, 0);
    int ans = 0;
    time_t s, t;
    time(&s);
    while(1){
        ans++;
        int flag2 = 0;
        time(&t);
        if(t - s > 0){
            cout << N * (N - 1) / 2 << endl;
            return 0;
        } 
        vector<int> used(N, 0);
        for(int i = 0; i < N; i++){
            int ind = A[i][cnt[i]];
            if(used[i] == 1 || used[ind] == 1 || cnt[i] == N - 1) continue;
            if(A[ind][cnt[ind]] == i){
                cnt[i]++;
                cnt[ind]++;
                used[i] = 1;
                used[ind] = 1;
                flag2 = 1;
            }
        }
        if(flag2 == 0){
            cout << -1 << endl;
            return 0;
        }
        int flag = 0;
        for(int i = 0; i < N; i++){
            if(cnt[i] != N - 1) flag = 1;
        }
        if(flag == 0) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7508
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#define INF 0x3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		
		String S = s.nextLine();
		String ans = "";
		
		for(int i = 0; i< S.length(); i++){
			if(Character.isUpperCase(S.charAt(i))){
				ans += Character.toLowerCase(S.charAt(i));
			}else if(Character.isLowerCase(S.charAt(i))){
				ans += Character.toUpperCase(S.charAt(i));
			}else{
				ans += S.charAt(i);
			}
		}
		System.out.println(ans);
	}
}


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    string s; cin >> s;
    int n = s.size();
    ll dp[n+1][13]; rep(i,n+1) rep(j,13) dp[i][j] = 0;
    dp[0][0] = 1;
    int d = -1;
    rep(i,n) {
        d = s[i]-'0';
        if (d == 15) {
            rep(d,10) {
                rep(j,13) {
                    dp[i+1][(10*j+d)%13] += dp[i][j];
                }
            }
            rep(j,13) dp[i+1][j] %= mod;
        } else {
            rep(j,13) {
                dp[i+1][(10*j+d)%13] = (dp[i][j]+dp[i+1][(10*j+d)%13])%mod;
            }

        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 13864
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
int ans;

string S;
int N;

void dfs(vector<int> v, int tmp){
    vector<int> u[26];
    for(int i = 0; i < v.size(); i++){
        if(v[i]+1 >= N) continue;
        int c = S[v[i]+1] - 'a';
        if(true){
            if(v[i]+1 < N) u[c].push_back(v[i]+1);
            if(u[c].size() >= 2) {
                if(u[c][0]+tmp-1 < v[i]){
                    ans = max(ans, tmp+1);
                }
            }
        }
    }
    for(int i = 0; i < 26; i++){
        if(u[i].size() >= 2) {
            dfs(u[i], tmp+1);
        }
    }
}

int main(){
    cin >> N >> S;
    vector<int> v;
    for(int i = 0; i < N; i++){
        v.push_back(i-1);
    }
    dfs(v, 0);
    cout << ans << endl;
}

Measured memory_bytes: 114176
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
int main()
{
    FAST
    FO
    FI
    string s;
    IN s;
    string temp= s;
    int n= int(s.length());
    reverse(temp.begin(),temp.end());
    if(temp==s)
    {
        temp= s.substr(0,(n-1)/2);
        string temp2= temp;
        reverse(temp.begin(),temp.end());
        if(temp2==temp)
        {
            string temp3= s.substr((n+1)/2,(n-1)/2);
            string temp4=temp3;
            reverse(temp3.begin(),temp3.end());
            if(temp3==temp4)
            {
                OUT "Yes";
            }
            else
            {
                OUT "No";
            }
        }
        else
        {
            OUT "No";
        }
    }
    else
    {
        OUT "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N; cin >> N;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		char c; cin >> c;
		if (c == 'R') cnt++;
	}

	if (2 * cnt > N) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque, OrderedDict

n = int(input())
edges = [tuple(map(int, input().split())) for _ in range(n-1)]
# print(edges)
tree = [[] for _ in range(n)]
# Zero-based index. グラフを陽に持つ。
edge_color = OrderedDict()  # 辺のタプルをキーにした順序付き辞書
for e in edges:
    a = e[0] - 1
    b = e[1] - 1
    tree[a].append(b)
    tree[b].append(a)
    edge_color[(min(a, b), max(a, b))] = 0

print(max(len(v) for v in tree))

seen = [False] * n  # 踏破
que = deque()
que_append = que.append
que_popleft = que.popleft
start = 0
seen[start] = True
que_append(start)
# ある頂点に接する辺にすでに塗られた色のセット。
v_based_color = [set() for _ in range(n)]
while len(que):
    v = que_popleft()
    color_i = 1  # One-based index.
    for adj in tree[v]:
        if seen[adj]:
            continue
        seen[adj] = True
        que_append(adj)
        while color_i in v_based_color[v]:
            # その頂点からの辺で使われていない色になるまで足す。
            color_i += 1
        edge_color[(min(v, adj), max(v, adj))] = color_i
        # 辺の両端の頂点が触れている色のセットに追加。
        v_based_color[v].add(color_i)
        v_based_color[adj].add(color_i)
        color_i += 1

{print(c) for c in edge_color.values()}


Measured memory_bytes: 148440
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0205
{
    public class Program

    {
        public static void Main(string[] args)
        {
            const int NUM = 5;
            Dictionary<int, int> winHand = new Dictionary<int, int>() { { 1, 2 }, { 2, 3 }, { 3, 1 } };

            while (true)
            {
                int[] hands = new int[NUM];
                for (int i = 0 ; i < NUM ; i++)
                {
                    int cur = RInt(); if (cur == 0) return;
                    hands[i] = cur;
                }

                if (hands.Distinct().Count() != 2)
                {
                    for (int i = 0 ; i < NUM ; i++) Console.WriteLine(3);
                }
                else
                {
                    int win = winHand[Enumerable.Range(1, 3).Except(hands).First()];
                    for (int i = 0 ; i < NUM ; i++) Console.WriteLine(hands[i] == win ? 1 : 2);
                }
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18460
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
    // 全体で n^m 通り
    // (1, d+1) ~ (n-d, n)とその入れ替え 2(n-d)通り (d == 0 の時は入れ替えなく, n通り)
    int n, m, d; scanf("%d%d%d", &n, &m, &d);
    long long int K = (d == 0) ? n : 2*(n-d); K *= m-1;
    long double ans = K; ans /= n; ans /= n;
    printf("%.16Lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

int s[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int a, b;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int d = min(abs(i - j), abs(i - a) + 1 + abs(b - j));
            d = min(d, abs(i - b) + 1 + abs(a - j));
            s[d]++;
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        printf("%d\n", s[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
struct nagase {
		int x;
		int y;
		int c;
		int r;
};
int kani[4]={0,1,-1,0};
int ebi[4]={1,0,0,-1};
int map[1001][1001]={0};
int s[1001][1001]={0};
int main(){
	queue<nagase>Q;
	nagase kotani;
	nagase yanagi;
	int h,w,n;
	cin>>h>>w>>n;
	char a;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a;
			if(a=='S'){
				kotani.x=i;
				kotani.y=j;
				kotani.c=1;
				kotani.r=0;
				s[i][j]=1;
				Q.push(kotani);
			}
			else if(a=='X'){
				map[i][j]=-1;
			}
			else if(a=='.'){
				map[i][j]=0;
			}
			else{
				map[i][j]=(int)(a-48);
			}
		}
	}
	while(!Q.empty()){
		yanagi=Q.front();
		Q.pop();
		if(yanagi.c==map[yanagi.x][yanagi.y]){
			if(yanagi.c==n){
				cout<<yanagi.r<<endl;
				break;
			}
			while(!Q.empty()){
				Q.pop();
			}
			yanagi.c++;
			memset(s,0,sizeof(s));
			s[yanagi.x][yanagi.y]=1;
			Q.push(yanagi);
		}
		else{
			for(int i=0;i<4;i++){
					kotani.c=yanagi.c;
					kotani.x=yanagi.x+kani[i];
					kotani.y=yanagi.y+ebi[i];
					kotani.r=yanagi.r+1;
					if(kotani.x>=0&&kotani.x<h&&kotani.y>=0&&kotani.y<w&&map[kotani.x][kotani.y]!=-1&&s[kotani.x][kotani.y]!=1){
					s[kotani.x][kotani.y]=1;
					Q.push(kotani);
				}
			}
		}
	}
}

		

			
	

Measured memory_bytes: 10848
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<double>dp(n+1);
	//dp[i]-p-billity that there are i heads so far
	dp[0]=1;
	for(int coin=0;coin<n;coin++){
		double p_heads;
		cin>>p_heads;
		for(int i=coin+1;i>=0;i--){
			dp[i]=(i==0?0:dp[i-1]*p_heads)+dp[i]*(1-p_heads);
		}
	}
	double ans=0;
	for(int heads=0;heads<=n;heads++){
		int tails=n-heads;
		if(heads>tails){
			ans+=dp[heads];
		}
	}
	cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
while True:
    P = int(input())
    if P == 0:
        break
    
    r = 1000 - P
    
    _500 = r // 500
    _100 = (r % 500) // 100
    _50 = (r % 100) // 50
    _10 = (r % 50) // 10
    _5 = (r % 10) // 5
    _1 = (r % 5)
    
    print(_500+_100+_50+_10+_5+_1)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n,m,a,b[100005]={},sum[2]={};
	string s;
	bool flag[100005]={};
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>s;
		if(!flag[a]&&s=="AC")
		{
			sum[0]++;
			sum[1]+=b[a];
			flag[a]=true;
		}
		else if(!flag[a]&&s=="WA")b[a]++;
	}
	cout<<sum[0]<<" "<<sum[1]<<endl;
	return 0;
}

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

int main()
{
  int N;
  string S;

  cin >> N >> S;

  for (int i = 0; i < N - 1; i++)
  {
    if (S.at(i) == S.at(i + 1))
    {
      S.replace(i, 1, "0");
    }
  }

  int count = 0;

  for (int i = 0; i < N; i++)
  {
    if (S.at(i) == '0')
    {
    }
    else
    {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

class UnionFind {
  std::vector<intmax_t> tree;

public:
  UnionFind(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

template <class RandomIt>
auto rsort(RandomIt first, RandomIt last)
  -> typename std::enable_if<std::is_integral<
    typename RandomIt::value_type::first_type>::value>::type
{
  using PairType = typename RandomIt::value_type;
  using KeyType = typename PairType::first_type;

  intmax_t cur_shift=0, max_exp=sizeof(KeyType);
  std::vector<PairType> work(last-first);
  for (int i=0; i<max_exp; ++i) {
    size_t num[256]={};

    for (RandomIt it=first; it<last; ++it)
      ++num[((it->first)>>cur_shift)&255];

    {
      size_t tmp=0;
      for (int j=0; j<256; ++j)
        std::swap(tmp, num[j]+=tmp);
    }

    for (RandomIt it=first; it<last; ++it)
      work[num[((it->first)>>cur_shift)&255]++] = *it;

    {
      size_t j=0;
      for (RandomIt it=first; it<last; ++it)
        *it = work[j++];
    }

    cur_shift += 8;
  }

  if (!std::is_signed<KeyType>::value) return;

  RandomIt mid=last;
  for (RandomIt it=last; --it>=first;)
    if ((it->first) >= 0) {
      mid = ++it;
      break;
    }

  if (mid == last)
    return;

  std::copy(first, mid, work.begin()+(last-mid));
  std::copy(mid, last, work.begin());
  std::copy(work.begin(), work.end(), first);
}

int main() {
  size_t W, H;
  scanf("%zu %zu", &W, &H);

  std::vector<std::pair<uintmax_t, size_t>> es;
  for (size_t j=0; j<W; ++j) {
    uintmax_t p;
    scanf("%ju", &p);
    es.emplace_back(p, j);
  }

  for (size_t i=0; i<H; ++i) {
    uintmax_t q;
    scanf("%ju", &q);
    es.emplace_back(q, W+i);
  }

  rsort(es.begin(), es.end());
  size_t a=W+1, b=H+1;
  uintmax_t res=0;
  UnionFind uf(a+b);
  for (const auto &e: es) {
    if (uf.connected(e.second, e.second+1))
      continue;

    uf.unite(e.second, e.second+1);
    if (e.second < W) {
      res += e.first*b;
      --a;
    } else {
      res += e.first*a;
      --b;
    }
  }

  printf("%ju\n", res);
}


Measured memory_bytes: 7532
import java.util.*;
import java.io.*;
 
public class Main{
    
	public static void main(String[] $){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int[] c = new int[26];
		for(int i = 0; i < 26; i++){
			c[i] = sc.nextInt();
		}
		int[][] s = new int[D][26];
		for(int i = 0; i < D; i++){
			for(int j = 0; j < 26; j++){
				s[i][j] = sc.nextInt();
			}
		}
		int[] last = new int[26];
		long satisfact = 0;
		
		for(int i = 0; i < D; i++){
			long max = Integer.MIN_VALUE;
			int sentaku = -1;
			for(int j = 0; j < 26; j++){
				if(max < s[i][j]){
					max = s[i][j];
					sentaku = j;
				}
			}
			satisfact = satisfact + max;
			last[sentaku] = i+1;
			for(int j = 0; j < 26; j++){
				satisfact -= c[j]*((i+1)-last[j]);
			}
			System.out.println(sentaku+1);
		}
	}
} 

Measured memory_bytes: 46652
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = str.length();
		for(int i = 0;i < n;i++){
			if(i % 2 == 0)System.out.print(str.charAt(i));
		}
	}
}

Measured memory_bytes: 31204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,M;
  	cin >> N;
  	string s[N];
  	for(int i=0;i<N;i++){
      cin >> s[i];
    }
  	cin >> M;
  	string t[M];
  	for(int i=0;i<M;i++){
      cin >> t[i];
    }
  	int point=0;
  	for(int i=0;i<N;i++){
      int num = 0;
      for(int j=0;j<N;j++){
        if(s[i] == s[j]){
          num++;
        }
      }
      for(int j=0;j<M;j++){
        if(s[i] == t[j]){
          num--;
        }
      }
      if(point < num){
        point = num;
      }
    }
  	for(int i=0;i<M;i++){
      int num = 0;
	  for(int j=0;j<M;j++){
        if(t[i] == t[j]){
          num--;
        }
      }
      if(point < num){
        point = num;
      }
    }
  	cout << point << endl;
  	
}
  

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

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

    int ans = 0;

    for(int i = 0; i < 4; i++){
        if(s[i] == '+'){
            ans++;
        }else{
            ans--;
        }
    }

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

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


int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	int x = 0;
		while (true) {
			for (int i = 0; i < n; i++) {
				if (vec.at(i) % 2 == 1) {
					x += 1;
					break;
				}
				vec.at(i) /= 2;
			}
			if (x>0) {
				break;
			}
				sum += 1;

		}
		cout << sum;
	
	return 0;
}










Measured memory_bytes: 256