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

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];
    
int main(void) {

    int p = 0;
    for(int i = 0; i <= 1000000; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;


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

    int a, d, n;
    while(1){
        cin >> a >> d >> n;
        if(!n) break;
        int i = a;
        int j = 0;
        while(1){
            if(is_prime[i + j*d]) n--;
            if(n == 0){
                cout << i + j*d << endl;
                break;
            }
            j++;
        }
    }

    return 0;
}

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

string R, S, T;
int dp[3003][3003];

int solve(int N, int M)
{
    if(N < 0 || M < 0)
        return 0;
    
    if(dp[N][M] != -1)
        return dp[N][M];
    
    int ans = max(solve(N-1, M), solve(N, M-1));
    
    if(S[N] == T[M])
        ans = max(ans, 1 + solve(N-1, M-1));
    
    return dp[N][M] = ans;
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    cin >> S >> T;
    memset(dp, -1, sizeof(dp));
    
    solve(S.size()-1, T.size()-1);
    
    int x = S.size()-1, y = T.size()-1;
    
    while(x >= 0 || y >= 0)
    {
        if(S[x] == T[y])
            R.push_back(S[x]), x--, y--;
        else if(x >= 1 && y >= 1)
        {
            if(dp[x-1][y] > dp[x][y-1])
                x--;
            else
                y--;
        }
        else if(x >= 1)
            x--;
        else if(y >= 1)
            y--;
        else
            break;
    }
    
    reverse(R.begin(), R.end());
    cout << R << "\n";
    
    return 0;
}

Measured memory_bytes: 35840
#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];
    }
    map <int, int> a;
    for(int i =0; i < N; i++)
    {
        if(a[A[i]] > 0)
        {
            cout << "NO" << endl;
            return 0;
        }
        a[A[i]] = 1;
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 10368
import numpy as np

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))

for i in range(d):
  if i%26==0:
    a=np.argmax(s[0])
  print((i+a)%26+1)

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

int main() {
	string w;
	int m[26] = { 0 };
	bool flg = true;

	cin >> w;

	for (int i = 0; i < (int)w.size(); i++)
	{
		//cout << w[i] << endl;
		m[w[i]-'a']++;
	}

	for (int i = 0; i < 26; i++)
	{
		//cout << m[i] << endl;
		if (m[i] % 2) {
			flg = false;
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
l = [0, 0, 0, 0]
n = int(input())
for i in range(n):
    s = input()
    if s == "AC":
        l[0] += 1
    elif s  == "WA":
        l[1] += 1
    elif s == "TLE":
        l[2] += 1
    else:
        l[3] += 1
print("AC x",l[0])
print("WA x",l[1])
print("TLE x",l[2])
print("RE x",l[3])

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int>l(n);
    int max = 1;
    int sum =0;
    REP(i,n){
        cin >> l[i];
        sum+=l[i];
        if(l[i]>max) max = l[i];
    }
    if(2*max<sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var m int
	var c int
	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&c)

	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}

	ks := make([][]int, n)
	for i := 0; i < n; i++ {
		k := make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&k[j])
		}
		ks[i] = k
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := c
		for j := 0; j < m; j++ {
			sum = sum + ks[i][j]*b[j]
		}
		if sum > 0 {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	nextReader = newScanner()
	n, k := nextInt(), nextInt()
	hs := nextInts(n)

	if k >= n {
		fmt.Println(0)
		return
	}

	ans := 0
	sort.Ints(hs)
	for _, h := range hs[:len(hs)-k] {
		ans += h
	}
	fmt.Println(ans)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 4608
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
if n==1:
  for i in range(10):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)
else:
  for i in range(10**(n-1),10**n):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)

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

int N, L;
string s[104];

