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

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
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(s[0]=='0'||s[n-1]=='1'){
        cout << -1 << endl;
        return 0;
    }
    vector<int>v;
    for(int i=0;i<n-1;i++){
        if(s[i]=='1'&&s[n-2-i]=='0'){
            cout << -1 << endl;
            return 0;
        }
        if(s[i]=='1'){
            v.push_back(i+1);
        }
    }
    int m = v.size();
    int cnt = 1;
    vector<int> a(n);
    a[0] = 1;
    for(int i=1;i<v.size();i++){
        a[i] = v[i]-v[i-1];
    }
    // for(int x:a)cout << x << " ";
    // cout << endl;
    vector<pair<int,int> > p;
    for(int i=0;i<n;i++){
        int k = cnt;
        for(int j = 0;j<a[i];j++){
            cnt++;
            p.PB(MP(k,cnt));
        }
        if(a[i]==0){
            continue;
        }
    }
    for(auto x:p){
        cout <<x.first << " " << x.second << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  V<int> a(n);
  rep(i, n) cin >> a[i];

  V<int> b(h * w);
  int k = 0;
  rep(i, n) rep(j, a[i]) b[k++] = i + 1;

  k = 0;
  V<V<int>> c(h, V<int>(w, 0));
  rep(i, h) {
    if (i % 2 == 0) {
      rep(j, w) c[i][j] = b[k++];
    } else {
      for (int j = w - 1; j >= 0; j--) c[i][j] = b[k++];
    }
  }
  rep(i, h) {
    rep(j, w) printf("%d ", c[i][j]);
    printf("\n");
  }
}


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

