akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    using namespace std;
     
    typedef long long ll;
    int n;
    ll a[19];
    ll f(int l, int r, ll xl, ll xr) {
      if (r - l == 1) return a[l] * xl + a[r] * xr;
      ll ans = 1ll << 60;
      for (int i = l + 1; i < r; i++) {
        ans = min(ans, f(l, i, xl, xl + xr) + f(i, r, xl + xr, xr) - (xl + xr) * a[i]);
      }
      return ans;
    }
    int main() {
      scanf("%d", &n);
      for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
      }
      printf("%lld\n", f(1, n, 1, 1));
    }

Measured memory_bytes: 256
import java.util.*;

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

	void doIt() {
		sA();
	}

	void sA() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(b / a > c) {
			System.out.println(c);
		}
		else System.out.println(b / a);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 23764
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*
		 *
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		int N = S.length();
		int A = -2;
		int B = -2;
		for (int i = 1; i < N; i++) {
			if (S.charAt(i)==S.charAt(i-1)) {
				A=i-1;
				B=i;
			}
		}
		for (int i = 0; i+2<N; i++) {
			if (S.charAt(i)==S.charAt(i+2)) {
				A=i;
				B=i+2;
			}
		}
		A++;
		B++; //One based indexing now
		O.pln(A+" "+B);
	}	
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 28460
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	char S[100001]; cin >> S;

	int i = 0;
	bool B[26] = { false };
	while (S[i] != '\0') {
		B[S[i] - 'a'] = true;
		i++;
	}

	rep(i, 0, 26) {
		if (!B[i]) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1 << 30)

int H, A[MAX+1];

void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if(r <= H && A[r] > A[largest]) largest = r;
	
	if(largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}	
}

int extract() {
	int maxv;
	if(H < 1) return -INFTY;
	maxv = A[1];
    A[1] = A[H--];
	maxHeapify(1);
	return maxv;		
}

void increaseKey(int i, int key) {
	if(key < A[i]) return;
	A[i] = key;
	while(i > 1 && A[i / 2] < A[i]) {
		swap(A[i], A[i / 2]);
		i = i / 2; 
	} 
}

void insert(int key) {
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}

int main() {
	int key;
	char com[10];
	
	while( 1 ) {
		scanf("%s", com);
		if(com[0] == 'e' && com[1] == 'n') break;
		if(com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		} else {
			printf("%d\n", extract());
		}
	}
	
}

Measured memory_bytes: 6464
(n,),a,*z=$<.map{_1.split.map &:to_i}
g=(d=0,*[2e9]*n).map{[]}
z.map{g[_1]<<_2;g[_2]<<_1}
f=->u,r{x=d[k=d.bsearch_index{_1>=a[u-1]}]
d[k]=a[u-1]
$*[u]=r=[r,k].max
g[u].map{$*[_1]||f[_1,r]}
d[k]=x}
f[1,0]
puts$*


Measured memory_bytes: 281740
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX_N=1010;
char s[MAX_N];
bool check(int l,int r){
	int flag=1;
	for(int i=0;i<=r-l;i++){
		if(s[l+i]!=s[r-i]){
			flag=0;
			break;
		}
	}
	if(flag)
	return true;
	else
	return false;
}
int main(void){
	scanf("%s",s);
	int n=strlen(s);
	//cout<<n<<"\n";
	if(check(0,n-1)&&check(0,(n-1)/2-1)&&check((n+3)/2-1,n-1))
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[] a = GetInts(N);

		if(a.All(x => x != 1))
		{
			WriteLine(-1);
			return;
		}

		int current = 1;
		for(int i = 0; i < N; i++)
		{
			if(a[i] == current)
				current++;
		}

		WriteLine(N - current + 1);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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

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

            int ret = 0;

            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    for (int k = 1; k <= N; k++)
                    {
                        var u = gcd(i, j);

                        var t = gcd(u, k);

                        ret += t;
                    }
                }
            }

            Console.WriteLine(ret);
        }

        static int gcd(int p, int q)
        {
            if (p % q == 0) return q;

            return gcd(q, p % q);
        }
    }
}


Measured memory_bytes: 27536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
 
