akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for(;;) {
      int n = ni();
      if(n==0) {
        break;
      }
      boolean[][] src = new boolean[n + 1][n + 1];
      int[] map = new int[n + 1];
      int[] cnt = new int[n + 1];
      for(int i = 1; i <= n; ++i) {
        int m = ni();
        for(int j = 0; j < m; ++j) {
          int p = ni();
          map[p] = i;
          ++cnt[p];
          src[i][p] = true;
        }
      }
//      for(boolean[] ite : src) debug(ite);
//      debug(map);
      
      int k = ni();
      int[] dst = new int[k];
      HashSet<Integer> list = new HashSet<Integer>();
      for(int i = 0; i < k; ++i) {
        int l = ni();
        dst[i] = l;
        if(cnt[l] == 1) {
          list.add( map[l] );
        }
      }
//      debug(list);
      if( list.size() > 0 ) {
        boolean fin = false;
        for(int ite : list) {
          boolean flag = true;
          for(int v : dst) {
//            debug(v, src[ite][v]);
            flag &= src[ite][v];
          }
          if(flag) {
            System.out.println(ite);
            fin = true;
            break;
          }
        }
        if(!fin) {
          System.out.println(-1);
        }
      } else {
        System.out.println(-1);
      }
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

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

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

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

int main(){
    int n;
    cin >> n;
    int ln = n % 10;

    if (ln == 2 || ln == 4 || ln == 5 || ln == 7 || ln==9){
        cout << "hon" << endl;
    }
    else if (ln == 3)
    {
        cout << "bon" << endl;
    }
    else
    {
        cout << "pon" << endl;
    }
    
    
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

const li N=3e6;

bool prime[N];
li spf[N];

void sieve()
{
    prime[1]=false;
    spf[1]=1;

    f(i,2,N-1)
    {
        prime[i]=true;
        spf[i]=i;
    }

    for(li i=2;i*i<N;i++)
    {
        if(prime[i])
        {
            for(li j=i*i;j<N;j+=i)
            {
                prime[j]=false;
            }
        }
    }

    for(li i=4;i<N;i+=2)
    {
        spf[i]=2;
    }

    for(li i=3;i*i<N;i++)
    {
        if(spf[i]==i)
        {
            for(li j=i*i;j<N;j+=i)
            {
                if(spf[j]==j)
                {
                    spf[j]=i;
                }
            }
        }
    }
}

void solve()
{
    sieve();

    li n;

    cin>>n;

    li a[n];

    f(i,0,n-1)
    {
        cin>>a[i];
    }

    map<li,li> m;

    li flag=1;

    f(i,0,n-1)
    {
        li x=a[i];

        set<li> v;

        while(x!=1)
        {
            v.insert(spf[x]);
            x=x/spf[x];
        }

        for(li j:v)
        {
            if(m.count(j))
            {
                flag=0;
                break;
            }
            else
            {
                m[j]=1;
            }
        }

        if(!flag)
            break;
    }

    if(flag)
    {
        cout<<"pairwise coprime";
        return;
    }

    li ans=a[0];

    f(i,1,n-1)
    {
        ans=__gcd(ans,a[i]);
    }

    if(ans==1)
    {
        cout<<"setwise coprime";
    }
    else
    {
        cout<<"not coprime";
    }
}

int main()
{    
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 37832
#include<cstdio>
#include<cstring>
using namespace std;
char s[100005];
int main()
{
	scanf("%s", s);
	int cnt = 0;
	for(int i = 1; i < strlen(s) - 1; i++)
		cnt++;
	printf("%c%d%c", s[0], cnt, s[strlen(s) - 1]);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll t = 1;
    //cin>>t;

    while(t--) {

        ll n;
        cin>>n;

        ll a;

        map<int,int>mp;
        for(int i=0;i<n-1;i++) {
            cin>>a;
            mp[a]++;
        }

        for(int i=1;i<=n;i++) {
            cout<<mp[i]<<"\n";
        }

    }

}



Measured memory_bytes: 13000
#coding : utf-8

class UnionFind:
    def __init__(self, n):
        self.nodes = list(range(n))
 
    def root(self, x):
        if (self.nodes[x] == x):
            return x
        self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]
    
    def unite(self, x, y):
        if (self.root(x) == self.root(y)):
            return
        self.nodes[self.root(x)] = self.root(self.nodes[y])
        return
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

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.unite(x-1, y-1)

s = 0
for i in range(n):
    if (tree.same(i, p[i] - 1)):
        s += 1
print(s)



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

int main(){
	int n; cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];

	int l_last = 1;
	ll l[n];
	l[0] = a[0];
	roop(i, 1, n){
		if(l[l_last-1] < a[i]) l[l_last++] = a[i];
		else {
			auto lb = lower_bound(l, l+l_last, a[i]);
			l[lb - l] = a[i];
		}
	}

	cout << l_last << endl;
	return 0;
}



Measured memory_bytes: 4652
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int p[100005];
int n;
int sugo[100005];
bool flag[100005];

int bfs() {

    queue<P> que;
    // 位置,回数
    que.push(P(0,0));

    while(que.size()) {
        P pos = que.front();
        que.pop();

        int now = pos.first;
        int count = pos.second;
        if(flag[now]) continue;
        flag[now]=true;
        // printf("[debug] %d,%d\n", now, count);

        if(now >= n-1) {
            return count;
        }

        rep(i,6) {
            if(sugo[now+i+1]==-1) continue;
            que.push(P(sugo[now+i+1],count+1));
        }
    }

    return INF;

}

int main() {
    cin>>n;
    rep(i,n) cin>>p[i];
    rep(i,100005) sugo[i]=INF;
    set<int> visited;

    rep(i,n) {
        if(sugo[i]!=INF) continue;
        if(p[i]==0) {
            sugo[i]=i;
        }
        else {
            int s = i;
            int now = i+p[i];
            visited.clear();
            while(1) {
                if(now==s) {
                    sugo[i]=-1;
                    now=-1;
                    break;
                }
                if(visited.find(now)!=visited.end()) {
                    sugo[i] = -1;
                    now=-1;
                    break;
                }
                if(p[now]==0) {
                    sugo[i]=now;
                    break;
                }
                else {
                    visited.insert(now);
                    now+=p[now];
                }
            }
            for(auto & e : visited) {
                sugo[e] = now;
            }
        }
    }

    // rep(i,n) cout<<sugo[i]<<endl;
    cout<<bfs()<<endl;

    return 0;
}

Measured memory_bytes: 5992
import math
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
S=[i+1 for i in range(N)]
#R=P
#S=Q
def place(a):
  R=S.copy()
  count=1
  for i in range(0,N):
    count += (R.index(a[i]))*math.factorial(N-1-i)
    del R[R.index(a[i])]
    
  return(count)

print(abs(place(P)-place(Q)))

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

int main () {
    int X, Y;
    string S;
    cin >> X >> Y;
  
    int min = X * 2;
    int max = X * 4;
    
    if (min <= Y && Y <= max && Y % 2 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a; cin >> n >> a;
	for (int h = 1; h < 12345; h++) {
		if (n >= a) {
			n = n - a;
		}
		else {
			n--;
		}
		if (n == 0) {
			cout << h << endl; return 0;
		}
	}
	cin >> n;
}


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

int main(){
    int n, r, rate[9] = {0};
    scanf("%d", &n);
    rep(_, n){
        scanf("%d", &r);
        rate[min(r, 3200) / 400]++;
    }
    int maxs, mins = 0;
    rep(i, 8){
        mins += rate[i] > 0;
    }
    maxs = mins + rate[8];
    printf("%d %d\n", max(1, mins), maxs);
    return 0;
}

Measured memory_bytes: 256
using System;
class Hoge
{
 
 
static void Main(){
 
    string a;   
    while((a = Console.ReadLine()) != null){
    int ans=0;     
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                for(int l=0;l<10;l++){
                    if((i+j+k+l)==int.Parse(a))ans++;
                }
            }
        }
    }
    Console.WriteLine(ans);
}
}}