int selectionSort(int A[], int N) {
	int sw = 0;
	for (int i = 0; i <= N-1; i++) {
		int minj = i;
		for (int j = i; j <= N-1; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		//????´????????????????
		if (A[i] != A[minj]) {
			swap(A[i], A[minj]);
			sw++;
		}
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	sw = selectionSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main()
{	
int i[3] = {0,0,0};
int n,j;
for(j=0;j<10;j++)
{
cin>>n;
	if(n >= 0 && n <=10000)
	{
		if(i[0] < n)
		{
		 i[2] = i[1];
		 i[1] = i[0];
		 i[0] = n;
		}
		else if(i[1] < n)
		{
		 i[2] = i[1];
		 i[1] = n;
		}
		else if(i[2] < n)
		{
		 i[2] = n;
		}
	}
}
	for(j=0;j<3;j++)
	{
 	cout<<i[j]<<endl;
	}
}

Measured memory_bytes: 1160
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
if  n%k!=0:
    leng=n//k+1
else:
    leng=n//k
data=[[0 for i in range(leng)] for j in range(k)]
ans=0
for i in range(0,k):
    for j in range(0,leng):
        if i+(k*j)<n:
            data[i][j]=t[i+(k*j)]
rz=0
sz=1
pz=2
for j in range(0,k):
    dp=[[0 for x in range(3)] for y in range(leng)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    elif data[j][0]=='p':
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,leng):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='p':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else:
            dp[i][rz]=dp[i-1][rz]
            dp[i][sz]=dp[i-1][sz]
            dp[i][pz]=dp[i-1][pz]
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

Measured memory_bytes: 25612
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	ll N, K; cin >> N >> K;
	if (K == 0) {
		cout << N * N << endl;
	}
	else {
		ll ans = 0;
		//bを固定する
		for (int b = K + 1; b <= N; ++b) {
			ans += (N / b)*(b - K);
			if (N%b >= K) {
				ans += (N%b - K + 1);
			}
		}
		cout << ans << endl;
	}
	return 0;
}
//何かを固定する、規則

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll> A(N);
    priority_queue<ll, vector<ll>, less<ll>> Q;
    rep(i,N){
        ll a;
        cin>>a;
        Q.push(a);

    } 

    rep(i,M){
        ll tmp = Q.top();
        Q.pop();
        Q.push(tmp/2);
    }
    ll ans = 0;
    while(!Q.empty()){
        ans += Q.top();
        Q.pop();
    }


    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 5028
// C - Many Medians
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi X(N), Y(N);
	rpz(i, N){ cin>>X[i]; Y[i] = X[i]; }
	sort(all(Y));
	rpz(i, N) cout<< (X[i]<Y[N/2]? Y[N/2]: Y[N/2-1]) <<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    string s;
    cin >> s;
    int res=700;
    for (int i=0;i<3;i++){
	if (s[i] == 'o') res+=100;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[] point = new int[n];
			for(int i=0;i<n;i++){
				point[i] = stdIn.nextInt();
			}
			Arrays.sort(point);
			int ans = 0;
			for(int i=1;i<n-1;i++){
				ans += point[i];
			}
			ans /= n-2;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#define max(x, y) (x < y ? y : x)

int main()
{
    long N, M;
    
    scanf("%ld %ld", &N, &M);
    
    if (N == 1 && M == 1) {
        printf("1");
    } else if (N == 1 && M != 1) {
        printf("%ld", max(N, M) - 2);
    } else if (N != 1 && M == 1){
        printf("%ld", max(N, M) - 2);
    } else {
        printf("%ld", (N - 2) * (M - 2));
    }
    
    
    return 0;
}


Measured memory_bytes: 128
import sys
read = sys.stdin.read

n, k, *alst = map(int, read().split())
alst.sort()
lst1 = alst[k - 1:]
lst2 = alst[n - k::-1]
mod = 10 ** 9 + 7
res = 0
prep = 1
for i in range(n - k + 1):
    res += prep * (lst1[i] - lst2[i])
    res %= mod
    prep = prep * (i + k) * pow(i + 1, mod - 2, mod)
    prep %= mod

print(res)

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int r;cin>>r;
    cout<<r*r<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import math

N = int(input())
n = round(math.sqrt(N))+2

minmin = 10**20
for i in range(1,n):
    com = N/i
    if N % i == 0:
        c = com + i - 2
        if minmin >= c:
            minmin = c

print(int(c))


Measured memory_bytes: 3064
import math
x, k, d = map(int, input().split())

if d * k >= abs(x) and x != 0:
  # 0超える1つ手前は？
  near_0 = x // d
  if x < 0:
    near_0 += 1
  if (k - abs(near_0)) %2 == 0:
    print(abs(x - near_0 * d))
  else:
    hoge = x - near_0 * d + d
    huga = x - near_0 * d - d
    if abs(hoge) < abs(huga):
      print(abs(hoge))
    else:
      print(abs(huga))
else:
  if x == 0:
    if k%2 == 0:
      print(0)
    else:
      print(d)
  elif x > 0:
    print(abs(x-(d*k)))
  else:
    print(abs(x+(d*k)))

Measured memory_bytes: 9148
N = int(input())
A = list(map(int, input().split()))
flg = 0
for a in A:
    if a % 2 == 0:
        if not(a % 3 == 0 or a % 5 == 0):
            flg += 1

print("APPROVED" if flg == 0 else "DENIED")

Measured memory_bytes: 2940
def trans(l):
    return [list(x) for x in list(zip(*l))]

from itertools import product
import copy

h, w, k = map(int, input().split())
c = []
for _ in range(h):
    c.append([c for c in input()])

A = [i for i in product([1,0], repeat=h)]
B = [i for i in product([1,0], repeat=w)]

ans = 0
for a in A:
    temp1 = copy.copy(c)
    for i, x in enumerate(a):
        if x == 1:
            temp1[i] = ["."] * w 
    for b in B:
        temp2 = trans(temp1)
        for i, x in enumerate(b):
            if x == 1:
                temp2[i] = ["."] * h
        
        cnt = 0
        for t in temp2:
            cnt += t.count("#")
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9304
#include<stdio.h>

#define M 100
#define I 10000000
#define W 0
#define G 1
#define B 2

int n,m[M][M];

void dijkstra(){
  int min,i,j,u;
  int a[M],c[M];

  for(i = 0;i < n;i++){
    a[i] = I;
    c[i] = W;
  }

  a[0] = 0;
  c[0] = G;
  while(1){
    min = I;
    u = -1;
    for(i = 0;i < n;i++){
      if(min > a[i] && c[i] != B){
	u = i;
	min = a[i];
      }
    }
    if(u == -1){
      break;
    }
    c[u] = B;

    for(j = 0;j < n;j++){
      if(c[j] != B && m[u][j] != I){
	if(a[j] > a[u] + m[u][j]){
	  a[j] = a[u] + m[u][j];
	  c[j] = G;
	}
      }
    }
  }

  for(i = 0;i < n;i++){
    if(a[i] == I){
      a[i] = -1;
      printf("%d %d",i, a[i]);
    }else printf("%d %d",i, a[i]);
    printf("\n");
  }
  
}

int main(){
  int i,j,k,l,p,o;
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      m[i][j] = I;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d%d",&k,&l);
    for(j = 0;j < l;j++){
      scanf("%d%d",&p,&o);
      m[k][p] = o;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
#define endl "\n"
#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
//me
ll const mod = 998244353 ;
ll const inf = 1e18;
ll const maxn = 1e5+1;

void solve()
{    
    
    string s; cin >> s;
    ll ok=0;
    if(s[s.size()-1]=='s')
        ok=1;

    if(!ok)
        cout << s + 's' << endl;
    else
        cout << s + "es" << endl;


}   


int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
  
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <fstream>
#include <bitset>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define sort1(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> p;
bool paircom (pair<int,int> p,pair<int,int> q){
return p.second<q.second;
}

void count(vector<int> v,vector<int>& ans){
    sort1(v);
    int n=v.size();
  int k=1;
  int i=1;
  bool bl=true;
    while(true){
    while(bl){
        if(v[i-1]==v[i]){
        k++;    
      }else{
          bl=false;
      }
      i++;
      }
      ans.push_back(k);
      if(i>=(n-1))break;
      k=1;
      bl=true;
    }
    }




int main() {

 ll a;
 double b;
 cin >>a>>b;
 ll k;
 k=b*100+0.5;
 ll ans;
 ans=a*k;
 ans/=100;
cout << ans;
}
    

Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

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

    ll ans = 0LL;
    for (int i = 0; i < N-1; i++) {
        ans += min(B, A * (X[i+1] - X[i]));
    }

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

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
  public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      String s = sc.nextLine();
      int ans = 0;
      for(int i = 0; i < 4; i++) {
          String next = String.valueOf(s.charAt(i));
          if(next.equals("+")) {
               ans = ans + 1;
          } else if(next.equals("-")) {
               ans = ans -1;
         }
      }
      System.out.println(ans);
  }
}

Measured memory_bytes: 22740
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000000
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(ll i = 0; i < n; i++){cin >> a[i];}
#define PI 3.141592653589793
using namespace std;
int main(){
    FAST
    int n; cin >> n;
    int a[n-1];
    int boss[n+1];
    mm(boss);
    for(int i=1; i<n; i++){
        cin >> a[i];
        boss[a[i]]++;
    }
    for(int i=1; i<=n; i++){
        cout << boss[i]<< endl;
    }
    return 0;





}


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

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

  vector<int> d(N);
  rep( i, 0, N ) cin >> d.at(i);

  int Ans = 0;
  rep( i, 0, N ) {
    rep( j, i+1, N ) {
      Ans += d.at(i) * d.at(j);
    }
  }
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void fileio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 1000001; 

vector<int> h;
vector<int> dp;

int rec(int i){

    if(i==0)
        return 0;

    if(i<0)
        return INT_MAX;

    if(dp[i] != -1)
        return dp[i];

    return dp[i] = min( (i-1) >= 0 ? rec(i-1)+abs(h[i]-h[i-1]) :INT_MAX , (i-2) >= 0 ? rec(i-2)+abs(h[i]-h[i-2]) :INT_MAX  );

}    

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

    h = vector<int>(n);
    dp  = vector<int>(n,-1);
    forn(i,0,n-1)
        cin>>h[i];

    cout<<rec(n-1)<<endl;


}
 
int32_t main()
{
    
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;
  cin >> s >> t;
  cout << ((s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0] ? "YES" : "NO")) << endl;
  return 0;
}

Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = s()

SN = 0
for c in N:
    SN += int(c)

if int(N) % SN == 0:
    print('Yes')
else:
    print('No')


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

int main()
{
    int n,k,num[101]={0};
    scanf("%d%d",&n,&k);
    int i,j;
    for(j=1;j<=k;j++){
        int m;
        scanf("%d",&m);
        for(i=1;i<=m;i++){
                int u;
        scanf("%d",&u);
            num[u]=1;
        }

    }
    int sum=0;
    for(i=1;i<=n;i++){
        if(num[i]==0)
            sum++;
    }
    printf("%d",sum);
    return 0;
}

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

class node {
public:
	int d = -1, k, v[100];
	bool t = false;
};

node V[101];
int E[101], e1 = 0, e2 = 0;

void Serch(int u) {
	for (int i = 0; i < V[u].k; i++) {
		if (V[V[u].v[i]].t == false) {
			E[e1] = V[u].v[i]; e1++;
			V[V[u].v[i]].t = true;
			V[V[u].v[i]].d = V[u].d+1;
		}
	}
	if (e2 < e1) { e2++; Serch(E[e2]); }
}

int main() {
	int n, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u; cin >> V[u].k;
		for (int j = 0; j < V[u].k; j++) {
			cin >> V[u].v[j];
		}
	}

	for (int i = 1; i <= n; i++) {
		E[0] = 1; V[1].t = true; V[1].d = 0; e1++;
		Serch(E[e2]);
	}

	for (int i = 1; i <= n; i++) cout << i << " " << V[i].d << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double A,B; cin >> A >> B;
    ll ans=floor(A*B);
    cout << ans << '\n';
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int findMaxGCD(vector<int> arr, int n){ 
    int high = 0; 
    for (int i = 0; i < n; i++) 
        high = max(high, arr[i]); 
    int count[high + 1] = {0}; 
    for (int i = 0; i < n; i++) 
        count[arr[i]]++; 
    int counter = 0; 
    for (int i = high; i >= 1; i--) 
    { 
        int j = i; 
       counter = 0; 
        while (j <= high){ 
  
            if(count[j] >=2) 
               return j; 
  
           else if (count[j] == 1)          
                counter++;           
            j += i; 
            if (counter == 2)          
                return i; 
        } 
    } 
} 
int main(){
    int n;
    cin >> n;
    vector<int> arr(n);
    int GCD = 0;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        GCD = __gcd(arr[i], GCD);
    }
    int tmp = findMaxGCD(arr, n);
    if(tmp == 1){
        cout << "pairwise coprime\n";
        return 0;
    }
    if(GCD == 1){
        cout << "setwise coprime\n";
        return 0;
    }
    cout << "not coprime\n";
    return 0;
}