//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//infinity
#define INTINF 2000000000
#define LONGINF 20000000000
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(){
	string s;
	int w;
	cin >> s >> w;
	string answer;
	for(int i=0;i<s.size();i+=w){
		answer.push_back(s[i]);
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]){
		print("Yes")
	}
	else{
		print("No")
	}
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut split = buf.split(" ");
    let a_raw = split.next().unwrap();
    let b_raw = split.next().unwrap();
    let a_num: u32 = a_raw.parse().unwrap();
    let b_num: u32 = b_raw.parse().unwrap();

    let res = if a_num <= b_num {
        append(a_raw, b_num)
    } else {
        append(b_raw, a_num)
    };
    println!("{}", res);
}

fn append(a: &str, b: u32) -> String {
    let mut buf = String::new();
    for _ in 0..b {
        buf.push_str(a);
    }
    buf
}

Measured memory_bytes: 4352
s = input()

ints = [int(s[i]) for i in range(len(s))]

rope = []
o = []
o.append(str(ints[0]))

for i  in range(2**(len(ints)-1)):
	total = ints[0]
	ope = ['-' for i in range(len(ints)-1)]

	for j in range(len(ints)-1):

		if((i>>j) & 1):
			total = total + ints[j+1]
			ope[j] = '+'
		else :
			total = total - ints[j+1]
			ope[j] = '-'

	# print('t',total)
	if total == 7:
		rope = ope
		break


for i in range(len(rope)):
	o.append(rope[i])
	o.append(str(ints[i+1]))


print(''.join(o)+'=7')



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i,n) for (int i=0; i < int(n); i++)
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) * b;
	//a*bは64bit integer overflow
}

bool integer(double num) {
	return floor(num) == num;
}

Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int n, m;
char field[100][100];

void dfs(int x, int y) {
	field[x][y] = '.';

	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			int nx = x + dx, ny = y + dy;
			if (0 <= nx && nx < n && 0 <= ny && ny < m && field[nx][ny] == 'W') {
				dfs(nx, ny);
			}
		}
	}
	return;
}





int main() {
	string str; cin >> str;
	string temp;
	int cnt1 = 0, cnt2 = 0;
	int pos = 0;
	string t="";
	int j;
	for (int i = 0; i < str.size(); i++) {
		for (int k = 1; k < 200001; k++) {
			if (k+pos<=str.size()&&pos< str.size())t = str.substr(pos, k);
			else {
				break;
			}
			if (t != temp) {
				cnt1++;
				temp = t;
				pos = pos+k;
				//cout << pos<<" "<<t << endl;
				break;
			}
		}
	}
	////cout << cnt1 << endl;
	//reverse(str.begin(), str.end());
	//pos = 0;
	//t = "";
	//for (int i = 0; i < str.size(); i++) {
	//	for (int k = 1; k < 200001; k++) {
	//		if (k + pos <= str.size() && pos < str.size())t = str.substr(pos, k);
	//		if (t != temp) {
	//			cnt2++;
	//			temp = t;
	//			pos = pos + k;
	//			//cout << pos<<" "<<t << endl;
	//			break;
	//		}
	//	}
	//}
	cout << cnt1;

	cout << endl;
	return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int ans = 0;
	if (A >= K) ans = K;
	else if (A < K && B >= K - A) ans = A;
	else ans = 2 * A + B - K;
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)

int main()
{
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++)
  {
    int a = n / i;
    sum += (ll)i * a * (a + 1) / 2;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3484
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String ans="";
		//int c=0;
		
		
		int K = Integer.parseInt(br.readLine());
		String s=br.readLine();
		
		int len=s.length();
	
		if(len<=K)
			ans=s;
		
		else
			ans=s.substring(0,K)+"...";
		
		out.println(ans);
		
	}
	
	
}




Measured memory_bytes: 36248
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

int main(void) {
    ll A, B;
    cin >> A >> B;
    A--; B--;
    vector<string> ans(100);
    ll i;
    
    for(i=0; i<50; i++) {
        ans[i]=string(100, '.');
        ans[i+50]=string(100, '#');
    }
    
    ll r=0, c=0;
    for(i=0; i<B; i++, c+=2) {
        if(c==100) {
            r+=2;
            c=0;
        }
        ans[r][c]='#';
    }
    r=99; c=0;
    for(i=0; i<A; i++, c+=2) {
        if(c==100) {
            r-=2;
            c=0;
        }
        ans[r][c]='.';
    }
    
    cout << "100 100" << endl;
    
    for(i=0; i<100; i++) {
        cout << ans[i] << endl;
    }
    
}

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