Measured memory_bytes: 5600
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    M = [1]
    for i in range(1, 12):
        if pow(6, i) > N: break
        M.append(pow(6, i))
    for i in range(1, 10):
        if pow(9, i) > N: break
        M.append(pow(9, i))
    M.sort()

    DP = [100000] * (N + 1)
    DP[N] = 0
    for i in reversed(range(N + 1)):
        if DP[i] < 100000:
            for m in M:
                if i - m >= 0: DP[i-m] = min(DP[i-m], DP[i] + 1)
    print(DP[0])

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
const int MX = 1e6 + 5;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(MX);
  rep(i,n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool p = true;
  for (int i = 2; i < MX; ++i) {
    int cnt = 0;
    for (int j = i; j < MX; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) p = false;
    if (!p) break;
  }
  if (p) {
    cout << "pairwise coprime\n";
    return 0;
  }

  int g = 0;
  rep(i,n) g = __gcd(g, a[i]);
  if (g == 1) cout << "setwise coprime\n";
  else cout << "not coprime\n";
}

Measured memory_bytes: 11056
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main(){
	long long x;
	scanf("%lld",&x);
	if(x<=6){
		printf("1\n");
		return 0;
	}
	if(x<=11){
		printf("2\n");
		return 0;
	}
	long long t = x/11;
	int m = x%11;
	if(m==0){
		printf("%lld\n",t*2 );
		return 0;
	}
	if(m<=6) printf("%lld\n",t*2+1);
	else printf("%lld\n",t*2+2);
	return 0;
}

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,n;
    cin>>n>>a>>b;
    ll ans=0,dummy=0,sum;
    for(int i=a;i<=n;i++)
    {
        dummy=i;
        sum=0;
        while(dummy)
        {
            sum+=(dummy%10);
            dummy/=10;
        }
        if(sum>=a&&sum<=b)
        {
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <time.h>
# include <math.h>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define MAXN 250
# define eps 1e-3
# define MAXM 500005
# define MOD 1000000007
# define INF 1000000000
# define MIN(a,b) (a)>(b)?(b):(a)
# define MAX(a,b) (a)<(b)?(b):(a)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
typedef long long LL;
typedef unsigned long long ULL;

int main()
{
    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')printf("vowel");
    else printf("consonant");
    return 0;
}



















Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(1,0); }
	V<V<pin>> qab(2);
  int sz=ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
	for (pin &x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2,x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2,(x.second + 1) / 2)); }
	}
  int c=0;
  		for (pin &x : qab[0]) {
			int qc = (2 * x.first + x.second)%3;
          c^=(qc+1);
		}
		if (!c) {
			pin ans = solve(qab[1], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += 1;
			return ans;
		}
    c=0;
		for (pin &x : qab[1]) {
			int qc = (2 * x.first + x.second)%3;
          c^=(qc+1);
		}
		if (!c) {
			pin ans = solve(qab[0], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += 0;
			return ans;
		}
	for(pin &v:ab) { v.first++; }
	pin ans = solve(ab, ex); ans.first--;
	return ans;
}
signed main() {
	long long inf = 2e17;
	int n; scanf("%lld", &n);
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; scanf("%lld", &a); scanf("%lld", &b);
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 11136
x, y = map(int, input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
if x == 2 or y == 2:
    print('No')
elif (x in a and y in a) or (x in b and y in b):
    print('Yes')
else:
    print('No')


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

int main(){
  int a;
  string s;
  cin >> s;
  int alp[26]={};
  for(int i=0;i<s.size();i++)
    alp[s.at(i)-97]++;
  for(int j=0;j<26;j++){
    if(alp[j]==0){
      cout << char(j+97) << endl;
      break;
    }
    else a++;
  }
  if(a==26)
    cout << "None" << endl;
}	

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


const ll MOD = ll(1e9 + 7);
ll dp[100010][4];


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;

	int N = s.size();
	dp[0][0] = 1;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= 3; j++){
			ll d = dp[i][j];
			for(int k = 0; k < 3; k++){
				if(s[i] != '?' && s[i] != 'A' + k) continue;
				dp[i + 1][j] += d;
				dp[i + 1][j] %= MOD;
				if(j == k){
					dp[i + 1][j + 1] += d;
					dp[i + 1][j + 1] %= MOD;
				}
			}
		}
	}

	cout << dp[N][3] << endl;
}