Measured memory_bytes: 14776
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int a, b, c; cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1 << endl;
  } else if (a == b || b == c || c == a) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
def fact(n)
  return (1..n).inject(:*)
end

def countLastZeros(num)
  num_list = num.to_s.split('').reverse
  zeroCount = 0
  num_list.each do |n|
    if n == "0"
      zeroCount += 1
    else 
      break
    end
  end
  return zeroCount
end

if __FILE__ == $0
  while line = gets
    n = line.to_i
    if n == 0
      break
    end
    puts countLastZeros(fact(n))
  end
end

Measured memory_bytes: 12704
N, K = (int(x) for x in input().split())

trees = list()

for i in range(N):
  trees.append(int(input()))
  
trees = sorted(trees)
diff_list = []

for i in range(N - K + 1):
  diff = trees[i + K - 1] - trees[i]
  diff_list.append(diff)
  
print(min(diff_list))

Measured memory_bytes: 10892
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
A = inputIL()

MAX = max(A)

imos = [0]*(MAX*2+2)
imos[0] = N

for i in A:
  imos[i+1] -= 1
for i in range(1,len(imos)):
  imos[i] = imos[i-1]+imos[i]


def count_m(X):
  m = 0
  for i in A:
    m += imos[max(0,X-i)]
  return m