int main()
{
    string s;
    char tmp_s;
    int N, ct_letr[26] = {0};
    cin >> N;
    REP(i, N) cin >> tmp_s, s += tmp_s;
    REP(i, N) ct_letr[s[i] - 'A']++;
    count_if(&ct_letr[0], &ct_letr[26], [](int x) { return 0 < x; }) == 3 ? cout << "Three" : cout << "Four";

    return 0;
}


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

public class Main{
	public static void main(String[] args) {
		int []money = new int[50];
		int []set = {1520, 1870, 2244};
		Arrays.fill(money, 10000000);
		for(int i = 0; i <= 22; i++) {
			for(int j = 0; j <= 16; j++) {
				for(int k = 0; k <= 10; k++) {
					int w = 200 * i + 300 * j + 500 * k;
					if(w < 500) continue;
					if(w > 5000) break;
					int t1 = i / 5;
					int t2 = j / 4;
					int t3 = k / 3;
					int m = t1 * set[0] + t2 * set[1] + t3 * set[2];
					m += (i - t1 * 5) * 380;
					m += (j - t2 * 4) * 550;
					m += (k - t3 * 3) * 850;
					money[w / 100 - 1] = Math.min(money[w / 100 - 1], m);
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true) {
			int k = sc.nextInt();
			if(k == 0) break;
			System.out.println(money[k / 100 - 1]);
		}
		sc.close();
	}
}


Measured memory_bytes: 26128
B = []
for i in range(3):
    B += list(map(int,input().split()))
# print(B)
N = int(input())
Y = []
for i in range(N):
    b = int(input())
    if b in B:
        Y.append(B.index(b)+1)
# print(Y)
if 1 in Y and 5 in Y and 9 in Y:
    print("Yes")
elif 3 in Y and 5 in Y and 7 in Y:
    print("Yes")
    
elif 1 in Y and 2 in Y and 3 in Y:
    print("Yes")
elif 4 in Y and 5 in Y and 6 in Y:
    print("Yes")
elif 7 in Y and 8 in Y and 9 in Y:
    print("Yes")
    
elif 1 in Y and 4 in Y and 7 in Y:
    print("Yes")
elif 2 in Y and 5 in Y and 8 in Y:
    print("Yes")
elif 3 in Y and 6 in Y and 9 in Y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N=input()
A=input()
Alist=A.split()
counts=0
for i in Alist:
    if int(i)%2==1:
        counts=counts
    elif int(i)%3==0:
        counts=counts
    elif int(i)%5==0:
        counts=counts
    else:
        counts=counts+1
if counts>=1:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans=1;
    for(ll i=1;i*i<=m;i++){
        if(m%i==0){
            if(i*n<=m){
                ans=max(ans,i);
            }

            ll x=m/i;
            if(x*n<=m){
                ans=max(ans,x);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3532
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
A = LI()
if all([a > 0 for a in A]):
    now = min(A)
    print(sum(A) - now * 2)
    A.remove(now)
    last = A.pop()
    while A:
        nxt = A.pop()
        print(now, nxt)
        now -= nxt
    print(last, now)
elif all([a < 0 for a in A]):
    now = max(A)
    print(-sum(A) + now * 2)
    A.remove(now)
    while A:
        nxt = A.pop()
        print(now, nxt)
        now -= nxt
else:
    print(sum([abs(i) for i in A]))
    minus = []
    plus = []
    for a in A:
        if a > 0:
            plus += [a]
        elif a < 0:
            minus += [a]
        else:
            if not plus:
                plus += [a]
            else:
                minus += [a]
    ret = minus.pop()
    plus_now = plus.pop()
    while plus:
        nxt = plus.pop()
        print(ret, nxt)
        ret -= nxt
    print(plus_now, ret)
    ret = plus_now - ret
    while minus:
        nxt = minus.pop()
        print(ret, nxt)
        ret -= nxt


Measured memory_bytes: 61712
score = ""
while True:
    m,f,r=map(int,input().split())
    if (m,f,r)==(-1,-1,-1):
        break
    if m==-1 or f==-1 or m+f<30:
        score="F"
    elif m+f>=80:
        score="A"
    elif m+f>=65:
        score="B"
    elif m+f>=50 or r>=50:
        score="C"
    else:
        score="D"
    print(score)


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

int main()
{
    int n,h[25]={0},i,j,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>h[i];
    for(i=1;i<=n;i++){
            int flag=1;
        for(j=0;j<i;j++)
        if(h[i]<h[j]) flag=0;
        if(flag==1) sum++;}
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    LL(x, k, d);
    if(x < 0) x = -x;
    ll c = x / d;
    if(k <= c){
        print(x - d * k);
        return 0;
    }
    else{
        k -= c;
        x -= d * c;
        if(k % 2) print(abs(x - d));
        else print(abs(x));
    }
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

ll hoge(ll n){
	while(n/10!=0){
		n/=10;
	}
	return n;
}

int main(){
	ll n; cin>>n;
	int c[10][10]={0};
	FOR(i,1,n+1){
		c[i%10][hoge(i)]++;
	}
	ll ans=0;
	REP(i,10){
		REP(j,10){
			ans+=c[i][j]*c[j][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int a,b;
    cin>>a>>b;
    string s3;
    cin>>s3;
    if(s3==s1)
        cout<<a-1<<" "<<b<<endl;
        else
            cout<<a<<" "<<b-1<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

LL dp[ 64 ][ 64 ][ 1 << 12 ];

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	cout << setprecision( 12 ) << fixed;

	int N, K;
	cin >> N >> K;

	VI A( N );
	cin >> A;

	dp[0][0][0] = 1;

	REP( i, N )
	{
		REP( j, N + 1 )
		{
			REP( k, K * N + 1 )
			{
				dp[ i + 1 ][j][k] += dp[i][j][k];
				dp[ i + 1 ][ j + 1 ][ k + A[i] ] += dp[i][j][k];
			}
		}
	}

	LL res = 0;
	REP( i, 1, N + 1 )
	{
		res += dp[N][i][ i * K ];
	}
	cout << res << endl;

	return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> X(N);
    for(int i=0; i<N; i++) cin >> X[i];

    vector<int> A = X;
    sort(A.begin(), A.end());
    int mid1 = A[N/2-1];
    int mid2 = A[N/2];
    for(int i=0; i<N; i++)
    {
        if(X[i] <= mid1) cout << mid2 << endl;
        else cout << mid1 << endl;
    }

    return 0;
}


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



//#define int int64_t
signed main()
{
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i];

	int x2 = 0;
	for(int i = 0; i < n; ++i)
	{
		if(i&1) x2 -= a[i];
		else x2 += a[i];
	}
	vector<int> ans(n);
	ans[0] = x2/2;
	for(int i = 0; i < n-1; ++i)
	{
		ans[i+1] = a[i] - ans[i];
	}
	for(int i = 0; i < n; ++i){
		ans[i] *= 2;
	}
	for(int i = 0; i < n; ++i){
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 2176
n = int(input())
s = list(input())

# W,E各々の累積和を求めておく
cumulative_e = [0] * (n+1)
cumulative_w = [0] * (n+1)
for i in range(1, n+1):
  if s[i-1] == 'W':
    cumulative_w[i] = cumulative_w[i-1] + 1
    cumulative_e[i] = cumulative_e[i-1]
  elif s[i-1] == 'E':
    cumulative_e[i] = cumulative_e[i-1] + 1
    cumulative_w[i] = cumulative_w[i-1]

# 誰がリーダーに適任か調べる
result = [0] * n
for j in range(n):
  result[j] = cumulative_w[j] + ( cumulative_e[n] - cumulative_e[min(n,j+1)])

print(min(result))

Measured memory_bytes: 31800
#include<bits/stdc++.h>
using namespace std;
int N;
pair<int,int> c[55];
map<pair<int,int>,int> pq;
int ans;
int main(){
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>c[i].first>>c[i].second;
	}
	sort(c+1,c+N+1);
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=N;j++)
		{
			if(i==j) continue;
			pq[{c[i].first-c[j].first,c[i].second-c[j].second}]++;
			ans=max(ans,pq[{c[i].first-c[j].first,c[i].second-c[j].second}]);
		}
	}
	cout<<N-ans;
	
	
	
}

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);i++)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int n, a, b, ans=0;
    cin>>n>>a>>b;

    loop(i, 1, n){
        ll sum = 0;
        ll j = i;
        while(j>0){
            sum = sum + j%10;
            j = j/10;
        }
        if(sum>= a && sum<=b){
            ans = ans + i;
            //cout<<i<<" "<<ans<<endl;
        }



    }

    cout<<ans;

}






























Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust";
    else cout<<"win";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n) {
        cin>>a[i];
        sum+=a[i];
    }
    
    if(sum%(n*(n+1)/2)!=0) {
        cout<<"NO"<<endl;
        return 0;
    }
    
    ll k=sum/(n*(n+1)/2);
    ll cnt=0;
    rep(i,n-1) {
        ll d=a[i+1]-a[i];
        if((k-d)%n!=0) {
            cout<<"NO"<<endl;
            return 0;
        }
        ll x=(k-d)/n;
        if(x<0) {
            cout<<"NO"<<endl;
            return 0;
        }
        cnt+=x;
    }
    
    cout<<(cnt<=k ? "YES" : "NO")<<endl;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
// }}}

// Mint {{{
template <i64 MOD>
class ModInt {
  i64 value;
public:
  inline ModInt(const ModInt& other) noexcept : value(other.value) {}
  inline ModInt(i64 value = 0) noexcept :
    value((value >= MOD) ? value % MOD : (value < 0) ? (value + MOD) % MOD : value) {}

  inline ModInt inv() const noexcept { return power(value, MOD - 2); }

  inline ModInt& operator+=(const ModInt& other) noexcept {
    value = (value + other.value) % MOD; return *this;
  }

  inline ModInt& operator-=(const ModInt& other) noexcept {
    value = (MOD + value - other.value) % MOD; return *this;
  }

  inline ModInt& operator*=(const ModInt& other) noexcept {
    value = (value * other.value) % MOD; return *this;
  }

  inline ModInt& operator/=(const ModInt& other) noexcept {
    value = (value * other.inv().value) % MOD; return *this;
  }

  inline ModInt operator+(const ModInt& other) noexcept { return ModInt(*this) += other; }
  inline ModInt operator-(const ModInt& other) noexcept { return ModInt(*this) -= other; }
  inline ModInt operator*(const ModInt& other) noexcept { return ModInt(*this) *= other; }
  inline ModInt operator/(const ModInt& other) noexcept { return ModInt(*this) /= other; }

  inline bool operator==(const ModInt& other) noexcept { return value == *other; }
  inline bool operator!=(const ModInt& other) noexcept { return value != *other; }

  template <class int_>
    explicit inline operator int_() const noexcept { return static_cast<int_>(value); }

  friend ostream& operator<<(ostream &os, ModInt other) noexcept {
    os << other.value; return os;
  }

  friend istream& operator>>(istream &is, ModInt& other) noexcept {
    is >> other.value; return is;
  }

  static constexpr inline ModInt power(i64 n, i64 p) noexcept {
    i64 ret = 1;
    for (; p > 0; p >>= 1) {
      if (p & 1) ret = (ret * n) % MOD;
      n = (n * n) % MOD;
    }
    return ret;
  }
};

using Mint = ModInt<MOD>;
// }}}

i64 sigma(i64 n) { return n * (1 + n) / 2; }

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

  i64 N, K;
  cin >> N >> K;

  vector<i64> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  Mint v1 = 0, v2 = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < i; ++j) {
      if (a[j] > a[i]) v1 += 1;
    }
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (a[j] > a[i]) v2 += 1;
    }
  }

  v1 *= K;
  v2 *= sigma(K - 1);

  cout << v1 + v2 << "\n";

  return 0;
}


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