Measured memory_bytes: 3664
import java.util.Scanner;

/**
 * @author yousack
 */
public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            int n = in.nextInt();
            if (n == 0) {
                break;
            } else {
                solve(n);
            }
        }
    }
    
    public static void solve(int n) {
        int counter = 0;
        for (int i = n + 1; i <= n * 2 ; i++) {
            if (isPrime(i)) {
                counter++;
            }
        }

        System.out.println(counter);
    }
    
    public static boolean isPrime(int n) {
        boolean result = true; 
        
        if (n == 1) {
            result = false;
        }
        
        for (int i = 2; i <= Math.sqrt((double)n); i++) {
            if (n % i == 0) {
                result = false;
                break;
            }
        }
        
        return result;
    }
}

Measured memory_bytes: 20056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

class Main{

static class DataOfPCK{

int num;
int answer;

DataOfPCK(int num,int answer){
this.num=num;  this.answer=answer;
}

static final Comparator<DataOfPCK> ANSWER_ORDER=new AnswerOrderComparator();

private static class AnswerOrderComparator implements Comparator<DataOfPCK>{
public int compare(DataOfPCK d1,DataOfPCK d2){
return (d1.answer>d2.answer)?-1:(d1.answer<d2.answer)?1:0;
}
}
}

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
ArrayList<DataOfPCK> array=new ArrayList<DataOfPCK>();
HashMap<Integer,Integer> dic=new HashMap<Integer,Integer>();
DataOfPCK d;
int p,rank;

while(!(line=br.readLine()).equals("0,0")){
String[] values=line.split(",");
int num=Integer.parseInt(values[0]);
int answer=Integer.parseInt(values[1]);
array.add(new DataOfPCK(num,answer));
}

Collections.sort(array,DataOfPCK.ANSWER_ORDER);

p=-1;
rank=0;
for(int i=0;i<array.size();i++){
d=array.get(i);
if(d.answer==p){
dic.put(d.num,rank);
}
else{
rank++;
dic.put(d.num,rank);
p=d.answer;
}
}

while((line=br.readLine())!=null){
System.out.println(dic.get(Integer.parseInt(line)));
}
}

}