upper = MAX*2
lower = 0
X = (upper+lower)//2
m = count_m(X)


#print(m,X,lower,upper)
while upper != lower:
  if m > M:
    temp = lower
    lower = (upper+lower-1)//2
    if lower == temp:
      lower += 1
  else:
    temp = upper
    upper = (upper+lower+1)//2
    if upper == temp:
      upper -= 1
  X = (upper+lower+1)//2
  m = count_m(X)
  #print(m,X,lower,upper)

  
imos2 = [0]*(MAX*2+2)
for i in A:
  imos2[0] += i
  imos2[i+1] -= i
for i in range(1,len(imos2)):
  imos2[i] = imos2[i-1]+imos2[i]
  
ans = 0
for i in A:
  ans += i*imos[max(X-i,0)]+imos2[max(X-i,0)]
  
print(ans-(m-M)*X)


Measured memory_bytes: 80780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  string s;
  cin >> s;

  deque<char> dq;
  rep(i, s.size()) {
    if (dq.empty()) {
      dq.push_back(s[i]);
    } else if (dq.back() == 'S' && s[i] == 'T') {
      dq.pop_back();
    } else {
      dq.push_back(s[i]);
    }
  }

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

  return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<stack>
#include<vector>
#include<map> 
#define maxn 100005
#define INF 1000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int a[maxn],tot=0,cnt=0;