int main() {
	cin >> N;
	cin >> L;
	for(int i = 0; i < N; i++) {
		cin >> s[i];
	}
	sort(s, s + N);
	string out = "";
	for(auto& str : s) 
		out += str;
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int num_A,num_B;
    scanf("%d %d",&num_A,&num_B);
    if (2*num_B-num_A>=0) {
        printf("0\n");
    }
    else {
        printf("%d\n",num_A-2*num_B);
    }
    return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

vector<vector<int>> g;
vector<int> z;
vector<int> p;
vector<int> h;
vector<int> st;

bool dfs(int x) {
    if (z[x] == 2) return false;
    if (z[x] == 1) {
        while (st.back() != x) {
            p.push_back(st.back());
            st.pop_back();
        }
        p.push_back(x);
        reverse(p.begin(), p.end());
        return true;
    }
    z[x] = 1;
    st.push_back(x);
    int u = -1;
    for (int i = 0; i < g[x].size(); i++) {
        int y = g[x][i];
        if (z[y] == 1) {
            if (u == -1 || h[y] > h[u]) u = y;
        }
    }
    if (u != -1) {
        dfs(u);
        return true;
    }
    for (int i = 0; i < g[x].size(); i++) {
        int y = g[x][i];
        if (z[y] == 0) {
            h[y] = h[x] + 1;
            if (dfs(y)) return true;
        }
    }
    st.pop_back();
    z[x] = 2;
    return false;
}

int main() {
    std::ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
    }
    z.resize(n);
    h.resize(n);
    for (int i = 0; i < n; i++) {
        if (dfs(i)) break;
    }
    if (p.size() == 0) {
        cout << -1;
        return 0;
    }
    vector<int> q(n, -1);
    for (int i = 0; i < p.size(); i++) {
        q[p[i]] = i;
    }
    vector<int> res;
    int v = p[0];
    while (true) {
        res.push_back(v);
        int vv = v;
        for (int u : g[v]) {
            if (q[u] > q[vv]) vv = u;
        }
        if (vv == v) break;
        v = vv;
    }
    cout << res.size() << "\n";
    for (int x : res) {
        cout << x + 1 << "\n";
    }

    return 0;
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()

typedef pair<ll, ll> P;
map<ll, ll> mp;
vector<int> a(100001);

int main(){
    int n, x;
    ll ans = 0;
    cin >> n >> x;
    REP(i, n) cin >> a[i];
    if(a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }

    REP(i, n-1) {
        if(a[i] + a[i+1] > x) {
            ans += a[i]+a[i+1] - x;
            a[i+1] -= (a[i]+a[i+1] - x);   
        }
    }    

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
n,a,b = map(int,input().split())
total = 0
for i in range(1,n+1):
    tmp = list(str(i))
    for j in range(len(tmp)):
        tmp[j] = int(tmp[j])
    tmp = sum(tmp)
    if a <= tmp <= b:
        total += i
print(total)


Measured memory_bytes: 3060
N, P = map(int, input().split())
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(int(n))
    return table

primes = prime_decomposition(P)
prime_dict = {}
for prime in primes:
    prime_dict.setdefault(prime, 0)
    prime_dict[prime] += 1

res = 1
for prime in prime_dict:
    res *= prime**(prime_dict[prime] // N)
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main()
{
    ll n;
    cin >> n;
    ll count=0;

    for(ll i=2;i*i<=n;++i){
        ll e=0,z=0;
        while(n%i==0){
            ++e;
            if(e>z){
                ++count;
                z=e;
                e=0;
            }
            n/=i;
        }
    }

    if(n!=1) ++count;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3644
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
t = ns()

a = 0
for i in range(3):
    if s[i] == t[i]:
        a +=1

print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll maxn = 1e6+10;
const ll inf = 1e14;

vector<pii> ve[maxn];
ll dis[maxn];
priority_queue<pii,vector<pii>,greater<pii>> heap;
int N,M;

void init(){
	for(int i = 1;i<=N;i++) dis[i] = inf;
	for(int i = 1;i<=N;i++) ve[i].push_back({0,i-1});
	
}

ll Dji(){
	heap.push({0,1});
	dis[1] = 0;
	
	while(heap.size()){
		auto cur = heap.top();heap.pop();
		ll d = cur.first,id = cur.second;
		for(auto v:ve[id]){
			ll w = v.first,id2 = v.second;
			if(d+w<dis[id2]){
				dis[id2] = d+w;
				heap.push({dis[id2],id2});
			}
		}
	}
	if(dis[N] == inf) return -1;
	return dis[N];
}

int main(){
	cin>>N>>M;
	init();
	int a,b,c;
	for(int i = 0;i<M;i++){
		scanf("%d%d%d",&a,&b,&c);
		ve[a].push_back({c,b});
	}
	cout<<Dji()<<endl;
	return 0;
}

Measured memory_bytes: 31608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  ull n; cin >> n;
  string ans;
  while(n){
    n--;
    char now = n % 26 + 'a';
    ans += now;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


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

const int MAX = 3;
int main() {
	string S[MAX];
	int num[MAX]; // 何枚カードを使ったか
	for (int i = 0;i < MAX;i ++) {
		cin >> S[i];
		num[i] = 0;
	}
	int turn = 0; // 誰のターンか
	while (num[turn] < S[turn].length()) { // まだカードが残っているなら
		num[turn] ++;
		turn = (char)(S[turn][num[turn] - 1] - 'a');
	}
	cout <<(char)(turn + 'A');
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

実際にゲームをプレイしていくと良い
その時、カードを捨てる動作は実行が面倒なので、代わりにn回目の自分のターンはn枚目のカードを参照することで代替すると良い
これで、カードをm-1枚しか持っていないのに自分にmターン回ってきたら勝利して終了になる
*/

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

int main() {
  int N;
  cin >> N;
  int det[N-1];
  for (int i=0; i<N-1; i++) {
    cin >> det[i];
  }
  
  int sumA = 0;
  
  for (int i=0; i<N-1; i++) {
    if (i == 0) {
      sumA += det[0];
    }
    else if (i < N-1) {
      sumA += min(det[i], det[i-1]);
    }
  }
  sumA += det[N-2];
  
  cout << sumA << endl;
}

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

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

Measured memory_bytes: 3200
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n;
  cin >> n;
  string s;
  while(n>0){
    if(n%26==0){
      s+="z";
      n=n/26-1;
    }
    else{
      ll t=n%26+'a'-1;
      s+=t;
      n=n/26;
    }
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3620
n=int(input())
for i in range(1,n+1):
    x = i
    if x % 3 == 0: print('',i,end='')
    else: 
        while x > 0:
            if x % 10 == 3: 
                print('',i,end='')
                break
            x //= 10
print('')

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

int main(void){
    while (1) {
        ll n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) return 0;
        
        ll dc[10010], my[10010];
        for (int i = 0; i < n; i++) {
            dc[i] = 0;  my[i] = 0;
        }
        
        for (int i = 0; i < m; i++) {
            ll s, k;
            cin >> s >> k;
            for (int i = 0; i < k; i++) {
                ll c;
                cin >> c;
                c--;
                if (k == 1) dc[c] += s;
                else my[c] += s;
            }
        }
        
        vector<pair<ll, ll> > sm, sm2;
        for (int i = 0; i < n; i++) {
            sm.emplace_back(dc[i] + my[i], i);
            sm2.emplace_back(dc[i], i);
        }
        
        sort(sm.begin(), sm.end());
        sort(sm2.begin(), sm2.end());
        
        //for (int i = 0; i < n; i++) cout << sm[i].first << " " << sm[i].second << endl;
        //for (int i = 0; i < n; i++) cout << sm2[i].first << " " << sm2[i].second << endl;
        
        if (sm[n - 1].second != sm2[0].second) cout << sm[n - 1].first - sm2[0].first + 1 << endl;
        else {
            cout << max(sm[n - 2].first - sm2[0].first, sm[n - 1].first - sm2[1].first) + 1 << endl;;
        }
        
        
    }
}



Measured memory_bytes: 3696
n,m,x=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
ans=[]
for bit in range(1<<n):
  total=0
  skill=[0]*m
  for i in range(n):
    if bit & (1<<i):
      total+=a[i][0]
      for j in range(m):
        skill[j]+=a[i][j+1]
  if all([k>=x for k in skill]):
    ans.append(total)
print(min(ans) if len(ans)!=0 else -1)
    
      

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

ll gcd(ll a, ll b){
    if(a < b) return gcd(b, a);
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
ll lcm(ll a, ll b){
    ll ret = (a * b)/gcd(a,b);
    return ret;
}

int main(){
    ll N, X;
    cin >> N >> X;
    vector<ll> x(N), d(N);
    rep(i, 0, N) cin >> x[i];
    x.push_back(X);
    sort(x.begin(), x.end());
    rep(i, 0, N) d[i] = x[i+1] - x[i];
    ll ans = d[0];
    rep(i, 1, N) ans = gcd(ans, d[i]);
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	int n;
	cin >> n;
	cout << 2 * atan(1)* 4 * n;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t = 1;
	// cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3800
#include <string>
#include <stdio.h>
#include <iostream>

using namespace std;
int main()
{
    string S;
    std::cin >> S;
    int C = 0;
    int A = 0;
    int len = S.size();
    for(int i=2; i<(len-1); i++)
    {
        if(S[i]=='C') C++;
    }
    for(int i=0; i<len; i++)
    {
        if((S[i]>= 'A') && (S[i]<='Z'))A++;
    }
    if(S[0] == 'A' && C==1 && A==2){
        std::cout << "AC";
    }
    else std::cout << "WA";

}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int INF = 1e18 + 239;
const int N = 3003;

int dp[N][N];

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

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dp[i][j] = INF;
		}
	}
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	a.insert(a.begin(), 0);
	a.push_back(0);
	n += 2;
	dp[0][0] = 0;
	for (int i = 0; i + 1 < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int ln = 0; i + ln + 1 < n; ln++) {
				dp[i + ln + 1][j + ln] = min(dp[i + ln + 1][j + ln], dp[i][j] + abs(a[i] - a[i + ln + 1]));
			}
		}
	}
	cout << dp[n - 1][k] / 2 << endl;
}


Measured memory_bytes: 70784
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int k, i, n, m;
	string s, t;
	cin >> s;
	cin >> t;
	n = s.size();
	m = t.size();
	for (k = n - m; k >= 0; k--){
		for (i = 0; i < m; i++){
			if (s[k + i] != '?' && s[k + i] != t[i]) break;
		}
		if (i == m){
			s.replace(k, m, t);
			break;
		}
	}
	if (k < 0){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (i = 0; i < n; i++){
		if (s[i] == '?') s[i] = 'a';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

//素数判定
bool isPrime(int num){
  if (num%2==0 || num==1) return false;
  for (int i=3;i<num/2;i+=2) {
    if (num%i==0) return false;
  }
  return true;
}

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

  for (int i=6;i<=55555;i+=5) {
    if (isPrime(i)==true) {
      std::cout << i << ' ';
      N--;
    }
    if (N==0) break;
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  int n;
  cin>>n;
  
  string s;
  int p;
  vector<pair<string,pair<int,int>>> shops;
  REP(i,n){
    cin>>s>>p;
    shops.push_back(make_pair(s,make_pair(-p,i+1)));
  }
  sort(shops.begin(),shops.end());
  
  REP(i,n){
    cout<<shops[i].second.second<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>

using namespace std;

int main(void){
    int H=0, W=0;

    while(cin >> H >> W){
        if(H==0 && W==0)
            break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i == 0) || (i == H-1) || (j == 0) || (j == W-1))
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"

using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    char s[52][52];
    for(int i = 1;i < H + 1;i++){
        for(int j = 1; j < W + 1 ; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0;i < H;i++){
        s[i + 1][0] = '.';
        s[i + 1][W+1] = '.';
    }
    for(int j = 0;j < W;j++){
        s[0][j + 1] = '.';
        s[H + 1][j + 1] = '.';
    }

    for(int i = 1;i < H + 1;i++){
        for(int j = 1; j < W + 1 ; j++){
            if(s[i][j] == '#'){
                if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

int main() {
	int a, b;
	cin >> a >> b;
	int sum = a+b;
	int dif = a-b;
	int mul = a*b;
	int ans = max(max(sum, dif), mul);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int kakko = 0;
  rep(i,n){
    if(s[i] == '(') kakko ++;
    if(s[i] == ')') kakko = max(0,kakko-1);
  }
  int kokka = 0;
  reverse(s);
  rep(i,n){
    if(s[i] == '(') kokka = max(0,kokka-1);
    if(s[i] == ')') kokka ++;
  }
  reverse(s);
  rep(i,kokka) cout << '(';
  cout << s;
  rep(i,kakko) cout << ')';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
// ll mod=998244353;
ll INF=1e9;
void dfs(int i,int j, vector<int> gr[],bool vis[])
{
	vis[i]=1;
	FOR(k,0,gr[i].size())
	{
		if(gr[i][k]!=j && vis[gr[i][k]]==0)
		{
			dfs(gr[i][k],i,gr,vis);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("INPUT.txt", "r", stdin);
	freopen("OUTPUT.txt", "w", stdout);
	#endif
	int test=1;
	// cin>>test;
	while(test--)
	{
		int n,m;
		cin>>n>>m;
		vector<int> gr[n];
		bool vis[n]={0};
		int o=0,a,b;
		FOR(i,0,m)
		{
			cin>>a>>b;
			gr[a-1].pb(b-1);
			gr[b-1].pb(a-1);
		}
		FOR(i,0,n)
		{
			// cout<<'l';
			if(vis[i]==0)
			{
				o++;
				dfs(i,-1,gr,vis);
			}
		}	
		cout<<o-1;
	}
	return 0;
}

Measured memory_bytes: 10524
#include<iostream>
#include<algorithm>
#define REP(i, n) for(int i=0;i<(n);++i)
using namespace std;
void chmax(double &a, double b){
    a = max(a, b);
}
double get_dice(){
    int n, m;
    cin >> n >> m;
    double res = 0;
    double ratesum = 0;
    REP(i, m){
        int d;
        double rate;
        cin >> d >> rate;
        res += d * rate;
        ratesum += rate;
    }
    return res / ratesum;
}
int main(){
    int t;
    cin >> t;
    double hd = 0;
    REP(i, t){
        chmax(hd, get_dice());
    }
    double nd = get_dice();
    if(nd < hd - 0.0000001){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3212
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int m = input.nextInt();
        int d = input.nextInt();
        int ans = 0;
        for (int i = 2; i < m+1; i++){
            for (int j = 11; j < d+1; j++){
                int a = j/10;
                int b = j%10;
                if (i == a*b && a >= 2 && b >= 2){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

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

  int N;
  cin >> N;
  vector<int> L(N);
  int s = 0;
  for (int i = 0; i < N; i++) {
    cin >> L[i];
    s += L[i];
  }
  string ans = "Yes";
  for (int i = 0; i < N; i++) {
    if (L[i] >= s - L[i]) ans = "No";
  }
  cout << ans << '\n';

  return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n){
    int tmp;
    cin >> tmp;
    b[i] = tmp-(i+1);
  }
  sort(all(b));
  ll ans=0;
  rep(i,n){
    ans += abs(b[i]-b[(n-1)/2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	mem(a,b)	memset(a,b,sizeof(a))
#define	_max(a,b,c)	(max(a,b)>c?max(a,b):c)
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
#define ls (k << 1)
#define rs (ls | 1)
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const int N = 200000;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
#include <iostream>
using namespace std;
char s[200005];
int n, p, a[10005];
ll ans;
int main()
{
	scanf("%d%d", &n, &p);
	scanf("%s", s);
	if (p == 2 || p == 5)
	{
		for (int i = 0; i < n; i++)
		{
			if ((s[i] - '0') % p == 0)
			{
				ans += i + 1;
			}
		}
	}
	else
	{
		int ct = 0, x = 1;
		for (int i = n - 1; i >= 0; i--)
		{
			ct = ct + (s[i] - '0') * x;
			ct %= p;
			ans += a[ct];
			a[ct]++;
			if (ct == 0)	ans++;
			x = x * 10 % p;
		}
	}
	printf("%lld", ans);
}

Measured memory_bytes: 512
n = int(input())
absum = []
for a in range(1,n):
    b = n-a
    asum = 0
    bsum = 0
    astr = str(a)
    bstr = str(b)
    for j in range(len(astr)):
        asum = asum + int(astr[j])
    for k in range(len(bstr)):
        bsum = bsum + int(bstr[k])
    absum.append(asum+bsum)
print(min(absum))

Measured memory_bytes: 9656
n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(n):
    f = True
    for j in range(len(A)):
        if A[len(A)-1-j] == len(A)-j:
            f = False
            B.append(len(A)-j)
            del A[len(A)-j-1]
            break
    if f: break
if len(A) > 0:print(-1)
else: print(*B[::-1], sep="\n")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	rep(i, N) cin >> p[i];
	int cnt = 0;
	auto sorted = p;
	sort(all(sorted));
	rep(i ,N){
		if(p[i] != sorted[i]) cnt++;
	}
	if(cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
N, X, M = map(int, input().split())
if M==1:
  print(0)
  exit()
lis = [0]*M
lis[0] = X
check = [-1]*M
check[X] = 0
for i in range(1,M):
  lis[i] = pow(lis[i-1],2,M)
  if check[lis[i]]>=0:
    cyc = i-check[lis[i]]
    start = check[lis[i]]
    break
  check[lis[i]] = i
from itertools import groupby, accumulate, product, permutations, combinations
cum = list(accumulate(lis))
cyc_cum = cum[-1]-cum[start]
if N-1<=start+cyc:
  ans = cum[N-1]
else:
  ans = cyc_cum*((N-1-start)//cyc)+cum[(N-1-start)%cyc+start]
print(ans)

Measured memory_bytes: 74676
n = int(input())
alst = list(map(int, input().split()))

ans = [0 for _ in range(n)]
pm = 1
for a in alst:
    ans[0] += a * pm
    pm *= -1
for i in range(n - 1):
    ans[i + 1] = alst[i] * 2 - ans[i]
print(*ans)

Measured memory_bytes: 20640
#include<stdio.h>

int main(void){
  char letter;

  while(1){
    scanf("%c",&letter);
    if(letter == '\n')break;
    if(letter == ' ' || letter == '.')printf("%c",letter);
    else printf("%c",letter - 32);
  }
  putchar('\n');

  return 0;
}

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

using namespace std;

int n, k;
int a[101];
long long dp[100001][101];
long long prefix[100001][101];
bool vis[100001][101];
const int MOD = 1e9 + 7;

int solve(int k, int n)
{
	if (k == 0)
		return 1;
	if (n == 0)
		return 0;
	if (vis[k][n])
		return dp[k][n];
	vis[k][n] = true;

	for (int i = 0; i <= min(k, a[n - 1]); i++)
		dp[k][n] = ((long long)dp[k][n] + solve(k - i, n - 1)) % MOD;

	return dp[k][n];
}

int solve2()
{
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			if (i == 0)
				dp[i][j] = 1;
			else if (j == 0)
				dp[i][j] = 0;
			else
			{
				if (i > a[j - 1])
					dp[i][j] = (prefix[i][j - 1] - prefix[i - a[j - 1] - 1][j - 1] + MOD ) % MOD;
				else
					dp[i][j] = prefix[i][j - 1];
			}
			prefix[i][j] = (dp[i][j] + ((i == 0) ? 0 : prefix[i - 1][j])) % MOD;
		}
	}
	return dp[k][n];
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	memset(dp, 0, sizeof(dp));
	//cout << solve(k, n) << endl;
	cout << solve2() << endl;
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int>d(n);
  rep(i,n){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  queue<int>q;
  rep(i,n){
    q.push(d.at(i));
  }
  int m;
  cin>>m;
  vector<int>t(m);
  rep(i,m){
    cin>>t.at(i);
  }
  sort(t.begin(),t.end());
  int i=0;
  while(!q.empty()&&i<m){
    int c=q.front();
    if(t.at(i)==c){
      i++;
    }
    q.pop();
  }
  
  if(i==m){
    cout<<"YES"<<endl;
  }
  
  else{
    cout<<"NO"<<endl;  
  }
  
}

Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define INF 0x3f3f3f3f
#define EXP 1e-9
#define MAXN 1000005
#define ltree 2*id,ll,mid
#define rtree 2*id+1,mid+1,rr
#define FO(i,n,m) for(LL i=n;i<=m;++i)
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
using namespace std;

char a[100005];

int main()
{

    scanf("%s",a+1);
    int len=strlen(a+1);
    int mid;
    if(len%2)
        mid=len/2+1;
    else
        mid=len/2;
    int ans;
    for(int i=mid;i<=len;++i)
    {

        if(a[i]!=a[len-i+1]||a[i]!=a[mid])
        {
            ans=i-1;
            break;
        }
        ans=i;
    }
    ans=max(ans,mid);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 384
#!/usr/bin/env python3
#ABC51 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,m = map(int,input().split())
w = [[float('inf')]*n for _ in range(n)]
x = [list(map(int,input().split())) for _ in range(m)]
for a,b,c in x:
    w[a-1][b-1] = c
    w[b-1][a-1] = c

for i in range(n):
    for j in range(n):
        for k in range(n):
            w[j][k] = min(w[j][k],w[j][i]+w[i][k])

ans = 0
for i in x:
    a,b,c = i
    if w[a-1][b-1] < c:
        ans += 1
print(ans)


Measured memory_bytes: 47212
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = map(int, raw_input().split())
A = sorted(map(int, raw_input().split()))
ans = 0
for i in range(N - K):
    ans += A[i]
print ans

Measured memory_bytes: 21680
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
  SC+=S[i][P[i][0]]
YY=[]
Y=[]
k=0
L=[]
for i in range(25):
  for j in range(50-i):
    L.append(i)
for l in range(666):
  for i in range(D):
    k=L[randrange(0,len(L))]
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
'''
スコア計算用
UKU=0
X=[0]*26
for i in range(D):
  T=P[i][0]+1
  UKU+=S[i][T-1]
  for j in range(26):
    X[j]+=C[j]
  X[T-1]=0
  UKU-=sum(X)
print(UKU)
'''
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 85944
import java.util.Scanner;

public class Main {
	static int n, m;
	static int book[];

	public static int binarySearch(int low, int high) {
		if (high - low <= 0) {
			return high;
		}
		int mid = (low + high) / 2;
		int shellId = 0;
		int sumWidth = 0;
		for (int i = 0; i < m; i++) {
			if (mid < sumWidth + book[i]) {
				shellId++;
				sumWidth = book[i];
			} else {
				sumWidth += book[i];
			}
		}

		if (n <= shellId) {
			return binarySearch(mid + 1, high);
		} else {
			return binarySearch(low, mid);
		}
	}

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

		while (true) {
			n = sc.nextInt();//tana
			m = sc.nextInt();//kann
			if ((n | m) == 0) {
				break;
			}
			book = new int[m];
			max = 0;
			for (int i = 0; i < m; i++) {
				book[i] = sc.nextInt();
				max = Math.max(max, book[i]);
			}

			System.out.println(binarySearch(max, 1500000));
		}
	}
}

Measured memory_bytes: 20972
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()


ans = 0
#Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索
for i in B:
    ans += bisect_right(A, i-0.1) * (N-bisect_left(C, i+0.1))
print (ans)


Measured memory_bytes: 23360
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n,m,a[102];
	vector<int> b;
	scanf("%d%d",&n,&m);
	rep(i,m)scanf("%d",&a[i]);
	
	int cnt = 0;
	rep(i,m)cnt += a[i]%2;
	if(cnt >= 3){
		puts("Impossible");
		return 0;
	}
	
	if(n%2 == 0){
		if(cnt == 0){
			if(m == 1){
				b.pb(a[0]-1);
				b.pb(1);
			}
			else {
				b.pb(a[0]+1);
				for(int i = 1 ; i+1 < m ; i ++){
					b.pb(a[i]);
				}
				b.pb(a[m-1]-1);
			}
		}
		else {
			rep1(i,m-1){
				if(a[i]%2 != 0){
					if(a[0]%2 == 0)swap(a[0],a[i]);
					else if(i != m-1)swap(a[i],a[m-1]);
				}
			}
			b.pb(a[0]-1);
			rep1(i,m-2)b.pb(a[i]);
			b.pb(a[m-1]+1);
		}
	}
	else {
		if(m == 1){
			b.pb(a[0]-1);
			b.pb(1);
		}
		else {
			rep(i,m)if(a[i]%2 != 0 && i != m-1)swap(a[i],a[m-1]);
			b.pb(a[0]+1);
			for(int i = 1 ; i+1 < m ; i ++){
				b.pb(a[i]);
			}
			b.pb(a[m-1]-1);
		}
	}
	
	vector<int> ans;
	rep(i,b.size())if(b[i] != 0)ans.pb(b[i]);
	
	rep(i,m)printf("%d%c",a[i],(i==m-1)?'\n':' ');
	printf("%d\n",ans.size());
	rep(i,ans.size())printf("%d%c",ans[i],(i+1==ans.size())?'\n':' ');
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 50
using namespace std;
int w,h,a[N][N],cnt,wcnt,bcnt;
int W,B,used[N][N];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
string s[N];

void dfs(int y,int x){
  if(used[y][x])return;
  used[y][x]=1;
  cnt++;
  for(int i=0;i<4;i++){
    int ny=y+dy[i],nx=x+dx[i];
    if(ny<0||nx<0||h<=ny||w<=nx)continue;
    if(s[ny][nx]!='.'){
      if(s[ny][nx]=='B')B=1;
      if(s[ny][nx]=='W')W=1;
      continue;
    }
    dfs(ny,nx);
  }
}

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h)break;
    for(int i=0;i<h;i++)cin>>s[i];
    memset(used,0,sizeof(used));
    wcnt=bcnt=0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(!used[i][j]&&s[i][j]=='.'){
	  W=B=cnt=0;
	  dfs(i,j);
	  if(!W&&B)bcnt+=cnt;
	  if(W&&!B)wcnt+=cnt;
	}
    cout<<bcnt<<' '<<wcnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 3336
import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len([1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]]))


Measured memory_bytes: 8452
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int sugo[1111];
  int sai[1111];
  int count;
  int ba;
  while(1){
    count=0;
    cin>>n>>m;
    if(n==0 && m==0) break;
    for(int i=1;i<=n;i++){
      cin>>sugo[i];
    }
    for(int i=0;i<m;i++){
      cin>>sai[i];
    }
    int j=0;
    ba=1;
    while(1){
      ba=ba+sai[j];
      ba=ba+sugo[ba];
      count++;
      j++;
      if(ba>=n) break;
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1164
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = 0
        abs_temp = 101

        for pi in range(0, 102):
            n = abs(pi - X)
            if n < abs_temp  and not pi in P:
                ans = pi
                abs_temp = n
            elif n == abs_temp  and not pi in P and pi < ans:
                ans = pi
                abs_temp = n

        print(ans)

    else:
        print(X)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61924
#include<stdio.h>
int main(void)
{
	int a,i,j;
	for(i=1;i<10;i++) {
		for(j=1;j<10;j++) {
			a=i*j;
			printf("%dx%d=%d\n",i,j,a);
		}
	}
	return 0;
}



Measured memory_bytes: 1928
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;


int main(){
	string s,t; cin >> s >> t;
	cout << t << s << endl;
}


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

using namespace std;

long long n, g[5], s[5], b[5];
vector < pair <long long, long long> > c;

long long calc(long long n) {
    if (c.size() == 1) {
        long long k = n / c[0].first;
        return n - k * c[0].first + k * c[0].second;
    }
    if (c.size() == 2) {
        long long ret = n;
        for (int i = 0; i <= n; i += c[0].first) {
            long long x = n - i;
            long long k = x / c[1].first;
            long long w = (i / c[0].first) * c[0].second + k * (c[1].second - c[1].first);
            ret = max(ret, x + w);
        }
        return ret;
    }
    if (c.size() == 3) {
        long long ret = 0;
        for (int i = 0; i <= n; i += c[0].first) {
            long long x = n - i;
            for (int j = 0; j <= x; j += c[1].first) {
                long long y = x - j;
                long long k = y / c[2].first;
                long long w = (i / c[0].first) * c[0].second + (j / c[1].first) * c[1].second + k * (c[2].second - c[2].first);
                ret = max(ret, y + w);
            }
        }
        return ret;
    }
    return n;
}

int main() {

    scanf("%lld", &n);

    for (int i = 0; i < 2; i++) {
        scanf("%lld %lld %lld", &g[i], &s[i], &b[i]);
    }

    if (g[0] < g[1]) {
        c.push_back({g[0], g[1]});
    }

    if (s[0] < s[1]) {
        c.push_back({s[0], s[1]});
    }

    if (b[0] < b[1]) {
        c.push_back({b[0], b[1]});
    }

    n = calc(n);

    c.clear();

    if (g[0] > g[1]) {
        c.push_back({g[1], g[0]});
    }

    if (s[0] > s[1]) {
        c.push_back({s[1], s[0]});
    }

    if (b[0] > b[1]) {
        c.push_back({b[1], b[0]});
    }

    n = calc(n);

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

    return 0;

}


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

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

  if (s.size() + 1 == t.size()) {
    int count = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s.at(i) == t.at(i)) {
        count++;
      }
      else {
        cout << "No" << endl;
        return 0;
      }  
    }
    if (s.size() == count) cout << "Yes" << endl;
  } else cout << "No" << endl;
}

Measured memory_bytes: 3624
//15DTG
//16072020
#include<bits/stdc++.h>
using namespace std;
#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef long double ld;
const ld pi=3.1415926535897932384626433;
const int mod = 1e9+7;
int main()
{
   bolt;
   ll n;
   cin>>n;
   ll s=0;
   vector <ll> a(n);
   map <ll,ll> mp;
   for (ll i=0;i<n;i++)
   {
      cin>>a[i];
      s+=a[i];
      mp[a[i]]++;
   }
   ll q;
   cin>>q;
   while (q--)
   {
      ll b,c;
      cin>>b>>c;
      s-=mp[b]*b;
      s+=mp[b]*c;
      mp[c]+=mp[b];
      mp[b]=0;
      cout<<s<<endl;
   }
}


Measured memory_bytes: 10016
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n, m;


//inputします
void input() {
    cin >> n >> m;
}

//ライブラリ置き場

//main
int main() {
    input();
    if (n == m) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256