Measured memory_bytes: 16936
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int x=a+b;
    int y=a-b;
    int z=a*b;
    if(x==y || x==z ||(x>y && x>z))
        printf("%d\n",x);
    else if(x==y || x==z ||(x<y && y>z))
        printf("%d\n",y);
    else
        printf("%d\n",z);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		int nums[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < m; k++) {
				int a = sc.nextInt();
				nums[i][k] = a;
			}
		}
		int matrix[][] = new int[m][l];
		for (int i = 0; i < m; i++) {
			for (int k = 0; k < l; k++) {
				int b = sc.nextInt();
				matrix[i][k] = b;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < l; k++) {
				long c = 0;
				for (int j = 0; j < m; j++) {
					c = nums[i][j] * matrix[j][k] + c;
				}
				System.out.print(c);
				if (k + 1 != l) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
    }
}



Measured memory_bytes: 53548
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if ((a==5 && b==5 && c==7) || (a==5 && b==7 && c==5) || (a==7 && b==5 && c==5))
		cout<<"YES";
	else
		cout<<"NO";
	re 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		
		int angka = input.nextInt();
		
		int sum = 0;
		
		for (int a=1;a<=angka;a++){
			sum+=a;
		}
		
		System.out.println(sum);

	}

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());

            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();


        }
    }
}


Measured memory_bytes: 11092
sp = gets.strip
t = gets.strip

min = '~'
sp.chars.each_cons(t.size).with_index do |subs, ix|
  rgx = Regexp.new(subs.map { |c| c == '?' ? '.' : c }.join)
  if t =~ rgx
    r = sp[0, ix] + t + sp[(ix + t.size)..-1]
    s = r.chars.map { |c| c == '?' ? 'a' : c }.join
    min = [min, s].min
  end
end
if min == '~'
  puts 'UNRESTORABLE'
else
  puts min
end


Measured memory_bytes: 1788
S = input()
ans = 'TBD'
if int(S[:4]) < 2019:
	ans = 'Heisei'
elif int(S[:4]) == 2019 and int(S[5:7]) < 4:
	ans = 'Heisei'
elif int(S[:4]) == 2019 and int(S[5:7]) == 4 and int(S[8:10]) <= 30:
	ans ='Heisei'
print(ans)

Measured memory_bytes: 3064
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,ans = 0;

    cin >> N;
    REPR(i,8){
        if(N%(i+1) == 0){
            if(N/(i+1) < 10){
                ans = 1;
            }
        }
    }
    if(ans == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#ABC154D
import sys
N, K = map(int, sys.stdin.readline().split())
P = list(map(int, sys.stdin.readline().split()))

#print(P)

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2
#print(L)

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

#print(S)
total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)