int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		tot+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(m*4*a[i]<tot)
		{
			continue;
		}else{
			cnt++;
		}
	}
	if(cnt>=m)
	{
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
k=int(input())
a=7%k
if k%2==0 or k%5==0:
	print(-1)
elif k==1:
	print(1)
else:
	for i in range(k):
		if a==0:
			print(i+1)
			break
		a=(a*10+7)%k
	else:
		print(-1)

Measured memory_bytes: 63240
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int m=(1<<n);
	vector<int> a(m),m1(m,0),m2(m,0);
	for(int i=0;i<m;i++){
		cin >> a[i];
	}
	for(int i=1;i<m;i++){
		for(int j=i;j>0;j=(j-1)&i){
			if(a[j]>m1[i]){
				m2[i]=m1[i];
				m1[i]=a[j];
			}
			else if(a[j]>m2[i]){
				m2[i]=a[j];
			}
		}
		if(a[0]>m1[i]){
			m2[i]=m1[i];
			m1[i]=a[0];
		}
		else if(a[0]>m2[i]){
			m2[i]=a[0];
		}
	}
	int now=0;
	for(int i=1;i<m;i++){
		now=max(now,m1[i]+m2[i]);
		cout << now << endl;
	}
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI  3.1415926535
#define rep(i, k, n) for(ll i = k; i < n; i++)

const ll MAX = 1000010;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  ll x, y; cin >> x >> y;
  ll a, b;
  a = -1; b = -1;
  rep(i, 0, x/2+1){
    ll s, t;
    s = i;
    t = x - 2*s;
    if(s + 2 * t == y){
      a = s; b = t; break;
    }
  }
  //cout << a << b << endl;
  if(a == -1){cout << 0 << endl;}
  else{
    COMinit();
    cout << COM(a+b,a) << endl;
  }
  
}

Measured memory_bytes: 27036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define all(a) (a).begin(),(a).end()
using namespace __gnu_pbds;
using namespace std;

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

signed main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int& i : arr) cin >> i; 
    int cnt = 0 ;
    for(int i=0;i<n;i++){
        if(!(i&1) and arr[i]&1){
            cnt++;
        }
    }
    cout << cnt << endl ;
    return 0;
}


Measured memory_bytes: 3612
# input
A = []
for i in range(3):
    A.append(list(map(int, input().split())))

N = int(input())

B = []
for i in range(N):
    B.append(int(input()))

# process
A2 = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A2[i][j] = 1
                break

# ビンゴの判定
result = False 

# 横
for i in range(3):
    if A2[i][0]==1 and A2[i][1]==1 and A2[i][2]==1:
        result = True
# 縦
if not result:
    for i in range(3):
        if A2[0][i]==1 and A2[1][i]==1 and A2[2][i]==1:
            result = True

# 斜め
if not result:
    if A2[0][0]==1 and A2[1][1]==1 and A2[2][2]==1:
        result = True
    elif A2[0][2]==1 and A2[1][1]==1 and A2[2][0]==1:
        result = True

