akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

template <typename _Ty>
_Ty bpow(_Ty a, int64_t n) {
    _Ty res = 1;
    for (; n > 0; n >>= 1) {
        if (n & 1) res *= a;
        a *= a;
    }
    return res;
}

void solve() {
    ll X;
    cin >> X;

    ll mx = 6209;

    Vl pow5(mx);
    for (ll i = 0; i < mx; i++) {
        pow5[i] = bpow(i, 5);
    }

    ll a, b;
    b = 0;
    while (true) {
        ll idx = lower_bound(pow5.begin(), pow5.end(), X + bpow(b, 5)) - pow5.begin();
        if (bpow(idx, 5) - bpow(b, 5) == X) {
            a = idx;
            break;
        }

        idx = lower_bound(pow5.begin(), pow5.end(), X - bpow(b, 5)) - pow5.begin();
        if (bpow(idx, 5) + bpow(b, 5) == X) {
            a = idx;
            b = -b;
            break;
        }

        ++b;
    }

    cout << a << " " << b << endl;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

int main()
{
    int n, digit = 0, num;
    cin >> n;
    num = n;


    long long int sum = 0;
    int ar[10][10];
    for(int i = 1; i < 10; i++){
        for(int j = 0; j < 10; j++)
            ar[i][j] = 0;
    }

    for(int i = 1; i <= n; i++){
        string s1;
        s1 = to_string(i);
        int len = s1.size()-1;

        int n1, n2;
        n1 = s1[0] - '0';
        n2 = s1[len] - '0';

        ar[n1][n2]++;
    }

    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i != j)
                ar[i][j] = 2*ar[i][j];
            sum += ar[i][j]*ar[j][i];
            ar[i][j] = 0;
            ar[j][i] = 0;
        }
    }

    cout << sum;


    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

class Main {

    static int[][] array = new int[10][10]; //先頭と末尾の組み合わせ
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        long ans = solve(N);
        System.out.println(ans);
    }

    static long solve(int N) {
        int ans = 0;
        for(int i=1; i<=N; i++) {
            count(i);
        }

        for(int i=1; i<=9; i++) {
            for(int j=1; j<=9; j++) {
                ans += array[i][j] * array[j][i];
            }
        }
        return ans;
    }

    static void count(int i){
        int a = i%10;
        int b = 0;
        while(i != 0) {
            b = i;
            i /= 10;
        }
        array[a][b]++;
    }
}


Measured memory_bytes: 22740
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	ll n;
	cin >>n;

	ll ret=(n/500)*1000;
	n%=500;
	ret+=(n/5)*5;

	cout<< ret<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define REPI(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) REPI(i,0,n)

typedef long long ll;

int SURP = 1000000007;



int uni[100005];

void init(int N){
    for (int i = 0; i < N; i++){
            uni[i] = -1;
    }
}

int root(int a){
    if (uni[a] < 0) return a;
    else return uni[a] = root(uni[a]);
}

bool connect(int a, int b){
    a = root(a);
    b = root(b);
    if (a == b) return false;
    if (uni[a] > uni[b]) swap(a,b);
    uni[a] += uni[b];
    uni[b] = a;
    return true;
}

bool isConnect(int a,int b){
    int ra = root(a);
    int rb = root(b);
    if(ra == rb) return true;
    else return false;
}

void swap(int a, int b){
    int c = a;
    a = b;
    b = c;
}

int main(){
	int N,M;
	cin >> N >> M;

	int p[N];
	REP(i,N) cin >> p[i];

	init(N);

	REP(i,M){
		int xi;
		int yi;
		cin >> xi >> yi;
		connect(xi,yi);
	}

	int ret = 0;
	REP(i,N){
		if(isConnect(i+1,p[i])) ret++;
	}

	cout << ret << endl;
	return 0;
}




Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pbi pair<bool,int>
#define pob pop_back
#define all(a) a.begin(),a.end()
#define fio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define i64 long long int
#define mem(x,y) memset(x,y,sizeof(x))
#define fill(arr,b) fill(arr, arr+sizeof(arr)/sizeof(arr[0]), b)
#define maxarr(n,arr,m) m =-1e9;for(int i=0;i<n;i++)if(arr[i]>m) m=arr[i];
#define read freopen("input.txt","r",stdin);

const double pi = acos(-1.0);
const int maxn = (i64)1e9+7;