Measured memory_bytes: 25632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1001;
int n;
vector<int> g[MAX_N];
int match[MAX_N];
int used[MAX_N];
void add_edge(int src,int dst){
    g[src].pb(dst);
    g[dst].pb(src);
}
bool dfs(int v){
    used[v]=true;
    rep(i,g[v].size()){
        int u=g[v][i],w=match[u];
        if(w<0||!used[w]&&dfs(w)){
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res=0;
    memset(match,-1,sizeof(match));
    rep(i,n){
        if(match[i]<0){
            memset(used,0,sizeof(used));
            if(dfs(i)) ++res;
        }
    }
    return res;
}

int a[1001];
int main(){
    int m;
    while(cin>>n>>m,n|m){
        rep(i,1001) g[i].clear();
        rep(i,n) cin>>a[i];
        rep(i,m) cin>>a[i+n];
        rep(i,n)FOR(j,n,n+m){
            if(__gcd(a[i],a[j])!=1) add_edge(i,j);
        }
        cout<<bipartite_matching()<<endl;
    }
    return 0;
}


Measured memory_bytes: 4904
import sys
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]
    if len(W) != len(set(W)):
        print('No')
        sys.exit(0)
    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print('No')
            sys.exit(0)
    print('Yes')

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

int main()
{
    priority_queue<int> Q;
    while (true)
    {
        string cmd;
        cin>>cmd;
        if (cmd=="insert")
        {
            int k;
            cin>>k;
            Q.push(k);
        }
        if (cmd=="extract")
        {
            cout<<Q.top()<<endl;
            Q.pop();
        }
        if (cmd=="end")
        {
            break;
        }
    }
}


Measured memory_bytes: 6996
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

   int n, t, a;
   cin >> n >> t >> a;

   vector<double> h(n);
   REP(i, n) {
       double tmp;
       cin >> tmp;
       h[i] = abs(a - ((double)t - tmp * 0.006));
   }

   decltype(h)::iterator itr = min_element(h.begin(), h.end());
   size_t indexMin = distance(h.begin(), itr);
   cout << indexMin + 1 << '\n';
   return 0;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
  A.append(int(input()))

P = [0 for i in range(N)]


for i in range(Q):
    P[A[i] - 1] = P[A[i] - 1] + 1
      

for i in range(N):
  if (Q - P[i] >= K ):
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 8596
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        while (true) {

            int h = inp.nextInt();
            int w = inp.nextInt();
            if (h == 0 && w == 0) {
                break;
            } else if (h >= 3 && w < 300) {
                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {

                        if (i == 0 || i == (h - 1)) {
                            System.out.print('#');
                        } else {
                            if (j == 0 || j == (w - 1)) {
                                System.out.print('#');
                            } else {
                                System.out.print('.');
                            }
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }

        }
    }
}


Measured memory_bytes: 36108
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)
def modinv(k,mod):
    return pow(k,mod-2,mod)

def main():
    mod=1000000007
    n=int(input())
    A=tuple(map(int,input().split()))
    l=1
    for a in A:
        l=lcm(l,a)
    l%=mod
    ans=0
    for a in A:
        ans+=l*modinv(a,mod)
        ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 71896
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
int a[150], n;
inline bool cmp(int a, int b) {
	return a > b;
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + n + 1, cmp);
	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		ans += a[i] - a[i + 1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
module Main where

-- import Utils
import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [a,b] <- getInts
  ; putStrLn (unwords (map show[a * b, 2 * (a + b)]))
  }
  



Measured memory_bytes: 3596
n = int(input())
slist = [""]*n
for i in range(n):
	slist[i] =sorted(input())
sslist=sorted(slist)
count=0
i = 0
while i < n-1:
	j=1
	if sslist[i]==sslist[i+1]:
		j=2
		while i+j<=n-1 and sslist[i]==sslist[i+j]:
			j=j+1
		count=count + j*(j-1)//2
#		print(j)
	i=i+j
#	print(sslist[i])
print(count)

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

using namespace std;

typedef long long ll;

void solve(ll n, vector<int> &a){
	if (n == 1)
		return;
	if (n & 1)
		solve(n - 1, a), a.insert(a.begin(), a.size() + 1);
	else
		solve(n >> 1, a), a.push_back(a.size() + 1);
}

int main(){
	long long n;
	scanf("%lld", &n);
	vector<int> ans;
	solve(n + 1, ans);
	int m = ans.size();
	for (int i = 1; i <= m; ++i)
		ans.push_back(i);

	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); ++i)
		printf("%d%c", ans[i], "\n "[i + 1 < ans.size()]);
	return 0;
}