# output
print("Yes" if result else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	map<int, int>u;
	for(int i = 1; i <= 100; i++){
		for(int j = 1; j <= 100; j++){
			for(int k = 1; k <= 100; k++){
				u[i*i+j*j+k*k+i*j+i*k+k*j]++;
			}
		}
	}	
	for(int i = 1; i <= n; i++)cout<<u[i]<<"\n";
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 5956
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 100000000000
#define MOD 1000000007
 
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

long path[401][401];
 
void init() {
	long i, j;
	
	for(i=1;i<=400;i++) {
		for(j=1;j<=400;j++) {
			if(i == j) {
				path[i][j] = 0;
			} else {
				path[i][j] = INF;
			}
		}
	}
}

int main() {
	long N, M;
	long a[1001], b[1001], c[1001];
	long i, j, k;
	long tmp;
	long ans;
	
	init();
	
	sl(N); sl(M);
	ans = M;
	for(i=1;i<=M;i++) {
		sl(a[i]); sl(b[i]); sl(c[i]);
		path[a[i]][b[i]] = c[i];
		path[b[i]][a[i]] = c[i];
	}
	
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			for(k=1;k<=N;k++)
				path[j][k] = MIN(path[j][k], path[j][i] + path[i][k]);
	
	for(k=1;k<=M;k++) {
		for(i=1;i<=N;i++) {
			if(path[i][a[k]] + c[k] == path[i][b[k]]) {
				ans--;
				break;
			}
		}
	}
	
	pl(ans);
	
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class Solver{
public:
	static void solve() {
		int a, b;
		cin >> a >> b;
		vector<string> res;

		while (a != 0 && b != 0) {
			int cnt = 0;
			for (int i = a; i <= b; i++) {
				if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
					string str("");
					int ii = i;
					while (ii > 0) {
						char c = '0' + ii % 10;
						str = string() + c + str;
						ii /= 10;
					}
					res.push_back(str);
					cnt++;
				}
			}
			if (cnt == 0)res.push_back("NA");
			cin >> a >> b;
			if (a != 0 && b != 0)res.push_back("");
		}

		for (int i = 0; i < res.size(); i++)cout << res[i] << endl;
	}
};

int main() {
	Solver::solve();
}


Measured memory_bytes: 3240
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
vector<long long> siz;long long vis[205][205];long long mod=998244353;
long long quipow(long long a,long long b)
{
    long long ans=1;
     while(b)
     {
         if(b&1) ans=ans*a%mod;
         b>>=1;
         a=a*a%mod;
     }
     return ans%mod;
}
long long fac[505],inv[505];
void prepare()    
{
    fac[0]=fac[1]=1;
    for(long long i=2;i<=500;i++)   fac[i]=fac[i-1]*i%mod;

    inv[500]=quipow(fac[500],mod-2);
    for(long long i=500-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
pair<double,double> p[505];
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	prepare();
	long long n;cin>>n;
	for(long long i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;
	}
	for(long long i=0;i<n;i++)
	{
		for(long long j=0;j<n;j++)
		{
			vector<int> v;v.clear();
			if(i==j or(vis[i][j]==1)) continue;v.push_back(i);v.push_back(j);
			if(p[i].first==p[j].first)
			{
				long long u=0;u++;u++;
				for(long long t=0;t<n;t++)
				{
					if(i==t or j==t) continue;
					if(abs(p[t].first-p[i].first)<1e-10)
					{
						v.push_back(t);
						u++;
					}
				}
				if(u>2)siz.push_back(u);
				for(int t=0;t<v.size();t++) for(int y=0;y<v.size();y++) vis[v[y]][v[t]]=1; 
				continue;
			}
			double k=(p[i].second-p[j].second)/(p[i].first-p[j].first);
			double b=p[i].second-p[i].first*k;
			long long u=0;u++;u++;
			for(long long t=0;t<n;t++)
			{
				if(i==t or j==t) continue;
				if(abs(p[t].first*k+b-p[t].second)<=1e-10)
				{
					v.push_back(t);
					u++;
				}
			}
			if(u>2)siz.push_back(u);
			for(int t=0;t<v.size();t++) for(int y=0;y<v.size();y++) vis[v[y]][v[t]]=1; 
		}
	}
	long long ans=0;long long y=n*(n-1);
	for(long long i=3;i<=n;i++)
	{
		y=y*(n-i+1);y=y%mod;
		ans+=y*inv[i];ans=ans%mod;
	}
	for(long long i=0;i<siz.size();i++)
	{
		y=(siz[i])*(siz[i]-1);
		for(long long j=3;j<=siz[i];j++)
		{
			y=y*(siz[i]-j+1);y=y%mod;
			ans-=y*inv[j];ans=ans%mod;
		}
	}
	if(ans<0) ans+=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
def match(s, t):
    if len(s)!=len(t):
        return False
    for i in range(len(s)):
        if s[i] != "?" and s[i] != t[i]:
            return False
    return True


def main():
    s = input()
    t = input()

    replaced = False
    for l in range(len(s)-len(t), -1, -1):
        r = l + len(t)
        if match(s[l:r], t):
            replaced = True
            s = s[:l] + t + s[r:]
            break
    if not replaced:
        print("UNRESTORABLE")
    else:
        print(s.replace("?", "a"))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 1 * 10**5 + 100
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ind = [-1] * (1+n)
for i,ai in enumerate(a,1):
    if(ind[ai]==-1):
        ind[ai] = i
    else:
        left = ind[ai]
        right = i
        break

ans = [0] * (n+2)
for k in range(1,n+2):
    cnt = com(n-1,k) + com(n-1,k-1)*2 - com(n - (right-left),k-1)
    if(k >= 2):
        cnt += com(n-1,k-2)
    ans[k] = cnt%mod

print('\n'.join(map(str,ans[1:])))

Measured memory_bytes: 94748
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 101;
int cnt=3,pw[N],pw2[N];
struct node{
	char opt;
	int x,y,z;
};
vector<node>ans;
#define A 0
#define B 1
ll a[500000];
inline int Add(int x,int y,int z){
	a[x]=a[y]+a[z];
	ans.pb((node){'+',y,z,x});
	return x;
}
inline int cmp(int x,int y,int z){
	a[x]=(a[y]<a[z]);
	ans.pb((node){'<',y,z,x});
	return x;
}
inline void init(){
	pw[0]=cnt;
	For(i,1,30) pw[i]=++cnt;
	pw2[0]=++cnt;
	For(i,1,60) pw2[i]=++cnt;
	Add(pw[0],A,pw[0]);
	For(i,1,30) Add(pw[i],pw[i-1],pw[i-1]);
	Add(pw2[0],pw2[0],cmp(100000,pw[0],pw[1]));
	For(i,1,60) Add(pw2[i],pw2[i-1],pw2[i-1]);
}

int B2,k,bit[N],s,Pw[N],Pw2[N];
inline void Mul(int x,int y){
	Add(120000,119999,x);
	Add(120000,120000,cmp(125000,x,y));
	Add(120001,x,y);
	Add(x,119999,cmp(120001,120000,120001));
}
inline void AddPow(int s,int bit,int b){
	Add(150000,149999,bit);
	For(i,1,b) Add(150000+i,150000+i-1,150000+i-1);
	Add(s,s,150000+b);
}
inline void work(){
	For(i,0,30) Pw[i]=++cnt,Add(Pw[i],pw[i],pw2[0]);
	For(i,0,60) Pw2[i]=++cnt,Add(Pw2[i],pw2[i],pw2[0]);
	B2=++cnt,k=++cnt;
	For(i,0,60) bit[i]=++cnt;
	s=++cnt;
	Add(B2,B,pw2[0]);
	Dow(i,30,0){
		int tmp=cmp(100000,Add(100001,k,pw2[i]),B2);
	//	printf("%d %lld\n",i,a[tmp]);
		cmp(s,pw2[1],pw2[0]);
		Dow(j,60,0){
			cmp(bit[j],Add(100002,s,pw2[j]),Pw[i]);
			AddPow(s,bit[j],j);
		}
		For(j,0,60) Mul(bit[j],tmp);
		Add(110000,109999,109999);
		Dow(j,60,0){
			Add(110000+(60-j+1),110000+(60-j+1)-1,110000+(60-j+1)-1);
			Add(110000+(60-j+1),110000+(60-j+1),bit[j]);
		}
		Add(2,110061,2);

		cmp(s,pw2[1],pw2[0]);
		Dow(j,30,0){
			cmp(bit[j],Add(100002,s,pw2[j]),Pw2[i]);
			AddPow(s,bit[j],j);
		}
		For(j,0,30) Mul(bit[j],tmp);
		Add(110000,109999,109999);
		Dow(j,30,0){
			Add(110000+(30-j+1),110000+(30-j+1)-1,110000+(30-j+1)-1);
			Add(110000+(30-j+1),110000+(30-j+1),bit[j]);
		}
		Add(k,110031,k);
	}
}

inline void print(){
	assert(a[2]==a[0]*a[1]);
//	printf("%lld\n",a[2]);
	printf("%d\n",siz(ans));
	for (auto i:ans) printf("%c %d %d %d\n",i.opt,i.x,i.y,i.z);
}

int main(){
//	a[0]=read(),a[1]=read();
	init(),work(),print();
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    vector<int> v(n);
    for(int i=0; i<n; i++){
        v[i]=(s[i]-'1');
    }
    
    vector<int> tct(n);
    for(int i=1; i<n; i++){
        int ct=0, cur=i;
        while(!(cur%2)){
            cur/=2;
            ct++;
        }
        tct[i]=tct[i-1]+ct;
    }
    bool has1=0;
    for(int i:v){
        if(i==1){
            has1=1;
            break;
        }
    }
    if(has1){
        int ans=0;
        for(int i=0; i<n; i++){
            int ct=tct[n-1]-tct[i]-tct[n-1-i];
            if(!ct){
                ans+=v[i];
            }
            
            ans%=2;
        }
        cout<<ans;
        return 0;
    }
    int ans=0;
    for(int i=0; i<n; i++){
        int ct=tct[n-1]-tct[i]-tct[n-1-i];
        if(!ct){
            ans+=v[i]/2;
        }
        
        ans%=2;
    }
    cout<<2*ans;
    return 0;
}

Measured memory_bytes: 9116
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        char[] ch = str.toCharArray();
 
        if (ch[0] == ch[1] && ch[0] == ch[1] && ch[0] == ch[3]) {

          System.out.println("No");
          
        } else if ( (ch[0] == ch[1] && ch[2] == ch[3]) ||
                    (ch[0] == ch[3] && ch[1] == ch[2]) ||
                    (ch[0] == ch[2] && ch[1] == ch[3]) ) {
          
          System.out.println("Yes");
            
        } else {
          System.out.println("No");
        }
	}
}

Measured memory_bytes: 20948
def get_prime_nums(max_p)
  primes = (0..max_p).map{true}
  primes[0] = primes[1] = false

  smp = Math::sqrt(0.5 + max_p).to_i

  for p in (2..smp)
    if (primes[p])
      (p * p).step(max_p, p){|q| primes[q] = false}
    end
  end
  #puts "#{primes.select{|p| p }.length} primes"

  return primes
end

### main

max_p = 60000
primes = get_prime_nums(max_p)

p_nums = (2..max_p).select{|p| primes[p]}

while true
  n = gets.chomp.to_i
  break if n == 0

  count = 0

  for p in p_nums
    q = n - p
    break if p > q

    if primes[q]
      count += 1
      #puts "#{p}+#{q}"
    end
  end

  puts count
end

Measured memory_bytes: 6720
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair

int node[100000];
ll ans = 0;
int main() 
{
   int n,m,k,l;
   cin>>n>>m;
   rep(i,m){
     cin>>k>>l;
     node[k]++;
     node[l]++;
   }
   bool isTrue=true;
   rep(i,n){
       if(node[i]%2){
           isTrue=false;
           break;
       }
   }
    cout<<(isTrue? "YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define N 1000000
bool a[1000000];
int main(){
  a[0]=a[1]=1;
  for(int i=2;i*i<=N;i++)
    if(a[i]==0)
      for(int j=2;j*i<N;j++)a[i*j]=1;
  vector <int> b;
  for(int i=0;i<N;i++)
    if(a[i]==0)
      b.push_back(i);
  while(1){
    int n,p,x;
    cin>>n>>p;
    if(n==-1&&p==-1)break;
    for(int i=0;i<b.size();i++)
      if(b[i]>n){
	x=i;
	break;
      }
  vector <int> c;
    for(int i=x;i<x+p;i++)
      for(int j=i;j<x+p;j++)
	c.push_back(b[i]+b[j]);
    sort(c.begin(),c.end());
    cout<<c[p-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a, b, k;
  cin >> a >> b >> k;
  long long err = 0;
  if(a - k > 0) cout << a - k << " " << b << endl;
  else cout << 0 << " " << max(err, b - (k - a)) << endl;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s = "";
  rep(i,3){
    string tmp; cin >> tmp;
    s+=tmp;
  }
  int a = stoi(s);
  if(a%4==0) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ABS(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))

#define MOD(x, y) ((x) % (y))
#define DIVCEIL(x, y) (((x) + ((y) - 1)) / (y))
#define DIVFLOOR(x, y) (((x) + ((y) / 2)) / (y))
#define DIVROUND(x, y) ((x) - MOD(x, y) >= MOD(x, y) ? DIVCEIL(x, y) : DIVFLOOR(x, y))

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

  if (X < Y)
    swap(X, Y);

  printf("%d %d\n", MIN(X, Y), MAX(0, X + Y - N));
  return 0;
}


Measured memory_bytes: 888