int main()
{
    //read;
    string s1;
    cin>>s1;
    if(s1=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;

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

	int dp[1 << n] = {};
	dp[0] = 1;

	for (int m = 1; m < (1 << n); m++) {
		int j = setbits(m) - 1;

		for (int x = 0; x < n; x++) {
			if (m & (1 << x)) {
				if (a[x][j] == 1)
					dp[m] += dp[m - (1 << x)], dp[m] %= mod;
			}
		}
	}

	cout << dp[(1 << n) - 1] << endl;

	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;

    map<string, int> dp, nxt, nnxt, null;
    dp["first"] = 0;

    rep(i, st.size()) {
        nnxt = null;
        for (auto j = dp.begin(); j != dp.end(); j++) {
            string tmp = ""; tmp += st[i];
            if (j->first != tmp) {
                nxt[tmp] = max(j->second + 1, nxt[tmp]);
            }
            if (i+1 < st.size()) {
                tmp += st[i+1];
                if (j->first != tmp) {
                    nnxt[tmp] = max(j->second + 1, nnxt[tmp]);
                }
            }
        }
        dp = nxt;
        nxt = nnxt;
    }
    int ans = 0;
    for (auto i = dp.begin(); i != dp.end(); i++) {
        ans = max(ans, i->second);
    }
    
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int n,a,b,j=0,o=0;
int pd(char c)
{
	if(c=='c') return 0;
	if(c=='a')
	{
		if(j<a+b)
		{
			j++;
			return 1;
		}
		else return 0;
	}
	else 
	{
		if(j<a+b&&o<b)
		{
			j++;
			o++;
			return 1;
		}
		else return 0;
	}
}
int main()
{
	scanf("%d%d%d\n",&n,&a,&b);
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
	if(pd(s[i])) printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll ret = 1LL << 60;
  for (ll i=1; i*i<=N; i++) {
    if (N % i != 0) continue;
    ll j = N / i;
    ret = min(ret, i - 1 + j - 1);
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,M;
ll x[1010];
ll y[1010];
ll z[1010];

ll hx(ll i){
    if (i & 1) return 1;
    else return -1;
}

ll hy(ll i){
    if (i & 1<<1) return 1;
    else return -1;
}

ll hz(ll i){
    if (i & 1<<2) return 1;
    else return -1;
}

int main() {
    cin >> N >> M;
    rep(i,N) cin >> x[i] >> y[i] >> z[i];
    ll ans;
    for (ll i=0; i<1<<3; i++){
        vector<ll> P;
        rep(j,N){
            P.push_back(hx(i)*x[j]+hy(i)*y[j]+hz(i)*z[j]);
        }
        sort(P.begin(),P.end());
        reverse(P.begin(),P.end());
        ll temp = 0;
        rep(k,M) temp += P[k];
        if (i == 0) ans = temp;
        else ans = max(ans,temp);
    }
        
    cout << ans << endl;
    
    return 0;
}


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

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

    int N, K;
    cin >> N >> K;
    vector<ll> a(N);
    for (auto &x : a) cin >> x;

    ll ans = LLONG_MAX;
    for (int tmp = 0; tmp < (1 << N); ++tmp) {
        bitset<20> BIT(tmp);
        if (!BIT.test(0)) continue;
        if (BIT.count() < K) continue;
        ll cost = 0;
        ll h = a.at(0);
        for (int i = 1; i < N; ++i) {
            h = max(h, a.at(i - 1));
            if (!BIT.test(i)) continue;
            if (a.at(i) <= h) {
                cost += h + 1 - a.at(i);
                h++;
            }
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

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



int main()
{
	int n, ac = 0, wa = 0, tle = 0, re = 0;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		if (s == "AC") ac++;
		else if (s == "WA") wa++;
		else if (s == "TLE") tle++;
		else if (s == "RE") re++;
	}
	cout << "AC x " << ac << '\n';
	cout << "WA x " << wa << '\n';
	cout << "TLE x " << tle << '\n';
	cout << "RE x " << re << '\n';
	return 0;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"math"
)

func main() {

	var a, b, rad float64
	fmt.Scan(&a, &b, &rad)
	c := math.Sqrt(a*a + b*b - 2*a*b*math.Cos((rad*math.Pi)/float64(180)))
	s := 0.5 * a * b * math.Sin((rad*math.Pi)/float64(180))
	h := float64(2) * s / a
	fmt.Println(s)
	fmt.Println(a + b + c)
	fmt.Println(h)

}



Measured memory_bytes: 1148
class Unionfind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]
        self.rank = [0]*(n+1)
    
    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def same_check(self,x,y):
        return self.find(x) == self.find(y)

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n,m = map(int,input().split())
p =list(map(int,input().split()))
tree = Unionfind(n)

for _ in range(m):
    x,y = map(int,input().split())
    tree.union(x,y)
ans = 0
for i in range(n):
    if tree.find(i+1) == tree.find(p[i]):
        ans += 1
print(ans)


Measured memory_bytes: 13812
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<cstdint>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);

int N,M;
vector<int> v[100000];
vector<int> tree[100000];
bool visited[100000];
vector<int> ans;
bool ok=true;
void dfs(int i){
      for(auto node:v[i]){
            if(!visited[node]){
                  ans.push_back(node);
                  visited[node]=true;
                  dfs(node);
            }
            int mochi=v[i].size()-1;
            if(node==v[i][mochi]) ok=false;
            if(!ok){
                  break;
            }
      }
}
int main(){
      cin>>N>>M;
      rep0(i,M){
            int A,B;
            cin>>A>>B;
            A--;B--;
            v[A].push_back(B);
            v[B].push_back(A);
      }
      ans.push_back(0);
      visited[0]=true;
      dfs(0);
      reverse(ans.begin(),ans.end());
      ok=true;
      dfs(0);
      cout<<ans.size()<<endl;
      for(auto a:ans){
            cout<<a+1<<" ";
      }
      cout<<endl;
      
      return 0;
}

Measured memory_bytes: 14968
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

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

    li n;
    cin >> n;

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

    vector<li> dp(n, 1LL << 50);
    dp[0] = 0;
    dp[1] = abs(hs[1] - hs[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(hs[i] - hs[i - 1]), dp[i - 2] + abs(hs[i] - hs[i - 2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

int main(){
  int x;
  cin >> x;
  if(x < 600){
    cout << 8 << endl;
  }
  else if(x < 800){
    cout << 7 << endl;
  }
  else if(x < 1000){
    cout << 6 << endl;
  }
  else if(x < 1200){
    cout << 5 << endl;
  }
  else if(x < 1400){
    cout << 4 << endl;
  }
  else if(x < 1600){
    cout << 3 << endl;
  }
  else if(x < 1800){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll k,x;
    cin >> k >> x;

    REP(i,x-k+1,x+k)cout << i << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
 
int main(){
    string n; cin >> n;
    int s = n.size();
    if(n[s-1] == '2' || n[s-1] == '4' || n[s-1] == '5' || n[s-1] == '7' || n[s-1] == '9') cout  << "hon" << endl;
    if(n[s-1] == '0' ||n[s-1] == '1' || n[s-1] == '6' || n[s-1] == '8') cout << "pon" << endl;
    if(n[s-1] == '3') cout << "bon" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <utility>
#include <stdint.h>
#include <set>

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  multiset<uint64_t> nums = {0,0,0};

  uint64_t count = 1;
  
  for (uint64_t n=0; n<N; ++n) {
    uint64_t a;
    cin >> a;

    count *= nums.count(a);

    if (count == 0)
      break;
    
    if (count >= 1000000007)
      count %= 1000000007;
    
    for (auto it=nums.begin(); it!=nums.end(); ++it) {
      if (*it==a) {
    	nums.erase(it);
    	break;
      }
    }
    nums.insert(a+1);
  }
  
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007
#define MAX 1000000000000000000


int main(){
  long double a;
  long double b;
  cin>>a>>b;
  
  long double ans = a*b;
  
  

  std::cout << std::fixed;
  std::cout << std::setprecision(2)<<(ll)ans<<endl;
  //cout<<(ll)ans;


  return 0;
}


Measured memory_bytes: 3716
#include<stdio.h>

int main(){

int i,j;
int x,y;
int square[100][2]={0};

for(i=0;i<100;i++){
	scanf("%d %d",&square[i][0],&square[i][1]);
	if(square[i][0] == 0 && square[i][1] == 0){
		break;
	}
}

for(j=0;j<i;j++){
	for(y=0;y<square[j][0];y++){
		for(x=0;x<square[j][1];x++){
			if((x+y)%2){
				printf(".");
			}else{
				printf("#");
			}
		}
		printf("\n");
	}
	printf("\n");
}	
return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef pair<int, int> iP;
typedef pair<iP, int> iiP;

struct edge{
  int to, cost; edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

int n, m, costed[101][2];
vector<vector<edge> > info(101);

void init(){
  for(int i = 0; i < 101; i++){
    costed[i][0] = costed[i][1] = INF;
  }
  info.resize(0); info.resize(101);
}

int Dijkstra(){
  
  priority_queue<iiP, vector<iiP>, greater<iiP> > que;
  que.push(iiP(iP(0, 1), 1)); costed[1][1] = 0;
  
  while(!que.empty()){
    iiP p = que.top(); que.pop();
    if(p.fr.sc == n) return p.fr.fr;
    for(int i = 0; i < info[p.fr.sc].size(); i++){
      edge e = info[p.fr.sc][i];
      if(costed[e.to][p.sc] > p.fr.fr + e.cost){
	que.push(iiP(iP(p.fr.fr + e.cost, e.to), p.sc));
	costed[e.to][p.sc] = p.fr.fr + e.cost;
      }
      if(p.sc == 1){
	for(int j = 0; j < info[e.to].size(); j++){
	  edge ee = info[e.to][j];
	  if(costed[ee.to][0] > p.fr.fr){
	    que.push(iiP(iP(p.fr.fr, ee.to), 0));
	    costed[ee.to][0] = p.fr.fr;
	  }
	}
      }
    }
  }
} 
  
int main(){
  
  while(cin >> n >> m, n||m){
    init();
    for(int i = 0; i < m; i++){
      int a, b, c; cin >> a >> b >> c;
      info[a].push_back(edge(b, c));
      info[b].push_back(edge(a, c));
    }
    
    cout << Dijkstra() << endl;
  
  }
}

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

int n,t,m[1000],l[1000],k[1000];

bool check(int x){
  int c[1001]={},used[1000]={},cnt=n;
  for(int i=0;i<t;i++,x+=c[i])
    for(int j=0;j<n&&x;j++){
      if(used[j])continue;
      if(i+m[j]>t)return 0;
      if(i%(l[j]+k[j])<=l[j])c[i+m[j]]++,cnt--,used[j]=1,x--;
    }
  return !cnt;
}

int main(){
  while(scanf("%d%d",&n,&t),n){
    for(int i=0;i<n;i++)scanf("%d%d%d",&m[i],&l[i],&k[i]);
    int ans=0;
    for(int i=1;i<=n&&!ans;i++)if(check(i))ans=i;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3148
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        long M = 2019;
        long L = nlong();
        long R = nlong();
        
        if (L%M == 0 || R%M == 0) {
            so.println(0);
        } else if (L/M != R/M) {
            so.println(0)   ;
        } else {
            long min = Integer.MAX_VALUE;
            for (long i = L; i < R; i++) {
                for (long j = i+1; j <= R; j++) {
                    min = Math.min(min, ((i%M) * (j%M)) % M);
                }
            }
            so.println(min);
        }
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 200003
#define pc(x) putchar_unlocked(x);
int state[mx*4],tree[mx*4][2],lazy[mx*4],a[mx],di[mx],n,mini[mx*4];
set<int>batas;
vector<int>ans;
void build(int idx,int l,int r){
	state[idx]=1;
	if(l==r){
		if(l&1){
			tree[idx][1]=a[l];
			tree[idx][0]=1e9;
		}
		else{
			tree[idx][0]=a[l];
			tree[idx][1]=1e9;
		}
		mini[idx]=tree[idx][state[idx]];
		return;
	}
	build(2*idx,l,MID);
	build(2*idx+1,MID+1,r);
	for(int i=0;i<2;i++)tree[idx][i]=min(tree[idx*2][i],tree[2*idx+1][i]);
	mini[idx]=min(mini[idx*2],mini[2*idx+1]);
}

void pd(int idx,int l,int r){
	lazy[idx]^=1;
	state[idx]^=1;
	mini[idx]=tree[idx][state[idx]];
}

void ganti(int idx,int l,int r,int fl,int fr){
	if(fl>r || fr<l)return;
	if(fl<=l && r<=fr){
		lazy[idx]^=1;
		state[idx]^=1;
		mini[idx]=tree[idx][state[idx]];
		return;
	}
	if(lazy[idx]){
		pd(2*idx,l,MID);
		pd(2*idx+1,MID+1,r);
		lazy[idx]=0;
	}
	ganti(2*idx,l,MID,fl,fr);
	ganti(2*idx+1,MID+1,r,fl,fr);
	for(int i=0;i<2;i++)tree[idx][i]=min(tree[idx*2][i],tree[2*idx+1][i]);
	mini[idx]=min(mini[idx*2],mini[2*idx+1]);
}

int cari(int t,int idx,int l,int r,int fl,int fr){
	if(fl>r || fr<l)return 1e9;
	if(fl<=l && r<=fr)return tree[idx][t];
	if(lazy[idx]){
		pd(2*idx,l,MID);
		pd(2*idx+1,MID+1,r);
		lazy[idx]=0;
	}
	return min(cari(t,idx*2,l,MID,fl,fr),cari(t,2*idx+1,MID+1,r,fl,fr));
}

void upd(int idx,int l,int r,int in){
	if(in>r || in<l)return;
	if(l==r){
		mini[idx]=tree[idx][0]=tree[idx][1]=1e9;
		return;
	}
	if(lazy[idx]){
		pd(2*idx,l,MID);
		pd(2*idx+1,MID+1,r);
		lazy[idx]=0;
	}
	upd(2*idx,l,MID,in);
	upd(2*idx+1,MID+1,r,in);
	for(int i=0;i<2;i++)tree[idx][i]=min(tree[idx*2][i],tree[2*idx+1][i]);
	mini[idx]=min(mini[idx*2],mini[2*idx+1]);
}

int main(){
	cin>>n;
	batas.insert(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		di[a[i]]=i;
	}
	build(1,1,n);
	for(int i=1;i<=n;i+=2){
		int x=mini[1];
		int pos=di[x];
		auto it=batas.lower_bound(pos);
		int y=*it-1;
		int t=1;
		if(pos&1)t=0;
		int z=cari(t,1,1,n,pos+1,y);
		int cnt=0;
		if(z==1e9){
			while(1)cnt++;
		}
	//	debug(x);
	//	debug(z);
		int tmp=di[z];
		ganti(1,1,n,pos+1,tmp-1);
		batas.insert(pos);
		batas.insert(tmp);
		upd(1,1,n,pos);
		upd(1,1,n,tmp);
		ans.pb(x);
		ans.pb(z);
	}
	for(int i:ans)cout<<i<<' ';
}




Measured memory_bytes: 28020
import sys
sys.setrecursionlimit(10**6)

def main():
	n, k = map(int, input().split())
	a = [int(i) for i in input().split()]
	ans = 10**9
	for i in range(k-1, n):
		if a[i-k+1] * a[i] < 0:
			ans = min(ans, a[i-k+1]*(-2) + a[i], a[i-k+1]*(-1)+2*a[i])
		else:
			ans = min(ans,max(abs(a[i-k+1]) , abs(a[i])))
	print(ans)
	return

main()

Measured memory_bytes: 14568
nons = input()
a = input()
b = list(a)
c= int(input())
d = b[c-1]
result = str()
for i in range(0,len(b)):
    if b[i] == d:
        pass
    else:
        b[i] = '*'
for i in range(len(b)):
    result = result+b[i]
print(result)


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

#define MAX_N 500000
#define INF 2139062143

int x[MAX_N][3], cnt;//num,left,right
int n, a;
string S;

void inorder(int u) {
	if (u == -1) { return; }
	inorder(x[u][1]);
	cout << ' ' << x[u][0];
	inorder(x[u][2]);
}
void preorder(int u) {
	if (u == -1) { return; }
	cout << ' ' << x[u][0];
	preorder(x[u][1]);
	preorder(x[u][2]);
}

int main() {
	int root = -INF;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		if (S == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		if (S == "insert") {
			cin >> a;
			if (root == -INF) {
				root = cnt;
			}
			else {
				int v = root;
				while (true) {
					if (a < x[v][0]) {
						if (x[v][1] == -1) {
							x[v][1] = cnt;
							goto E;
						}
						v = x[v][1];
					}
					else {
						if (x[v][2] == -1) {
							x[v][2] = cnt;
							goto E;
						}
						v = x[v][2];
					}
				}
			E:;
			}
			x[cnt][0] = a; x[cnt][1] = -1; x[cnt][2] = -1;
			cnt++;
		}
	}
	return 0;
}

Measured memory_bytes: 7068
#include <stdio.h>

int main(void){

    char word[20], tipical;
    int wordnum, i, index;

    scanf("%d", &wordnum);
    scanf("%s", &word);
    scanf("%d", &index);

    tipical = word[index-1];

    for(i=0; i<wordnum; i++){
        if(word[i] != tipical){
            word[i] = '*';
        } else {
            continue;
        }
    }

    printf("%s", word);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=998244353;
const int INF=1e9;
const ll LINF=1e18;

struct SegmentTree{
private:
    int n;
    vector<int> node;
public:
    SegmentTree(const int sz){
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1);
    }
    void update(int a,int x){
        a+=n-1;
        node[a]=x;
        while(a>0){
            a=(a-1)/2;
            node[a]=node[2*a+1]+node[2*a+2];
        }
    }
    int get(int a,int b=-1,int k=0,int l=0,int r=-1){
        if(b==-1)b=n;
        if(r==-1)r=n;
        if(b<=l||r<=a)return 0;
        if(a<=l&&r<=b){
            return node[k];
        }
        else{
            return get(a,b,2*k+1,l,(l+r)/2)+get(a,b,2*k+2,(l+r)/2,r);
        }
    }
};

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    pair<int,int> p[n],q[n];
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        p[i]={x,i};
        q[i]={y,i};
    }
    sort(p,p+n);
    sort(q,q+n);
    int x[n],y[n];
    for(int i=0;i<n;i++){
        x[p[i].second]=i;
        y[q[i].second]=i;
    }
    pair<int,int> pos[n];
    for(int i=0;i<n;i++){
        pos[i]={x[i],y[i]};
    }
    sort(pos,pos+n);
    int ss[n],sg[n],gs[n],gg[n];
    SegmentTree segl(n),segg(n);
    for(int i=0;i<n;i++){
        ss[i]=segl.get(0,pos[i].second);
        sg[i]=segl.get(pos[i].second);
        segl.update(pos[i].second,1);
    }
    for(int i=n-1;i>=0;i--){
        gs[i]=segg.get(0,pos[i].second);
        gg[i]=segg.get(pos[i].second);
        segg.update(pos[i].second,1);
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ll a=modpow(2,ss[i]);
        ll b=modpow(2,sg[i]);
        ll c=modpow(2,gs[i]);
        ll d=modpow(2,gg[i]);
        ll e=((a-1)*(d-1))%MOD;
        ll f=((b-1)*(c-1))%MOD;
        ll g=(a*d)%MOD;
        ll h=(b*c)%MOD;
        ans=(ans+e*h)%MOD;
        ans=(ans+f*g)%MOD;
        ans=(ans-e*f)%MOD;
    }
    ans=(ans+n*modpow(2,n-1))%MOD;
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/4;
    public static final int inf = Integer.MAX_VALUE/4;

    static void solve(InputReader in, PrintWriter out){
        int h = in.ni(), w = in.ni();
        int[] alp = new int['z'-'a'+1];
        for (int i = 0; i < h; i++) {
            char[] s = in.ns().toCharArray();
            for (int j = 0; j < w; j++) {
                alp[s[j] - 'a']++;
            }
        }
        boolean flag = true;
        if(h%2==0&&w%2==0){

            for(int i: alp) if(i%4!=0) flag = false;
        }else if(h%2==1&&w%2==1){

            int a=0,b=0,c=0;
            for(int i: alp){
                if(i==0) continue;
                if(i%4==0) a++;
                else if(i%2==0) b++;
                else {
                    if(c != 0) flag = false;
                    c = i;
                }
            }
            if(c>1&&(c-1)%4==0) a++;
            else if(c>1)b++;
            if(b>(h+w-2)/2) flag = false;
        }else{

            int a=0,b=0;
            for(int i: alp){
                if(i==0) continue;
                if(i%4==0) a++;
                else if(i%2==0) b++;
                else flag = false;
            }
            if(w%2==0&&b>w/2||h%2==0&&b>h/2) flag = false;
        }
        out.println(flag?"Yes":"No");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 23124
#include <stdio.h>

int main(void)
{
 int K, S;
 int x, y, z;
 int cnt = 0;
 
 
 scanf("%d %d", &K, &S);
 
 for( x = 0; x <= K; x++ ){
   for( y = 0; y <= x; y++ ){
     for( z = 0; z <= y; z++ ){
       if( x + y + z == S ){
         if( x==y || y==z || z==x ){
           if( x==y && y==z ) cnt++;
           else{              cnt+=3;}
         }
         else{                cnt+=6;}         
       }
     }
   }
 }
 
 printf("%d\n", cnt);
 

 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;

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

	string s;
	cin >> s;

	int n = s.size();

	int ans = 0;
	rep(i, n) if(s[i] == '1') ans++;
	cout << ans << endl;
}


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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cerr << #x << " " << x << endl
#define eb emplace_back
#define __ << " " <<
typedef long long ll;
typedef std::pair<int, int> P;
#define X first
#define Y second
#define double long double
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;

int N, M;
int l[MaxN], r[MaxN];
int d[MaxN];
vector <int> wedge[MaxN], adj[MaxN];
bool bio[MaxN];
int val[MaxN];
bool moze;

void dfs(int v){
  bio[v] = 1;
  REP(i, (int)adj[v].size()){
    int x = adj[v][i];
    int w = wedge[v][i];
  
    if (!bio[x]){
      val[x] = val[v] + w;
      dfs(x);
    }
    else{
      if (val[x] != val[v] + w){
        moze = 0;
      }
    }
  }
}

void load(){
  scanf("%d%d", &N, &M);
  REP(i, M){
    scanf("%d%d%d", l + i, r + i, d + i);
    
    adj[l[i]].eb(r[i]);
    wedge[l[i]].eb(d[i]);

    adj[r[i]].eb(l[i]);
    wedge[r[i]].eb(-d[i]);
  }
  moze = 1;

  for (int i = 1; i <= N; i++){
    if (!bio[i]){
      val[i] = 0;
      dfs(i);
    }
  }

  if (moze){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

int main(){
    load();	
    return 0;
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 105 B / Link: http://abc105.contest.atcoder.jp/tasks/abc105_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N; 
	cin >> N;
	FOR(i, 0, 100) {
		FOR(j, 0, 100) {
			if (4 * i + 7 * j == N) {
				ans = 1;
			}
		}
	}
	
	cout <<(ans?"Yes":"No") << "\n";

	return 0;
}


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

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; ++i){
        int sum = FindSumOfDigits(i);
        if (A <= sum && sum <= B){
            ans += i;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
N=int(input())
A=list(map(int,input().split()))

SUM=A[0]
ANS=0
if SUM<=0:
    ANS=1-SUM
    SUM=1

for a in A[1:]:
    if SUM>0:
        y=SUM+a
        if y<0:
            SUM=y
        else:
            ANS+=y+1
            SUM=-1

    else:

        y=SUM+a
        if y>0:
            SUM=y
        else:
            ANS+=1-y
            SUM=1


SUM=A[0]
ANS2=0
if SUM>=0:
    ANS2+=SUM+1
    SUM=-1

for a in A[1:]:
    if SUM>0:
        y=SUM+a
        if y<0:
            SUM=y
        else:
            ANS2+=y+1
            SUM=-1

    else:

        y=SUM+a
        if y>0:
            SUM=y
        else:
            ANS2+=1-y
            SUM=1

print(min(ANS,ANS2))
        


Measured memory_bytes: 14468
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

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

n, k = na()
f = na()
c = na()

for i in range(n):
    f[i] -= 1

def mx(a, inf, sup):
    n = len(a)
    b = a + a
    ret = -1000000009 if inf > 0 else 0
    for i in range(n):
        s = 0
        for j in range(sup):
            s += b[i+j]
            if j >= inf-1:
                ret = max(ret, s)
    return ret

done = [False] * n
ans = -1000000007
for i in range(n):
    if not done[i]:
        a = []
        cur = i
        while not done[cur]:
            done[cur] = True
            a.append(c[cur])
            cur = f[cur]
        s = sum(a)
        need = k
        if need >= len(a):
            if s >= 0:
                can = need//len(a)*s + mx(a, 0, need % len(a))
                if need > 1:
                    can = max(can, (need//len(a)-1)*s + mx(a, 0, len(a)))
                else:
                    can = max(can, mx(a, 1, len(a)))
            else:
                can = mx(a, 1, len(a))
        else:
            can = mx(a, 1, need)
        ans = max(ans, can)

print(ans)



Measured memory_bytes: 69376
#include<stdio.h>

int main(void){
  char s[4];
  scanf("%s",s);
  int c=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      c++;
    }else{
      c--;
    }
  }
    printf("%d",c);
   return 0;
}


Measured memory_bytes: 1700
package main

import (
	"fmt"
	"math"
)

func main() {
	var x, a, b float64
	var ans string
	fmt.Scan(&x, &a, &b)

	if math.Abs(x-a) < math.Abs(x-b) {
		ans = "A"
	} else {
		ans = "B"
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int  a,b,c;
int main(){
	cin>>a>>b>>c;


	if((b-a) == (c-b)){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}



	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N,K,W,H,ans = 1,dp[HMAX][WMAX];
string S,T;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

bool check(int k){
	for (int i = 0; i < T.size(); ++i)
	{
		if(T[i] != S[k+i] && S[k+i] != '?'){
			return false;
		}
	}
	return true;
}

void solve(){
	for (int i = S.size()-T.size(); i >= 0 ; --i)
	{
		if(check(i)){
			for (int j = 0; j < T.size(); ++j)
			{
				if(S[i+j] == '?'){
					S[i+j] = T[j];
				}
			}
			for (int k = 0; k < i; ++k)
			{
				if(S[k] == '?'){
					S[k] = 'a';
				}
			}
			for (int k = i+T.size(); k < S.size(); ++k)
			{
				if(S[k] == '?'){
					S[k] = 'a';
				}
			}
			return;
		}
	}
	S = "UNRESTORABLE";
}

void debug(){

}

void answer(){
	cout << S << "\n";
}

int main(){
	cin >> S;
	cin >> T;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

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

using namespace std;

#define ALPHABET_NUM 26

int num1[ALPHABET_NUM], num2[ALPHABET_NUM];

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    int n = s.length();

    for (int i = 0; i < n; i++)
    {
        num1[s[i] - 'a']++;
        num2[t[i] - 'a']++;
    }

    sort(num1, num1 + ALPHABET_NUM);
    sort(num2, num2 + ALPHABET_NUM);

    bool j = true;
    for (int i = 0; i < ALPHABET_NUM; i++)
    {
        if (num1[i] != num2[i])
        {
            j = false;
            break;
        }
    }

    printf("%s\n", j ? "Yes" : "No");

    return 0;
}


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

const int TIME = 200002;

int main(){
    int n,C;cin>>n>>C;
    int s[n],t[n],c[n];
    int tt[TIME]={0};
    int sm[TIME]={0};

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

    for(int i=1;i<=C;i++){
        for(int j=0;j<TIME;j++) {
            tt[j] = 0;
        }
        for(int j=0;j<n;j++) {
            if(c[j]==i) {
                tt[2*s[j]-1] = 1;
                tt[2*t[j]] = -1;
            }
        }
        for(int j=0;j<TIME-1;j++) {
            tt[j+1] += tt[j];
        }
        for(int j=0;j<TIME;j++) {
            if(tt[j]>0) sm[j]++;
        }
    }

    int ans=0;
    for(int i=0;i<TIME;i++) {
        if(ans<sm[i]) {
            ans=sm[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
signed main(){
  int n;
  cin>>n;
  string a,b,c;
  cin>>a>>b>>c;
  int ans=0;
  fo(i,n){
    V<char> d={a[i],b[i],c[i]};
    Sort(d);
    uni(d);
    if(d.size()==2)
      ans++;
    if(d.size()==3)
      ans+=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  int i,c;
  c=0;
  for(i=0;i<s.size();i++){
    if (s[i] != t[i])
      c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 3924
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include<tuple>

using namespace std;

int count(int n) {
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (n % i == 0)cnt++;
	}
	return cnt;
}

int main() {
	int N;
	int cnt = 0;

	cin >> N;
	for (int i = 1; i <= N; i += 2) {
		if (count(i) == 8)cnt++;
	}

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

Measured memory_bytes: 256
N = int(input())
uvw = [[int(x) for x in input().split()] for _ in range(N-1)]

path = [[] for _ in range(N)]

ans = [-1]*N
ans[0] = 0

for u,v,w in uvw:
    path[u-1].append([v-1,w%2])
    path[v-1].append([u-1,w%2])
    
Q = [0]     
while Q:
    v = Q.pop(-1)
    for p,d in path[v]:
        if ans[p] == -1:
            ans[p] = (ans[v]+d)%2
            Q.append(p)
            
for a in ans:
    print(a)


Measured memory_bytes: 97112
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int main(){
	ll n,m;
	cin >> n >> m;
	vector<vector<int> >v(n+1);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		v[a].PB(b);
		v[b].PB(a);
	}
	int x = 1;
	vector<bool>flag(n+1);
	vector<bool>color(n+1);
	flag[1]=1;
	color[1]=1;
	bool pp=0;
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		//cout << q.size() << endl;
		int k = q.front();
		q.pop();
		for(int i=0;i<v[k].size();i++){
			int p = v[k][i];
			if(flag[p]==0){
				flag[p]=1;
				color[p] = !color[k];
				q.push(p);
			}else{
				if(color[p]==color[k]){
					pp = 1;
				}
			}
		}
	}
	ll ans=0;
	if(pp==0){
		ll bl=0,wh=0;
		for(int i=1;i<=n;i++){
			if(color[i]==0){
				bl++;
			}else{
				wh++;
			}
		}
		ans = bl*wh - (ll)m;
	}else{
		ans = n*(n-1)/2 -m;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5888
N = int(input())
S = input()

from collections import defaultdict

memo = [defaultdict(int) for j in range(N+1)]

ans = 0



for i,s in enumerate(S):
    memo[i+1]["R"] = memo[i]["R"]
    memo[i+1]["G"] = memo[i]["G"]
    memo[i+1]["B"] = memo[i]["B"]
    memo[i+1][s]+=1
    others = set(["R","G","B"])
    others.remove(s)
    others = list(others)
    ans += memo[i+1][others[0]] * memo[i+1][others[1]]

rgb = set(["R","G","B"])
# print(rgb)

if N > 2:
    if N %2 == 1:
        length = N // 2
    else:
        length = N // 2 - 1

    # print(length)
    
    for skip in range(length):
        for i in range(len(S)):
            # print(i)
            if i+2+skip*2 > len(S)-1:

                break
            a,b,c = S[i],S[i+1+skip],S[i+2+skip*2]
            # print(set([a,b,c]))
            if set([a,b,c]) == rgb:
                ans -= 1
        

print(ans)


Measured memory_bytes: 76880
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, 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 REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n;

signed main(){
    cin >> n;
    ll ret = 0;
    if(n % 2 == 0){
        ll tmp = n / 2;
        while(tmp > 1){
            ret += tmp / 5;
            tmp /= 5;
        }
    }else{
        ret = 0;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256