Measured memory_bytes: 384
s=input()
t=input()
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()
for i in range(len(s)-len(t),-1,-1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
    else:
        print(s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a'))
        break
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

int main(int argc, char* argv[]){

	int N, M;
	int A[20000];

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

	int sum =0 ;
	for(int i=0; i<M; i++){
		scanf("%d", &A[i]);
		sum+= A[i];
	}
	if(N-sum < 0){
		printf("-1");
	}else{
		printf("%d", N-sum);
	}
	return 0;
}





Measured memory_bytes: 3768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)
int dp[2001][2001][2][2];
int main() {
	string S;
	cin >> S;
	int K;
	cin >> K;
	int N = S.size();
	int ans = 0;
	for (int rx = 0; rx < 2; rx++) {
		for (int ry = 0; ry < 2; ry++) {
			fill((int*)dp, (int*)(dp + N + 1), -(1 << 30));
			dp[0][0][rx][ry] = 0;
			for (int i = 0; i < N; i++) {
				for (int j = 0; j <= K; j++) {
					for (int k = 0; k < 2; k++) {
						for (int l = 0; l < 2; l++) {
							if (dp[i][j][k][l] == -(1 << 30)) continue;
							int x = 0, y = 0;
							if (S[i] == 'R')  x = 1;
							else if (S[i] == 'L') x = -1;
							else if (S[i] == 'U') y = 1;
							else y = -1;
							if (k) x *= -1;
							if (l) y *= -1;
							//操作をしない
							dp[i + 1][j][k][l] = max(dp[i + 1][j][k][l], dp[i][j][k][l] + x + y);
							if (j == K) continue;
							//x反転
							dp[i + 1][j + 1][k ^ 1][l] = max(dp[i + 1][j + 1][k ^ 1][l], dp[i][j][k][l] - x + y);
							//y反転
							dp[i + 1][j + 1][k][l ^ 1] = max(dp[i + 1][j + 1][k][l ^ 1], dp[i][j][k][l] + x - y);
						}
					}
				}
			}
			for (int i = 0; i <= K; i++) {
				for (int j = 0; j < 2; j++) {
					for (int k = 0; k < 2; k++) {
						ans = max(ans, dp[N][i][j][k]);
					}
				}
			}
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 65776
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		SparseWeightedGraph sparseGraph = new SparseWeightedGraph(n, false);
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			sparseGraph.addEdge(a-1,b-1);
		}
		Queue<Edge> queue = new LinkedList<>();
		Map<Integer, Integer> map = new HashMap<>();
		queue.add(new Edge(0, 0));
		map.put(0,0);
		while (!queue.isEmpty()) {
			Edge p = queue.remove();
			for (Edge edge : sparseGraph.adj(p.v())) {
				int newP = edge.other(p.v());
				if (map.containsKey(newP)) {
					continue;
				}
				queue.add(new Edge(newP, p.v()));
				map.put(newP, p.v());
			}
		}
		for (int i = 0; i < n; i++) {
			if (!map.containsKey(i)) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		for (int i = 1; i < n; i++) {
			System.out.println(map.get(i)+1);
		}
	}
}

class Edge {
	private int a, b;

	Edge(int v, int w) {
		this.a = v;
		this.b = w;
	}

	public int v() {
		return a;
	}

	public int w() {
		return b;
	}

	public int other(int x) {
		assert (x == a) || (x == b);
		return x == a ? b : a;
	}
}

class SparseWeightedGraph {
	private int n, m;
	private boolean directed;
	private ArrayList<ArrayList<Edge>> g;

	SparseWeightedGraph(int n, boolean directed) {
		this.n = n;
		this.m = 0;
		this.g = new ArrayList<>();
		this.directed = directed;
		for (int i = 0; i < n; i++) {
			g.add(i, new ArrayList<>());
		}
	}

	private void checkOutOfRange(int v) {
		if (v > n || v < 0) {
			throw new IllegalArgumentException("v is out of range");
		}
	}

	public int V() {
		return this.n;
	}

	public int E() {
		return this.m;
	}

	public void addEdge(int v, int w) {
		g.get(v).add(new Edge(v, w));
		if (v != w && !directed) {
			g.get(w).add(new Edge(w, v));
		}
		m++;
	}

	public Iterable<Edge> adj(int v) {
		this.checkOutOfRange(v);
		return g.get(v);
	}
}

Measured memory_bytes: 95132
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v.begin(), v.end());

	int ans = INF;
	for (int i = 0; i < N - K + 1; i++) {
		int n = v[i + K - 1] - v[i];
		ans = min(ans, n);
	}

	cout << ans << endl;
}

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

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;vector<int>v(n);
    erep(e,v)cin >> e;
    reverse(all(v));
    rep(i,n){
        if(i)cout << " ";
        cout << v[i];
    }
    cout << endl;
}





Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------

map<vector<int>, int> mp;

void init() {
   vector<int> v(8);
   iota(all(v), 0);
   mp[v] = 0;

   queue<vector<int>> que;
   que.push(v); // 最終状態をpush
   while (que.size()) {
      vector<int> cur = que.front(); que.pop();
      int idx = find(all(cur), 0) - cur.begin(); // 0の場所

      rep (k, 4) {
         int ny = (idx / 4) + dy[k]; // 上段
         int nx = (idx % 4) + dx[k]; // 下段
         if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
         int nc = ny * 4 + nx; // 2次元座標を1次元に変換したもの
         vector<int> tmp = cur;
         swap(tmp[nc], tmp[idx]); // 0の場所を入れ替える
         if (mp.count(tmp)) continue; // 計算済みならはじく
         mp[tmp] = mp[cur] + 1;
         que.push(tmp);
      }
   }
}