#define forn(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)x.size() 
typedef long long ll;
using namespace std;

int T[5];

int main() {
	
	forn(i,5) cin>>T[i];
	ll mn=1e9;
	do{
		ll cost=0;
		forn(i,5){
			int x=(T[i]+9)/10;
			cost+=T[i]+(i==4?0:(10*x-T[i]));
		}
		mn=min(mn,cost);
	}while(next_permutation(T,T+5));
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 3580
//
// Created by Akifumi Ohata on 2017/10/03.
//


#include<iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

using ll =  long long int;

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

    string S;



    cin >> S;


    int S_size = static_cast<int>(S.size());


    int ans_size = S_size-2;


    string Answer;

    Answer = S.front() + std::to_string(ans_size) + S.back();

    cout  << Answer << endl ;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())
 
using namespace std;
 
typedef long long ll;
 
int n, m; ll t;
int s[300005], d[300005];
pair<int,int> o[300005];
int res[300005];
 
int main() {
    scanf("%d%d%lld", &n, &m, &t);
    FO(i,0,n) scanf("%d %d", s+i, d+i), s[i];
    FO(i,0,n) o[i] = make_pair(s[i],i);
    sort(o,o+n);
    vector<ll> p;
    ll nc = 0;
    FO(i,0,n) {
        int dir = d[i] == 2 ? -1 : 1;
        ll pos = s[i] + dir * t;
        ll fp = ((pos%m)+m)%m;
        ll g = pos > 0 ? pos / m : (pos-m+1) / m;
        nc += g;
        p.push_back(fp);
    }
    nc = ((nc%n)+n)%n;
    sort(p.begin(),p.end());
    FO(i,0,n) res[o[i].second] = p[(i+nc)%n];
    FO(i,0,n) printf("%d%c", res[i], " \n"[i+1==n]);
}