int main() {
   init();
   vector<int> vs(8);
   while (cin >> vs[0]) {
      repp (i, 1, 8) cin >> vs[i];
      cout << mp[vs] << endl;
   }

   return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//エラトステネスの篩
vector<bool> IsPrime;
void e_sieve(int size){
    size=max(2,size);
    IsPrime.assign(size,true);
    IsPrime[0]=false;
    IsPrime[1]=false;
    int chk=2;
    while(chk*chk<=size) {
        if(IsPrime[chk]){
            int tchk=chk*2;
            while(tchk<=size){
                IsPrime[tchk]=false;
                tchk+=chk;
            }
        }
        chk++;
    }
}

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    e_sieve(55555);
    vector<int> cnt;
    for(int i = 0; i < 55555; i++) {
        if(IsPrime[i] && i%5==1) cnt.emplace_back(i);
    }

    for(int i = 0; i < n; i++) {
        cout << cnt[i] << " ";
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 3568
A = int(input())
B = int(input())

if A==1 and B==2:
    print(3)
elif A==1 and B == 3:
    print(2)
elif A==2 and B==1:
    print(3)
elif A==2 and B==3:
    print(1)
elif A==3 and B==1:
    print(2)
elif A==3 and B==2:
    print(1)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

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

  int a1 = 0, a2 = W;
  int a3 = 0, a4 = H;

  for(int i=0;i<N;i++){
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1) a1 = max(a1, x);
    if (a == 2) a2 = min(a2, x);
    if (a == 3) a3 = max(a3, y);
    if (a == 4) a4 = min(a4, y);
  }

  int w = max(0, a2 - a1);
  int h = max(0, a4 - a3);

  cout << w * h << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //参加者
		int days = sc.nextInt();
		int remain = sc.nextInt();// x
		int chocos = 0;
		int every = 0;
		for (int i = 0; i < n; i++) {
			every = sc.nextInt();
			chocos += checkChoco(days, every);
		}
		System.out.println(chocos + remain);
	}

	static int checkChoco(int days, int every) {
		int counta = 0;
		if (days % every == 0) {
			counta = days / every;
		} else {
			counta = days / every;
			counta++;
		}
		return counta;
	}
}

Measured memory_bytes: 21716
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> nums(26);
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        nums[c - 'a']++;
    }
    ll ans = 1;
    for(auto& n : nums){
        ans *= n + 1;
        ans %= M;
    }
    cout << ans - 1 << '\n';
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

const ll mod = 1e9+7;

ll modpow(ll base, ll po){
    if(po == 0) return 1;
    if(po == 1) return base;
    ll a = modpow(base,po/2);
    a = (a*a)%mod;
    if(po&1) a = (a*base)%mod;
    return a;
}

ll modinv(ll num){
    return modpow(num,mod-2);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int k; string str; cin >> k >> str;
    int s = str.length();
    int n = k+s;
    vector<ll> fact(n+1);
    vector<ll> invfact(n+1);
    fact[0] = 1;
    F0R(i,1,n) fact[i] = (fact[i-1]*(ll)i)%mod;
    F0R(i,0,n) invfact[i] = modinv(fact[i]);
    ll tot = modpow(26,n);
    ll sub = 0;
    FOR(i,s){
        ll temp = (modpow(25,n-i)*fact[n])%mod;
        temp = (((temp*invfact[i])%mod)*invfact[n-i])%mod;
        sub += temp;
        if(sub >= mod) sub -= mod;
    }
    tot -= sub;
    if(tot < 0) tot += mod;
    cout << tot << endl;
    return 0;
}


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

bool is_prime[10000001];

int main(){

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<10000001;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<10000001;i++){
		if(is_prime[i]){
			for(int j=i*i;j<10000001;j+=i){
				is_prime[j]=false;
			}
		}
	}

	while(true){
		int n;
		cin>>n;

		if(n==0)
			break;

		while(n>=13){
			if((is_prime[n]&&is_prime[n-2])&&(is_prime[n-6]&&is_prime[n-8]))
				break;
			n--;
		}
		cout<<n<<endl;
	}
	return 0; 
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    int max = *max_element(a, a + n);
    int min = *min_element(a, a + n);
    cout << max - min << endl;
}


Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const S = lines[0]
    const T = lines[1]

    let count = 0
    for (let i = 0; i < S.length; i++) {
        if (S[i] !== T[i]) {
            count++
        }
    }

    console.log(count)

})(input)


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

#define jaldi ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 1000000007

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

ll root(ll a,vll &head)
{
    while(a!=head[a])
    {
        head[a]=head[head[a]];
        a=head[a];
    }
    return a;
}