Measured memory_bytes: 5748
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 08:35:15 2019

@author: Owner
"""

from collections import deque

Sd = input()
T = input()
S = deque()

Sr = list(reversed(Sd))
Tr = list(reversed(T))

flg_match = True    
for i,s in enumerate(Sr):
    flg_match = True    
    for j,t in enumerate(Tr):
        if i+j >= len(Sr):
            flg_match = False
            break
        if t == Sr[i+j] or Sr[i+j] == "?":
            pass
        else:
            flg_match = False
            break
        #print(t, Sr[i+j], flg_match)
    if flg_match:
        S.appendleft(T)
        #print(Sd)
        break
    else:
        if s == "?":
            S.appendleft("a")
        else:
            S.appendleft(s)
#print(flg_match)
if not flg_match:
    print("UNRESTORABLE")
else:    
    S = "".join(list(S))
    S = Sd[:len(Sd)-len(S)]+S
    S = S.replace("?", "a")
    
    print(S)

Measured memory_bytes: 3444
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
typedef struct
{
  char a;
  int b;
  int c;
}card;
 
void quickSort(int,int);
int partition(int,int);
int inStable();
int n;
card A[1000000];
 
int main(){
 
  int i;
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf(" %c%d",&A[i].a,&A[i].b);
    A[i].c = i;
  }
  quickSort(1,n);
 
  if(inStable()==1){
printf("Stable\n");
  }
     else printf("Not stable\n");
   
  for(i = 1;i <= n;i++){
    printf("%c %d\n",A[i].a,A[i].b);
    
  }
  return 0;
}
 
void quickSort(p,r){
  int q;
 
  if(p < r){
    q = partition(p,r);
    quickSort(p,q-1);
    quickSort(q+1,r);
  }
}
 
int partition(int p,int r){
 
  int x;
  card y;
  int i,j;
 
  x=A[r].b;
  i=p-1;
 
  for(j=p;j<=r-1;j++){
    if(A[j].b<= x){
      i=i+1;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
    }
  }
  y=A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}
 
int inStable()
{
  int i,j;
 
  for(i=1;i<=n;i++){
   
    if(A[i].b==A[i-1].b){
      if(A[i].c< A[i-1].c){
 return 0;
      }
    }
  }
  return 1;
}

Measured memory_bytes: 1780
#include <iostream>

using namespace std;

int main()
{
    int health , kind , attack, counter=0;
    cin>>health>>kind;
    for (int i=0; i<kind; i++){
        cin>>attack;
        counter=counter+attack;
    };
    if(health<counter ){
        cout<<"Yes";
    }
    else if (health==counter){
         cout<<"Yes";

    }
    else {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define p 1000000007
using namespace std;
int n,K;
int a[2020],bok[2020];
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),bok[a[i]]++;
	long long sum=0,sum2=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
		if(a[j]>a[i]) sum++;
	for(int i=1;i<=2000;i++)
	bok[i]+=bok[i-1];
	for(int i=1;i<=2000;i++)
	sum2+=1LL*(bok[i]-bok[i-1])*(n-bok[i])%p;
	printf("%lld\n",(sum*K%p+sum2*K%p*(K-1)%p*500000004%p)%p);
	return 0;
}

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

long long gcd(long long a, long long b){
	if(b == 0){
		return a;
	}
	return gcd(b, a%b);
}

int main(){
	long long a, b, res;
	cin >> a >> b;
	res = gcd(a, b);
	cout << a*b/res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <cctype>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;


int main() {
    
    int n; cin >>n;
    vector<int> a(n); REP(i,n) cin >> a[i];

    vector<int> b = a;
    sort(b.begin(), b.end(), greater<int>());

    for (int i = 0; i < n; i++) {
        if (a[i] == b[0]) {
            cout << b[1] << endl;
        } else {
            cout << b[0] << endl;
        } 
    }

    return 0;

}




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

using namespace std;

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

    vector< pair<int, int> > a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());

    long sum = 0;
    long count = 0;
    while(sum < K) {
        sum += a[count].second;
        count++;
    }
    cout << a[count-1].first << endl;
    return 0;
}


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

int main() {
    int n, s;
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int mins = 1000, maxs = 0, sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> s;
            sum += s;
            mins = min(s, mins);
            maxs = max(s, maxs);
        }
        sum -= mins + maxs;
        cout << sum / (n - 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
#define itc(n) char(n+48)
#define cti(ch) (ch-48)
#define pb push_back
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){ostringstream convert;convert<<n;return convert.str();}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>bool is_palindrome(T s){T s1=s;reverse(s1.begin(),s1.end());if(s==s1)return true;return false;}
template<class T>int digit_sum(T s){int sum=0; for(int i=0; i<s.size(); i++)sum+=cti(s[i]);return sum;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}
template<class T>T doStringSum(T s1, T s2){int len1=s1.length(), len2=s2.length();
    if(len1<len2)return doStringSum(s2, s1);
    T ans="";int carry=0, i, s;
    for(i=1;i<=len1;i++){s = carry+cti(s1[len1-i]);if(i<=len2)s += cti(s2[len2-i]);
    ans = itc(s%10)+ans;carry = s/10;}if(carry!=0)ans = itc(carry)+ans;
    return ans;
}
template<class T>T dostringmultiply(T s1, T s2){int len1=s1.length(), len2=s2.length();
    if(len1<len2)return dostringmultiply(s2,s1);
    int i,j,p, carry=0;T result, net="", c;
    for(i=len2-1;i>=0;i--){carry=0;result="";c="";
    for(j=len1-1;j>=0;j--){p=cti(s1[j])*cti(s2[i]);result = itc((p+carry)%10)+result;carry=(p+carry)/10;}
    if(carry!=0){c=to_string(carry);result=c+result;}
    for(j=i;j<len2-1;j++)result+="0";net=doStringSum(net,result);}
    return net;
}

int main()
{
    fast;
    int n,m;
    cin>>n;
    int a[n+5];
    for(int i=0; i<n; i++)cin>>a[i];
    sort(a,a+n);
    if(a[n/2]==a[n/2-1])cout<<0<<endl;
    else cout<<a[n/2]-a[n/2-1]<<endl;
    return 0;
}


Measured memory_bytes: 640
buf = $stdin.gets.chop

ary = [0]
buf.each_char do |ch|
  ary << ((ch == "<") ? ary[-1]+1 : 0)
end
(ary.size-2).downto(0) do |i|
  if buf[i] == ">" then
    ary[i] = [ary[i], ary[i+1]+1].max
  end
end

puts ary.inject(:+)

Measured memory_bytes: 6788
n = int(input())
tmp = [input() for _ in range(n)]
ans = []
for i in range(26):
    x=chr(ord('a')+i)
    cnt=50
    for s in tmp:
        cnt = min(cnt,s.count(x))
    else:
        ans.append(x*cnt)
print(''.join(ans))

Measured memory_bytes: 9156
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    char s[4],l[4];

    while (~scanf ("%s%s",s,l))
    {
        int t;
        if(s[0]==l[2]&&s[1]==l[1]&&s[2]==l[0])
            t=1;
        else t=0;
        if(t==1)
        {
            printf("YES\n");
        }
        else
        {
            printf ("NO\n");
        }
    }
}

Measured memory_bytes: 128