void merge(ll a,ll b,vll &head, vll &size)
{
    ll p_a = root(a,head);
    ll p_b = root(b,head);
    if(p_a==p_b)
        return;
    
    if(size[p_a]>size[p_b])
    {
        size[p_a]+=size[p_b];
        head[p_b]=head[p_a];
    }
    else
    {
        size[p_b]+=size[p_a];
        head[p_a]=head[p_b];
    }
    
}

int main()
{
    jaldi;
    precision(20);
    ll i,j;

    ll n,k;
    cin>>n>>k;

    vll A(n);
    for(i=0;i<n;i++)
    {
        cin>>A[i];
        A[i]--;
    }   
    
    vll visited(n,0);
    i=0;
    ll c=0;
    while(visited[i]==0)
    {
        visited[i]=c;
        i=A[i];
        c++;
    }
    c = c-visited[i];
    // cout<<c<<" ";
    ll st=i;
    i=0;
    ll f=0;
    while(k>0)
    {
        if(st==i)
        {
            f=1;
            break;
        }
        i=A[i];
        k--;
    }
    if(f==1)
    {
        k=k%c;
        while(k>0)
        {
            i=A[i];
            k--;
        }
        cout<<i+1<<endl;
    }
    else
        cout<<i+1<<endl;

    return 0;
}

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

using namespace std;
#define eps = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
vector<Point> polygon;
bool check(vector<Point> polygon){
    int n=(int)polygon.size();
    polygon.push_back(polygon[0]);
    polygon.push_back(polygon[2]);
    for(int i=0;i<n;i++){
        Point a=polygon[i+1]-polygon[i];
        Point b=polygon[i+2]-polygon[i+1];
        if(cross(a,b)<0) return 0;
    }
    return 1;
}
int main(){
    int n;
    scanf("%d",&n);
    double x,y;
    for(int i=1;i<=n;i++){
        scanf("%lf %lf",&x,&y);
        polygon.push_back({x,y});
    }
    if(check(polygon)) puts("1");
    else puts("0");
    return 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a+b<10)cout<<a+b;
else cout<<"error";
}
/*
Rating 1-399 : gray
Rating 400-799 : brown
Rating 800-1199 : green
Rating 1200-1599 : cyan
Rating 1600-1999 : blue
Rating 2000-2399 : yellow
Rating 2400-2799 : orange
Rating 2800-3199 : red

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    int X[n],Y[n];
    rep(i,n) cin>>X[i]>>Y[i];
    int t = (abs(X[0]) + abs(Y[0]) )%2;
    rep(i,n) if((abs(X[i]) + abs(Y[i]))%2 != t ) {cout<<-1<<endl; return 0;}
    int m = 32;
    vector <int> d(m); 
    rep(i,m) d[i] = 1LL<<(31-i);
    if(t == 0) {d.push_back(1); m++;}
    sort(d.begin(),d.end(), greater <int>());
    cout<<m<<endl;
    rep(i, m) cout<<d[i]<<' ';
    cout<<endl;
    FOR(i,n) {
		string S;
		FOR(j,m) {
			if(abs(X[i])>=abs(Y[i])) {
				if(X[i]>=0) {
					S+='R';
					X[i]-=d[j];
				}
				else {
					S+='L';
					X[i]+=d[j];
				}
			}
			else {
				if(Y[i]>=0) {
					S+='U';
					Y[i]-=d[j];
				}
				else {
					S+='D';
					Y[i]+=d[j];
				}
			}
		}
		cout<<S<<endl;
	}
}


Measured memory_bytes: 256
#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);
	while(1){
		int n; cin >> n;
		if(!n)break;
		vector<double> a(n);
		double sum=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
			sum+=a[i];
		}
		double ave=sum/n;
		sum=0;
		for(int i=0;i<n;i++){
			sum+=(a[i]-ave)*(a[i]-ave);
		}
		sum/=n;
		printf("%.8f\n",sqrt(sum));
	}
}


Measured memory_bytes: 3320
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=21;
const int MAXW=50001;
const int INFTY=(1<<29);
int main()
{
    int N,W,c[MAXN],T[MAXN][MAXW];
    cin>>N>>W;
    for(int i=1;i<=W;i++)
        cin>>c[i];

    for(int i=0;i<=W;i++)T[i][0]=0;
    for(int j=0;j<=N;j++)T[0][j]=INFTY;

    for(int i=1;i<=W;i++)
        for(int j=1;j<=N;j++)
        {
            if(j>=c[i])
                T[i][j]=min(T[i-1][j],T[i][j-c[i]]+1);
            else
                T[i][j]=T[i-1][j];
        }


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


Measured memory_bytes: 7216